summaryrefslogtreecommitdiff
path: root/src/application.cpp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-07-24 02:10:05 +0200
committerAndrea Diamantini <adjam7@gmail.com>2009-07-24 02:10:05 +0200
commite3a8092aaaed8b596e762119ee3f165a69ff77c2 (patch)
tree1563bd22ed5dc1e26ce5c3cde5b394e015457695 /src/application.cpp
parentFixing Rekonfig call (diff)
downloadrekonq-e3a8092aaaed8b596e762119ee3f165a69ff77c2.tar.xz
Removed rekonqrun class and provided slots in Application one.
Diffstat (limited to 'src/application.cpp')
-rw-r--r--src/application.cpp107
1 files changed, 101 insertions, 6 deletions
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 );
+}