aboutsummaryrefslogtreecommitdiff
path: root/plugins/Plugin.hpp
blob: 54d49e5eaff42343683828a694aaa208ab310003 (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
#pragma once

#include "../include/Page.hpp"
#include "../include/Body.hpp"
#include <string>
#include <vector>
#include <memory>

namespace QuickMedia {
    enum class SearchResult {
        OK,
        ERR,
        NET_ERR
    };

    enum class SuggestionResult {
        OK,
        ERR,
        NET_ERR
    };

    enum class DownloadResult {
        OK,
        ERR,
        NET_ERR
    };

    enum class ImageResult {
        OK,
        END,
        ERR,
        NET_ERR
    };

    struct CommandArg {
        std::string option;
        std::string value;
    };

    DownloadResult download_to_string(const std::string &url, std::string &result, const std::vector<CommandArg> &additional_args = {});
    std::string strip(const std::string &str);

    class Plugin {
    public:
        virtual ~Plugin() = default;

        virtual SearchResult search(const std::string &text, std::vector<std::unique_ptr<BodyItem>> &result_items);
        virtual SuggestionResult update_search_suggestions(const std::string &text, std::vector<std::unique_ptr<BodyItem>> &result_items);
        virtual std::vector<std::unique_ptr<BodyItem>> get_related_media(const std::string &url);
        virtual bool search_suggestions_has_thumbnails() const = 0;
        virtual bool search_results_has_thumbnails() const = 0;
        virtual int get_search_delay() const = 0;
        virtual bool search_suggestion_is_search() const { return false; }
        virtual Page get_page_after_search() const = 0;
    protected:
        std::string url_param_encode(const std::string &param) const;
    };
}