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
|
/*
SPDX-FileCopyrightText: 2003-2005 Ralf Hoelzer <ralf@well.com>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "sweeper.h"
#include "privacyaction.h"
#include "privacyfunctions.h"
#include "sweeperadaptor.h"
#include <KActionCollection>
#include <KConfig>
#include <KMessageBox>
#include <KSharedConfig>
#include <KStandardAction>
#include <QDBusConnection>
Sweeper::Sweeper(bool automatic)
: KXmlGuiWindow(nullptr)
, m_generalCLI(new QTreeWidgetItem(QStringList(i18nc("General system content", "General"))))
, m_webbrowsingCLI(new QTreeWidgetItem(QStringList(i18nc("Web browsing content", "Web Browsing"))))
, m_privacyConfGroup(KSharedConfig::openConfig(QStringLiteral("kprivacyrc"), KConfig::NoGlobals), QStringLiteral("Cleaning"))
, m_automatic(automatic)
{
auto mainWidget = new QWidget(this);
ui.setupUi(mainWidget);
setCentralWidget(mainWidget);
QTreeWidget *sw = ui.privacyListView;
KStandardAction::quit(this, &Sweeper::close, actionCollection());
createGUI(QStringLiteral("sweeperui.rc"));
setAutoSaveSettings();
sw->addTopLevelItem(m_generalCLI);
sw->addTopLevelItem(m_webbrowsingCLI);
m_generalCLI->setExpanded(true);
m_webbrowsingCLI->setExpanded(true);
this->InitActions();
connect(ui.cleanupButton, &QPushButton::clicked, this, &Sweeper::cleanup);
connect(ui.selectAllButton, &QPushButton::clicked, this, &Sweeper::selectAll);
connect(ui.selectNoneButton, &QPushButton::clicked, this, &Sweeper::selectNone);
new KsweeperAdaptor(this);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/ksweeper"), this);
load();
if (automatic) {
cleanup();
close();
}
}
Sweeper::~Sweeper()
{
save();
}
void Sweeper::load()
{
for (auto &&act : checklist) {
act->setCheckState(0, m_privacyConfGroup.readEntry(act->configKey(), true) ? Qt::Checked : Qt::Unchecked);
}
}
void Sweeper::save()
{
for (auto &&act : checklist) {
m_privacyConfGroup.writeEntry(act->configKey(), act->checkState(0) == Qt::Checked);
}
m_privacyConfGroup.sync();
}
void Sweeper::selectAll()
{
for (auto &&act : checklist) {
act->setCheckState(0, Qt::Checked);
}
}
void Sweeper::selectNone()
{
for (auto &&act : checklist) {
act->setCheckState(0, Qt::Unchecked);
}
}
void Sweeper::cleanup()
{
if (!m_automatic) {
if (KMessageBox::warningContinueCancel(this, i18n("You are deleting data that is potentially valuable to you. Are you sure?"))
!= KMessageBox::Continue) {
return;
}
}
ui.statusTextEdit->clear();
ui.statusTextEdit->setText(i18n("Starting cleanup..."));
for (auto &&act : checklist) {
if (act->checkState(0) == Qt::Checked) {
QString statusText = i18n("Clearing %1...", act->text(0));
ui.statusTextEdit->append(statusText);
// actions return whether they were successful
if (!act->action()) {
QString errorText = i18n("Clearing of %1 failed: %2", act->text(0), act->getErrMsg());
ui.statusTextEdit->append(errorText);
}
}
}
ui.statusTextEdit->append(i18n("Clean up finished."));
}
void Sweeper::InitActions()
{
// store all entries in a list for easy access later on
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.klipper"))) {
checklist.append(new ClearSavedClipboardContentsAction(m_generalCLI));
}
checklist.append(new ClearRecentDocumentsAction(m_generalCLI));
checklist.append(new ClearRunCommandHistoryAction(m_generalCLI));
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.ActivityManager"))) {
checklist.append(new ClearRecentApplicationAction(m_generalCLI));
}
checklist.append(new ClearThumbnailsAction(m_generalCLI));
checklist.append(new ClearAllCookiesAction(m_webbrowsingCLI));
checklist.append(new ClearFaviconsAction(m_webbrowsingCLI));
checklist.append(new ClearWebHistoryAction(m_webbrowsingCLI));
checklist.append(new ClearWebCacheAction(m_webbrowsingCLI));
checklist.append(new ClearFormCompletionAction(m_webbrowsingCLI));
checklist.append(new ClearAllCookiesPoliciesAction(m_webbrowsingCLI));
ui.privacyListView->resizeColumnToContents(0);
}
// kate: tab-width 3; indent-mode cstyle; replace-tabs true;
|