Files
z-bar-qt/Plugins/ZShell/Settings/rootnode.cpp
T
zach 9ea1f846ae
C++ / fmt (pull_request) Failing after 5s
C++ / build (pull_request) Failing after 10s
C++ / clang-tidy (pull_request) Failing after 11s
JS/TS / fmt (pull_request) Successful in 9s
JS/TS / lint (pull_request) Successful in 10s
Python / static (pull_request) Successful in 34s
Rust / build (pull_request) Successful in 59s
Python / verify (pull_request) Successful in 1m48s
Rust / fmt (pull_request) Successful in 47s
Rust / clippy (pull_request) Successful in 1m6s
more unfinished changes, process tab for dashboard
2026-09-25 16:51:28 +02:00

47 lines
1.3 KiB
C++

#include "rootnode.hpp"
#include <qjsonobject.h>
namespace ZShell::settings {
RootNode::RootNode(const QString& path, RootNode* fallback, QObject* parent)
: ObjectNode(fallback, parent)
, m_file(new SettingsFile(path, this)) {
QObject::connect(batcher(), &ChangeBatcher::dirtied, this, &RootNode::saveToFile);
QObject::connect(m_file, &SettingsFile::changed, this, &RootNode::reloadFromFile);
QObject::connect(m_file, &SettingsFile::readFailed, this, [this](const QString& error) {
emit treeLoadFailed(this, error);
});
QObject::connect(m_file, &SettingsFile::writeFailed, this, [this](const QString& error) {
emit treeSaveFailed(this, error);
});
}
void RootNode::load() {
if (m_file->load() != SettingsFile::LoadResult::Changed)
reloadFromFile();
}
QList<Diagnostic> RootNode::diagnostics() const {
return m_diagnostics;
}
void RootNode::reloadFromFile() {
const auto oldDiagnostics = m_diagnostics;
m_diagnostics.clear();
const auto data = m_file->read();
syncJson(data ? data.value() : QJsonObject(), m_diagnostics);
if (m_diagnostics != oldDiagnostics)
emit diagnosticsChanged();
emit treeLoaded(this);
}
void RootNode::saveToFile() {
m_file->write(toJson());
}
} // namespace ZShell::settings