Changeset View
Changeset View
Standalone View
Standalone View
kded/config.cpp
Show All 11 Lines | |||||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. | ||
14 | 14 | | |||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | *********************************************************************/ | 17 | *********************************************************************/ | ||
18 | #include "config.h" | 18 | #include "config.h" | ||
19 | #include "output.h" | 19 | #include "output.h" | ||
20 | #include "control.h" | ||||
20 | #include "kscreen_daemon_debug.h" | 21 | #include "kscreen_daemon_debug.h" | ||
21 | #include "device.h" | 22 | #include "device.h" | ||
22 | 23 | | |||
23 | #include <QFile> | 24 | #include <QFile> | ||
24 | #include <QStandardPaths> | 25 | #include <QStandardPaths> | ||
25 | #include <QRect> | 26 | #include <QRect> | ||
26 | #include <QJsonDocument> | 27 | #include <QJsonDocument> | ||
27 | #include <QDir> | 28 | #include <QDir> | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 96 | { | |||
99 | return config; | 100 | return config; | ||
100 | } | 101 | } | ||
101 | 102 | | |||
102 | std::unique_ptr<Config> Config::readFile(const QString &fileName) | 103 | std::unique_ptr<Config> Config::readFile(const QString &fileName) | ||
103 | { | 104 | { | ||
104 | if (!m_data) { | 105 | if (!m_data) { | ||
105 | return nullptr; | 106 | return nullptr; | ||
106 | } | 107 | } | ||
107 | KScreen::ConfigPtr config = m_data->clone(); | 108 | auto config = std::unique_ptr<Config>(new Config(m_data->clone())); | ||
109 | config->setValidityFlags(m_validityFlags); | ||||
108 | 110 | | |||
109 | QFile file; | 111 | QFile file; | ||
110 | if (QFile::exists(configsDirPath() % s_fixedConfigFileName)) { | 112 | if (QFile::exists(configsDirPath() % s_fixedConfigFileName)) { | ||
111 | file.setFileName(configsDirPath() % s_fixedConfigFileName); | 113 | file.setFileName(configsDirPath() % s_fixedConfigFileName); | ||
112 | qCDebug(KSCREEN_KDED) << "found a fixed config, will use " << file.fileName(); | 114 | qCDebug(KSCREEN_KDED) << "found a fixed config, will use " << file.fileName(); | ||
113 | } else { | 115 | } else { | ||
114 | file.setFileName(configsDirPath() % fileName); | 116 | file.setFileName(configsDirPath() % fileName); | ||
115 | } | 117 | } | ||
116 | if (!file.open(QIODevice::ReadOnly)) { | 118 | if (!file.open(QIODevice::ReadOnly)) { | ||
117 | qCDebug(KSCREEN_KDED) << "failed to open file" << file.fileName(); | 119 | qCDebug(KSCREEN_KDED) << "failed to open file" << file.fileName(); | ||
118 | return nullptr; | 120 | return nullptr; | ||
119 | } | 121 | } | ||
120 | 122 | | |||
121 | QJsonDocument parser; | 123 | QJsonDocument parser; | ||
122 | QVariantList outputs = parser.fromJson(file.readAll()).toVariant().toList(); | 124 | QVariantList outputs = parser.fromJson(file.readAll()).toVariant().toList(); | ||
123 | Output::readInOutputs(config->outputs(), outputs); | 125 | Output::readInOutputs(config->data()->outputs(), outputs, Control::readInOutputRetentionValues(config->id())); | ||
124 | 126 | | |||
125 | QSize screenSize; | 127 | QSize screenSize; | ||
126 | for (const auto &output : config->outputs()) { | 128 | for (const auto &output : config->data()->outputs()) { | ||
127 | if (!output->isConnected() || !output->isEnabled()) { | 129 | if (!output->isConnected() || !output->isEnabled()) { | ||
128 | continue; | 130 | continue; | ||
129 | } | 131 | } | ||
130 | 132 | | |||
131 | const QRect geom = output->geometry(); | 133 | const QRect geom = output->geometry(); | ||
132 | if (geom.x() + geom.width() > screenSize.width()) { | 134 | if (geom.x() + geom.width() > screenSize.width()) { | ||
133 | screenSize.setWidth(geom.x() + geom.width()); | 135 | screenSize.setWidth(geom.x() + geom.width()); | ||
134 | } | 136 | } | ||
135 | if (geom.y() + geom.height() > screenSize.height()) { | 137 | if (geom.y() + geom.height() > screenSize.height()) { | ||
136 | screenSize.setHeight(geom.y() + geom.height()); | 138 | screenSize.setHeight(geom.y() + geom.height()); | ||
137 | } | 139 | } | ||
138 | } | 140 | } | ||
139 | config->screen()->setCurrentSize(screenSize); | 141 | config->data()->screen()->setCurrentSize(screenSize); | ||
140 | 142 | | |||
141 | if (!canBeApplied(config)) { | 143 | if (!canBeApplied(config->data())) { | ||
142 | return nullptr; | 144 | return nullptr; | ||
143 | } | 145 | } | ||
144 | auto cfg = std::unique_ptr<Config>(new Config(config)); | 146 | return config; | ||
145 | cfg->setValidityFlags(m_validityFlags); | | |||
146 | return cfg; | | |||
147 | } | 147 | } | ||
148 | 148 | | |||
149 | bool Config::canBeApplied() const | 149 | bool Config::canBeApplied() const | ||
150 | { | 150 | { | ||
151 | return canBeApplied(m_data); | 151 | return canBeApplied(m_data); | ||
152 | } | 152 | } | ||
153 | 153 | | |||
154 | bool Config::canBeApplied(KScreen::ConfigPtr config) const | 154 | bool Config::canBeApplied(KScreen::ConfigPtr config) const | ||
Show All 13 Lines | |||||
168 | 168 | | |||
169 | bool Config::writeOpenLidFile() | 169 | bool Config::writeOpenLidFile() | ||
170 | { | 170 | { | ||
171 | return writeFile(filePath() % QStringLiteral("_lidOpened")); | 171 | return writeFile(filePath() % QStringLiteral("_lidOpened")); | ||
172 | } | 172 | } | ||
173 | 173 | | |||
174 | bool Config::writeFile(const QString &filePath) | 174 | bool Config::writeFile(const QString &filePath) | ||
175 | { | 175 | { | ||
176 | if (!m_data) { | 176 | if (id().isEmpty()) { | ||
177 | return false; | 177 | return false; | ||
178 | } | 178 | } | ||
179 | const KScreen::OutputList outputs = m_data->outputs(); | 179 | const KScreen::OutputList outputs = m_data->outputs(); | ||
180 | 180 | | |||
181 | const auto retentions = Control::readInOutputRetentionValues(id()); | ||||
182 | | ||||
181 | QVariantList outputList; | 183 | QVariantList outputList; | ||
182 | Q_FOREACH(const KScreen::OutputPtr &output, outputs) { | 184 | Q_FOREACH(const KScreen::OutputPtr &output, outputs) { | ||
183 | QVariantMap info; | 185 | QVariantMap info; | ||
184 | 186 | | |||
185 | if (!output->isConnected()) { | 187 | if (!output->isConnected()) { | ||
186 | continue; | 188 | continue; | ||
187 | } | 189 | } | ||
188 | if (!Output::writeGlobalPart(output, info)) { | 190 | if (!Output::writeGlobalPart(output, info)) { | ||
189 | continue; | 191 | continue; | ||
190 | } | 192 | } | ||
191 | 193 | | |||
192 | info[QStringLiteral("primary")] = output->isPrimary(); | 194 | info[QStringLiteral("primary")] = output->isPrimary(); | ||
193 | info[QStringLiteral("enabled")] = output->isEnabled(); | 195 | info[QStringLiteral("enabled")] = output->isEnabled(); | ||
194 | 196 | | |||
195 | QVariantMap pos; | 197 | QVariantMap pos; | ||
196 | pos[QStringLiteral("x")] = output->pos().x(); | 198 | pos[QStringLiteral("x")] = output->pos().x(); | ||
197 | pos[QStringLiteral("y")] = output->pos().y(); | 199 | pos[QStringLiteral("y")] = output->pos().y(); | ||
198 | info[QStringLiteral("pos")] = pos; | 200 | info[QStringLiteral("pos")] = pos; | ||
199 | 201 | | |||
202 | if (Control::getOutputRetention(output->hash(), retentions) != Control::OutputRetention::Individual) { | ||||
200 | // try to update global output data | 203 | // try to update global output data | ||
201 | Output::writeGlobal(output); | 204 | Output::writeGlobal(output); | ||
205 | } | ||||
202 | 206 | | |||
203 | outputList.append(info); | 207 | outputList.append(info); | ||
204 | } | 208 | } | ||
205 | 209 | | |||
206 | QFile file(filePath); | 210 | QFile file(filePath); | ||
207 | if (!file.open(QIODevice::WriteOnly)) { | 211 | if (!file.open(QIODevice::WriteOnly)) { | ||
208 | qCWarning(KSCREEN_KDED) << "Failed to open config file for writing! " << file.errorString(); | 212 | qCWarning(KSCREEN_KDED) << "Failed to open config file for writing! " << file.errorString(); | ||
209 | return false; | 213 | return false; | ||
Show All 19 Lines |