2022-12-21 21:26:25 +00:00
|
|
|
// 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
|
|
|
|
|
2022-12-29 02:42:20 +00:00
|
|
|
#include "GtkCompat.h"
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "Torrent.h"
|
2022-12-21 21:26:25 +00:00
|
|
|
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <glibmm/refptr.h>
|
|
|
|
|
|
|
|
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
|
|
|
#include <gtkmm/sorter.h>
|
|
|
|
#else
|
|
|
|
#include <glibmm/object.h>
|
|
|
|
#endif
|
2022-12-21 21:26:25 +00:00
|
|
|
|
|
|
|
class TorrentSorter : public IF_GTKMM4(Gtk::Sorter, Glib::Object)
|
|
|
|
{
|
|
|
|
using CompareFunc = int (*)(Torrent const&, Torrent const&);
|
|
|
|
|
|
|
|
#if !GTKMM_CHECK_VERSION(4, 0, 0)
|
|
|
|
enum class Change{
|
|
|
|
DIFFERENT,
|
|
|
|
INVERTED,
|
|
|
|
LESS_STRICT,
|
|
|
|
MORE_STRICT,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_mode(std::string_view mode);
|
|
|
|
void set_reversed(bool is_reversed);
|
|
|
|
|
|
|
|
int compare(Torrent const& lhs, Torrent const& rhs) const;
|
|
|
|
|
|
|
|
void update(Torrent::ChangeFlags changes);
|
|
|
|
|
|
|
|
#if !GTKMM_CHECK_VERSION(4, 0, 0)
|
|
|
|
sigc::signal<void()>& signal_changed();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static Glib::RefPtr<TorrentSorter> create();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
|
|
|
Gtk::Ordering compare_vfunc(gpointer lhs, gpointer rhs) override;
|
|
|
|
Order get_order_vfunc() override;
|
|
|
|
#else
|
|
|
|
void changed(Change change);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
|
|
|
TorrentSorter();
|
|
|
|
|
|
|
|
private:
|
|
|
|
CompareFunc compare_func_ = nullptr;
|
|
|
|
bool is_reversed_ = false;
|
|
|
|
|
|
|
|
#if !GTKMM_CHECK_VERSION(4, 0, 0)
|
|
|
|
sigc::signal<void()> signal_changed_;
|
|
|
|
#endif
|
|
|
|
};
|