Commit df0a276b authored by Méven Car's avatar Méven Car
Browse files

[KCM/Activity] Use KConfigXT to store settings

Test Plan:
kcmshell5 kcm_activities
Changed settings, restored defaults

Reviewers: #plasma, ervin, crossi

Reviewed By: ervin

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26068
parent 3d2d0752
......@@ -51,6 +51,9 @@ qt5_add_dbus_interface (
features_interface
)
kconfig_add_kcfg_files(KAMD_KCM_SRCS kactivitymanagerd_settings.kcfgc GENERATE_MOC)
kconfig_add_kcfg_files(KAMD_KCM_SRCS kactivitymanagerd_plugins_settings.kcfgc GENERATE_MOC)
add_library (kcm_activities MODULE ${KAMD_KCM_SRCS})
target_link_libraries (kcm_activities
......@@ -87,3 +90,5 @@ install (
DESTINATION ${KAMD_KCM_DATADIR}/qml
)
install(FILES kactivitymanagerd_settings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(FILES kactivitymanagerd_plugins_settings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
......@@ -31,7 +31,6 @@
#include "utils/dbusfuture_p.h"
#include "features_interface.h"
#include "definitions.h"
#include "common/dbus/common.h"
#define ENABLE_QJSVALUE_CONTINUATION
......
......@@ -19,6 +19,8 @@
*/
#include "PrivacyTab.h"
#include "kactivitymanagerd_settings.h"
#include "kactivitymanagerd_plugins_settings.h"
#include <QMenu>
#include <QQmlContext>
......@@ -34,7 +36,6 @@
#include "ui_PrivacyTabBase.h"
#include "BlacklistedApplicationsModel.h"
#include "definitions.h"
#include <utils/d_ptr_implementation.h>
......@@ -46,29 +47,34 @@
class PrivacyTab::Private : public Ui::PrivacyTabBase {
public:
KSharedConfig::Ptr mainConfig;
KSharedConfig::Ptr pluginConfig;
KActivityManagerdSettings *mainConfig;
KActivityManagerdPluginsSettings *pluginConfig;
BlacklistedApplicationsModel *blacklistedApplicationsModel;
QObject *viewBlacklistedApplicationsRoot;
std::unique_ptr<QQuickView> viewBlacklistedApplications;
Private()
: viewBlacklistedApplicationsRoot(nullptr)
Private(QObject *parent)
: mainConfig(new KActivityManagerdSettings(parent))
, pluginConfig(new KActivityManagerdPluginsSettings(parent))
, viewBlacklistedApplicationsRoot(nullptr)
, viewBlacklistedApplications(nullptr)
{
}
~Private()
{
mainConfig->deleteLater();
pluginConfig->deleteLater();
}
};
PrivacyTab::PrivacyTab(QWidget *parent)
: QWidget(parent)
, d()
, d(this)
{
d->setupUi(this);
d->mainConfig = KSharedConfig::openConfig(QStringLiteral("kactivitymanagerdrc"));
d->pluginConfig = KSharedConfig::openConfig(QStringLiteral("kactivitymanagerd-pluginsrc"));
// Keep history initialization
d->spinKeepHistory->setRange(0, INT_MAX);
......@@ -122,6 +128,8 @@ PrivacyTab::PrivacyTab(QWidget *parent)
connect(d->radioRememberSpecificApplications, &QAbstractButton::toggled,
d->checkBlacklistAllNotOnList, &QWidget::setEnabled);
connect(d->checkBlacklistAllNotOnList, &QAbstractButton::toggled, this, &PrivacyTab::changed);
defaults();
d->checkBlacklistAllNotOnList->setEnabled(false);
......@@ -137,54 +145,44 @@ PrivacyTab::~PrivacyTab()
void PrivacyTab::defaults()
{
d->radioRememberAllApplications->click();
d->spinKeepHistory->setValue(0);
d->blacklistedApplicationsModel->defaults();
d->radioRememberAllApplications->click();
d->spinKeepHistory->setValue(d->pluginConfig->defaultKeepHistoryForValue());
d->checkBlacklistAllNotOnList->setChecked(d->pluginConfig->defaultBlockedByDefaultValue());
}
void PrivacyTab::load()
{
d->blacklistedApplicationsModel->load();
const auto statisticsConfig
= d->pluginConfig->group(SQLITE_PLUGIN_CONFIG_KEY);
const auto whatToRemember = static_cast<WhatToRemember>(statisticsConfig.readEntry(
"what-to-remember", static_cast<int>(AllApplications)));
const auto whatToRemember = static_cast<WhatToRemember>(d->pluginConfig->whatToRemember());
d->radioRememberAllApplications->setChecked(whatToRemember == AllApplications);
d->radioRememberSpecificApplications->setChecked(whatToRemember == SpecificApplications);
d->radioDontRememberApplications->setChecked(whatToRemember == NoApplications);
d->spinKeepHistory->setValue(
statisticsConfig.readEntry("keep-history-for", 0));
d->checkBlacklistAllNotOnList->setChecked(
statisticsConfig.readEntry("blocked-by-default", false));
d->spinKeepHistory->setValue(d->pluginConfig->keepHistoryFor());
d->checkBlacklistAllNotOnList->setChecked(d->pluginConfig->blockedByDefault());
}
void PrivacyTab::save()
{
d->blacklistedApplicationsModel->save();
auto statisticsConfig = d->pluginConfig->group(SQLITE_PLUGIN_CONFIG_KEY);
const auto whatToRemember =
d->radioRememberSpecificApplications->isChecked() ? SpecificApplications :
d->radioDontRememberApplications->isChecked() ? NoApplications :
/* otherwise */ AllApplications;
statisticsConfig.writeEntry("what-to-remember", static_cast<int>(whatToRemember));
statisticsConfig.writeEntry("keep-history-for", d->spinKeepHistory->value());
statisticsConfig.writeEntry("blocked-by-default", d->checkBlacklistAllNotOnList->isChecked());
statisticsConfig.sync();
auto pluginListConfig = d->mainConfig->group("Plugins");
d->pluginConfig->setWhatToRemember(static_cast<int>(whatToRemember));
d->pluginConfig->setKeepHistoryFor(d->spinKeepHistory->value());
d->pluginConfig->setBlockedByDefault(d->checkBlacklistAllNotOnList->isChecked());
pluginListConfig.writeEntry("org.kde.ActivityManager.ResourceScoringEnabled",
whatToRemember != NoApplications);
d->pluginConfig->save();
pluginListConfig.sync();
d->mainConfig->setResourceScoringEnabled(whatToRemember != NoApplications);
d->mainConfig->save();
}
void PrivacyTab::forget(int count, const QString &what)
......
......@@ -19,6 +19,7 @@
*/
#include "SwitchingTab.h"
#include "kactivitymanagerd_settings.h"
#include <KActionCollection>
#include <KConfigGroup>
......@@ -32,7 +33,7 @@
class SwitchingTab::Private : public Ui::SwitchingTabBase {
public:
KSharedConfig::Ptr mainConfig;
KActivityManagerdSettings mainConfig;
KActionCollection *mainActionCollection;
KActivities::Consumer activities;
......@@ -58,8 +59,6 @@ SwitchingTab::SwitchingTab(QWidget *parent)
{
d->setupUi(this);
d->mainConfig = KSharedConfig::openConfig(QStringLiteral("kactivitymanagerdrc"));
// Shortcut config. The shortcut belongs to the component "plasmashell"!
d->mainActionCollection = new KActionCollection(this, QStringLiteral("plasmashell"));
d->mainActionCollection->setComponentDisplayName(i18n("Activity switching"));
......@@ -111,19 +110,12 @@ void SwitchingTab::defaults()
void SwitchingTab::load()
{
auto pluginListConfig = d->mainConfig->group("Plugins");
d->checkRememberVirtualDesktop->setChecked(pluginListConfig.readEntry(
"org.kde.ActivityManager.VirtualDesktopSwitchEnabled", false));
d->checkRememberVirtualDesktop->setChecked(d->mainConfig.virtualDesktopSwitchEnabled());
}
void SwitchingTab::save()
{
auto pluginListConfig = d->mainConfig->group("Plugins");
pluginListConfig.writeEntry(
"org.kde.ActivityManager.VirtualDesktopSwitchEnabled",
d->checkRememberVirtualDesktop->isChecked());
pluginListConfig.sync();
d->mainConfig.setVirtualDesktopSwitchEnabled(d->checkRememberVirtualDesktop->isChecked());
d->mainConfig.save();
}
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kactivitymanagerd-pluginsrc"/>
<group name="Plugin-org.kde.ActivityManager.Resources.Scoring">
<entry name="keepHistoryFor" key="keep-history-for" type="Int">
<label>How many month keep the activity history</label>
<default>0</default>
</entry>
<entry name="blockedByDefault" key="blocked-by-default" type="Bool">
<default>false</default>
</entry>
<entry name="whatToRemember" key="what-to-remember" type="Int">
<label>whick data to keep in activity history</label>
<default>0</default>
</entry>
</group>
</kcfg>
File=kactivitymanagerd_plugins_settings.kcfg
ClassName=KActivityManagerdPluginsSettings
Mutators=true
DefaultValueGetters=true
ParentInConstructor=true
GlobalEnums=true
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name="kactivitymanagerdrc"/>
<group name="Plugins">
<entry name="virtualDesktopSwitchEnabled" key="org.kde.ActivityManager.VirtualDesktopSwitchEnabled" type="Bool">
<default>false</default>
</entry>
<entry name="resourceScoringEnabled" key="org.kde.ActivityManager.ResourceScoringEnabled" type="Bool">
<default>false</default>
</entry>
</group>
</kcfg>
File=kactivitymanagerd_settings.kcfg
ClassName=KActivityManagerdSettings
Mutators=true
DefaultValueGetters=true
ParentInConstructor=true
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment