2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2010-2023 Mnemosyne LLC.
|
2022-08-08 18:05:39 +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.
|
2009-04-11 18:25:12 +00:00
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2009-04-11 18:25:12 +00:00
|
|
|
|
2022-04-08 01:50:26 +00:00
|
|
|
#include <cstdint> // uint64_t
|
|
|
|
|
2020-06-23 23:54:08 +00:00
|
|
|
#include "Torrent.h"
|
|
|
|
|
2009-04-11 18:25:12 +00:00
|
|
|
class FilterMode
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2015-06-12 22:12:12 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
SHOW_ALL,
|
|
|
|
SHOW_ACTIVE,
|
|
|
|
SHOW_DOWNLOADING,
|
|
|
|
SHOW_SEEDING,
|
|
|
|
SHOW_PAUSED,
|
|
|
|
SHOW_FINISHED,
|
|
|
|
SHOW_VERIFYING,
|
|
|
|
SHOW_ERROR,
|
|
|
|
NUM_MODES
|
2015-06-12 22:12:12 +00:00
|
|
|
};
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
explicit FilterMode(int mode = SHOW_ALL)
|
|
|
|
: mode_(mode)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int mode() const
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return mode_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 23:54:08 +00:00
|
|
|
/* The Torrent properties that can affect this filter.
|
|
|
|
When one of these changes, it's time to refilter. */
|
2021-08-15 09:41:48 +00:00
|
|
|
static Torrent::fields_t constexpr TorrentFields = //
|
|
|
|
(uint64_t(1) << Torrent::ERROR) | //
|
|
|
|
(uint64_t(1) << Torrent::IS_FINISHED) | //
|
|
|
|
(uint64_t(1) << Torrent::PEERS_GETTING_FROM_US) | //
|
|
|
|
(uint64_t(1) << Torrent::PEERS_SENDING_TO_US) | //
|
|
|
|
(uint64_t(1) << Torrent::STATUS);
|
2020-06-23 23:54:08 +00:00
|
|
|
|
|
|
|
static bool test(Torrent const& tor, int mode);
|
2021-08-15 09:41:48 +00:00
|
|
|
|
|
|
|
bool test(Torrent const& tor) const
|
|
|
|
{
|
|
|
|
return test(tor, mode());
|
|
|
|
}
|
2020-06-23 23:54:08 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
private:
|
2020-05-27 21:53:12 +00:00
|
|
|
int mode_;
|
2009-04-11 18:25:12 +00:00
|
|
|
};
|
|
|
|
|
2015-06-12 22:12:12 +00:00
|
|
|
Q_DECLARE_METATYPE(FilterMode)
|
|
|
|
|
2009-04-11 18:25:12 +00:00
|
|
|
class SortMode
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
public:
|
2015-06-12 22:12:12 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
SORT_BY_ACTIVITY,
|
|
|
|
SORT_BY_AGE,
|
|
|
|
SORT_BY_ETA,
|
|
|
|
SORT_BY_NAME,
|
|
|
|
SORT_BY_PROGRESS,
|
|
|
|
SORT_BY_QUEUE,
|
|
|
|
SORT_BY_RATIO,
|
|
|
|
SORT_BY_SIZE,
|
|
|
|
SORT_BY_STATE,
|
|
|
|
SORT_BY_ID,
|
|
|
|
NUM_MODES
|
2015-06-12 22:12:12 +00:00
|
|
|
};
|
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
explicit SortMode(int mode = SORT_BY_ID) noexcept
|
|
|
|
: mode_{ mode }
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
}
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2022-06-13 03:59:30 +00:00
|
|
|
[[nodiscard]] constexpr auto mode() const noexcept
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return mode_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-12 22:12:12 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
private:
|
2020-05-27 21:53:12 +00:00
|
|
|
int mode_ = SORT_BY_ID;
|
2009-04-11 18:25:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(SortMode)
|