aboutsummaryrefslogtreecommitdiff
path: root/plugins/FileManager.hpp
blob: 20ed49c4ba2ad77721947ad6d243fd241b089ef1 (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
#pragma once

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

namespace QuickMedia {
    class FileManagerPage;

    enum FileManagerMimeType {
        FILE_MANAGER_MIME_TYPE_IMAGE = (1 << 0),
        FILE_MANAGER_MIME_TYPE_VIDEO = (1 << 1),
        FILE_MANAGER_MIME_TYPE_OTHER = (1 << 2)
    };

    static const FileManagerMimeType FILE_MANAGER_MIME_TYPE_ALL = (FileManagerMimeType)(FILE_MANAGER_MIME_TYPE_IMAGE|FILE_MANAGER_MIME_TYPE_VIDEO|FILE_MANAGER_MIME_TYPE_OTHER);
    // Return the tags to go to after selecting a file, or return an empty array to exit the program
    using FileSelectionHandler = std::function<std::vector<Tab>(FileManagerPage*, const std::filesystem::path&)>;

    class FileManagerPage : public Page {
    public:
        FileManagerPage(Program *program, FileManagerMimeType mime_type = FILE_MANAGER_MIME_TYPE_ALL, FileSelectionHandler selection_handler = nullptr, bool allow_empty_match_submit = false, const std::string &title_prefix = "") :
            Page(program), current_dir("/"), mime_type(mime_type), selection_handler(selection_handler), allow_empty_match_submit(allow_empty_match_submit), title_prefix(title_prefix)
        {
            title = title_prefix + current_dir.string();
        }
        const char* get_title() const override { return title.c_str(); }
        PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
        bool is_single_page() const override { return true; }
        bool allow_submit_no_selection() const override { return allow_empty_match_submit; }
        void on_navigate_to_page(Body*) override;

        bool set_current_directory(const std::string &path);
        PluginResult get_files_in_directory(BodyItems &result_items);

        bool close = false;
    private:
        std::filesystem::path current_dir;
        FileManagerMimeType mime_type;
        FileSelectionHandler selection_handler;
        bool allow_empty_match_submit;
        std::string title;
        std::string title_prefix;
    };
}