2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2012-2022 Mnemosyne LLC.
|
2022-02-07 16:25:02 +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.
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "FilterBar.h"
|
|
|
|
|
2020-06-23 23:54:08 +00:00
|
|
|
#include <cstdint> // uint64_t
|
2019-11-12 01:37:05 +00:00
|
|
|
#include <map>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
2017-02-11 10:44:34 +00:00
|
|
|
#include <QLineEdit>
|
2015-06-10 21:27:11 +00:00
|
|
|
#include <QStandardItemModel>
|
|
|
|
|
|
|
|
#include "Application.h"
|
|
|
|
#include "FaviconCache.h"
|
|
|
|
#include "FilterBarComboBox.h"
|
|
|
|
#include "FilterBarComboBoxDelegate.h"
|
2020-08-11 18:11:55 +00:00
|
|
|
#include "Filters.h"
|
2021-12-09 08:13:04 +00:00
|
|
|
#include "IconCache.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "Prefs.h"
|
2015-06-12 22:12:12 +00:00
|
|
|
#include "Torrent.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "TorrentFilter.h"
|
|
|
|
#include "TorrentModel.h"
|
2019-11-12 01:37:05 +00:00
|
|
|
#include "Utils.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
ACTIVITY_ROLE = FilterBarComboBox::UserRole,
|
|
|
|
TRACKER_ROLE
|
2015-06-10 21:27:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
FilterBarComboBox* FilterBar::createActivityCombo()
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* c = new FilterBarComboBox(this);
|
|
|
|
auto* delegate = new FilterBarComboBoxDelegate(this, c);
|
2017-04-19 12:04:45 +00:00
|
|
|
c->setItemDelegate(delegate);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* model = new QStandardItemModel(this);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* row = new QStandardItem(tr("All"));
|
2020-06-05 19:02:11 +00:00
|
|
|
row->setData(FilterMode::SHOW_ALL, ACTIVITY_ROLE);
|
2017-04-19 12:04:45 +00:00
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
model->appendRow(new QStandardItem); // separator
|
2020-11-02 01:13:32 +00:00
|
|
|
FilterBarComboBoxDelegate::setSeparator(model, model->index(1, 0));
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2021-12-09 08:13:04 +00:00
|
|
|
auto& icons = IconCache::get();
|
|
|
|
|
|
|
|
row = new QStandardItem(icons.getThemeIcon(QStringLiteral("system-run")), tr("Active"));
|
2020-06-05 19:02:11 +00:00
|
|
|
row->setData(FilterMode::SHOW_ACTIVE, ACTIVITY_ROLE);
|
2017-04-19 12:04:45 +00:00
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2021-12-09 08:13:04 +00:00
|
|
|
row = new QStandardItem(icons.getThemeIcon(QStringLiteral("go-down")), tr("Downloading"));
|
2020-06-05 19:02:11 +00:00
|
|
|
row->setData(FilterMode::SHOW_DOWNLOADING, ACTIVITY_ROLE);
|
2017-04-19 12:04:45 +00:00
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2021-12-09 08:13:04 +00:00
|
|
|
row = new QStandardItem(icons.getThemeIcon(QStringLiteral("go-up")), tr("Seeding"));
|
2020-06-05 19:02:11 +00:00
|
|
|
row->setData(FilterMode::SHOW_SEEDING, ACTIVITY_ROLE);
|
2017-04-19 12:04:45 +00:00
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2021-12-09 08:13:04 +00:00
|
|
|
row = new QStandardItem(icons.getThemeIcon(QStringLiteral("media-playback-pause")), tr("Paused"));
|
2020-06-05 19:02:11 +00:00
|
|
|
row->setData(FilterMode::SHOW_PAUSED, ACTIVITY_ROLE);
|
2017-04-19 12:04:45 +00:00
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2021-12-09 08:13:04 +00:00
|
|
|
row = new QStandardItem(icons.getThemeIcon(QStringLiteral("dialog-ok")), tr("Finished"));
|
2020-06-05 19:02:11 +00:00
|
|
|
row->setData(FilterMode::SHOW_FINISHED, ACTIVITY_ROLE);
|
2017-04-19 12:04:45 +00:00
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2021-12-09 08:13:04 +00:00
|
|
|
row = new QStandardItem(icons.getThemeIcon(QStringLiteral("view-refresh")), tr("Verifying"));
|
2020-06-05 19:02:11 +00:00
|
|
|
row->setData(FilterMode::SHOW_VERIFYING, ACTIVITY_ROLE);
|
2017-04-19 12:04:45 +00:00
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2021-12-09 08:13:04 +00:00
|
|
|
row = new QStandardItem(icons.getThemeIcon(QStringLiteral("process-stop")), tr("Error"));
|
2020-06-05 19:02:11 +00:00
|
|
|
row->setData(FilterMode::SHOW_ERROR, ACTIVITY_ROLE);
|
2017-04-19 12:04:45 +00:00
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
c->setModel(model);
|
|
|
|
return c;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
namespace
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-11-09 03:31:02 +00:00
|
|
|
QString getCountString(size_t n)
|
2019-11-12 01:37:05 +00:00
|
|
|
{
|
2020-05-29 17:40:07 +00:00
|
|
|
return QStringLiteral("%L1").arg(n);
|
2019-11-12 01:37:05 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-06-23 23:54:08 +00:00
|
|
|
Torrent::fields_t constexpr TrackerFields = {
|
2021-08-15 09:41:48 +00:00
|
|
|
uint64_t(1) << Torrent::TRACKER_STATS,
|
|
|
|
};
|
2020-06-23 23:54:08 +00:00
|
|
|
|
|
|
|
auto constexpr ActivityFields = FilterMode::TorrentFields;
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
} // namespace
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void FilterBar::refreshTrackers()
|
|
|
|
{
|
|
|
|
enum
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
ROW_TOTALS = 0,
|
|
|
|
ROW_SEPARATOR,
|
|
|
|
ROW_FIRST_TRACKER
|
2019-11-12 01:37:05 +00:00
|
|
|
};
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-24 18:28:54 +00:00
|
|
|
auto torrents_per_tracker = std::unordered_map<FaviconCache::Key, int>{};
|
2020-05-27 21:53:12 +00:00
|
|
|
for (auto const& tor : torrents_.torrents())
|
2019-11-12 01:37:05 +00:00
|
|
|
{
|
2020-06-24 18:28:54 +00:00
|
|
|
for (auto const& key : tor->trackerKeys())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-24 18:28:54 +00:00
|
|
|
++torrents_per_tracker[key];
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// update the "All" row
|
2020-06-24 18:28:54 +00:00
|
|
|
auto const num_trackers = torrents_per_tracker.size();
|
2020-05-27 21:53:12 +00:00
|
|
|
auto* item = tracker_model_->item(ROW_TOTALS);
|
2019-11-12 01:37:05 +00:00
|
|
|
item->setData(int(num_trackers), FilterBarComboBox::CountRole);
|
|
|
|
item->setData(getCountString(num_trackers), FilterBarComboBox::CountStringRole);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
auto update_tracker_item = [](QStandardItem* i, auto const& it)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
auto const& key = it->first;
|
|
|
|
auto const& display_name = FaviconCache::getDisplayName(key);
|
|
|
|
auto const& count = it->second;
|
|
|
|
auto const icon = trApp->faviconCache().find(key);
|
|
|
|
|
|
|
|
i->setData(display_name, Qt::DisplayRole);
|
|
|
|
i->setData(display_name, TRACKER_ROLE);
|
|
|
|
i->setData(getCountString(static_cast<size_t>(count)), FilterBarComboBox::CountStringRole);
|
|
|
|
i->setData(icon, Qt::DecorationRole);
|
|
|
|
i->setData(int(count), FilterBarComboBox::CountRole);
|
|
|
|
|
|
|
|
return i;
|
|
|
|
};
|
2019-11-12 01:37:05 +00:00
|
|
|
|
2020-06-24 18:28:54 +00:00
|
|
|
auto new_trackers = std::map<FaviconCache::Key, int>(torrents_per_tracker.begin(), torrents_per_tracker.end());
|
2020-05-27 21:53:12 +00:00
|
|
|
auto old_it = tracker_counts_.cbegin();
|
|
|
|
auto new_it = new_trackers.cbegin();
|
|
|
|
auto const old_end = tracker_counts_.cend();
|
|
|
|
auto const new_end = new_trackers.cend();
|
|
|
|
bool any_added = false;
|
2019-11-12 01:37:05 +00:00
|
|
|
int row = ROW_FIRST_TRACKER;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
while ((old_it != old_end) || (new_it != new_end))
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2019-11-12 01:37:05 +00:00
|
|
|
if ((old_it == old_end) || ((new_it != new_end) && (old_it->first > new_it->first)))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
tracker_model_->insertRow(row, update_tracker_item(new QStandardItem(1), new_it));
|
2020-05-27 21:53:12 +00:00
|
|
|
any_added = true;
|
2019-11-12 01:37:05 +00:00
|
|
|
++new_it;
|
|
|
|
++row;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2019-11-12 01:37:05 +00:00
|
|
|
else if ((new_it == new_end) || ((old_it != old_end) && (old_it->first < new_it->first)))
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tracker_model_->removeRow(row);
|
2019-11-12 01:37:05 +00:00
|
|
|
++old_it;
|
|
|
|
}
|
|
|
|
else // update
|
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
update_tracker_item(tracker_model_->item(row), new_it);
|
2019-11-12 01:37:05 +00:00
|
|
|
++old_it;
|
|
|
|
++new_it;
|
|
|
|
++row;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (any_added) // the one added might match our filter...
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
refreshPref(Prefs::FILTER_TRACKERS);
|
|
|
|
}
|
2019-11-12 01:37:05 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
tracker_counts_.swap(new_trackers);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
FilterBarComboBox* FilterBar::createTrackerCombo(QStandardItemModel* model)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* c = new FilterBarComboBox(this);
|
|
|
|
auto* delegate = new FilterBarComboBoxDelegate(this, c);
|
2017-04-19 12:04:45 +00:00
|
|
|
c->setItemDelegate(delegate);
|
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* row = new QStandardItem(tr("All"));
|
2020-06-05 19:02:11 +00:00
|
|
|
row->setData(QString(), TRACKER_ROLE);
|
2020-05-27 21:53:12 +00:00
|
|
|
int const count = torrents_.rowCount();
|
2017-04-19 12:04:45 +00:00
|
|
|
row->setData(count, FilterBarComboBox::CountRole);
|
2020-11-09 03:31:02 +00:00
|
|
|
row->setData(getCountString(static_cast<size_t>(count)), FilterBarComboBox::CountStringRole);
|
2017-04-19 12:04:45 +00:00
|
|
|
model->appendRow(row);
|
|
|
|
|
|
|
|
model->appendRow(new QStandardItem); // separator
|
2020-11-02 01:13:32 +00:00
|
|
|
FilterBarComboBoxDelegate::setSeparator(model, model->index(1, 0));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
c->setModel(model);
|
|
|
|
return c;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
FilterBar::FilterBar(Prefs& prefs, TorrentModel const& torrents, TorrentFilter const& filter, QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, prefs_(prefs)
|
|
|
|
, torrents_(torrents)
|
|
|
|
, filter_(filter)
|
|
|
|
, is_bootstrapping_(true)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* h = new QHBoxLayout(this);
|
2017-04-19 12:04:45 +00:00
|
|
|
h->setContentsMargins(3, 3, 3, 3);
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
count_label_ = new QLabel(tr("Show:"), this);
|
|
|
|
h->addWidget(count_label_);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
activity_combo_ = createActivityCombo();
|
|
|
|
h->addWidget(activity_combo_);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
tracker_model_ = new QStandardItemModel(this);
|
|
|
|
tracker_combo_ = createTrackerCombo(tracker_model_);
|
|
|
|
h->addWidget(tracker_combo_);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
h->addStretch();
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
line_edit_ = new QLineEdit(this);
|
|
|
|
line_edit_->setClearButtonEnabled(true);
|
|
|
|
line_edit_->setPlaceholderText(tr("Search..."));
|
|
|
|
line_edit_->setMaximumWidth(250);
|
|
|
|
h->addWidget(line_edit_, 1);
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(line_edit_, &QLineEdit::textChanged, this, &FilterBar::onTextChanged);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
// listen for changes from the other players
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(&prefs_, &Prefs::changed, this, &FilterBar::refreshPref);
|
|
|
|
connect(activity_combo_, qOverload<int>(&QComboBox::currentIndexChanged), this, &FilterBar::onActivityIndexChanged);
|
|
|
|
connect(tracker_combo_, qOverload<int>(&QComboBox::currentIndexChanged), this, &FilterBar::onTrackerIndexChanged);
|
2020-06-23 23:54:08 +00:00
|
|
|
connect(&torrents_, &TorrentModel::modelReset, this, &FilterBar::recountAllSoon);
|
|
|
|
connect(&torrents_, &TorrentModel::rowsInserted, this, &FilterBar::recountAllSoon);
|
|
|
|
connect(&torrents_, &TorrentModel::rowsRemoved, this, &FilterBar::recountAllSoon);
|
2020-06-23 21:11:16 +00:00
|
|
|
connect(&torrents_, &TorrentModel::torrentsChanged, this, &FilterBar::onTorrentsChanged);
|
2020-10-31 18:56:12 +00:00
|
|
|
connect(&recount_timer_, &QTimer::timeout, this, &FilterBar::recount);
|
2020-11-08 19:54:40 +00:00
|
|
|
connect(&trApp->faviconCache(), &FaviconCache::pixmapReady, this, &FilterBar::recountTrackersSoon);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-06-23 23:54:08 +00:00
|
|
|
recountAllSoon();
|
2020-05-27 21:53:12 +00:00
|
|
|
is_bootstrapping_ = false;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
// initialize our state
|
2019-11-12 01:37:05 +00:00
|
|
|
for (int const key : { Prefs::FILTER_MODE, Prefs::FILTER_TRACKERS })
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
refreshPref(key);
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void FilterBar::clear()
|
2015-10-24 20:56:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
activity_combo_->setCurrentIndex(0);
|
|
|
|
tracker_combo_->setCurrentIndex(0);
|
|
|
|
line_edit_->clear();
|
2015-10-24 20:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void FilterBar::refreshPref(int key)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (key)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::FILTER_MODE:
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
auto const m = prefs_.get<FilterMode>(key);
|
|
|
|
QAbstractItemModel* model = activity_combo_->model();
|
2020-06-05 19:02:11 +00:00
|
|
|
QModelIndexList indices = model->match(model->index(0, 0), ACTIVITY_ROLE, m.mode());
|
2020-05-27 21:53:12 +00:00
|
|
|
activity_combo_->setCurrentIndex(indices.isEmpty() ? 0 : indices.first().row());
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::FILTER_TRACKERS:
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
auto const display_name = prefs_.getString(key);
|
|
|
|
auto rows = tracker_model_->findItems(display_name);
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!rows.isEmpty())
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tracker_combo_->setCurrentIndex(rows.front()->row());
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else // hm, we don't seem to have this tracker anymore...
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
bool const is_bootstrapping = tracker_model_->rowCount() <= 2;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!is_bootstrapping)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(key, QString());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
break;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 21:11:16 +00:00
|
|
|
void FilterBar::onTorrentsChanged(torrent_ids_t const& ids, Torrent::fields_t const& changed_fields)
|
|
|
|
{
|
2020-06-23 23:54:08 +00:00
|
|
|
Q_UNUSED(ids)
|
2020-06-23 21:11:16 +00:00
|
|
|
|
2020-06-23 23:54:08 +00:00
|
|
|
if ((changed_fields & TrackerFields).any())
|
|
|
|
{
|
|
|
|
recountTrackersSoon();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((changed_fields & ActivityFields).any())
|
|
|
|
{
|
|
|
|
recountActivitySoon();
|
|
|
|
}
|
2020-06-23 21:11:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void FilterBar::onTextChanged(QString const& str)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!is_bootstrapping_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(Prefs::FILTER_TEXT, str.trimmed());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void FilterBar::onTrackerIndexChanged(int i)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!is_bootstrapping_)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-06-24 18:28:54 +00:00
|
|
|
auto const display_name = tracker_combo_->itemData(i, TRACKER_ROLE).toString();
|
|
|
|
prefs_.set(Prefs::FILTER_TRACKERS, display_name);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void FilterBar::onActivityIndexChanged(int i)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!is_bootstrapping_)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-11-01 21:47:57 +00:00
|
|
|
auto const mode = FilterMode(activity_combo_->itemData(i, ACTIVITY_ROLE).toInt());
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(Prefs::FILTER_MODE, mode);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2020-06-23 23:54:08 +00:00
|
|
|
void FilterBar::recountSoon(Pending const& pending)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-06-23 23:54:08 +00:00
|
|
|
pending_ |= pending;
|
|
|
|
|
2020-10-31 18:56:12 +00:00
|
|
|
if (!recount_timer_.isActive())
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-10-31 18:56:12 +00:00
|
|
|
recount_timer_.setSingleShot(true);
|
|
|
|
recount_timer_.start(800);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-14 21:30:14 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void FilterBar::recount()
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QAbstractItemModel* model = activity_combo_->model();
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-06-23 23:54:08 +00:00
|
|
|
decltype(pending_) pending = {};
|
|
|
|
std::swap(pending_, pending);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2020-06-23 23:54:08 +00:00
|
|
|
if (pending[ACTIVITY])
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2020-06-23 23:54:08 +00:00
|
|
|
auto const torrents_per_mode = filter_.countTorrentsPerMode();
|
|
|
|
|
|
|
|
for (int row = 0, n = model->rowCount(); row < n; ++row)
|
|
|
|
{
|
|
|
|
auto const index = model->index(row, 0);
|
|
|
|
auto const mode = index.data(ACTIVITY_ROLE).toInt();
|
|
|
|
auto const count = torrents_per_mode[mode];
|
|
|
|
model->setData(index, count, FilterBarComboBox::CountRole);
|
2020-11-09 03:31:02 +00:00
|
|
|
model->setData(index, getCountString(static_cast<size_t>(count)), FilterBarComboBox::CountStringRole);
|
2020-06-23 23:54:08 +00:00
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 23:54:08 +00:00
|
|
|
if (pending[TRACKERS])
|
|
|
|
{
|
|
|
|
refreshTrackers();
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|