From ab36fbffef977b99cc03d0b77ac37bdc1b5705dc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 14 Apr 2021 19:52:21 +0200 Subject: Rework manga plugins downloading.. preparing for parallel downloads --- include/AsyncTask.hpp | 22 +++++++--------------- include/ImageViewer.hpp | 4 +--- include/QuickMedia.hpp | 4 +++- 3 files changed, 11 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/AsyncTask.hpp b/include/AsyncTask.hpp index abdc0f8..6148923 100644 --- a/include/AsyncTask.hpp +++ b/include/AsyncTask.hpp @@ -5,25 +5,17 @@ #include namespace QuickMedia { - template + template class AsyncTask { public: - using CallbackFunc = std::function; + using CallbackFunc = std::function; AsyncTask() = default; - AsyncTask(CallbackFunc callback_func) { + AsyncTask(CallbackFunc callback_func, Args&&... args) { std::promise promise; future = promise.get_future(); - thread = std::thread(&AsyncTask::thread_handler, this, std::move(promise), std::move(callback_func)); - } - - AsyncTask& operator=(CallbackFunc callback_func) { - cancel(); - std::promise promise; - future = promise.get_future(); - thread = std::thread(&AsyncTask::thread_handler, this, std::move(promise), std::move(callback_func)); - return *this; + thread = std::thread(&AsyncTask::thread_handler, this, std::move(promise), std::move(callback_func), std::forward(args)...); } AsyncTask(AsyncTask &&other) { @@ -63,12 +55,12 @@ namespace QuickMedia { } } private: - void thread_handler(std::promise &&promise, CallbackFunc callback_func) { + void thread_handler(std::promise &&promise, CallbackFunc callback_func, Args&&... args) { if constexpr(std::is_same::value) { - callback_func(); + callback_func(std::forward(args)...); promise.set_value(); } else { - promise.set_value(callback_func()); + promise.set_value(callback_func(std::forward(args)...)); } } private: diff --git a/include/ImageViewer.hpp b/include/ImageViewer.hpp index cd1bc8f..c29ea13 100644 --- a/include/ImageViewer.hpp +++ b/include/ImageViewer.hpp @@ -15,8 +15,6 @@ namespace sf { } namespace QuickMedia { - class MangaImagesPage; - enum class ImageStatus { WAITING, LOADING, @@ -46,7 +44,7 @@ namespace QuickMedia { class ImageViewer { public: - ImageViewer(sf::RenderWindow *window, MangaImagesPage *manga_images_page, const std::string &content_title, const std::string &chapter_title, int current_page, const Path &chapter_cache_dir); + ImageViewer(sf::RenderWindow *window, int num_pages, const std::string &content_title, const std::string &chapter_title, int current_page, const Path &chapter_cache_dir); ~ImageViewer(); ImageViewerAction draw(); // Returns page as 1 indexed diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index 2877e0c..b387968 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -160,12 +160,14 @@ namespace QuickMedia { std::unordered_set watched_videos; AsyncTask search_suggestion_future; AsyncTask autocomplete_future; - AsyncTask image_download_future; + AsyncTask> image_download_future; std::thread image_upscale_thead; MessageQueue images_to_upscale_queue; std::vector image_upscale_status; std::string downloading_chapter_url; bool image_download_cancel = false; + std::future num_manga_pages_future; + int num_manga_pages = 0; int exit_code = 0; std::string resources_root; sf::Shader circle_mask_shader; -- cgit v1.2.3-70-g09d2