From b09d1e70661226697e2441c18ea6ff59c387fb93 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 16 Jul 2021 07:31:02 +0200 Subject: Add sorting options to nyaa.si --- plugins/NyaaSi.hpp | 34 ++++++++++++++++++++++++++++++++-- plugins/Page.hpp | 1 + 2 files changed, 33 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/NyaaSi.hpp b/plugins/NyaaSi.hpp index 897c5ab..6f161ac 100644 --- a/plugins/NyaaSi.hpp +++ b/plugins/NyaaSi.hpp @@ -16,18 +16,48 @@ namespace QuickMedia { const bool is_sukebei; }; + enum class NyaaSiSortType { + SIZE_DESC, + UPLOAD_DATE_DESC, + SEEDERS_DESC, + LEECHERS_DESC, + DOWNLOADS_DESC, + + SIZE_ASC, + UPLOAD_DATE_ASC, + SEEDERS_ASC, + LEECHERS_ASC, + DOWNLOADS_ASC + }; + class NyaaSiSearchPage : public Page { public: - NyaaSiSearchPage(Program *program, std::string category_name, std::string category_id, std::string domain) : Page(program), category_name(std::move(category_name)), category_id(std::move(category_id)), domain(std::move(domain)) {} - const char* get_title() const override { return category_name.c_str(); } + NyaaSiSearchPage(Program *program, std::string category_name, std::string category_id, std::string domain); + const char* get_title() const override { return title.c_str(); } bool search_is_filter() override { return false; } SearchResult search(const std::string &str, BodyItems &result_items) override; PluginResult get_page(const std::string &str, int page, BodyItems &result_items) override; PluginResult submit(const std::string &title, const std::string &url, std::vector &result_tabs) override; + void set_sort_type(NyaaSiSortType sort_type); + const std::string category_name; const std::string category_id; const std::string domain; + private: + NyaaSiSortType sort_type = NyaaSiSortType::UPLOAD_DATE_DESC; + std::string title; + }; + + class NyaaSiSortOrderPage : public Page { + public: + NyaaSiSortOrderPage(Program *program, Body *body, NyaaSiSearchPage *search_page) : Page(program), body(body), search_page(search_page) {} + const char* get_title() const override { return "Sort order"; } + PluginResult submit(const std::string &title, const std::string &url, std::vector &result_tabs) override; + bool submit_is_async() override { return false; } + private: + Body *body; + NyaaSiSearchPage *search_page; }; class NyaaSiTorrentPage : public Page { diff --git a/plugins/Page.hpp b/plugins/Page.hpp index 2d10d50..3a382ec 100644 --- a/plugins/Page.hpp +++ b/plugins/Page.hpp @@ -67,6 +67,7 @@ namespace QuickMedia { Program *program; std::shared_ptr submit_body_item; // TODO: Remove this + bool needs_refresh = false; // Set to true to refresh the page }; enum class TrackResult { -- cgit v1.2.3