From 75c610d1f65d741bbeba9f1ddeef60a6e9315427 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 7 Feb 2022 22:54:20 +0100 Subject: Use one struct for all args in Page::submit instead of multiple args (easier to add new fields without changing code) Also remove submit_body_item from page. --- plugins/Page.hpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'plugins/Page.hpp') diff --git a/plugins/Page.hpp b/plugins/Page.hpp index b9f220d..0e904c2 100644 --- a/plugins/Page.hpp +++ b/plugins/Page.hpp @@ -20,6 +20,14 @@ namespace QuickMedia { CHAT }; + struct SubmitArgs { + std::string title; + std::string url; + std::string thumbnail_url; + void *userdata; + std::shared_ptr extra; + }; + class Page { public: Page(Program *program) : program(program) {} @@ -34,18 +42,16 @@ namespace QuickMedia { virtual bool search_is_suggestion() { 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 std::string &title, const std::string &url, std::vector &result_tabs) { - (void)title; - (void)url; + virtual PluginResult submit(const SubmitArgs &args, std::vector &result_tabs) { + (void)args; (void)result_tabs; return PluginResult::ERR; } // Override and return false to make submit run in the main (ui) thread virtual bool submit_is_async() const { return true; } virtual bool clear_search_after_submit() { return false; } - virtual PluginResult submit_suggestion(const std::string &title, const std::string &url, BodyItems &result_items) { - (void)title; - (void)url; + virtual PluginResult submit_suggestion(const SubmitArgs &args, BodyItems &result_items) { + (void)args; (void)result_items; return PluginResult::ERR; } @@ -84,7 +90,6 @@ namespace QuickMedia { void set_clipboard(const std::string &str); Program *program; - std::shared_ptr submit_body_item; // TODO: Remove this bool needs_refresh = false; // Set to true to refresh the page. Note: only works for search pages and lazy fetch pages }; @@ -173,7 +178,7 @@ namespace QuickMedia { public: BookmarksPage(Program *program, Page *redirect_page) : LazyFetchPage(program), redirect_page(redirect_page) {} const char* get_title() const override { return "Bookmarks"; } - PluginResult submit(const std::string &title, const std::string &url, std::vector &result_tabs) override; + PluginResult submit(const SubmitArgs &args, std::vector &result_tabs) override; PluginResult lazy_fetch(BodyItems &result_items) override; bool reload_on_page_change() override { return true; } const char* get_bookmark_name() const override { return redirect_page->get_bookmark_name(); } -- cgit v1.2.3