aboutsummaryrefslogtreecommitdiff
path: root/plugins/Page.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Page.hpp')
-rw-r--r--plugins/Page.hpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/plugins/Page.hpp b/plugins/Page.hpp
new file mode 100644
index 0000000..947f045
--- /dev/null
+++ b/plugins/Page.hpp
@@ -0,0 +1,61 @@
+#pragma once
+
+#include "Plugin.hpp"
+
+#include "../include/Tab.hpp"
+#include "../include/SearchBar.hpp"
+#include "../include/Body.hpp"
+
+namespace QuickMedia {
+ constexpr int SEARCH_DELAY_FILTER = 50;
+
+ class Page {
+ public:
+ Page(Program *program) : program(program) {}
+ virtual ~Page() = default;
+
+ virtual const char* get_title() const = 0;
+ virtual bool search_is_filter() { return true; }
+ // This show be overriden if search_is_filter is overriden to return false
+ virtual SearchResult search(const std::string &str, BodyItems &result_items) { (void)str; (void)result_items; return SearchResult::ERR; }
+
+ // Return empty |result_tabs| and PluginResult::OK to do nothing; which is useful for implementing custom actions on item submit
+ virtual PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) = 0;
+ virtual PluginResult get_page(const std::string &str, int page, BodyItems &result_items) { (void)str; (void)page; (void)result_items; return PluginResult::OK; }
+
+ virtual BodyItems get_related_media(const std::string &url);
+
+ DownloadResult download_json(Json::Value &result, const std::string &url, std::vector<CommandArg> additional_args, bool use_browser_useragent = false, std::string *err_msg = nullptr);
+
+ virtual bool is_manga_images_page() const { return false; }
+ virtual bool is_image_board_thread_page() const { return false; }
+ virtual bool is_video_page() const { return false; }
+ // Mutually exclusive with |is_manga_images_page|, |is_image_board_thread_page| and |is_video_page|
+ virtual bool is_single_page() const { return false; }
+ virtual bool is_trackable() const { return false; }
+
+ bool is_tor_enabled();
+ std::unique_ptr<Body> create_body();
+ std::unique_ptr<SearchBar> create_search_bar(const std::string &placeholder_text, int search_delay);
+
+ bool load_manga_content_storage(const char *service_name, const std::string &manga_title, const std::string &manga_id);
+
+ Program *program;
+ };
+
+ enum class TrackResult {
+ OK,
+ ERR
+ };
+
+ class TrackablePage : public Page {
+ public:
+ TrackablePage(Program *program, std::string content_title, std::string content_url) : Page(program), content_title(std::move(content_title)), content_url(std::move(content_url)) {}
+ const char* get_title() const override { return content_title.c_str(); }
+ bool is_trackable() const override { return true; }
+ virtual TrackResult track(const std::string &str) = 0;
+
+ const std::string content_title;
+ const std::string content_url;
+ };
+} \ No newline at end of file