diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-08-17 14:55:10 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-08-17 14:55:10 +0200 |
commit | df95eccc5e8ef62ad9c83a925adc83926491dfb3 (patch) | |
tree | 324ce8c2f204f55a4758c93c1110bb4e395159d8 | |
parent | 37e0de2d586099fba5736b13dfb945db5f54fe94 (diff) |
AniList: separate anime and manga searches to different tabs
-rw-r--r-- | plugins/AniList.hpp | 11 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 3 | ||||
-rw-r--r-- | src/plugins/AniList.cpp | 33 |
3 files changed, 17 insertions, 30 deletions
diff --git a/plugins/AniList.hpp b/plugins/AniList.hpp index c877b8e..5fc5eef 100644 --- a/plugins/AniList.hpp +++ b/plugins/AniList.hpp @@ -3,10 +3,15 @@ #include "Page.hpp" namespace QuickMedia { + enum class AniListMediaType { + ANIME, + MANGA + }; + class AniListSearchPage : public Page { public: - AniListSearchPage(Program *program) : Page(program) {} - const char* get_title() const override { return "Search for anime or manga"; } + AniListSearchPage(Program *program, AniListMediaType media_type) : Page(program), media_type(media_type) {} + const char* get_title() const override { return media_type == AniListMediaType::ANIME ? "Search for anime" : "Search for manga"; } bool search_is_filter() override { return false; } bool submit_is_async() const override { return false; } SearchResult search(const std::string &str, BodyItems &result_items) override; @@ -14,6 +19,8 @@ namespace QuickMedia { PluginResult get_page(const std::string &str, int page, BodyItems &result_items) override; private: SearchResult search_page(const std::string &str, int page, BodyItems &result_items); + private: + AniListMediaType media_type; }; class AniListRelatedPage : public LazyFetchPage { diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 79f6d51..6be7dab 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1214,7 +1214,8 @@ namespace QuickMedia { body->set_items(std::move(body_items)); tabs.push_back(Tab{std::move(body), std::make_unique<HotExamplesLanguageSelectPage>(this), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); } else if(strcmp(plugin_name, "anilist") == 0) { - tabs.push_back(Tab{create_body(), std::make_unique<AniListSearchPage>(this), create_search_bar("Search...", 300)}); + tabs.push_back(Tab{create_body(), std::make_unique<AniListSearchPage>(this, AniListMediaType::ANIME), create_search_bar("Search...", 300)}); + tabs.push_back(Tab{create_body(), std::make_unique<AniListSearchPage>(this, AniListMediaType::MANGA), create_search_bar("Search...", 300)}); } else if(strcmp(plugin_name, "file-manager") == 0) { auto file_manager_page = std::make_unique<FileManagerPage>(this, fm_mime_type, file_selection_handler); if(!file_manager_page->set_current_directory(file_manager_start_dir)) diff --git a/src/plugins/AniList.cpp b/src/plugins/AniList.cpp index fe9a62f..1523129 100644 --- a/src/plugins/AniList.cpp +++ b/src/plugins/AniList.cpp @@ -10,7 +10,7 @@ namespace QuickMedia { static const std::string search_query_graphql = R"END( query ($page: Int, $perPage: Int, $search: String) { Page (page: $page, perPage: $perPage) { - media (search: $search) { + media (search: $search, type: %TYPE%) { id type format @@ -152,11 +152,6 @@ query ($id: Int, $page: Int, $perPage: Int) { } )END"; - enum class AniListMediaType { - ANIME, - MANGA - }; - static const char *month_names[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; static bool in_range(int value, int min, int max) { return value >= min && value <= max; @@ -438,8 +433,11 @@ query ($id: Int, $page: Int, $perPage: Int) { variables_json["perPage"] = 20; variables_json["search"] = str; + std::string query = search_query_graphql; + string_replace_all(query, "%TYPE%", media_type == AniListMediaType::ANIME ? "ANIME" : "MANGA"); + Json::Value request_json(Json::objectValue); - request_json["query"] = search_query_graphql; + request_json["query"] = std::move(query); request_json["variables"] = std::move(variables_json); Json::StreamWriterBuilder json_builder; @@ -484,32 +482,13 @@ query ($id: Int, $page: Int, $perPage: Int) { if(!media_list_json.isArray()) return SearchResult::ERR; - BodyItems anime_items; - BodyItems manga_items; for(const Json::Value &media_json : media_list_json) { AniListMediaType media_type; auto body_item = media_json_to_body_item(media_json, ThumbnailSize::MEDIUM, media_type); if(!body_item) continue; - if(media_type == AniListMediaType::ANIME) - anime_items.push_back(std::move(body_item)); - else if(media_type == AniListMediaType::MANGA) - manga_items.push_back(std::move(body_item)); - } - - if(!anime_items.empty()) { - auto anime_title_item = BodyItem::create(""); - anime_title_item->set_author("------------------------ Anime ------------------------"); - result_items.push_back(std::move(anime_title_item)); - result_items.insert(result_items.end(), std::move_iterator(anime_items.begin()), std::move_iterator(anime_items.end())); - } - - if(!manga_items.empty()) { - auto manga_title_item = BodyItem::create(""); - manga_title_item->set_author("------------------------ Manga ------------------------"); - result_items.push_back(std::move(manga_title_item)); - result_items.insert(result_items.end(), std::move_iterator(manga_items.begin()), std::move_iterator(manga_items.end())); + result_items.push_back(std::move(body_item)); } return SearchResult::OK; |