feat: initial database creation, loading
fixes for cartographer and automatically add track to album when adding to artist
This commit is contained in:
parent
72bbcaba9e
commit
62c99ee67c
18 changed files with 515 additions and 108 deletions
|
@ -2,18 +2,60 @@
|
|||
|
||||
#include <QDir>
|
||||
#include <QStandardPaths>
|
||||
#include <QTextStream>
|
||||
#include <filesystem>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
KotoConfig::KotoConfig() {
|
||||
// Define our application's config location
|
||||
auto configDir = QDir(QStandardPaths::writableLocation(QStandardPaths::StandardLocation::AppConfigLocation));
|
||||
auto configDirPath = configDir.absolutePath();
|
||||
auto configDir = QDir(QStandardPaths::writableLocation(QStandardPaths::StandardLocation::AppConfigLocation));
|
||||
auto configDirPath = configDir.absolutePath();
|
||||
this->i_configDirPath = configDirPath;
|
||||
this->i_libraries = QList<KotoLibraryConfig*>();
|
||||
|
||||
fs::path filePath {};
|
||||
auto configPathStd = configDirPath.toStdString();
|
||||
filePath /= configPathStd;
|
||||
filePath /= "config.toml";
|
||||
this->i_configPath = QString {filePath.c_str()};
|
||||
|
||||
if (QFileInfo::exists(i_configPath)) {
|
||||
this->parseConfigFile(filePath);
|
||||
} else {
|
||||
this->bootstrap();
|
||||
}
|
||||
}
|
||||
|
||||
KotoConfig& KotoConfig::instance() {
|
||||
static KotoConfig _instance;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
void KotoConfig::bootstrap() {
|
||||
this->i_uiPreferences = new KotoUiPreferences();
|
||||
|
||||
auto musicDir = QDir(QStandardPaths::writableLocation(QStandardPaths::StandardLocation::MusicLocation));
|
||||
auto musicLibrary = new KotoLibraryConfig("Music", musicDir.absolutePath().toStdString(), KotoLibraryType::Music);
|
||||
|
||||
this->i_libraries.append(musicLibrary);
|
||||
|
||||
this->save();
|
||||
}
|
||||
|
||||
QString KotoConfig::getConfigDirPath() {
|
||||
return QString {this->i_configDirPath};
|
||||
}
|
||||
|
||||
KotoUiPreferences* KotoConfig::getUiPreferences() {
|
||||
return this->i_uiPreferences;
|
||||
}
|
||||
|
||||
QList<KotoLibraryConfig*> KotoConfig::getLibraries() {
|
||||
return this->i_libraries;
|
||||
}
|
||||
|
||||
void KotoConfig::parseConfigFile(std::string filePath) {
|
||||
auto data = toml::parse(filePath);
|
||||
std::optional<toml::value> ui_prefs;
|
||||
|
||||
|
@ -22,22 +64,35 @@ KotoConfig::KotoConfig() {
|
|||
if (ui_prefs_at.is_table()) ui_prefs = ui_prefs_at.as_table();
|
||||
}
|
||||
|
||||
auto prefs = KotoUiPreferences(ui_prefs);
|
||||
this->i_uiPreferences = &prefs;
|
||||
auto prefs = new 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);
|
||||
auto lib = new KotoLibraryConfig(lib_value);
|
||||
this->i_libraries.append(lib);
|
||||
}
|
||||
}
|
||||
|
||||
KotoConfig::~KotoConfig() {}
|
||||
void KotoConfig::save() {
|
||||
toml::ordered_value config_table(toml::ordered_table {});
|
||||
config_table["preferences.ui"] = this->i_uiPreferences->serialize();
|
||||
|
||||
KotoUiPreferences* KotoConfig::getUiPreferences() {
|
||||
return this->i_uiPreferences;
|
||||
}
|
||||
toml::ordered_value libraries_array(toml::ordered_array {});
|
||||
for (auto lib : this->i_libraries) {
|
||||
auto lib_table = lib->serialize();
|
||||
libraries_array.push_back(lib_table);
|
||||
}
|
||||
config_table["libraries"] = libraries_array;
|
||||
|
||||
std::vector<KotoLibraryConfig> KotoConfig::getLibraries() {
|
||||
return this->i_libraries;
|
||||
auto configContent = toml::format(config_table);
|
||||
|
||||
auto config_dir = QDir {this->i_configDirPath};
|
||||
if (!config_dir.exists()) config_dir.mkpath(".");
|
||||
auto config_file = QFile {this->i_configPath};
|
||||
|
||||
auto out = QTextStream {&config_file};
|
||||
if (config_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
out << configContent.c_str();
|
||||
config_file.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue