Commit e5abdd26 authored by Roman Gilg's avatar Roman Gilg
Browse files

refactor: let Control be a QObject

Summary: This is a preparatory step to add signals later for watching file changes.

Test Plan: Tested in Wayland session.

Reviewers: #plasma

Subscribers: davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26026
parent 9213a13f
......@@ -26,6 +26,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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 @@ Control::OutputRetention Control::convertVariantToOutputRetention(QVariant varia
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 @@ void ControlConfig::setOutputs(QVariantList outputsInfo)
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)
{
}
......
......@@ -22,9 +22,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QObject>
#include <QVariantMap>
class Control
class Control : public QObject
{
Q_GADGET
Q_OBJECT
public:
enum class OutputRetention {
Undefined = -1,
......@@ -33,8 +33,10 @@ public:
};
Q_ENUM(OutputRetention)
explicit Control(QObject *parent = nullptr);
virtual ~Control() = default;
~Control() override = default;
protected:
virtual QString dirPath() const;
......@@ -49,9 +51,9 @@ private:
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 @@ private:
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
......
......@@ -39,8 +39,10 @@ QString Config::configsDirPath()
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 @@ bool Config::writeFile(const QString &filePath)
}
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 @@ bool Config::writeFile(const QString &filePath)
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);
......
......@@ -22,10 +22,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <memory>
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 @@ private:
KScreen::ConfigPtr m_data;
KScreen::Config::ValidityFlags m_validityFlags;
ControlConfig *m_control;
static QString s_configsDirName;
static QString s_fixedConfigFileName;
......
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