From 42ef59ef17cb0a56c6ac1d8f220db7ca461c5411 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 22 Oct 2020 04:52:32 +0200 Subject: Matrix: temporary disable vim keys that interfer with room search, also include embedded item when pressing enter --- README.md | 4 +--- TODO | 3 ++- include/NetUtils.hpp | 2 +- include/Path.hpp | 7 +------ project.conf | 2 +- src/Body.cpp | 8 ++++---- src/NetUtils.cpp | 5 +---- src/QuickMedia.cpp | 44 ++++++++++++++++++++++++-------------------- 8 files changed, 35 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index a9778ca..7033d2f 100644 --- a/README.md +++ b/README.md @@ -46,14 +46,12 @@ Press `Tab` to switch between username/password field in login panel.\ Press `Ctrl + C` to copy the url of the currently playing video to the clipboard (with timestamp).\ Press `Ctrl + V` to paste the content of your clipboard into the search bar.\ Press `Enter` to view image/video attached to matrix message, or to view the url in the message in quickmedia (youtube) or in the browser.\ -Press `M or I` to begin writing a message in a matrix room, press `ESC` to cancel.\ +Press `M` to begin writing a message in a matrix room, press `ESC` to cancel.\ Press `R` to reply to a message on matrix, press `ESC` to cancel.\ Press `E` to edit a message on matrix, press `ESC` to cancel. Currently only works for your own messages.\ Press `D` to delete a message on matrix. Currently deleting a message only deletes the event, so if you delete an edit then the original message wont be deleted.\ Press `Ctrl + V` to upload media to room in matrix, if the clipboard contains a path to an absolute filepath. -In the matrix client you can also navigate using VIM keys (H, J, K, L). - In matrix you can select a message with enter to open the url in the message (or if there are multiple urls then a menu will appear for selecting which to open). ## Matrix commands `/upload` to upload an image. TODO: Support regular files and videos.\ diff --git a/TODO b/TODO index 2da7a9c..6ba625a 100644 --- a/TODO +++ b/TODO @@ -109,4 +109,5 @@ Remove calls to get the original message of an edit in edits and replies in matr Read image exif into to apply image rotation. This is common in images taken on phones. If not done, the width and height will also be mixed and thumbnail fallback size will be incorrectly calculated (for example in matrix). Handle M_LIMIT_EXCEEDED in matrix Check if we need to call /_matrix/client/r0/notifications for intial sync to receive old notifications or if /sync always includes mentions. -Maybe dont clear cache for body items when filtering. \ No newline at end of file +Maybe dont clear cache for body items when filtering. +Change scroll in body when previous items change size (such as when thumbnail has finished loading). \ No newline at end of file diff --git a/include/NetUtils.hpp b/include/NetUtils.hpp index 84b9d18..4770fb4 100644 --- a/include/NetUtils.hpp +++ b/include/NetUtils.hpp @@ -7,5 +7,5 @@ namespace QuickMedia { void html_escape_sequences(std::string &str); void html_unescape_sequences(std::string &str); std::string url_param_encode(const std::string ¶m); - std::vector extract_urls(const std::string &str); + void extract_urls(const std::string &str, std::vector &urls); } \ No newline at end of file diff --git a/include/Path.hpp b/include/Path.hpp index 95a5d23..d26f605 100644 --- a/include/Path.hpp +++ b/include/Path.hpp @@ -6,14 +6,9 @@ namespace QuickMedia { class Path { public: Path() = default; - ~Path() = default; - Path(const Path &other) = default; - Path& operator=(const Path &other) = default; + Path(const char *path) : data(path) {} Path(const std::string &path) : data(path) {} - Path(Path &&other) { - data = std::move(other.data); - } Path& join(const Path &other) { data += "/"; diff --git a/project.conf b/project.conf index 3950938..3c200db 100644 --- a/project.conf +++ b/project.conf @@ -17,4 +17,4 @@ x11 = "1" xrandr = "1" jsoncpp = "1" cppcodec-1 = "0" -gl = ">=0" \ No newline at end of file +gl = ">=0" diff --git a/src/Body.cpp b/src/Body.cpp index 6b7826d..f1c101f 100644 --- a/src/Body.cpp +++ b/src/Body.cpp @@ -476,14 +476,14 @@ namespace QuickMedia { else strftime(time_str, sizeof(time_str) - 1, "%a %b %d %H:%M:%S %Y", message_tm); */ - strftime(time_str, sizeof(time_str) - 1, "%H:%M:%S", message_tm); + strftime(time_str, sizeof(time_str) - 1, "%a %b %d %H:%M", message_tm); if(body_item->timestamp_text) body_item->timestamp_text->setString(time_str); else - body_item->timestamp_text = std::make_unique(time_str, *font, 14); + body_item->timestamp_text = std::make_unique(time_str, *font, 10); - body_item->timestamp_text->setFillColor(sf::Color(185, 190, 198)); + body_item->timestamp_text->setFillColor(sf::Color(185, 190, 198, 100)); } } @@ -702,7 +702,7 @@ namespace QuickMedia { } if(item->timestamp_text) { - item->timestamp_text->setPosition(std::floor(item_pos.x + size.x - item->timestamp_text->getLocalBounds().width - padding_x), timestamp_text_y + 4.0f); + item->timestamp_text->setPosition(std::floor(item_pos.x + size.x - item->timestamp_text->getLocalBounds().width - padding_x), timestamp_text_y + 8.0f); window.draw(*item->timestamp_text); } diff --git a/src/NetUtils.cpp b/src/NetUtils.cpp index e87c42c..4d5a940 100644 --- a/src/NetUtils.cpp +++ b/src/NetUtils.cpp @@ -105,9 +105,7 @@ namespace QuickMedia { // Implementation follows URI standard: https://tools.ietf.org/html/rfc3986#section-2.2 // TODO: Maybe check if the TLD only contains valid characters (is_alpha)? - std::vector extract_urls(const std::string &str) { - std::vector urls; - + void extract_urls(const std::string &str, std::vector &urls) { size_t url_start = std::string::npos; size_t url_dot_index = std::string::npos; // str.size() is fine, we want to include the NULL character so we can extract url at the end of the string @@ -135,6 +133,5 @@ namespace QuickMedia { } } } - return urls; } } \ No newline at end of file diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 48ef01b..d0a93fe 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -108,7 +108,7 @@ static bool vsync_set = false; static bool test_vsync(Display *disp, Window window) { unsigned int swap = 0; glXQueryDrawable(disp, window, GLX_SWAP_INTERVAL_EXT, &swap); - printf("The swap interval is %u\n", swap); + fprintf(stderr, "The swap interval is %u\n", swap); return swap == 1; } @@ -3180,7 +3180,7 @@ namespace QuickMedia { room_search_bar.onTextSubmitCallback = [this, &tabs, &selected_tab, ¤t_room, &room_name_text, &modify_related_messages_in_current_room, &room_avatar_thumbnail_data, - &read_marker_timeout_ms, &redraw] + &read_marker_timeout_ms, &redraw, &room_search_bar] (const std::string&) { BodyItem *selected_item = tabs[ROOMS_TAB_INDEX].body->get_selected(); @@ -3209,9 +3209,11 @@ namespace QuickMedia { read_marker_timeout_ms = 0; redraw = true; + room_search_bar.clear(); + tabs[ROOMS_TAB_INDEX].body->filter_search_fuzzy(""); }; - Entry chat_input("Press m or i to begin writing a message...", font.get(), cjk_font.get()); + Entry chat_input("Press m to begin writing a message...", font.get(), cjk_font.get()); chat_input.draw_background = false; chat_input.set_editable(false); @@ -3468,12 +3470,10 @@ namespace QuickMedia { } else if(event.type == sf::Event::Resized || event.type == sf::Event::GainedFocus) { redraw = true; } else if(event.type == sf::Event::KeyPressed && chat_state == ChatState::NAVIGATING) { - if(event.key.code == sf::Keyboard::Up || event.key.code == sf::Keyboard::PageUp || event.key.code == sf::Keyboard::Home || event.key.code == sf::Keyboard::K) - { + if(event.key.code == sf::Keyboard::Up || event.key.code == sf::Keyboard::PageUp || event.key.code == sf::Keyboard::Home){ bool hit_top = false; switch(event.key.code) { case sf::Keyboard::Up: - case sf::Keyboard::K: hit_top = !tabs[selected_tab].body->select_previous_item(); break; case sf::Keyboard::PageUp: @@ -3498,15 +3498,15 @@ namespace QuickMedia { return messages; }); } - } else if(event.key.code == sf::Keyboard::Down || event.key.code == sf::Keyboard::J) { + } else if(event.key.code == sf::Keyboard::Down) { tabs[selected_tab].body->select_next_item(); } else if(event.key.code == sf::Keyboard::PageDown) { tabs[selected_tab].body->select_next_page(); } else if(event.key.code == sf::Keyboard::End) { tabs[selected_tab].body->select_last_item(); - } else if((event.key.code == sf::Keyboard::Left || event.key.code == sf::Keyboard::H) && synced) { + } else if((event.key.code == sf::Keyboard::Left) && synced && selected_tab > 0) { tabs[selected_tab].body->clear_cache(); - selected_tab = std::max(0, selected_tab - 1); + --selected_tab; read_marker_timer.restart(); redraw = true; if(typing && current_room) { @@ -3514,9 +3514,9 @@ namespace QuickMedia { typing = false; typing_futures.push_back(std::async(typing_async_func, false, current_room)); } - } else if((event.key.code == sf::Keyboard::Right || event.key.code == sf::Keyboard::L) && synced) { + } else if((event.key.code == sf::Keyboard::Right) && synced && selected_tab < (int)tabs.size() - 1) { tabs[selected_tab].body->clear_cache(); - selected_tab = std::min((int)tabs.size() - 1, selected_tab + 1); + ++selected_tab; read_marker_timer.restart(); redraw = true; if(typing && current_room) { @@ -3555,9 +3555,10 @@ namespace QuickMedia { } // TODO: If content type is a file, show file-manager prompt where it should be saved and asynchronously save it instead - - const std::string &message_str = selected->get_description(); - std::vector urls = extract_urls(message_str); + std::vector urls; + extract_urls(selected->get_description(), urls); + if(selected->embedded_item) + extract_urls(selected->embedded_item->get_description(), urls); if(urls.size() == 1) { launch_url(urls[0]); } else if(urls.size() > 1) { @@ -3584,12 +3585,15 @@ namespace QuickMedia { } else if(event.key.code == sf::Keyboard::End) { url_selection_body.select_last_item(); } else if(event.key.code == sf::Keyboard::Left) { - // TODO: Clear url_selection_body? - selected_tab = std::max(0, selected_tab - 1); - chat_state = ChatState::NAVIGATING; + if(selected_tab > 0) { + --selected_tab; + chat_state = ChatState::NAVIGATING; + } } else if(event.key.code == sf::Keyboard::Right) { - selected_tab = std::min((int)tabs.size() - 1, selected_tab + 1); - chat_state = ChatState::NAVIGATING; + if(selected_tab < (int)tabs.size() - 1) { + ++selected_tab; + chat_state = ChatState::NAVIGATING; + } } else if(event.key.code == sf::Keyboard::Escape) { url_selection_body.clear_items(); chat_state = ChatState::NAVIGATING; @@ -3605,7 +3609,7 @@ namespace QuickMedia { chat_input.set_editable(false); } - if(event.key.code == sf::Keyboard::M || event.key.code == sf::Keyboard::I) { + if(event.key.code == sf::Keyboard::M) { chat_input.set_editable(true); chat_state = ChatState::TYPING_MESSAGE; } -- cgit v1.2.3