aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-11-12 22:37:23 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-12 22:37:23 +0100
commit5c27b5fbaa0f1693bf4605a3e6fc57d0f066c0ec (patch)
tree5a9d3e2cccc08d671da99c45fee040f3e24fae3c /src
parent09d8b9895c7001f991d2aab7a75e8b573edb086f (diff)
Allow plugins to add their own tabs in ctrl+r instead of search, comments, related and channel
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp32
-rw-r--r--src/plugins/ImageBoard.cpp4
-rw-r--r--src/plugins/Lbry.cpp12
-rw-r--r--src/plugins/MediaGeneric.cpp14
-rw-r--r--src/plugins/Peertube.cpp12
-rw-r--r--src/plugins/Youtube.cpp27
6 files changed, 21 insertions, 80 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 091ce3b..29976ad 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3082,34 +3082,20 @@ namespace QuickMedia {
window.setMouseCursorVisible(true);
cursor_visible = true;
- Tab search_page_tab;
- const bool search_page_created = video_page->create_search_page(this, search_page_tab);
- auto comments_page = video_page->create_comments_page(this);
- auto related_videos_page = video_page->create_related_videos_page(this);
- auto channels_page = video_page->create_channels_page(this, channel_url);
- if(search_page_created || related_videos_page || channels_page) {
+ std::vector<Tab> related_pages;
+ TaskResult related_pages_result = run_task_with_loading_screen([&video_page, &related_videos, &channel_url, &related_pages]{
+ return video_page->get_related_pages(related_videos, channel_url, related_pages) == PluginResult::OK;
+ });
+
+ if(related_pages_result == TaskResult::FALSE) {
+ show_notification("QuickMedia", "Failed to get related pages", Urgency::CRITICAL);
+ } else if(related_pages_result == TaskResult::TRUE) {
XUnmapWindow(disp, video_player_window);
XSync(disp, False);
- std::vector<Tab> tabs;
- if(search_page_created) {
- tabs.push_back(std::move(search_page_tab));
- }
- if(comments_page) {
- tabs.push_back(Tab{create_body(), std::move(comments_page), nullptr});
- }
- if(related_videos_page) {
- auto related_videos_body = create_body(false, true);
- related_videos_body->set_items(related_videos);
- tabs.push_back(Tab{std::move(related_videos_body), std::move(related_videos_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
- }
- if(channels_page) {
- tabs.push_back(Tab{create_body(false, true), std::move(channels_page), create_search_bar("Search...", 350)});
- }
-
bool page_changed = false;
double resume_start_time = 0.0;
- page_loop(tabs, 1, [this, &page_changed, &resume_start_time, &youtube_video_media_proxy, &youtube_audio_media_proxy, &youtube_downloader_task](const std::vector<Tab> &new_tabs) {
+ page_loop(related_pages, video_page->get_related_pages_first_tab(), [&](const std::vector<Tab> &new_tabs) {
if(!page_changed && new_tabs.size() == 1 && new_tabs[0].page->get_type() == PageTypez::VIDEO) {
video_player->get_time_in_file(&resume_start_time);
video_player.reset();
diff --git a/src/plugins/ImageBoard.cpp b/src/plugins/ImageBoard.cpp
index f813068..b87e4bb 100644
--- a/src/plugins/ImageBoard.cpp
+++ b/src/plugins/ImageBoard.cpp
@@ -6,10 +6,6 @@ namespace QuickMedia {
sf::Clipboard::setString(sf::String::fromUtf8(body_item->get_description().begin(), body_item->get_description().end()));
}
- std::unique_ptr<RelatedVideosPage> ImageBoardThreadPage::create_related_videos_page(Program*) {
- return nullptr;
- }
-
PluginResult ImageBoardThreadPage::login(const std::string &token, const std::string &pin, std::string &response_msg) {
(void)token;
(void)pin;
diff --git a/src/plugins/Lbry.cpp b/src/plugins/Lbry.cpp
index 239a269..50da718 100644
--- a/src/plugins/Lbry.cpp
+++ b/src/plugins/Lbry.cpp
@@ -373,18 +373,6 @@ namespace QuickMedia {
return PluginResult::OK;
}
- std::unique_ptr<Page> LbryVideoPage::create_comments_page(Program*) {
- return nullptr;
- }
-
- std::unique_ptr<RelatedVideosPage> LbryVideoPage::create_related_videos_page(Program*) {
- return nullptr;
- }
-
- std::unique_ptr<Page> LbryVideoPage::create_channels_page(Program*, const std::string&) {
- return nullptr;
- }
-
// TODO: Support |max_height|. This can be done by gettin video source hash and checking for sd_hash and then resolution.
// If max_height is below max resolution height then choose the sd_hash version (replace hash in video stream with sd hash for the lower quality version)
std::string LbryVideoPage::get_download_url(int max_height) {
diff --git a/src/plugins/MediaGeneric.cpp b/src/plugins/MediaGeneric.cpp
index 713c7f7..dd70efc 100644
--- a/src/plugins/MediaGeneric.cpp
+++ b/src/plugins/MediaGeneric.cpp
@@ -193,14 +193,10 @@ namespace QuickMedia {
return result_items;
}
- bool MediaGenericVideoPage::create_search_page(Program*, Tab &tab) {
- tab.body = create_body(false, true);
- tab.page = std::make_unique<MediaGenericSearchPage>(*search_page);
- tab.search_bar = create_search_bar("Search...", 500); // TODO: Make search delay configurable?
- return true;
- }
-
- std::unique_ptr<RelatedVideosPage> MediaGenericVideoPage::create_related_videos_page(Program *program) {
- return std::make_unique<MediaGenericRelatedPage>(program, search_page);
+ PluginResult MediaGenericVideoPage::get_related_pages(const BodyItems &related_videos, const std::string&, std::vector<Tab> &result_tabs) {
+ auto related_page_body = create_body(false, true);
+ related_page_body->set_items(related_videos);
+ result_tabs.push_back(Tab{std::move(related_page_body), std::make_unique<MediaGenericRelatedPage>(program, search_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
+ return PluginResult::OK;
}
} \ No newline at end of file
diff --git a/src/plugins/Peertube.cpp b/src/plugins/Peertube.cpp
index b83daf5..2e7fec4 100644
--- a/src/plugins/Peertube.cpp
+++ b/src/plugins/Peertube.cpp
@@ -298,18 +298,6 @@ namespace QuickMedia {
return get_page("", 0, result_items);
}
- std::unique_ptr<Page> PeertubeVideoPage::create_comments_page(Program*) {
- return nullptr;
- }
-
- std::unique_ptr<RelatedVideosPage> PeertubeVideoPage::create_related_videos_page(Program*) {
- return nullptr;
- }
-
- std::unique_ptr<Page> PeertubeVideoPage::create_channels_page(Program*, const std::string&) {
- return nullptr;
- }
-
static std::string get_ext_from_url(const std::string &url) {
const size_t dot_index = url.rfind('.');
if(dot_index == std::string::npos)
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index 40b6970..c7a9e5c 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -2167,26 +2167,13 @@ namespace QuickMedia {
return result_items;
}
- bool YoutubeVideoPage::create_search_page(Program *program, Tab &tab) {
- std::string video_id;
- youtube_url_extract_id(url, video_id);
-
- tab.body = create_body(false, false);
- tab.page = std::make_unique<YoutubeSearchPage>(program, std::move(video_id));
- tab.search_bar = create_search_bar("Search...", 100);
- return true;
- }
-
- std::unique_ptr<Page> YoutubeVideoPage::create_comments_page(Program *program) {
- return std::make_unique<YoutubeCommentsPage>(program, url, comments_continuation_token);
- }
-
- std::unique_ptr<RelatedVideosPage> YoutubeVideoPage::create_related_videos_page(Program *program) {
- return std::make_unique<YoutubeRelatedVideosPage>(program);
- }
-
- std::unique_ptr<Page> YoutubeVideoPage::create_channels_page(Program *program, const std::string &channel_url) {
- return std::make_unique<YoutubeChannelPage>(program, channel_url, "", "Channel videos");
+ PluginResult YoutubeVideoPage::get_related_pages(const BodyItems &related_videos, const std::string &channel_url, std::vector<Tab> &result_tabs) {
+ auto related_page_body = create_body(false, true);
+ related_page_body->set_items(related_videos);
+ result_tabs.push_back(Tab{create_body(), std::make_unique<YoutubeCommentsPage>(program, url, comments_continuation_token), nullptr});
+ result_tabs.push_back(Tab{std::move(related_page_body), std::make_unique<YoutubeRelatedVideosPage>(program), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
+ result_tabs.push_back(Tab{create_body(false, true), std::make_unique<YoutubeChannelPage>(program, channel_url, "", "Channel videos"), create_search_bar("Search...", 350)});
+ return PluginResult::OK;
}
static std::map<std::string, std::string> http_params_parse(const std::string &http_params) {