summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-06-01 01:43:03 +0200
committerAndrea Diamantini <adjam7@gmail.com>2009-06-01 23:59:35 +0200
commit0f96a0ae5d93853d56ad723557fc58ca51b7cef0 (patch)
tree88b10962d5cf6fc06359ecf07b7f3a9d6b7bfb11 /src
parentRemoved unuseful download classes (diff)
downloadrekonq-0f96a0ae5d93853d56ad723557fc58ca51b7cef0.tar.xz
Moving guessUrlFromString function to Application class
Diffstat (limited to 'src')
-rw-r--r--src/application.cpp63
-rw-r--r--src/application.h4
-rw-r--r--src/mainview.cpp6
-rw-r--r--src/mainwindow.cpp61
-rw-r--r--src/mainwindow.h1
5 files changed, 67 insertions, 68 deletions
diff --git a/src/application.cpp b/src/application.cpp
index 06947e22..09a8a087 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -91,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);
}
@@ -148,7 +148,7 @@ WebView *Application::newWebView(Rekonq::OpenType type)
CookieJar *Application::cookieJar()
{
- return (CookieJar*)networkAccessManager()->cookieJar();
+ return (CookieJar *)networkAccessManager()->cookieJar();
}
@@ -193,3 +193,62 @@ 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;
+}
diff --git a/src/application.h b/src/application.h
index dd26ef9c..e61b2a31 100644
--- a/src/application.h
+++ b/src/application.h
@@ -75,10 +75,12 @@ public:
static Application *instance();
MainWindow *mainWindow();
- WebView* newWebView(Rekonq::OpenType type = Rekonq::Default);
+ WebView *newWebView(Rekonq::OpenType type = Rekonq::Default);
KIcon icon(const KUrl &url) const;
+ static KUrl guessUrlFromString(const QString &url);
+
static HistoryManager *historyManager();
static CookieJar *cookieJar();
static NetworkAccessManager *networkAccessManager();
diff --git a/src/mainview.cpp b/src/mainview.cpp
index d8d1c2b5..ea56527d 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -362,10 +362,8 @@ WebView *MainView::newWebView(Rekonq::OpenType type)
connect(webView, SIGNAL(shiftCtrlTabPressed()), this, SLOT(previousTab()));
// connecting webPage signals with mainview
- connect(webView->page(), SIGNAL(windowCloseRequested()),
- this, SLOT(windowCloseRequested()));
- connect(webView->page(), SIGNAL(printRequested(QWebFrame *)),
- this, SIGNAL(printRequested(QWebFrame *)));
+ connect(webView->page(), SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested()));
+ connect(webView->page(), SIGNAL(printRequested(QWebFrame *)), this, SIGNAL(printRequested(QWebFrame *)));
addTab(webView, i18n("(Untitled)"));
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index f47c6677..287d423d 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -409,65 +409,6 @@ void MainWindow::slotUpdateBrowser()
}
-KUrl MainWindow::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;
-}
-
-
void MainWindow::loadUrl(const KUrl &url)
{
m_view->loadUrl(url);
@@ -543,7 +484,7 @@ void MainWindow::slotFileOpen()
if (filePath.isEmpty())
return;
- loadUrl(guessUrlFromString(filePath));
+ loadUrl(Application::guessUrlFromString(filePath));
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 7d0b2e5c..cc0aa2e8 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -62,7 +62,6 @@ public:
MainWindow();
~MainWindow();
- static KUrl guessUrlFromString(const QString &url);
MainView *mainView() const;
WebView *currentTab() const;
QAction *actionByName(const QString name);