From aa9521b0e0f810a9ba94d7f6c7f9100c3f69d862 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 15 Dec 2009 03:29:48 +0100 Subject: First form of protocol handling --- src/CMakeLists.txt | 1 + src/application.cpp | 8 ++-- src/mainview.cpp | 24 +++++----- src/mainwindow.cpp | 24 ---------- src/mainwindow.h | 6 +-- src/protocolhandler.cpp | 101 ++++++++++++++++++++++++++++++++++++++++++ src/protocolhandler.h | 45 +++++++++++++++++++ src/rekonqpage/newtabpage.cpp | 4 +- src/rekonqpage/newtabpage.h | 2 +- src/webpage.cpp | 13 +----- src/webpage.h | 4 ++ 11 files changed, 173 insertions(+), 59 deletions(-) create mode 100644 src/protocolhandler.cpp create mode 100644 src/protocolhandler.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ede49328..c80aedc0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,7 @@ SET( rekonq_KDEINIT_SRCS networkaccessmanager.cpp webinspectordock.cpp walletbar.cpp + protocolhandler.cpp #---------------------------------------- history/autosaver.cpp history/historymanager.cpp diff --git a/src/application.cpp b/src/application.cpp index cacdcb5a..28d998f3 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -100,7 +100,7 @@ int Application::newInstance() mainWindow()->homePage(); break; case 1: // open new tab page - mainWindow()->newTabPage(); + loadUrl( KUrl("about:home") ); break; case 2: // restore session if(sessionManager()->restoreSession()) @@ -279,9 +279,9 @@ void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type) return; } - // loading home pages - if (mainWindow()->newTabPage(loadingUrl)) - return; + /* // loading home pages + if (mainWindow()->newTabPage(loadingUrl)) + return;*/ if (loadingUrl.scheme() == QLatin1String("mailto")) { diff --git a/src/mainview.cpp b/src/mainview.cpp index 9f5b433e..713c171b 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -51,15 +51,15 @@ #include // Qt Includes -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include -#include -#include -#include -#include -#include -#include MainView::MainView(MainWindow *parent) : KTabWidget(parent) @@ -351,18 +351,18 @@ WebTab *MainView::newWebTab(bool focused, bool nearParent) void MainView::newTab() { - WebTab *w = newWebTab(); + WebView *w = newWebTab()->view(); switch(ReKonfig::newTabsBehaviour()) { case 0: // new tab page - if(m_parentWindow->newTabPage()) - break; + w->load( KUrl("about:home") ); + break; case 1: // blank page urlBar()->setUrl(KUrl("")); break; case 2: // homepage - w->view()->load( QUrl(ReKonfig::homePage()) ); + w->load( KUrl(ReKonfig::homePage()) ); break; default: break; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b141401c..a9d014ef 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -45,7 +45,6 @@ #include "webinspectordock.h" #include "urlbar.h" #include "tabbar.h" -#include "newtabpage.h" #include "adblockmanager.h" // Ui Includes @@ -108,7 +107,6 @@ MainWindow::MainWindow() , m_popup( new KPassivePopup(this) ) , m_hidePopup( new QTimer(this) ) , m_ac( new KActionCollection(this) ) - , m_loadingNewTabPage(false) { // enable window size "auto-save" setAutoSaveSettings(); @@ -1164,25 +1162,3 @@ void MainWindow::openActionUrl(QAction *action) } } - - -bool MainWindow::newTabPage(const KUrl &url) -{ - if(m_loadingNewTabPage) - return false; - - if ( url == KUrl("about:closedTabs") - || url == KUrl("about:history") - || url == KUrl("about:bookmarks") - || url == KUrl("about:favorites") - || url == KUrl("about:home") - ) - { - m_loadingNewTabPage = true; - NewTabPage p(currentTab()->page()); - p.generate(url); - m_loadingNewTabPage = false; - return true; - } - return false; -} diff --git a/src/mainwindow.h b/src/mainwindow.h index 5360d264..95964e22 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -71,9 +71,7 @@ public: QAction *actionByName(const QString name); virtual QSize sizeHint() const; virtual KActionCollection *actionCollection () const; - - bool newTabPage(const KUrl &url = KUrl("about:home")); - + private: void setupActions(); void setupTools(); @@ -178,8 +176,6 @@ private: QTimer *m_hidePopup; KActionCollection *m_ac; - - bool m_loadingNewTabPage; }; #endif // MAINWINDOW_H diff --git a/src/protocolhandler.cpp b/src/protocolhandler.cpp new file mode 100644 index 00000000..fb01b266 --- /dev/null +++ b/src/protocolhandler.cpp @@ -0,0 +1,101 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* 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 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + +// Self Includes +#include "protocolhandler.h" + +// Local Includes +#include "newtabpage.h" + +// KDE Includes +#include +#include +#include + +// Qt Includes +#include +#include +#include + + +ProtocolHandler::ProtocolHandler() +{ +} + + +ProtocolHandler::~ProtocolHandler() +{ +} + + +bool ProtocolHandler::handle(const QNetworkRequest &request, QWebFrame *frame) +{ + KUrl url( request.url() ); + + // mailto handling + if ( url.protocol() == QLatin1String("mailto") ) + { + KToolInvocation::invokeMailer(url); + return true; + } + + if ( url.protocol() == QLatin1String("about") ) + { + if( url == KUrl("about:closedTabs") + || url == KUrl("about:history") + || url == KUrl("about:bookmarks") + || url == KUrl("about:favorites") + || url == KUrl("about:home") + ) + { + NewTabPage p(frame); + p.generate(url); + + return true; + } + } + + // "ftp" handling + if(url.protocol() == QLatin1String("ftp")) + { + KUrl::List list; + list.append(url); + KRun::run("dolphin %u",url,0); + + return true; + } + + // "file" handling + if(url.protocol() == QLatin1String("file")) + { + KUrl::List list; + list.append(url); + KRun::run("dolphin %u",url,0); + + return true; + } + + return false; +} diff --git a/src/protocolhandler.h b/src/protocolhandler.h new file mode 100644 index 00000000..b857f27b --- /dev/null +++ b/src/protocolhandler.h @@ -0,0 +1,45 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2009 by Andrea Diamantini +* +* 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 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + + +#ifndef PROTOCOL_HANDLER_H +#define PROTOCOL_HANDLER_H + + +class QNetworkRequest; +class QWebFrame; + + +class ProtocolHandler +{ + +public: + ProtocolHandler(); + ~ProtocolHandler(); + + bool handle(const QNetworkRequest &request, QWebFrame *frame); +}; + +#endif // PROTOCOL_HANDLER_H diff --git a/src/rekonqpage/newtabpage.cpp b/src/rekonqpage/newtabpage.cpp index a1b20ac0..66f74b86 100644 --- a/src/rekonqpage/newtabpage.cpp +++ b/src/rekonqpage/newtabpage.cpp @@ -48,8 +48,8 @@ #include -NewTabPage::NewTabPage(WebPage *page) - : m_root(page->mainFrame()->documentElement()) +NewTabPage::NewTabPage(QWebFrame *frame) + : m_root(frame->documentElement()) { QString htmlFilePath = KStandardDirs::locate("data", "rekonq/htmls/home.html"); diff --git a/src/rekonqpage/newtabpage.h b/src/rekonqpage/newtabpage.h index 62baf79e..003aa84e 100644 --- a/src/rekonqpage/newtabpage.h +++ b/src/rekonqpage/newtabpage.h @@ -47,7 +47,7 @@ class NewTabPage { public: - NewTabPage(WebPage *page); + NewTabPage(QWebFrame *frame); ~NewTabPage(); /** diff --git a/src/webpage.cpp b/src/webpage.cpp index 3fc0aac4..accf0e44 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -100,18 +100,9 @@ bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &r return false; } - if (request.url().scheme() == QLatin1String("mailto")) - { - KToolInvocation::invokeMailer(request.url()); + if(m_protHandler.handle(request,frame)) return false; - } - - if (request.url().scheme() == QLatin1String("about")) - { - Application::instance()->mainWindow()->newTabPage( request.url() ); - return true; - } - + m_requestedUrl = request.url(); return KWebPage::acceptNavigationRequest(frame, request, type); diff --git a/src/webpage.h b/src/webpage.h index 79d8e8e7..c76eaea3 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -32,6 +32,9 @@ #define WEBPAGE_H +// Local Includes +#include "protocolhandler.h" + // KDE Includes #include @@ -71,6 +74,7 @@ private: QString errorPage(QNetworkReply *); QUrl m_requestedUrl; + ProtocolHandler m_protHandler; }; #endif -- cgit v1.2.1