From 313314b39214c6b6c673d882dfbf3deab91007c0 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 30 Jun 2009 02:17:15 +0200 Subject: Fake gg:// and wk:// protocol. Initial Url && Search Bar (to be improved in 0.3) Trivial cleaning things here and there.. --- src/mainview.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-) (limited to 'src/mainview.cpp') diff --git a/src/mainview.cpp b/src/mainview.cpp index 75154528..f3ccbce2 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -46,6 +46,7 @@ #include #include #include +#include // Qt Includes #include @@ -629,24 +630,71 @@ void MainView::webViewUrlChanged(const QUrl &url) } +// WARNING this method is ready to be refactored with real KServices implementation +// and moved to a RekonqRun class (0.3 target) void MainView::loadUrl(const KUrl &url) { if (url.isEmpty()) return; - currentUrlBar()->setUrl(url.prettyUrl()); + QString scheme = url.scheme(); - WebView *webView = currentWebView(); + 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()) { - QString fn = loadingUrl.url(KUrl::RemoveTrailingSlash); - loadingUrl.setUrl("//" + fn); - loadingUrl.setScheme("http"); + 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/complete/search?output=toolbar&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) ); + } + + currentUrlBar()->setUrl(loadingUrl.prettyUrl()); + + WebView *webView = currentWebView(); + if (webView) { webView->load(loadingUrl); -- cgit v1.2.1