aboutsummaryrefslogtreecommitdiff
path: root/plugins/Plugin.hpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-10-11 21:35:37 +0200
committerdec05eba <dec05eba@protonmail.com>2020-10-13 13:13:01 +0200
commit77ed51898157d99112be7550471ec06e32344c9e (patch)
tree0645274d0f13b4fa6940d4054f74a070611a8ef0 /plugins/Plugin.hpp
parentda89ec98fb34757f0c46dc8cb2dd87ae78d317ce (diff)
Refactor plugin into seperate pages
TODO: Readd 4chan login page, manganelo creators page, autocomplete
Diffstat (limited to 'plugins/Plugin.hpp')
-rw-r--r--plugins/Plugin.hpp72
1 files changed, 11 insertions, 61 deletions
diff --git a/plugins/Plugin.hpp b/plugins/Plugin.hpp
index 438b4ea..1427233 100644
--- a/plugins/Plugin.hpp
+++ b/plugins/Plugin.hpp
@@ -1,12 +1,9 @@
#pragma once
-#include "../include/Page.hpp"
#include "../include/Body.hpp"
-#include "../include/StringUtils.hpp"
#include "../include/DownloadUtils.hpp"
+#include <stddef.h>
#include <string>
-#include <vector>
-#include <memory>
namespace QuickMedia {
enum class PluginResult {
@@ -34,64 +31,17 @@ namespace QuickMedia {
NET_ERR
};
+ struct BodyItemImageContext {
+ BodyItems *body_items;
+ size_t index;
+ };
+
void html_escape_sequences(std::string &str);
void html_unescape_sequences(std::string &str);
+ std::string url_param_encode(const std::string &param);
- class Plugin {
- public:
- Plugin(const std::string &name) : name(name) {}
- virtual ~Plugin() = default;
-
- virtual bool is_image_board() { return false; }
- virtual bool is_manga() { return false; }
- // Return true if searching should update the search result (which could be a remote server search) or filter the existing list locally
- virtual bool search_is_filter() { return false; }
-
- virtual PluginResult get_front_page(BodyItems &result_items) {
- (void)result_items; return PluginResult::OK;
- }
- virtual SearchResult search(const std::string &text, BodyItems &result_items);
- virtual SuggestionResult update_search_suggestions(const std::string &text, BodyItems &result_items);
- virtual SearchResult content_list_search(const std::string &list_url, const std::string &text, BodyItems &result_items);
- // TODO: Merge with above?
- // page 0 is the first page
- virtual SearchResult content_list_search_page(const std::string &list_url, const std::string &text, int page, BodyItems &result_items) {
- (void)list_url;
- (void)text;
- (void)page;
- (void)result_items;
- return SearchResult::OK;
- }
- virtual BodyItems get_related_media(const std::string &url);
- virtual PluginResult get_content_list(const std::string &url, BodyItems &result_items) {
- (void)url;
- (void)result_items;
- return PluginResult::OK;
- }
- virtual PluginResult get_content_details(const std::string &list_url, const std::string &url, BodyItems &result_items) {
- (void)list_url;
- (void)url;
- (void)result_items;
- return PluginResult::OK;
- }
- virtual bool search_suggestions_has_thumbnails() const = 0;
- virtual bool search_results_has_thumbnails() const = 0;
- virtual std::string autocomplete_search(const std::string &query) { return query; }
- virtual int get_autocomplete_delay() const { return 100; }
- virtual int get_search_delay() const = 0;
- virtual int get_content_list_search_delay() const { return 350; }
- virtual bool search_suggestion_is_search() const { return false; }
- virtual bool content_list_search_is_filter() const { return true; }
- virtual Page get_page_after_search() const = 0;
-
- const std::string name;
- bool use_tor = false;
- protected:
- std::string url_param_encode(const std::string &param) const;
- 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) const;
- SuggestionResult download_result_to_suggestion_result(DownloadResult download_result) const { return (SuggestionResult)download_result; }
- PluginResult download_result_to_plugin_result(DownloadResult download_result) const { return (PluginResult)download_result; }
- SearchResult download_result_to_search_result(DownloadResult download_result) const { return (SearchResult)download_result; }
- ImageResult download_result_to_image_result(DownloadResult download_result) const { return (ImageResult)download_result; }
- };
+ SuggestionResult download_result_to_suggestion_result(DownloadResult download_result);
+ PluginResult download_result_to_plugin_result(DownloadResult download_result);
+ SearchResult download_result_to_search_result(DownloadResult download_result);
+ ImageResult download_result_to_image_result(DownloadResult download_result);
} \ No newline at end of file