aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp68
1 files changed, 67 insertions, 1 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 881f2d6..9b57b0b 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -12,6 +12,7 @@
#include "../include/StringUtils.hpp"
#include "../include/GoogleCaptcha.hpp"
#include "../include/Notification.hpp"
+#include "../include/ImageViewer.hpp"
#include <cppcodec/base64_rfc4648.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
@@ -234,6 +235,11 @@ namespace QuickMedia {
window.setKeyRepeatEnabled(true);
break;
}
+ case Page::IMAGES_CONTINUOUS: {
+ body->draw_thumbnails = false;
+ image_continuous_page();
+ break;
+ }
case Page::CONTENT_LIST: {
body->draw_thumbnails = true;
content_list_page();
@@ -796,7 +802,7 @@ namespace QuickMedia {
images_url = item->url;
chapter_title = item->title;
image_index = 0;
- current_page = Page::IMAGES;
+ current_page = Page::IMAGES_CONTINUOUS;
if(start_from_beginning)
return;
@@ -1181,6 +1187,66 @@ namespace QuickMedia {
}
}
+ void Program::image_continuous_page() {
+ search_bar->onTextUpdateCallback = nullptr;
+ search_bar->onTextSubmitCallback = nullptr;
+
+ assert(current_plugin->is_manga());
+ Manga *image_plugin = static_cast<Manga*>(current_plugin);
+
+ content_cache_dir = get_cache_dir().join(image_plugin->name).join(manga_id_base64).join(base64_encode(chapter_title));
+ if(create_directory_recursive(content_cache_dir) != 0) {
+ show_notification("Storage", "Failed to create directory: " + content_cache_dir.data, Urgency::CRITICAL);
+ current_page = Page::EPISODE_LIST;
+ return;
+ }
+ download_chapter_images_if_needed(image_plugin);
+
+ Json::Value &json_chapters = content_storage_json["chapters"];
+ Json::Value json_chapter;
+ int latest_read = 1 + image_index;
+ if(json_chapters.isObject()) {
+ json_chapter = json_chapters[chapter_title];
+ if(json_chapter.isObject()) {
+ const Json::Value &current = json_chapter["current"];
+ if(current.isNumeric())
+ latest_read = std::max(latest_read, current.asInt());
+ } else {
+ json_chapter = Json::Value(Json::objectValue);
+ }
+ } else {
+ json_chapters = Json::Value(Json::objectValue);
+ json_chapter = Json::Value(Json::objectValue);
+ }
+
+ ImageViewer image_viewer(image_plugin, images_url, chapter_title, image_index, content_cache_dir, &font);
+
+ json_chapter["current"] = std::min(latest_read, image_viewer.get_num_pages());
+ json_chapter["total"] = image_viewer.get_num_pages();
+ json_chapters[chapter_title] = json_chapter;
+ if(!save_manga_progress_json(content_storage_file, content_storage_json)) {
+ show_notification("Manga progress", "Failed to save manga progress", Urgency::CRITICAL);
+ }
+
+ while(current_page == Page::IMAGES_CONTINUOUS) {
+ window.clear(back_color);
+ if(!image_viewer.draw(window))
+ current_page = Page::EPISODE_LIST;
+ window.display();
+
+ int focused_page = image_viewer.get_focused_page();
+ if(focused_page > latest_read) {
+ latest_read = focused_page;
+ image_index = latest_read - 1;
+ json_chapter["current"] = latest_read;
+ json_chapters[chapter_title] = json_chapter;
+ if(!save_manga_progress_json(content_storage_file, content_storage_json)) {
+ show_notification("Manga progress", "Failed to save manga progress", Urgency::CRITICAL);
+ }
+ }
+ }
+ }
+
void Program::content_list_page() {
if(current_plugin->get_content_list(content_list_url, body->items) != PluginResult::OK) {
show_notification("Content list", "Failed to get content list for url: " + content_list_url, Urgency::CRITICAL);