mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +00:00
* 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
97 lines
2.0 KiB
C++
97 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 <initializer_list>
|
|
#include <type_traits>
|
|
|
|
#define DEFINE_FLAGS_OPERATORS(FlagType) \
|
|
constexpr inline Flags<FlagType> operator|(FlagType lhs, FlagType rhs) noexcept \
|
|
{ \
|
|
return { lhs, rhs }; \
|
|
}
|
|
|
|
template<typename T>
|
|
class Flags
|
|
{
|
|
public:
|
|
using FlagType = T;
|
|
using ValueType = std::underlying_type_t<FlagType>;
|
|
|
|
static_assert(std::is_enum_v<FlagType> && !std::is_convertible_v<FlagType, ValueType>);
|
|
|
|
public:
|
|
constexpr Flags() noexcept = default;
|
|
|
|
constexpr Flags(FlagType flag) noexcept
|
|
{
|
|
set(flag);
|
|
}
|
|
|
|
constexpr Flags(std::initializer_list<FlagType> flags) noexcept
|
|
{
|
|
for (auto const flag : flags)
|
|
{
|
|
set(flag);
|
|
}
|
|
}
|
|
|
|
constexpr bool none() const noexcept
|
|
{
|
|
return value_ == 0;
|
|
}
|
|
|
|
constexpr bool any() const noexcept
|
|
{
|
|
return !none();
|
|
}
|
|
|
|
constexpr bool test(FlagType flag) const noexcept
|
|
{
|
|
return (value_ & get_mask(flag)) != 0;
|
|
}
|
|
|
|
constexpr bool test(Flags rhs) const noexcept
|
|
{
|
|
return (value_ & rhs.value_) != 0;
|
|
}
|
|
|
|
constexpr void set(FlagType flag) noexcept
|
|
{
|
|
value_ |= get_mask(flag);
|
|
}
|
|
|
|
constexpr Flags operator|(Flags rhs) noexcept
|
|
{
|
|
return Flags(value_ | rhs.value_);
|
|
}
|
|
|
|
constexpr Flags& operator|=(Flags rhs) noexcept
|
|
{
|
|
value_ |= rhs.value_;
|
|
return *this;
|
|
}
|
|
|
|
constexpr Flags operator~() const noexcept
|
|
{
|
|
return Flags(~value_);
|
|
}
|
|
|
|
private:
|
|
constexpr explicit Flags(ValueType value) noexcept
|
|
: value_(value)
|
|
{
|
|
}
|
|
|
|
static constexpr ValueType get_mask(FlagType flag) noexcept
|
|
{
|
|
return ValueType{ 1 } << static_cast<ValueType>(flag);
|
|
}
|
|
|
|
private:
|
|
ValueType value_ = {};
|
|
};
|