sweeper.cpp 5.2 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
#include <kaction.h>
Aaron J. Seigo's avatar
Aaron J. Seigo committed
26
#include <kstandardaction.h>
27
#include <kconfig.h>
28
#include <kdebug.h>
Frans Englich's avatar
 
Frans Englich committed
29
#include <klocale.h>
30
#include <kmessagebox.h>
31
#include <QtDBus/QtDBus>
Laurent Montel's avatar
Port++  
Laurent Montel committed
32
#include <kactioncollection.h>
33
#include <KSharedConfig>
34

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

44
   QTreeWidget *sw = ui.privacyListView;
45

Aaron J. Seigo's avatar
Aaron J. Seigo committed
46
   KStandardAction::quit(this, SLOT(close()), actionCollection());
47

48
   createGUI(QLatin1String( "sweeperui.rc" ));
49

50 51
   setAutoSaveSettings();

52 53 54 55
   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);
56

57 58
   generalCLI->setExpanded(true);
   webbrowsingCLI->setExpanded(true);
59

60
   this->InitActions();
61 62


63 64 65
   connect(ui.cleanupButton, SIGNAL(clicked()), SLOT(cleanup()));
   connect(ui.selectAllButton, SIGNAL(clicked()), SLOT(selectAll()));
   connect(ui.selectNoneButton, SIGNAL(clicked()), SLOT(selectNone()));
66

Laurent Montel's avatar
Laurent Montel committed
67
   new KsweeperAdaptor(this);
68
   QDBusConnection::sessionBus().registerObject(QLatin1String( "/ksweeper" ), this);
69 70

   load();
71 72 73 74 75

   if(automatic) {
      cleanup();
      close();
   }
Dirk Mueller's avatar
Dirk Mueller committed
76
}
77 78


79
Sweeper::~Sweeper()
80
{
81
   save();
82 83 84
}


85
void Sweeper::load()
86
{
87
   QLinkedList<PrivacyAction*>::iterator itr;
88

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

94
void Sweeper::save()
95
{
96
   QLinkedList<PrivacyAction*>::iterator itr;
97

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

102
   m_privacyConfGroup.sync();
103 104
}

105
void Sweeper::selectAll()
Ralf Hoelzer's avatar
Ralf Hoelzer committed
106
{
107
   QLinkedList<PrivacyAction*>::iterator itr;
108

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

Ralf Hoelzer's avatar
Ralf Hoelzer committed
113 114
}

115
void Sweeper::selectNone()
Ralf Hoelzer's avatar
Ralf Hoelzer committed
116
{
117
   QLinkedList<PrivacyAction*>::iterator itr;
118

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

Ralf Hoelzer's avatar
Ralf Hoelzer committed
123 124 125
}


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

134 135
   ui.statusTextEdit->clear();
   ui.statusTextEdit->setText(i18n("Starting cleanup..."));
136

137
   QLinkedList<PrivacyAction*>::iterator itr;
138

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

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

152
   ui.statusTextEdit->append(i18n("Clean up finished."));
153 154
}

155
void Sweeper::InitActions() {
156
    // store all entries in a list for easy access later on
157 158
   checklist.append(new ClearSavedClipboardContentsAction(generalCLI));
   checklist.append(new ClearRecentDocumentsAction(generalCLI));
Laurent Montel's avatar
Laurent Montel committed
159
#ifdef Q_WS_X11
160
   checklist.append(new ClearRunCommandHistoryAction(generalCLI));
161
   checklist.append( new ClearRecentApplicationAction( generalCLI ) );
Laurent Montel's avatar
Laurent Montel committed
162
#endif
163
   checklist.append(new ClearThumbnailsAction(generalCLI));
164

165 166 167 168 169 170
   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));
171

172
   ui.privacyListView->resizeColumnToContents(0);
173 174
}

175
#include "sweeper.moc"
176

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