Commit ec73805e authored by Méven Car's avatar Méven Car

[KCM/Activities] Use KConfigXT in ui

Summary: Port the ui components to use KConfig XT features to reduce amount of boilerplate code.

Test Plan: kcmshell5 activities

Reviewers: #plasma, ervin, bport

Reviewed By: ervin

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26398
parent df7cd5b6
......@@ -61,14 +61,3 @@ ActivitiesTab::~ActivitiesTab()
{
}
void ActivitiesTab::defaults()
{
}
void ActivitiesTab::load()
{
}
void ActivitiesTab::save()
{
}
......@@ -34,14 +34,6 @@ public:
explicit ActivitiesTab(QWidget *parent);
~ActivitiesTab() override;
public Q_SLOTS:
void defaults();
void load();
void save();
Q_SIGNALS:
void changed();
private:
D_PTR;
};
......
......@@ -29,9 +29,8 @@
#include <QDebug>
#include <KService>
#include <KConfig>
#include <KSharedConfig>
#include <KConfigGroup>
#include "kactivitymanagerd_plugins_settings.h"
#include <utils/d_ptr_implementation.h>
......@@ -48,8 +47,8 @@ public:
QList<ApplicationData> applications;
QSqlDatabase database;
KSharedConfig::Ptr pluginConfig;
KActivityManagerdPluginsSettings *pluginConfig;
bool enabled;
};
......@@ -57,7 +56,13 @@ BlacklistedApplicationsModel::BlacklistedApplicationsModel(QObject *parent)
: QAbstractListModel(parent)
{
d->enabled = false;
d->pluginConfig = KSharedConfig::openConfig(QStringLiteral("kactivitymanagerd-pluginsrc"));
d->pluginConfig = new KActivityManagerdPluginsSettings;
const QString path
= QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
+ QStringLiteral("/kactivitymanagerd/resources/database");
d->database = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), QStringLiteral("plugins_sqlite_db_resources"));
d->database.setDatabaseName(path);
}
BlacklistedApplicationsModel::~BlacklistedApplicationsModel()
......@@ -77,22 +82,13 @@ QHash<int, QByteArray> BlacklistedApplicationsModel::roleNames() const
void BlacklistedApplicationsModel::load()
{
// Loading plugin configuration
const auto config = d->pluginConfig->group(SQLITE_PLUGIN_CONFIG_KEY);
const auto defaultBlockedValue = config.readEntry("blocked-by-default", false);
auto blockedApplications = QSet<QString>::fromList(config.readEntry("blocked-applications", QStringList()));
auto allowedApplications = QSet<QString>::fromList(config.readEntry("allowed-applications", QStringList()));
d->pluginConfig->load();
const auto defaultBlockedValue = d->pluginConfig->defaultBlockedByDefaultValue();
auto blockedApplications = QSet<QString>::fromList(d->pluginConfig->blockedApplications());
auto allowedApplications = QSet<QString>::fromList(d->pluginConfig->allowedApplications());
// Reading new applications from the database
const QString path
= QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)
+ QStringLiteral("/kactivitymanagerd/resources/database");
d->database = QSqlDatabase::addDatabase(QStringLiteral("QSQLITE"), QStringLiteral("plugins_sqlite_db_resources"));
d->database.setDatabaseName(path);
if (!d->database.open()) {
// qDebug() << "Failed to open the database" << path << d->database.lastError();
return;
......@@ -150,17 +146,8 @@ void BlacklistedApplicationsModel::load()
void BlacklistedApplicationsModel::save()
{
auto config = d->pluginConfig->group(SQLITE_PLUGIN_CONFIG_KEY);
QStringList blockedApplications;
QStringList allowedApplications;
for (int i = 0; i < rowCount(); i++) {
(d->applications[i].blocked ? blockedApplications : allowedApplications)
<< d->applications[i].name;
}
config.writeEntry("allowed-applications", allowedApplications);
config.writeEntry("blocked-applications", blockedApplications);
d->pluginConfig->save();
emit changed(false);
}
void BlacklistedApplicationsModel::defaults()
......@@ -171,6 +158,8 @@ void BlacklistedApplicationsModel::defaults()
dataChanged(QAbstractListModel::index(0),
QAbstractListModel::index(rowCount() - 1));
emit defaulted(true);
}
void BlacklistedApplicationsModel::toggleApplicationBlocked(int index)
......@@ -183,14 +172,35 @@ void BlacklistedApplicationsModel::toggleApplicationBlocked(int index)
dataChanged(QAbstractListModel::index(index),
QAbstractListModel::index(index));
emit changed();
QStringList blockedApplications;
QStringList allowedApplications;
for (int i = 0; i < rowCount(); i++) {
const auto name = d->applications[i].name;
if (d->applications[i].blocked) {
blockedApplications << name;
} else {
allowedApplications << name;
}
}
d->pluginConfig->setBlockedApplications(blockedApplications);
d->pluginConfig->setAllowedApplications(allowedApplications);
const auto allowedApplicationsItem = d->pluginConfig->findItem("allowedApplications");
Q_ASSERT(allowedApplicationsItem);
const auto blockedApplicationsItem = d->pluginConfig->findItem("allowedApplications");
Q_ASSERT(blockedApplicationsItem);
emit changed(blockedApplicationsItem->isSaveNeeded() && allowedApplicationsItem->isSaveNeeded());
emit defaulted(blockedApplicationsItem->isDefault() && allowedApplicationsItem->isDefault());
}
QVariant BlacklistedApplicationsModel::headerData(int section, Qt::Orientation orientation, int role) const
{
Q_UNUSED(section);
Q_UNUSED(orientation);
Q_UNUSED(role);
Q_UNUSED(section)
Q_UNUSED(orientation)
Q_UNUSED(role)
return QVariant();
}
......@@ -224,7 +234,7 @@ QVariant BlacklistedApplicationsModel::data(const QModelIndex &modelIndex, int r
int BlacklistedApplicationsModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
Q_UNUSED(parent)
return d->applications.size();
}
......
......@@ -49,7 +49,8 @@ public:
QHash<int, QByteArray> roleNames() const override;
Q_SIGNALS:
void changed();
void changed(bool changed);
void defaulted(bool isDefault);
void enabledChanged(bool enabled);
public Q_SLOTS:
......
......@@ -46,48 +46,37 @@ MainConfigurationWidget::MainConfigurationWidget(QWidget *parent, QVariantList a
d->tabs->insertTab(0, d->tabActivities = new ActivitiesTab(d->tabs), i18n("Activities"));
d->tabs->insertTab(1, d->tabSwitching = new SwitchingTab(d->tabs), i18n("Switching"));
d->tabs->insertTab(2, d->tabPrivacy = new PrivacyTab(d->tabs), i18n("Privacy"));
connect(d->tabActivities, &ActivitiesTab::changed, this, &MainConfigurationWidget::onChanged);
connect(d->tabSwitching, &SwitchingTab::changed, this, &MainConfigurationWidget::onChanged);
connect(d->tabPrivacy, &PrivacyTab::changed, this, &MainConfigurationWidget::onChanged);
addConfig(d->tabPrivacy->pluginConfig(), d->tabPrivacy);
addConfig(d->tabSwitching->mainConfig(), d->tabSwitching);
connect (d->tabPrivacy, &PrivacyTab::blackListModelChanged, this, &MainConfigurationWidget::unmanagedWidgetChangeState);
connect (d->tabPrivacy, &PrivacyTab::blackListModelDefaulted, this, &MainConfigurationWidget::unmanagedWidgetDefaultState);
}
MainConfigurationWidget::~MainConfigurationWidget()
{
}
void MainConfigurationWidget::checkDefault()
{
defaulted(d->tabSwitching->isDefault() && d->tabPrivacy->isDefault());
}
void MainConfigurationWidget::onChanged()
{
checkDefault();
markAsChanged();
}
void MainConfigurationWidget::defaults()
{
d->tabActivities->defaults();
KCModule::defaults();
d->tabPrivacy->defaults();
d->tabSwitching->defaults();
}
void MainConfigurationWidget::load()
{
d->tabActivities->load();
KCModule::load();
d->tabPrivacy->load();
d->tabSwitching->load();
checkDefault();
}
void MainConfigurationWidget::save()
{
d->tabActivities->save();
KCModule::save();
d->tabPrivacy->save();
d->tabSwitching->save();
}
#include "MainConfigurationWidget.moc"
......@@ -42,12 +42,6 @@ public Q_SLOTS:
void load() override;
void save() override;
private Q_SLOTS:
void onChanged();
private:
void checkDefault();
private:
D_PTR;
};
......
......@@ -63,6 +63,11 @@ public:
}
};
KCoreConfigSkeleton *PrivacyTab::pluginConfig()
{
return d->pluginConfig;
}
PrivacyTab::PrivacyTab(QWidget *parent)
: QWidget(parent)
, d(this)
......@@ -71,10 +76,10 @@ PrivacyTab::PrivacyTab(QWidget *parent)
// Keep history initialization
d->spinKeepHistory->setRange(0, INT_MAX);
d->spinKeepHistory->setSpecialValueText(i18nc("unlimited number of months", "Forever"));
d->kcfg_keepHistoryFor->setRange(0, INT_MAX);
d->kcfg_keepHistoryFor->setSpecialValueText(i18nc("unlimited number of months", "Forever"));
connect(d->spinKeepHistory, SIGNAL(valueChanged(int)),
connect(d->kcfg_keepHistoryFor, SIGNAL(valueChanged(int)),
this, SLOT(spinKeepHistoryValueChanged(int)));
spinKeepHistoryValueChanged(0);
......@@ -96,6 +101,8 @@ PrivacyTab::PrivacyTab(QWidget *parent)
// Blacklist applications
d->blacklistedApplicationsModel = new BlacklistedApplicationsModel(this);
connect(d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::changed, this, &PrivacyTab::blackListModelChanged);
connect(d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::defaulted, this, &PrivacyTab::blackListModelDefaulted);
new QGridLayout(d->viewBlacklistedApplicationsContainer);
......@@ -108,21 +115,9 @@ PrivacyTab::PrivacyTab(QWidget *parent)
// React to changes
connect(d->radioRememberAllApplications, &QAbstractButton::toggled, this, &PrivacyTab::changed);
connect(d->radioDontRememberApplications, &QAbstractButton::toggled, this, &PrivacyTab::changed);
connect(d->spinKeepHistory, SIGNAL(valueChanged(int)), this, SIGNAL(changed()));
connect(d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::changed, this, &PrivacyTab::changed);
connect(d->radioRememberSpecificApplications, &QAbstractButton::toggled,
d->blacklistedApplicationsModel, &BlacklistedApplicationsModel::setEnabled);
connect(d->checkBlacklistAllNotOnList, &QAbstractButton::toggled, this, &PrivacyTab::changed);
defaults();
d->checkBlacklistAllNotOnList->setEnabled(false);
d->blacklistedApplicationsModel->setEnabled(false);
d->viewBlacklistedApplicationsContainer->setEnabled(false);
d->messageWidget->setVisible(false);
}
......@@ -131,51 +126,25 @@ PrivacyTab::~PrivacyTab()
{
}
bool PrivacyTab::isDefault()
{
return d->radioRememberAllApplications->isChecked() &&
d->spinKeepHistory->value() == d->pluginConfig->defaultKeepHistoryForValue() &&
d->checkBlacklistAllNotOnList->isChecked() == d->pluginConfig->defaultBlockedByDefaultValue();
}
void PrivacyTab::defaults()
{
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 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(d->pluginConfig->keepHistoryFor());
d->checkBlacklistAllNotOnList->setChecked(d->pluginConfig->blockedByDefault());
}
void PrivacyTab::save()
{
d->blacklistedApplicationsModel->save();
const auto whatToRemember =
d->radioRememberSpecificApplications->isChecked() ? SpecificApplications :
d->radioDontRememberApplications->isChecked() ? NoApplications :
/* otherwise */ AllApplications;
d->pluginConfig->setWhatToRemember(static_cast<int>(whatToRemember));
d->pluginConfig->setKeepHistoryFor(d->spinKeepHistory->value());
d->pluginConfig->setBlockedByDefault(d->checkBlacklistAllNotOnList->isChecked());
d->pluginConfig->save();
d->mainConfig->setResourceScoringEnabled(whatToRemember != NoApplications);
d->mainConfig->save();
}
......@@ -216,8 +185,8 @@ void PrivacyTab::spinKeepHistoryValueChanged(int value)
" month", " months");
if (value) {
d->spinKeepHistory->setPrefix(
d->kcfg_keepHistoryFor->setPrefix(
i18nc("for in 'keep history for 5 months'", "For "));
d->spinKeepHistory->setSuffix(months.subs(value).toString());
d->kcfg_keepHistoryFor->setSuffix(months.subs(value).toString());
}
}
......@@ -25,6 +25,8 @@
#include <utils/d_ptr.h>
class KCoreConfigSkeleton;
/**
* PrivacyTab
*/
......@@ -35,7 +37,8 @@ public:
~PrivacyTab() override;
bool isDefault();
KCoreConfigSkeleton *pluginConfig();
public Q_SLOTS:
void defaults();
void load();
......@@ -51,7 +54,8 @@ private Q_SLOTS:
void spinKeepHistoryValueChanged(int value);
Q_SIGNALS:
void changed();
void blackListModelChanged(bool changed);
void blackListModelDefaulted(bool isDefault);
private:
enum WhatToRemember {
......
......@@ -33,7 +33,7 @@
class SwitchingTab::Private : public Ui::SwitchingTabBase {
public:
KActivityManagerdSettings mainConfig;
KActivityManagerdSettings *mainConfig;
KActionCollection *mainActionCollection;
KActivities::Consumer activities;
......@@ -49,7 +49,8 @@ public:
}
Private()
: mainActionCollection(nullptr)
: mainConfig(new KActivityManagerdSettings),
mainActionCollection(nullptr)
{
}
};
......@@ -74,22 +75,15 @@ SwitchingTab::SwitchingTab(QWidget *parent)
d->scActivities->setActionTypes(KShortcutsEditor::GlobalAction);
d->scActivities->addCollection(d->mainActionCollection);
connect(d->scActivities, &KShortcutsEditor::keyChange,
this, [this] { changed(); });
connect(d->checkRememberVirtualDesktop, &QAbstractButton::toggled,
this, &SwitchingTab::changed);
defaults();
}
SwitchingTab::~SwitchingTab()
{
}
bool SwitchingTab::isDefault()
KCoreConfigSkeleton *SwitchingTab::mainConfig()
{
return !d->checkRememberVirtualDesktop->isChecked();
return d->mainConfig;
}
void SwitchingTab::shortcutChanged(const QKeySequence &sequence)
......@@ -105,23 +99,5 @@ void SwitchingTab::shortcutChanged(const QKeySequence &sequence)
KGlobalAccel::self()->setShortcut(action, { sequence },
KGlobalAccel::NoAutoloading);
d->mainActionCollection->writeSettings();
emit changed();
}
void SwitchingTab::defaults()
{
d->checkRememberVirtualDesktop->setChecked(false);
}
void SwitchingTab::load()
{
d->checkRememberVirtualDesktop->setChecked(d->mainConfig.virtualDesktopSwitchEnabled());
}
void SwitchingTab::save()
{
d->mainConfig.setVirtualDesktopSwitchEnabled(d->checkRememberVirtualDesktop->isChecked());
d->mainConfig.save();
}
......@@ -26,6 +26,7 @@
#include <utils/d_ptr.h>
class QKeySequence;
class KCoreConfigSkeleton;
/**
* SwitchingTab
......@@ -36,19 +37,11 @@ public:
explicit SwitchingTab(QWidget *parent);
~SwitchingTab() override;
bool isDefault();
public Q_SLOTS:
void defaults();
void load();
void save();
KCoreConfigSkeleton *mainConfig();
private Q_SLOTS:
void shortcutChanged(const QKeySequence &sequence);
Q_SIGNALS:
void changed();
private:
D_PTR;
};
......
......@@ -16,6 +16,12 @@
<entry name="whatToRemember" key="what-to-remember" type="Int">
<label>Which data to keep in activity history</label>
<default>0</default>
</entry>
</entry>
<entry name="allowedApplications" key="allowed-applications" type="StringList">
<label>List of Applications whose activity history to save</label>
</entry>
<entry name="blockedApplications" key="blocked-applications" type="StringList">
<label>List of Applications whose activity history not to save</label>
</entry>
</group>
</kcfg>
......@@ -30,41 +30,17 @@
<property name="formAlignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<item row="1" column="0">
<widget class="QLabel" name="labelRememberDocuments">
<property name="text">
<string>Remember opened documents:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="radioRememberAllApplications">
<property name="text">
<string>For a&amp;ll applications</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QRadioButton" name="radioDontRememberApplications">
<property name="text">
<string>&amp;Do not remember</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QRadioButton" name="radioRememberSpecificApplications">
<item row="0" column="0">
<widget class="QLabel" name="labelKeepHistory">
<property name="text">
<string>O&amp;nly for specific applications:</string>
<string>Keep history:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSpinBox" name="spinKeepHistory"/>
<widget class="QSpinBox" name="kcfg_keepHistoryFor"/>
</item>
<item>
<widget class="QPushButton" name="buttonClearRecentHistory">
......@@ -79,10 +55,46 @@
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelKeepHistory">
<item row="1" column="1">
<widget class="QGroupBox" name="kcfg_whatToRemember">
<property name="title">
<string/>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QRadioButton" name="radioRememberAllApplications">
<property name="text">
<string>For a&amp;ll applications</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioDontRememberApplications">
<property name="text">
<string>&amp;Do not remember</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioRememberSpecificApplications">
<property name="text">
<string>O&amp;nly for specific applications:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelRememberDocuments">
<property name="text">
<string>Keep history:</string>
<string>Remember opened documents:</string>
</property>
</widget>
</item>
......@@ -104,7 +116,7 @@
<number>6</number>
</property>
<item>
<widget class="QCheckBox" name="checkBlacklistAllNotOnList">
<widget class="QCheckBox" name="kcfg_blockedByDefault">
<property name="text">
<string>Blacklist applications not on the list</string>
</property>
......@@ -142,7 +154,7 @@
<connection>
<sender>radioRememberSpecificApplications</sender>
<signal>toggled(bool)</signal>
<receiver>checkBlacklistAllNotOnList</receiver>
<receiver>kcfg_blockedByDefault</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
......
......@@ -17,7 +17,7 @@
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
<item row="0" column="1">
<widget class="QCheckBox" name="checkRememberVirtualDesktop">
<widget class="QCheckBox" name="kcfg_virtualDesktopSwitchEnabled">
<property name="text">
<string>Remember for each activity (needs restart)</string>
</property>
......@@ -47,10 +47,13 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>195</height>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
......
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