From d5de8a91d16e0945e471937953b903ac76cb020f Mon Sep 17 00:00:00 2001 From: Toff Date: Mon, 17 Apr 2017 14:56:11 +0200 Subject: [PATCH] Merge chros73 suggestions (settings to exclude views and hide info logs) - Certain views can be excluded from subfiltering via view.temp_filter.excluded config option - its default value: "default,started,stopped" - example usage in config: view.temp_filter.excluded.set="default,started,stopped,leeching" - Log messages can be displayed when temp filtering occured - disabled by default - can be enabled with: ui.console.log.tempfilter.set=1 --- src/command_ui.cc | 3 +++ src/ui/download_list.cc | 28 +++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/command_ui.cc b/src/command_ui.cc index 58abf54e..eba8f137 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -605,6 +605,9 @@ initialize_command_ui() { CMD2_ANY ("ui.current_view", std::bind(&cmd_ui_current_view)); CMD2_ANY_STRING("ui.current_view.set", std::bind(&cmd_ui_set_view, std::placeholders::_2)); + CMD2_VAR_STRING("view.temp_filter.excluded", "default,started,stopped"); + CMD2_VAR_BOOL ("ui.console.log.tempfilter", 0); + // TODO: Add 'option_string' for rtorrent-specific options. CMD2_VAR_STRING("ui.torrent_list.layout", "full"); diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index c88079af..9be1da1e 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -36,6 +36,8 @@ #include "config.h" +#include + #include #include #include @@ -263,12 +265,22 @@ DownloadList::receive_view_input(Input type) { break; case INPUT_FILTER: - // STARTED and STOPPED views are not allowed to being filtered: they are special - if (current_view()->name() == "started" || current_view()->name() == "stopped") { - control->core()->push_log_std("View '" + current_view()->name() + "' can't be filtered."); - return; + { + // Do not allow to subfilter the defined excluded views + const std::string excluded_views = rpc::call_command_string("view.temp_filter.excluded"); + std::stringstream ss(excluded_views); + std::string view_name_var; + + while(ss.good()) { + std::getline(ss, view_name_var, ','); + if (current_view()->name() == rak::trim(view_name_var)) { + control->core()->push_log_std("View '" + current_view()->name() + "' can't be filtered."); + return; + } + } + + title = "filter"; } - title = "filter"; break; default: @@ -336,7 +348,8 @@ DownloadList::receive_exit_input(Input type) { case INPUT_FILTER: if (input->str().empty()) { - control->core()->push_log_std("Clear temporary filter on '" + current_view()->name() + "' view."); + if (rpc::call_command_value("ui.console.log.tempfilter")) + control->core()->push_log_std("Clear temporary filter on '" + current_view()->name() + "' view."); current_view()->set_temp_filter(torrent::Object()); current_view()->filter(); current_view()->sort(); @@ -348,7 +361,8 @@ DownloadList::receive_exit_input(Input type) { pattern = ".*" + pattern; std::transform(pattern.begin(), pattern.end(), pattern.begin(), ::tolower); std::string tempFilter = "match={d.name=," + pattern + "}"; - control->core()->push_log_std("Temporary filter on '" + current_view()->name() + "' view: " + pattern); + if (rpc::call_command_value("ui.console.log.tempfilter")) + control->core()->push_log_std("Temporary filter on '" + current_view()->name() + "' view: " + pattern); current_view()->set_temp_filter(tempFilter); current_view()->filter(); }