From 77ed51898157d99112be7550471ec06e32344c9e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 11 Oct 2020 21:35:37 +0200 Subject: Refactor plugin into seperate pages TODO: Readd 4chan login page, manganelo creators page, autocomplete --- src/plugins/FileManager.cpp | 75 ++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 35 deletions(-) (limited to 'src/plugins/FileManager.cpp') diff --git a/src/plugins/FileManager.cpp b/src/plugins/FileManager.cpp index ccaf2c1..5fac79c 100644 --- a/src/plugins/FileManager.cpp +++ b/src/plugins/FileManager.cpp @@ -1,12 +1,8 @@ #include "../../plugins/FileManager.hpp" #include "../../include/ImageUtils.hpp" -#include +#include "../../include/QuickMedia.hpp" namespace QuickMedia { - FileManager::FileManager() : Plugin("file-manager"), current_dir("/") { - - } - // Returns empty string if no extension static const char* get_ext(const std::filesystem::path &path) { const char *path_c = path.c_str(); @@ -26,7 +22,45 @@ namespace QuickMedia { } } - PluginResult FileManager::get_files_in_directory(BodyItems &result_items) { + PluginResult FileManagerPage::submit(const std::string &title, const std::string &url, std::vector &result_tabs) { + (void)url; + + std::filesystem::path new_path; + if(title == "..") + new_path = current_dir.parent_path(); + else + new_path = current_dir / title; + + if(std::filesystem::is_regular_file(new_path)) { + program->select_file(new_path); + return PluginResult::OK; + } + + if(!std::filesystem::is_directory(new_path)) + return PluginResult::ERR; + + current_dir = std::move(new_path); + + BodyItems result_items; + PluginResult result = get_files_in_directory(result_items); + if(result != PluginResult::OK) + return result; + + auto body = create_body(); + body->items = std::move(result_items); + body->draw_thumbnails = true; + result_tabs.push_back(Tab{std::move(body), nullptr, nullptr}); + return PluginResult::OK; + } + + bool FileManagerPage::set_current_directory(const std::string &path) { + if(!std::filesystem::is_directory(path)) + return false; + current_dir = path; + return true; + } + + PluginResult FileManagerPage::get_files_in_directory(BodyItems &result_items) { std::vector paths; try { for(auto &p : std::filesystem::directory_iterator(current_dir)) { @@ -58,33 +92,4 @@ namespace QuickMedia { return PluginResult::OK; } - - bool FileManager::set_current_directory(const std::string &path) { - if(!std::filesystem::is_directory(path)) - return false; - current_dir = path; - return true; - } - - bool FileManager::set_child_directory(const std::string &filename) { - if(filename == "..") { - std::filesystem::path new_path = current_dir.parent_path(); - if(std::filesystem::is_directory(new_path)) { - current_dir = std::move(new_path); - return true; - } - return false; - } else { - std::filesystem::path new_path = current_dir / filename; - if(std::filesystem::is_directory(new_path)) { - current_dir = std::move(new_path); - return true; - } - return false; - } - } - - const std::filesystem::path& FileManager::get_current_dir() const { - return current_dir; - } } \ No newline at end of file -- cgit v1.2.3