aboutsummaryrefslogtreecommitdiff
path: root/plugins/Manga.hpp
blob: 74d8ed120cfb9ee31c81c05d74919f9f5ed479b0 (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
58
59
60
61
62
63
64
65
66
67
68
#pragma once

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

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

    enum class CreatorType {
        AUTHOR,
        ARTIST
    };

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

    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)), chapter_num_pages(-1) {}
        virtual ~MangaImagesPage() = default;
        const char* get_title() const override { return chapter_name.c_str(); }
        PageTypez get_type() const override { return PageTypez::MANGA_IMAGES; }

        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();
                chapter_num_pages = -1;
            }
        }

        const std::string& get_chapter_name() const { return chapter_name; }
        const std::string& get_url() const { return url; }

        // TODO: Remove and use plugin name instead
        virtual const char* get_service_name() const = 0;

        virtual const char* get_website_url() const = 0;

        const std::string manga_name;
    protected:
        std::string chapter_name;
        std::string url;
        std::vector<std::string> chapter_image_urls;
        int chapter_num_pages;
    };

    class MangaChaptersPage : public Page, public TrackablePage {
    public:
        MangaChaptersPage(Program *program, std::string manga_name, std::string manga_url) : Page(program), TrackablePage(std::move(manga_name), std::move(manga_url)) {}
        const char* get_title() const override { return content_title.c_str(); }
        TrackResult track(const std::string &str) override;
        void on_navigate_to_page(Body *body) override;
        bool is_trackable() const override { return true; }
        std::shared_ptr<BodyItem> get_bookmark_body_item() override;
    protected:
        virtual bool extract_id_from_url(const std::string &url, std::string &manga_id) const = 0;
        virtual const char* get_service_name() const = 0;
    };
}