summaryrefslogtreecommitdiffstats
path: root/kcontrol/privacy/kprivacymanager.cpp
blob: c52c1b5c4bff30c6d7e4e1e1f030b5502e39eb6d (plain)
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 <ralf@well.com>
 *
 *  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 <tdeapplication.h>
#include <dcopclient.h>
#include <tdeconfig.h>
#include <ksimpleconfig.h>
#include <kprocess.h>
#include <tdeglobal.h>
#include <tdeapplication.h>
#include <kdebug.h>
#include <tderecentdocument.h>
#include <kstandarddirs.h>

#include <tqstringlist.h>
#include <tqfile.h>
#include <tqdir.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

  TQDir thumbnailDir( TQDir::homeDirPath() + "/.thumbnails/normal");
  thumbnailDir.setFilter( TQDir::Files );
  TQStringList entries = thumbnailDir.entryList();
  for( TQStringList::Iterator it = entries.begin() ; it != entries.end() ; ++it)
    if(!thumbnailDir.remove(*it)) m_error = true;
  if(m_error) return m_error;

  thumbnailDir.setPath(TQDir::homeDirPath() + "/.thumbnails/large");
  entries = thumbnailDir.entryList();
  for( TQStringList::Iterator it = entries.begin() ; it != entries.end() ; ++it)
    if(!thumbnailDir.remove(*it)) m_error = true;
  if(m_error) return m_error;

  thumbnailDir.setPath(TQDir::homeDirPath() + "/.thumbnails/fail");
  entries = thumbnailDir.entryList();
  for( TQStringList::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()", TQString("") );
}

bool KPrivacyManager::clearAllCookies() const
{
  return kapp->dcopClient()->send( "kded", "kcookiejar", "deleteAllCookies()", TQString("") );
}

bool KPrivacyManager::clearSavedClipboardContents()
{
  if(!isApplicationRegistered("klipper"))
  {
    TDEConfig *c = new TDEConfig("klipperrc", false, false);

    {
      TDEConfigGroupSaver saver(c, "General");
      c->deleteEntry("ClipboardData");
      c->sync();
    }
    delete c;
    return true;
  }

  return kapp->dcopClient()->send( "klipper", "klipper", "clearClipboardHistory()", TQString("") );
}

bool KPrivacyManager::clearFormCompletion() const
{
  TQFile completionFile(locateLocal("data", "tdehtml/formcompletions"));

  return completionFile.remove();
}

bool KPrivacyManager::clearWebCache() const
{
    TDEProcess process;
    process << "tdeio_http_cache_cleaner" << "--clear-all";
    return process.start(TDEProcess::DontCare);
}

bool KPrivacyManager::clearRecentDocuments() const
{
  TDERecentDocument::clear();
  return TDERecentDocument::recentDocuments().isEmpty();
}

bool KPrivacyManager::clearQuickStartMenu() const
{
  return kapp->dcopClient()->send( "kicker", "kicker", "clearQuickStartMenu()", TQString("") );
}

bool KPrivacyManager::clearWebHistory()
{
  TQStringList args("--preload");

  // preload Konqueror if it is not running
  if(!isApplicationRegistered("konqueror"))
  {
    kdDebug() << "couldn't find Konqueror instance, preloading." << endl;
    kapp->tdeinitExec("konqueror", args, 0,0);
  }

  return kapp->dcopClient()->send( "konqueror*", "KonqHistoryManager",
                                   "notifyClear(TQCString)", TQString("") );
}

bool KPrivacyManager::clearFavIcons()
{
  TQDir favIconDir(TDEGlobal::dirs()->saveLocation( "cache", "favicons/" ));
  favIconDir.setFilter( TQDir::Files );
  
  TQStringList entries = favIconDir.entryList();

  // erase all files in favicon directory
  for( TQStringList::Iterator it = entries.begin() ; it != entries.end() ; ++it)
    if(!favIconDir.remove(*it)) m_error = true;
  return m_error;
}


bool KPrivacyManager::isApplicationRegistered(const TQString &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"