FileManager.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include "Page.hpp"
  3. #include <filesystem>
  4. namespace QuickMedia {
  5. class FileManagerPage;
  6. enum FileManagerMimeType {
  7. FILE_MANAGER_MIME_TYPE_IMAGE = (1 << 0),
  8. FILE_MANAGER_MIME_TYPE_VIDEO = (1 << 1),
  9. FILE_MANAGER_MIME_TYPE_AUDIO = (1 << 2),
  10. FILE_MANAGER_MIME_TYPE_OTHER = (1 << 3)
  11. };
  12. static const FileManagerMimeType FILE_MANAGER_MIME_TYPE_ALL = (FileManagerMimeType)(FILE_MANAGER_MIME_TYPE_IMAGE|FILE_MANAGER_MIME_TYPE_VIDEO|FILE_MANAGER_MIME_TYPE_AUDIO|FILE_MANAGER_MIME_TYPE_OTHER);
  13. // Return the tags to go to after selecting a file, or return an empty array to exit the program
  14. using FileSelectionHandler = std::function<std::vector<Tab>(FileManagerPage*, const std::filesystem::path&)>;
  15. class FileManagerPage : public Page {
  16. public:
  17. FileManagerPage(Program *program, FileManagerMimeType mime_type = FILE_MANAGER_MIME_TYPE_ALL, FileSelectionHandler selection_handler = nullptr) :
  18. Page(program), current_dir("/"), mime_type(mime_type), selection_handler(selection_handler) {}
  19. const char* get_title() const override { return current_dir.c_str(); }
  20. PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) override;
  21. bool is_single_page() const override { return true; }
  22. bool set_current_directory(const std::string &path);
  23. const std::filesystem::path& get_current_directory() const { return current_dir; }
  24. PluginResult get_files_in_directory(BodyItems &result_items);
  25. // |fallback| is used if no directory has been accessed
  26. static std::filesystem::path& get_last_accessed_directory(std::filesystem::path &fallback);
  27. private:
  28. std::filesystem::path current_dir;
  29. FileManagerMimeType mime_type;
  30. FileSelectionHandler selection_handler;
  31. bool allow_empty_match_submit;
  32. };
  33. }