Changeset View
Changeset View
Standalone View
Standalone View
common/control.cpp
Show All 15 Lines | |||||
16 | *********************************************************************/ | 16 | *********************************************************************/ | ||
17 | #include "control.h" | 17 | #include "control.h" | ||
18 | #include "globals.h" | 18 | #include "globals.h" | ||
19 | 19 | | |||
20 | #include <QFile> | 20 | #include <QFile> | ||
21 | #include <QJsonDocument> | 21 | #include <QJsonDocument> | ||
22 | #include <QDir> | 22 | #include <QDir> | ||
23 | 23 | | |||
24 | #include <kscreen/config.h> | ||||
25 | #include <kscreen/output.h> | ||||
26 | | ||||
24 | QString Control::s_dirName = QStringLiteral("control/"); | 27 | QString Control::s_dirName = QStringLiteral("control/"); | ||
25 | 28 | | |||
26 | QString Control::dirPath() | 29 | QString Control::dirPath() | ||
27 | { | 30 | { | ||
28 | return Globals::dirPath() % s_dirName; | 31 | return Globals::dirPath() % s_dirName; | ||
29 | } | 32 | } | ||
30 | 33 | | |||
31 | QString Control::outputFilePath(const QString &hash) | 34 | Control::OutputRetention Control::getOutputRetention(const QString &outputId, const QMap<QString, Control::OutputRetention> &retentions) | ||
32 | { | 35 | { | ||
33 | const QString dir = dirPath() % QStringLiteral("outputs/"); | 36 | if (retentions.contains(outputId)) { | ||
34 | if (!QDir().mkpath(dir)) { | 37 | return retentions[outputId]; | ||
35 | return QString(); | | |||
36 | } | 38 | } | ||
37 | return dir % hash; | 39 | // default is accessing output data globally | ||
40 | return OutputRetention::Global; | ||||
38 | } | 41 | } | ||
39 | 42 | | |||
40 | QString Control::configFilePath(const QString &hash) | 43 | ControlConfig::ControlConfig(KScreen::ConfigPtr config) | ||
44 | : m_config(config) | ||||
45 | { | ||||
46 | } | ||||
47 | | ||||
48 | QString ControlConfig::filePath(const QString &hash) | ||||
41 | { | 49 | { | ||
42 | const QString dir = dirPath() % QStringLiteral("configs/"); | 50 | const QString dir = dirPath() % QStringLiteral("configs/"); | ||
43 | if (!QDir().mkpath(dir)) { | 51 | if (!QDir().mkpath(dir)) { | ||
44 | return QString(); | 52 | return QString(); | ||
45 | } | 53 | } | ||
46 | return dir % hash; | 54 | return dir % hash; | ||
47 | } | 55 | } | ||
48 | 56 | | |||
49 | QMap<QString, Control::OutputRetention> Control::readInOutputRetentionValues(const QString &configId) | 57 | QString ControlConfig::filePath() | ||
58 | { | ||||
59 | if (!m_config) { | ||||
60 | return QString(); | ||||
61 | } | ||||
62 | return ControlConfig::filePath(m_config->connectedOutputsHash()); | ||||
63 | } | ||||
64 | | ||||
65 | QMap<QString, Control::OutputRetention> ControlConfig::readInOutputRetentionValues() | ||||
50 | { | 66 | { | ||
51 | // qDebug() << "Looking for control file:" << configId; | 67 | // qDebug() << "Looking for control file:" << configId; | ||
52 | QFile file(configFilePath(configId)); | 68 | QFile file(filePath(m_config->connectedOutputsHash())); | ||
53 | if (!file.open(QIODevice::ReadOnly)) { | 69 | if (!file.open(QIODevice::ReadOnly)) { | ||
54 | // TODO: have a logging category | 70 | // TODO: have a logging category | ||
55 | // qCDebug(KSCREEN_COMMON) << "Failed to open file" << file.fileName(); | 71 | // qCDebug(KSCREEN_COMMON) << "Failed to open file" << file.fileName(); | ||
56 | return QMap<QString, Control::OutputRetention>(); | 72 | return QMap<QString, Control::OutputRetention>(); | ||
57 | } | 73 | } | ||
58 | 74 | | |||
59 | QJsonDocument parser; | 75 | QJsonDocument parser; | ||
60 | const QVariantList outputsInfo = parser.fromJson(file.readAll()).toVariant().toList(); | 76 | const QVariantList outputsInfo = parser.fromJson(file.readAll()).toVariant().toList(); | ||
Show All 15 Lines | 79 | for (const auto variantInfo : outputsInfo) { | |||
76 | } | 92 | } | ||
77 | 93 | | |||
78 | retentions[outputHash] = retention; | 94 | retentions[outputHash] = retention; | ||
79 | } | 95 | } | ||
80 | 96 | | |||
81 | return retentions; | 97 | return retentions; | ||
82 | } | 98 | } | ||
83 | 99 | | |||
84 | Control::OutputRetention Control::getOutputRetention(const QString &outputId, const QMap<QString, Control::OutputRetention> &retentions) | 100 | ControlOutput::ControlOutput(KScreen::OutputPtr output) | ||
101 | : m_output(output) | ||||
85 | { | 102 | { | ||
86 | if (retentions.contains(outputId)) { | | |||
87 | return retentions[outputId]; | | |||
88 | } | 103 | } | ||
89 | // default is accessing output data globally | 104 | | ||
90 | return OutputRetention::Global; | 105 | QString ControlOutput::filePath(const QString &hash) | ||
106 | { | ||||
107 | const QString dir = dirPath() % QStringLiteral("outputs/"); | ||||
108 | if (!QDir().mkpath(dir)) { | ||||
109 | return QString(); | ||||
110 | } | ||||
111 | return dir % hash; | ||||
112 | } | ||||
113 | | ||||
114 | QString ControlOutput::filePath() | ||||
115 | { | ||||
116 | if (!m_output) { | ||||
117 | return QString(); | ||||
118 | } | ||||
119 | return ControlOutput::filePath(m_output->hash()); | ||||
91 | } | 120 | } |