1 | /** |
2 | * Copyright (c) 2003-2005 Ralf Hoelzer <ralf@well.com> |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU Lesser General Public License as published |
6 | * by the Free Software Foundation; either version 2.1 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public License |
15 | * along with this program; if not, write to the Free Software |
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | */ |
18 | |
19 | #include "sweeper.h" |
20 | |
21 | #include "privacyaction.h" |
22 | #include "privacyfunctions.h" |
23 | #include "sweeperadaptor.h" |
24 | |
25 | #include <kaction.h> |
26 | #include <kstandardaction.h> |
27 | #include <kconfig.h> |
28 | #include <kdebug.h> |
29 | #include <klocale.h> |
30 | #include <kmessagebox.h> |
31 | #include <QtDBus/QtDBus> |
32 | #include <kactioncollection.h> |
33 | |
34 | Sweeper::Sweeper(bool automatic) |
35 | : KXmlGuiWindow(0) |
36 | , m_privacyConfGroup(KSharedConfig::openConfig(QLatin1String( "kprivacyrc" ), KConfig::NoGlobals), "Cleaning" ) |
37 | , m_automatic(automatic) |
38 | { |
39 | QWidget *mainWidget = new QWidget(this); |
40 | ui.setupUi(mainWidget); |
41 | setCentralWidget(mainWidget); |
42 | |
43 | QTreeWidget *sw = ui.privacyListView; |
44 | |
45 | KStandardAction::quit(this, SLOT(close()), actionCollection()); |
46 | |
47 | createGUI(QLatin1String( "sweeperui.rc" )); |
48 | |
49 | setAutoSaveSettings(); |
50 | |
51 | generalCLI = new QTreeWidgetItem(QStringList() << i18nc("General system content" , "General" )); |
52 | sw->addTopLevelItem(generalCLI); |
53 | webbrowsingCLI = new QTreeWidgetItem(QStringList() << i18nc("Web browsing content" , "Web Browsing" )); |
54 | sw->addTopLevelItem(webbrowsingCLI); |
55 | |
56 | generalCLI->setExpanded(true); |
57 | webbrowsingCLI->setExpanded(true); |
58 | |
59 | this->InitActions(); |
60 | |
61 | |
62 | connect(ui.cleanupButton, SIGNAL(clicked()), SLOT(cleanup())); |
63 | connect(ui.selectAllButton, SIGNAL(clicked()), SLOT(selectAll())); |
64 | connect(ui.selectNoneButton, SIGNAL(clicked()), SLOT(selectNone())); |
65 | |
66 | new KsweeperAdaptor(this); |
67 | QDBusConnection::sessionBus().registerObject(QLatin1String( "/ksweeper" ), this); |
68 | |
69 | load(); |
70 | |
71 | if(automatic) { |
72 | cleanup(); |
73 | close(); |
74 | } |
75 | } |
76 | |
77 | |
78 | Sweeper::~Sweeper() |
79 | { |
80 | save(); |
81 | } |
82 | |
83 | |
84 | void Sweeper::load() |
85 | { |
86 | QLinkedList<PrivacyAction*>::iterator itr; |
87 | |
88 | for (itr = checklist.begin(); itr != checklist.end(); ++itr) { |
89 | (*itr)->setCheckState(0, m_privacyConfGroup.readEntry((*itr)->configKey(), true) ? Qt::Checked : Qt::Unchecked); |
90 | } |
91 | } |
92 | |
93 | void Sweeper::save() |
94 | { |
95 | QLinkedList<PrivacyAction*>::iterator itr; |
96 | |
97 | for (itr = checklist.begin(); itr != checklist.end(); ++itr) { |
98 | m_privacyConfGroup.writeEntry((*itr)->configKey(), (*itr)->checkState(0) == Qt::Checked); |
99 | } |
100 | |
101 | m_privacyConfGroup.sync(); |
102 | } |
103 | |
104 | void Sweeper::selectAll() |
105 | { |
106 | QLinkedList<PrivacyAction*>::iterator itr; |
107 | |
108 | for (itr = checklist.begin(); itr != checklist.end(); ++itr) { |
109 | (*itr)->setCheckState(0, Qt::Checked); |
110 | } |
111 | |
112 | } |
113 | |
114 | void Sweeper::selectNone() |
115 | { |
116 | QLinkedList<PrivacyAction*>::iterator itr; |
117 | |
118 | for (itr = checklist.begin(); itr != checklist.end(); ++itr) { |
119 | (*itr)->setCheckState(0, Qt::Unchecked); |
120 | } |
121 | |
122 | } |
123 | |
124 | |
125 | void Sweeper::cleanup() |
126 | { |
127 | if (!m_automatic) { |
128 | if (KMessageBox::warningContinueCancel(this, i18n("You are deleting data that is potentially valuable to you. Are you sure?" )) != KMessageBox::Continue) { |
129 | return; |
130 | } |
131 | } |
132 | |
133 | ui.statusTextEdit->clear(); |
134 | ui.statusTextEdit->setText(i18n("Starting cleanup..." )); |
135 | |
136 | QLinkedList<PrivacyAction*>::iterator itr; |
137 | |
138 | for (itr = checklist.begin(); itr != checklist.end(); ++itr) { |
139 | if((*itr)->checkState(0) == Qt::Checked) { |
140 | QString statusText = i18n("Clearing %1..." , (*itr)->text(0)); |
141 | ui.statusTextEdit->append(statusText); |
142 | |
143 | // actions return whether they were successful |
144 | if(!(*itr)->action()) { |
145 | QString errorText = i18n("Clearing of %1 failed: %2" , (*itr)->text(0), (*itr)->getErrMsg()); |
146 | ui.statusTextEdit->append(errorText); |
147 | } |
148 | } |
149 | } |
150 | |
151 | ui.statusTextEdit->append(i18n("Clean up finished." )); |
152 | } |
153 | |
154 | void Sweeper::InitActions() { |
155 | // store all entries in a list for easy access later on |
156 | checklist.append(new ClearSavedClipboardContentsAction(generalCLI)); |
157 | checklist.append(new ClearRecentDocumentsAction(generalCLI)); |
158 | #ifdef Q_WS_X11 |
159 | checklist.append(new ClearRunCommandHistoryAction(generalCLI)); |
160 | checklist.append( new ClearRecentApplicationAction( generalCLI ) ); |
161 | #endif |
162 | checklist.append(new ClearThumbnailsAction(generalCLI)); |
163 | |
164 | checklist.append(new ClearAllCookiesAction(webbrowsingCLI)); |
165 | checklist.append(new ClearFaviconsAction(webbrowsingCLI)); |
166 | checklist.append(new ClearWebHistoryAction(webbrowsingCLI)); |
167 | checklist.append(new ClearWebCacheAction(webbrowsingCLI)); |
168 | checklist.append(new ClearFormCompletionAction(webbrowsingCLI)); |
169 | checklist.append(new ClearAllCookiesPoliciesAction(webbrowsingCLI)); |
170 | |
171 | ui.privacyListView->resizeColumnToContents(0); |
172 | } |
173 | |
174 | #include "sweeper.moc" |
175 | |
176 | // kate: tab-width 3; indent-mode cstyle; replace-tabs true; |
177 | |