aboutsummaryrefslogtreecommitdiff
path: root/src/QuickMedia.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r--src/QuickMedia.cpp140
1 files changed, 76 insertions, 64 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 842ecbe..4b645d4 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -246,62 +246,16 @@ static sf::Color interpolate_colors(sf::Color source, sf::Color target, double p
}
namespace QuickMedia {
- enum class HistoryType {
- YOUTUBE,
- MANGA
- };
-
- class HistoryPage : public Page {
- public:
- HistoryPage(Program *program, Page *search_page, SearchBar *search_bar, HistoryType history_type) :
- Page(program), search_page(search_page), search_bar(search_bar), history_type(history_type) {}
- const char* get_title() const override { return "History"; }
- PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override {
- return search_page->submit(title, url, result_tabs);
+ // Returns index to item or -1 if not found
+ static int get_body_item_by_url(Body *body, const std::string &url) {
+ if(url.empty()) return -1;
+ for(size_t i = 0; i < body->items.size(); ++i) {
+ auto &body_item = body->items[i];
+ if(body_item->url == url)
+ return i;
}
- void on_navigate_to_page(Body *body) override {
- std::string selected_item_url = body->get_selected() ? body->get_selected()->url : "";
- body->clear_items();
- switch(history_type) {
- case HistoryType::YOUTUBE:
- program->youtube_get_watch_history(body->items);
- break;
- case HistoryType::MANGA:
- program->manga_get_watch_history(program->get_plugin_name(), body->items);
- break;
- }
- body->filter_search_fuzzy(search_bar->get_text());
- int item_to_revert_selection_to = get_body_item_by_url(body, selected_item_url);
- if(item_to_revert_selection_to != -1)
- body->set_selected_item(item_to_revert_selection_to, false);
- }
-
- // Returns index to item or -1 if not found
- int get_body_item_by_url(Body *body, const std::string &url) {
- if(url.empty()) return -1;
- for(size_t i = 0; i < body->items.size(); ++i) {
- auto &body_item = body->items[i];
- if(body_item->url == url)
- return i;
- }
- return -1;
- }
- private:
- Page *search_page;
- SearchBar *search_bar;
- HistoryType history_type;
- };
-
- class RecommendedPage : public Page {
- public:
- RecommendedPage(Program *program, Page *search_page) : Page(program), search_page(search_page) {}
- const char* get_title() const override { return "Recommended"; }
- PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override {
- return search_page->submit(title, url, result_tabs);
- }
- private:
- Page *search_page;
- };
+ return -1;
+ }
static Path get_recommended_filepath(const char *plugin_name) {
Path video_history_dir = get_storage_dir().join("recommended");
@@ -411,6 +365,63 @@ namespace QuickMedia {
std::random_shuffle(body_items.begin(), body_items.end());
}
+ enum class HistoryType {
+ YOUTUBE,
+ MANGA
+ };
+
+ class HistoryPage : public Page {
+ public:
+ HistoryPage(Program *program, Page *search_page, SearchBar *search_bar, HistoryType history_type) :
+ Page(program), search_page(search_page), search_bar(search_bar), history_type(history_type) {}
+ const char* get_title() const override { return "History"; }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override {
+ return search_page->submit(title, url, result_tabs);
+ }
+ void on_navigate_to_page(Body *body) override {
+ std::string selected_item_url = body->get_selected() ? body->get_selected()->url : "";
+ body->clear_items();
+ switch(history_type) {
+ case HistoryType::YOUTUBE:
+ program->youtube_get_watch_history(body->items);
+ break;
+ case HistoryType::MANGA:
+ program->manga_get_watch_history(program->get_plugin_name(), body->items);
+ break;
+ }
+ body->filter_search_fuzzy(search_bar->get_text());
+ int item_to_revert_selection_to = get_body_item_by_url(body, selected_item_url);
+ if(item_to_revert_selection_to != -1)
+ body->set_selected_item(item_to_revert_selection_to, false);
+ }
+ private:
+ Page *search_page;
+ SearchBar *search_bar;
+ HistoryType history_type;
+ };
+
+ class RecommendedPage : public Page {
+ public:
+ RecommendedPage(Program *program, Page *search_page, SearchBar *search_bar, const char *plugin_name) : Page(program), search_page(search_page), search_bar(search_bar), plugin_name(plugin_name) {}
+ const char* get_title() const override { return "Recommended"; }
+ PluginResult submit(const std::string &title, const std::string &url, std::vector<Tab> &result_tabs) override {
+ return search_page->submit(title, url, result_tabs);
+ }
+ void on_navigate_to_page(Body *body) override {
+ std::string selected_item_url = body->get_selected() ? body->get_selected()->url : "";
+ body->clear_items();
+ fill_recommended_items_from_json(plugin_name, program->load_recommended_json(), body->items);
+ body->filter_search_fuzzy(search_bar->get_text());
+ int item_to_revert_selection_to = get_body_item_by_url(body, selected_item_url);
+ if(item_to_revert_selection_to != -1)
+ body->set_selected_item(item_to_revert_selection_to, false);
+ }
+ private:
+ Page *search_page;
+ SearchBar *search_bar;
+ const char *plugin_name;
+ };
+
Program::Program() :
disp(nullptr),
window_size(1280, 720),
@@ -911,14 +922,13 @@ namespace QuickMedia {
tabs.push_back(Tab{std::move(search_body), std::make_unique<YoutubeSearchPage>(this), create_search_bar("Search...", 350)});
auto history_body = create_body();
- auto search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER);
- auto history_page = std::make_unique<HistoryPage>(this, tabs.front().page.get(), search_bar.get(), HistoryType::YOUTUBE);
- tabs.push_back(Tab{std::move(history_body), std::move(history_page), std::move(search_bar)});
-
- auto recommended_body = create_body();
- fill_recommended_items_from_json(plugin_name, load_recommended_json(), recommended_body->items);
- tabs.push_back(Tab{std::move(recommended_body), std::make_unique<RecommendedPage>(this, tabs.front().page.get()), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
+ auto history_search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER);
+ auto history_page = std::make_unique<HistoryPage>(this, tabs.front().page.get(), history_search_bar.get(), HistoryType::YOUTUBE);
+ tabs.push_back(Tab{std::move(history_body), std::move(history_page), std::move(history_search_bar)});
+ auto recommended_search_bar = create_search_bar("Search...", SEARCH_DELAY_FILTER);
+ auto recommended_page = std::make_unique<RecommendedPage>(this, tabs.front().page.get(), recommended_search_bar.get(), plugin_name);
+ tabs.push_back(Tab{create_body(), std::move(recommended_page), std::move(recommended_search_bar)});
tabs.push_back(Tab{create_body(), std::make_unique<YoutubeSubscriptionsPage>(this), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
} else if(strcmp(plugin_name, "pornhub") == 0) {
auto search_body = create_body();
@@ -3917,8 +3927,10 @@ namespace QuickMedia {
process_pinned_events(std::move(pinned_events));
tabs[PINNED_TAB_INDEX].body->select_last_item();
- room_name_text.setString(current_room->get_name());
- room_topic_text.setString(current_room->get_topic());
+ std::string room_name = current_room->get_name();
+ std::string room_topic = current_room->get_topic();
+ room_name_text.setString(sf::String::fromUtf8(room_name.begin(), room_name.end()));
+ room_topic_text.setString(sf::String::fromUtf8(room_topic.begin(), room_topic.end()));
room_avatar_thumbnail_data = std::make_shared<ThumbnailData>();
read_marker_timeout_ms = 0;