2024-09-29 17:29:10 +03:00
|
|
|
#include "config.hpp"
|
2024-10-02 17:51:51 +03:00
|
|
|
|
2024-09-29 17:29:10 +03:00
|
|
|
#include <QDir>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <filesystem>
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
|
|
|
KotoConfig::KotoConfig() {
|
2024-10-02 17:51:51 +03:00
|
|
|
// Define our application's config location
|
|
|
|
auto configDir = QDir(QStandardPaths::writableLocation(QStandardPaths::StandardLocation::AppConfigLocation));
|
|
|
|
auto configDirPath = configDir.absolutePath();
|
|
|
|
fs::path filePath {};
|
|
|
|
auto configPathStd = configDirPath.toStdString();
|
|
|
|
filePath /= configPathStd;
|
|
|
|
filePath /= "config.toml";
|
|
|
|
|
|
|
|
auto data = toml::parse(filePath);
|
|
|
|
std::optional<toml::value> ui_prefs;
|
|
|
|
|
|
|
|
if (data.contains("preferences.ui")) {
|
|
|
|
auto ui_prefs_at = data.at("preferences.ui");
|
|
|
|
if (ui_prefs_at.is_table()) ui_prefs = ui_prefs_at.as_table();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto prefs = KotoUiPreferences(ui_prefs);
|
|
|
|
this->i_uiPreferences = &prefs;
|
|
|
|
|
|
|
|
this->i_libraries = {};
|
|
|
|
for (const auto& lib_value : toml::find<std::vector<toml::value>>(data, "libraries")) {
|
|
|
|
auto lib = KotoLibraryConfig(lib_value);
|
|
|
|
this->i_libraries.push_back(lib);
|
|
|
|
}
|
2024-09-29 17:29:10 +03:00
|
|
|
}
|
|
|
|
|
2024-10-02 17:51:51 +03:00
|
|
|
KotoConfig::~KotoConfig() {}
|
|
|
|
|
|
|
|
KotoUiPreferences* KotoConfig::getUiPreferences() {
|
|
|
|
return this->i_uiPreferences;
|
2024-09-29 17:29:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<KotoLibraryConfig> KotoConfig::getLibraries() {
|
2024-10-02 17:51:51 +03:00
|
|
|
return this->i_libraries;
|
2024-09-29 17:29:10 +03:00
|
|
|
}
|