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 "ScreensConfiguration.h"
20#include "WorkspaceManager.h"
23#include <QJsonDocument>
26#include <QStandardPaths>
30QJsonArray jsonScreens;
33ScreensConfiguration::ScreensConfiguration()
35 const QString dbPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QStringLiteral("/unity8/");
36 QFile f(dbPath + "workspaces");
38 if (f.open(QIODevice::ReadOnly)) {
39 QByteArray saveData = f.readAll();
40 QJsonDocument loadDoc(QJsonDocument::fromJson(saveData));
41 QJsonObject json(loadDoc.object());
42 jsonScreens = json["screens"].toArray();
46ScreensConfiguration::~ScreensConfiguration()
48 const QString dbPath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QStringLiteral("/unity8/");
49 QFile f(dbPath + "workspaces");
50 if (f.open(QIODevice::WriteOnly)) {
52 json["screens"] = jsonScreens;
53 QJsonDocument saveDoc(json);
54 f.write(saveDoc.toJson());
58void ScreensConfiguration::load(Screen *screen)
61 for (auto iter = jsonScreens.begin(); iter != jsonScreens.end(); ++iter) {
62 QJsonObject jsonScreen = (*iter).toObject();
63 if (jsonScreen["name"] == screen->name()) {
64 QJsonValue jsonWorkspaces = jsonScreen["workspaces"];
65 workspaces = jsonWorkspaces.toInt(workspaces);
70 for (int i = 0; i < workspaces; i++) {
71 WorkspaceManager::instance()->createWorkspace()->assign(screen->workspaces());
75void ScreensConfiguration::save(Screen *screen)
77 QJsonObject newJsonScreen;
78 newJsonScreen["name"] = screen->name();
79 newJsonScreen["workspaces"] = screen->workspaces()->rowCount();
81 auto iter = jsonScreens.begin();
82 for (; iter != jsonScreens.end(); ++iter) {
83 QJsonObject jsonScreen = (*iter).toObject();
84 if (jsonScreen["name"] == screen->name()) {
89 if (iter == jsonScreens.end()) {
90 jsonScreens.push_back(newJsonScreen);
92 *iter = newJsonScreen;
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