diff options
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/application.cpp | 98 | ||||
-rw-r--r-- | src/application.h | 15 | ||||
-rw-r--r-- | src/filterurljob.cpp | 80 | ||||
-rw-r--r-- | src/filterurljob.h | 65 | ||||
-rw-r--r-- | src/mainview.cpp | 4 | ||||
-rw-r--r-- | src/mainwindow.cpp | 105 | ||||
-rw-r--r-- | src/mainwindow.h | 17 | ||||
-rw-r--r-- | src/rekonq_defines.h | 1 |
9 files changed, 144 insertions, 243 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 518ce571..da9b48c5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,7 +11,6 @@ SET( rekonq_KDEINIT_SRCS clicktoflash.cpp downloaditem.cpp downloadmanager.cpp - filterurljob.cpp findbar.cpp icondownloader.cpp iconmanager.cpp @@ -170,7 +169,6 @@ TARGET_LINK_LIBRARIES ( kdeinit_rekonq ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${KDE4_KPARTS_LIBS} - ${KDE4_THREADWEAVER_LIBRARIES} ) diff --git a/src/application.cpp b/src/application.cpp index 40197d78..bfe5cc09 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -40,7 +40,6 @@ #include "adblockmanager.h" #include "bookmarkmanager.h" #include "downloadmanager.h" -#include "filterurljob.h" #include "historymanager.h" #include "iconmanager.h" #include "mainview.h" @@ -80,9 +79,6 @@ Application::Application() : KUniqueApplication() , _privateBrowsingAction(0) { - connect(Weaver::instance(), SIGNAL(jobDone(ThreadWeaver::Job*)), - this, SLOT(loadResolvedUrl(ThreadWeaver::Job*))); - _privateBrowsingAction = new KAction(KIcon("view-media-artist"), i18n("Private &Browsing"), this); _privateBrowsingAction->setCheckable(true); connect(_privateBrowsingAction, SIGNAL(triggered(bool)), this, SLOT(setPrivateBrowsingMode(bool))); @@ -456,15 +452,16 @@ SyncManager *Application::syncManager() return m_syncManager.data(); } -WebTab* Application::loadUrl(const KUrl& url, QWebHistory* webHistory, const Rekonq::OpenType& type) + +void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type) { if (url.isEmpty()) - return 0; + return; if (!url.isValid()) { KMessageBox::error(0, i18n("Malformed URL:\n%1", url.url(KUrl::RemoveTrailingSlash))); - return 0; + return; } Rekonq::OpenType newType = type; @@ -472,74 +469,23 @@ WebTab* Application::loadUrl(const KUrl& url, QWebHistory* webHistory, const Rek if (url.url().contains("about:") && url.url().contains("/")) newType = Rekonq::CurrentTab; - // first, create the webview(s) to not let hangs UI.. - WebTab *tab = 0; MainWindow *w = 0; - w = (newType == Rekonq::NewWindow) - ? newMainWindow() - : mainWindow(); - - // be SURE window exists - if (!w) - w = newMainWindow(); - - switch (newType) - { - case Rekonq::NewTab: - if (ReKonfig::openLinksInNewWindow()) - { - w = newMainWindow(); - tab = w->mainView()->currentWebTab(); - } - else - { - tab = w->mainView()->newWebTab(!ReKonfig::openNewTabsInBackground()); - } - break; - case Rekonq::NewFocusedTab: - tab = w->mainView()->newWebTab(true); - break; - case Rekonq::NewBackTab: - tab = w->mainView()->newWebTab(false); - break; - case Rekonq::NewWindow: - case Rekonq::CurrentTab: - tab = w->mainView()->currentWebTab(); - break; - }; - - - // rapidly show first loading url.. - int tabIndex = w->mainView()->indexOf(tab); - Q_ASSERT(tabIndex != -1); - UrlBar *barForTab = qobject_cast<UrlBar *>(w->mainView()->widgetBar()->widget(tabIndex)); - barForTab->activateSuggestions(false); - barForTab->setQUrl(url); - - WebView *view = tab->view(); - if (view) + if (newType == Rekonq::NewWindow + || (newType == Rekonq::NewTab && ReKonfig::openLinksInNewWindow())) { - FilterUrlJob *job = new FilterUrlJob(view, url.pathOrUrl(), this); - Weaver::instance()->enqueue(job); + w = newMainWindow(); + newType = Rekonq::CurrentTab; } - - if (webHistory) + else { - QByteArray historyBytes; - QDataStream historyStream(&historyBytes, QIODevice::ReadWrite); - - historyStream << *webHistory; - historyStream.device()->seek(0); - historyStream >> *(view->history()); + w = mainWindow(); } - - return tab; -} + // be SURE window exists + if (!w) + w = newMainWindow(); -void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type) -{ - Q_UNUSED(loadUrl(url, 0, type)); + w->loadCheckedUrl(url, newType); } @@ -582,22 +528,6 @@ AdBlockManager *Application::adblockManager() } -void Application::loadResolvedUrl(ThreadWeaver::Job *job) -{ - FilterUrlJob *threadedJob = static_cast<FilterUrlJob *>(job); - KUrl url = threadedJob->url(); - WebView *view = threadedJob->view(); - - if (view) - { - view->load(url); - } - - // Bye and thanks :) - delete threadedJob; -} - - void Application::newWindow() { loadUrl(KUrl("about:home"), Rekonq::NewWindow); diff --git a/src/application.h b/src/application.h index 5e078756..2fe1499e 100644 --- a/src/application.h +++ b/src/application.h @@ -60,11 +60,6 @@ class WebTab; class KAction; -namespace ThreadWeaver -{ -class Job; -} - typedef QList< QWeakPointer<MainWindow> > MainWindowList; @@ -107,8 +102,6 @@ public: return _privateBrowsingAction; }; - WebTab *loadUrl(const KUrl& url, QWebHistory *webHistory, const Rekonq::OpenType& type = Rekonq::CurrentTab); - public Q_SLOTS: /** * Save application's configuration @@ -117,6 +110,12 @@ public Q_SLOTS: */ void saveConfiguration() const; + /** + * @short load url + * + * @param url The url to load + * @param type the type where loading the url. @see Rekonq::OpenType + */ void loadUrl(const KUrl& url, const Rekonq::OpenType& type = Rekonq::CurrentTab ); @@ -129,8 +128,6 @@ protected: bool eventFilter(QObject *watched, QEvent *event); private Q_SLOTS: - void loadResolvedUrl(ThreadWeaver::Job *); - void updateConfiguration(); // the general place to set private browsing diff --git a/src/filterurljob.cpp b/src/filterurljob.cpp deleted file mode 100644 index ff017a07..00000000 --- a/src/filterurljob.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2010-2011 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 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 <http://www.gnu.org/licenses/>. -* -* ============================================================ */ - - -// Self Includes -#include "filterurljob.h" - -// KDE Includes -#include <KUriFilterData> - - -KUriFilter *FilterUrlJob::s_uriFilter; - - -FilterUrlJob::FilterUrlJob(WebView *view, const QString &urlString, QObject *parent) - : Job(parent) - , _view(view) - , _urlString(urlString) -{ - if (!s_uriFilter) - s_uriFilter = KUriFilter::self(); -} - - -WebView *FilterUrlJob::view() -{ - return _view; -} - - -KUrl FilterUrlJob::url() -{ - return _url; -} - - -void FilterUrlJob::run() -{ - // Bookmarklets handling - if (_urlString.startsWith(QL1S("javascript:"))) - { - _url = KUrl(_urlString); - return; - } - - // 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) - { - QString tempUrlString = data.uri().url(); - _url = KUrl(tempUrlString); - } - else - _url = QUrl::fromUserInput(_urlString); -} diff --git a/src/filterurljob.h b/src/filterurljob.h deleted file mode 100644 index 20cdd394..00000000 --- a/src/filterurljob.h +++ /dev/null @@ -1,65 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2010-2011 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 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 <http://www.gnu.org/licenses/>. -* -* ============================================================ */ - - -#ifndef FILTER_URL_JOB_H -#define FILTER_URL_JOB_H - -// Rekonq Includes -#include "rekonq_defines.h" - -// KDE Includes -#include <KUrl> -#include <ThreadWeaver/Job> - -// Qt Includes -#include <QtCore/QString> - -// Forward Declarations -class WebView; - -class KUriFilter; - - -class REKONQ_TESTS_EXPORT FilterUrlJob : public ThreadWeaver::Job -{ -public: - FilterUrlJob(WebView *view, const QString &urlString, QObject *parent = 0); - - WebView *view(); - KUrl url(); - -protected: - void run(); - -private: - WebView *_view; - QString _urlString; - KUrl _url; - - static KUriFilter *s_uriFilter; -}; - -#endif // FILTER_URL_JOB_H diff --git a/src/mainview.cpp b/src/mainview.cpp index ec838ff4..2da26db7 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -414,9 +414,9 @@ void MainView::cloneTab(int index) return; KUrl url = webTab(index)->url(); - QWebHistory * history = webTab(index)->view()->history(); + QWebHistory* history = webTab(index)->view()->history(); - rApp->loadUrl(url, history, Rekonq::NewTab); + rApp->mainWindow()->loadUrl(url, Rekonq::NewTab, history); } 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); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 789c0c1a..d652a499 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -50,7 +50,10 @@ class WebInspectorPanel; class WebTab; class ZoomBar; +class KUriFilter; + class QWebFrame; +class QWebHistory; class QLabel; @@ -67,6 +70,11 @@ public: MainWindow(); ~MainWindow(); + + static KUriFilter *s_uriFilter; + static KUrl filterUrlToLoad(const KUrl &url); + + inline MainView *mainView() const { return m_view; @@ -82,6 +90,10 @@ public: QString selectedText() const; + void loadCheckedUrl(const KUrl& url, + const Rekonq::OpenType& type = Rekonq::CurrentTab, + QWebHistory *webHistory = 0 + ); private: void setupBookmarksAndToolsShortcuts(); void setupActions(); @@ -90,6 +102,11 @@ private: void setupPanels(); public Q_SLOTS: + void loadUrl(const KUrl& url, + const Rekonq::OpenType& type = Rekonq::CurrentTab, + QWebHistory *webHistory = 0 + ); + void openDownloadsPage(); void homePage(); diff --git a/src/rekonq_defines.h b/src/rekonq_defines.h index 439ee8cc..0a60e658 100644 --- a/src/rekonq_defines.h +++ b/src/rekonq_defines.h @@ -87,7 +87,6 @@ enum OpenType CurrentTab, ///< open url in current tab NewTab, ///< open url according to users settings NewFocusedTab, ///< open url in new tab and focus it - NewBackTab, ///< open url in new tab in background NewWindow ///< open url in new window }; |