aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp59
1 files changed, 51 insertions, 8 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 594b93a..c9789cf 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -13,6 +13,7 @@
#include "../plugins/Soundcloud.hpp"
#include "../plugins/FileManager.hpp"
#include "../plugins/Pipe.hpp"
+#include "../plugins/Saucenao.hpp"
#include "../include/Scale.hpp"
#include "../include/Program.hpp"
#include "../include/VideoPlayer.hpp"
@@ -76,7 +77,8 @@ static const std::pair<const char*, const char*> valid_plugins[] = {
std::make_pair("mastodon", "pleroma_logo.png"),
std::make_pair("pleroma", "pleroma_logo.png"),
std::make_pair("file-manager", nullptr),
- std::make_pair("stdin", nullptr)
+ std::make_pair("stdin", nullptr),
+ std::make_pair("saucenao", nullptr)
};
static const char* get_plugin_logo_name(const char *plugin_name) {
@@ -301,12 +303,12 @@ namespace QuickMedia {
static void usage() {
fprintf(stderr, "usage: quickmedia <plugin> [--no-video] [--use-system-mpv-config] [--dir <directory>] [-e <window>]\n");
fprintf(stderr, "OPTIONS:\n");
- fprintf(stderr, " plugin The plugin to use. Should be either launcher, 4chan, manga, manganelo, manganelos, mangatown, mangakatana, mangadex, readm, youtube, spotify, soundcloud, nyaa.si, matrix, file-manager, stdin, pornhub, spankbang, xvideos or xhamster\n");
+ fprintf(stderr, " plugin The plugin to use. Should be either launcher, 4chan, manga, manganelo, manganelos, mangatown, mangakatana, mangadex, readm, youtube, spotify, soundcloud, nyaa.si, matrix, saucenao, file-manager, stdin, pornhub, spankbang, xvideos or xhamster\n");
fprintf(stderr, " --no-video Only play audio when playing a video. Disabled by default\n");
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 <directory> Set the start directory when using file-manager\n");
+ fprintf(stderr, " --dir <directory> Set the start directory when using file-manager. Default is the user home directory\n");
fprintf(stderr, " -e <window> Embed QuickMedia into another window\n");
fprintf(stderr, "EXAMPLES:\n");
fprintf(stderr, " quickmedia launcher\n");
@@ -450,10 +452,20 @@ namespace QuickMedia {
return -1;
}
+ Path home_dir = get_home_dir();
+ if(!start_dir)
+ start_dir = home_dir.data.c_str();
+
int start_tab_index = 0;
+ FileManagerMimeType fm_mine_type = FILE_MANAGER_MIME_TYPE_ALL;
init(parent_window);
- load_plugin_by_name(tabs, start_dir, start_tab_index);
+ bool is_saucenao = (strcmp(plugin_name, "saucenao") == 0);
+ if(is_saucenao) {
+ plugin_name = "file-manager";
+ fm_mine_type = FILE_MANAGER_MIME_TYPE_IMAGE;
+ }
+ load_plugin_by_name(tabs, start_dir, start_tab_index, fm_mine_type);
while(!tabs.empty() || matrix) {
if(matrix) {
@@ -473,7 +485,10 @@ 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);
+ 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);
}
}
@@ -787,7 +802,7 @@ namespace QuickMedia {
.related_media_thumbnail_handler({{"//img", "src", "/thumb-"}});
}
- void Program::load_plugin_by_name(std::vector<Tab> &tabs, const char *start_dir, int &start_tab_index) {
+ void Program::load_plugin_by_name(std::vector<Tab> &tabs, const char *start_dir, int &start_tab_index, FileManagerMimeType fm_mime_type) {
if(!plugin_name || plugin_name[0] == '\0')
return;
@@ -898,7 +913,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);
+ auto file_manager_page = std::make_unique<FileManagerPage>(this, fm_mime_type);
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;
@@ -911,6 +926,8 @@ 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)});
@@ -1378,7 +1395,7 @@ namespace QuickMedia {
}
if(tabs[selected_tab].page->is_single_page()) {
- tabs[selected_tab].search_bar->clear();
+ if(tabs[selected_tab].search_bar) tabs[selected_tab].search_bar->clear();
if(new_tabs.size() == 1)
tabs[selected_tab].body = std::move(new_tabs[0].body);
else
@@ -1615,6 +1632,19 @@ namespace QuickMedia {
TrackablePage *trackable_page = dynamic_cast<TrackablePage*>(tabs[selected_tab].page.get());
trackable_page->track(selected_item->get_title());
}
+ } else if(event.key.code == sf::Keyboard::C && event.key.control) {
+ BodyItem *selected_item = tabs[selected_tab].body->get_selected();
+ if(selected_item) {
+ std::string title = selected_item->get_title();
+ std::string description = selected_item->get_description();
+ std::string clipboard = title;
+ if(!clipboard.empty()) {
+ clipboard += '\n';
+ clipboard += std::move(description);
+ }
+ if(!clipboard.empty())
+ sf::Clipboard::setString(sf::String::fromUtf8(clipboard.begin(), clipboard.end()));
+ }
}
}
}
@@ -3089,6 +3119,19 @@ namespace QuickMedia {
frame_skip_text_entry = true;
} else if(event.key.code == sf::Keyboard::D && event.key.control) {
selected_file_for_upload.clear();
+ } else if(event.key.code == sf::Keyboard::C && event.key.control) {
+ BodyItem *selected_item = thread_body->get_selected();
+ if(selected_item) {
+ std::string title = selected_item->get_title();
+ std::string description = selected_item->get_description();
+ std::string clipboard = title;
+ if(!clipboard.empty()) {
+ clipboard += '\n';
+ clipboard += std::move(description);
+ }
+ if(!clipboard.empty())
+ sf::Clipboard::setString(sf::String::fromUtf8(clipboard.begin(), clipboard.end()));
+ }
}
BodyItem *selected_item = thread_body->get_selected();