From 77ed51898157d99112be7550471ec06e32344c9e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 11 Oct 2020 21:35:37 +0200 Subject: Refactor plugin into seperate pages TODO: Readd 4chan login page, manganelo creators page, autocomplete --- include/Body.hpp | 4 +-- include/ImageViewer.hpp | 4 +-- include/Page.hpp | 7 +---- include/QuickMedia.hpp | 69 +++++++++++++++++++++---------------------------- include/SearchBar.hpp | 4 +-- include/Storage.hpp | 2 ++ include/Tab.hpp | 15 +++++++++++ 7 files changed, 54 insertions(+), 51 deletions(-) create mode 100644 include/Tab.hpp (limited to 'include') diff --git a/include/Body.hpp b/include/Body.hpp index 3d5c870..875ad61 100644 --- a/include/Body.hpp +++ b/include/Body.hpp @@ -101,7 +101,6 @@ namespace QuickMedia { class Body { public: Body(Program *program, sf::Font *font, sf::Font *bold_font, sf::Font *cjk_font); - ~Body(); // Select previous page, ignoring invisible items. Returns true if the item was changed. This can be used to check if the top was hit when wrap_around is set to false bool select_previous_page(); @@ -126,6 +125,8 @@ namespace QuickMedia { void append_items(BodyItems new_items); void insert_item_by_timestamp(std::shared_ptr body_item); void insert_items_by_timestamps(BodyItems new_items); + void clear_cache(); + void clear_text_cache(); void clear_thumbnails(); BodyItem* get_selected() const; @@ -188,7 +189,6 @@ namespace QuickMedia { sf::RectangleShape item_background_shadow; sf::RoundedRectangleShape item_background; sf::Sprite image; - std::future load_thumbnail_future; int num_visible_items; bool last_item_fully_visible; int last_fully_visible_item; diff --git a/include/ImageViewer.hpp b/include/ImageViewer.hpp index b8063ee..2cf3ac2 100644 --- a/include/ImageViewer.hpp +++ b/include/ImageViewer.hpp @@ -15,7 +15,7 @@ namespace sf { } namespace QuickMedia { - class Manga; + class MangaImagesPage; enum class ImageStatus { WAITING, @@ -46,7 +46,7 @@ namespace QuickMedia { class ImageViewer { public: - ImageViewer(Manga *manga, const std::string &images_url, const std::string &content_title, const std::string &chapter_title, int current_page, const Path &chapter_cache_dir, sf::Font *font); + ImageViewer(MangaImagesPage *manga_images_page, const std::string &content_title, const std::string &chapter_title, int current_page, const Path &chapter_cache_dir, sf::Font *font); ImageViewerAction draw(sf::RenderWindow &window); // Returns page as 1 indexed int get_focused_page() const; diff --git a/include/Page.hpp b/include/Page.hpp index f8af3c0..d0e40b3 100644 --- a/include/Page.hpp +++ b/include/Page.hpp @@ -1,16 +1,11 @@ #pragma once namespace QuickMedia { - enum class Page { + enum class PageType { EXIT, - SEARCH_SUGGESTION, VIDEO_CONTENT, - EPISODE_LIST, IMAGES, IMAGES_CONTINUOUS, - CONTENT_LIST, - CONTENT_DETAILS, - IMAGE_BOARD_THREAD_LIST, IMAGE_BOARD_THREAD, CHAT_LOGIN, CHAT, diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index 016202c..0a0b509 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -4,6 +4,7 @@ #include "SearchBar.hpp" #include "Page.hpp" #include "Storage.hpp" +#include "Tab.hpp" #include #include #include @@ -20,9 +21,10 @@ #include namespace QuickMedia { - class Plugin; + class Matrix; class FileManager; - class Manga; + class MangaImagesPage; + class ImageBoardThreadPage; enum class ImageViewMode { SINGLE, @@ -40,24 +42,23 @@ namespace QuickMedia { ~Program(); int run(int argc, char **argv); - Plugin* get_current_plugin() { return current_plugin; } + bool is_tor_enabled(); + std::unique_ptr create_body(); + std::unique_ptr create_search_bar(const std::string &placeholder, int search_delay); + + 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); private: - void base_event_handler(sf::Event &event, Page previous_page, bool handle_key_press = true, bool clear_on_escape = true, bool handle_searchbar = true); - void search_suggestion_page(); - void search_result_page(); - void video_content_page(); - void episode_list_page(); - void image_page(); - void image_continuous_page(); - void content_list_page(); - void content_details_page(); - void image_board_thread_list_page(); - void image_board_thread_page(); + 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 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 file_manager_page(); - - bool on_search_suggestion_submit_text(Body *input_body, Body *output_body); enum class LoadImageResult { OK, @@ -66,17 +67,18 @@ namespace QuickMedia { }; LoadImageResult load_image_by_index(int image_index, sf::Texture &image_texture, sf::String &error_message); - void download_chapter_images_if_needed(Manga *image_plugin); + void download_chapter_images_if_needed(MangaImagesPage *images_page); void select_episode(BodyItem *item, bool start_from_beginning); - // Returns Page::EXIT if empty - Page pop_page_stack(); + // Returns PageType::EXIT if empty + PageType pop_page_stack(); - void plugin_get_watch_history(Plugin *plugin, BodyItems &history_items); - Json::Value load_video_history_json(Plugin *plugin); - Json::Value load_recommended_json(Plugin *plugin); + void manga_get_watch_history(const char *plugin_name, BodyItems &history_items); + void youtube_get_watch_history(BodyItems &history_items); + Json::Value load_video_history_json(); + Json::Value load_recommended_json(); - void save_recommendations_from_related_videos(); + void save_recommendations_from_related_videos(const std::string &video_url, const std::string &video_title, const Body *related_media_body); private: enum class UpscaleImageAction { NO, @@ -86,25 +88,16 @@ namespace QuickMedia { Display *disp; sf::RenderWindow window; + Matrix *matrix = nullptr; int monitor_hz; sf::Vector2f window_size; std::unique_ptr font; std::unique_ptr bold_font; std::unique_ptr cjk_font; - Body *body; - Plugin *current_plugin; + const char *plugin_name = nullptr; sf::Texture plugin_logo; - std::unique_ptr search_bar; - Page current_page; - std::stack page_stack; - // TODO: Combine these - std::string images_url; - std::string content_title; - std::string content_episode; - std::string content_url; - std::string content_list_url; - std::string image_board_thread_list_url; - std::string chapter_title; + PageType current_page; + std::stack page_stack; int image_index; Path content_storage_file; Path content_cache_dir; @@ -130,9 +123,7 @@ namespace QuickMedia { bool running = false; // TODO: Save this to config file when switching modes ImageViewMode image_view_mode = ImageViewMode::SINGLE; - Body *related_media_body; std::vector selected_files; - FileManager *file_manager = nullptr; bool fit_image_to_window = false; }; } \ No newline at end of file diff --git a/include/SearchBar.hpp b/include/SearchBar.hpp index e5245be..6b7ca6d 100644 --- a/include/SearchBar.hpp +++ b/include/SearchBar.hpp @@ -15,8 +15,7 @@ namespace sf { namespace QuickMedia { using TextUpdateCallback = std::function; - // Return true to consume the search (clear the search field) - using TextSubmitCallback = std::function; + using TextSubmitCallback = std::function; using TextBeginTypingCallback = std::function; using AutocompleteRequestCallback = std::function; @@ -69,6 +68,7 @@ namespace QuickMedia { bool draw_logo; bool needs_update; bool input_masked; + bool typing; float vertical_pos; sf::Clock time_since_search_update; }; diff --git a/include/Storage.hpp b/include/Storage.hpp index 38c083e..8a1bbfa 100644 --- a/include/Storage.hpp +++ b/include/Storage.hpp @@ -29,4 +29,6 @@ namespace QuickMedia { bool read_file_as_json(const Path &filepath, Json::Value &result); bool save_json_to_file_atomic(const Path &path, const Json::Value &json); + + bool is_program_executable_by_name(const char *name); } \ No newline at end of file diff --git a/include/Tab.hpp b/include/Tab.hpp new file mode 100644 index 0000000..ccb8c85 --- /dev/null +++ b/include/Tab.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace QuickMedia { + class Body; + class Page; + class SearchBar; + + struct Tab { + std::unique_ptr body; + std::unique_ptr page; // Only null when current page has |is_single_page()| set to true + std::unique_ptr search_bar; // Nullable + }; +} \ No newline at end of file -- cgit v1.2.3