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. --- src/plugins/NyaaSi.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/plugins/NyaaSi.cpp') diff --git a/src/plugins/NyaaSi.cpp b/src/plugins/NyaaSi.cpp index a110c57..fc3e7ee 100644 --- a/src/plugins/NyaaSi.cpp +++ b/src/plugins/NyaaSi.cpp @@ -284,14 +284,14 @@ namespace QuickMedia { return SearchResult::OK; } - PluginResult NyaaSiCategoryPage::submit(const std::string &title, const std::string &url, std::vector &result_tabs) { + PluginResult NyaaSiCategoryPage::submit(const SubmitArgs &args, std::vector &result_tabs) { std::string domain = is_sukebei ? "sukebei.nyaa.si" : "nyaa.si"; BodyItems result_items; - SearchResult search_result = search_page(domain, url, "", 1, NyaaSiSortType::UPLOAD_DATE_DESC, result_items); + SearchResult search_result = search_page(domain, args.url, "", 1, NyaaSiSortType::UPLOAD_DATE_DESC, result_items); if(search_result != SearchResult::OK) return search_result_to_plugin_result(search_result); - auto search_page = std::make_unique(program, strip(title), url, std::move(domain)); + auto search_page = std::make_unique(program, strip(args.title), args.url, std::move(domain)); NyaaSiSearchPage *search_page_p = search_page.get(); auto body = create_body(); body->set_items(std::move(result_items)); @@ -323,7 +323,7 @@ namespace QuickMedia { const std::string *domain; }; - PluginResult NyaaSiSearchPage::submit(const std::string&, const std::string &url, std::vector &result_tabs) { + PluginResult NyaaSiSearchPage::submit(const SubmitArgs &args, std::vector &result_tabs) { size_t comments_start_index; std::string title; BodyItems result_items; @@ -337,7 +337,7 @@ namespace QuickMedia { result_item_extra.domain = &domain; std::string website_data; - if(download_to_string(url, website_data, {}, true) != DownloadResult::OK) + if(download_to_string(args.url, website_data, {}, true) != DownloadResult::OK) return PluginResult::NET_ERR; QuickMediaHtmlSearch html_search; @@ -498,8 +498,8 @@ namespace QuickMedia { title.erase(title.end() - 5, title.end()); // Erase emoji character and space at the end. TODO: Remove this when tabs support emojis. } - PluginResult NyaaSiSortOrderPage::submit(const std::string&, const std::string&, std::vector&) { - const NyaaSiSortType sort_type = (NyaaSiSortType)(size_t)submit_body_item->userdata; + PluginResult NyaaSiSortOrderPage::submit(const SubmitArgs &args, std::vector&) { + const NyaaSiSortType sort_type = (NyaaSiSortType)(size_t)args.userdata; body->clear_items(); sort_page_create_body_items(body, sort_type); search_page->set_sort_type(sort_type); @@ -507,15 +507,14 @@ namespace QuickMedia { return PluginResult::OK; } - PluginResult NyaaSiTorrentPage::submit(const std::string &title, const std::string &url, std::vector &result_tabs) { - (void)title; + PluginResult NyaaSiTorrentPage::submit(const SubmitArgs &submit_args, std::vector &result_tabs) { (void)result_tabs; - if(strncmp(url.c_str(), "magnet:?", 8) == 0) { + if(strncmp(submit_args.url.c_str(), "magnet:?", 8) == 0) { if(!is_program_executable_by_name("xdg-open")) { show_notification("QuickMedia", "xdg-utils which provides xdg-open needs to be installed to download torrents", Urgency::CRITICAL); return PluginResult::ERR; } - const char *args[] = { "xdg-open", url.c_str(), nullptr }; + const char *args[] = { "xdg-open", submit_args.url.c_str(), nullptr }; exec_program_async(args, nullptr); } return PluginResult::OK; -- cgit v1.2.3