aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/AsyncTask.hpp22
-rw-r--r--include/ImageViewer.hpp4
-rw-r--r--include/QuickMedia.hpp4
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;