2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "FilterBar.h"
|
2022-10-15 16:13:50 +00:00
|
|
|
|
2023-01-08 15:31:03 +00:00
|
|
|
#include "FilterListModel.hh"
|
2022-09-07 22:25:04 +00:00
|
|
|
#include "HigWorkarea.h" // GUI_PAD
|
2022-12-21 21:26:25 +00:00
|
|
|
#include "ListModelAdapter.h"
|
2022-09-07 22:25:04 +00:00
|
|
|
#include "Session.h" // torrent_cols
|
2022-12-21 21:26:25 +00:00
|
|
|
#include "Torrent.h"
|
|
|
|
#include "TorrentFilter.h"
|
2022-02-12 17:30:27 +00:00
|
|
|
#include "Utils.h"
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <gdkmm/pixbuf.h>
|
2022-12-26 21:13:21 +00:00
|
|
|
#include <glibmm/i18n.h>
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <glibmm/main.h>
|
|
|
|
#include <glibmm/unicode.h>
|
|
|
|
#include <glibmm/ustring.h>
|
|
|
|
#include <gtkmm/cellrendererpixbuf.h>
|
|
|
|
#include <gtkmm/cellrenderertext.h>
|
|
|
|
#include <gtkmm/combobox.h>
|
|
|
|
#include <gtkmm/entry.h>
|
|
|
|
#include <gtkmm/label.h>
|
|
|
|
#include <gtkmm/liststore.h>
|
|
|
|
#include <gtkmm/treemodel.h>
|
|
|
|
#include <gtkmm/treemodelcolumn.h>
|
|
|
|
#include <gtkmm/treemodelfilter.h>
|
|
|
|
#include <gtkmm/treerowreference.h>
|
|
|
|
#include <gtkmm/treestore.h>
|
|
|
|
|
|
|
|
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
|
|
|
#include <gtkmm/filterlistmodel.h>
|
|
|
|
#else
|
|
|
|
#include <gtkmm/treemodelfilter.h>
|
|
|
|
#endif
|
2022-12-26 21:13:21 +00:00
|
|
|
|
|
|
|
#include <fmt/core.h>
|
|
|
|
|
|
|
|
#include <algorithm> // std::transform()
|
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2024-01-08 14:32:58 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
using ActivityType = TorrentFilter::Activity;
|
|
|
|
using TrackerType = TorrentFilter::Tracker;
|
|
|
|
|
|
|
|
constexpr auto ActivitySeparator = static_cast<ActivityType>(-1);
|
|
|
|
constexpr auto TrackerSeparator = static_cast<TrackerType>(-1);
|
|
|
|
} // namespace
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
class FilterBar::Impl
|
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
using FilterModel = IF_GTKMM4(Gtk::FilterListModel, Gtk::TreeModelFilter);
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
2022-12-21 21:26:25 +00:00
|
|
|
Impl(FilterBar& widget, Glib::RefPtr<Session> const& core);
|
2021-10-18 20:22:31 +00:00
|
|
|
~Impl();
|
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(Impl)
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
[[nodiscard]] Glib::RefPtr<FilterModel> get_filter_model() const;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
private:
|
2022-09-07 22:25:04 +00:00
|
|
|
template<typename T>
|
|
|
|
T* get_template_child(char const* name) const;
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
void activity_combo_box_init(Gtk::ComboBox& combo);
|
|
|
|
static void render_activity_pixbuf_func(Gtk::CellRendererPixbuf& cell_renderer, Gtk::TreeModel::const_iterator const& iter);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
void tracker_combo_box_init(Gtk::ComboBox& combo);
|
|
|
|
static void render_pixbuf_func(Gtk::CellRendererPixbuf& cell_renderer, Gtk::TreeModel::const_iterator const& iter);
|
|
|
|
static void render_number_func(Gtk::CellRendererText& cell_renderer, Gtk::TreeModel::const_iterator const& iter);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
void update_filter_activity();
|
|
|
|
void update_filter_tracker();
|
|
|
|
void update_filter_text();
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
bool activity_filter_model_update();
|
|
|
|
|
|
|
|
bool tracker_filter_model_update();
|
2023-04-23 02:11:16 +00:00
|
|
|
void favicon_ready_cb(Glib::RefPtr<Gdk::Pixbuf> const* pixbuf, Gtk::TreeModel::Path const& path);
|
2022-11-15 00:53:12 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
void update_filter_models(Torrent::ChangeFlags changes);
|
|
|
|
void update_filter_models_idle(Torrent::ChangeFlags changes);
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
void update_count_label_idle();
|
|
|
|
bool update_count_label();
|
|
|
|
|
2022-12-28 14:47:53 +00:00
|
|
|
static Glib::RefPtr<Gtk::ListStore> activity_filter_model_new();
|
|
|
|
static void status_model_update_count(Gtk::TreeModel::iterator const& iter, int n);
|
|
|
|
static bool activity_is_it_a_separator(Gtk::TreeModel::const_iterator const& iter);
|
|
|
|
|
|
|
|
static Glib::RefPtr<Gtk::TreeStore> tracker_filter_model_new();
|
|
|
|
static void tracker_model_update_count(Gtk::TreeModel::iterator const& iter, int n);
|
|
|
|
static bool is_it_a_separator(Gtk::TreeModel::const_iterator const& iter);
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
static Glib::ustring get_name_from_host(std::string const& host);
|
|
|
|
|
|
|
|
static Gtk::CellRendererText* number_renderer_new();
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
private:
|
|
|
|
FilterBar& widget_;
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<Session> const core_;
|
2022-11-15 00:53:12 +00:00
|
|
|
|
|
|
|
Glib::RefPtr<Gtk::ListStore> const activity_model_;
|
|
|
|
Glib::RefPtr<Gtk::TreeStore> const tracker_model_;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
Gtk::ComboBox* activity_ = nullptr;
|
|
|
|
Gtk::ComboBox* tracker_ = nullptr;
|
|
|
|
Gtk::Entry* entry_ = nullptr;
|
|
|
|
Gtk::Label* show_lb_ = nullptr;
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<TorrentFilter> filter_ = TorrentFilter::create();
|
2023-01-08 15:31:03 +00:00
|
|
|
Glib::RefPtr<FilterListModel<Torrent>> filter_model_;
|
2022-10-08 22:50:03 +00:00
|
|
|
|
|
|
|
sigc::connection update_count_label_tag_;
|
2022-12-21 21:26:25 +00:00
|
|
|
sigc::connection update_filter_models_tag_;
|
|
|
|
sigc::connection update_filter_models_on_add_remove_tag_;
|
|
|
|
sigc::connection update_filter_models_on_change_tag_;
|
2021-10-18 20:22:31 +00:00
|
|
|
};
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2024-01-08 14:32:58 +00:00
|
|
|
// --- TRACKERS
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class TrackerFilterModelColumns : public Gtk::TreeModelColumnRecord
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
2022-11-15 00:53:12 +00:00
|
|
|
TrackerFilterModelColumns() noexcept
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-02-12 17:30:27 +00:00
|
|
|
add(displayname);
|
2021-10-18 20:22:31 +00:00
|
|
|
add(count);
|
|
|
|
add(type);
|
2022-02-12 17:30:27 +00:00
|
|
|
add(sitename);
|
2021-10-18 20:22:31 +00:00
|
|
|
add(pixbuf);
|
|
|
|
}
|
|
|
|
|
2022-02-12 17:30:27 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> displayname; /* human-readable name; ie, Legaltorrents */
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<int> count; /* how many matches there are */
|
2024-01-08 14:32:58 +00:00
|
|
|
Gtk::TreeModelColumn<TrackerType> type;
|
2022-02-12 17:30:27 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> sitename; // pattern-matching text; see tr_parsed_url.sitename
|
2021-10-18 20:22:31 +00:00
|
|
|
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
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
} // namespace
|
|
|
|
|
2010-03-15 14:35:43 +00:00
|
|
|
/* human-readable name; ie, Legaltorrents */
|
2022-11-15 00:53:12 +00:00
|
|
|
Glib::ustring FilterBar::Impl::get_name_from_host(std::string const& host)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2022-02-12 17:30:27 +00:00
|
|
|
std::string name = host;
|
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
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
void FilterBar::Impl::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
|
|
|
}
|
|
|
|
|
2023-04-23 02:11:16 +00:00
|
|
|
void FilterBar::Impl::favicon_ready_cb(Glib::RefPtr<Gdk::Pixbuf> const* pixbuf, Gtk::TreeModel::Path const& path)
|
2010-03-15 02:53:31 +00:00
|
|
|
{
|
2023-04-23 02:11:16 +00:00
|
|
|
if (pixbuf != nullptr && *pixbuf != nullptr)
|
2010-03-15 02:53:31 +00:00
|
|
|
{
|
2022-12-28 14:47:53 +00:00
|
|
|
if (auto const iter = tracker_model_->get_iter(path); iter)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2023-04-23 02:11:16 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
bool FilterBar::Impl::tracker_filter_model_update()
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2022-02-12 17:30:27 +00:00
|
|
|
struct site_info
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
std::string host;
|
|
|
|
std::string sitename;
|
2023-04-23 02:11:16 +00:00
|
|
|
std::string announce_url;
|
2022-02-12 17:30:27 +00:00
|
|
|
|
|
|
|
bool operator<(site_info const& that) const
|
|
|
|
{
|
|
|
|
return sitename < that.sitename;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const torrents_model = core_->get_model();
|
|
|
|
|
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 */
|
2022-02-12 17:30:27 +00:00
|
|
|
auto n_torrents = int{ 0 };
|
|
|
|
auto site_infos = std::unordered_map<std::string /*site*/, site_info>{};
|
2022-12-21 21:26:25 +00:00
|
|
|
for (auto i = 0U, count = torrents_model->get_n_items(); i < count; ++i)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const torrent = gtr_ptr_dynamic_cast<Torrent>(torrents_model->get_object(i));
|
|
|
|
if (torrent == nullptr)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto const& raw_torrent = torrent->get_underlying();
|
2020-11-04 00:59:19 +00:00
|
|
|
|
2023-04-23 02:11:16 +00:00
|
|
|
auto site_to_host_and_announce = std::map<std::string, std::pair<std::string, std::string>>{};
|
2022-12-21 21:26:25 +00:00
|
|
|
for (size_t j = 0, n = tr_torrentTrackerCount(&raw_torrent); j < n; ++j)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const view = tr_torrentTracker(&raw_torrent, j);
|
2023-05-09 01:28:10 +00:00
|
|
|
site_to_host_and_announce.try_emplace(std::data(view.sitename), view.host_and_port, view.announce);
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2023-04-23 02:11:16 +00:00
|
|
|
for (auto const& [sitename, host_and_announce] : site_to_host_and_announce)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-02-12 17:30:27 +00:00
|
|
|
auto& info = site_infos[sitename];
|
2023-04-23 02:11:16 +00:00
|
|
|
info.host = host_and_announce.first;
|
|
|
|
info.announce_url = host_and_announce.second;
|
2022-02-12 17:30:27 +00:00
|
|
|
info.sitename = sitename;
|
|
|
|
++info.count;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2022-02-12 17:30:27 +00:00
|
|
|
++n_torrents;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2022-02-12 17:30:27 +00:00
|
|
|
auto const n_sites = std::size(site_infos);
|
|
|
|
auto sites_v = std::vector<site_info>(n_sites);
|
|
|
|
std::transform(std::begin(site_infos), std::end(site_infos), std::begin(sites_v), [](auto const& it) { return it.second; });
|
|
|
|
std::sort(std::begin(sites_v), std::end(sites_v));
|
2013-01-01 18:43:41 +00:00
|
|
|
|
2020-11-04 00:59:19 +00:00
|
|
|
// update the "all" count
|
2022-11-15 00:53:12 +00:00
|
|
|
auto iter = tracker_model_->children().begin();
|
2021-10-18 20:22:31 +00:00
|
|
|
if (iter)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-02-12 17:30:27 +00:00
|
|
|
tracker_model_update_count(iter, n_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?
|
2022-02-12 17:30:27 +00:00
|
|
|
bool const new_sites_done = i >= n_sites;
|
|
|
|
bool const old_sites_done = !iter;
|
|
|
|
if (new_sites_done && old_sites_done)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
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;
|
2022-02-12 17:30:27 +00:00
|
|
|
if (new_sites_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
|
|
|
}
|
2022-02-12 17:30:27 +00:00
|
|
|
else if (old_sites_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
|
|
|
{
|
2022-02-12 17:30:27 +00:00
|
|
|
auto const sitename = iter->get_value(tracker_filter_cols.sitename);
|
2022-10-08 22:50:03 +00:00
|
|
|
int const cmp = sitename.raw().compare(sites_v.at(i).sitename);
|
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
|
|
|
{
|
2022-11-15 00:53:12 +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
|
|
|
{
|
2022-02-12 17:30:27 +00:00
|
|
|
auto const& site = sites_v.at(i);
|
2022-11-15 00:53:12 +00:00
|
|
|
auto const add = tracker_model_->insert(iter);
|
2022-02-12 17:30:27 +00:00
|
|
|
add->set_value(tracker_filter_cols.sitename, Glib::ustring{ site.sitename });
|
|
|
|
add->set_value(tracker_filter_cols.displayname, get_name_from_host(site.sitename));
|
|
|
|
add->set_value(tracker_filter_cols.count, site.count);
|
2024-01-08 14:32:58 +00:00
|
|
|
add->set_value(tracker_filter_cols.type, TrackerType::HOST);
|
2022-11-15 00:53:12 +00:00
|
|
|
auto path = tracker_model_->get_path(add);
|
2023-04-23 02:11:16 +00:00
|
|
|
core_->favicon_cache().load(
|
|
|
|
site.announce_url,
|
2023-08-22 02:59:47 +00:00
|
|
|
[this, path = std::move(path)](auto const* pixbuf) { favicon_ready_cb(pixbuf, path); });
|
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
|
|
|
{
|
2022-02-12 17:30:27 +00:00
|
|
|
tracker_model_update_count(iter, sites_v.at(i).count);
|
2021-10-18 20:22:31 +00:00
|
|
|
++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
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
Glib::RefPtr<Gtk::TreeStore> FilterBar::Impl::tracker_filter_model_new()
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2022-11-13 20:50:07 +00:00
|
|
|
auto store = Gtk::TreeStore::create(tracker_filter_cols);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
auto iter = store->append();
|
2022-02-12 17:30:27 +00:00
|
|
|
iter->set_value(tracker_filter_cols.displayname, Glib::ustring(_("All")));
|
2024-01-08 14:32:58 +00:00
|
|
|
iter->set_value(tracker_filter_cols.type, TrackerType::ALL);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
iter = store->append();
|
2024-01-08 14:32:58 +00:00
|
|
|
iter->set_value(tracker_filter_cols.type, TrackerSeparator);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
return store;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
bool FilterBar::Impl::is_it_a_separator(Gtk::TreeModel::const_iterator const& iter)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2024-01-08 14:32:58 +00:00
|
|
|
return iter->get_value(tracker_filter_cols.type) == TrackerSeparator;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
void FilterBar::Impl::render_pixbuf_func(Gtk::CellRendererPixbuf& cell_renderer, Gtk::TreeModel::const_iterator const& iter)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
cell_renderer.property_width() = TrackerType{ iter->get_value(tracker_filter_cols.type) } == TrackerType::HOST ? 20 : 0;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
void FilterBar::Impl::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);
|
2022-11-15 00:53:12 +00:00
|
|
|
cell_renderer.property_text() = count >= 0 ? fmt::format("{:L}", count) : "";
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
Gtk::CellRendererText* FilterBar::Impl::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
|
|
|
|
2022-09-10 13:19:54 +00:00
|
|
|
r->property_alignment() = TR_PANGO_ALIGNMENT(RIGHT);
|
|
|
|
r->property_weight() = TR_PANGO_WEIGHT(ULTRALIGHT);
|
2021-10-18 20:22:31 +00:00
|
|
|
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
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
void FilterBar::Impl::tracker_combo_box_init(Gtk::ComboBox& combo)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-11-15 00:53:12 +00:00
|
|
|
combo.set_model(tracker_model_);
|
2022-12-28 14:47:53 +00:00
|
|
|
combo.set_row_separator_func(sigc::hide<0>(&Impl::is_it_a_separator));
|
2022-11-15 00:53:12 +00:00
|
|
|
combo.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>();
|
2022-11-15 00:53:12 +00:00
|
|
|
combo.pack_start(*r, false);
|
|
|
|
combo.set_cell_data_func(*r, [r](auto const& iter) { render_pixbuf_func(*r, iter); });
|
|
|
|
combo.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>();
|
2022-11-15 00:53:12 +00:00
|
|
|
combo.pack_start(*r, false);
|
|
|
|
combo.add_attribute(r->property_text(), tracker_filter_cols.displayname);
|
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();
|
2022-11-15 00:53:12 +00:00
|
|
|
combo.pack_end(*r, true);
|
|
|
|
combo.set_cell_data_func(*r, [r](auto const& iter) { render_number_func(*r, iter); });
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
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
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
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:
|
2022-11-15 00:53:12 +00:00
|
|
|
ActivityFilterModelColumns() noexcept
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
add(name);
|
|
|
|
add(count);
|
|
|
|
add(type);
|
|
|
|
add(icon_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> name;
|
|
|
|
Gtk::TreeModelColumn<int> count;
|
2024-01-08 14:32:58 +00:00
|
|
|
Gtk::TreeModelColumn<ActivityType> type;
|
2021-10-18 20:22:31 +00:00
|
|
|
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
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
bool FilterBar::Impl::activity_is_it_a_separator(Gtk::TreeModel::const_iterator const& iter)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2024-01-08 14:32:58 +00:00
|
|
|
return iter->get_value(activity_filter_cols.type) == ActivitySeparator;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
void FilterBar::Impl::status_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(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
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
bool FilterBar::Impl::activity_filter_model_update()
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const torrents_model = core_->get_model();
|
|
|
|
|
2022-11-15 00:53:12 +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);
|
2024-01-08 14:32:58 +00:00
|
|
|
if (type == ActivitySeparator)
|
2022-12-21 21:26:25 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto hits = 0;
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
for (auto i = 0U, count = torrents_model->get_n_items(); i < count; ++i)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const torrent = gtr_ptr_dynamic_cast<Torrent>(torrents_model->get_object(i));
|
2023-08-06 03:26:29 +00:00
|
|
|
if (torrent != nullptr && TorrentFilter::match_activity(*torrent, static_cast<ActivityType>(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
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
status_model_update_count(TR_GTK_TREE_MODEL_CHILD_ITER(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
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
Glib::RefPtr<Gtk::ListStore> FilterBar::Impl::activity_filter_model_new()
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2022-11-10 19:35:31 +00:00
|
|
|
struct FilterTypeInfo
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
ActivityType type;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* context;
|
|
|
|
char const* name;
|
2022-12-21 21:26:25 +00:00
|
|
|
char const* icon_name;
|
2022-11-10 19:35:31 +00:00
|
|
|
};
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
static auto constexpr types = std::array<FilterTypeInfo, 9>({ {
|
|
|
|
{ ActivityType::ALL, nullptr, N_("All"), nullptr },
|
|
|
|
{ ActivityType{ -1 }, nullptr, nullptr, nullptr },
|
|
|
|
{ ActivityType::ACTIVE, nullptr, N_("Active"), "system-run" },
|
|
|
|
{ ActivityType::DOWNLOADING, "Verb", NC_("Verb", "Downloading"), "network-receive" },
|
|
|
|
{ ActivityType::SEEDING, "Verb", NC_("Verb", "Seeding"), "network-transmit" },
|
|
|
|
{ ActivityType::PAUSED, nullptr, N_("Paused"), "media-playback-pause" },
|
|
|
|
{ ActivityType::FINISHED, nullptr, N_("Finished"), "media-playback-stop" },
|
|
|
|
{ ActivityType::VERIFYING, "Verb", NC_("Verb", "Verifying"), "view-refresh" },
|
|
|
|
{ ActivityType::ERROR, nullptr, N_("Error"), "dialog-error" },
|
2022-11-10 19:35:31 +00:00
|
|
|
} });
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-11-13 20:50:07 +00:00
|
|
|
auto 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-11-15 14:25:11 +00:00
|
|
|
auto const name = type.name != nullptr ?
|
|
|
|
Glib::ustring(type.context != nullptr ? g_dpgettext2(nullptr, type.context, type.name) : _(type.name)) :
|
|
|
|
Glib::ustring();
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const iter = store->append();
|
|
|
|
iter->set_value(activity_filter_cols.name, name);
|
2024-01-08 14:32:58 +00:00
|
|
|
iter->set_value(activity_filter_cols.type, type.type);
|
2022-12-21 21:26:25 +00:00
|
|
|
iter->set_value(activity_filter_cols.icon_name, Glib::ustring(type.icon_name != nullptr ? 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
|
|
|
return store;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
void FilterBar::Impl::render_activity_pixbuf_func(
|
|
|
|
Gtk::CellRendererPixbuf& cell_renderer,
|
|
|
|
Gtk::TreeModel::const_iterator const& iter)
|
2010-05-18 14:14:17 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
auto const type = ActivityType{ iter->get_value(activity_filter_cols.type) };
|
|
|
|
cell_renderer.property_width() = type == ActivityType::ALL ? 0 : 20;
|
|
|
|
cell_renderer.property_ypad() = type == ActivityType::ALL ? 0 : 2;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
void FilterBar::Impl::activity_combo_box_init(Gtk::ComboBox& combo)
|
2010-03-14 05:13:02 +00:00
|
|
|
{
|
2022-11-15 00:53:12 +00:00
|
|
|
combo.set_model(activity_model_);
|
2022-12-28 14:47:53 +00:00
|
|
|
combo.set_row_separator_func(sigc::hide<0>(&Impl::activity_is_it_a_separator));
|
2022-11-15 00:53:12 +00:00
|
|
|
combo.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>();
|
2022-11-15 00:53:12 +00:00
|
|
|
combo.pack_start(*r, false);
|
|
|
|
combo.add_attribute(r->property_icon_name(), activity_filter_cols.icon_name);
|
|
|
|
combo.set_cell_data_func(*r, [r](auto const& iter) { render_activity_pixbuf_func(*r, iter); });
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
2022-11-15 00:53:12 +00:00
|
|
|
combo.pack_start(*r, true);
|
|
|
|
combo.add_attribute(r->property_text(), activity_filter_cols.name);
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2011-03-25 17:42:47 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
auto* r = number_renderer_new();
|
2022-11-15 00:53:12 +00:00
|
|
|
combo.pack_end(*r, true);
|
|
|
|
combo.set_cell_data_func(*r, [r](auto const& iter) { render_number_func(*r, iter); });
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
void FilterBar::Impl::update_filter_text()
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
filter_->set_text(entry_->get_text());
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
void FilterBar::Impl::update_filter_activity()
|
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
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
filter_->set_activity(ActivityType{ iter->get_value(activity_filter_cols.type) });
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
filter_->set_activity(ActivityType::ALL);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2022-12-21 21:26:25 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
void FilterBar::Impl::update_filter_tracker()
|
|
|
|
{
|
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
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
filter_->set_tracker(
|
|
|
|
static_cast<TrackerType>(iter->get_value(tracker_filter_cols.type)),
|
|
|
|
iter->get_value(tracker_filter_cols.sitename));
|
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
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
filter_->set_tracker(TrackerType::ALL, {});
|
2011-04-13 22:04:31 +00:00
|
|
|
}
|
2010-03-14 05:13:02 +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 */
|
2023-01-08 15:31:03 +00:00
|
|
|
auto const visibleCount = static_cast<int>(filter_model_->get_n_items());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* get the tracker count */
|
2022-11-13 17:36:16 +00:00
|
|
|
int trackerCount = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* get the activity count */
|
2022-11-13 17:36:16 +00:00
|
|
|
int activityCount = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* set the text */
|
2023-01-30 23:25:23 +00:00
|
|
|
if (auto const new_markup = visibleCount == std::min(activityCount, trackerCount) ?
|
2022-03-21 14:15:48 +00:00
|
|
|
_("_Show:") :
|
2023-01-30 23:25:23 +00:00
|
|
|
fmt::format(_("_Show {count:L} of:"), fmt::arg("count", visibleCount));
|
|
|
|
new_markup != show_lb_->get_label().raw())
|
|
|
|
{
|
|
|
|
show_lb_->set_markup_with_mnemonic(new_markup);
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
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
|
|
|
{
|
2022-11-15 00:53:12 +00:00
|
|
|
if (!update_count_label_tag_.connected())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-10-08 22:50:03 +00:00
|
|
|
update_count_label_tag_ = 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
|
|
|
}
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
void FilterBar::Impl::update_filter_models(Torrent::ChangeFlags changes)
|
|
|
|
{
|
|
|
|
static auto constexpr activity_flags = Torrent::ChangeFlag::ACTIVE_PEERS_DOWN | Torrent::ChangeFlag::ACTIVE_PEERS_UP |
|
|
|
|
Torrent::ChangeFlag::ACTIVE | Torrent::ChangeFlag::ACTIVITY | Torrent::ChangeFlag::ERROR_CODE |
|
|
|
|
Torrent::ChangeFlag::FINISHED;
|
|
|
|
static auto constexpr tracker_flags = Torrent::ChangeFlag::TRACKERS;
|
|
|
|
|
|
|
|
if (changes.test(activity_flags))
|
|
|
|
{
|
|
|
|
activity_filter_model_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changes.test(tracker_flags))
|
|
|
|
{
|
|
|
|
tracker_filter_model_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
filter_->update(changes);
|
2023-01-30 23:25:23 +00:00
|
|
|
|
|
|
|
if (changes.test(activity_flags | tracker_flags))
|
|
|
|
{
|
|
|
|
update_count_label_idle();
|
|
|
|
}
|
2022-12-21 21:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FilterBar::Impl::update_filter_models_idle(Torrent::ChangeFlags changes)
|
|
|
|
{
|
|
|
|
if (!update_filter_models_tag_.connected())
|
|
|
|
{
|
|
|
|
update_filter_models_tag_ = Glib::signal_idle().connect(
|
|
|
|
[this, changes]()
|
|
|
|
{
|
|
|
|
update_filter_models(changes);
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
2020-08-18 10:36:10 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
FilterBarExtraInit::FilterBarExtraInit()
|
|
|
|
: ExtraClassInit(&FilterBarExtraInit::class_init, nullptr, &FilterBarExtraInit::instance_init)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilterBarExtraInit::class_init(void* klass, void* /*user_data*/)
|
|
|
|
{
|
|
|
|
auto* const widget_klass = GTK_WIDGET_CLASS(klass);
|
|
|
|
|
|
|
|
gtk_widget_class_set_template_from_resource(widget_klass, gtr_get_full_resource_path("FilterBar.ui").c_str());
|
|
|
|
|
|
|
|
gtk_widget_class_bind_template_child_full(widget_klass, "activity_combo", FALSE, 0);
|
|
|
|
gtk_widget_class_bind_template_child_full(widget_klass, "tracker_combo", FALSE, 0);
|
|
|
|
gtk_widget_class_bind_template_child_full(widget_klass, "text_entry", FALSE, 0);
|
|
|
|
gtk_widget_class_bind_template_child_full(widget_klass, "show_label", FALSE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilterBarExtraInit::instance_init(GTypeInstance* instance, void* /*klass*/)
|
|
|
|
{
|
|
|
|
gtk_widget_init_template(GTK_WIDGET(instance));
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
FilterBar::FilterBar()
|
|
|
|
: Glib::ObjectBase(typeid(FilterBar))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FilterBar::FilterBar(
|
|
|
|
BaseObjectType* cast_item,
|
|
|
|
Glib::RefPtr<Gtk::Builder> const& /*builder*/,
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<Session> const& core)
|
2022-09-07 22:25:04 +00:00
|
|
|
: Glib::ObjectBase(typeid(FilterBar))
|
|
|
|
, Gtk::Box(cast_item)
|
2022-12-21 21:26:25 +00:00
|
|
|
, impl_(std::make_unique<Impl>(*this, core))
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2013-02-01 20:58:55 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
FilterBar::~FilterBar() = default;
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
FilterBar::Impl::Impl(FilterBar& widget, Glib::RefPtr<Session> const& core)
|
2021-10-18 20:22:31 +00:00
|
|
|
: widget_(widget)
|
2022-12-21 21:26:25 +00:00
|
|
|
, core_(core)
|
2022-11-15 00:53:12 +00:00
|
|
|
, activity_model_(activity_filter_model_new())
|
|
|
|
, tracker_model_(tracker_filter_model_new())
|
2022-09-07 22:25:04 +00:00
|
|
|
, activity_(get_template_child<Gtk::ComboBox>("activity_combo"))
|
|
|
|
, tracker_(get_template_child<Gtk::ComboBox>("tracker_combo"))
|
|
|
|
, entry_(get_template_child<Gtk::Entry>("text_entry"))
|
|
|
|
, show_lb_(get_template_child<Gtk::Label>("show_label"))
|
2013-02-01 20:58:55 +00:00
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
update_filter_models_on_add_remove_tag_ = core_->get_model()->signal_items_changed().connect(
|
|
|
|
[this](guint /*position*/, guint /*removed*/, guint /*added*/) { update_filter_models_idle(~Torrent::ChangeFlags()); });
|
|
|
|
update_filter_models_on_change_tag_ = core_->signal_torrents_changed().connect(
|
|
|
|
sigc::hide<0>(sigc::mem_fun(*this, &Impl::update_filter_models_idle)));
|
|
|
|
|
2022-11-15 00:53:12 +00:00
|
|
|
activity_filter_model_update();
|
|
|
|
tracker_filter_model_update();
|
|
|
|
|
|
|
|
activity_combo_box_init(*activity_);
|
|
|
|
tracker_combo_box_init(*tracker_);
|
2022-09-07 22:25:04 +00:00
|
|
|
|
2023-01-30 23:25:23 +00:00
|
|
|
filter_->signal_changed().connect([this](auto /*changes*/) { update_count_label_idle(); });
|
|
|
|
|
2023-01-08 15:31:03 +00:00
|
|
|
filter_model_ = FilterListModel<Torrent>::create(core_->get_sorted_model(), filter_);
|
2013-02-01 20:58:55 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
tracker_->signal_changed().connect(sigc::mem_fun(*this, &Impl::update_filter_tracker));
|
|
|
|
activity_->signal_changed().connect(sigc::mem_fun(*this, &Impl::update_filter_activity));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
|
|
|
entry_->signal_icon_release().connect([this](auto /*icon_position*/) { entry_->set_text({}); });
|
|
|
|
#else
|
2021-10-18 20:22:31 +00:00
|
|
|
entry_->signal_icon_release().connect([this](auto /*icon_position*/, auto const* /*event*/) { entry_->set_text({}); });
|
2022-10-08 22:50:03 +00:00
|
|
|
#endif
|
2022-12-21 21:26:25 +00:00
|
|
|
entry_->signal_changed().connect(sigc::mem_fun(*this, &Impl::update_filter_text));
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FilterBar::Impl::~Impl()
|
|
|
|
{
|
2022-12-21 21:26:25 +00:00
|
|
|
update_filter_models_on_change_tag_.disconnect();
|
|
|
|
update_filter_models_on_add_remove_tag_.disconnect();
|
|
|
|
update_filter_models_tag_.disconnect();
|
2022-11-15 00:53:12 +00:00
|
|
|
update_count_label_tag_.disconnect();
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<FilterBar::Model> FilterBar::get_filter_model() const
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
return impl_->get_filter_model();
|
|
|
|
}
|
|
|
|
|
2022-12-21 21:26:25 +00:00
|
|
|
Glib::RefPtr<FilterBar::Impl::FilterModel> FilterBar::Impl::get_filter_model() const
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
return filter_model_;
|
2010-03-14 05:13:02 +00:00
|
|
|
}
|
2022-09-07 22:25:04 +00:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
T* FilterBar::Impl::get_template_child(char const* name) const
|
|
|
|
{
|
|
|
|
auto full_type_name = std::string("gtkmm__CustomObject_");
|
|
|
|
Glib::append_canonical_typename(full_type_name, typeid(FilterBar).name());
|
|
|
|
|
2022-11-13 17:36:16 +00:00
|
|
|
return Glib::wrap(G_TYPE_CHECK_INSTANCE_CAST(
|
|
|
|
gtk_widget_get_template_child(GTK_WIDGET(widget_.gobj()), g_type_from_name(full_type_name.c_str()), name),
|
|
|
|
T::get_base_type(),
|
|
|
|
typename T::BaseObjectType));
|
2022-09-07 22:25:04 +00:00
|
|
|
}
|