From 996e5c02ca6f24f54e671a321e5f48f16f59836d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 2 Mar 2022 22:40:55 +0100 Subject: Allow using ~ and $HOME in config paths --- TODO | 1 - src/Config.cpp | 13 +++++++++++-- src/Theme.cpp | 4 +--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 6bf6e24..258c6ca 100644 --- a/TODO +++ b/TODO @@ -208,7 +208,6 @@ Cleanup font sizes that are not visible (or not used for a while). Also do the s Show video upload date in video description on youtube. Add latest read chapter name to manga progress, to easily see from manga list page how we have progressed in the manga. Allow changing manga sorting in gui (especially for local manga). -Allow using ~ and $HOME in config file. Save manga "I" mode to file and load it on startup. Show in bookmarks and history page if a manga has been read (local-manga). Add "finished reading" to online manga as well, for the manga sites that publish latest chapter in the search page. diff --git a/src/Config.cpp b/src/Config.cpp index 7ddc1af..a1752b1 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -53,6 +53,15 @@ namespace QuickMedia { return scale; } + static std::string path_expanduser(const std::string &path) { + std::string result; + if(!path.empty() && path[0] == '~') + result = get_home_dir().data + path.substr(1); + else + result = path; + return result; + } + // No-op if this has already been called before static void init_config() { if(config_initialized) @@ -135,7 +144,7 @@ namespace QuickMedia { if(local_manga_json.isObject()) { const Json::Value &directory_json = local_manga_json["directory"]; if(directory_json.isString()) { - config->local_manga.directory = directory_json.asString(); + config->local_manga.directory = path_expanduser(directory_json.asString()); while(config->local_manga.directory.size() > 1 && config->local_manga.directory.back() == '/') { config->local_manga.directory.pop_back(); } @@ -154,7 +163,7 @@ namespace QuickMedia { if(local_anime_json.isObject()) { const Json::Value &directory_json = local_anime_json["directory"]; if(directory_json.isString()) { - config->local_anime.directory = directory_json.asString(); + config->local_anime.directory = path_expanduser(directory_json.asString()); while(config->local_anime.directory.size() > 1 && config->local_anime.directory.back() == '/') { config->local_anime.directory.pop_back(); } diff --git a/src/Theme.cpp b/src/Theme.cpp index 8320054..9f525d5 100644 --- a/src/Theme.cpp +++ b/src/Theme.cpp @@ -13,7 +13,7 @@ namespace QuickMedia { if(read_file_as_json(config_path, json_root) && json_root.isObject()) return true; - config_path = Path("/usr/share/quickmedia/themes/").join(theme_name).append(".json"); + config_path = Path("/usr/share/quickmedia/themes").join(theme_name).append(".json"); if(read_file_as_json(config_path, json_root) && json_root.isObject()) return true; @@ -63,8 +63,6 @@ namespace QuickMedia { fprintf(stderr, "Warning: theme variable \"%s\" is an invalid color value. Expected #RRGGBB or #RRGGBBAA, was: %s\n", field_name, color_str); return; } - - // TODO: Test on big endian systems (&new_color.r)[(i - 1)/2] = (c1 << 4) | c2; } color = new_color; -- cgit v1.2.3