diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-04-14 19:52:21 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-04-14 23:45:11 +0200 |
commit | ab36fbffef977b99cc03d0b77ac37bdc1b5705dc (patch) | |
tree | 17207a364eecee330a26ac117a1384ad0b4a1e97 /include | |
parent | 4db0876f45533d3b55ee79df2d2bc78b789b5a28 (diff) |
Rework manga plugins downloading.. preparing for parallel downloads
Diffstat (limited to 'include')
-rw-r--r-- | include/AsyncTask.hpp | 22 | ||||
-rw-r--r-- | include/ImageViewer.hpp | 4 | ||||
-rw-r--r-- | include/QuickMedia.hpp | 4 |
3 files changed, 11 insertions, 19 deletions
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 <future> namespace QuickMedia { - template <typename T> + template <class T, class... Args> class AsyncTask { public: - using CallbackFunc = std::function<T()>; + using CallbackFunc = std::function<T(Args&&... args)>; AsyncTask() = default; - AsyncTask(CallbackFunc callback_func) { + AsyncTask(CallbackFunc callback_func, Args&&... args) { std::promise<T> 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<T> 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>(args)...); } AsyncTask(AsyncTask &&other) { @@ -63,12 +55,12 @@ namespace QuickMedia { } } private: - void thread_handler(std::promise<T> &&promise, CallbackFunc callback_func) { + void thread_handler(std::promise<T> &&promise, CallbackFunc callback_func, Args&&... args) { if constexpr(std::is_same<T, void>::value) { - callback_func(); + callback_func(std::forward<Args>(args)...); promise.set_value(); } else { - promise.set_value(callback_func()); + promise.set_value(callback_func(std::forward<Args>(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<std::string> watched_videos; AsyncTask<BodyItems> search_suggestion_future; AsyncTask<std::string> autocomplete_future; - AsyncTask<void> image_download_future; + AsyncTask<void, std::promise<int>> image_download_future; std::thread image_upscale_thead; MessageQueue<CopyOp> images_to_upscale_queue; std::vector<char> image_upscale_status; std::string downloading_chapter_url; bool image_download_cancel = false; + std::future<int> num_manga_pages_future; + int num_manga_pages = 0; int exit_code = 0; std::string resources_root; sf::Shader circle_mask_shader; |