aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-02-16 02:24:28 +0100
committerdec05eba <dec05eba@protonmail.com>2022-02-16 02:24:28 +0100
commitd89ea960364f6518f412897d0601a1161b5aee6a (patch)
treeddb96665dc92ee4bae24bd7bbf14d3e709a6219e /src
parent2030684b16004a4f6c60f499584366ae5ad57bc9 (diff)
local_manga: move local manga config from local_manga_... to local_manga. object
Diffstat (limited to 'src')
-rw-r--r--src/Config.cpp23
-rw-r--r--src/QuickMedia.cpp2
-rw-r--r--src/plugins/LocalManga.cpp20
3 files changed, 25 insertions, 20 deletions
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;