summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/application.cpp107
-rw-r--r--src/application.h27
-rw-r--r--src/mainwindow.cpp2
-rw-r--r--src/rekonqrun.cpp201
-rw-r--r--src/rekonqrun.h84
6 files changed, 127 insertions, 295 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 726ac82e..73ef1dc0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -32,7 +32,6 @@ SET( rekonq_SRCS
webpage.cpp
cookiedialog.cpp
cookieexceptiondialog.cpp
- rekonqrun.cpp
)
diff --git a/src/application.cpp b/src/application.cpp
index 27dcc83a..0cebac26 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -34,6 +34,7 @@
#include "networkaccessmanager.h"
#include "mainview.h"
#include "webview.h"
+#include "urlbar.h"
// KDE Includes
#include <KCmdLineArgs>
@@ -43,8 +44,12 @@
#include <kio/job.h>
#include <kio/jobclasses.h>
#include <KPassivePopup>
+#include <KToolInvocation>
// Qt Includes
+#include <QRegExp>
+#include <QFile>
+#include <QFileInfo>
#include <QtCore/QTimer>
#include <QtWebKit/QWebSettings>
#include <QtWebKit/QWebHistoryInterface>
@@ -84,7 +89,7 @@ int Application::newInstance()
setWindowIcon(KIcon("rekonq"));
m_mainWindow->show();
-
+
QTimer::singleShot(0, this, SLOT(postLaunch()));
}
@@ -92,16 +97,14 @@ int Application::newInstance()
{
for (int i = 0; i < args->count(); ++i)
{
- KUrl url = guessUrlFromString(args->arg(i));
- newWebView();
- mainWindow()->loadUrl(url);
+ loadUrl(args->arg(i), Rekonq::New);
}
args->clear();
}
else
{
- newWebView();
- mainWindow()->slotHome();
+ m_mainWindow->mainView()->newTab();
+ m_mainWindow->slotHome();
}
return 0;
@@ -253,3 +256,95 @@ KUrl Application::guessUrlFromString(const QString &string)
}
return url;
}
+
+
+void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type)
+{
+ if (url.isEmpty())
+ return;
+
+ QString scheme = url.scheme();
+
+ if (scheme == QLatin1String("mailto"))
+ {
+ KToolInvocation::invokeMailer(url);
+ return;
+ }
+
+ KUrl loadingUrl(url);
+
+ // create convenience fake api:// protocol for KDE apidox search and Qt docs
+ if (scheme == QLatin1String("api"))
+ {
+ QString path;
+ QString className = url.host().toLower();
+ if (className[0] == 'k')
+ {
+ path = QString("http://api.kde.org/new.classmapper.php?class=%1").arg(className);
+ }
+ else if (className[0] == 'q')
+ {
+ path = QString("http://doc.trolltech.com/4.5/%1.html").arg(className);
+ }
+ loadingUrl.setUrl(path);
+ }
+
+ if (loadingUrl.isRelative())
+ {
+ if(loadingUrl.path().contains('.'))
+ {
+ QString fn = loadingUrl.url(KUrl::RemoveTrailingSlash);
+ loadingUrl.setUrl("//" + fn);
+ loadingUrl.setScheme("http");
+ }
+ else
+ {
+ scheme = QLatin1String("gg");
+ }
+ }
+
+ // create convenience fake gg:// protocol, waiting for KServices learning
+ if(scheme == QLatin1String("gg"))
+ {
+ QString str = loadingUrl.path();
+ loadingUrl.setUrl( QString("http://google.com/search?&q=%1").arg(str) );
+ }
+
+ // create convenience fake wk:// protocol, waiting for KServices learning
+ if(scheme == QLatin1String("wk"))
+ {
+ QString str = loadingUrl.path();
+ loadingUrl.setUrl( QString("http://en.wikipedia.org/wiki/%1").arg(str) );
+ }
+
+
+ WebView *webView = m_mainWindow->mainView()->newTab();
+ m_mainWindow->mainView()->currentUrlBar()->setUrl(loadingUrl.prettyUrl());
+
+ switch(type)
+ {
+ case Rekonq::Default:
+ if (!ReKonfig::openTabsBack())
+ {
+ m_mainWindow->mainView()->setCurrentWidget(webView); // this method does NOT take ownership of webView
+ }
+ break;
+ case Rekonq::New:
+ m_mainWindow->mainView()->setCurrentWidget(webView); // this method does NOT take ownership of webView
+ break;
+ case Rekonq::Background:
+ break;
+ };
+
+ if (webView)
+ {
+ webView->setFocus();
+ webView->load(loadingUrl);
+ }
+}
+
+
+void Application::loadUrl(const QString& urlString, const Rekonq::OpenType& type)
+{
+ return loadUrl( guessUrlFromString(urlString), type );
+}
diff --git a/src/application.h b/src/application.h
index 24ee7d28..202cd99e 100644
--- a/src/application.h
+++ b/src/application.h
@@ -60,6 +60,18 @@ namespace Rekonq
Download, ///< downloading url
Info ///< information, (default)
};
+
+ /**
+ * @short Open link options
+ * Different modes of opening new tab
+ */
+ enum OpenType
+ {
+ Default, ///< open url according to users settings
+ New, ///< open url in new tab and make it current
+ Background ///< open url in new tab in background
+ };
+
}
@@ -81,8 +93,6 @@ public:
static KIcon icon(const KUrl &url);
- static KUrl guessUrlFromString(const QString &url);
-
static HistoryManager *historyManager();
static CookieJar *cookieJar();
static NetworkAccessManager *networkAccessManager();
@@ -95,7 +105,17 @@ public slots:
*/
void slotSaveConfiguration() const;
+public slots:
+
+ void loadUrl( const KUrl& url,
+ const Rekonq::OpenType& type = Rekonq::Default
+ );
+
+ void loadUrl( const QString& urlString,
+ const Rekonq::OpenType& type = Rekonq::Default
+ );
+
private slots:
/**
@@ -105,6 +125,9 @@ private slots:
private:
+
+ KUrl guessUrlFromString(const QString &url);
+
static QPointer<HistoryManager> s_historyManager;
static QPointer<NetworkAccessManager> s_networkAccessManager;
static QPointer<BookmarkProvider> s_bookmarkProvider;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 54f72e61..ef51e1e0 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -520,7 +520,7 @@ void MainWindow::slotFileOpen()
if (filePath.isEmpty())
return;
- loadUrl(Application::guessUrlFromString(filePath));
+ Application::instance()->loadUrl(filePath);
}
diff --git a/src/rekonqrun.cpp b/src/rekonqrun.cpp
deleted file mode 100644
index da1f4d93..00000000
--- a/src/rekonqrun.cpp
+++ /dev/null
@@ -1,201 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com>
-*
-*
-* This program is free software; you can redistribute it
-* and/or modify it under the terms of the GNU General
-* Public License as published by the Free Software Foundation;
-* either version 3, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* ============================================================ */
-
-
-// Self Includes
-#include "rekonqrun.h"
-#include "rekonqrun.moc"
-
-// Auto Includes
-#include "rekonq.h"
-
-// Local Includes
-#include "mainview.h"
-#include "urlbar.h"
-
-// KDE Includes
-#include <KToolInvocation>
-
-// Qt Includes
-#include <QRegExp>
-#include <QFile>
-#include <QFileInfo>
-
-
-RekonqRun::RekonqRun(QWidget *parent = 0)
- : QObject(parent)
- , m_window(parent)
-{
-}
-
-
-RekonqRun::~RekonqRun()
-{
-}
-
-
-void RekonqRun::loadUrl(const KUrl& url, const Rekonq::OpenType& type)
-{
- if (url.isEmpty())
- return;
-
- QString scheme = url.scheme();
-
- if (scheme == QLatin1String("mailto"))
- {
- KToolInvocation::invokeMailer(url);
- return;
- }
-
- KUrl loadingUrl(url);
-
- // create convenience fake api:// protocol for KDE apidox search and Qt docs
- if (scheme == QLatin1String("api"))
- {
- QString path;
- QString className = url.host().toLower();
- if (className[0] == 'k')
- {
- path = QString("http://api.kde.org/new.classmapper.php?class=%1").arg(className);
- }
- else if (className[0] == 'q')
- {
- path = QString("http://doc.trolltech.com/4.5/%1.html").arg(className);
- }
- loadingUrl.setUrl(path);
- }
-
- if (loadingUrl.isRelative())
- {
- if(loadingUrl.path().contains('.'))
- {
- QString fn = loadingUrl.url(KUrl::RemoveTrailingSlash);
- loadingUrl.setUrl("//" + fn);
- loadingUrl.setScheme("http");
- }
- else
- {
- scheme = QLatin1String("gg");
- }
- }
-
- // create convenience fake gg:// protocol, waiting for KServices learning
- if(scheme == QLatin1String("gg"))
- {
- QString str = loadingUrl.path();
- loadingUrl.setUrl( QString("http://google.com/search?&q=%1").arg(str) );
- }
-
- // create convenience fake wk:// protocol, waiting for KServices learning
- if(scheme == QLatin1String("wk"))
- {
- QString str = loadingUrl.path();
- loadingUrl.setUrl( QString("http://en.wikipedia.org/wiki/%1").arg(str) );
- }
-
-
- WebView *webView = m_window->newTab();
- m_window->currentUrlBar()->setUrl(loadingUrl.prettyUrl());
-
- switch(type)
- {
- case Rekonq::Default:
- if (!ReKonfig::openTabsBack())
- {
- setCurrentWidget(webView); // this method does NOT take ownership of webView
- }
- break;
- case Rekonq::New:
- m_window->setCurrentWidget(webView); // this method does NOT take ownership of webView
- break;
- case Rekonq::Background:
- break;
- };
-
- if (webView)
- {
- webView->setFocus();
- webView->load(loadingUrl);
- }
-}
-
-
-void RekonqRun::loadUrl(const QString& urlString, const Rekonq::OpenType& type)
-{
- return loadUrl( guessUrlFromString(urlString), type );
-}
-
-
-KUrl RekonqRun::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/rekonqrun.h b/src/rekonqrun.h
deleted file mode 100644
index d5113df1..00000000
--- a/src/rekonqrun.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com>
-*
-*
-* This program is free software; you can redistribute it
-* and/or modify it under the terms of the GNU General
-* Public License as published by the Free Software Foundation;
-* either version 3, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* ============================================================ */
-
-#ifndef REKONQRUN_H
-#define REKONQRUN_H
-
-// KDE Includes
-#include <KUrl>
-
-// Qt Includes
-#include <QtCore/QString>
-#include <QtGui/QWidget>
-
-namespace Rekonq
-{
- /**
- * @short Open link options
- * Different modes of opening new tab
- */
- enum OpenType
- {
- Default, ///< open url according to users settings
- New, ///< open url in new tab and make it current
- Background ///< open url in new tab in background
- };
-}
-
-
-/**
- * RekonqRun is not inherited from KRun or KParts::BrowserRun, as probably expected.
- * We (actually) use this class just to find the REAL url to load (and load it!), so it does
- * these operations:
- *
- * - stop loading malformed urls
- * - find url scheme on relative urls
- * - find right url to load on SearchProviders (Google, Wikipedia, etc.)
- * - handle local urls (launches dolphin)
- * - guess urls from strings
- *
-*/
-
-class RekonqRun : public QObject
-{
- Q_OBJECT
-
-public:
- RekonqRun(QWidget *parent = 0);
- ~RekonqRun();
-
-
-public slots:
-
- void loadUrl( const KUrl& url,
- const Rekonq::OpenType& type = Rekonq::Default
- );
-
- void loadUrl( const QString& urlString,
- const Rekonq::OpenType& type = Rekonq::Default
- );
-
-private:
-
- KUrl guessUrlFromString(const QString &url);
-
- QWidget *m_window;
-};
-
-#endif