1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
/**
* kprivacymanager.cpp
*
* Copyright (c) 2003 Ralf Hoelzer <[email protected]>
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kprivacymanager.h"
#include <kapplication.h>
#include <dcopclient.h>
#include <kconfig.h>
#include <ksimpleconfig.h>
#include <kprocess.h>
#include <kglobal.h>
#include <kapplication.h>
#include <kdebug.h>
#include <krecentdocument.h>
#include <kstandarddirs.h>
#include <qstringlist.h>
#include <qfile.h>
#include <qdir.h>
KPrivacyManager::KPrivacyManager()
{
if (!kapp->dcopClient()->isAttached())
kapp->dcopClient()->attach();
m_error = false;
}
KPrivacyManager::~KPrivacyManager()
{
}
bool KPrivacyManager::clearThumbnails()
{
// http://freedesktop.org/Standards/Home
// http://triq.net/~jens/thumbnail-spec/index.html
QDir thumbnailDir( QDir::homeDirPath() + "/.thumbnails/normal");
thumbnailDir.setFilter( QDir::Files );
QStringList entries = thumbnailDir.entryList();
for( QStringList::Iterator it = entries.begin() ; it != entries.end() ; ++it)
if(!thumbnailDir.remove(*it)) m_error = true;
if(m_error) return m_error;
thumbnailDir.setPath(QDir::homeDirPath() + "/.thumbnails/large");
entries = thumbnailDir.entryList();
for( QStringList::Iterator it = entries.begin() ; it != entries.end() ; ++it)
if(!thumbnailDir.remove(*it)) m_error = true;
if(m_error) return m_error;
thumbnailDir.setPath(QDir::homeDirPath() + "/.thumbnails/fail");
entries = thumbnailDir.entryList();
for( QStringList::Iterator it = entries.begin() ; it != entries.end() ; ++it)
if(!thumbnailDir.remove(*it)) m_error = true;
return m_error;
}
bool KPrivacyManager::clearRunCommandHistory() const
{
return kapp->dcopClient()->send( "kdesktop", "KDesktopIface", "clearCommandHistory()", "" );
}
bool KPrivacyManager::clearAllCookies() const
{
return kapp->dcopClient()->send( "kded", "kcookiejar", "deleteAllCookies()", "" );
}
bool KPrivacyManager::clearSavedClipboardContents()
{
if(!isApplicationRegistered("klipper"))
{
KConfig *c = new KConfig("klipperrc", false, false);
{
KConfigGroupSaver saver(c, "General");
c->deleteEntry("ClipboardData");
c->sync();
}
delete c;
return true;
}
return kapp->dcopClient()->send( "klipper", "klipper", "clearClipboardHistory()", "" );
}
bool KPrivacyManager::clearFormCompletion() const
{
QFile completionFile(locateLocal("data", "khtml/formcompletions"));
return completionFile.remove();
}
bool KPrivacyManager::clearWebCache() const
{
KProcess process;
process << "kio_http_cache_cleaner" << "--clear-all";
return process.start(KProcess::DontCare);
}
bool KPrivacyManager::clearRecentDocuments() const
{
KRecentDocument::clear();
return KRecentDocument::recentDocuments().isEmpty();
}
bool KPrivacyManager::clearQuickStartMenu() const
{
return kapp->dcopClient()->send( "kicker", "kicker", "clearQuickStartMenu()", "" );
}
bool KPrivacyManager::clearWebHistory()
{
QStringList args("--preload");
// preload Konqueror if it is not running
if(!isApplicationRegistered("konqueror"))
{
kdDebug() << "couldn't find Konqueror instance, preloading." << endl;
kapp->kdeinitExec("konqueror", args, 0,0);
}
return kapp->dcopClient()->send( "konqueror*", "KonqHistoryManager",
"notifyClear(QCString)", "" );
}
bool KPrivacyManager::clearFavIcons()
{
QDir favIconDir(KGlobal::dirs()->saveLocation( "cache", "favicons/" ));
favIconDir.setFilter( QDir::Files );
QStringList entries = favIconDir.entryList();
// erase all files in favicon directory
for( QStringList::Iterator it = entries.begin() ; it != entries.end() ; ++it)
if(!favIconDir.remove(*it)) m_error = true;
return m_error;
}
bool KPrivacyManager::isApplicationRegistered(const QString &appName)
{
QCStringList regApps = kapp->dcopClient()->registeredApplications();
for ( QCStringList::Iterator it = regApps.begin(); it != regApps.end(); ++it )
if((*it).find(appName.latin1()) != -1) return true;
return false;
}
#include "kprivacymanager.moc"
|