diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/Page.cpp | 42 | ||||
-rw-r--r-- | src/plugins/Youtube.cpp | 24 |
2 files changed, 42 insertions, 24 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 ×tamp_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 diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index b490e97..6c080c5 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -1660,30 +1660,6 @@ namespace QuickMedia { return self->size == sub_len && memcmp(self->data, sub, sub_len) == 0; } - // Returns relative time as a string (approximation) - static std::string seconds_to_relative_time_str(time_t seconds) { - seconds = std::max(0L, seconds); - - time_t minutes = seconds / 60; - time_t hours = minutes / 60; - time_t days = hours / 24; - time_t months = days / 30; - time_t years = days / 365; - - if(years >= 1) - return std::to_string(years) + " year" + (years == 1 ? "" : "s") + " ago"; - else if(months >= 1) - return std::to_string(months) + " month" + (months == 1 ? "" : "s") + " ago"; - else if(days >= 1) - return std::to_string(days) + " day" + (days == 1 ? "" : "s") + " ago"; - else if(hours >= 1) - return std::to_string(hours) + " hour" + (hours == 1 ? "" : "s") + " ago"; - else if(minutes >= 1) - return std::to_string(minutes) + " minute" + (minutes == 1 ? "" : "s") + " ago"; - else - return std::to_string(seconds) + " second" + (seconds == 1 ? "" : "s") + " ago"; - } - PluginResult YoutubeSubscriptionsPage::lazy_fetch(BodyItems &result_items) { Path subscriptions_path = get_storage_dir().join("subscriptions").join("youtube.txt"); std::string subscriptions_str; |