2 * Copyright (C) 2017 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "DisplayConfigurationStorage.h"
20#include <QStandardPaths>
22#include <QJsonDocument>
26inline QString stringFromEdid(const miral::Edid& edid)
29 str += QString::fromStdString(edid.vendor);
30 str += QString("%1%2").arg(edid.product_code).arg(edid.serial_number);
32 for (int i = 0; i < 4; i++) {
33 str += QString::fromStdString(edid.descriptors[i].string_value());
40DisplayConfigurationStorage::DisplayConfigurationStorage()
44void DisplayConfigurationStorage::save(const miral::DisplayId &displayId, const miral::DisplayConfigurationOptions &options)
46 const QString dbPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QStringLiteral("/unity8/");
47 QFile f(dbPath + stringFromEdid(displayId.edid) + ".edid");
50 if (options.used.is_set()) json.insert("used", options.used.value());
51 if (options.clone_output_index.is_set()) json.insert("clone_output_index", static_cast<int>(options.clone_output_index.value()));
52 if (options.mode.is_set()) {
53 auto const& mode = options.mode.value();
55 QString sz(QString("%1x%2").arg(mode.size.width.as_int()).arg(mode.size.height.as_int()));
56 QJsonObject jsonMode({
58 {"refresh_rate", mode.refresh_rate }
60 json.insert("mode", jsonMode);
62 if (options.orientation.is_set()) json.insert("orientation", static_cast<int>(options.orientation.value()));
63 if (options.form_factor.is_set()) json.insert("form_factor", static_cast<int>(options.form_factor.value()));
64 if (options.scale.is_set()) json.insert("scale", options.scale.value());
66 if (f.open(QIODevice::WriteOnly)) {
67 QJsonDocument saveDoc(json);
68 f.write(saveDoc.toJson());
72bool DisplayConfigurationStorage::load(const miral::DisplayId &displayId, miral::DisplayConfigurationOptions &options) const
74 const QString dbPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QStringLiteral("/unity8/");
75 QFile f(dbPath + stringFromEdid(displayId.edid) + ".edid");
77 if (f.open(QIODevice::ReadOnly)) {
78 QByteArray saveData = f.readAll();
79 QJsonDocument loadDoc(QJsonDocument::fromJson(saveData));
81 QJsonObject json(loadDoc.object());
82 if (json.contains("used")) options.used = json["used"].toBool();
83 if (json.contains("clone_output_index")) options.clone_output_index = json["clone_output_index"].toInt();
84 if (json.contains("mode")) {
85 QJsonObject jsonMode = json["mode"].toObject();
87 if (jsonMode.contains("size") && jsonMode.contains("refresh_rate")) {
88 QString sz(jsonMode["size"].toString());
89 QStringList geo = sz.split("x", QString::SkipEmptyParts);
90 if (geo.count() == 2) {
91 miral::DisplayConfigurationOptions::DisplayMode mode;
92 mode.size = mir::geometry::Size(geo[0].toInt(), geo[1].toInt());
93 mode.refresh_rate = jsonMode["refresh_rate"].toDouble();
98 if (json.contains("orientation")) options.orientation = static_cast<MirOrientation>(json["orientation"].toInt());
99 if (json.contains("form_factor")) options.form_factor = static_cast<MirFormFactor>(json["form_factor"].toInt());
100 if (json.contains("scale")) options.scale = json["form_factor"].toDouble();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list