config file!
parent
72e7875576
commit
49d01418af
10
notes
10
notes
|
@ -43,17 +43,15 @@ TODO {
|
|||
...
|
||||
}
|
||||
|
||||
- actual config file loading/saving
|
||||
color scheme load/save
|
||||
|
||||
indexer abstraction for audioports (assign/add std::pair<float, float>)
|
||||
maybe a similar abstraction for processing notes to what commandreader does
|
||||
|
||||
|
||||
- pattern folding (mode where all but every nth row is hidden (and skipped when scrolling), determined by a pattern property)
|
||||
|
||||
- extra blank row at end of pattern
|
||||
|
||||
|
||||
bugs to fix {
|
||||
it sometimes crashes on exit??
|
||||
-? it sometimes crashes on exit??
|
||||
|
||||
... does graph really need to call reset() on its children at this point
|
||||
}
|
||||
|
|
|
@ -3,5 +3,7 @@ using namespace Xybrid::Config;
|
|||
|
||||
#include <QStandardPaths>
|
||||
|
||||
const QString Directories::configFile = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation).append("/xybrid/config.json");
|
||||
|
||||
QString Directories::projects = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation).append("/xybrid/projects");
|
||||
QString Directories::presets = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation).append("/xybrid/nodes");
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
namespace Xybrid::Config {
|
||||
namespace Directories {
|
||||
const extern QString configFile;
|
||||
|
||||
extern QString projects;
|
||||
extern QString presets;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
#include <QCborArray>
|
||||
#include <QCborStreamReader>
|
||||
#include <QCborStreamWriter>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
|
||||
#include <QUndoStack>
|
||||
#include <QFileDialog>
|
||||
|
@ -288,7 +291,18 @@ std::shared_ptr<Node> FileOps::loadNode(QString fileName, std::shared_ptr<Graph>
|
|||
}
|
||||
|
||||
void FileOps::loadConfig() {
|
||||
// TODO: actually load
|
||||
QFile file(Config::Directories::configFile);
|
||||
if (file.open(QFile::ReadOnly)) { // file exists! read in
|
||||
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
|
||||
auto root = doc.object();
|
||||
file.close();
|
||||
|
||||
if (auto dirs = root["directories"].toObject(); !dirs.isEmpty()) {
|
||||
if (auto s = dirs["projects"].toString(); !s.isNull()) Config::Directories::projects = s;
|
||||
if (auto s = dirs["presets"].toString(); !s.isNull()) Config::Directories::presets = s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// make sure directories exist
|
||||
if (auto d = QDir(Config::Directories::projects); !d.exists()) d.mkpath(".");
|
||||
|
@ -296,5 +310,25 @@ void FileOps::loadConfig() {
|
|||
}
|
||||
|
||||
void FileOps::saveConfig() {
|
||||
QFileInfo fi(Config::Directories::configFile);
|
||||
fi.dir().mkpath("."); // make sure directory exists
|
||||
|
||||
QFile file(fi.filePath());
|
||||
if (!file.open(QFile::WriteOnly)) return;
|
||||
|
||||
QJsonDocument doc;
|
||||
QJsonObject root;
|
||||
|
||||
{
|
||||
QJsonObject dirs;
|
||||
|
||||
dirs["projects"] = Config::Directories::projects;
|
||||
dirs["presets"] = Config::Directories::presets;
|
||||
|
||||
root["directories"] = dirs;
|
||||
}
|
||||
|
||||
doc.setObject(root);
|
||||
file.write(doc.toJson(QJsonDocument::Indented));
|
||||
file.close();
|
||||
}
|
||||
|
|
|
@ -33,5 +33,10 @@ int main(int argc, char *argv[]) {
|
|||
auto* w = new Xybrid::MainWindow();
|
||||
w->show();
|
||||
|
||||
// hook up exit event
|
||||
QObject::connect(&a, &QCoreApplication::aboutToQuit, [] {
|
||||
Xybrid::FileOps::saveConfig();
|
||||
});
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue