diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-02-16 02:24:28 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-02-16 02:24:28 +0100 |
commit | d89ea960364f6518f412897d0601a1161b5aee6a (patch) | |
tree | ddb96665dc92ee4bae24bd7bbf14d3e709a6219e | |
parent | 2030684b16004a4f6c60f499584366ae5ad57bc9 (diff) |
local_manga: move local manga config from local_manga_... to local_manga. object
-rw-r--r-- | example-config.json | 10 | ||||
-rw-r--r-- | include/Config.hpp | 10 | ||||
-rw-r--r-- | src/Config.cpp | 23 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 2 | ||||
-rw-r--r-- | src/plugins/LocalManga.cpp | 20 |
5 files changed, 38 insertions, 27 deletions
diff --git a/example-config.json b/example-config.json index d4663cd..566bbae 100644 --- a/example-config.json +++ b/example-config.json @@ -21,13 +21,15 @@ "video": { "max_height": 2160 }, + "local_manga": { + "directory": "", + "sort_by_name": false, + "sort_chapters_by_name": false + }, "use_system_fonts": false, "use_system_mpv_config": false, "theme": "default", "scale": 1.0, "font_scale": 1.0, - "spacing_scale": 1.0, - "local_manga_directory": "", - "local_manga_sort_by_name": false, - "local_manga_sort_chapters_by_name": false + "spacing_scale": 1.0 }
\ No newline at end of file diff --git a/include/Config.hpp b/include/Config.hpp index 522c285..b2abbf1 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -30,6 +30,12 @@ namespace QuickMedia { int max_height = 0; }; + struct LocalMangaConfig { + std::string directory; + bool sort_by_name = false; + bool sort_chapters_by_name = false; + }; + struct Config { Config() = default; Config(const Config&) = delete; @@ -40,15 +46,13 @@ namespace QuickMedia { BodyConfig body; InputConfig input; VideoConfig video; + LocalMangaConfig local_manga; bool use_system_fonts = false; bool use_system_mpv_config = false; std::string theme = "default"; float scale = 1.0f; float font_scale = 1.0f; float spacing_scale = 1.0f; - std::string local_manga_directory; - bool local_manga_sort_by_name = false; - bool local_manga_sort_chapters_by_name = false; }; const Config& get_config(); diff --git a/src/Config.cpp b/src/Config.cpp index 31da8f0..780bf32 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -4,6 +4,8 @@ #include <assert.h> #include <X11/Xlib.h> +// TODO: Show nice error message if config looks wrong (wrong types, has configs that do not exist (maybe spelling mistake?)) + namespace QuickMedia { static bool config_initialized = false; static Config *config = nullptr; @@ -153,17 +155,20 @@ namespace QuickMedia { if(spacing_scale.isNumeric()) config->spacing_scale = spacing_scale.asFloat(); - const Json::Value &local_manga_directory_json = json_root["local_manga_directory"]; - if(local_manga_directory_json.isString()) - config->local_manga_directory = local_manga_directory_json.asString(); + const Json::Value &local_manga_json = json_root["local_manga"]; + 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(); - const Json::Value &local_manga_sort_by_name_json = json_root["local_manga_sort_by_name"]; - if(local_manga_sort_by_name_json.isBool()) - config->local_manga_sort_by_name = local_manga_sort_by_name_json.asBool(); + const Json::Value &sort_by_name_json = local_manga_json["sort_by_name"]; + if(sort_by_name_json.isBool()) + config->local_manga.sort_by_name = sort_by_name_json.asBool(); - const Json::Value &local_manga_sort_chapters_by_name_json = json_root["local_manga_sort_chapters_by_name"]; - if(local_manga_sort_chapters_by_name_json.isBool()) - config->local_manga_sort_chapters_by_name = local_manga_sort_chapters_by_name_json.asBool(); + const Json::Value &sort_chapters_by_name_json = local_manga_json["sort_chapters_by_name"]; + if(sort_chapters_by_name_json.isBool()) + config->local_manga.sort_chapters_by_name = sort_chapters_by_name_json.asBool(); + } } const Config& get_config() { diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 35efd8d..e317ce3 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1112,7 +1112,7 @@ namespace QuickMedia { pages.push_back({std::move(readm), "Readm", "readm"}); pages.push_back({std::move(mangadex), "Mangadex", "mangadex"}); - if(!get_config().local_manga_directory.empty()) + if(!get_config().local_manga.directory.empty()) pages.push_back({std::move(local_manga), "Local manga", "local-manga", true}); tabs.push_back(Tab{create_body(), std::make_unique<MangaCombinedSearchPage>(this, std::move(pages)), create_search_bar("Search...", 400)}); diff --git a/src/plugins/LocalManga.cpp b/src/plugins/LocalManga.cpp index 8ab8cd1..4367401 100644 --- a/src/plugins/LocalManga.cpp +++ b/src/plugins/LocalManga.cpp @@ -131,7 +131,7 @@ namespace QuickMedia { return only_include_latest ? false : true; }; - if(get_config().local_manga_sort_chapters_by_name) + if(get_config().local_manga.sort_chapters_by_name) for_files_in_dir_sort_name(directory, std::move(callback), FileSortDirection::DESC); else for_files_in_dir_sort_last_modified(directory, std::move(callback)); @@ -155,7 +155,7 @@ namespace QuickMedia { return true; }; - if(get_config().local_manga_sort_by_name) + if(get_config().local_manga.sort_by_name) for_files_in_dir_sort_name(directory, std::move(callback), FileSortDirection::ASC); else for_files_in_dir_sort_last_modified(directory, std::move(callback)); @@ -164,13 +164,13 @@ namespace QuickMedia { } static bool validate_local_manga_dir_config_is_set() { - if(get_config().local_manga_directory.empty()) { - show_notification("QuickMedia", "local_manga_directory config is not set", Urgency::CRITICAL); + if(get_config().local_manga.directory.empty()) { + show_notification("QuickMedia", "local_manga.directory config is not set", Urgency::CRITICAL); return false; } - if(get_file_type(get_config().local_manga_directory) != FileType::DIRECTORY) { - show_notification("QuickMedia", "local_manga_directory config is not set to a valid directory", Urgency::CRITICAL); + if(get_file_type(get_config().local_manga.directory) != FileType::DIRECTORY) { + show_notification("QuickMedia", "local_manga.directory config is not set to a valid directory", Urgency::CRITICAL); return false; } @@ -187,7 +187,7 @@ namespace QuickMedia { if(!validate_local_manga_dir_config_is_set()) return false; - Path manga_url = Path(get_config().local_manga_directory).join(manga_name); + Path manga_url = Path(get_config().local_manga.directory).join(manga_name); std::vector<LocalMangaChapter> chapters = get_chapters_in_manga(manga_name, manga_url, true, true); if(chapters.empty() || chapters.front().pages.empty()) return false; @@ -337,7 +337,7 @@ namespace QuickMedia { if(!validate_local_manga_dir_config_is_set()) return PluginResult::OK; - Path manga_url = Path(get_config().local_manga_directory).join(args.url); + Path manga_url = Path(get_config().local_manga.directory).join(args.url); std::vector<LocalMangaChapter> chapters = get_chapters_in_manga(args.url, manga_url, false, false); auto manga_it = std::find_if(manga_list.begin(), manga_list.end(), [&args](const LocalManga &local_manga) { @@ -374,7 +374,7 @@ namespace QuickMedia { if(!validate_local_manga_dir_config_is_set()) return PluginResult::OK; - manga_list = get_manga_in_directory(get_config().local_manga_directory, true); + manga_list = get_manga_in_directory(get_config().local_manga.directory, true); if(standalone) finished_reading_manga = get_manga_finished_reading(manga_list); @@ -475,7 +475,7 @@ namespace QuickMedia { ImageResult LocalMangaImagesPage::update_image_urls(int &num_images) { num_images = 0; - Path chapter_url = Path(get_config().local_manga_directory).join(manga_name).join(url); + Path chapter_url = Path(get_config().local_manga.directory).join(manga_name).join(url); std::vector<LocalMangaPage> pages = get_images_in_manga(chapter_url); if(pages.empty()) return ImageResult::ERR; |