Commit a7b49bec authored by Cyril Rossi's avatar Cyril Rossi
Browse files

KCM Feedback port to ManagedConfigModule and SettingStateBinding

parent 0be05533
add_definitions(-DTRANSLATION_DOMAIN=\"kcm_feedback\")
add_library(kcm_feedback MODULE feedback.cpp)
set(kcm_feedback_PART_SRCS feedback.cpp)
kconfig_add_kcfg_files(kcm_feedback_PART_SRCS feedbacksettings.kcfgc GENERATE_MOC)
add_library(kcm_feedback MODULE ${kcm_feedback_PART_SRCS})
target_link_libraries(kcm_feedback
KF5::I18n
......@@ -11,6 +14,7 @@ target_link_libraries(kcm_feedback
kcoreaddons_desktop_to_json(kcm_feedback "kcm_feedback.desktop")
install(FILES feedbacksettings.kcfg DESTINATION ${KDE_INSTALL_KCFGDIR})
install(TARGETS kcm_feedback DESTINATION ${KDE_INSTALL_PLUGINDIR}/kcms)
install(FILES kcm_feedback.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
kpackage_install_package(package kcm_feedback kcms)
......@@ -30,6 +30,8 @@
#include <KUserFeedback/Provider>
#include <KUserFeedback/FeedbackConfigUiController>
#include "feedbacksettings.h"
K_PLUGIN_CLASS_WITH_JSON(Feedback, "kcm_feedback.json");
//Program to icon hash
......@@ -46,20 +48,18 @@ inline void swap(QJsonValueRef v1, QJsonValueRef v2)
}
Feedback::Feedback(QObject *parent, const QVariantList &args)
: KQuickAddons::ConfigModule(parent)
: KQuickAddons::ManagedConfigModule(parent)
//UserFeedback.conf is used by KUserFeedback which uses QSettings and won't go through globals
, m_plasmaConfig(KSharedConfig::openConfig(QStringLiteral("PlasmaUserFeedback")))
, m_feedbackSettings(new FeedbackSettings(this))
{
Q_UNUSED(args)
qmlRegisterType<FeedbackSettings>();
setAboutData(new KAboutData(QStringLiteral("kcm_feedback"),
i18n("User Feedback"),
QStringLiteral("1.0"), i18n("Configure user feedback settings"), KAboutLicense::LGPL));
connect(this, &Feedback::plasmaFeedbackLevelChanged, this, [this](){
auto current = m_plasmaConfig->group("Global").readEntry("FeedbackLevel", int(KUserFeedback::Provider::NoTelemetry));
setNeedsSave(current != m_plasmaFeedbackLevel);
});
QVector<QProcess*> processes;
for (const auto exec: s_programs.keys()) {
QProcess* p = new QProcess(this);
......@@ -132,30 +132,9 @@ bool Feedback::feedbackEnabled() const
return p.isEnabled();
}
void Feedback::load()
{
//We only operate if the kill switch is off, all KDE components should default to KUserFeedback::Provider::NoTelemetry
setPlasmaFeedbackLevel(m_plasmaConfig->group("Global").readEntry("FeedbackLevel", int(KUserFeedback::Provider::NoTelemetry)));
setNeedsSave(false);
}
void Feedback::save()
{
m_plasmaConfig->group("Global").writeEntry("FeedbackLevel", m_plasmaFeedbackLevel);
m_plasmaConfig->sync();
}
void Feedback::defaults()
FeedbackSettings *Feedback::feedbackSettings() const
{
setPlasmaFeedbackLevel(KUserFeedback::Provider::NoTelemetry);
}
void Feedback::setPlasmaFeedbackLevel(int plasmaFeedbackLevel) {
if (plasmaFeedbackLevel != m_plasmaFeedbackLevel) {
m_plasmaFeedbackLevel = plasmaFeedbackLevel;
Q_EMIT plasmaFeedbackLevelChanged(plasmaFeedbackLevel);
}
setRepresentsDefaults(plasmaFeedbackLevel == KUserFeedback::Provider::NoTelemetry);
return m_feedbackSettings;
}
#include "feedback.moc"
......@@ -20,41 +20,34 @@
#pragma once
#include <KQuickAddons/ConfigModule>
#include <KQuickAddons/ManagedConfigModule>
#include <KSharedConfig>
class Feedback : public KQuickAddons::ConfigModule
class FeedbackSettings;
class Feedback : public KQuickAddons::ManagedConfigModule
{
Q_OBJECT
Q_PROPERTY(QJsonArray feedbackSources MEMBER m_feedbackSources NOTIFY feedbackSourcesChanged)
Q_PROPERTY(bool feedbackEnabled READ feedbackEnabled CONSTANT)
Q_PROPERTY(int plasmaFeedbackLevel READ plasmaFeedbackLevel WRITE setPlasmaFeedbackLevel NOTIFY plasmaFeedbackLevelChanged)
Q_PROPERTY(FeedbackSettings *feedbackSettings READ feedbackSettings CONSTANT)
public:
explicit Feedback(QObject* parent = nullptr, const QVariantList &list = QVariantList());
explicit Feedback(QObject *parent = nullptr, const QVariantList &list = QVariantList());
~Feedback() override;
bool feedbackEnabled() const;
int plasmaFeedbackLevel() const { return m_plasmaFeedbackLevel; }
void setPlasmaFeedbackLevel(int plasmaFeedbackLevel);
FeedbackSettings *feedbackSettings() const;
void programFinished(int exitCode);
public Q_SLOTS:
void load() override;
void save() override;
void defaults() override;
Q_SIGNALS:
void feedbackSourcesChanged();
void plasmaFeedbackLevelChanged(bool plasmaFeedbackLevel);
private:
KSharedConfig::Ptr m_plasmaConfig;
int m_plasmaFeedbackLevel = 0;
QHash<int, QHash<QString, QJsonArray>> m_uses;
QJsonArray m_feedbackSources;
FeedbackSettings *m_feedbackSettings;
};
<?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="PlasmaUserFeedback" />
<group name="Global">
<entry name="feedbackLevel" key="FeedbackLevel" type="Int">
<default code="true">KUserFeedback::Provider::NoTelemetry</default>
</entry>
</group>
</kcfg>
File=feedbacksettings.kcfg
ClassName=FeedbackSettings
IncludeFiles="KUserFeedback/Provider"
Mutators=true
DefaultValueGetters=true
GenerateProperties=true
ParentInConstructor=true
......@@ -23,7 +23,7 @@ import QtQuick.Layouts 1.1
import QtQuick.Controls 2.3 as QQC2
import org.kde.kirigami 2.6 as Kirigami
import org.kde.userfeedback 1.0 as UserFeedback
import org.kde.kcm 1.2
import org.kde.kcm 1.3
SimpleKCM {
id: root
......@@ -72,7 +72,6 @@ SimpleKCM {
id: statisticsModeSlider
Kirigami.FormData.label: i18n("Plasma:")
readonly property var currentMode: modeOptions[value]
enabled: kcm.feedbackEnabled
Layout.fillWidth: true
Layout.minimumWidth: Kirigami.Units.gridUnit * 21
......@@ -91,10 +90,16 @@ SimpleKCM {
return defaultValue;
}
value: findIndex(modeOptions, kcm.plasmaFeedbackLevel, 0)
value: findIndex(modeOptions, kcm.feedbackSettings.feedbackLevel, 0)
onMoved: {
kcm.plasmaFeedbackLevel = modeOptions[value]
kcm.feedbackSettings.feedbackLevel = modeOptions[value]
}
SettingStateBinding {
configObject: kcm.feedbackSettings
settingName: "feedbackLevel"
extraEnabledConditions: kcm.feedbackEnabled
}
}
......
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