From 77ed51898157d99112be7550471ec06e32344c9e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 11 Oct 2020 21:35:37 +0200 Subject: Refactor plugin into seperate pages TODO: Readd 4chan login page, manganelo creators page, autocomplete --- plugins/Manga.hpp | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'plugins/Manga.hpp') diff --git a/plugins/Manga.hpp b/plugins/Manga.hpp index 13c494e..732e208 100644 --- a/plugins/Manga.hpp +++ b/plugins/Manga.hpp @@ -1,8 +1,7 @@ #pragma once -#include "Plugin.hpp" +#include "Page.hpp" #include -#include namespace QuickMedia { // Return false to stop iteration @@ -13,18 +12,46 @@ namespace QuickMedia { std::string url; }; - class Manga : public Plugin { + class MangaImagesPage : public Page { public: - Manga(const std::string &plugin_name) : Plugin(plugin_name) {} - bool is_manga() override { return true; } - virtual ImageResult get_number_of_images(const std::string &url, int &num_images) = 0; - virtual ImageResult for_each_page_in_chapter(const std::string &chapter_url, PageCallback callback) = 0; - virtual bool extract_id_from_url(const std::string &url, std::string &manga_id) = 0; + MangaImagesPage(Program *program, std::string manga_name, std::string chapter_name, std::string url) : Page(program), manga_name(std::move(manga_name)), chapter_name(std::move(chapter_name)), url(std::move(url)) {} + virtual ~MangaImagesPage() = default; + const char* get_title() const override { return chapter_name.c_str(); } + PluginResult submit(const std::string &title, const std::string &url, std::vector &result_tabs) override { + (void)title; + (void)url; + (void)result_tabs; + return PluginResult::OK; + } - virtual PluginResult get_creators_manga_list(const std::string &url, BodyItems &result_items) { (void)url; (void)result_items; return {}; } + bool is_manga_images_page() const override { return true; } - const std::vector& get_creators() const; + virtual ImageResult get_number_of_images(int &num_images) = 0; + virtual ImageResult for_each_page_in_chapter(PageCallback callback) = 0; + + virtual void change_chapter(std::string new_chapter_name, std::string new_url) { + chapter_name = std::move(new_chapter_name); + if(url != new_url) { + url = std::move(new_url); + chapter_image_urls.clear(); + } + } + + const std::string& get_chapter_name() const { return chapter_name; } + const std::string& get_url() const { return url; } + + virtual const char* get_service_name() const = 0; + + const std::string manga_name; protected: - std::vector creators; + std::string chapter_name; + std::string url; + std::vector chapter_image_urls; + }; + + class MangaChaptersPage : public TrackablePage { + public: + MangaChaptersPage(Program *program, std::string manga_name, std::string manga_url) : TrackablePage(program, std::move(manga_name), std::move(manga_url)) {} + TrackResult track(const std::string &str) override; }; } \ No newline at end of file -- cgit v1.2.3