summaryrefslogtreecommitdiff
path: root/src/mainwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mainwindow.cpp')
-rw-r--r--src/mainwindow.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index a14f11f0..f8fab524 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -85,6 +85,8 @@
#include <KParts/BrowserExtension>
#include <KMimeTypeTrader>
+#include <KUriFilterData>
+
// Qt Includes
#include <QtCore/QTimer>
@@ -103,6 +105,9 @@
#include <QTextDocument>
+KUriFilter *MainWindow::s_uriFilter;
+
+
MainWindow::MainWindow()
: KXmlGuiWindow()
, m_view(new MainView(this))
@@ -222,6 +227,9 @@ MainWindow::MainWindow()
// accept d'n'd
setAcceptDrops(true);
+ if (!s_uriFilter)
+ s_uriFilter = KUriFilter::self();
+
// Things that need to be setup after the call to setupGUI() and after ctor call
QTimer::singleShot(1, this, SLOT(postLaunch()));
}
@@ -1589,3 +1597,100 @@ void MainWindow::populateUserAgentMenu()
KMenu *uaMenu = static_cast<KMenu *>(QObject::sender());
rApp->userAgentManager()->populateUAMenuForTabUrl(uaMenu, currentTab());
}
+
+
+void MainWindow::loadUrl(const KUrl& url,
+ const Rekonq::OpenType& type,
+ QWebHistory *webHistory
+ )
+{
+ if (url.isEmpty())
+ return;
+
+ if (!url.isValid())
+ {
+ KMessageBox::error(0, i18n("Malformed URL:\n%1", url.url(KUrl::RemoveTrailingSlash)));
+ return;
+ }
+
+ Rekonq::OpenType newType = type;
+ // Don't open useless tabs or windows for actions in about: pages
+ if (url.url().contains("about:") && url.url().contains("/"))
+ newType = Rekonq::CurrentTab;
+
+ loadCheckedUrl(url, newType, webHistory);
+}
+
+
+void MainWindow::loadCheckedUrl(const KUrl& url, const Rekonq::OpenType& type, QWebHistory *webHistory)
+{
+ // First, calculate url
+ KUrl urlToLoad = filterUrlToLoad(url);
+
+ WebTab *tab = 0;
+ switch (type)
+ {
+ case Rekonq::NewTab:
+ tab = mainView()->newWebTab(!ReKonfig::openNewTabsInBackground());
+ break;
+ case Rekonq::NewFocusedTab:
+ tab = mainView()->newWebTab(true);
+ break;
+ case Rekonq::NewWindow:
+ rApp->loadUrl(url, type);
+ return;
+ case Rekonq::CurrentTab:
+ default:
+ tab = mainView()->currentWebTab();
+ break;
+ };
+
+ // rapidly show first loading url..
+ int tabIndex = mainView()->indexOf(tab);
+ Q_ASSERT(tabIndex != -1);
+ UrlBar *barForTab = qobject_cast<UrlBar *>(mainView()->widgetBar()->widget(tabIndex));
+ barForTab->activateSuggestions(false);
+ barForTab->setQUrl(url);
+
+ WebView *view = tab->view();
+ if (view)
+ {
+ view->load(urlToLoad);
+
+ if (webHistory)
+ {
+ QByteArray historyBytes;
+ QDataStream historyStream(&historyBytes, QIODevice::ReadWrite);
+
+ historyStream << *webHistory;
+ historyStream.device()->seek(0);
+ historyStream >> *(view->history());
+ }
+ }
+}
+
+
+// ------------------------------------------------------------------------------------------
+
+
+KUrl MainWindow::filterUrlToLoad(const KUrl &url)
+{
+ QString urlString = url.pathOrUrl();
+ // Bookmarklets handling
+ if (urlString.startsWith(QL1S("javascript:")))
+ {
+ return KUrl(urlString);
+ }
+
+ // this should let rekonq filtering URI info and supporting
+ // the beautiful KDE web browsing shortcuts
+ KUriFilterData data(urlString);
+ data.setCheckForExecutables(false); // if true, queries like "rekonq" or "dolphin" are considered as executables
+
+ if (s_uriFilter->filterUri(data) && data.uriType() != KUriFilterData::Error)
+ {
+ return data.uri();
+ }
+
+ return QUrl::fromUserInput(urlString);
+}