aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Page.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-08-26 01:10:40 +0200
committerdec05eba <dec05eba@protonmail.com>2021-08-26 01:10:40 +0200
commite62b707603ec00fc5192bf702b4bca0ed77501e6 (patch)
tree49e71f28a0ef42ab10872561f72b0e51d86cced6 /src/plugins/Page.cpp
parent0a26a319b241978ee317bbe768eb61c4eb7a39d9 (diff)
Add ctrl+b to bookmark manga
Diffstat (limited to 'src/plugins/Page.cpp')
-rw-r--r--src/plugins/Page.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/plugins/Page.cpp b/src/plugins/Page.cpp
index 8605d82..5c64183 100644
--- a/src/plugins/Page.cpp
+++ b/src/plugins/Page.cpp
@@ -1,4 +1,6 @@
#include "../../plugins/Page.hpp"
+#include "../../include/StringUtils.hpp"
+#include "../../include/Theme.hpp"
#include "../../include/QuickMedia.hpp"
#include <json/reader.h>
@@ -40,4 +42,44 @@ namespace QuickMedia {
bool Page::load_manga_content_storage(const char *service_name, const std::string &manga_title, const std::string &manga_id) {
return program->load_manga_content_storage(service_name, manga_title, manga_id);
}
+
+ PluginResult BookmarksPage::submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) {
+ return redirect_page->submit(title, url, result_tabs);
+ }
+
+ PluginResult BookmarksPage::lazy_fetch(BodyItems &result_items) {
+ const char *bookmark_name = redirect_page->get_bookmark_name();
+ if(!bookmark_name)
+ return PluginResult::ERR;
+
+ Path bookmark_path = get_storage_dir().join("bookmarks").join(bookmark_name);
+ Json::Value json_root;
+ if(!read_file_as_json(bookmark_path, json_root) || !json_root.isArray())
+ return PluginResult::OK;
+
+ const time_t time_now = time(nullptr);
+ for(const Json::Value &item_json : json_root) {
+ if(!item_json.isObject())
+ continue;
+
+ const Json::Value &title_json = item_json["title"];
+ const Json::Value &author_json = item_json["author"];
+ const Json::Value &url_json = item_json["url"];
+ const Json::Value &timestamp_json = item_json["timestamp"];
+
+ auto body_item = BodyItem::create(title_json.isString() ? title_json.asString() : "");
+ if(author_json.isString())
+ body_item->set_author(author_json.asString());
+ if(url_json.isString())
+ body_item->url = url_json.asString();
+ if(timestamp_json.isInt64()) {
+ body_item->set_description("Bookmarked " + seconds_to_relative_time_str(time_now - timestamp_json.asInt64()));
+ body_item->set_description_color(get_current_theme().faded_text_color);
+ }
+ result_items.push_back(std::move(body_item));
+ }
+
+ std::reverse(result_items.begin(), result_items.end());
+ return PluginResult::OK;
+ }
} \ No newline at end of file