sweeper.cpp 5.24 KB
Newer Older
1
/**
2
  * Copyright (c) 2003-2005 Ralf Hoelzer <ralf@well.com>
3 4 5 6 7 8 9 10 11 12 13 14 15
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU Lesser General Public License as published
  *  by the Free Software Foundation; either version 2.1 of the License, or
  *  (at your option) any later version.
  *
  *  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 Lesser General Public License for more details.
  *
  *  You should have received a copy of the GNU Lesser General Public License
  *  along with this program; if not, write to the Free Software
Dirk Mueller's avatar
Dirk Mueller committed
16
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 18
  */

19
#include "sweeper.h"
Pino Toscano's avatar
Pino Toscano committed
20 21 22

#include "privacyaction.h"
#include "privacyfunctions.h"
23 24
#include "sweeperadaptor.h"

25 26 27
#include <KActionCollection>
#include <KConfig>
#include <KMessageBox>
28
#include <KSharedConfig>
29
#include <KStandardAction>
30
#include <QDBusConnection>
31

32
Sweeper::Sweeper(bool automatic)
Laurent Montel's avatar
Laurent Montel committed
33
   : KXmlGuiWindow(0)
34
   , m_privacyConfGroup(KSharedConfig::openConfig(QStringLiteral("kprivacyrc"), KConfig::NoGlobals), "Cleaning")
35
   , m_automatic(automatic)
36
{
37 38 39
   QWidget *mainWidget = new QWidget(this);
   ui.setupUi(mainWidget);
   setCentralWidget(mainWidget);
40

41
   QTreeWidget *sw = ui.privacyListView;
42

43
   KStandardAction::quit(this, &Sweeper::close, actionCollection());
44

45
   createGUI(QStringLiteral("sweeperui.rc"));
46

47 48
   setAutoSaveSettings();

49 50 51 52
   generalCLI     = new QTreeWidgetItem(QStringList() << i18nc("General system content", "General"));
   sw->addTopLevelItem(generalCLI);
   webbrowsingCLI = new QTreeWidgetItem(QStringList() << i18nc("Web browsing content", "Web Browsing"));
   sw->addTopLevelItem(webbrowsingCLI);
53

54 55
   generalCLI->setExpanded(true);
   webbrowsingCLI->setExpanded(true);
56

57
   this->InitActions();
58 59


60 61 62
   connect(ui.cleanupButton, &QPushButton::clicked, this, &Sweeper::cleanup);
   connect(ui.selectAllButton, &QPushButton::clicked, this, &Sweeper::selectAll);
   connect(ui.selectNoneButton, &QPushButton::clicked, this, &Sweeper::selectNone);
63

Laurent Montel's avatar
Laurent Montel committed
64
   new KsweeperAdaptor(this);
65
   QDBusConnection::sessionBus().registerObject(QStringLiteral("/ksweeper"), this);
66 67

   load();
68 69 70 71 72

   if(automatic) {
      cleanup();
      close();
   }
Dirk Mueller's avatar
Dirk Mueller committed
73
}
74 75


76
Sweeper::~Sweeper()
77
{
78
   save();
79 80 81
}


82
void Sweeper::load()
83
{
84
   QLinkedList<PrivacyAction*>::iterator itr;
85

86
   for (itr = checklist.begin(); itr != checklist.end(); ++itr) {
87
      (*itr)->setCheckState(0, m_privacyConfGroup.readEntry((*itr)->configKey(), true) ? Qt::Checked : Qt::Unchecked);
88
   }
89 90
}

91
void Sweeper::save()
92
{
93
   QLinkedList<PrivacyAction*>::iterator itr;
94

95
   for (itr = checklist.begin(); itr != checklist.end(); ++itr) {
96
      m_privacyConfGroup.writeEntry((*itr)->configKey(), (*itr)->checkState(0) == Qt::Checked);
97
   }
98

99
   m_privacyConfGroup.sync();
100 101
}

102
void Sweeper::selectAll()
Ralf Hoelzer's avatar
Ralf Hoelzer committed
103
{
104
   QLinkedList<PrivacyAction*>::iterator itr;
105

106
   for (itr = checklist.begin(); itr != checklist.end(); ++itr) {
107
      (*itr)->setCheckState(0, Qt::Checked);
108
   }
109

Ralf Hoelzer's avatar
Ralf Hoelzer committed
110 111
}

112
void Sweeper::selectNone()
Ralf Hoelzer's avatar
Ralf Hoelzer committed
113
{
114
   QLinkedList<PrivacyAction*>::iterator itr;
115

116
   for (itr = checklist.begin(); itr != checklist.end(); ++itr) {
117
      (*itr)->setCheckState(0, Qt::Unchecked);
118
   }
119

Ralf Hoelzer's avatar
Ralf Hoelzer committed
120 121 122
}


123
void Sweeper::cleanup()
124
{
125 126 127 128
   if (!m_automatic) {
      if (KMessageBox::warningContinueCancel(this, i18n("You are deleting data that is potentially valuable to you. Are you sure?")) != KMessageBox::Continue) {
         return;
      }
129
   }
130

131 132
   ui.statusTextEdit->clear();
   ui.statusTextEdit->setText(i18n("Starting cleanup..."));
133

134
   QLinkedList<PrivacyAction*>::iterator itr;
135

136
   for (itr = checklist.begin(); itr != checklist.end(); ++itr) {
137 138
      if((*itr)->checkState(0) == Qt::Checked) {
         QString statusText = i18n("Clearing %1...", (*itr)->text(0));
139
         ui.statusTextEdit->append(statusText);
140

141 142
         // actions return whether they were successful
         if(!(*itr)->action()) {
143
            QString errorText =  i18n("Clearing of %1 failed: %2", (*itr)->text(0), (*itr)->getErrMsg());
144
            ui.statusTextEdit->append(errorText);
145 146 147
         }
      }
   }
148

149
   ui.statusTextEdit->append(i18n("Clean up finished."));
150 151
}

152
void Sweeper::InitActions() {
153
    // store all entries in a list for easy access later on
154 155 156
   checklist.append(new ClearSavedClipboardContentsAction(generalCLI));
   checklist.append(new ClearRecentDocumentsAction(generalCLI));
   checklist.append(new ClearRunCommandHistoryAction(generalCLI));
157 158 159
   if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.ActivityManager"))) {
        checklist.append( new ClearRecentApplicationAction( generalCLI ) );
   }
160
   checklist.append(new ClearThumbnailsAction(generalCLI));
161

162 163 164 165 166 167
   checklist.append(new ClearAllCookiesAction(webbrowsingCLI));
   checklist.append(new ClearFaviconsAction(webbrowsingCLI));
   checklist.append(new ClearWebHistoryAction(webbrowsingCLI));
   checklist.append(new ClearWebCacheAction(webbrowsingCLI));
   checklist.append(new ClearFormCompletionAction(webbrowsingCLI));
   checklist.append(new ClearAllCookiesPoliciesAction(webbrowsingCLI));
168

169
   ui.privacyListView->resizeColumnToContents(0);
170 171
}

172
// kate: tab-width 3; indent-mode cstyle; replace-tabs true;