Files
z-bar-qt/Plugins/ZShell/Services/desktopstatemanager.cpp
AramJonghu 467e44bb9f
C++ / build (pull_request) Failing after 15s
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 28s
Python / lint-format (pull_request) Successful in 45s
Python / test (pull_request) Successful in 38s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m45s
tidy&format(all): all files formatted and relevant warnings resolved
2026-06-30 02:04:24 +02:00

58 lines
1.3 KiB
C++

#include "desktopstatemanager.hpp"
#include <QStandardPaths>
#include <QDir>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QDebug>
#include <QJsonArray>
namespace ZShell::services {
DesktopStateManager::DesktopStateManager(QObject* parent) : QObject(parent) {}
QString DesktopStateManager::getConfigFilePath() const {
QString configDir =
QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) +
"/zshell";
QDir dir(configDir);
if (!dir.exists()) {
dir.mkpath(".");
}
return configDir + "/desktop_layout.json";
}
void DesktopStateManager::saveLayout(const QVariantMap& layout) {
QJsonObject jsonObj = QJsonObject::fromVariantMap(layout);
QJsonDocument doc(jsonObj);
QFile file(getConfigFilePath());
if (file.open(QIODevice::WriteOnly)) {
file.write(doc.toJson(QJsonDocument::Indented));
file.close();
} else {
qWarning() << "zshell: Cannot save desktop layout to"
<< getConfigFilePath();
}
}
QVariantMap DesktopStateManager::getLayout() {
QFile file(getConfigFilePath());
if (!file.open(QIODevice::ReadOnly)) {
return QVariantMap();
}
QByteArray data = file.readAll();
file.close();
QJsonDocument doc = QJsonDocument::fromJson(data);
if (doc.isObject()) {
return doc.object().toVariantMap();
}
return QVariantMap();
}
} // namespace ZShell::services