From 7c981aa978bea7551aec99bc3c68a23cd6c8df00 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Fri, 22 Oct 2010 00:04:47 +0200 Subject: This commit implements the new private browsign mode for rekonq: - it implements a new KAaction in the Application class to trace changes on - stops session management and save it, restoring last visited sites on restoring mormal mode - implements necessary changes to iconmanager, urlbar & application Please, note that the private browsing mode will definitely work just on KDE SC 4.6, cause of the needed changes in kdewebkit to eg handle cookies and so on.. . Hope you like it :) --- src/application.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src/application.cpp') diff --git a/src/application.cpp b/src/application.cpp index 233be527..cadfa50f 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -55,10 +55,12 @@ #include #include #include +#include // Qt Includes #include + QWeakPointer Application::s_adblockManager; QWeakPointer Application::s_bookmarkProvider; QWeakPointer Application::s_historyManager; @@ -66,13 +68,20 @@ QWeakPointer Application::s_iconManager; QWeakPointer Application::s_opensearchManager; QWeakPointer Application::s_sessionManager; + using namespace ThreadWeaver; + 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))); } @@ -575,3 +584,55 @@ bool Application::clearDownloadsHistory() QFile downloadFile(downloadFilePath); return downloadFile.remove(); } + + +void Application::setPrivateBrowsingMode(bool b) +{ +// NOTE +// to let work nicely Private Browsing, we need the following: +// - enable WebKit Private Browsing mode :) +// - treat all cookies as session cookies +// (so that they do not get saved to a persistent storage). Available from KDE SC 4.5.72, see BUG: 250122 +// - favicons (fixed in rekonq 0.5.87) +// - save actual session (to restore it when Private Mode is closed) and stop storing it +// - disable history saving + + QWebSettings *settings = QWebSettings::globalSettings(); + bool isJustEnabled = settings->testAttribute(QWebSettings::PrivateBrowsingEnabled); + if(isJustEnabled == b) + return; // uhm... something goes wrong... + + if (b) + { + QString caption = i18n("Are you sure you want to turn on private browsing?"); + QString text = i18n("%1" + "

rekonq will save your current tabs for when you'll stop private browsing the net..

", caption); + + int button = KMessageBox::warningContinueCancel(mainWindow(), text, caption, KStandardGuiItem::cont(), KStandardGuiItem::cancel(), i18n("don't ask again") ); + if (button != KMessageBox::Continue) + return; + + settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, true); + _privateBrowsingAction->setChecked(true); + + Q_FOREACH(const QWeakPointer &w, m_mainWindows) + { + w.data()->close(); + } + loadUrl( KUrl("about:home"), Rekonq::NewWindow); + } + else + { + Q_FOREACH(const QWeakPointer &w, m_mainWindows) + { + w.data()->close(); + } + + settings->setAttribute(QWebSettings::PrivateBrowsingEnabled, false); + _privateBrowsingAction->setChecked(false); + + loadUrl( KUrl("about:blank"), Rekonq::NewWindow); + if(!sessionManager()->restoreSession()) + loadUrl( KUrl("about:home"), Rekonq::NewWindow); + } +} -- cgit v1.2.1