aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/AsyncImageLoader.hpp10
-rw-r--r--include/Body.hpp4
-rw-r--r--include/Entry.hpp2
-rw-r--r--include/MessageQueue.hpp50
-rw-r--r--include/Path.hpp2
-rw-r--r--include/QuickMedia.hpp18
6 files changed, 66 insertions, 20 deletions
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 <SFML/System/Vector2.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/System/Clock.hpp>
#include <string>
-#include <vector>
#include <memory>
#include <thread>
-#include <mutex>
-#include <condition_variable>
-#include <deque>
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<ThumbnailLoadData> images_to_load;
- bool running = true;
+ MessageQueue<ThumbnailLoadData> 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<bool(const std::string& text)>;
+ using OnEntrySubmit = std::function<bool(std::string text)>;
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 <deque>
+#include <mutex>
+#include <condition_variable>
+#include <optional>
+
+namespace QuickMedia {
+ template <typename T>
+ class MessageQueue {
+ public:
+ MessageQueue() : running(true) {
+
+ }
+
+ void push(T data) {
+ std::unique_lock<std::mutex> lock(mutex);
+ data_queue.push_back(std::move(data));
+ cv.notify_one();
+ }
+
+ std::optional<T> pop_wait() {
+ if(!running)
+ return std::nullopt;
+ std::unique_lock<std::mutex> 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<std::mutex> lock(mutex);
+ running = false;
+ cv.notify_one();
+ }
+
+ void clear() {
+ std::unique_lock<std::mutex> lock(mutex);
+ data_queue.clear();
+ }
+ private:
+ std::deque<T> 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 <vector>
#include <memory>
#include <SFML/Graphics/Font.hpp>
@@ -14,10 +15,7 @@
#include <unordered_set>
#include <future>
#include <thread>
-#include <mutex>
-#include <condition_variable>
#include <stack>
-#include <deque>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
@@ -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<Tab> tabs);
+ void page_loop(std::vector<Tab> &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<std::string> autocomplete_future;
std::future<void> image_download_future;
std::thread image_upscale_thead;
- std::mutex image_upscale_mutex;
- std::deque<CopyOp> images_to_upscale;
+ MessageQueue<CopyOp> images_to_upscale_queue;
std::vector<char> 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<std::string> selected_files;
bool fit_image_to_window = false;
+ RoomData *current_chat_room = nullptr;
};
} \ No newline at end of file