1/**
2 * kprivacymanager.cpp
3 *
4 * Copyright (c) 2003 Ralf Hoelzer <ralf@well.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#include "privacyfunctions.h"
22
23#include <ktoolinvocation.h>
24#include <kconfig.h>
25#include <kglobal.h>
26#include <kdebug.h>
27#include <krecentdocument.h>
28#include <kstandarddirs.h>
29#include <kbookmarkmanager.h>
30#include <klocale.h>
31#include <QtDBus/QtDBus>
32
33#include <qstringlist.h>
34#include <QFile>
35#include <QDir>
36#include <kconfiggroup.h>
37#include <QProcess>
38#include <QLatin1String>
39
40bool ClearThumbnailsAction::action()
41{
42 // http://freedesktop.org/Standards/Home
43 // http://triq.net/~jens/thumbnail-spec/index.html
44
45 QDir thumbnailDir( QDir::homePath() + QLatin1String( "/.thumbnails/normal" ));
46 thumbnailDir.setFilter( QDir::Files );
47 const QStringList entries = thumbnailDir.entryList();
48 for( QStringList::const_iterator it = entries.begin() ; it != entries.end() ; ++it) {
49 if(!thumbnailDir.remove(*it)) {
50 errMsg = i18n("A thumbnail could not be removed.");
51 return false;
52 }
53 }
54
55 thumbnailDir.setPath(QDir::homePath() + QLatin1String( "/.thumbnails/large" ));
56 const QStringList entries2 = thumbnailDir.entryList();
57 for( QStringList::const_iterator it = entries2.begin() ; it != entries2.end() ; ++it) {
58 if(!thumbnailDir.remove(*it)) {
59 errMsg = i18n("A thumbnail could not be removed.");
60 return false;
61 }
62 }
63
64 thumbnailDir.setPath(QDir::homePath() + QLatin1String( "/.thumbnails/fail" ));
65 const QStringList entries3 = thumbnailDir.entryList();
66 for( QStringList::const_iterator it = entries3.begin() ; it != entries3.end() ; ++it) {
67 if(!thumbnailDir.remove(*it)) {
68 errMsg = i18n("A thumbnail could not be removed.");
69 return false;
70 }
71 }
72
73 return true;
74}
75
76bool ClearRunCommandHistoryAction::action()
77{
78 QDBusInterface krunner(QLatin1String( "org.kde.krunner" ), QLatin1String( "/App" ), QLatin1String( "org.kde.krunner.App" ));
79 QDBusReply<void> reply = krunner.call(QLatin1String( "clearHistory" ));
80 return reply.isValid();
81}
82
83bool ClearAllCookiesAction::action()
84{
85 QDBusInterface mediamanager(QLatin1String( "org.kde.kded" ), QLatin1String( "/modules/kcookiejar" ), QLatin1String( "org.kde.KCookieServer" ));
86 QDBusReply<void> reply = mediamanager.call(QLatin1String( "deleteAllCookies" ));
87 return reply.isValid();
88}
89
90bool ClearAllCookiesPoliciesAction::action()
91{
92 // load the config file and section
93 KConfig cfg(QLatin1String( "kcookiejarrc" ));
94 KConfigGroup group = cfg.group("Cookie Policy");
95
96 kDebug() << "removing all saved cookie policies" ;
97 group.deleteEntry("CookieDomainAdvice");
98 cfg.sync();
99
100 // inform the cookie jar we pillaged it
101 QDBusInterface kcookiejar(QLatin1String( "org.kde.kded" ), QLatin1String( "/modules/kcookiejar" ), QLatin1String( "org.kde.KCookieServer" ));
102 QDBusReply<void> reply = kcookiejar.call(QLatin1String( "reloadPolicy" ));
103
104 return reply.isValid();
105}
106
107bool ClearSavedClipboardContentsAction::action()
108{
109 if(!QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String( "org.kde.klipper" ))) {
110 KConfig *c = new KConfig(QLatin1String( "klipperrc" ), KConfig::NoGlobals);
111 KConfigGroup group(c, "General");
112 group.deleteEntry("ClipboardData");
113 c->sync();
114
115 delete c;
116 return true;
117 }
118 QDBusInterface klipper(QLatin1String( "org.kde.klipper" ), QLatin1String( "/klipper" ), QLatin1String( "org.kde.klipper.klipper" ));
119 QDBusReply<void> reply = klipper.call(QLatin1String( "clearClipboardHistory" ));
120 return reply.isValid();
121}
122
123bool ClearFormCompletionAction::action()
124{
125 bool status;
126
127 // try to delete the file, if it exists
128 QFile completionFile(KStandardDirs::locateLocal("data", QLatin1String( "khtml/formcompletions" )));
129 (completionFile.exists() ? status = completionFile.remove() : status = true);
130
131 if (!status) {
132 errMsg = i18n("The file exists but could not be removed.");
133 }
134
135 return status;
136}
137
138bool ClearWebCacheAction::action()
139{
140 QStringList lst;
141 lst << QLatin1String( "--clear-all" );
142 return QProcess::startDetached(KStandardDirs::findExe(QLatin1String( "kio_http_cache_cleaner" )),lst);
143}
144
145bool ClearRecentDocumentsAction::action()
146{
147 KRecentDocument::clear();
148 return KRecentDocument::recentDocuments().isEmpty();
149}
150
151bool ClearWebHistoryAction::action()
152{
153 // Clear the history from the memory of the running konquerors
154 QDBusMessage message = QDBusMessage::createSignal(QLatin1String( "/KonqHistoryManager" ), QLatin1String( "org.kde.Konqueror.HistoryManager" ), QLatin1String( "notifyClear" ) );
155 (void) QDBusConnection::sessionBus().send(message);
156
157 // Delete the file
158 const QString file = KStandardDirs::locateLocal("data", QLatin1String("konqueror/konq_history"));
159 QFile::remove(file);
160
161 const QDBusMessage message2 = QDBusMessage::createSignal(QLatin1String( "/KonqUndoManager" ), QLatin1String( "org.kde.Konqueror.UndoManager" ), QLatin1String( "notifyRemove" ) );
162 (void) QDBusConnection::sessionBus().send(message2);
163
164 // Delete the file
165 const QString file2 = KStandardDirs::locateLocal("data", QLatin1String("konqueror/closeditems_saved"));
166 QFile::remove(file2);
167 return true;
168}
169
170bool ClearFaviconsAction::action()
171{
172 QDir favIconDir(KGlobal::dirs()->saveLocation( "cache", QLatin1String( "favicons/" ) ));
173 QStringList saveTheseFavicons;
174 KBookmarkManager* konqiBookmarkMgr;
175
176 konqiBookmarkMgr =
177 KBookmarkManager::managerForFile(KStandardDirs::locateLocal("data",
178 QLatin1String("konqueror/bookmarks.xml")), QLatin1String( "konqueror" ));
179 kDebug() << "saving the favicons that are in konqueror bookmarks" ;
180 kDebug() << "opened konqueror bookmarks at " << konqiBookmarkMgr->path() ;
181
182 // get the entire slew of bookmarks
183 KBookmarkGroup konqiBookmarks = konqiBookmarkMgr->root();
184
185 // walk through the bookmarks, if they have a favicon we should keep it
186 KBookmark bookmark = konqiBookmarks.first();
187
188 while (!bookmark.isNull()) {
189 if ((bookmark.icon()).startsWith(QLatin1String("favicons/"))) {
190 // pick out the name, throw .png on the end, and store the filename
191 QRegExp regex(QLatin1String( "favicons/(.*)" ));
192 regex.indexIn(bookmark.icon(), 0);
193 kDebug() << "will save " << (regex.cap(1) + QLatin1String( ".png" )) ;
194 saveTheseFavicons << (regex.cap(1) + QLatin1String( ".png" ));
195 }
196 bookmark = konqiBookmarks.next(bookmark);
197 }
198
199 favIconDir.setFilter( QDir::Files );
200
201 const QStringList entries = favIconDir.entryList();
202
203 // erase all files in favicon directory...
204 for( QStringList::const_iterator it = entries.begin() ; it != entries.end() ; ++it) {
205 // ...if we're not supposed to save them, of course
206 if (!saveTheseFavicons.contains(*it)) {
207 kDebug() << "removing " << *it ;
208 if(!favIconDir.remove(*it)) {
209 errMsg = i18n("A favicon could not be removed.");
210 return false;
211 }
212 }
213 }
214
215 return true;
216}
217
218bool ClearRecentApplicationAction::action()
219{
220 QDBusMessage message =
221 QDBusMessage::createSignal(QLatin1String( "/kickoff/RecentAppDoc" ), QLatin1String( "org.kde.plasma" ), QLatin1String( "clearRecentDocumentsAndApplications" ));
222 QDBusConnection::sessionBus().send(message);
223
224 return true;
225}
226
227
228// kate: tab-width 3; indent-mode cstyle; replace-tabs true;
229