Changeset View
Changeset View
Standalone View
Standalone View
kcms/activities/PrivacyTab.cpp
Show All 13 Lines | |||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | 15 | * GNU General Public License for more details. | ||
16 | * | 16 | * | ||
17 | * You should have received a copy of the GNU General Public License | 17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "PrivacyTab.h" | 21 | #include "PrivacyTab.h" | ||
22 | #include "kactivitymanagerd_settings.h" | ||||
23 | #include "kactivitymanagerd_plugins_settings.h" | ||||
22 | 24 | | |||
23 | #include <QMenu> | 25 | #include <QMenu> | ||
24 | #include <QQmlContext> | 26 | #include <QQmlContext> | ||
25 | #include <QQmlEngine> | 27 | #include <QQmlEngine> | ||
26 | #include <QQmlComponent> | 28 | #include <QQmlComponent> | ||
27 | #include <QDBusPendingCall> | 29 | #include <QDBusPendingCall> | ||
28 | 30 | | |||
29 | #include <QQuickView> | 31 | #include <QQuickView> | ||
30 | 32 | | |||
31 | #include <KConfigGroup> | 33 | #include <KConfigGroup> | ||
32 | #include <KSharedConfig> | 34 | #include <KSharedConfig> | ||
33 | #include <KMessageWidget> | 35 | #include <KMessageWidget> | ||
34 | 36 | | |||
35 | #include "ui_PrivacyTabBase.h" | 37 | #include "ui_PrivacyTabBase.h" | ||
36 | #include "BlacklistedApplicationsModel.h" | 38 | #include "BlacklistedApplicationsModel.h" | ||
37 | #include "definitions.h" | | |||
38 | 39 | | |||
39 | #include <utils/d_ptr_implementation.h> | 40 | #include <utils/d_ptr_implementation.h> | ||
40 | 41 | | |||
41 | #include "kactivities-kcm-features.h" | 42 | #include "kactivities-kcm-features.h" | ||
42 | 43 | | |||
43 | #include "common/dbus/common.h" | 44 | #include "common/dbus/common.h" | ||
44 | 45 | | |||
45 | #include "utils.h" | 46 | #include "utils.h" | ||
46 | 47 | | |||
47 | class PrivacyTab::Private : public Ui::PrivacyTabBase { | 48 | class PrivacyTab::Private : public Ui::PrivacyTabBase { | ||
48 | public: | 49 | public: | ||
49 | KSharedConfig::Ptr mainConfig; | 50 | KActivityManagerdSettings *mainConfig; | ||
50 | KSharedConfig::Ptr pluginConfig; | 51 | KActivityManagerdPluginsSettings *pluginConfig; | ||
51 | 52 | | |||
52 | BlacklistedApplicationsModel *blacklistedApplicationsModel; | 53 | BlacklistedApplicationsModel *blacklistedApplicationsModel; | ||
53 | QObject *viewBlacklistedApplicationsRoot; | 54 | QObject *viewBlacklistedApplicationsRoot; | ||
54 | std::unique_ptr<QQuickView> viewBlacklistedApplications; | 55 | std::unique_ptr<QQuickView> viewBlacklistedApplications; | ||
55 | 56 | | |||
56 | Private() | 57 | Private(QObject *parent) | ||
57 | : viewBlacklistedApplicationsRoot(nullptr) | 58 | : mainConfig(new KActivityManagerdSettings(parent)) | ||
59 | , pluginConfig(new KActivityManagerdPluginsSettings(parent)) | ||||
60 | , viewBlacklistedApplicationsRoot(nullptr) | ||||
58 | , viewBlacklistedApplications(nullptr) | 61 | , viewBlacklistedApplications(nullptr) | ||
59 | { | 62 | { | ||
60 | } | 63 | } | ||
61 | }; | 64 | }; | ||
62 | 65 | | |||
63 | PrivacyTab::PrivacyTab(QWidget *parent) | 66 | PrivacyTab::PrivacyTab(QWidget *parent) | ||
64 | : QWidget(parent) | 67 | : QWidget(parent) | ||
65 | , d() | 68 | , d(this) | ||
66 | { | 69 | { | ||
67 | d->setupUi(this); | 70 | d->setupUi(this); | ||
68 | 71 | | |||
69 | d->mainConfig = KSharedConfig::openConfig(QStringLiteral("kactivitymanagerdrc")); | | |||
70 | d->pluginConfig = KSharedConfig::openConfig(QStringLiteral("kactivitymanagerd-pluginsrc")); | | |||
71 | | ||||
72 | // Keep history initialization | 72 | // Keep history initialization | ||
73 | 73 | | |||
74 | d->spinKeepHistory->setRange(0, INT_MAX); | 74 | d->spinKeepHistory->setRange(0, INT_MAX); | ||
75 | d->spinKeepHistory->setSpecialValueText(i18nc("unlimited number of months", "Forever")); | 75 | d->spinKeepHistory->setSpecialValueText(i18nc("unlimited number of months", "Forever")); | ||
76 | 76 | | |||
77 | connect(d->spinKeepHistory, SIGNAL(valueChanged(int)), | 77 | connect(d->spinKeepHistory, SIGNAL(valueChanged(int)), | ||
78 | this, SLOT(spinKeepHistoryValueChanged(int))); | 78 | this, SLOT(spinKeepHistoryValueChanged(int))); | ||
79 | spinKeepHistoryValueChanged(0); | 79 | spinKeepHistoryValueChanged(0); | ||
Show All 31 Lines | |||||
111 | connect(d->radioRememberAllApplications, &QAbstractButton::toggled, this, &PrivacyTab::changed); | 111 | connect(d->radioRememberAllApplications, &QAbstractButton::toggled, this, &PrivacyTab::changed); | ||
112 | connect(d->radioDontRememberApplications, &QAbstractButton::toggled, this, &PrivacyTab::changed); | 112 | connect(d->radioDontRememberApplications, &QAbstractButton::toggled, this, &PrivacyTab::changed); | ||
113 | connect(d->spinKeepHistory, SIGNAL(valueChanged(int)), this, SIGNAL(changed())); | 113 | connect(d->spinKeepHistory, SIGNAL(valueChanged(int)), this, SIGNAL(changed())); | ||
114 | connect(d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::changed, this, &PrivacyTab::changed); | 114 | connect(d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::changed, this, &PrivacyTab::changed); | ||
115 | 115 | | |||
116 | connect(d->radioRememberSpecificApplications, &QAbstractButton::toggled, | 116 | connect(d->radioRememberSpecificApplications, &QAbstractButton::toggled, | ||
117 | d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::setEnabled); | 117 | d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::setEnabled); | ||
118 | 118 | | |||
119 | connect(d->radioRememberSpecificApplications, &QAbstractButton::toggled, | 119 | connect(d->checkBlacklistAllNotOnList, &QAbstractButton::toggled, this, &PrivacyTab::changed); | ||
120 | d->viewBlacklistedApplicationsContainer, &QWidget::setEnabled); | | |||
121 | | ||||
122 | connect(d->radioRememberSpecificApplications, &QAbstractButton::toggled, | | |||
123 | d->checkBlacklistAllNotOnList, &QWidget::setEnabled); | | |||
124 | 120 | | |||
125 | defaults(); | 121 | defaults(); | ||
126 | 122 | | |||
127 | d->checkBlacklistAllNotOnList->setEnabled(false); | 123 | d->checkBlacklistAllNotOnList->setEnabled(false); | ||
128 | d->blacklistedApplicationsModel->setEnabled(false); | 124 | d->blacklistedApplicationsModel->setEnabled(false); | ||
129 | d->viewBlacklistedApplicationsContainer->setEnabled(false); | 125 | d->viewBlacklistedApplicationsContainer->setEnabled(false); | ||
130 | 126 | | |||
131 | d->messageWidget->setVisible(false); | 127 | d->messageWidget->setVisible(false); | ||
132 | } | 128 | } | ||
133 | 129 | | |||
134 | PrivacyTab::~PrivacyTab() | 130 | PrivacyTab::~PrivacyTab() | ||
135 | { | 131 | { | ||
136 | } | 132 | } | ||
137 | 133 | | |||
134 | bool PrivacyTab::isDefault() | ||||
135 | { | ||||
136 | return d->radioRememberAllApplications->isChecked() && | ||||
137 | d->spinKeepHistory->value() == d->pluginConfig->defaultKeepHistoryForValue() && | ||||
138 | d->checkBlacklistAllNotOnList->isChecked() == d->pluginConfig->defaultBlockedByDefaultValue(); | ||||
139 | } | ||||
140 | | ||||
138 | void PrivacyTab::defaults() | 141 | void PrivacyTab::defaults() | ||
139 | { | 142 | { | ||
140 | d->radioRememberAllApplications->click(); | | |||
141 | d->spinKeepHistory->setValue(0); | | |||
142 | d->blacklistedApplicationsModel->defaults(); | 143 | d->blacklistedApplicationsModel->defaults(); | ||
144 | | ||||
145 | d->radioRememberAllApplications->click(); | ||||
146 | d->spinKeepHistory->setValue(d->pluginConfig->defaultKeepHistoryForValue()); | ||||
147 | d->checkBlacklistAllNotOnList->setChecked(d->pluginConfig->defaultBlockedByDefaultValue()); | ||||
143 | } | 148 | } | ||
144 | 149 | | |||
145 | void PrivacyTab::load() | 150 | void PrivacyTab::load() | ||
146 | { | 151 | { | ||
147 | d->blacklistedApplicationsModel->load(); | 152 | d->blacklistedApplicationsModel->load(); | ||
148 | 153 | | |||
149 | const auto statisticsConfig | 154 | const auto whatToRemember = static_cast<WhatToRemember>(d->pluginConfig->whatToRemember()); | ||
150 | = d->pluginConfig->group(SQLITE_PLUGIN_CONFIG_KEY); | | |||
151 | | ||||
152 | const auto whatToRemember = static_cast<WhatToRemember>(statisticsConfig.readEntry( | | |||
153 | "what-to-remember", static_cast<int>(AllApplications))); | | |||
154 | 155 | | |||
155 | d->radioRememberAllApplications->setChecked(whatToRemember == AllApplications); | 156 | d->radioRememberAllApplications->setChecked(whatToRemember == AllApplications); | ||
156 | d->radioRememberSpecificApplications->setChecked(whatToRemember == SpecificApplications); | 157 | d->radioRememberSpecificApplications->setChecked(whatToRemember == SpecificApplications); | ||
157 | d->radioDontRememberApplications->setChecked(whatToRemember == NoApplications); | 158 | d->radioDontRememberApplications->setChecked(whatToRemember == NoApplications); | ||
158 | 159 | | |||
159 | d->spinKeepHistory->setValue( | 160 | d->spinKeepHistory->setValue(d->pluginConfig->keepHistoryFor()); | ||
160 | statisticsConfig.readEntry("keep-history-for", 0)); | 161 | d->checkBlacklistAllNotOnList->setChecked(d->pluginConfig->blockedByDefault()); | ||
161 | d->checkBlacklistAllNotOnList->setChecked( | | |||
162 | statisticsConfig.readEntry("blocked-by-default", false)); | | |||
163 | } | 162 | } | ||
164 | 163 | | |||
165 | void PrivacyTab::save() | 164 | void PrivacyTab::save() | ||
166 | { | 165 | { | ||
167 | d->blacklistedApplicationsModel->save(); | 166 | d->blacklistedApplicationsModel->save(); | ||
168 | 167 | | |||
169 | auto statisticsConfig = d->pluginConfig->group(SQLITE_PLUGIN_CONFIG_KEY); | | |||
170 | | ||||
171 | const auto whatToRemember = | 168 | const auto whatToRemember = | ||
172 | d->radioRememberSpecificApplications->isChecked() ? SpecificApplications : | 169 | d->radioRememberSpecificApplications->isChecked() ? SpecificApplications : | ||
173 | d->radioDontRememberApplications->isChecked() ? NoApplications : | 170 | d->radioDontRememberApplications->isChecked() ? NoApplications : | ||
174 | /* otherwise */ AllApplications; | 171 | /* otherwise */ AllApplications; | ||
175 | 172 | | |||
176 | statisticsConfig.writeEntry("what-to-remember", static_cast<int>(whatToRemember)); | 173 | d->pluginConfig->setWhatToRemember(static_cast<int>(whatToRemember)); | ||
177 | statisticsConfig.writeEntry("keep-history-for", d->spinKeepHistory->value()); | 174 | d->pluginConfig->setKeepHistoryFor(d->spinKeepHistory->value()); | ||
178 | statisticsConfig.writeEntry("blocked-by-default", d->checkBlacklistAllNotOnList->isChecked()); | 175 | d->pluginConfig->setBlockedByDefault(d->checkBlacklistAllNotOnList->isChecked()); | ||
179 | | ||||
180 | statisticsConfig.sync(); | | |||
181 | | ||||
182 | auto pluginListConfig = d->mainConfig->group("Plugins"); | | |||
183 | 176 | | |||
184 | pluginListConfig.writeEntry("org.kde.ActivityManager.ResourceScoringEnabled", | 177 | d->pluginConfig->save(); | ||
185 | whatToRemember != NoApplications); | | |||
186 | 178 | | |||
187 | pluginListConfig.sync(); | 179 | d->mainConfig->setResourceScoringEnabled(whatToRemember != NoApplications); | ||
180 | d->mainConfig->save(); | ||||
188 | } | 181 | } | ||
189 | 182 | | |||
190 | void PrivacyTab::forget(int count, const QString &what) | 183 | void PrivacyTab::forget(int count, const QString &what) | ||
191 | { | 184 | { | ||
192 | KAMD_DBUS_DECL_INTERFACE(rankingsservice, Resources/Scoring, | 185 | KAMD_DBUS_DECL_INTERFACE(rankingsservice, Resources/Scoring, | ||
193 | ResourcesScoring); | 186 | ResourcesScoring); | ||
194 | 187 | | |||
195 | rankingsservice.asyncCall(QStringLiteral("DeleteRecentStats"), QString(), count, what); | 188 | rankingsservice.asyncCall(QStringLiteral("DeleteRecentStats"), QString(), count, what); | ||
Show All 35 Lines |