Files
transmission/gtk/TorrentFilter.h
Mike Gelfand 32531fe5ef Use Gio::List{Model,Store} for torrents (#4430)
* Use `Gio::List{Model,Store}` for torrents

Switch from `Gtk::{TreeModel,ListStore}` in preparation for cell
renderers deprecation in GTK 4.10. That will require switching to the
new view classes (`Gtk::{Column,List}View`) which only work with `Gio`
models. Implement an adapter to support GTK+ 3 where the old view class
(`Gtk::TreeView`) only works with `Gtk` models; it is effective enough
but requires a signal connection per item to notify on row changes.

Refactor filtering and sorting (which now happen over the new model) to
use compatible `Gtk::Filter` and `Gtk::Sorter` classes. Although these
classes are only present in GTK 4, the abstraction is suitable for GTK+
3 as well so make our subclasses work for both versions.

Since items (of `Torrent` class) of the new model provide only a very
limited (by design) layer of compatibility with GTK+ 3 way of doing
things, refactor selection handling to do it the new way. Move selection
helpers into `MainWindow` to abstract them away since new view classes
handle it differently.

* Improve session load performance based on profiling results
2022-12-21 21:26:25 +00:00

87 lines
2.0 KiB
C++

// This file Copyright © 2022 Mnemosyne LLC.
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#pragma once
#include <gtkmm.h>
#include "Utils.h"
class Torrent;
class TorrentFilter : public IF_GTKMM4(Gtk::Filter, Glib::Object)
{
#if !GTKMM_CHECK_VERSION(4, 0, 0)
enum class Change{
DIFFERENT,
LESS_STRICT,
MORE_STRICT,
};
#endif
public:
enum class Activity
{
ALL,
DOWNLOADING,
SEEDING,
ACTIVE,
PAUSED,
FINISHED,
VERIFYING,
ERROR,
};
enum class Tracker
{
ALL,
HOST,
};
public:
void set_activity(Activity type);
void set_tracker(Tracker type, Glib::ustring const& host);
void set_text(Glib::ustring const& text);
bool match_activity(Torrent const& torrent) const;
bool match_tracker(Torrent const& torrent) const;
bool match_text(Torrent const& torrent) const;
bool match(Torrent const& torrent) const;
void update(Torrent::ChangeFlags changes);
#if !GTKMM_CHECK_VERSION(4, 0, 0)
sigc::signal<void()>& signal_changed();
#endif
static Glib::RefPtr<TorrentFilter> create();
static bool match_activity(Torrent const& torrent, Activity type);
static bool match_tracker(Torrent const& torrent, Tracker type, Glib::ustring const& host);
static bool match_text(Torrent const& torrent, Glib::ustring const& text);
protected:
#if GTKMM_CHECK_VERSION(4, 0, 0)
bool match_vfunc(Glib::RefPtr<Glib::ObjectBase> const& item) override;
Match get_strictness_vfunc() override;
#else
void changed(Change change);
#endif
private:
TorrentFilter();
private:
Activity activity_type_ = Activity::ALL;
Tracker tracker_type_ = Tracker::ALL;
Glib::ustring tracker_host_;
Glib::ustring text_;
#if !GTKMM_CHECK_VERSION(4, 0, 0)
sigc::signal<void()> signal_changed_;
#endif
};