aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-06-19 04:46:27 +0200
committerdec05eba <dec05eba@protonmail.com>2022-06-19 04:46:27 +0200
commit295ab1f44b76bf88606a217fd6a014cbdf5a915d (patch)
tree665fb8f0f67e46f05a0c84157c6c01e59a7150c6
parent42891df4c3c184b7123ba44693c489f489de10e3 (diff)
Fix submit on async reload page, fix submit on search suggestion page empty text
-rw-r--r--TODO3
-rw-r--r--include/QuickMedia.hpp1
-rw-r--r--plugins/Page.hpp2
-rw-r--r--plugins/Youtube.hpp2
-rw-r--r--src/QuickMedia.cpp60
5 files changed, 39 insertions, 29 deletions
diff --git a/TODO b/TODO
index bb0ba83..be98cd6 100644
--- a/TODO
+++ b/TODO
@@ -223,4 +223,5 @@ Periodically cleanup old cache files (especially manga images, thumbnails and me
Render watch progress in youtube.
Set _NET_WM_USER_TIME (see sfml).
Make saucenao work with encrypted images in matrix, or show an error as this is a "security" risk.
-Body image cache (async image loader) should take requested size into consideration, because the same image can be requested at multiple sizes and we dont want to cache the smaller sized image for both. \ No newline at end of file
+Body image cache (async image loader) should take requested size into consideration, because the same image can be requested at multiple sizes and we dont want to cache the smaller sized image for both.
+To make quickmedia more resilient against broken youtube videos, quickmedia should try other quality if video/audio fails to play. Also do that if the download is stuck/slow for the current quality. \ No newline at end of file
diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp
index b5570da..4011ca0 100644
--- a/include/QuickMedia.hpp
+++ b/include/QuickMedia.hpp
@@ -69,6 +69,7 @@ namespace QuickMedia {
bool fetching_next_page_running = false;
bool fetching_next_page_failed = false;
bool search_suggestion_submitted = false;
+ bool search_text_empty = true;
bool card_view = false;
int fetched_page = 0;
mgl::Text search_result_text;
diff --git a/plugins/Page.hpp b/plugins/Page.hpp
index 64c24c3..c1ca012 100644
--- a/plugins/Page.hpp
+++ b/plugins/Page.hpp
@@ -39,7 +39,7 @@ namespace QuickMedia {
virtual SearchResult search(const std::string &str, BodyItems &result_items) { (void)str; (void)result_items; return SearchResult::ERR; }
// If this returns true then |submit_suggestion| is called when submitting the selected item instead of |submit|
// and |submit| is called when submitting the response of |submit_suggestion|
- virtual bool search_is_suggestion() { return false; }
+ virtual bool search_is_suggestion(bool empty_search) { (void)empty_search; return false; }
// Return empty |result_tabs| and PluginResult::OK to do nothing; which is useful for implementing custom actions on item submit
virtual PluginResult submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) {
diff --git a/plugins/Youtube.hpp b/plugins/Youtube.hpp
index dc604a9..5affe04 100644
--- a/plugins/Youtube.hpp
+++ b/plugins/Youtube.hpp
@@ -45,7 +45,7 @@ namespace QuickMedia {
public:
YoutubeSearchPage(Program *program, std::string video_id = "") : LazyFetchPage(program), video_id(std::move(video_id)) {}
const char* get_title() const override { return "Search"; }
- bool search_is_suggestion() override { return true; }
+ bool search_is_suggestion(bool empty_search) override { return !empty_search; }
bool search_is_filter() override { return false; }
SearchResult search(const std::string &str, BodyItems &result_items) override;
PluginResult get_page(const std::string &str, int page, BodyItems &result_items) override;
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index dad215f..29ada07 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -1942,7 +1942,7 @@ namespace QuickMedia {
if(tab_associated_data.fetching_next_page_running)
window.draw(gradient_points, 4, mgl::PrimitiveType::Quads); // TODO: mgl::PrimitiveType::Quads doesn't work with egl
- if(!tab_associated_data.search_result_text.get_string().empty() && !tabs[selected_tab].page->search_is_suggestion()) {
+ if(!tab_associated_data.search_result_text.get_string().empty() && !tabs[selected_tab].page->search_is_suggestion(tab_associated_data.search_text_empty)) {
auto search_result_text_bounds = tab_associated_data.search_result_text.get_bounds();
tab_associated_data.search_result_text.set_position(mgl::vec2f(
std::floor(body_pos.x + body_size.x * 0.5f - search_result_text_bounds.size.x * 0.5f),
@@ -2070,7 +2070,7 @@ namespace QuickMedia {
BodyItems new_body_items;
const bool search_suggestion_submitted = tab_associated_data[selected_tab].search_suggestion_submitted;
- if((tabs[selected_tab].page->is_single_page() || (tabs[selected_tab].page->search_is_suggestion() && !search_suggestion_submitted))
+ if((tabs[selected_tab].page->is_single_page() || (tabs[selected_tab].page->search_is_suggestion(tab_associated_data[selected_tab].search_text_empty) && !search_suggestion_submitted))
&& tab_associated_data[selected_tab].fetch_future.valid())
{
tabs[selected_tab].page->cancel_operation();
@@ -2087,7 +2087,7 @@ namespace QuickMedia {
submit_args.userdata = selected_item ? selected_item->userdata : nullptr;
submit_args.extra = selected_item ? selected_item->extra : nullptr;
- if(tabs[selected_tab].page->search_is_suggestion() && !search_suggestion_submitted) {
+ if(tabs[selected_tab].page->search_is_suggestion(tab_associated_data[selected_tab].search_text_empty) && !search_suggestion_submitted) {
tabs[selected_tab].body->card_view = tab_associated_data[selected_tab].card_view;
PluginResult plugin_result = tabs[selected_tab].page->submit_suggestion(submit_args, new_body_items);
return plugin_result == PluginResult::OK;
@@ -2125,7 +2125,7 @@ namespace QuickMedia {
}
}
- if(tabs[selected_tab].page->is_single_page() && !tabs[selected_tab].page->search_is_suggestion()) {
+ if(tabs[selected_tab].page->is_single_page() && !tabs[selected_tab].page->search_is_suggestion(tab_associated_data[selected_tab].search_text_empty)) {
if(tabs[selected_tab].search_bar) tabs[selected_tab].search_bar->clear();
if(new_tabs.size() == 1 && !new_tabs[0].page) {
tabs[selected_tab].body = std::move(new_tabs[0].body);
@@ -2136,7 +2136,7 @@ namespace QuickMedia {
}
}
- if(tabs[selected_tab].page->search_is_suggestion() && !search_suggestion_submitted) {
+ if(tabs[selected_tab].page->search_is_suggestion(tab_associated_data[selected_tab].search_text_empty) && !search_suggestion_submitted) {
if(tabs[selected_tab].search_bar)
tabs[selected_tab].search_bar->set_text(selected_item ? selected_item->get_title() : search_text, false);
tabs[selected_tab].body->set_items(std::move(new_body_items));
@@ -2153,14 +2153,6 @@ namespace QuickMedia {
for(size_t i = 0; i < tabs.size(); ++i) {
tabs[i].body->clear_cache();
- const bool lazy_update = tabs[i].page->search_is_filter() || (tabs[i].search_bar && tabs[i].search_bar->get_text().empty());
- if(tabs[i].page->is_lazy_fetch_page() && static_cast<LazyFetchPage*>(tabs[i].page.get())->reload_on_page_change() && lazy_update) {
- tab_associated_data[i].lazy_fetch_finished = false;
- tab_associated_data[i].fetched_page = 0;
- const BodyItem *selected_item = tabs[i].body->get_selected();
- tab_associated_data[i].body_item_url_before_refresh = selected_item ? selected_item->url : "";
- tabs[i].body->clear_items();
- }
}
if(tabs[selected_tab].page->allow_submit_no_selection()) {
@@ -2293,6 +2285,17 @@ namespace QuickMedia {
page_loop(new_tabs, 0, after_submit_handler);
}
+ for(size_t i = 0; i < tabs.size(); ++i) {
+ const bool lazy_update = tabs[i].page->search_is_filter() || (tabs[i].search_bar && tabs[i].search_bar->get_text().empty());
+ if(tabs[i].page->is_lazy_fetch_page() && static_cast<LazyFetchPage*>(tabs[i].page.get())->reload_on_page_change() && lazy_update) {
+ tab_associated_data[i].lazy_fetch_finished = false;
+ tab_associated_data[i].fetched_page = 0;
+ const BodyItem *selected_item = tabs[i].body->get_selected();
+ tab_associated_data[i].body_item_url_before_refresh = selected_item ? selected_item->url : "";
+ tabs[i].body->clear_items();
+ }
+ }
+
for(Tab &tab : tabs) {
tab.page->on_navigate_to_page(tab.body.get());
}
@@ -2309,7 +2312,7 @@ namespace QuickMedia {
&& !tab_associated_data[selected_tab].fetching_next_page_failed
&& (!tabs[selected_tab].search_bar || !tabs[selected_tab].page->search_is_filter() || tabs[selected_tab].search_bar->is_empty())
&& tabs[selected_tab].body->get_num_visible_items() > 0
- && (!tabs[selected_tab].page->search_is_suggestion() || tab_associated_data[selected_tab].search_suggestion_submitted)
+ && (!tabs[selected_tab].page->search_is_suggestion(tab_associated_data[selected_tab].search_text_empty) || tab_associated_data[selected_tab].search_suggestion_submitted)
&& tabs[selected_tab].page->is_ready()
&& (!tabs[selected_tab].page->is_lazy_fetch_page() || tab_associated_data[selected_tab].lazy_fetch_finished))
{
@@ -2612,10 +2615,10 @@ namespace QuickMedia {
if(associated_data.search_text_updated && associated_data.fetch_status == FetchStatus::NONE && !associated_data.fetching_next_page_running) {
std::string update_search_text = associated_data.update_search_text;
- if(!tabs[i].page->search_is_suggestion() || associated_data.search_suggestion_submitted)
+ if(!tabs[i].page->search_is_suggestion(associated_data.search_text_empty) || associated_data.search_suggestion_submitted)
tabs[i].body->clear_items();
- if(tabs[i].page->search_is_suggestion() && tabs[i].body) {
+ if(tabs[i].page->search_is_suggestion(associated_data.search_text_empty) && tabs[i].body) {
if(update_search_text.empty())
tabs[i].body->card_view = tab_associated_data[selected_tab].card_view;
else
@@ -2647,6 +2650,7 @@ namespace QuickMedia {
}
associated_data.fetched_page = 0;
associated_data.fetching_next_page_failed = false;
+ associated_data.search_text_empty = associated_data.update_search_text.empty();
if(fetch_result.result != PluginResult::OK)
associated_data.search_result_text.set_string("Search failed!");
else if(tabs[i].body->get_num_items() == 0)
@@ -3163,11 +3167,13 @@ namespace QuickMedia {
SubmitArgs submit_args;
if(parent_body) {
BodyItem *selected = parent_body->get_selected();
- submit_args.title = selected->get_title();
- submit_args.url = selected->url;
- submit_args.thumbnail_url = selected->thumbnail_url;
- submit_args.userdata = selected->userdata;
- submit_args.extra = selected->extra;
+ if(selected) {
+ submit_args.title = selected->get_title();
+ submit_args.url = selected->url;
+ submit_args.thumbnail_url = selected->thumbnail_url;
+ submit_args.userdata = selected->userdata;
+ submit_args.extra = selected->extra;
+ }
}
std::string err_str;
@@ -7879,11 +7885,13 @@ namespace QuickMedia {
std::vector<Tab> new_tabs;
TaskResult task_result = run_task_with_loading_screen([&]() {
SubmitArgs submit_args;
- submit_args.title = selected->get_title();
- submit_args.url = selected->url;
- submit_args.thumbnail_url = selected->thumbnail_url;
- submit_args.userdata = selected->userdata;
- submit_args.extra = selected->extra;
+ if(selected) {
+ submit_args.title = selected->get_title();
+ submit_args.url = selected->url;
+ submit_args.thumbnail_url = selected->thumbnail_url;
+ submit_args.userdata = selected->userdata;
+ submit_args.extra = selected->extra;
+ }
return file_manager_page->submit(submit_args, new_tabs) == PluginResult::OK;
});