diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2009-06-02 19:07:49 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2009-06-02 19:07:49 +0200 |
commit | 8361d1cc4e8fe34ba737815b7de5d8e0bf0b34d7 (patch) | |
tree | 50fa6564b14cff40946bd1aa8af2c5ec6217e88e /src/application.cpp | |
parent | Porting history Ui to KDE.. (diff) | |
parent | Moving guessUrlFromString function to Application class (diff) | |
download | rekonq-8361d1cc4e8fe34ba737815b7de5d8e0bf0b34d7.tar.xz |
Fixing (again) merge conflicts..
Diffstat (limited to 'src/application.cpp')
-rw-r--r-- | src/application.cpp | 74 |
1 files changed, 60 insertions, 14 deletions
diff --git a/src/application.cpp b/src/application.cpp index 5f7892c4..09a8a087 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -34,7 +34,6 @@ #include "networkaccessmanager.h" #include "mainview.h" #include "webview.h" -#include "download.h" // KDE Includes #include <KCmdLineArgs> @@ -52,7 +51,6 @@ QPointer<HistoryManager> Application::s_historyManager; QPointer<NetworkAccessManager> Application::s_networkAccessManager; -QPointer<DownloadManager> Application::s_downloadManager; QPointer<BookmarkProvider> Application::s_bookmarkProvider; @@ -93,7 +91,7 @@ int Application::newInstance() { for (int i = 0; i < args->count(); ++i) { - KUrl url = MainWindow::guessUrlFromString(args->arg(i)); + KUrl url = guessUrlFromString(args->arg(i)); newWebView(); mainWindow()->loadUrl(url); } @@ -150,7 +148,7 @@ WebView *Application::newWebView(Rekonq::OpenType type) CookieJar *Application::cookieJar() { - return (CookieJar*)networkAccessManager()->cookieJar(); + return (CookieJar *)networkAccessManager()->cookieJar(); } @@ -176,16 +174,6 @@ HistoryManager *Application::historyManager() } -DownloadManager *Application::downloadManager() -{ - if (!s_downloadManager) - { - s_downloadManager = new DownloadManager(); - } - return s_downloadManager; -} - - BookmarkProvider *Application::bookmarkProvider() { if (!s_bookmarkProvider) @@ -206,3 +194,61 @@ KIcon Application::icon(const KUrl &url) const return icon; } + +KUrl Application::guessUrlFromString(const QString &string) +{ + QString urlStr = string.trimmed(); + QRegExp test(QLatin1String("^[a-zA-Z]+\\:.*")); + + // Check if it looks like a qualified URL. Try parsing it and see. + bool hasSchema = test.exactMatch(urlStr); + + if (hasSchema) + { + QUrl qurl(urlStr, QUrl::TolerantMode); + KUrl url(qurl); + + if (url.isValid()) + { + return url; + } + } + + // Might be a file. + if (QFile::exists(urlStr)) + { + QFileInfo info(urlStr); + return KUrl::fromPath(info.absoluteFilePath()); + } + + // Might be a shorturl - try to detect the schema. + if (!hasSchema) + { + int dotIndex = urlStr.indexOf(QLatin1Char('.')); + + if (dotIndex != -1) + { + QString prefix = urlStr.left(dotIndex).toLower(); + QString schema = (prefix == QLatin1String("ftp")) ? prefix : QLatin1String("http"); + QUrl qurl(schema + QLatin1String("://") + urlStr, QUrl::TolerantMode); + KUrl url(qurl); + + if (url.isValid()) + { + return url; + } + } + } + + // Fall back to QUrl's own tolerant parser. + QUrl qurl = QUrl(string, QUrl::TolerantMode); + KUrl url(qurl); + + // finally for cases where the user just types in a hostname add http + if (qurl.scheme().isEmpty()) + { + qurl = QUrl(QLatin1String("http://") + string, QUrl::TolerantMode); + url = KUrl(qurl); + } + return url; +} |