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; | ||
ervin: I'd have it by pointer and give it a parent at construction time. It's a more common pattern… | |||||
ervin: Ditto | |||||
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) | ||||
ervin: Space before * not after | |||||
58 | , viewBlacklistedApplications(nullptr) | 61 | , viewBlacklistedApplications(nullptr) | ||
59 | { | 62 | { | ||
60 | } | 63 | } | ||
64 | | ||||
65 | ~Private() | ||||
66 | { | ||||
67 | mainConfig->deleteLater(); | ||||
davidedmundson: Why do we explicitly call deleteLater on these?
| |||||
meven: That was not needed, will clean up | |||||
meven: D26287 | |||||
68 | pluginConfig->deleteLater(); | ||||
69 | } | ||||
61 | }; | 70 | }; | ||
62 | 71 | | |||
63 | PrivacyTab::PrivacyTab(QWidget *parent) | 72 | PrivacyTab::PrivacyTab(QWidget *parent) | ||
64 | : QWidget(parent) | 73 | : QWidget(parent) | ||
65 | , d() | 74 | , d(this) | ||
66 | { | 75 | { | ||
67 | d->setupUi(this); | 76 | d->setupUi(this); | ||
68 | 77 | | |||
69 | d->mainConfig = KSharedConfig::openConfig(QStringLiteral("kactivitymanagerdrc")); | | |||
70 | d->pluginConfig = KSharedConfig::openConfig(QStringLiteral("kactivitymanagerd-pluginsrc")); | | |||
71 | | ||||
72 | // Keep history initialization | 78 | // Keep history initialization | ||
73 | 79 | | |||
74 | d->spinKeepHistory->setRange(0, INT_MAX); | 80 | d->spinKeepHistory->setRange(0, INT_MAX); | ||
75 | d->spinKeepHistory->setSpecialValueText(i18nc("unlimited number of months", "Forever")); | 81 | d->spinKeepHistory->setSpecialValueText(i18nc("unlimited number of months", "Forever")); | ||
76 | 82 | | |||
77 | connect(d->spinKeepHistory, SIGNAL(valueChanged(int)), | 83 | connect(d->spinKeepHistory, SIGNAL(valueChanged(int)), | ||
78 | this, SLOT(spinKeepHistoryValueChanged(int))); | 84 | this, SLOT(spinKeepHistoryValueChanged(int))); | ||
79 | spinKeepHistoryValueChanged(0); | 85 | spinKeepHistoryValueChanged(0); | ||
Show All 37 Lines | 122 | connect(d->radioRememberSpecificApplications, &QAbstractButton::toggled, | |||
117 | d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::setEnabled); | 123 | d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::setEnabled); | ||
118 | 124 | | |||
119 | connect(d->radioRememberSpecificApplications, &QAbstractButton::toggled, | 125 | connect(d->radioRememberSpecificApplications, &QAbstractButton::toggled, | ||
120 | d->viewBlacklistedApplicationsContainer, &QWidget::setEnabled); | 126 | d->viewBlacklistedApplicationsContainer, &QWidget::setEnabled); | ||
121 | 127 | | |||
122 | connect(d->radioRememberSpecificApplications, &QAbstractButton::toggled, | 128 | connect(d->radioRememberSpecificApplications, &QAbstractButton::toggled, | ||
123 | d->checkBlacklistAllNotOnList, &QWidget::setEnabled); | 129 | d->checkBlacklistAllNotOnList, &QWidget::setEnabled); | ||
124 | 130 | | |||
131 | connect(d->checkBlacklistAllNotOnList, &QAbstractButton::toggled, this, &PrivacyTab::changed); | ||||
132 | | ||||
125 | defaults(); | 133 | defaults(); | ||
126 | 134 | | |||
127 | d->checkBlacklistAllNotOnList->setEnabled(false); | 135 | d->checkBlacklistAllNotOnList->setEnabled(false); | ||
128 | d->blacklistedApplicationsModel->setEnabled(false); | 136 | d->blacklistedApplicationsModel->setEnabled(false); | ||
129 | d->viewBlacklistedApplicationsContainer->setEnabled(false); | 137 | d->viewBlacklistedApplicationsContainer->setEnabled(false); | ||
130 | 138 | | |||
131 | d->messageWidget->setVisible(false); | 139 | d->messageWidget->setVisible(false); | ||
132 | } | 140 | } | ||
133 | 141 | | |||
134 | PrivacyTab::~PrivacyTab() | 142 | PrivacyTab::~PrivacyTab() | ||
135 | { | 143 | { | ||
136 | } | 144 | } | ||
137 | 145 | | |||
138 | void PrivacyTab::defaults() | 146 | void PrivacyTab::defaults() | ||
139 | { | 147 | { | ||
140 | d->radioRememberAllApplications->click(); | | |||
141 | d->spinKeepHistory->setValue(0); | | |||
142 | d->blacklistedApplicationsModel->defaults(); | 148 | d->blacklistedApplicationsModel->defaults(); | ||
149 | | ||||
150 | d->radioRememberAllApplications->click(); | ||||
151 | d->spinKeepHistory->setValue(d->pluginConfig->defaultKeepHistoryForValue()); | ||||
152 | d->checkBlacklistAllNotOnList->setChecked(d->pluginConfig->defaultBlockedByDefaultValue()); | ||||
143 | } | 153 | } | ||
144 | 154 | | |||
145 | void PrivacyTab::load() | 155 | void PrivacyTab::load() | ||
146 | { | 156 | { | ||
147 | d->blacklistedApplicationsModel->load(); | 157 | d->blacklistedApplicationsModel->load(); | ||
148 | 158 | | |||
149 | const auto statisticsConfig | 159 | 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 | 160 | | |||
155 | d->radioRememberAllApplications->setChecked(whatToRemember == AllApplications); | 161 | d->radioRememberAllApplications->setChecked(whatToRemember == AllApplications); | ||
156 | d->radioRememberSpecificApplications->setChecked(whatToRemember == SpecificApplications); | 162 | d->radioRememberSpecificApplications->setChecked(whatToRemember == SpecificApplications); | ||
157 | d->radioDontRememberApplications->setChecked(whatToRemember == NoApplications); | 163 | d->radioDontRememberApplications->setChecked(whatToRemember == NoApplications); | ||
158 | 164 | | |||
159 | d->spinKeepHistory->setValue( | 165 | d->spinKeepHistory->setValue(d->pluginConfig->keepHistoryFor()); | ||
160 | statisticsConfig.readEntry("keep-history-for", 0)); | 166 | d->checkBlacklistAllNotOnList->setChecked(d->pluginConfig->blockedByDefault()); | ||
161 | d->checkBlacklistAllNotOnList->setChecked( | | |||
162 | statisticsConfig.readEntry("blocked-by-default", false)); | | |||
163 | } | 167 | } | ||
164 | 168 | | |||
165 | void PrivacyTab::save() | 169 | void PrivacyTab::save() | ||
166 | { | 170 | { | ||
167 | d->blacklistedApplicationsModel->save(); | 171 | d->blacklistedApplicationsModel->save(); | ||
168 | 172 | | |||
169 | auto statisticsConfig = d->pluginConfig->group(SQLITE_PLUGIN_CONFIG_KEY); | | |||
170 | | ||||
171 | const auto whatToRemember = | 173 | const auto whatToRemember = | ||
172 | d->radioRememberSpecificApplications->isChecked() ? SpecificApplications : | 174 | d->radioRememberSpecificApplications->isChecked() ? SpecificApplications : | ||
173 | d->radioDontRememberApplications->isChecked() ? NoApplications : | 175 | d->radioDontRememberApplications->isChecked() ? NoApplications : | ||
174 | /* otherwise */ AllApplications; | 176 | /* otherwise */ AllApplications; | ||
175 | 177 | | |||
176 | statisticsConfig.writeEntry("what-to-remember", static_cast<int>(whatToRemember)); | 178 | d->pluginConfig->setWhatToRemember(static_cast<int>(whatToRemember)); | ||
177 | statisticsConfig.writeEntry("keep-history-for", d->spinKeepHistory->value()); | 179 | d->pluginConfig->setKeepHistoryFor(d->spinKeepHistory->value()); | ||
178 | statisticsConfig.writeEntry("blocked-by-default", d->checkBlacklistAllNotOnList->isChecked()); | 180 | d->pluginConfig->setBlockedByDefault(d->checkBlacklistAllNotOnList->isChecked()); | ||
179 | | ||||
180 | statisticsConfig.sync(); | | |||
181 | | ||||
182 | auto pluginListConfig = d->mainConfig->group("Plugins"); | | |||
183 | 181 | | |||
184 | pluginListConfig.writeEntry("org.kde.ActivityManager.ResourceScoringEnabled", | 182 | d->pluginConfig->save(); | ||
185 | whatToRemember != NoApplications); | | |||
186 | 183 | | |||
187 | pluginListConfig.sync(); | 184 | d->mainConfig->setResourceScoringEnabled(whatToRemember != NoApplications); | ||
185 | d->mainConfig->save(); | ||||
188 | } | 186 | } | ||
189 | 187 | | |||
190 | void PrivacyTab::forget(int count, const QString &what) | 188 | void PrivacyTab::forget(int count, const QString &what) | ||
191 | { | 189 | { | ||
192 | KAMD_DBUS_DECL_INTERFACE(rankingsservice, Resources/Scoring, | 190 | KAMD_DBUS_DECL_INTERFACE(rankingsservice, Resources/Scoring, | ||
193 | ResourcesScoring); | 191 | ResourcesScoring); | ||
194 | 192 | | |||
195 | rankingsservice.asyncCall(QStringLiteral("DeleteRecentStats"), QString(), count, what); | 193 | rankingsservice.asyncCall(QStringLiteral("DeleteRecentStats"), QString(), count, what); | ||
Show All 35 Lines |
I'd have it by pointer and give it a parent at construction time. It's a more common pattern for QObject as members.