1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 00:34:04 +00:00
transmission/gtk/Torrent.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

120 lines
3.2 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 <algorithm>
#include <bitset>
#include <initializer_list>
#include <memory>
#include <vector>
#include <glibmm.h>
#include <gtkmm.h>
#include <libtransmission/transmission.h>
#include "Flags.h"
class Torrent : public Glib::Object
{
public:
class Columns : public Gtk::TreeModelColumnRecord
{
public:
Columns();
Gtk::TreeModelColumn<Torrent*> self;
Gtk::TreeModelColumn<Glib::ustring> name_collated;
};
enum class ChangeFlag
{
ACTIVE_PEER_COUNT,
ACTIVE_PEERS_DOWN,
ACTIVE_PEERS_UP,
ACTIVE,
ACTIVITY,
ADDED_DATE,
ERROR_CODE,
ERROR_MESSAGE,
ETA,
FINISHED,
HAS_METADATA,
LONG_PROGRESS,
LONG_STATUS,
MIME_TYPE,
NAME,
PERCENT_COMPLETE,
PERCENT_DONE,
PRIORITY,
QUEUE_POSITION,
RATIO,
RECHECK_PROGRESS,
SEED_RATIO_PERCENT_DONE,
SPEED_DOWN,
SPEED_UP,
STALLED,
TOTAL_SIZE,
TRACKERS,
};
using ChangeFlags = Flags<ChangeFlag>;
public:
int get_active_peer_count() const;
int get_active_peers_down() const;
int get_active_peers_up() const;
bool get_active() const;
tr_torrent_activity get_activity() const;
time_t get_added_date() const;
int get_error_code() const;
Glib::ustring const& get_error_message() const;
time_t get_eta() const;
bool get_finished() const;
tr_torrent_id_t get_id() const;
Glib::ustring const& get_name_collated() const;
Glib::ustring get_name() const;
float get_percent_complete() const;
float get_percent_done() const;
tr_priority_t get_priority() const;
size_t get_queue_position() const;
float get_ratio() const;
float get_recheck_progress() const;
float get_seed_ratio_percent_done() const;
float get_speed_down() const;
float get_speed_up() const;
tr_torrent& get_underlying() const;
uint64_t get_total_size() const;
unsigned int get_trackers() const;
Glib::RefPtr<Gio::Icon> get_icon() const;
Glib::ustring get_short_status_text() const;
Glib::ustring get_long_progress_text() const;
Glib::ustring get_long_status_text() const;
bool get_sensitive() const;
ChangeFlags update();
static Glib::RefPtr<Torrent> create(tr_torrent* torrent);
static Columns const& get_columns();
static int get_item_id(Glib::RefPtr<Glib::ObjectBase const> const& item);
static void get_item_value(Glib::RefPtr<Glib::ObjectBase const> const& item, int column, Glib::ValueBase& value);
static int compare_by_id(Glib::RefPtr<Torrent const> const& lhs, Glib::RefPtr<Torrent const> const& rhs);
static bool less_by_id(Glib::RefPtr<Torrent const> const& lhs, Glib::RefPtr<Torrent const> const& rhs);
private:
Torrent();
explicit Torrent(tr_torrent* torrent);
private:
class Impl;
std::unique_ptr<Impl> const impl_;
};
DEFINE_FLAGS_OPERATORS(Torrent::ChangeFlag)