1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-11 14:43:42 +00:00
transmission/qt/Filters.cc
Charles Kerr 33a421e97f
refactor: only update filterbar comboboxes when necessary (#1335)
* refactor: Torrent::update() returns a delta bitset

Setting up for followup PRs where, instead of doing expensive work every
time there is a change, we can be more fine-grained and do the work only
if the relevant Torrent properties changed.

* chore: make uncrustify happy

* refactor: update filterbar counts more selectively

Only rebuild the activity and tracker combobox models when the model's
size changes or when the relevant Torrent properties change.

Previously, rebuild would happen on any Torrent property change even if
the properties were unrelated to activity or trackers.

* chore: remove redundant "private:" key
2020-06-23 18:54:08 -05:00

98 lines
2.2 KiB
C++

/*
* This file Copyright (C) 2009-2015 Mnemosyne LLC
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
*
*/
#include <cstdint> // uint64_t
#include "Filters.h"
std::array<QString, FilterMode::NUM_MODES> const FilterMode::Names =
{
QStringLiteral("show-all"),
QStringLiteral("show-active"),
QStringLiteral("show-downloading"),
QStringLiteral("show-seeding"),
QStringLiteral("show-paused"),
QStringLiteral("show-finished"),
QStringLiteral("show-verifying"),
QStringLiteral("show-error")
};
int FilterMode::modeFromName(QString const& name)
{
for (int i = 0; i < NUM_MODES; ++i)
{
if (Names[i] == name)
{
return i;
}
}
return FilterMode().mode(); // use the default value
}
// NB: if you change this function, update TorrentFields too
bool FilterMode::test(Torrent const& tor, int mode)
{
switch (mode)
{
case SHOW_ACTIVE:
return tor.peersWeAreUploadingTo() > 0 || tor.peersWeAreDownloadingFrom() > 0 || tor.isVerifying();
case SHOW_DOWNLOADING:
return tor.isDownloading() || tor.isWaitingToDownload();
case SHOW_ERROR:
return tor.hasError();
case SHOW_FINISHED:
return tor.isFinished();
case SHOW_PAUSED:
return tor.isPaused();
case SHOW_SEEDING:
return tor.isSeeding() || tor.isWaitingToSeed();
case SHOW_VERIFYING:
return tor.isVerifying() || tor.isWaitingToVerify();
default: // SHOW_ALL
return true;
}
}
/***
****
***/
std::array<QString, SortMode::NUM_MODES> const SortMode::Names =
{
QStringLiteral("sort-by-activity"),
QStringLiteral("sort-by-age"),
QStringLiteral("sort-by-eta"),
QStringLiteral("sort-by-name"),
QStringLiteral("sort-by-progress"),
QStringLiteral("sort-by-queue"),
QStringLiteral("sort-by-ratio"),
QStringLiteral("sort-by-size"),
QStringLiteral("sort-by-state"),
QStringLiteral("sort-by-id")
};
int SortMode::modeFromName(QString const& name)
{
for (int i = 0; i < NUM_MODES; ++i)
{
if (Names[i] == name)
{
return i;
}
}
return SortMode().mode(); // use the default value
}