From 1026360c595818eabe75813bcd02258c4d0dddc7 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 24 May 2021 07:53:33 +0200 Subject: Save the last accessed file manager directory and use that the next time. Add ctrl+s for 4chan without viewing the image/video in fullscreen mode --- src/QuickMedia.cpp | 58 ++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 498de29..e93536b 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -319,7 +319,7 @@ namespace QuickMedia { fprintf(stderr, " --use-system-mpv-config Use system mpv config instead of no config. Disabled by default\n"); fprintf(stderr, " --upscale-images Upscale low-resolution manga pages using waifu2x-ncnn-vulkan. Disabled by default\n"); fprintf(stderr, " --upscale-images-always Upscale manga pages using waifu2x-ncnn-vulkan, no matter what the original image resolution is. Disabled by default\n"); - fprintf(stderr, " --dir Set the start directory when using file-manager. Default is the user home directory\n"); + fprintf(stderr, " --dir Set the start directory when using file-manager. Default is the last accessed directory in QuickMedia or the users home directory\n"); fprintf(stderr, " -e Embed QuickMedia into another window\n"); fprintf(stderr, "EXAMPLES:\n"); fprintf(stderr, " quickmedia launcher\n"); @@ -350,7 +350,6 @@ namespace QuickMedia { return -1; } - const char *start_dir = nullptr; Window parent_window = None; std::vector tabs; const char *url = nullptr; @@ -377,7 +376,7 @@ namespace QuickMedia { upscale_image_action = UpscaleImageAction::FORCE; } else if(strcmp(argv[i], "--dir") == 0) { if(i < argc - 1) { - start_dir = argv[i + 1]; + file_manager_start_dir = argv[i + 1]; ++i; } else { fprintf(stderr, "Missing directory after --dir argument\n"); @@ -471,15 +470,9 @@ namespace QuickMedia { }); } - if(strcmp(plugin_name, "file-manager") != 0 && start_dir) { - fprintf(stderr, "Option --dir is only valid with file-manager\n"); - usage(); - return -1; - } - - Path home_dir = get_home_dir(); - if(!start_dir) - start_dir = home_dir.data.c_str(); + std::filesystem::path home_path = get_home_dir().data; + if(file_manager_start_dir.empty()) + file_manager_start_dir = FileManagerPage::get_last_accessed_directory(home_path); int start_tab_index = 0; FileManagerMimeType fm_mine_type = FILE_MANAGER_MIME_TYPE_ALL; @@ -510,7 +503,7 @@ namespace QuickMedia { file_selection_handler = std::move(saucenao_file_selection_handler); } - load_plugin_by_name(tabs, start_dir, start_tab_index, fm_mine_type, std::move(file_selection_handler)); + load_plugin_by_name(tabs, start_tab_index, fm_mine_type, std::move(file_selection_handler)); while(!tabs.empty() || matrix) { if(matrix) { @@ -535,7 +528,7 @@ namespace QuickMedia { fm_mine_type = FILE_MANAGER_MIME_TYPE_IMAGE; file_selection_handler = std::move(saucenao_file_selection_handler); } - load_plugin_by_name(tabs, start_dir, start_tab_index, fm_mine_type, std::move(file_selection_handler)); + load_plugin_by_name(tabs, start_tab_index, fm_mine_type, std::move(file_selection_handler)); } } @@ -671,6 +664,9 @@ namespace QuickMedia { if(create_directory_recursive(get_cache_dir().join("thumbnails")) != 0) throw std::runtime_error("Failed to create thumbnails directory"); + if(create_directory_recursive(get_storage_dir().join("file-manager")) != 0) + throw std::runtime_error("Failed to create file-manager directory"); + const char *qm_phone_factor = getenv("QM_PHONE_FACTOR"); if(qm_phone_factor && atoi(qm_phone_factor) == 1) show_room_side_panel = false; @@ -984,7 +980,7 @@ namespace QuickMedia { return PluginResult::OK; } - void Program::load_plugin_by_name(std::vector &tabs, const char *start_dir, int &start_tab_index, FileManagerMimeType fm_mime_type, FileSelectionHandler file_selection_handler) { + void Program::load_plugin_by_name(std::vector &tabs, int &start_tab_index, FileManagerMimeType fm_mime_type, FileSelectionHandler file_selection_handler) { if(!plugin_name || plugin_name[0] == '\0') return; @@ -1116,11 +1112,8 @@ namespace QuickMedia { tabs.push_back(Tab{std::move(boards_body), std::move(boards_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); } else if(strcmp(plugin_name, "file-manager") == 0) { auto file_manager_page = std::make_unique(this, fm_mime_type, file_selection_handler); - if(start_dir && !file_manager_page->set_current_directory(start_dir)) { - fprintf(stderr, "Invalid directory provided with --dir: %s\n", start_dir); - exit_code = -3; - return; - } + if(!file_manager_page->set_current_directory(file_manager_start_dir)) + fprintf(stderr, "Warning: Invalid directory provided with --dir\n"); auto file_manager_body = create_body(); file_manager_page->get_files_in_directory(file_manager_body->items); tabs.push_back(Tab{std::move(file_manager_body), std::move(file_manager_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); @@ -2453,7 +2446,7 @@ namespace QuickMedia { } else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::C && event.key.control) { save_video_url_to_clipboard(); } else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::S && event.key.control) { - download_async_gui(original_video_url, !is_matrix, no_video); + download_async_gui(original_video_url, FileManagerPage::get_last_accessed_directory(file_manager_start_dir).string(), !is_matrix, no_video); } } handle_window_close(); @@ -2470,7 +2463,7 @@ namespace QuickMedia { } else if(pressed_keysym == XK_f && pressing_ctrl) { window_set_fullscreen(disp, window.getSystemHandle(), WindowFullscreenState::TOGGLE); } else if(pressed_keysym == XK_s && pressing_ctrl) { - download_async_gui(original_video_url, !is_matrix, no_video); + download_async_gui(original_video_url, FileManagerPage::get_last_accessed_directory(file_manager_start_dir).string(), !is_matrix, no_video); } else if(pressed_keysym == XK_r && pressing_ctrl) { if(!cursor_visible) window.setMouseCursorVisible(true); @@ -3411,8 +3404,9 @@ namespace QuickMedia { } } } else if(event.key.code == sf::Keyboard::U) { + std::filesystem::path &fm_dir = FileManagerPage::get_last_accessed_directory(file_manager_start_dir); auto file_manager_page = std::make_unique(this, (FileManagerMimeType)(FILE_MANAGER_MIME_TYPE_IMAGE|FILE_MANAGER_MIME_TYPE_VIDEO)); - file_manager_page->set_current_directory(get_home_dir().data); + file_manager_page->set_current_directory(fm_dir.string()); auto file_manager_body = create_body(); file_manager_page->get_files_in_directory(file_manager_body->items); std::vector file_manager_tabs; @@ -3453,6 +3447,10 @@ namespace QuickMedia { redraw = true; frame_skip_text_entry = true; } + } else if(event.key.code == sf::Keyboard::S && event.key.control) { + BodyItem *selected_item = thread_body->get_selected(); + if(selected_item && !selected_item->url.empty()) + download_async_gui(selected_item->url, FileManagerPage::get_last_accessed_directory(file_manager_start_dir).string(), false, false); } BodyItem *selected_item = thread_body->get_selected(); @@ -3572,7 +3570,7 @@ namespace QuickMedia { redraw = true; frame_skip_text_entry = true; } else if(event.key.code == sf::Keyboard::S && event.key.control) { - download_async_gui(attached_image_url, false, false); + download_async_gui(attached_image_url, FileManagerPage::get_last_accessed_directory(file_manager_start_dir).string(), false, false); } } } @@ -4965,7 +4963,7 @@ namespace QuickMedia { redraw = true; return true; } else if(message_type == MessageType::FILE) { - download_async_gui(selected->url, false, no_video); + download_async_gui(selected->url, FileManagerPage::get_last_accessed_directory(file_manager_start_dir).string(), false, no_video); return true; } @@ -5006,7 +5004,7 @@ namespace QuickMedia { if(selected_item_message) { MessageType message_type = selected_item_message->type; if(!selected->url.empty() && message_type >= MessageType::IMAGE && message_type <= MessageType::FILE) { - download_async_gui(selected->url, false, no_video); + download_async_gui(selected->url, FileManagerPage::get_last_accessed_directory(file_manager_start_dir).string(), false, no_video); return true; } } @@ -5436,8 +5434,9 @@ namespace QuickMedia { tab.body->clear_cache(); } + std::filesystem::path &fm_dir = FileManagerPage::get_last_accessed_directory(file_manager_start_dir); auto file_manager_page = std::make_unique(this); - file_manager_page->set_current_directory(get_home_dir().data); + file_manager_page->set_current_directory(fm_dir.string()); auto file_manager_body = create_body(); file_manager_page->get_files_in_directory(file_manager_body->items); std::vector file_manager_tabs; @@ -6510,14 +6509,13 @@ namespace QuickMedia { sf::Event event; auto file_manager_page = std::make_unique(this); - std::string home_dir = get_home_dir().data; - file_manager_page->set_current_directory(home_dir); + file_manager_page->set_current_directory(file_manager_start_dir); auto file_manager_body = create_body(); file_manager_page->get_files_in_directory(file_manager_body->items); auto search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER); Tabs ui_tabs(&rounded_rectangle_shader); - const int tab_path_index = ui_tabs.add_tab(home_dir); + const int tab_path_index = ui_tabs.add_tab(file_manager_start_dir); search_bar->onTextUpdateCallback = [&file_manager_body](const std::string &text) { file_manager_body->filter_search_fuzzy(text); -- cgit v1.2.3