2010-03-14 05:13:02 +00:00
|
|
|
/*
|
2021-10-18 20:22:31 +00:00
|
|
|
* This file Copyright (C) 2012-2021 Mnemosyne LLC
|
2010-03-14 05:13:02 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2010-03-14 05:13:02 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <set>
|
2017-04-21 07:40:57 +00:00
|
|
|
#include <stdlib.h> /* qsort() */
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <unordered_map>
|
2011-03-16 18:04:23 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <glibmm.h>
|
|
|
|
#include <glibmm/i18n.h>
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/utils.h>
|
|
|
|
|
2017-04-21 07:40:57 +00:00
|
|
|
#include "favicon.h" /* gtr_get_favicon() */
|
2010-03-14 05:13:02 +00:00
|
|
|
#include "filter.h"
|
|
|
|
#include "hig.h" /* GUI_PAD */
|
2011-03-03 01:59:25 +00:00
|
|
|
#include "tr-core.h" /* MC_TORRENT */
|
2017-04-21 07:40:57 +00:00
|
|
|
#include "util.h" /* gtr_get_host_from_url() */
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
auto const DIRTY_KEY = Glib::Quark("tr-filter-dirty-key");
|
|
|
|
auto const SESSION_KEY = Glib::Quark("tr-session-key");
|
|
|
|
auto const TEXT_KEY = Glib::Quark("tr-filter-text-key");
|
|
|
|
auto const TORRENT_MODEL_KEY = Glib::Quark("tr-filter-torrent-model-key");
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class FilterBar::Impl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Impl(FilterBar& widget, tr_session* session, Glib::RefPtr<Gtk::TreeModel> const& torrent_model);
|
|
|
|
~Impl();
|
|
|
|
|
|
|
|
Glib::RefPtr<Gtk::TreeModel> get_filter_model() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Gtk::ComboBox* activity_combo_box_new(Glib::RefPtr<Gtk::TreeModel> const& tmodel);
|
|
|
|
Gtk::ComboBox* tracker_combo_box_new(Glib::RefPtr<Gtk::TreeModel> const& tmodel);
|
|
|
|
|
|
|
|
void update_count_label_idle();
|
|
|
|
|
|
|
|
bool is_row_visible(Gtk::TreeModel::const_iterator const& iter);
|
|
|
|
|
|
|
|
void selection_changed_cb();
|
|
|
|
bool update_count_label();
|
|
|
|
void filter_entry_changed();
|
|
|
|
|
|
|
|
private:
|
|
|
|
FilterBar& widget_;
|
|
|
|
|
|
|
|
Gtk::ComboBox* activity_ = nullptr;
|
|
|
|
Gtk::ComboBox* tracker_ = nullptr;
|
|
|
|
Gtk::Entry* entry_ = nullptr;
|
|
|
|
Gtk::Label* show_lb_ = nullptr;
|
|
|
|
Glib::RefPtr<Gtk::TreeModelFilter> filter_model_;
|
|
|
|
int active_activity_type_ = 0;
|
|
|
|
int active_tracker_type_ = 0;
|
|
|
|
Glib::ustring active_tracker_host_;
|
|
|
|
|
|
|
|
sigc::connection activity_model_row_changed_tag_;
|
|
|
|
sigc::connection activity_model_row_inserted_tag_;
|
|
|
|
sigc::connection activity_model_row_deleted_cb_tag_;
|
|
|
|
|
|
|
|
sigc::connection torrent_model_row_changed_tag_;
|
|
|
|
sigc::connection torrent_model_row_inserted_tag_;
|
|
|
|
sigc::connection torrent_model_row_deleted_cb_tag_;
|
|
|
|
};
|
2010-03-14 05:13:02 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
2013-01-01 19:45:00 +00:00
|
|
|
**** TRACKERS
|
2010-03-14 05:13:02 +00:00
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2010-03-14 05:13:02 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
TRACKER_FILTER_TYPE_ALL,
|
|
|
|
TRACKER_FILTER_TYPE_HOST,
|
|
|
|
TRACKER_FILTER_TYPE_SEPARATOR,
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
class TrackerFilterModelColumns : public Gtk::TreeModelColumnRecord
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
|
|
|
TrackerFilterModelColumns()
|
|
|
|
{
|
|
|
|
add(name);
|
|
|
|
add(count);
|
|
|
|
add(type);
|
|
|
|
add(host);
|
|
|
|
add(pixbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> name; /* human-readable name; ie, Legaltorrents */
|
|
|
|
Gtk::TreeModelColumn<int> count; /* how many matches there are */
|
|
|
|
Gtk::TreeModelColumn<int> type;
|
|
|
|
Gtk::TreeModelColumn<std::string> host; /* pattern-matching text; ie, legaltorrents.com */
|
|
|
|
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>> pixbuf;
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
TrackerFilterModelColumns const tracker_filter_cols;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2010-03-15 14:35:43 +00:00
|
|
|
/* human-readable name; ie, Legaltorrents */
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::ustring get_name_from_host(std::string const& host)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
std::string name;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (tr_addressIsIP(host.c_str()))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
name = host;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
else if (auto const dot = host.rfind('.'); dot != std::string::npos)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
name = host.substr(0, dot);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
name = host;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!name.empty())
|
|
|
|
{
|
|
|
|
name.front() = Glib::Ascii::toupper(name.front());
|
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return name;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void tracker_model_update_count(Gtk::TreeModel::iterator const& iter, int n)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (n != iter->get_value(tracker_filter_cols.count))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
iter->set_value(tracker_filter_cols.count, n);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void favicon_ready_cb(Glib::RefPtr<Gdk::Pixbuf> const& pixbuf, Gtk::TreeRowReference& reference)
|
2010-03-15 02:53:31 +00:00
|
|
|
{
|
2021-10-06 16:32:17 +00:00
|
|
|
if (pixbuf != nullptr)
|
2010-03-15 02:53:31 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const path = reference.get_path();
|
|
|
|
auto const model = reference.get_model();
|
2010-03-15 02:53:31 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto const iter = model->get_iter(path); iter)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
iter->set_value(tracker_filter_cols.pixbuf, pixbuf);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-03-15 02:53:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool tracker_filter_model_update(Glib::RefPtr<Gtk::TreeStore> const& tracker_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tracker_model->steal_data(DIRTY_KEY);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* Walk through all the torrents, tallying how many matches there are
|
|
|
|
* for the various categories. Also make a sorted list of all tracker
|
|
|
|
* hosts s.t. we can merge it with the existing list */
|
2020-11-04 00:59:19 +00:00
|
|
|
int num_torrents = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
std::vector<std::string const*> hosts;
|
|
|
|
std::set<std::string> strings;
|
|
|
|
std::unordered_map<std::string const*, int> hosts_hash;
|
|
|
|
auto* tmodel = static_cast<Gtk::TreeModel*>(tracker_model->get_data(TORRENT_MODEL_KEY));
|
|
|
|
for (auto const& row : tmodel->children())
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const* tor = static_cast<tr_torrent const*>(row.get_value(torrent_cols.torrent));
|
|
|
|
auto const* const inf = tr_torrentInfo(tor);
|
2020-11-04 00:59:19 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
std::set<std::string const*> keys;
|
2011-04-04 16:54:09 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (unsigned int i = 0; i < inf->trackerCount; ++i)
|
|
|
|
{
|
|
|
|
auto const* const key = &*strings.insert(gtr_get_host_from_url(inf->trackers[i].announce)).first;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto const count = hosts_hash.find(key); count == hosts_hash.end())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
hosts_hash.emplace(key, 1);
|
|
|
|
hosts.push_back(key);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
keys.insert(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto const* const key : keys)
|
|
|
|
{
|
|
|
|
++hosts_hash.at(key);
|
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
++num_torrents;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
std::sort(hosts.begin(), hosts.end(), [](auto const* lhs, auto const& rhs) { return *lhs < *rhs; });
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2020-11-04 00:59:19 +00:00
|
|
|
// update the "all" count
|
2021-10-18 20:22:31 +00:00
|
|
|
auto iter = tracker_model->children().begin();
|
|
|
|
if (iter)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tracker_model_update_count(iter, num_torrents);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
// offset past the "All" and the separator
|
|
|
|
++iter;
|
|
|
|
++iter;
|
|
|
|
|
|
|
|
size_t i = 0;
|
2020-11-04 00:59:19 +00:00
|
|
|
for (;;)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2020-11-04 00:59:19 +00:00
|
|
|
// are we done yet?
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const new_hosts_done = i >= hosts.size();
|
|
|
|
bool const old_hosts_done = !iter;
|
2017-04-19 12:04:45 +00:00
|
|
|
if (new_hosts_done && old_hosts_done)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2020-11-04 00:59:19 +00:00
|
|
|
// decide what to do
|
2021-10-18 20:22:31 +00:00
|
|
|
bool remove_row = false;
|
|
|
|
bool insert_row = false;
|
2017-04-19 12:04:45 +00:00
|
|
|
if (new_hosts_done)
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
remove_row = true;
|
2013-01-01 18:43:41 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (old_hosts_done)
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
insert_row = true;
|
2013-01-01 18:43:41 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const host = iter->get_value(tracker_filter_cols.host);
|
|
|
|
int const cmp = host.compare(*hosts.at(i));
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (cmp < 0)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
remove_row = true;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else if (cmp > 0)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
insert_row = true;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-04 00:59:19 +00:00
|
|
|
// do something
|
2017-04-19 12:04:45 +00:00
|
|
|
if (remove_row)
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
iter = tracker_model->erase(iter);
|
2013-01-01 18:43:41 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (insert_row)
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* session = static_cast<tr_session*>(tracker_model->get_data(SESSION_KEY));
|
|
|
|
auto const* host = hosts.at(i);
|
|
|
|
auto const add = tracker_model->insert(iter);
|
|
|
|
add->set_value(tracker_filter_cols.host, *host);
|
|
|
|
add->set_value(tracker_filter_cols.name, get_name_from_host(*host));
|
|
|
|
add->set_value(tracker_filter_cols.count, hosts_hash.at(host));
|
|
|
|
add->set_value(tracker_filter_cols.type, static_cast<int>(TRACKER_FILTER_TYPE_HOST));
|
|
|
|
auto path = tracker_model->get_path(add);
|
|
|
|
gtr_get_favicon(
|
|
|
|
session,
|
|
|
|
*host,
|
|
|
|
[ref = Gtk::TreeRowReference(tracker_model, path)](auto const& pixbuf) mutable
|
|
|
|
{ favicon_ready_cb(pixbuf, ref); });
|
|
|
|
// ++iter;
|
2017-04-19 12:04:45 +00:00
|
|
|
++i;
|
2013-01-01 18:43:41 +00:00
|
|
|
}
|
2020-11-04 00:59:19 +00:00
|
|
|
else // update row
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const* const host = hosts.at(i);
|
|
|
|
auto const count = hosts_hash.at(host);
|
|
|
|
tracker_model_update_count(iter, count);
|
|
|
|
++iter;
|
2017-04-19 12:04:45 +00:00
|
|
|
++i;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-17 17:07:40 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return false;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::RefPtr<Gtk::TreeStore> tracker_filter_model_new(Glib::RefPtr<Gtk::TreeModel> const& tmodel)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const store = Gtk::TreeStore::create(tracker_filter_cols);
|
|
|
|
|
|
|
|
auto iter = store->append();
|
|
|
|
iter->set_value(tracker_filter_cols.name, Glib::ustring(_("All")));
|
|
|
|
iter->set_value(tracker_filter_cols.type, static_cast<int>(TRACKER_FILTER_TYPE_ALL));
|
|
|
|
|
|
|
|
iter = store->append();
|
|
|
|
iter->set_value(tracker_filter_cols.type, static_cast<int>(TRACKER_FILTER_TYPE_SEPARATOR));
|
|
|
|
|
|
|
|
store->set_data(TORRENT_MODEL_KEY, gtr_get_ptr(tmodel));
|
2017-04-19 12:04:45 +00:00
|
|
|
tracker_filter_model_update(store);
|
2021-10-18 20:22:31 +00:00
|
|
|
return store;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool is_it_a_separator(Glib::RefPtr<Gtk::TreeModel> const& /*model*/, Gtk::TreeIter const& iter)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
return iter->get_value(tracker_filter_cols.type) == TRACKER_FILTER_TYPE_SEPARATOR;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void tracker_model_update_idle(Glib::RefPtr<Gtk::TreeStore> const& tracker_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const pending = tracker_model->get_data(DIRTY_KEY) != nullptr;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!pending)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tracker_model->set_data(DIRTY_KEY, GINT_TO_POINTER(1));
|
|
|
|
Glib::signal_idle().connect([tracker_model]() { return tracker_filter_model_update(tracker_model); });
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void render_pixbuf_func(Gtk::CellRendererPixbuf* cell_renderer, Gtk::TreeModel::const_iterator const& iter)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
cell_renderer->property_width() = (iter->get_value(tracker_filter_cols.type) == TRACKER_FILTER_TYPE_HOST) ? 20 : 0;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void render_number_func(Gtk::CellRendererText* cell_renderer, Gtk::TreeModel::const_iterator const& iter)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const count = iter->get_value(tracker_filter_cols.count);
|
|
|
|
cell_renderer->property_text() = count >= 0 ? gtr_sprintf("%'d", count) : "";
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::CellRendererText* number_renderer_new()
|
2010-03-15 02:53:31 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
2020-08-18 10:36:10 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
r->property_alignment() = Pango::ALIGN_RIGHT;
|
|
|
|
r->property_weight() = Pango::WEIGHT_ULTRALIGHT;
|
|
|
|
r->property_xalign() = 1.0;
|
|
|
|
r->property_xpad() = GUI_PAD;
|
2010-03-16 00:45:12 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return r;
|
2010-03-15 02:53:31 +00:00
|
|
|
}
|
2010-03-16 00:45:12 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::ComboBox* FilterBar::Impl::tracker_combo_box_new(Glib::RefPtr<Gtk::TreeModel> const& tmodel)
|
|
|
|
{
|
|
|
|
/* create the tracker combobox */
|
|
|
|
auto const cat_model = tracker_filter_model_new(tmodel);
|
|
|
|
auto* c = Gtk::make_managed<Gtk::ComboBox>(static_cast<Glib::RefPtr<Gtk::TreeModel> const&>(cat_model));
|
|
|
|
c->set_row_separator_func(&is_it_a_separator);
|
|
|
|
c->set_active(0);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererPixbuf>();
|
|
|
|
c->pack_start(*r, false);
|
|
|
|
c->set_cell_data_func(*r, [r](auto const& iter) { render_pixbuf_func(r, iter); });
|
|
|
|
c->add_attribute(r->property_pixbuf(), tracker_filter_cols.pixbuf);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
c->pack_start(*r, false);
|
|
|
|
c->add_attribute(r->property_text(), tracker_filter_cols.name);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
auto* r = number_renderer_new();
|
|
|
|
c->pack_end(*r, true);
|
|
|
|
c->set_cell_data_func(*r, [r](auto const& iter) { render_number_func(r, iter); });
|
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
torrent_model_row_changed_tag_ = tmodel->signal_row_changed().connect(
|
|
|
|
[cat_model](auto const& /*path*/, auto const& /*iter*/) { tracker_model_update_idle(cat_model); });
|
|
|
|
torrent_model_row_inserted_tag_ = tmodel->signal_row_inserted().connect(
|
|
|
|
[cat_model](auto const& /*path*/, auto const& /*iter*/) { tracker_model_update_idle(cat_model); });
|
|
|
|
torrent_model_row_deleted_cb_tag_ = tmodel->signal_row_deleted().connect( //
|
|
|
|
[cat_model](auto const& /*path*/) { tracker_model_update_idle(cat_model); });
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return c;
|
2011-03-25 17:42:47 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool test_tracker(tr_torrent const* tor, int active_tracker_type, Glib::ustring const& host)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool matches = true;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (active_tracker_type == TRACKER_FILTER_TYPE_HOST)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const* const inf = tr_torrentInfo(tor);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
matches = false;
|
2017-05-13 22:38:31 +00:00
|
|
|
|
|
|
|
for (unsigned int i = 0; !matches && i < inf->trackerCount; ++i)
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
matches = gtr_get_host_from_url(inf->trackers[i].announce) == host;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-01 19:45:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return matches;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
2010-03-27 02:52:10 +00:00
|
|
|
**** ACTIVITY
|
2010-03-14 05:13:02 +00:00
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ACTIVITY_FILTER_ALL,
|
|
|
|
ACTIVITY_FILTER_DOWNLOADING,
|
|
|
|
ACTIVITY_FILTER_SEEDING,
|
|
|
|
ACTIVITY_FILTER_ACTIVE,
|
|
|
|
ACTIVITY_FILTER_PAUSED,
|
|
|
|
ACTIVITY_FILTER_FINISHED,
|
|
|
|
ACTIVITY_FILTER_VERIFYING,
|
|
|
|
ACTIVITY_FILTER_ERROR,
|
|
|
|
ACTIVITY_FILTER_SEPARATOR
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
class ActivityFilterModelColumns : public Gtk::TreeModelColumnRecord
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
|
|
|
ActivityFilterModelColumns()
|
|
|
|
{
|
|
|
|
add(name);
|
|
|
|
add(count);
|
|
|
|
add(type);
|
|
|
|
add(icon_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> name;
|
|
|
|
Gtk::TreeModelColumn<int> count;
|
|
|
|
Gtk::TreeModelColumn<int> type;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> icon_name;
|
2010-03-14 05:13:02 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
ActivityFilterModelColumns const activity_filter_cols;
|
2020-08-18 10:36:10 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool activity_is_it_a_separator(Glib::RefPtr<Gtk::TreeModel> const& /*model*/, Gtk::TreeIter const& iter)
|
|
|
|
{
|
|
|
|
return iter->get_value(activity_filter_cols.type) == ACTIVITY_FILTER_SEPARATOR;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool test_torrent_activity(tr_torrent* tor, int type)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const* st = tr_torrentStatCached(tor);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (type)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_DOWNLOADING:
|
2017-04-30 16:25:26 +00:00
|
|
|
return st->activity == TR_STATUS_DOWNLOAD || st->activity == TR_STATUS_DOWNLOAD_WAIT;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_SEEDING:
|
2017-04-30 16:25:26 +00:00
|
|
|
return st->activity == TR_STATUS_SEED || st->activity == TR_STATUS_SEED_WAIT;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_ACTIVE:
|
2017-04-30 16:25:26 +00:00
|
|
|
return st->peersSendingToUs > 0 || st->peersGettingFromUs > 0 || st->webseedsSendingToUs > 0 ||
|
2019-02-10 11:05:16 +00:00
|
|
|
st->activity == TR_STATUS_CHECK;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_PAUSED:
|
2013-01-01 18:43:41 +00:00
|
|
|
return st->activity == TR_STATUS_STOPPED;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_FINISHED:
|
2021-10-18 20:22:31 +00:00
|
|
|
return st->finished == true;
|
2010-08-01 17:43:35 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_VERIFYING:
|
2017-04-30 16:25:26 +00:00
|
|
|
return st->activity == TR_STATUS_CHECK || st->activity == TR_STATUS_CHECK_WAIT;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case ACTIVITY_FILTER_ERROR:
|
2013-01-01 18:43:41 +00:00
|
|
|
return st->error != 0;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default: /* ACTIVITY_FILTER_ALL */
|
2021-10-18 20:22:31 +00:00
|
|
|
return true;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void status_model_update_count(Gtk::TreeIter const& iter, int n)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (n != iter->get_value(activity_filter_cols.count))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
iter->set_value(activity_filter_cols.count, n);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool activity_filter_model_update(Glib::RefPtr<Gtk::ListStore> const& activity_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* tmodel = static_cast<Gtk::TreeModel*>(activity_model->get_data(TORRENT_MODEL_KEY));
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
activity_model->steal_data(DIRTY_KEY);
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto& row : activity_model->children())
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const type = row.get_value(activity_filter_cols.type);
|
|
|
|
auto hits = 0;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const& torrent_row : tmodel->children())
|
|
|
|
{
|
|
|
|
if (test_torrent_activity(static_cast<tr_torrent*>(torrent_row.get_value(torrent_cols.torrent)), type))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
++hits;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
status_model_update_count(row, hits);
|
2013-01-01 18:43:41 +00:00
|
|
|
}
|
2013-02-02 23:01:33 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return false;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::RefPtr<Gtk::ListStore> activity_filter_model_new(Glib::RefPtr<Gtk::TreeModel> const& tmodel)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
static struct
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
int type;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* context;
|
|
|
|
char const* name;
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::ustring icon_name;
|
|
|
|
} const types[] = {
|
|
|
|
{ ACTIVITY_FILTER_ALL, nullptr, N_("All"), {} },
|
|
|
|
{ ACTIVITY_FILTER_SEPARATOR, nullptr, "", {} },
|
2021-10-06 16:32:17 +00:00
|
|
|
{ ACTIVITY_FILTER_ACTIVE, nullptr, N_("Active"), "system-run" },
|
2020-07-27 17:49:45 +00:00
|
|
|
{ ACTIVITY_FILTER_DOWNLOADING, "Verb", NC_("Verb", "Downloading"), "network-receive" },
|
|
|
|
{ ACTIVITY_FILTER_SEEDING, "Verb", NC_("Verb", "Seeding"), "network-transmit" },
|
2021-10-06 16:32:17 +00:00
|
|
|
{ ACTIVITY_FILTER_PAUSED, nullptr, N_("Paused"), "media-playback-pause" },
|
|
|
|
{ ACTIVITY_FILTER_FINISHED, nullptr, N_("Finished"), "media-playback-stop" },
|
2020-07-27 17:49:45 +00:00
|
|
|
{ ACTIVITY_FILTER_VERIFYING, "Verb", NC_("Verb", "Verifying"), "view-refresh" },
|
2021-10-06 16:32:17 +00:00
|
|
|
{ ACTIVITY_FILTER_ERROR, nullptr, N_("Error"), "dialog-error" },
|
2017-04-19 12:04:45 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const store = Gtk::ListStore::create(activity_filter_cols);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const& type : types)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const name = Glib::ustring(
|
|
|
|
type.context != nullptr ? g_dpgettext2(nullptr, type.context, type.name) : _(type.name));
|
|
|
|
auto const iter = store->append();
|
|
|
|
iter->set_value(activity_filter_cols.name, name);
|
|
|
|
iter->set_value(activity_filter_cols.type, type.type);
|
|
|
|
iter->set_value(activity_filter_cols.icon_name, type.icon_name);
|
2012-04-13 14:49:34 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
store->set_data(TORRENT_MODEL_KEY, gtr_get_ptr(tmodel));
|
2017-04-19 12:04:45 +00:00
|
|
|
activity_filter_model_update(store);
|
2021-10-18 20:22:31 +00:00
|
|
|
return store;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void render_activity_pixbuf_func(Gtk::CellRendererPixbuf* cell_renderer, Gtk::TreeModel::iterator const& iter)
|
2010-05-18 14:14:17 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const type = iter->get_value(activity_filter_cols.type);
|
|
|
|
cell_renderer->property_width() = type == ACTIVITY_FILTER_ALL ? 0 : 20;
|
|
|
|
cell_renderer->property_ypad() = type == ACTIVITY_FILTER_ALL ? 0 : 2;
|
2010-05-18 14:14:17 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void activity_model_update_idle(Glib::RefPtr<Gtk::ListStore> const& activity_model)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const pending = activity_model->get_data(DIRTY_KEY) != nullptr;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!pending)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
activity_model->set_data(DIRTY_KEY, GINT_TO_POINTER(1));
|
|
|
|
Glib::signal_idle().connect([activity_model]() { return activity_filter_model_update(activity_model); });
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
2020-08-18 10:36:10 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::ComboBox* FilterBar::Impl::activity_combo_box_new(Glib::RefPtr<Gtk::TreeModel> const& tmodel)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const activity_model = activity_filter_model_new(tmodel);
|
|
|
|
auto* c = Gtk::make_managed<Gtk::ComboBox>(static_cast<Glib::RefPtr<Gtk::TreeModel> const&>(activity_model));
|
|
|
|
c->set_row_separator_func(&activity_is_it_a_separator);
|
|
|
|
c->set_active(0);
|
2020-08-18 10:36:10 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererPixbuf>();
|
|
|
|
c->pack_start(*r, false);
|
|
|
|
c->add_attribute(r->property_icon_name(), activity_filter_cols.icon_name);
|
|
|
|
c->set_cell_data_func(*r, [r](auto const& iter) { render_activity_pixbuf_func(r, iter); });
|
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
c->pack_start(*r, true);
|
|
|
|
c->add_attribute(r->property_text(), activity_filter_cols.name);
|
|
|
|
}
|
2011-03-25 17:42:47 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
auto* r = number_renderer_new();
|
|
|
|
c->pack_end(*r, true);
|
|
|
|
c->set_cell_data_func(*r, [r](auto const& iter) { render_number_func(r, iter); });
|
|
|
|
}
|
|
|
|
|
|
|
|
activity_model_row_changed_tag_ = tmodel->signal_row_changed().connect(
|
|
|
|
[activity_model](auto const& /*path*/, auto const& /*iter*/) { activity_model_update_idle(activity_model); });
|
|
|
|
activity_model_row_inserted_tag_ = tmodel->signal_row_inserted().connect(
|
|
|
|
[activity_model](auto const& /*path*/, auto const& /*iter*/) { activity_model_update_idle(activity_model); });
|
|
|
|
activity_model_row_deleted_cb_tag_ = tmodel->signal_row_deleted().connect( //
|
|
|
|
[activity_model](auto const& /*path*/) { activity_model_update_idle(activity_model); });
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return c;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
***** ENTRY FIELD
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool testText(tr_torrent const* tor, Glib::ustring const* key)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (key == nullptr || key->empty())
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
ret = true;
|
2010-08-06 15:03:25 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2010-08-06 15:03:25 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_info const* inf = tr_torrentInfo(tor);
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* test the torrent name... */
|
2021-10-18 20:22:31 +00:00
|
|
|
ret = Glib::ustring(tr_torrentName(tor)).casefold().find(*key) != Glib::ustring::npos;
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* test the files... */
|
2017-05-13 22:38:31 +00:00
|
|
|
for (tr_file_index_t i = 0; i < inf->fileCount && !ret; ++i)
|
2010-08-06 15:03:25 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
ret = Glib::ustring(inf->files[i].name).casefold().find(*key) != Glib::ustring::npos;
|
2010-08-06 15:03:25 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return ret;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void FilterBar::Impl::filter_entry_changed()
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
filter_model_->set_data(
|
|
|
|
TEXT_KEY,
|
|
|
|
new Glib::ustring(gtr_str_strip(entry_->get_text().casefold())),
|
|
|
|
[](void* p) { delete static_cast<Glib::ustring*>(p); });
|
|
|
|
filter_model_->refilter();
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****
|
|
|
|
******
|
|
|
|
******
|
|
|
|
******
|
|
|
|
*****/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool FilterBar::Impl::is_row_visible(Gtk::TreeModel::const_iterator const& iter)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* tor = static_cast<tr_torrent*>(iter->get_value(torrent_cols.torrent));
|
|
|
|
auto const* text = static_cast<Glib::ustring const*>(filter_model_->get_data(TEXT_KEY));
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return tor != nullptr && test_tracker(tor, active_tracker_type_, active_tracker_host_) &&
|
|
|
|
test_torrent_activity(tor, active_activity_type_) && testText(tor, text);
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void FilterBar::Impl::selection_changed_cb()
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
/* set active_activity_type_ from the activity combobox */
|
|
|
|
if (auto const iter = activity_->get_active(); iter)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
active_activity_type_ = iter->get_value(activity_filter_cols.type);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
active_activity_type_ = ACTIVITY_FILTER_ALL;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set the active tracker type & host from the tracker combobox */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto const iter = tracker_->get_active(); iter)
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
active_tracker_type_ = iter->get_value(tracker_filter_cols.type);
|
|
|
|
active_tracker_host_ = iter->get_value(tracker_filter_cols.host);
|
2013-01-01 18:43:41 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-01 18:43:41 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
active_tracker_type_ = TRACKER_FILTER_TYPE_ALL;
|
|
|
|
active_tracker_host_.clear();
|
2011-04-13 22:04:31 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* refilter */
|
2021-10-18 20:22:31 +00:00
|
|
|
filter_model_->refilter();
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2013-02-01 20:58:55 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool FilterBar::Impl::update_count_label()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
/* get the visible count */
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const visibleCount = static_cast<int>(filter_model_->children().size());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* get the tracker count */
|
2021-10-18 20:22:31 +00:00
|
|
|
int trackerCount;
|
|
|
|
if (auto const iter = tracker_->get_active(); iter)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
trackerCount = iter->get_value(tracker_filter_cols.count);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trackerCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the activity count */
|
2021-10-18 20:22:31 +00:00
|
|
|
int activityCount;
|
|
|
|
if (auto const iter = activity_->get_active(); iter)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
activityCount = iter->get_value(activity_filter_cols.count);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
activityCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the text */
|
2021-10-18 20:22:31 +00:00
|
|
|
show_lb_->set_markup_with_mnemonic(
|
|
|
|
visibleCount == std::min(activityCount, trackerCount) ? _("_Show:") : gtr_sprintf(_("_Show %'d of:"), visibleCount));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
show_lb_->steal_data(DIRTY_KEY);
|
|
|
|
return false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void FilterBar::Impl::update_count_label_idle()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const pending = show_lb_->get_data(DIRTY_KEY) != nullptr;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!pending)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
show_lb_->set_data(DIRTY_KEY, GINT_TO_POINTER(1));
|
|
|
|
Glib::signal_idle().connect(sigc::mem_fun(this, &Impl::update_count_label));
|
2013-02-02 23:01:33 +00:00
|
|
|
}
|
2013-02-01 20:58:55 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2020-08-18 10:36:10 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
FilterBar::FilterBar(tr_session* session, Glib::RefPtr<Gtk::TreeModel> const& tmodel)
|
|
|
|
: Gtk::Box(Gtk::ORIENTATION_HORIZONTAL, GUI_PAD_SMALL)
|
|
|
|
, impl_(std::make_unique<Impl>(*this, session, tmodel))
|
|
|
|
{
|
2013-02-01 20:58:55 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
FilterBar::Impl::Impl(FilterBar& widget, tr_session* session, Glib::RefPtr<Gtk::TreeModel> const& tmodel)
|
|
|
|
: widget_(widget)
|
2013-02-01 20:58:55 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
show_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
activity_ = activity_combo_box_new(tmodel);
|
|
|
|
tracker_ = tracker_combo_box_new(tmodel);
|
|
|
|
filter_model_ = Gtk::TreeModelFilter::create(tmodel);
|
|
|
|
filter_model_->signal_row_deleted().connect([this](auto const& /*path*/) { update_count_label_idle(); });
|
|
|
|
filter_model_->signal_row_inserted().connect([this](auto const& /*path*/, auto const& /*iter*/)
|
|
|
|
{ update_count_label_idle(); });
|
2020-08-18 10:36:10 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
tracker_->property_width_request() = 170;
|
|
|
|
static_cast<Gtk::TreeStore*>(gtr_get_ptr(tracker_->get_model()))->set_data(SESSION_KEY, session);
|
2013-02-01 20:58:55 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
filter_model_->set_visible_func(sigc::mem_fun(this, &Impl::is_row_visible));
|
2013-02-01 20:58:55 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
tracker_->signal_changed().connect(sigc::mem_fun(this, &Impl::selection_changed_cb));
|
|
|
|
activity_->signal_changed().connect(sigc::mem_fun(this, &Impl::selection_changed_cb));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* add the activity combobox */
|
2021-10-18 20:22:31 +00:00
|
|
|
show_lb_->set_mnemonic_widget(*activity_);
|
|
|
|
widget_.pack_start(*show_lb_, false, false, 0);
|
|
|
|
widget_.pack_start(*activity_, true, true, 0);
|
2019-11-06 19:09:27 +00:00
|
|
|
#if GTK_CHECK_VERSION(3, 12, 0)
|
2021-10-18 20:22:31 +00:00
|
|
|
activity_->set_margin_end(GUI_PAD);
|
2019-11-06 19:09:27 +00:00
|
|
|
#else
|
2021-10-18 20:22:31 +00:00
|
|
|
activity_->set_margin_right(GUI_PAD);
|
2019-11-06 19:09:27 +00:00
|
|
|
#endif
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* add the tracker combobox */
|
2021-10-18 20:22:31 +00:00
|
|
|
widget_.pack_start(*tracker_, true, true, 0);
|
2019-11-06 19:09:27 +00:00
|
|
|
#if GTK_CHECK_VERSION(3, 12, 0)
|
2021-10-18 20:22:31 +00:00
|
|
|
tracker_->set_margin_end(GUI_PAD);
|
2019-11-06 19:09:27 +00:00
|
|
|
#else
|
2021-10-18 20:22:31 +00:00
|
|
|
tracker_->set_margin_right(GUI_PAD);
|
2019-11-06 19:09:27 +00:00
|
|
|
#endif
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* add the entry field */
|
2021-10-18 20:22:31 +00:00
|
|
|
entry_ = Gtk::make_managed<Gtk::Entry>();
|
|
|
|
entry_->set_icon_from_icon_name("edit-clear", Gtk::ENTRY_ICON_SECONDARY);
|
|
|
|
entry_->signal_icon_release().connect([this](auto /*icon_position*/, auto const* /*event*/) { entry_->set_text({}); });
|
|
|
|
widget_.pack_start(*entry_, true, true, 0);
|
|
|
|
|
|
|
|
entry_->signal_changed().connect(sigc::mem_fun(this, &Impl::filter_entry_changed));
|
|
|
|
selection_changed_cb();
|
|
|
|
|
|
|
|
update_count_label();
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterBar::~FilterBar() = default;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
FilterBar::Impl::~Impl()
|
|
|
|
{
|
|
|
|
torrent_model_row_deleted_cb_tag_.disconnect();
|
|
|
|
torrent_model_row_inserted_tag_.disconnect();
|
|
|
|
torrent_model_row_changed_tag_.disconnect();
|
|
|
|
|
|
|
|
activity_model_row_deleted_cb_tag_.disconnect();
|
|
|
|
activity_model_row_inserted_tag_.disconnect();
|
|
|
|
activity_model_row_changed_tag_.disconnect();
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::RefPtr<Gtk::TreeModel> FilterBar::get_filter_model() const
|
|
|
|
{
|
|
|
|
return impl_->get_filter_model();
|
|
|
|
}
|
|
|
|
|
|
|
|
Glib::RefPtr<Gtk::TreeModel> FilterBar::Impl::get_filter_model() const
|
|
|
|
{
|
|
|
|
return filter_model_;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|