From a3eb2a9d6315f8a953f7dee72ebe4d17a4b9d42e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 11 Feb 2022 01:02:11 +0100 Subject: Add local_manga_sort_by_name and local_manga_sort_chapters_by_name config --- TODO | 3 ++- example-config.json | 4 +++- include/Config.hpp | 2 ++ src/Config.cpp | 14 +++++++++++--- src/plugins/LocalManga.cpp | 20 ++++++++++++++++---- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index 620e88f..a74fa5d 100644 --- a/TODO +++ b/TODO @@ -214,4 +214,5 @@ Use std::move(string) for all places where text.set_string is called. Use reference for text.get_string() in all places. Cleanup font sizes that are not visible (or not used for a while). Also do the same for character ranges font texture. 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. \ No newline at end of file +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). \ No newline at end of file diff --git a/example-config.json b/example-config.json index 0d76348..d4663cd 100644 --- a/example-config.json +++ b/example-config.json @@ -27,5 +27,7 @@ "scale": 1.0, "font_scale": 1.0, "spacing_scale": 1.0, - "local_manga_directory": "" + "local_manga_directory": "", + "local_manga_sort_by_name": false, + "local_manga_sort_chapters_by_name": false } \ No newline at end of file diff --git a/include/Config.hpp b/include/Config.hpp index 8430e73..522c285 100644 --- a/include/Config.hpp +++ b/include/Config.hpp @@ -47,6 +47,8 @@ namespace QuickMedia { 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 7f71f21..31da8f0 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -133,9 +133,9 @@ namespace QuickMedia { if(use_system_fonts_json.isBool()) config->use_system_fonts = use_system_fonts_json.asBool(); - const Json::Value &use_system_mpv_config = json_root["use_system_mpv_config"]; - if(use_system_mpv_config.isBool()) - config->use_system_mpv_config = use_system_mpv_config.asBool(); + const Json::Value &use_system_mpv_config_json = json_root["use_system_mpv_config"]; + if(use_system_mpv_config_json.isBool()) + config->use_system_mpv_config = use_system_mpv_config_json.asBool(); const Json::Value &theme_json = json_root["theme"]; if(theme_json.isString()) @@ -156,6 +156,14 @@ namespace QuickMedia { 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_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 &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 Config& get_config() { diff --git a/src/plugins/LocalManga.cpp b/src/plugins/LocalManga.cpp index 06b5cf0..4deb229 100644 --- a/src/plugins/LocalManga.cpp +++ b/src/plugins/LocalManga.cpp @@ -33,7 +33,7 @@ namespace QuickMedia { static std::vector get_chapters_in_manga(const Path &directory) { std::vector chapter_list; - for_files_in_dir_sort_last_modified(directory, [&chapter_list](const Path &filepath) -> bool { + auto callback = [&chapter_list](const Path &filepath) -> bool { if(get_file_type(filepath) != FileType::DIRECTORY) return true; @@ -45,13 +45,19 @@ namespace QuickMedia { chapter_list.push_back(std::move(local_manga_chapter)); return true; - }); + }; + + 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)); + return chapter_list; } static std::vector get_manga_in_directory(const Path &directory) { std::vector manga_list; - for_files_in_dir_sort_last_modified(directory, [&manga_list](const Path &filepath) -> bool { + auto callback = [&manga_list](const Path &filepath) -> bool { if(get_file_type(filepath) != FileType::DIRECTORY) return true; @@ -63,7 +69,13 @@ namespace QuickMedia { manga_list.push_back(std::move(local_manga)); return true; - }); + }; + + 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)); + return manga_list; } -- cgit v1.2.3