[rekonq] clear private data on close

mark at dinicola.id.au mark at dinicola.id.au
Mon May 31 13:02:23 CEST 2010


Hi everyone,

I love rekonq but I miss Firefox's custom history settings that I use to
clear things when Firefox is closed, so I've quickly whipped something up.
Basically all I did was add a new settings widget and added
Application::clearPrivateData that gets called from
MainWindow::clearPrivateData and Application::~Application. I didn't reuse
the cleardata widget for some reason that I can't remember. Patch is
attached (I'm hoping the mailing list software doesn't strip it out).

Mark
-------------- next part --------------
From 8ee0a69fa3964d90e71fc7c5d20c735e9d18bc4c Mon Sep 17 00:00:00 2001
From: Mark Di Nicola <mark at dinicola.id.au>
Date: Sun, 30 May 2010 22:10:24 +1000
Subject: [PATCH] new settings widget and functionality for clearing private data when rekonq is closed

---
 src/CMakeLists.txt               |    2 +
 src/application.cpp              |   49 ++++++++++++++++
 src/application.h                |    3 +
 src/mainwindow.cpp               |   42 +------------
 src/rekonq.kcfg                  |   18 ++++++
 src/settings/privacywidget.cpp   |   96 ++++++++++++++++++++++++++++++
 src/settings/privacywidget.h     |   58 ++++++++++++++++++
 src/settings/settings_privacy.ui |  119 ++++++++++++++++++++++++++++++++++++++
 src/settings/settingsdialog.cpp  |   14 ++++-
 9 files changed, 360 insertions(+), 41 deletions(-)
 create mode 100644 src/settings/privacywidget.cpp
 create mode 100644 src/settings/privacywidget.h
 create mode 100644 src/settings/settings_privacy.ui

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d0e5721..b7b874f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -42,6 +42,7 @@ SET( rekonq_KDEINIT_SRCS
     settings/tabswidget.cpp
     settings/webkitwidget.cpp
     settings/networkwidget.cpp
+    settings/privacywidget.cpp
     #----------------------------------------
     bookmarks/bookmarksmanager.cpp
     bookmarks/bookmarkspanel.cpp
@@ -71,6 +72,7 @@ KDE4_ADD_UI_FILES( rekonq_KDEINIT_SRCS
     settings/settings_appearance.ui
     settings/settings_webkit.ui
     settings/settings_adblock.ui
+    settings/settings_privacy.ui
     cleardata.ui
  )
 
diff --git a/src/application.cpp b/src/application.cpp
index fb52dc5..05b3c9b 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -53,6 +53,7 @@
 #include <kio/jobclasses.h>
 #include <KUriFilter>
 #include <KMessageBox>
+#include <KProcess>
 #include <KUrl>
 #include <ThreadWeaver/Weaver>
 
@@ -81,6 +82,10 @@ Application::~Application()
     ReKonfig::setRecoverOnCrash(0);
     saveConfiguration();
 
+    clearPrivateData(ReKonfig::clearVisitedPagesHistory(), ReKonfig::clearDownloadsHistory(),
+                     ReKonfig::clearCookies(), ReKonfig::clearCachedWebPages(),
+                     ReKonfig::clearWebsiteIcons(), ReKonfig::clearHomepageThumbs());
+
     foreach(QWeakPointer<MainWindow> window, m_mainWindows)
     {
         delete window.data();
@@ -494,3 +499,47 @@ void Application::updateConfiguration()
 
     defaultSettings = 0;
 }
+
+void Application::clearPrivateData(bool pages, bool downloads, bool cookies,
+                                   bool cache, bool icons, bool thumbs)
+{
+    if (pages)
+    {
+        Application::historyManager()->clear();
+    }
+
+    if (downloads)
+    {
+        Application::historyManager()->clearDownloadsHistory();
+    }
+
+    if (cookies)
+    {
+        QDBusInterface kcookiejar("org.kde.kded", "/modules/kcookiejar", "org.kde.KCookieServer");
+        QDBusReply<void> reply = kcookiejar.call("deleteAllCookies");
+    }
+
+    if (cache)
+    {
+        KProcess::startDetached(KStandardDirs::findExe("kio_http_cache_cleaner"),
+                                QStringList(QL1S("--clear-all")));
+    }
+
+    if (icons)
+    {
+        QWebSettings::clearIconDatabase();
+    }
+
+    if (thumbs)
+    {
+        QString path = KStandardDirs::locateLocal("cache", QString("thumbs/rekonq"), true);
+        path.remove("rekonq");
+        QDir cacheDir(path);
+        QStringList fileList = cacheDir.entryList();
+        foreach(const QString &str, fileList)
+        {
+            QFile file(path + str);
+            file.remove();
+        }
+    }
+}
diff --git a/src/application.h b/src/application.h
index 7b58ab1..807aa4c 100644
--- a/src/application.h
+++ b/src/application.h
@@ -80,6 +80,9 @@ public:
     static SessionManager *sessionManager();
     static AdBlockManager *adblockManager();
 
+    void clearPrivateData(bool pages = true, bool downloads = true, bool cookies = true,
+                          bool cache = true, bool icons = true, bool thumbs = true);
+
 public slots:
     /**
      * Save application's configuration
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index dc29d2e..54a8912 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1212,45 +1212,9 @@ void MainWindow::clearPrivateData()
 
     if (dialog->result() == QDialog::Accepted)
     {
-        if (clearWidget.clearHistory->isChecked())
-        {
-            Application::historyManager()->clear();
-        }
-
-        if (clearWidget.clearDownloads->isChecked())
-        {
-            Application::historyManager()->clearDownloadsHistory();
-        }
-
-        if (clearWidget.clearCookies->isChecked())
-        {
-            QDBusInterface kcookiejar("org.kde.kded", "/modules/kcookiejar", "org.kde.KCookieServer");
-            QDBusReply<void> reply = kcookiejar.call("deleteAllCookies");
-        }
-
-        if (clearWidget.clearCachedPages->isChecked())
-        {
-            KProcess::startDetached(KStandardDirs::findExe("kio_http_cache_cleaner"),
-                                    QStringList(QL1S("--clear-all")));
-        }
-
-        if (clearWidget.clearWebIcons->isChecked())
-        {
-            QWebSettings::clearIconDatabase();
-        }
-
-        if (clearWidget.homePageThumbs->isChecked())
-        {
-            QString path = KStandardDirs::locateLocal("cache", QString("thumbs/rekonq"), true);
-            path.remove("rekonq");
-            QDir cacheDir(path);
-            QStringList fileList = cacheDir.entryList();
-            foreach(const QString &str, fileList)
-            {
-                QFile file(path + str);
-                file.remove();
-            }
-        }
+        Application::instance()->clearPrivateData(clearWidget.clearHistory->isChecked(), clearWidget.clearDownloads->isChecked(),
+                                                  clearWidget.clearCookies->isChecked(), clearWidget.clearCachedPages->isChecked(),
+                                                  clearWidget.clearWebIcons->isChecked(), clearWidget.homePageThumbs->isChecked());
     }
 
     dialog->deleteLater();
diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg
index b934c6d..f84cc61 100644
--- a/src/rekonq.kcfg
+++ b/src/rekonq.kcfg
@@ -133,6 +133,24 @@
     <entry name="expireHistory" type="Int">
         <default>1</default>
     </entry>
+    <entry name="clearVisitedPagesHistory" type="Bool">
+        <default>false</default>
+    </entry>
+    <entry name="clearDownloadsHistory" type="Bool">
+        <default>false</default>
+    </entry>
+    <entry name="clearCookies" type="Bool">
+        <default>false</default>
+    </entry>
+    <entry name="clearCachedWebPages" type="Bool">
+        <default>false</default>
+    </entry>
+    <entry name="clearWebsiteIcons" type="Bool">
+        <default>false</default>
+    </entry>
+    <entry name="clearHomepageThumbs" type="Bool">
+        <default>false</default>
+    </entry>
 </group>
 
 
diff --git a/src/settings/privacywidget.cpp b/src/settings/privacywidget.cpp
new file mode 100644
index 0000000..94ff078
--- /dev/null
+++ b/src/settings/privacywidget.cpp
@@ -0,0 +1,96 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2010 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/>.
+*
+* ============================================================ */
+
+
+// Local Includes
+#include "privacywidget.h"
+#include "privacywidget.moc"
+
+// Auto Includes
+#include "rekonq.h"
+
+PrivacyWidget::PrivacyWidget(QWidget *parent)
+        : QWidget(parent)
+        , _changed(false)
+{
+    setupUi(this);
+
+    load();
+
+    connect(checkPagesHistory, SIGNAL(stateChanged(int)),   this, SLOT(hasChanged()));
+    connect(checkDownloadsHistory, SIGNAL(stateChanged(int)),   this, SLOT(hasChanged()));
+    connect(checkCookies, SIGNAL(stateChanged(int)),   this, SLOT(hasChanged()));
+    connect(checkCache, SIGNAL(stateChanged(int)),   this, SLOT(hasChanged()));
+    connect(checkIcons, SIGNAL(stateChanged(int)),   this, SLOT(hasChanged()));
+    connect(checkThumbs, SIGNAL(stateChanged(int)),   this, SLOT(hasChanged()));
+}
+
+void PrivacyWidget::load()
+{
+    bool clearVisitedPagesHistory = ReKonfig::clearVisitedPagesHistory();
+    checkPagesHistory->setChecked(clearVisitedPagesHistory);
+
+    bool clearDownloadsHistory = ReKonfig::clearDownloadsHistory();
+    checkDownloadsHistory->setChecked(clearDownloadsHistory);
+
+    bool clearCookies = ReKonfig::clearCookies();
+    checkCookies->setChecked(clearCookies);
+
+    bool clearCachedWebPages = ReKonfig::clearCachedWebPages();
+    checkCache->setChecked(clearCachedWebPages);
+
+    bool clearWebsiteIcons = ReKonfig::clearWebsiteIcons();
+    checkIcons->setChecked(clearWebsiteIcons);
+
+    bool clearHomepageThumbs = ReKonfig::clearHomepageThumbs();
+    checkThumbs->setChecked(clearHomepageThumbs);
+}
+
+void PrivacyWidget::save()
+{
+    ReKonfig::setClearVisitedPagesHistory(checkPagesHistory->isChecked());
+    ReKonfig::setClearDownloadsHistory(checkDownloadsHistory->isChecked());
+    ReKonfig::setClearCookies(checkCookies->isChecked());
+    ReKonfig::setClearCachedWebPages(checkCache->isChecked());
+    ReKonfig::setClearWebsiteIcons(checkIcons->isChecked());
+    ReKonfig::setClearHomepageThumbs(checkThumbs->isChecked());
+
+    _changed = false;
+    emit changed(false);
+
+}
+
+
+bool PrivacyWidget::changed()
+{
+    return _changed;
+}
+
+
+void PrivacyWidget::hasChanged()
+{
+    _changed = true;
+    emit changed(true);
+}
diff --git a/src/settings/privacywidget.h b/src/settings/privacywidget.h
new file mode 100644
index 0000000..51be54d
--- /dev/null
+++ b/src/settings/privacywidget.h
@@ -0,0 +1,58 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2010 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 PRIVACYWIDGET_H
+#define PRIVACYWIDGET_H
+
+// Ui Includes
+#include "ui_settings_privacy.h"
+
+// Qt Includes
+#include <QtGui/QWidget>
+
+
+class PrivacyWidget : public QWidget, private Ui::privacy
+{
+    Q_OBJECT
+
+public:
+    PrivacyWidget(QWidget *parent = 0);
+
+    void save();
+    bool changed();
+
+signals:
+    void changed(bool);
+
+private slots:
+    void hasChanged();
+
+private:
+    void load();
+
+    bool _changed;
+};
+
+#endif // PRIVACYWIDGET_H
diff --git a/src/settings/settings_privacy.ui b/src/settings/settings_privacy.ui
new file mode 100644
index 0000000..e6372aa
--- /dev/null
+++ b/src/settings/settings_privacy.ui
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>privacy</class>
+ <widget class="QWidget" name="privacy">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string>Privacy Settings</string>
+     </property>
+     <widget class="QLabel" name="label">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>30</y>
+        <width>281</width>
+        <height>17</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>When closing rekonq, automatically clear:</string>
+      </property>
+     </widget>
+     <widget class="QCheckBox" name="checkPagesHistory">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>50</y>
+        <width>171</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Visited pages history</string>
+      </property>
+     </widget>
+     <widget class="QCheckBox" name="checkDownloadsHistory">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>80</y>
+        <width>151</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Downloads history</string>
+      </property>
+     </widget>
+     <widget class="QCheckBox" name="checkCookies">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>110</y>
+        <width>81</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Cookies</string>
+      </property>
+     </widget>
+     <widget class="QCheckBox" name="checkCache">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>140</y>
+        <width>151</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Cached web pages</string>
+      </property>
+     </widget>
+     <widget class="QCheckBox" name="checkIcons">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>170</y>
+        <width>121</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Website icons</string>
+      </property>
+     </widget>
+     <widget class="QCheckBox" name="checkThumbs">
+      <property name="geometry">
+       <rect>
+        <x>20</x>
+        <y>200</y>
+        <width>151</width>
+        <height>23</height>
+       </rect>
+      </property>
+      <property name="text">
+       <string>Homepage thumbs</string>
+      </property>
+     </widget>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/settings/settingsdialog.cpp b/src/settings/settingsdialog.cpp
index 27d4046..54eae17 100644
--- a/src/settings/settingsdialog.cpp
+++ b/src/settings/settingsdialog.cpp
@@ -45,6 +45,7 @@
 #include "appearancewidget.h"
 #include "webkitwidget.h"
 #include "tabswidget.h"
+#include "privacywidget.h"
 
 // KDE Includes
 #include <KConfig>
@@ -70,6 +71,7 @@ private:
     WebKitWidget *webkitWidg;
     NetworkWidget *networkWidg;
     AdBlockWidget *adBlockWidg;
+    PrivacyWidget *privacyWidg;
     
     KCModuleProxy *ebrowsingModule;
 
@@ -132,7 +134,12 @@ Private::Private(SettingsDialog *parent)
     pageItem = parent->addPage(ebrowsingModule, i18n(ebrowsingInfo.moduleName().toLocal8Bit()));
     pageItem->setIcon(KIcon(ebrowsingInfo.icon()));
 
-    // WARNING 
+    // -- 6
+    privacyWidg = new PrivacyWidget(parent);
+    privacyWidg->layout()->setMargin(0);
+    pageItem = parent->addPage(privacyWidg , i18n("Privacy"));
+
+    // WARNING
     // remember wheh changing here that the smallest netbooks
     // have a 1024x576 resolution. So DON'T bother that limits!!
     parent->setMinimumSize(700, 525);
@@ -161,6 +168,7 @@ SettingsDialog::SettingsDialog(QWidget *parent)
     connect(d->adBlockWidg,     SIGNAL(changed(bool)), this, SLOT(updateButtons()));
     connect(d->ebrowsingModule, SIGNAL(changed(bool)), this, SLOT(updateButtons()));
     connect(d->shortcutsEditor, SIGNAL(keyChange()),   this, SLOT(updateButtons()));
+    connect(d->privacyWidg,     SIGNAL(changed(bool)), this, SLOT(updateButtons()));
 
     // save settings
     connect(this, SIGNAL(applyClicked()), this, SLOT(saveSettings()));
@@ -196,6 +204,7 @@ void SettingsDialog::saveSettings()
     d->adBlockWidg->save();
     d->shortcutsEditor->save();
     d->ebrowsingModule->save();
+    d->privacyWidg->save();
     
     SearchEngine::loadDefaultWS();
     SearchEngine::loadDelimiter();
@@ -216,6 +225,7 @@ bool SettingsDialog::hasChanged()
            || d->networkWidg->changed()
            || d->adBlockWidg->changed()
            || d->ebrowsingModule->changed()
-           || d->shortcutsEditor->isModified();
+           || d->shortcutsEditor->isModified()
+           || d->privacyWidg->changed();
     ;
 }
-- 
1.7.0.4


More information about the rekonq mailing list