aboutsummaryrefslogtreecommitdiff
path: root/plugins/Manga.hpp
blob: 732e208feb1d0909fa42cd79d4b8c2a77e50f5b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#include "Page.hpp"
#include <functional>

namespace QuickMedia {
    // Return false to stop iteration
    using PageCallback = std::function<bool(const std::string &url)>;

    struct Creator {
        std::string name;
        std::string url;
    };

    class MangaImagesPage : public Page {
    public:
        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<Tab> &result_tabs) override {
            (void)title;
            (void)url;
            (void)result_tabs;
            return PluginResult::OK;
        }

        bool is_manga_images_page() const override { return true; }

        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::string chapter_name;
        std::string url;
        std::vector<std::string> 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;
    };
}