Changeset View
Changeset View
Standalone View
Standalone View
src/configserializer.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | #include "configserializer_p.h" | 20 | #include "configserializer_p.h" | ||
21 | 21 | | |||
22 | #include "config.h" | 22 | #include "config.h" | ||
23 | #include "mode.h" | 23 | #include "mode.h" | ||
24 | #include "output.h" | 24 | #include "output.h" | ||
25 | #include "screen.h" | 25 | #include "screen.h" | ||
26 | #include "edid.h" | 26 | #include "edid.h" | ||
27 | #include "edid_p.h" | ||||
27 | #include "kscreen_debug.h" | 28 | #include "kscreen_debug.h" | ||
28 | 29 | | |||
29 | #include <QDBusArgument> | 30 | #include <QDBusArgument> | ||
30 | #include <QJsonDocument> | 31 | #include <QJsonDocument> | ||
31 | #include <QFile> | 32 | #include <QFile> | ||
32 | #include <QRect> | 33 | #include <QRect> | ||
33 | 34 | | |||
34 | using namespace KScreen; | 35 | using namespace KScreen; | ||
Show All 9 Lines | |||||
44 | QJsonObject ConfigSerializer::serializeSize(const QSize &size) | 45 | QJsonObject ConfigSerializer::serializeSize(const QSize &size) | ||
45 | { | 46 | { | ||
46 | QJsonObject obj; | 47 | QJsonObject obj; | ||
47 | obj[QLatin1String("width")] = size.width(); | 48 | obj[QLatin1String("width")] = size.width(); | ||
48 | obj[QLatin1String("height")] = size.height(); | 49 | obj[QLatin1String("height")] = size.height(); | ||
49 | return obj; | 50 | return obj; | ||
50 | } | 51 | } | ||
51 | 52 | | |||
52 | QJsonObject ConfigSerializer::serializeConfig(const ConfigPtr &config) | 53 | QJsonObject ConfigSerializer::serializeQuaternion(const QQuaternion &quaternion) | ||
54 | { | ||||
55 | QJsonObject obj; | ||||
56 | obj[QLatin1String("x")] = quaternion.x(); | ||||
57 | obj[QLatin1String("y")] = quaternion.y(); | ||||
58 | obj[QLatin1String("z")] = quaternion.z(); | ||||
59 | obj[QLatin1String("scalar")] = quaternion.scalar(); | ||||
60 | return obj; | ||||
61 | } | ||||
62 | | ||||
63 | QJsonObject ConfigSerializer::serializeConfig(const ConfigPtr &config, SerializerFlags flags) | ||||
53 | { | 64 | { | ||
54 | QJsonObject obj; | 65 | QJsonObject obj; | ||
55 | 66 | | |||
56 | if (!config) { | 67 | if (!config) { | ||
57 | return obj; | 68 | return obj; | ||
58 | } | 69 | } | ||
59 | 70 | | |||
60 | obj[QLatin1String("features")] = static_cast<int>(config->supportedFeatures()); | 71 | obj[QLatin1String("features")] = static_cast<int>(config->supportedFeatures()); | ||
61 | 72 | | |||
62 | QJsonArray outputs; | 73 | QJsonArray outputs; | ||
63 | Q_FOREACH (const OutputPtr &output, config->outputs()) { | 74 | Q_FOREACH (const OutputPtr &output, config->outputs()) { | ||
64 | outputs.append(serializeOutput(output)); | 75 | outputs.append(serializeOutput(output, flags)); | ||
65 | } | 76 | } | ||
66 | obj[QLatin1String("outputs")] = outputs; | 77 | obj[QLatin1String("outputs")] = outputs; | ||
67 | if (config->screen()) { | 78 | if (config->screen()) { | ||
68 | obj[QLatin1String("screen")] = serializeScreen(config->screen()); | 79 | obj[QLatin1String("screen")] = serializeScreen(config->screen()); | ||
69 | } | 80 | } | ||
70 | 81 | | |||
71 | return obj; | 82 | return obj; | ||
72 | } | 83 | } | ||
73 | 84 | | |||
74 | QJsonObject ConfigSerializer::serializeOutput(const OutputPtr &output) | 85 | QJsonObject ConfigSerializer::serializeOutput(const OutputPtr &output, SerializerFlags flags) | ||
75 | { | 86 | { | ||
76 | QJsonObject obj; | 87 | QJsonObject obj; | ||
77 | 88 | | |||
78 | obj[QLatin1String("id")] = output->id(); | 89 | obj[QLatin1String("id")] = output->id(); | ||
79 | obj[QLatin1String("name")] = output->name(); | 90 | obj[QLatin1String("name")] = output->name(); | ||
80 | obj[QLatin1String("type")] = static_cast<int>(output->type()); | 91 | obj[QLatin1String("type")] = static_cast<int>(output->type()); | ||
81 | obj[QLatin1String("icon")] = output->icon(); | 92 | obj[QLatin1String("icon")] = output->icon(); | ||
82 | obj[QLatin1String("pos")] = serializePoint(output->pos()); | 93 | obj[QLatin1String("pos")] = serializePoint(output->pos()); | ||
83 | obj[QLatin1String("scale")] = output->scale(); | 94 | obj[QLatin1String("scale")] = output->scale(); | ||
84 | obj[QLatin1String("size")] = serializeSize(output->size()); | 95 | obj[QLatin1String("size")] = serializeSize(output->size()); | ||
85 | obj[QLatin1String("rotation")] = static_cast<int>(output->rotation()); | 96 | obj[QLatin1String("rotation")] = static_cast<int>(output->rotation()); | ||
86 | obj[QLatin1String("currentModeId")] = output->currentModeId(); | 97 | obj[QLatin1String("currentModeId")] = output->currentModeId(); | ||
87 | obj[QLatin1String("preferredModes")] = serializeList(output->preferredModes()); | 98 | obj[QLatin1String("preferredModes")] = serializeList(output->preferredModes()); | ||
88 | obj[QLatin1String("connected")] = output->isConnected(); | 99 | obj[QLatin1String("connected")] = output->isConnected(); | ||
89 | obj[QLatin1String("followPreferredMode")] = output->followPreferredMode(); | 100 | obj[QLatin1String("followPreferredMode")] = output->followPreferredMode(); | ||
90 | obj[QLatin1String("enabled")] = output->isEnabled(); | 101 | obj[QLatin1String("enabled")] = output->isEnabled(); | ||
91 | obj[QLatin1String("primary")] = output->isPrimary(); | 102 | obj[QLatin1String("primary")] = output->isPrimary(); | ||
92 | obj[QLatin1String("clones")] = serializeList(output->clones()); | 103 | obj[QLatin1String("clones")] = serializeList(output->clones()); | ||
93 | //obj[QLatin1String("edid")] = output->edid()->raw(); | | |||
94 | obj[QLatin1String("sizeMM")] = serializeSize(output->sizeMm()); | 104 | obj[QLatin1String("sizeMM")] = serializeSize(output->sizeMm()); | ||
95 | obj[QLatin1String("replicationSource")] = output->replicationSource(); | 105 | obj[QLatin1String("replicationSource")] = output->replicationSource(); | ||
106 | if (!(flags & ExcludeEDID) && output->edid() != nullptr) { | ||||
107 | obj[QLatin1String("edid")] = serializeEdid(output->edid()); | ||||
108 | } | ||||
96 | 109 | | |||
97 | QJsonArray modes; | 110 | QJsonArray modes; | ||
98 | Q_FOREACH (const ModePtr &mode, output->modes()) { | 111 | Q_FOREACH (const ModePtr &mode, output->modes()) { | ||
99 | modes.append(serializeMode(mode)); | 112 | modes.append(serializeMode(mode)); | ||
100 | } | 113 | } | ||
101 | obj[QLatin1String("modes")] = modes; | 114 | obj[QLatin1String("modes")] = modes; | ||
102 | 115 | | |||
103 | return obj; | 116 | return obj; | ||
Show All 15 Lines | |||||
119 | { | 132 | { | ||
120 | QJsonObject obj; | 133 | QJsonObject obj; | ||
121 | 134 | | |||
122 | obj[QLatin1String("id")] = screen->id(); | 135 | obj[QLatin1String("id")] = screen->id(); | ||
123 | obj[QLatin1String("currentSize")] = serializeSize(screen->currentSize()); | 136 | obj[QLatin1String("currentSize")] = serializeSize(screen->currentSize()); | ||
124 | obj[QLatin1String("maxSize")] = serializeSize(screen->maxSize()); | 137 | obj[QLatin1String("maxSize")] = serializeSize(screen->maxSize()); | ||
125 | obj[QLatin1String("minSize")] = serializeSize(screen->minSize()); | 138 | obj[QLatin1String("minSize")] = serializeSize(screen->minSize()); | ||
126 | obj[QLatin1String("maxActiveOutputsCount")] = screen->maxActiveOutputsCount(); | 139 | obj[QLatin1String("maxActiveOutputsCount")] = screen->maxActiveOutputsCount(); | ||
140 | return obj; | ||||
141 | } | ||||
127 | 142 | | |||
143 | QJsonObject ConfigSerializer::serializeEdid(const Edid *edid) | ||||
144 | { | ||||
145 | QJsonObject obj; | ||||
146 | obj[QLatin1String("name")] = edid->name(); | ||||
147 | obj[QLatin1String("vendor")] = edid->vendor(); | ||||
148 | obj[QLatin1String("serial")] = edid->serial(); | ||||
149 | obj[QLatin1String("eisaId")] = edid->eisaId(); | ||||
150 | obj[QLatin1String("hash")] = edid->hash(); | ||||
151 | obj[QLatin1String("pnpId")] = edid->pnpId(); | ||||
152 | obj[QLatin1String("width")] = static_cast<int>(edid->width()); | ||||
153 | obj[QLatin1String("height")] = static_cast<int>(edid->height()); | ||||
154 | obj[QLatin1String("gamma")] = edid->gamma(); | ||||
155 | obj[QLatin1String("red")] = serializeQuaternion(edid->red()); | ||||
156 | obj[QLatin1String("blue")] = serializeQuaternion(edid->blue()); | ||||
157 | obj[QLatin1String("green")] = serializeQuaternion(edid->green()); | ||||
158 | obj[QLatin1String("white")] = serializeQuaternion(edid->white()); | ||||
128 | return obj; | 159 | return obj; | ||
129 | } | 160 | } | ||
130 | 161 | | |||
131 | QPoint ConfigSerializer::deserializePoint(const QDBusArgument &arg) | 162 | QPoint ConfigSerializer::deserializePoint(const QDBusArgument &arg) | ||
132 | { | 163 | { | ||
133 | int x = 0, y = 0; | 164 | int x = 0, y = 0; | ||
134 | arg.beginMap(); | 165 | arg.beginMap(); | ||
135 | while (!arg.atEnd()) { | 166 | while (!arg.atEnd()) { | ||
Show All 34 Lines | 189 | while (!arg.atEnd()) { | |||
170 | } | 201 | } | ||
171 | arg.endMapEntry(); | 202 | arg.endMapEntry(); | ||
172 | } | 203 | } | ||
173 | arg.endMap(); | 204 | arg.endMap(); | ||
174 | 205 | | |||
175 | return QSize(w, h); | 206 | return QSize(w, h); | ||
176 | } | 207 | } | ||
177 | 208 | | |||
178 | ConfigPtr ConfigSerializer::deserializeConfig(const QVariantMap &map) | 209 | QQuaternion KScreen::ConfigSerializer::deserializeQuaternion(const QDBusArgument &arg) | ||
210 | { | ||||
211 | QQuaternion quaternion; | ||||
212 | arg.beginMap(); | ||||
213 | while (!arg.atEnd()) { | ||||
214 | QString key; | ||||
215 | QVariant value; | ||||
216 | arg.beginMapEntry(); | ||||
217 | arg >> key >> value; | ||||
218 | if (key == QLatin1String("x")) { | ||||
219 | quaternion.setX(value.toFloat()); | ||||
220 | } else if (key == QLatin1String("y")) { | ||||
221 | quaternion.setY(value.toFloat()); | ||||
222 | } else if (key == QLatin1String("z")) { | ||||
223 | quaternion.setZ(value.toFloat()); | ||||
224 | } else if (key == QLatin1String("scalar")) { | ||||
225 | quaternion.setScalar(value.toFloat()); | ||||
226 | } else { | ||||
227 | qCWarning(KSCREEN) << "Invalid key in Quaternion struct:" << key; | ||||
228 | return {}; | ||||
229 | } | ||||
230 | arg.endMapEntry(); | ||||
231 | } | ||||
232 | arg.endMap(); | ||||
233 | | ||||
234 | return quaternion; | ||||
235 | } | ||||
236 | | ||||
237 | | ||||
238 | | ||||
239 | ConfigPtr ConfigSerializer::deserializeConfig(const QVariantMap &map, SerializerFlags flags) | ||||
179 | { | 240 | { | ||
180 | ConfigPtr config(new Config); | 241 | ConfigPtr config(new Config); | ||
181 | 242 | | |||
182 | if (map.contains(QLatin1String("features"))) { | 243 | if (map.contains(QLatin1String("features"))) { | ||
183 | config->setSupportedFeatures(static_cast<Config::Features>(map[QStringLiteral("features")].toInt())); | 244 | config->setSupportedFeatures(static_cast<Config::Features>(map[QStringLiteral("features")].toInt())); | ||
184 | } | 245 | } | ||
185 | 246 | | |||
186 | if (map.contains(QLatin1String("outputs"))) { | 247 | if (map.contains(QLatin1String("outputs"))) { | ||
187 | const QDBusArgument &outputsArg = map[QStringLiteral("outputs")].value<QDBusArgument>(); | 248 | const QDBusArgument &outputsArg = map[QStringLiteral("outputs")].value<QDBusArgument>(); | ||
188 | outputsArg.beginArray(); | 249 | outputsArg.beginArray(); | ||
189 | OutputList outputs; | 250 | OutputList outputs; | ||
190 | while (!outputsArg.atEnd()) { | 251 | while (!outputsArg.atEnd()) { | ||
191 | QVariant value; | 252 | QVariant value; | ||
192 | outputsArg >> value; | 253 | outputsArg >> value; | ||
193 | const KScreen::OutputPtr output = deserializeOutput(value.value<QDBusArgument>()); | 254 | const KScreen::OutputPtr output = deserializeOutput(value.value<QDBusArgument>(), flags); | ||
194 | if (!output) { | 255 | if (!output) { | ||
195 | return ConfigPtr(); | 256 | return ConfigPtr(); | ||
196 | } | 257 | } | ||
197 | outputs.insert(output->id(), output); | 258 | outputs.insert(output->id(), output); | ||
198 | } | 259 | } | ||
199 | outputsArg.endArray(); | 260 | outputsArg.endArray(); | ||
200 | config->setOutputs(outputs); | 261 | config->setOutputs(outputs); | ||
201 | } | 262 | } | ||
202 | 263 | | |||
203 | if (map.contains(QLatin1String("screen"))) { | 264 | if (map.contains(QLatin1String("screen"))) { | ||
204 | const QDBusArgument &screenArg = map[QStringLiteral("screen")].value<QDBusArgument>(); | 265 | const QDBusArgument &screenArg = map[QStringLiteral("screen")].value<QDBusArgument>(); | ||
205 | const KScreen::ScreenPtr screen = deserializeScreen(screenArg); | 266 | const KScreen::ScreenPtr screen = deserializeScreen(screenArg); | ||
206 | if (!screen) { | 267 | if (!screen) { | ||
207 | return ConfigPtr(); | 268 | return ConfigPtr(); | ||
208 | } | 269 | } | ||
209 | config->setScreen(screen); | 270 | config->setScreen(screen); | ||
210 | } | 271 | } | ||
211 | 272 | | |||
212 | return config; | 273 | return config; | ||
213 | } | 274 | } | ||
214 | 275 | | |||
215 | OutputPtr ConfigSerializer::deserializeOutput(const QDBusArgument &arg) | 276 | OutputPtr ConfigSerializer::deserializeOutput(const QDBusArgument &arg, SerializerFlags flags) | ||
216 | { | 277 | { | ||
217 | OutputPtr output(new Output); | 278 | OutputPtr output(new Output); | ||
218 | 279 | | |||
219 | arg.beginMap(); | 280 | arg.beginMap(); | ||
220 | while (!arg.atEnd()) { | 281 | while (!arg.atEnd()) { | ||
221 | QString key; | 282 | QString key; | ||
222 | QVariant value; | 283 | QVariant value; | ||
223 | arg.beginMapEntry(); | 284 | arg.beginMapEntry(); | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 324 | while (!arg.atEnd()) { | |||
266 | const KScreen::ModePtr mode = deserializeMode(value.value<QDBusArgument>()); | 327 | const KScreen::ModePtr mode = deserializeMode(value.value<QDBusArgument>()); | ||
267 | if (!mode) { | 328 | if (!mode) { | ||
268 | return OutputPtr(); | 329 | return OutputPtr(); | ||
269 | } | 330 | } | ||
270 | modes.insert(mode->id(), mode); | 331 | modes.insert(mode->id(), mode); | ||
271 | } | 332 | } | ||
272 | arg.endArray(); | 333 | arg.endArray(); | ||
273 | output->setModes(modes); | 334 | output->setModes(modes); | ||
335 | } else if (!(flags & ExcludeEDID) && key == QLatin1String("edid")) { | ||||
336 | output->setEdid(deserializeEdid(value.value<QDBusArgument>())); | ||||
274 | } else { | 337 | } else { | ||
275 | qCWarning(KSCREEN) << "Invalid key in Output map: " << key; | 338 | qCWarning(KSCREEN) << "Invalid key in Output map: " << key; | ||
276 | return OutputPtr(); | 339 | return OutputPtr(); | ||
277 | } | 340 | } | ||
278 | arg.endMapEntry(); | 341 | arg.endMapEntry(); | ||
279 | } | 342 | } | ||
280 | arg.endMap(); | 343 | arg.endMap(); | ||
281 | return output; | 344 | return output; | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 396 | } else { | |||
334 | qCWarning(KSCREEN) << "Invalid key in Screen map:" << key; | 397 | qCWarning(KSCREEN) << "Invalid key in Screen map:" << key; | ||
335 | return ScreenPtr(); | 398 | return ScreenPtr(); | ||
336 | } | 399 | } | ||
337 | arg.endMapEntry(); | 400 | arg.endMapEntry(); | ||
338 | } | 401 | } | ||
339 | arg.endMap(); | 402 | arg.endMap(); | ||
340 | return screen; | 403 | return screen; | ||
341 | } | 404 | } | ||
405 | | ||||
406 | Edid *ConfigSerializer::deserializeEdid(const QDBusArgument &arg) | ||||
407 | { | ||||
408 | auto edid = new Edid::Private; | ||||
409 | arg.beginMap(); | ||||
410 | QString key; | ||||
411 | QVariant value; | ||||
412 | while (!arg.atEnd()) { | ||||
413 | arg.beginMapEntry(); | ||||
414 | arg >> key >> value; | ||||
415 | if (key == QLatin1String("name")) { | ||||
416 | edid->monitorName = value.toString(); | ||||
417 | } else if (key == QLatin1String("vendor")) { | ||||
418 | edid->vendorName = value.toString(); | ||||
419 | } else if (key == QLatin1String("serial")) { | ||||
420 | edid->serialNumber = value.toString(); | ||||
421 | } else if (key == QLatin1String("eisaId")) { | ||||
422 | edid->eisaId = value.toString(); | ||||
423 | } else if (key == QLatin1String("hash")) { | ||||
424 | edid->checksum = value.toString(); | ||||
425 | } else if (key == QLatin1String("pnpId")) { | ||||
426 | edid->pnpId = value.toString(); | ||||
427 | } else if (key == QLatin1String("width")) { | ||||
428 | edid->width = static_cast<uint>(value.toInt()); | ||||
429 | } else if (key == QLatin1String("height")) { | ||||
430 | edid->height = static_cast<uint>(value.toInt()); | ||||
431 | } else if (key == QLatin1String("gamma")) { | ||||
432 | edid->gamma = value.toReal(); | ||||
433 | } else if (key == QLatin1String("red")) { | ||||
434 | edid->red = deserializeQuaternion(value.value<QDBusArgument>()); | ||||
435 | } else if (key == QLatin1String("blue")) { | ||||
436 | edid->blue = deserializeQuaternion(value.value<QDBusArgument>()); | ||||
437 | } else if (key == QLatin1String("green")) { | ||||
438 | edid->green = deserializeQuaternion(value.value<QDBusArgument>()); | ||||
439 | } else if (key == QLatin1String("white")) { | ||||
440 | edid->white = deserializeQuaternion(value.value<QDBusArgument>()); | ||||
441 | } else { | ||||
442 | qCWarning(KSCREEN) << "Invalid key in Edid map:" << key; | ||||
443 | delete edid; | ||||
444 | return {}; | ||||
445 | } | ||||
446 | arg.endMapEntry(); | ||||
447 | } | ||||
448 | arg.endMap(); | ||||
449 | | ||||
450 | edid->valid = true; | ||||
451 | return new Edid(edid); | ||||
452 | } |