From 644c8b04f27827759a830738820143105c7e2536 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 18 Jun 2021 12:56:26 +0200 Subject: 4chan, soundcloud: move selection to autoplay item --- src/QuickMedia.cpp | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'src/QuickMedia.cpp') diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 5316d3f..bf6cf7e 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1197,7 +1197,7 @@ namespace QuickMedia { current_page = PageType::VIDEO_CONTENT; auto youtube_video_page = std::make_unique(this, youtube_url); BodyItems body_items; - video_content_page(nullptr, youtube_video_page.get(), "", false, body_items, 0); + video_content_page(nullptr, youtube_video_page.get(), "", false, nullptr, body_items, 0); } } else if(strcmp(plugin_name, "pornhub") == 0) { auto search_page = std::make_unique(this, "https://www.pornhub.com/", sf::Vector2i(320/1.5f, 180/1.5f)); @@ -1791,7 +1791,7 @@ namespace QuickMedia { page_stack.push(current_page); current_page = PageType::VIDEO_CONTENT; int selected_index = tabs[selected_tab].body->get_selected_item(); - video_content_page(tabs[selected_tab].page.get(), static_cast(new_tabs[0].page.get()), "", false, tabs[selected_tab].body->items, selected_index, &tab_associated_data[selected_tab].fetched_page, tab_associated_data[selected_tab].update_search_text); + video_content_page(tabs[selected_tab].page.get(), static_cast(new_tabs[0].page.get()), "", false, tabs[selected_tab].body.get(), tabs[selected_tab].body->items, selected_index, &tab_associated_data[selected_tab].fetched_page, tab_associated_data[selected_tab].update_search_text); } else if(new_tabs.size() == 1 && new_tabs[0].page->get_type() == PageTypez::CHAT) { MatrixChatPage *tmp_matrix_chat_page = static_cast(new_tabs[0].page.get()); MatrixRoomsPage *rooms_page = tmp_matrix_chat_page->rooms_page; @@ -2084,6 +2084,7 @@ 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; associated_data.search_text_updated = false; + tabs[i].body->clear_items(); associated_data.fetch_status = FetchStatus::LOADING; associated_data.fetch_type = FetchType::SEARCH; associated_data.search_result_text.setString("Searching..."); @@ -2455,7 +2456,7 @@ namespace QuickMedia { #define CLEANMASK(mask) ((mask) & (ShiftMask|ControlMask|Mod1Mask|Mod4Mask|Mod5Mask)) - void Program::video_content_page(Page *parent_page, VideoPage *video_page, std::string video_title, bool download_if_streaming_fails, BodyItems &next_play_items, int play_index, int *parent_body_page, const std::string &parent_page_search) { + void Program::video_content_page(Page *parent_page, VideoPage *video_page, std::string video_title, bool download_if_streaming_fails, Body *parent_body, BodyItems &next_play_items, int play_index, int *parent_body_page, const std::string &parent_page_search) { PageType previous_page = pop_page_stack(); bool video_loaded = false; @@ -2467,8 +2468,11 @@ namespace QuickMedia { video_player.reset(); BodyItems related_videos; - if(video_page->autoplay_next_item() && play_index + 1 >= 0 && play_index + 1 < (int)next_play_items.size()) + bool move_in_parent = false; + if(video_page->autoplay_next_item() && play_index + 1 >= 0 && play_index + 1 < (int)next_play_items.size()) { related_videos.insert(related_videos.end(), next_play_items.begin() + play_index + 1, next_play_items.end()); + move_in_parent = true; + } sf::WindowHandle video_player_window = None; auto on_window_create = [this, &video_player_window](sf::WindowHandle _video_player_window) mutable { @@ -2849,9 +2853,13 @@ namespace QuickMedia { } // Find video that hasn't been played before in this video session - auto find_next_video = [this, &related_videos, &video_page, &new_video_url]() { + auto find_next_video = [this, parent_body, move_in_parent, &related_videos, &video_page, &new_video_url]() { for(auto it = related_videos.begin(), end = related_videos.end(); it != end; ++it) { if(!(*it)->url.empty() && watched_videos.find((*it)->url) == watched_videos.end() && !video_page->video_should_be_skipped((*it)->url)) { + if(parent_body && move_in_parent) { + parent_body->filter_search_fuzzy(""); + parent_body->set_selected_item(it->get()); + } new_video_url = (*it)->url; related_videos.erase(it); break; @@ -2875,6 +2883,7 @@ namespace QuickMedia { size_t num_new_messages = new_body_items.size(); if(num_new_messages > 0) { next_play_items.insert(next_play_items.end(), new_body_items.begin(), new_body_items.end()); + if(parent_body) parent_body->items_set_dirty(); (*parent_body_page)++; related_videos = std::move(new_body_items); find_next_video(); @@ -3661,8 +3670,8 @@ namespace QuickMedia { sf::Vector2f body_size; sf::Event event; - std::stack comment_navigation_stack; - std::stack comment_page_scroll_stack; + std::deque comment_navigation_stack; + std::deque comment_page_scroll_stack; while (current_page == PageType::IMAGE_BOARD_THREAD && window.isOpen()) { while (window.pollEvent(event)) { @@ -3705,8 +3714,13 @@ namespace QuickMedia { watched_videos.clear(); thread_page->set_url(selected_item->url); BodyItems next_items; + int prev_selected = thread_body->get_selected_item(); // TODO: Use real title - video_content_page(thread_page, thread_page, "", true, thread_body->items, thread_body->get_selected_item()); + video_content_page(thread_page, thread_page, "", true, thread_body, thread_body->items, thread_body->get_selected_item()); + if(thread_body->get_selected_item() != prev_selected) { + comment_navigation_stack.clear(); + comment_page_scroll_stack.clear(); + } redraw = true; } else { BodyItem *selected_item = thread_body->get_selected(); @@ -3777,7 +3791,7 @@ namespace QuickMedia { } BodyItem *selected_item = thread_body->get_selected(); - if(event.key.code == sf::Keyboard::Enter && selected_item && (comment_navigation_stack.empty() || thread_body->get_selected_item() != comment_navigation_stack.top()) && (!selected_item->replies_to.empty() || !selected_item->replies.empty())) { + if(event.key.code == sf::Keyboard::Enter && selected_item && (comment_navigation_stack.empty() || thread_body->get_selected_item() != comment_navigation_stack.back()) && (!selected_item->replies_to.empty() || !selected_item->replies.empty())) { for(auto &body_item : thread_body->items) { body_item->visible = false; } @@ -3788,15 +3802,15 @@ namespace QuickMedia { for(size_t reply_index : selected_item->replies) { thread_body->items[reply_index]->visible = true; } - comment_navigation_stack.push(thread_body->get_selected_item()); - comment_page_scroll_stack.push(thread_body->get_page_scroll()); + comment_navigation_stack.push_back(thread_body->get_selected_item()); + comment_page_scroll_stack.push_back(thread_body->get_page_scroll()); //thread_body->clamp_selection(); thread_body->set_page_scroll(0.0f); } else if(event.key.code == sf::Keyboard::BackSpace && !comment_navigation_stack.empty()) { - size_t previous_selected = comment_navigation_stack.top(); - float previous_page_scroll = comment_page_scroll_stack.top(); - comment_navigation_stack.pop(); - comment_page_scroll_stack.pop(); + size_t previous_selected = comment_navigation_stack.back(); + float previous_page_scroll = comment_page_scroll_stack.back(); + comment_navigation_stack.pop_back(); + comment_page_scroll_stack.pop_back(); if(comment_navigation_stack.empty()) { for(auto &body_item : thread_body->items) { body_item->visible = true; @@ -3808,7 +3822,7 @@ namespace QuickMedia { body_item->visible = false; } thread_body->set_selected_item(previous_selected); - selected_item = thread_body->items[comment_navigation_stack.top()].get(); + selected_item = thread_body->items[comment_navigation_stack.back()].get(); selected_item->visible = true; for(size_t reply_to_index : selected_item->replies_to) { thread_body->items[reply_to_index]->visible = true; @@ -5165,7 +5179,7 @@ namespace QuickMedia { current_page = PageType::VIDEO_CONTENT; auto youtube_video_page = std::make_unique(this, url); // TODO: Use real title - video_content_page(matrix_chat_page, youtube_video_page.get(), "", false, tabs[MESSAGES_TAB_INDEX].body->items, tabs[MESSAGES_TAB_INDEX].body->get_selected_item()); + video_content_page(matrix_chat_page, youtube_video_page.get(), "", false, nullptr, tabs[MESSAGES_TAB_INDEX].body->items, tabs[MESSAGES_TAB_INDEX].body->get_selected_item()); redraw = true; avatar_applied = false; } else { @@ -5243,7 +5257,7 @@ namespace QuickMedia { no_video = is_audio; video_page->set_url(selected->url); BodyItems next_items; - video_content_page(matrix_chat_page, video_page.get(), selected_item_message->body, message_type == MessageType::VIDEO || message_type == MessageType::AUDIO, next_items, 0); + video_content_page(matrix_chat_page, video_page.get(), selected_item_message->body, message_type == MessageType::VIDEO || message_type == MessageType::AUDIO, nullptr, next_items, 0); no_video = prev_no_video; redraw = true; avatar_applied = false; -- cgit v1.2.3