aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-08-29 09:27:41 +0200
committerdec05eba <dec05eba@protonmail.com>2021-08-29 09:27:41 +0200
commita12c897435e615618b14f5cbdd50c7d01dd291fa (patch)
treedae906a7a4a46f45f77ff2d41c53569b1354d8f6
parentb4f2787ef695f9957fbf6c8674ef1669d8524b0a (diff)
Allow bookmarking manga from chapters page
-rw-r--r--README.md2
-rw-r--r--include/Scale.hpp17
-rw-r--r--plugins/Manga.hpp1
-rw-r--r--plugins/MangaGeneric.hpp1
-rw-r--r--plugins/Mangadex.hpp1
-rw-r--r--plugins/Manganelo.hpp1
-rw-r--r--plugins/Page.hpp2
-rw-r--r--src/QuickMedia.cpp8
-rw-r--r--src/Storage.cpp1
-rw-r--r--src/plugins/Manga.cpp6
10 files changed, 32 insertions, 8 deletions
diff --git a/README.md b/README.md
index 9a46fc1..3a001a5 100644
--- a/README.md
+++ b/README.md
@@ -72,7 +72,7 @@ Type text and then wait and QuickMedia will automatically search.\
`F5`: Reload the video/music.
### Youtube channel controls
`Ctrl+T`: Subscribe/Unsubscribe from the channel.
-### Manga search/history page controls
+### Manga search/history/chapters page controls
`Ctrl+B`: Bookmark the selected manga. If the manga is already bookmarked then its removed from bookmarks.
### Manga page view controls
`Up`/`Ctrl+K`: Go to the next page (or chapter if the current page is the last one).\
diff --git a/include/Scale.hpp b/include/Scale.hpp
index e458894..eb902cd 100644
--- a/include/Scale.hpp
+++ b/include/Scale.hpp
@@ -2,12 +2,15 @@
#include <SFML/System/Vector2.hpp>
-// TODO: Check if size is 0 before dividing to prevent division by 0?
-
namespace QuickMedia {
template<typename T>
static T wrap_to_size_x(const T &size, const T &clamp_size) {
T new_size;
+ if(size.x == 0) {
+ new_size.x = 0;
+ new_size.y = 0;
+ return new_size;
+ }
float size_ratio = (float)size.y / (float)size.x;
new_size.x = clamp_size.x;
new_size.y = new_size.x * size_ratio;
@@ -17,6 +20,11 @@ namespace QuickMedia {
template<typename T>
static T wrap_to_size_y(const T &size, const T &clamp_size) {
T new_size;
+ if(size.y == 0) {
+ new_size.x = 0;
+ new_size.y = 0;
+ return new_size;
+ }
float size_ratio = (float)size.x / (float)size.y;
new_size.y = clamp_size.y;
new_size.x = new_size.y * size_ratio;
@@ -50,6 +58,9 @@ namespace QuickMedia {
template<typename T>
static sf::Vector2f get_ratio(const T &original_size, const T &new_size) {
- return sf::Vector2f((float)new_size.x / (float)original_size.x, (float)new_size.y / (float)original_size.y);
+ if(original_size.x == 0 || original_size.y == 0)
+ return sf::Vector2f(0.0f, 0.0f);
+ else
+ return sf::Vector2f((float)new_size.x / (float)original_size.x, (float)new_size.y / (float)original_size.y);
}
} \ No newline at end of file
diff --git a/plugins/Manga.hpp b/plugins/Manga.hpp
index ee7638b..020099e 100644
--- a/plugins/Manga.hpp
+++ b/plugins/Manga.hpp
@@ -54,6 +54,7 @@ namespace QuickMedia {
TrackResult track(const std::string &str) override;
void on_navigate_to_page(Body *body) override;
bool is_trackable() const override { return true; }
+ std::shared_ptr<BodyItem> get_bookmark_body_item() override;
protected:
virtual bool extract_id_from_url(const std::string &url, std::string &manga_id) const = 0;
virtual const char* get_service_name() const = 0;
diff --git a/plugins/MangaGeneric.hpp b/plugins/MangaGeneric.hpp
index 4b4f55c..183fbb4 100644
--- a/plugins/MangaGeneric.hpp
+++ b/plugins/MangaGeneric.hpp
@@ -158,6 +158,7 @@ namespace QuickMedia {
MangaGenericChaptersPage(Program *program, std::string manga_name, std::string manga_url, const MangaIdExtractor &manga_id_extractor, const char *service_name, const std::string &website_url, const ListPageQuery *list_page_query, bool fail_on_http_error) :
MangaChaptersPage(program, std::move(manga_name), std::move(manga_url)), manga_id_extractor(manga_id_extractor), service_name(service_name), website_url(website_url), list_page_query(list_page_query), fail_on_http_error(fail_on_http_error) {}
PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ const char* get_bookmark_name() const override { return service_name; }
protected:
bool extract_id_from_url(const std::string &url, std::string &manga_id) const override;
const char* get_service_name() const override { return service_name; }
diff --git a/plugins/Mangadex.hpp b/plugins/Mangadex.hpp
index cb412da..beceddb 100644
--- a/plugins/Mangadex.hpp
+++ b/plugins/Mangadex.hpp
@@ -32,6 +32,7 @@ namespace QuickMedia {
MangadexChaptersPage(Program *program, MangadexSearchPage *search_page, std::string manga_name, std::string manga_url) : MangaChaptersPage(program, std::move(manga_name), std::move(manga_url)), search_page(search_page) {}
PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
PluginResult get_page(const std::string &str, int page, BodyItems &result_items) override;
+ const char* get_bookmark_name() const override { return "mangadex"; }
protected:
bool extract_id_from_url(const std::string &url, std::string &manga_id) const override;
const char* get_service_name() const override { return "mangadex"; }
diff --git a/plugins/Manganelo.hpp b/plugins/Manganelo.hpp
index 70526ff..5012fa3 100644
--- a/plugins/Manganelo.hpp
+++ b/plugins/Manganelo.hpp
@@ -17,6 +17,7 @@ namespace QuickMedia {
public:
ManganeloChaptersPage(Program *program, std::string manga_name, std::string manga_url) : MangaChaptersPage(program, std::move(manga_name), std::move(manga_url)) {}
PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override;
+ const char* get_bookmark_name() const override { return "manganelo"; }
protected:
bool extract_id_from_url(const std::string &url, std::string &manga_id) const override;
const char* get_service_name() const override { return "manganelo"; }
diff --git a/plugins/Page.hpp b/plugins/Page.hpp
index 39d76d6..3ecb016 100644
--- a/plugins/Page.hpp
+++ b/plugins/Page.hpp
@@ -61,6 +61,8 @@ namespace QuickMedia {
virtual bool is_trackable() const { return false; }
// Return nullptr if bookmark is not supported by this page
virtual const char* get_bookmark_name() const { return nullptr; }
+ // If this returns nullptr then the currently selected body item is used instead
+ virtual std::shared_ptr<BodyItem> get_bookmark_body_item() { return nullptr; }
virtual bool is_bookmark_page() const { return false; }
virtual bool is_lazy_fetch_page() const { return false; }
// Note: If submit is done without any selection, then the search term is sent as the |title| and |url|. Submit will only be sent if the input text is not empty or if an item is selected
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 9dd8c25..174d779 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -2179,11 +2179,13 @@ namespace QuickMedia {
});
}
} else if(event.key.code == sf::Keyboard::B && event.key.control) {
- BodyItem *selected_item = tabs[selected_tab].body->get_selected();
- if(selected_item) {
+ auto bookmark_item = tabs[selected_tab].page->get_bookmark_body_item();
+ if(!bookmark_item)
+ bookmark_item = tabs[selected_tab].body->get_selected_shared();
+ if(bookmark_item) {
const char *bookmark_name = tabs[selected_tab].page->get_bookmark_name();
if(bookmark_name) {
- if(toggle_bookmark(selected_item, bookmark_name)) {
+ if(toggle_bookmark(bookmark_item.get(), bookmark_name)) {
for(Tab &tab : tabs) {
if(tab.page && tab.page->is_bookmark_page())
tab.page->needs_refresh = true;
diff --git a/src/Storage.cpp b/src/Storage.cpp
index 1b5435f..35cf5f8 100644
--- a/src/Storage.cpp
+++ b/src/Storage.cpp
@@ -331,7 +331,6 @@ namespace QuickMedia {
}
bool is_program_executable_by_name(const char *name) {
- // TODO: Implement for Windows. Windows also uses semicolon instead of colon as a separator
char *env = getenv("PATH");
if(!env)
return false;
diff --git a/src/plugins/Manga.cpp b/src/plugins/Manga.cpp
index 2c7bae0..3fa5d47 100644
--- a/src/plugins/Manga.cpp
+++ b/src/plugins/Manga.cpp
@@ -20,4 +20,10 @@ namespace QuickMedia {
if(extract_id_from_url(content_url, manga_id))
load_manga_content_storage(get_service_name(), content_title, manga_id);
}
+
+ std::shared_ptr<BodyItem> MangaChaptersPage::get_bookmark_body_item() {
+ auto body_item = std::make_shared<BodyItem>(content_title);
+ body_item->url = content_url;
+ return body_item;
+ }
} \ No newline at end of file