diff options
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r-- | src/QuickMedia.cpp | 101 |
1 files changed, 62 insertions, 39 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 9593e80..4647787 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -335,9 +335,9 @@ namespace QuickMedia { if(!thumbnail_url.empty()) { body_item->thumbnail_url = thumbnail_url; body_item->thumbnail_is_local = true; - body_item->thumbnail_size.x = 32; - body_item->thumbnail_size.y = 32; } + body_item->thumbnail_size.x = 32; + body_item->thumbnail_size.y = 32; return body_item; } @@ -414,7 +414,7 @@ namespace QuickMedia { if(upscale_image_action != UpscaleImageAction::NO) { if(!is_manga_plugin(plugin_name)) { - fprintf(stderr, "Option --upscale-images/-upscale-images-force is only valid for manganelo, manganelos, mangatown and mangadex\n"); + fprintf(stderr, "Option --upscale-images/-upscale-images-force is only valid for manga plugins\n"); return -2; } @@ -466,14 +466,21 @@ namespace QuickMedia { int start_tab_index = 0; FileManagerMimeType fm_mine_type = FILE_MANAGER_MIME_TYPE_ALL; + FileSelectionHandler file_selection_handler = nullptr; + + FileSelectionHandler saucenao_file_selection_handler = [this]() { + std::vector<Tab> tabs; + tabs.push_back(Tab{create_body(), std::make_unique<SaucenaoPage>(this, selected_files[0], true), nullptr}); + return tabs; + }; init(parent_window); - bool is_saucenao = (strcmp(plugin_name, "saucenao") == 0); - if(is_saucenao) { + if(strcmp(plugin_name, "saucenao") == 0) { plugin_name = "file-manager"; 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); + load_plugin_by_name(tabs, start_dir, start_tab_index, fm_mine_type, std::move(file_selection_handler)); while(!tabs.empty() || matrix) { if(matrix) { @@ -493,10 +500,12 @@ namespace QuickMedia { if(strcmp(plugin_name, "launcher") == 0) { plugin_name = pipe_selected_text.c_str(); - load_plugin_by_name(tabs, start_dir, start_tab_index, fm_mine_type); - } else if(strcmp(plugin_name, "file-manager") == 0 && is_saucenao && !selected_files.empty()) { - plugin_name = "saucenao"; - load_plugin_by_name(tabs, start_dir, start_tab_index, fm_mine_type); + if(strcmp(plugin_name, "saucenao") == 0) { + plugin_name = "file-manager"; + 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)); } } @@ -884,7 +893,7 @@ namespace QuickMedia { return PluginResult::OK; } - void Program::load_plugin_by_name(std::vector<Tab> &tabs, const char *start_dir, int &start_tab_index, FileManagerMimeType fm_mime_type) { + void Program::load_plugin_by_name(std::vector<Tab> &tabs, const char *start_dir, int &start_tab_index, FileManagerMimeType fm_mime_type, FileSelectionHandler file_selection_handler) { if(!plugin_name || plugin_name[0] == '\0') return; @@ -921,6 +930,7 @@ namespace QuickMedia { pipe_body->items.push_back(create_launcher_body_item("Readm", "readm", resources_root + "icons/readm_launcher.png")); pipe_body->items.push_back(create_launcher_body_item("Matrix", "matrix", resources_root + "icons/matrix_launcher.png")); pipe_body->items.push_back(create_launcher_body_item("Nyaa.si", "nyaa.si", resources_root + "icons/nyaa_si_launcher.png")); + pipe_body->items.push_back(create_launcher_body_item("SauceNAO", "saucenao", "")); pipe_body->items.push_back(create_launcher_body_item("Soundcloud", "soundcloud", resources_root + "icons/soundcloud_launcher.png")); pipe_body->items.push_back(create_launcher_body_item("Spotify", "spotify", resources_root + "icons/spotify_launcher.png")); pipe_body->items.push_back(create_launcher_body_item("YouTube", "youtube", resources_root + "icons/yt_launcher.png")); @@ -996,7 +1006,7 @@ namespace QuickMedia { boards_page->get_boards(boards_body->items); 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<FileManagerPage>(this, fm_mime_type); + auto file_manager_page = std::make_unique<FileManagerPage>(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; @@ -1009,8 +1019,6 @@ namespace QuickMedia { auto pipe_body = create_body(); PipePage::load_body_items_from_stdin(pipe_body->items); tabs.push_back(Tab{std::move(pipe_body), std::make_unique<PipePage>(this), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); - } else if(strcmp(plugin_name, "saucenao") == 0) { - tabs.push_back(Tab{create_body(), std::make_unique<SaucenaoPage>(this, selected_files[0]), nullptr}); } else if(strcmp(plugin_name, "youtube") == 0) { start_tab_index = 1; tabs.push_back(Tab{create_body(), std::make_unique<YoutubeSubscriptionsPage>(this), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); @@ -1212,11 +1220,6 @@ namespace QuickMedia { show_notification("QuickMedia", "Failed to create directory: " + content_storage_dir.data, Urgency::CRITICAL); exit(1); } - Path credentials_storage_dir = get_storage_dir().join("credentials"); - if(create_directory_recursive(credentials_storage_dir) != 0) { - show_notification("QuickMedia", "Failed to create directory: " + credentials_storage_dir.data, Urgency::CRITICAL); - exit(1); - } // TODO: Make asynchronous for_files_in_dir_sort_last_modified(content_storage_dir, [&history_items, plugin_name](const std::filesystem::path &filepath) { // This can happen when QuickMedia crashes/is killed while writing to storage. @@ -1320,6 +1323,7 @@ namespace QuickMedia { void Program::select_file(const std::string &filepath) { puts(filepath.c_str()); + selected_files.clear(); selected_files.push_back(filepath); } @@ -1471,12 +1475,15 @@ namespace QuickMedia { if(tabs[selected_tab].page->is_single_page()) { if(tabs[selected_tab].search_bar) tabs[selected_tab].search_bar->clear(); - if(new_tabs.size() == 1) + if(new_tabs.size() == 1 && !new_tabs[0].page) { tabs[selected_tab].body = std::move(new_tabs[0].body); - else + tabs[selected_tab].page->submit_body_item = prev_selected_item; + return; + } else if(new_tabs.empty()) { loop_running = false; - tabs[selected_tab].page->submit_body_item = prev_selected_item; - return; + tabs[selected_tab].page->submit_body_item = prev_selected_item; + return; + } } if(new_tabs.empty()) { @@ -2927,6 +2934,7 @@ namespace QuickMedia { sf::Texture captcha_texture; sf::Sprite captcha_sprite; std::mutex captcha_image_mutex; + std::string attached_image_url; auto attached_image_texture = std::make_unique<sf::Texture>(); sf::Sprite attached_image_sprite; @@ -3153,21 +3161,21 @@ namespace QuickMedia { video_content_page(thread_page, thread_page, selected_item->get_title(), true, thread_body->items, thread_body->get_selected_item()); redraw = true; } else { - load_image_future.cancel(); - downloading_image = true; - navigation_stage = NavigationStage::VIEWING_ATTACHED_IMAGE; - load_image_future = AsyncTask<std::string>([&thread_body]() { - std::string image_data; - BodyItem *selected_item = thread_body->get_selected(); - if(!selected_item || selected_item->url.empty()) { + BodyItem *selected_item = thread_body->get_selected(); + if(selected_item && !selected_item->url.empty()) { + load_image_future.cancel(); + downloading_image = true; + navigation_stage = NavigationStage::VIEWING_ATTACHED_IMAGE; + attached_image_url = selected_item->url; + load_image_future = AsyncTask<std::string>([attached_image_url]() { + std::string image_data; + if(download_to_string_cache(attached_image_url, image_data, {}) != DownloadResult::OK) { + show_notification("QuickMedia", "Failed to download image: " + attached_image_url, Urgency::CRITICAL); + image_data.clear(); + } return image_data; - } - if(download_to_string_cache(selected_item->url, image_data, {}) != DownloadResult::OK) { - show_notification("QuickMedia", "Failed to download image: " + selected_item->url, Urgency::CRITICAL); - image_data.clear(); - } - return image_data; - }); + }); + } } } } else if(event.key.code == sf::Keyboard::U) { @@ -3207,6 +3215,15 @@ namespace QuickMedia { if(!clipboard.empty()) sf::Clipboard::setString(sf::String::fromUtf8(clipboard.begin(), clipboard.end())); } + } else if(event.key.code == sf::Keyboard::I && event.key.control) { + BodyItem *selected_item = thread_body->get_selected(); + if(selected_item && !selected_item->url.empty()) { + std::vector<Tab> saucenao_tabs; + saucenao_tabs.push_back(Tab{create_body(), std::make_unique<SaucenaoPage>(this, selected_item->url, false), nullptr}); + page_loop(saucenao_tabs); + redraw = true; + frame_skip_text_entry = true; + } } BodyItem *selected_item = thread_body->get_selected(); @@ -3252,7 +3269,7 @@ namespace QuickMedia { comment_input.move_caret_to_end(); } - if(event.key.code == sf::Keyboard::I) { + if(event.key.code == sf::Keyboard::I && !event.key.control) { frame_skip_text_entry = true; navigation_stage = NavigationStage::REPLYING; comment_input.set_editable(true); @@ -3310,6 +3327,12 @@ namespace QuickMedia { if(event.key.code == sf::Keyboard::Escape || event.key.code == sf::Keyboard::BackSpace) { navigation_stage = NavigationStage::VIEWING_COMMENTS; attached_image_texture.reset(new sf::Texture()); + } else if(event.key.code == sf::Keyboard::I && event.key.control && !attached_image_url.empty()) { + std::vector<Tab> saucenao_tabs; + saucenao_tabs.push_back(Tab{create_body(), std::make_unique<SaucenaoPage>(this, attached_image_url, false), nullptr}); + page_loop(saucenao_tabs); + redraw = true; + frame_skip_text_entry = true; } } } @@ -4885,7 +4908,7 @@ namespace QuickMedia { chat_input.set_editable(false); } - if(event.key.code == sf::Keyboard::I) { + if(event.key.code == sf::Keyboard::I && !event.key.control) { frame_skip_text_entry = true; chat_input.set_editable(true); chat_state = ChatState::TYPING_MESSAGE; |