diff --git a/common/control.h b/common/control.h --- a/common/control.h +++ b/common/control.h @@ -22,19 +22,21 @@ #include #include -class Control +class Control : public QObject { - Q_GADGET + Q_OBJECT public: enum class OutputRetention { Undefined = -1, Global = 0, Individual = 1, }; Q_ENUM(OutputRetention) + explicit Control(QObject *parent = nullptr); - virtual ~Control() = default; + + ~Control() override = default; protected: virtual QString dirPath() const; @@ -49,9 +51,9 @@ class ControlConfig : public Control { - Q_GADGET + Q_OBJECT public: - ControlConfig(KScreen::ConfigPtr config); + explicit ControlConfig(KScreen::ConfigPtr config, QObject *parent = nullptr); OutputRetention getOutputRetention(const KScreen::OutputPtr &output) const; OutputRetention getOutputRetention(const QString &outputId, const QString &outputName) const; @@ -75,9 +77,9 @@ class ControlOutput : public Control { - Q_GADGET + Q_OBJECT public: - ControlOutput(KScreen::OutputPtr output); + explicit ControlOutput(KScreen::OutputPtr output, QObject *parent = nullptr); // TODO: scale auto value diff --git a/common/control.cpp b/common/control.cpp --- a/common/control.cpp +++ b/common/control.cpp @@ -26,6 +26,11 @@ QString Control::s_dirName = QStringLiteral("control/"); +Control::Control(QObject *parent) + : QObject(parent) +{ +} + QString Control::dirPath() const { return Globals::dirPath() % s_dirName; @@ -50,8 +55,9 @@ return OutputRetention::Undefined; } -ControlConfig::ControlConfig(KScreen::ConfigPtr config) - : m_config(config) +ControlConfig::ControlConfig(KScreen::ConfigPtr config, QObject *parent) + : Control(parent) + , m_config(config) { // qDebug() << "Looking for control file:" << config->connectedOutputsHash(); QFile file(filePathFromHash(config->connectedOutputsHash())); @@ -214,8 +220,9 @@ m_info[QStringLiteral("outputs")] = outputsInfo; } -ControlOutput::ControlOutput(KScreen::OutputPtr output) - : m_output(output) +ControlOutput::ControlOutput(KScreen::OutputPtr output, QObject *parent) + : Control(parent) + , m_output(output) { } diff --git a/kded/config.h b/kded/config.h --- a/kded/config.h +++ b/kded/config.h @@ -22,10 +22,13 @@ #include -class Config +class ControlConfig; + +class Config : public QObject { + Q_OBJECT public: - explicit Config(KScreen::ConfigPtr config); + explicit Config(KScreen::ConfigPtr config, QObject *parent = nullptr); ~Config() = default; QString id() const; @@ -59,6 +62,7 @@ KScreen::ConfigPtr m_data; KScreen::Config::ValidityFlags m_validityFlags; + ControlConfig *m_control; static QString s_configsDirName; static QString s_fixedConfigFileName; diff --git a/kded/config.cpp b/kded/config.cpp --- a/kded/config.cpp +++ b/kded/config.cpp @@ -39,8 +39,10 @@ return Globals::dirPath() % s_configsDirName; } -Config::Config(KScreen::ConfigPtr config) - : m_data(config) +Config::Config(KScreen::ConfigPtr config, QObject *parent) + : QObject(parent) + , m_data(config) + , m_control(new ControlConfig(config, this)) { } @@ -169,7 +171,9 @@ } const KScreen::OutputList outputs = m_data->outputs(); - const auto control = ControlConfig(m_data); + // TODO: until we have the file watcher this is necessary to reload control files. + delete m_control; + m_control = new ControlConfig(m_data, this); const auto oldConfig = readFile(); KScreen::OutputList oldOutputs; @@ -215,7 +219,7 @@ setOutputConfigInfo(output->isEnabled() ? output : oldOutput); if (output->isEnabled() && - control.getOutputRetention(output->hash(), output->name()) != + m_control->getOutputRetention(output->hash(), output->name()) != Control::OutputRetention::Individual) { // try to update global output data Output::writeGlobal(output);