diff options
author | xsmile | 2017-03-11 23:41:21 +0100 |
---|---|---|
committer | xsmile | 2017-03-11 23:41:21 +0100 |
commit | 7548f9e4db9261cbae7ddb285316e1b5ced60e57 (patch) | |
tree | 9195572b8c1ecb2c4145015411c3e3b1d1ab0966 /ui_pyroscope.cc | |
parent | 6c3ec2953f25407677ab0df9607eeee1040a6bed (diff) | |
download | aur-7548f9e4db9261cbae7ddb285316e1b5ced60e57.tar.gz |
update
Diffstat (limited to 'ui_pyroscope.cc')
-rw-r--r-- | ui_pyroscope.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/ui_pyroscope.cc b/ui_pyroscope.cc index fd80f174b584..f430df654087 100644 --- a/ui_pyroscope.cc +++ b/ui_pyroscope.cc @@ -100,6 +100,10 @@ static const char* color_vars[ps::COL_MAX] = { // collapsed state of views (default is false) static std::map<std::string, bool> is_collapsed; +// tracker aliases map +typedef std::map<std::string, std::string> string_kv_map; +static string_kv_map tracker_aliases; + // Traffic history static int network_history_depth = 0; static uint32_t network_history_count = 0; @@ -340,6 +344,9 @@ static void decorate_download_title(Window* window, display::Canvas* canvas, cor // show label for tracker in focus std::string url = get_active_tracker_domain((*range.first)->download()); if (!url.empty()) { + std::string alias = tracker_aliases[url]; + if (!alias.empty()) url = alias; + // shorten label if too long int len = url.length(); if (len > TRACKER_LABEL_WIDTH) { @@ -756,6 +763,33 @@ torrent::Object network_history_sample() { } +torrent::Object cmd_trackers_alias_set_key(rpc::target_type target, const torrent::Object::list_type& args) { + torrent::Object::list_const_iterator itr = args.begin(); + if (args.size() != 2) { + throw torrent::input_error("trackers.alias.set_key: expecting two arguments!"); + } + std::string domain = (itr++)->as_string(); + std::string alias = (itr++)->as_string(); + + tracker_aliases[domain] = alias; + + return torrent::Object(); +} + + +torrent::Object cmd_trackers_alias_items(rpc::target_type target) { + torrent::Object rawResult = torrent::Object::create_list(); + torrent::Object::list_type& result = rawResult.as_list(); + + for (string_kv_map::const_iterator itr = tracker_aliases.begin(), last = tracker_aliases.end(); itr != last; itr++) { + std::string mapping = itr->first + "=" + itr->second; + result.push_back(mapping); + } + + return rawResult; +} + + // register our commands void initialize_command_ui_pyroscope() { #define PS_VARIABLE_COLOR(key, value) \ @@ -776,6 +810,9 @@ void initialize_command_ui_pyroscope() { CMD2_ANY_STRING("view.collapsed.toggle", _cxxstd_::bind(&cmd_view_collapsed_toggle, _cxxstd_::placeholders::_2)); + CMD2_ANY_LIST("trackers.alias.set_key", &cmd_trackers_alias_set_key); + CMD2_ANY("trackers.alias.items", _cxxstd_::bind(&cmd_trackers_alias_items, _cxxstd_::placeholders::_1)); + CMD2_VAR_VALUE("ui.style.progress", 1); CMD2_VAR_VALUE("ui.style.ratio", 1); |