aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-05-11 00:53:22 +0200
committerdec05eba <dec05eba@protonmail.com>2021-05-11 00:53:22 +0200
commit6b90f55f4dc14b9d39fa0dbf6b82b3c12ccc29d9 (patch)
tree42c6febe79d5f14136ca494acca91c235017f60d
parent8b9870c8de18ec0828d087abb0f33335caad1c2c (diff)
Allow downloading regular files with matrix (ctrl+s when item is selected)
-rw-r--r--src/QuickMedia.cpp41
1 files changed, 36 insertions, 5 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index d4e9bac..b4fa915 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -4718,6 +4718,29 @@ namespace QuickMedia {
return false;
};
+ auto download_selected_item = [this, &ui_tabs, PINNED_TAB_INDEX, MESSAGES_TAB_INDEX](BodyItem *selected) {
+ if(!selected)
+ return false;
+
+ const int selected_tab = ui_tabs.get_selected();
+ Message *selected_item_message = nullptr;
+ if(selected_tab == MESSAGES_TAB_INDEX) {
+ selected_item_message = static_cast<Message*>(selected->userdata);
+ } else if(selected_tab == PINNED_TAB_INDEX && static_cast<PinnedEventData*>(selected->userdata)->status == FetchStatus::FINISHED_LOADING) {
+ selected_item_message = static_cast<PinnedEventData*>(selected->userdata)->message;
+ }
+
+ if(selected_item_message) {
+ MessageType message_type = selected_item_message->type;
+ if(!selected->url.empty() && (message_type == MessageType::VIDEO || message_type == MessageType::IMAGE || message_type == MessageType::AUDIO)) {
+ download_async_gui(selected->url, false, force_no_video);
+ return true;
+ }
+ }
+
+ return false;
+ };
+
auto update_pinned_messages_author = [&tabs, &current_room, PINNED_TAB_INDEX](const std::shared_ptr<UserInfo> &user) {
fprintf(stderr, "updated pinned messages author for user: %s\n", user->user_id.c_str());
for(auto &pinned_body_item : tabs[PINNED_TAB_INDEX].body->items) {
@@ -4931,11 +4954,19 @@ namespace QuickMedia {
}
}
- if((selected_tab == MESSAGES_TAB_INDEX || selected_tab == PINNED_TAB_INDEX) && event.key.code == sf::Keyboard::Enter && !frame_skip_text_entry) {
- BodyItem *selected = tabs[selected_tab].body->get_selected();
- if(selected) {
- if(!display_url_or_image(selected))
- display_url_or_image(selected->embedded_item.get());
+ if((selected_tab == MESSAGES_TAB_INDEX || selected_tab == PINNED_TAB_INDEX) && !frame_skip_text_entry) {
+ if(event.key.code == sf::Keyboard::Enter) {
+ BodyItem *selected = tabs[selected_tab].body->get_selected();
+ if(selected) {
+ if(!display_url_or_image(selected))
+ display_url_or_image(selected->embedded_item.get());
+ }
+ } else if(event.key.code == sf::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());
+ }
}
}