From 620123fbd6c18dc48a25cc735565f6d8d85f8639 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 26 Oct 2020 09:48:25 +0100 Subject: Matrix: add room tags Fix pinned events that are added after starting QuickMedia (before this change it adds all elements again to the list). Add /me command. Other fixes... --- include/AsyncImageLoader.hpp | 10 ++------- include/Body.hpp | 4 ++-- include/Entry.hpp | 2 +- include/MessageQueue.hpp | 50 ++++++++++++++++++++++++++++++++++++++++++++ include/Path.hpp | 2 +- include/QuickMedia.hpp | 18 +++++++++------- 6 files changed, 66 insertions(+), 20 deletions(-) create mode 100644 include/MessageQueue.hpp (limited to 'include') diff --git a/include/AsyncImageLoader.hpp b/include/AsyncImageLoader.hpp index 3189565..c1c2e11 100644 --- a/include/AsyncImageLoader.hpp +++ b/include/AsyncImageLoader.hpp @@ -1,16 +1,13 @@ #pragma once #include "../include/Storage.hpp" +#include "../include/MessageQueue.hpp" #include #include #include #include -#include #include #include -#include -#include -#include namespace QuickMedia { enum class LoadingState { @@ -55,9 +52,6 @@ namespace QuickMedia { // TODO: Use curl single-threaded multi-download feature instead std::thread download_image_thread[NUM_IMAGE_LOAD_THREADS]; std::thread load_image_thread; - std::mutex load_image_mutex; - std::condition_variable load_image_cv; - std::deque images_to_load; - bool running = true; + MessageQueue image_load_queue; }; } \ No newline at end of file diff --git a/include/Body.hpp b/include/Body.hpp index f3498c7..9cdcd7b 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -180,7 +180,7 @@ namespace QuickMedia { // because of Text::setMaxWidth void draw_item(sf::RenderWindow &window, BodyItem *item, sf::Vector2f pos, sf::Vector2f size, bool include_embedded_item = true); - float get_item_height(BodyItem *item, bool load_texture = true, bool include_embedded_item = true); + float get_item_height(BodyItem *item, float width, bool load_texture = true, bool include_embedded_item = true); float get_spacing_y() const; static bool string_find_case_insensitive(const std::string &str, const std::string &substr); @@ -216,7 +216,7 @@ namespace QuickMedia { sf::Shader *thumbnail_mask_shader; private: void draw_item(sf::RenderWindow &window, BodyItem *item, const sf::Vector2f &pos, const sf::Vector2f &size, const float item_height, const int item_index, const Json::Value &content_progress, bool include_embedded_item = true); - void update_dirty_state(BodyItem *body_item, sf::Vector2f size); + void update_dirty_state(BodyItem *body_item, float width); void clear_body_item_cache(BodyItem *body_item); sf::Vector2i get_item_thumbnail_size(BodyItem *item) const; private: diff --git a/include/Entry.hpp b/include/Entry.hpp index 23535e4..27c3517 100644 --- a/include/Entry.hpp +++ b/include/Entry.hpp @@ -13,7 +13,7 @@ namespace sf { namespace QuickMedia { // Return true to clear the text - using OnEntrySubmit = std::function; + using OnEntrySubmit = std::function; class Entry { public: diff --git a/include/MessageQueue.hpp b/include/MessageQueue.hpp new file mode 100644 index 0000000..174a227 --- /dev/null +++ b/include/MessageQueue.hpp @@ -0,0 +1,50 @@ +#pragma once + +#include +#include +#include +#include + +namespace QuickMedia { + template + class MessageQueue { + public: + MessageQueue() : running(true) { + + } + + void push(T data) { + std::unique_lock lock(mutex); + data_queue.push_back(std::move(data)); + cv.notify_one(); + } + + std::optional pop_wait() { + if(!running) + return std::nullopt; + std::unique_lock lock(mutex); + while(data_queue.empty() && running) cv.wait(lock); + if(!running) + return std::nullopt; + T data = std::move(data_queue.front()); + data_queue.pop_front(); + return data; + } + + void close() { + std::unique_lock lock(mutex); + running = false; + cv.notify_one(); + } + + void clear() { + std::unique_lock lock(mutex); + data_queue.clear(); + } + private: + std::deque data_queue; + std::mutex mutex; + std::condition_variable cv; + bool running; + }; +} \ No newline at end of file diff --git a/include/Path.hpp b/include/Path.hpp index d26f605..46c8dee 100644 --- a/include/Path.hpp +++ b/include/Path.hpp @@ -24,7 +24,7 @@ namespace QuickMedia { const char* filename() const { size_t index = data.rfind('/'); if(index == std::string::npos) - return "/"; + return data.c_str(); return data.c_str() + index + 1; } diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index 45c499a..bdbafef 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -5,6 +5,7 @@ #include "Page.hpp" #include "Storage.hpp" #include "Tab.hpp" +#include "MessageQueue.hpp" #include #include #include @@ -14,10 +15,7 @@ #include #include #include -#include -#include #include -#include #include #include @@ -26,6 +24,8 @@ namespace QuickMedia { class FileManager; class MangaImagesPage; class ImageBoardThreadPage; + class RoomData; + class MatrixChatPage; enum class ImageViewMode { SINGLE, @@ -50,16 +50,19 @@ namespace QuickMedia { bool load_manga_content_storage(const char *service_name, const std::string &manga_title, const std::string &manga_id); void select_file(const std::string &filepath); + + bool is_window_focused(); + RoomData* get_current_chat_room(); private: void base_event_handler(sf::Event &event, PageType previous_page, Body *body, SearchBar *search_bar, bool handle_key_press = true, bool handle_searchbar = true); - void page_loop(std::vector tabs); + void page_loop(std::vector &tabs); void video_content_page(Page *page, std::string video_url, std::string video_title); // Returns -1 to go to previous chapter, 0 to stay on same chapter and 1 to go to next chapter int image_page(MangaImagesPage *images_page, Body *chapters_body); void image_continuous_page(MangaImagesPage *images_page); void image_board_thread_page(ImageBoardThreadPage *thread_page, Body *thread_body); void chat_login_page(); - void chat_page(); + void chat_page(MatrixChatPage *chat_page, RoomData *current_room); enum class LoadImageResult { OK, @@ -110,10 +113,8 @@ namespace QuickMedia { std::future autocomplete_future; std::future image_download_future; std::thread image_upscale_thead; - std::mutex image_upscale_mutex; - std::deque images_to_upscale; + MessageQueue images_to_upscale_queue; std::vector image_upscale_status; - std::condition_variable image_upscale_cv; std::string downloading_chapter_url; bool image_download_cancel = false; int exit_code = 0; @@ -127,5 +128,6 @@ namespace QuickMedia { ImageViewMode image_view_mode = ImageViewMode::SINGLE; std::vector selected_files; bool fit_image_to_window = false; + RoomData *current_chat_room = nullptr; }; } \ No newline at end of file -- cgit v1.2.3