Changeset View
Changeset View
Standalone View
Standalone View
common/control.cpp
Show All 20 Lines | |||||
21 | #include <QJsonDocument> | 21 | #include <QJsonDocument> | ||
22 | #include <QDir> | 22 | #include <QDir> | ||
23 | 23 | | |||
24 | #include <kscreen/config.h> | 24 | #include <kscreen/config.h> | ||
25 | #include <kscreen/output.h> | 25 | #include <kscreen/output.h> | ||
26 | 26 | | |||
27 | QString Control::s_dirName = QStringLiteral("control/"); | 27 | QString Control::s_dirName = QStringLiteral("control/"); | ||
28 | 28 | | |||
29 | Control::Control(QObject *parent) | ||||
30 | : QObject(parent) | ||||
31 | { | ||||
32 | } | ||||
33 | | ||||
29 | QString Control::dirPath() const | 34 | QString Control::dirPath() const | ||
30 | { | 35 | { | ||
31 | return Globals::dirPath() % s_dirName; | 36 | return Globals::dirPath() % s_dirName; | ||
32 | } | 37 | } | ||
33 | 38 | | |||
34 | QString Control::filePathFromHash(const QString &hash) const | 39 | QString Control::filePathFromHash(const QString &hash) const | ||
35 | { | 40 | { | ||
36 | return dirPath() % hash; | 41 | return dirPath() % hash; | ||
37 | } | 42 | } | ||
38 | 43 | | |||
39 | Control::OutputRetention Control::convertVariantToOutputRetention(QVariant variant) | 44 | Control::OutputRetention Control::convertVariantToOutputRetention(QVariant variant) | ||
40 | { | 45 | { | ||
41 | if (variant.canConvert<int>()) { | 46 | if (variant.canConvert<int>()) { | ||
42 | const auto retention = variant.toInt(); | 47 | const auto retention = variant.toInt(); | ||
43 | if (retention == (int)OutputRetention::Global) { | 48 | if (retention == (int)OutputRetention::Global) { | ||
44 | return OutputRetention::Global; | 49 | return OutputRetention::Global; | ||
45 | } | 50 | } | ||
46 | if (retention == (int)OutputRetention::Individual) { | 51 | if (retention == (int)OutputRetention::Individual) { | ||
47 | return OutputRetention::Individual; | 52 | return OutputRetention::Individual; | ||
48 | } | 53 | } | ||
49 | } | 54 | } | ||
50 | return OutputRetention::Undefined; | 55 | return OutputRetention::Undefined; | ||
51 | } | 56 | } | ||
52 | 57 | | |||
53 | ControlConfig::ControlConfig(KScreen::ConfigPtr config) | 58 | ControlConfig::ControlConfig(KScreen::ConfigPtr config, QObject *parent) | ||
54 | : m_config(config) | 59 | : Control(parent) | ||
60 | , m_config(config) | ||||
55 | { | 61 | { | ||
56 | // qDebug() << "Looking for control file:" << config->connectedOutputsHash(); | 62 | // qDebug() << "Looking for control file:" << config->connectedOutputsHash(); | ||
57 | QFile file(filePathFromHash(config->connectedOutputsHash())); | 63 | QFile file(filePathFromHash(config->connectedOutputsHash())); | ||
58 | if (file.open(QIODevice::ReadOnly)) { | 64 | if (file.open(QIODevice::ReadOnly)) { | ||
59 | // This might not be reached, bus this is ok. The control file will | 65 | // This might not be reached, bus this is ok. The control file will | ||
60 | // eventually be created on first write later on. | 66 | // eventually be created on first write later on. | ||
61 | QJsonDocument parser; | 67 | QJsonDocument parser; | ||
62 | m_info = parser.fromJson(file.readAll()).toVariant().toMap(); | 68 | m_info = parser.fromJson(file.readAll()).toVariant().toMap(); | ||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Line(s) | 214 | { | |||
209 | return m_info[QStringLiteral("outputs")].toList(); | 215 | return m_info[QStringLiteral("outputs")].toList(); | ||
210 | } | 216 | } | ||
211 | 217 | | |||
212 | void ControlConfig::setOutputs(QVariantList outputsInfo) | 218 | void ControlConfig::setOutputs(QVariantList outputsInfo) | ||
213 | { | 219 | { | ||
214 | m_info[QStringLiteral("outputs")] = outputsInfo; | 220 | m_info[QStringLiteral("outputs")] = outputsInfo; | ||
215 | } | 221 | } | ||
216 | 222 | | |||
217 | ControlOutput::ControlOutput(KScreen::OutputPtr output) | 223 | ControlOutput::ControlOutput(KScreen::OutputPtr output, QObject *parent) | ||
218 | : m_output(output) | 224 | : Control(parent) | ||
225 | , m_output(output) | ||||
219 | { | 226 | { | ||
220 | } | 227 | } | ||
221 | 228 | | |||
222 | QString ControlOutput::dirPath() const | 229 | QString ControlOutput::dirPath() const | ||
223 | { | 230 | { | ||
224 | return Control::dirPath() % QStringLiteral("outputs/"); | 231 | return Control::dirPath() % QStringLiteral("outputs/"); | ||
225 | } | 232 | } | ||
226 | 233 | | |||
227 | QString ControlOutput::filePath() const | 234 | QString ControlOutput::filePath() const | ||
228 | { | 235 | { | ||
229 | if (!m_output) { | 236 | if (!m_output) { | ||
230 | return QString(); | 237 | return QString(); | ||
231 | } | 238 | } | ||
232 | return filePathFromHash(m_output->hashMd5()); | 239 | return filePathFromHash(m_output->hashMd5()); | ||
233 | } | 240 | } |