aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/FileManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/FileManager.cpp')
-rw-r--r--src/plugins/FileManager.cpp75
1 files changed, 40 insertions, 35 deletions
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 <filesystem>
+#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<Tab> &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<std::filesystem::directory_entry> 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