aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/FileManager.cpp36
-rw-r--r--src/plugins/MangaGeneric.cpp30
2 files changed, 17 insertions, 49 deletions
diff --git a/src/plugins/FileManager.cpp b/src/plugins/FileManager.cpp
index 52f9f4e..e1f3b04 100644
--- a/src/plugins/FileManager.cpp
+++ b/src/plugins/FileManager.cpp
@@ -23,24 +23,6 @@ namespace QuickMedia {
return last_write_time;
}
- static std::string file_size_to_human_readable_string(size_t bytes) {
- double kb = (double)bytes / 1024.0;
- double mb = (double)bytes / 1024.0 / 1024.0;
- double gb = (double)bytes / 1024.0 / 1024.0 / 1024.0;
- char result[32];
-
- if(gb >= 1.0)
- snprintf(result, sizeof(result), "%.1f GiB", gb);
- else if(mb >= 1.0)
- snprintf(result, sizeof(result), "%.1f MiB", mb);
- else if(kb >= 1.0)
- snprintf(result, sizeof(result), "%.1f KiB", kb);
- else
- snprintf(result, sizeof(result), "%zu bytes", bytes);
-
- return result;
- }
-
PluginResult FileManagerPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) {
(void)url;
@@ -53,14 +35,22 @@ namespace QuickMedia {
if(std::filesystem::is_regular_file(new_path)) {
program->select_file(new_path);
if(selection_handler)
- result_tabs = selection_handler();
+ result_tabs = selection_handler(this, new_path);
return PluginResult::OK;
}
- if(!std::filesystem::is_directory(new_path))
+ if(!std::filesystem::is_directory(new_path)) {
+ if(allow_empty_match_submit) {
+ program->select_file(new_path);
+ if(selection_handler)
+ result_tabs = selection_handler(this, new_path);
+ return PluginResult::OK;
+ }
return PluginResult::ERR;
+ }
current_dir = std::move(new_path);
+ this->title = title_prefix + current_dir.string();
BodyItems result_items;
PluginResult result = get_files_in_directory(result_items);
@@ -73,10 +63,16 @@ namespace QuickMedia {
return PluginResult::OK;
}
+ void FileManagerPage::on_navigate_to_page(Body*) {
+ if(close)
+ program->set_go_to_previous_page();
+ }
+
bool FileManagerPage::set_current_directory(const std::string &path) {
if(!std::filesystem::is_directory(path))
return false;
current_dir = path;
+ title = title_prefix + current_dir.string();
return true;
}
diff --git a/src/plugins/MangaGeneric.cpp b/src/plugins/MangaGeneric.cpp
index a6df1c1..2e88d60 100644
--- a/src/plugins/MangaGeneric.cpp
+++ b/src/plugins/MangaGeneric.cpp
@@ -121,34 +121,6 @@ namespace QuickMedia {
}, page_image_userdata);
}
- static size_t str_find_case_insensitive(const std::string &str, size_t start_index, const char *substr, size_t substr_len) {
- auto it = std::search(str.begin() + start_index, str.end(), substr, substr + substr_len,
- [](char c1, char c2) {
- return std::toupper(c1) == std::toupper(c2);
- });
- if(it == str.end())
- return std::string::npos;
- return it - str.begin();
- }
-
- static std::string header_extract_location(const std::string &headers) {
- size_t index = str_find_case_insensitive(headers, 0, "location:", 9);
- if(index != std::string::npos && (index == 0 || headers[index - 1] == '\n')) {
- index += 9;
- size_t end = headers.find('\r', index);
- size_t start = index;
- while(start < end) {
- char c = headers[start];
- if(c != ' ' && c != '\t')
- break;
- ++start;
- }
- if(end - start > 0)
- return headers.substr(start, end - start);
- }
- return "";
- }
-
MangaGenericSearchPage::MangaGenericSearchPage(Program *program, const char *service_name, const char *website_url, bool fail_on_http_error) :
Page(program), service_name(service_name), website_url(website_url ? website_url : ""), fail_on_http_error(fail_on_http_error)
{
@@ -228,7 +200,7 @@ namespace QuickMedia {
goto cleanup;
}
- target_url = header_extract_location(response_headers);
+ target_url = header_extract_value(response_headers, "location");
if(target_url.empty()) {
fprintf(stderr, "Failed to extract target location from %s HEAD\n", url.c_str());
result = -1;