aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-10-31 22:54:59 +0100
committerdec05eba <dec05eba@protonmail.com>2022-10-31 22:54:59 +0100
commit53316e4bada29f1392df2528d8616afde17f570b (patch)
tree4b687dc2bd2b46da1b2d31648bc40ceb6179972f /src/QuickMedia.cpp
parent9540ab168be53f3ec2aec513d855df0194d9cb8a (diff)
Add ctrl+shift+s to download files without a dialog
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp68
1 files changed, 47 insertions, 21 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 44b1315..fbf2006 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -384,6 +384,7 @@ namespace QuickMedia {
std::string program_path = dirname(argv[0]);
std::string instance;
std::string download_filename;
+ bool no_dialog = false;
for(int i = 1; i < argc; ++i) {
if(!plugin_name) {
@@ -481,6 +482,8 @@ namespace QuickMedia {
usage();
return -1;
}
+ } else if(strcmp(argv[i], "--no-dialog") == 0) {
+ no_dialog = true;
} else if(strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
usage();
return 0;
@@ -560,7 +563,7 @@ namespace QuickMedia {
};
no_video = force_no_video;
- init(parent_window, program_path);
+ init(parent_window, program_path, no_dialog);
if(strcmp(plugin_name, "download") == 0) {
if(!url) {
@@ -568,7 +571,7 @@ namespace QuickMedia {
usage();
return -1;
}
- download_page(url, download_filename);
+ download_page(url, download_filename, no_dialog);
return exit_code;
}
@@ -641,7 +644,7 @@ namespace QuickMedia {
return focused_monitor_center;
}
- void Program::init(mgl::WindowHandle parent_window, std::string &program_path) {
+ void Program::init(mgl::WindowHandle parent_window, std::string &program_path, bool no_dialog) {
disp = XOpenDisplay(NULL);
if (!disp) {
show_notification("QuickMedia", "Failed to open display to X11 server", Urgency::CRITICAL);
@@ -669,6 +672,7 @@ namespace QuickMedia {
window_create_params.min_size = window_size;
window_create_params.max_size = window_size;
}
+ window_create_params.hidden = no_dialog;
window_create_params.parent_window = parent_window;
if(!window.create("QuickMedia", std::move(window_create_params))) {
show_notification("QuickMedia", "Failed to create opengl window", Urgency::CRITICAL);
@@ -3058,7 +3062,7 @@ namespace QuickMedia {
redirect_focus_to_video_player_window(video_player_window);
}
- void Program::video_page_download_video(const std::string &url, const std::string &filename, mgl::WindowHandle video_player_window) {
+ void Program::video_page_download_video(const std::string &url, const std::string &filename, mgl::WindowHandle video_player_window, bool download_no_dialog) {
bool separate_audio_option = url_should_download_with_youtube_dl(url);
std::string video_id;
separate_audio_option |= youtube_url_extract_id(url, video_id);
@@ -3067,7 +3071,7 @@ namespace QuickMedia {
separate_audio_option = false;
if(!separate_audio_option) {
- download_async_gui(url, file_manager_start_dir.string(), no_video, filename);
+ download_async_gui(url, file_manager_start_dir.string(), no_video, filename, download_no_dialog);
return;
}
@@ -3097,7 +3101,7 @@ namespace QuickMedia {
if(!selected)
return;
- download_async_gui(url, file_manager_start_dir.string(), audio_only, filename);
+ download_async_gui(url, file_manager_start_dir.string(), audio_only, filename, download_no_dialog);
}
bool Program::video_download_if_non_streamable(std::string &video_url, std::string &audio_url, bool &is_audio_only, bool &has_embedded_audio, PageType previous_page) {
@@ -3595,7 +3599,8 @@ namespace QuickMedia {
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
KeySym pressed_keysym = XKeycodeToKeysym(disp, xev.xkey.keycode, 0);
#pragma GCC diagnostic pop
- bool pressing_ctrl = (CLEANMASK(xev.xkey.state) == ControlMask);
+ const bool pressing_ctrl = (CLEANMASK(xev.xkey.state) & ControlMask);
+ const bool pressing_shift = (CLEANMASK(xev.xkey.state) & ShiftMask);
if(pressed_keysym == XK_q && pressing_ctrl) {
window.close();
} else if(pressed_keysym == XK_Escape || pressed_keysym == XK_BackSpace) {
@@ -3614,7 +3619,8 @@ namespace QuickMedia {
} else if(pressed_keysym == XK_f && pressing_ctrl) {
video_player->cycle_fullscreen();
} else if(pressed_keysym == XK_s && pressing_ctrl && !video_page->is_local()) {
- video_page_download_video(video_page->get_download_url(video_get_max_height()), video_page->get_filename(), video_player_window);
+ const bool download_no_dialog = pressing_shift;
+ video_page_download_video(video_page->get_download_url(video_get_max_height()), video_page->get_filename(), video_player_window, download_no_dialog);
} else if(pressed_keysym == XK_F5 && !video_page->is_local()) {
double resume_start_time = 0.0;
video_player->get_time_in_file(&resume_start_time);
@@ -4777,7 +4783,7 @@ namespace QuickMedia {
} else if(event.key.code == mgl::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, file_manager_start_dir.string(), false, "");
+ download_async_gui(selected_item->url, file_manager_start_dir.string(), false, "", event.key.shift);
}
BodyItem *selected_item = thread_body->get_selected();
@@ -4905,7 +4911,7 @@ namespace QuickMedia {
redraw = true;
frame_skip_text_entry = true;
} else if(event.key.code == mgl::Keyboard::S && event.key.control) {
- download_async_gui(attached_image_url, file_manager_start_dir.string(), false, "");
+ download_async_gui(attached_image_url, file_manager_start_dir.string(), false, "", event.key.shift);
}
}
}
@@ -6556,7 +6562,7 @@ namespace QuickMedia {
avatar_applied = false;
return true;
} else if(message_type == MessageType::FILE) {
- download_async_gui(selected->url, file_manager_start_dir.string(), no_video, filename);
+ download_async_gui(selected->url, file_manager_start_dir.string(), no_video, filename, false);
return true;
}
@@ -6582,7 +6588,7 @@ namespace QuickMedia {
return false;
};
- auto download_selected_item = [this, &ui_tabs, PINNED_TAB_INDEX, MESSAGES_TAB_INDEX](BodyItem *selected) {
+ auto download_selected_item = [this, &ui_tabs, PINNED_TAB_INDEX, MESSAGES_TAB_INDEX](BodyItem *selected, bool no_dialog) {
if(!selected)
return false;
@@ -6609,7 +6615,7 @@ namespace QuickMedia {
else if(string_starts_with(filename, file_prefix))
filename.erase(filename.begin(), filename.begin() + strlen(file_prefix));
- download_async_gui(selected->url, file_manager_start_dir.string(), no_video, filename);
+ download_async_gui(selected->url, file_manager_start_dir.string(), no_video, filename, no_dialog);
return true;
}
}
@@ -6890,8 +6896,8 @@ namespace QuickMedia {
} else if(event.key.code == mgl::Keyboard::S && event.key.control) {
BodyItem *selected = tabs[selected_tab].body->get_selected();
if(selected) {
- if(!download_selected_item(selected))
- download_selected_item(selected->embedded_item.get());
+ if(!download_selected_item(selected, event.key.shift))
+ download_selected_item(selected->embedded_item.get(), event.key.shift);
}
}
}
@@ -7819,7 +7825,7 @@ namespace QuickMedia {
return 0;
}
- void Program::download_page(std::string url, std::string download_filename) {
+ void Program::download_page(std::string url, std::string download_filename, bool no_dialog) {
window.set_title(("QuickMedia - Select where you want to save " + std::string(url)).c_str());
url = invidious_url_to_youtube_url(url);
@@ -7970,10 +7976,25 @@ namespace QuickMedia {
}
string_replace_all(filename, '/', '_');
- std::string output_filepath = file_save_page(filename);
- if(!window.is_open() || output_filepath.empty()) {
- exit_code = 1;
- return;
+ std::string output_filepath;
+ if(no_dialog) {
+ std::string filename_ext = Path(filename).ext();
+ if(is_video_ext(filename_ext.c_str()))
+ output_filepath = get_config().download.video_directory;
+ else if(is_image_ext(filename_ext.c_str()))
+ output_filepath = get_config().download.image_directory;
+ else if(is_music_ext(filename_ext.c_str()))
+ output_filepath = get_config().download.music_directory;
+ else
+ output_filepath = get_config().download.file_directory;
+ output_filepath += "/" + filename;
+ } else {
+ window.set_visible(true);
+ output_filepath = file_save_page(filename);
+ if(!window.is_open() || output_filepath.empty()) {
+ exit_code = 1;
+ return;
+ }
}
mgl::vec2i monitor_size;
@@ -7984,10 +8005,15 @@ namespace QuickMedia {
window.set_size_limits(window_size, window_size);
window.set_position(mgl::vec2i(focused_monitor_center.x - window_size.x * 0.5f, focused_monitor_center.y - window_size.y * 0.5f));
+ std::string window_title = "QuickMedia - downloading ";
+ window_title += Path(output_filepath).filename();
+ window.set_title(window_title.c_str());
+ window.set_visible(true);
+
std::string output_filepath_s = output_filepath;
char *output_dir = dirname(output_filepath_s.data());
if(create_directory_recursive(output_dir) != 0) {
- show_notification("QuickMedia", std::string("Failed to download ") + url + " to " + output_filepath, Urgency::CRITICAL);
+ show_notification("QuickMedia", std::string("Failed to download ") + url + " to " + output_filepath + " (failed to create directory)", Urgency::CRITICAL);
exit_code = 1;
return;
}