2015-06-10 21:27:11 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2012-2015 Mnemosyne LLC
|
|
|
|
*
|
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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 "Filters.h"
|
|
|
|
#include "FilterBar.h"
|
|
|
|
#include "FilterBarComboBox.h"
|
|
|
|
#include "FilterBarComboBoxDelegate.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
ActivityRole = FilterBarComboBox::UserRole,
|
|
|
|
TrackerRole
|
2015-06-10 21:27:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QString readableHostName(QString const& host)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2015-06-10 21:27:11 +00:00
|
|
|
// get the readable name...
|
|
|
|
QString name = host;
|
2017-04-20 16:02:19 +00:00
|
|
|
int const pos = name.lastIndexOf(QLatin1Char('.'));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
if (pos >= 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
name.truncate(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!name.isEmpty())
|
|
|
|
{
|
|
|
|
name[0] = name[0].toUpper();
|
|
|
|
}
|
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
} // namespace
|
|
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
FilterBarComboBox* c = new FilterBarComboBox(this);
|
|
|
|
FilterBarComboBoxDelegate* delegate = new FilterBarComboBoxDelegate(this, c);
|
|
|
|
c->setItemDelegate(delegate);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QStandardItemModel* model = new QStandardItemModel(this);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QStandardItem* row = new QStandardItem(tr("All"));
|
|
|
|
row->setData(FilterMode::SHOW_ALL, ActivityRole);
|
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
model->appendRow(new QStandardItem); // separator
|
|
|
|
delegate->setSeparator(model, model->index(1, 0));
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
row = new QStandardItem(QIcon::fromTheme(QLatin1String("system-run")), tr("Active"));
|
|
|
|
row->setData(FilterMode::SHOW_ACTIVE, ActivityRole);
|
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
row = new QStandardItem(QIcon::fromTheme(QLatin1String("go-down")), tr("Downloading"));
|
|
|
|
row->setData(FilterMode::SHOW_DOWNLOADING, ActivityRole);
|
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
row = new QStandardItem(QIcon::fromTheme(QLatin1String("go-up")), tr("Seeding"));
|
|
|
|
row->setData(FilterMode::SHOW_SEEDING, ActivityRole);
|
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
row = new QStandardItem(QIcon::fromTheme(QLatin1String("media-playback-pause")), tr("Paused"));
|
|
|
|
row->setData(FilterMode::SHOW_PAUSED, ActivityRole);
|
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
row = new QStandardItem(QIcon::fromTheme(QLatin1String("dialog-ok")), tr("Finished"));
|
|
|
|
row->setData(FilterMode::SHOW_FINISHED, ActivityRole);
|
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
row = new QStandardItem(QIcon::fromTheme(QLatin1String("view-refresh")), tr("Verifying"));
|
|
|
|
row->setData(FilterMode::SHOW_VERIFYING, ActivityRole);
|
|
|
|
model->appendRow(row);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
row = new QStandardItem(QIcon::fromTheme(QLatin1String("process-stop")), tr("Error"));
|
|
|
|
row->setData(FilterMode::SHOW_ERROR, ActivityRole);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void FilterBar::refreshTrackers()
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
FaviconCache& favicons = qApp->faviconCache();
|
2017-04-20 16:02:19 +00:00
|
|
|
int const firstTrackerRow = 2; // skip over the "All" and separator...
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
// pull info from the tracker model...
|
|
|
|
QSet<QString> oldHosts;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
for (int row = firstTrackerRow;; ++row)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QModelIndex index = myTrackerModel->index(row, 0);
|
|
|
|
|
|
|
|
if (!index.isValid())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
oldHosts << index.data(TrackerRole).toString();
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// pull the new stats from the torrent model...
|
|
|
|
QSet<QString> newHosts;
|
|
|
|
QMap<QString, int> torrentsPerHost;
|
|
|
|
|
|
|
|
for (int row = 0;; ++row)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QModelIndex index = myTorrents.index(row, 0);
|
|
|
|
|
|
|
|
if (!index.isValid())
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
Torrent const* tor = index.data(TorrentModel::TorrentRole).value<Torrent const*>();
|
2017-04-19 12:04:45 +00:00
|
|
|
QSet<QString> torrentNames;
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QString const& host : tor->hosts())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
newHosts.insert(host);
|
|
|
|
torrentNames.insert(readableHostName(host));
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QString const& name : torrentNames)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
++torrentsPerHost[name];
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// update the "All" row
|
|
|
|
myTrackerModel->setData(myTrackerModel->index(0, 0), myTorrents.rowCount(), FilterBarComboBox::CountRole);
|
2017-04-30 16:30:03 +00:00
|
|
|
myTrackerModel->setData(myTrackerModel->index(0, 0), getCountString(myTorrents.rowCount()),
|
|
|
|
FilterBarComboBox::CountStringRole);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// rows to update
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QString const& host : oldHosts & newHosts)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const name = readableHostName(host);
|
2017-04-19 12:04:45 +00:00
|
|
|
QStandardItem* row = myTrackerModel->findItems(name).front();
|
2017-04-20 16:02:19 +00:00
|
|
|
int const count = torrentsPerHost[name];
|
2017-04-19 12:04:45 +00:00
|
|
|
row->setData(count, FilterBarComboBox::CountRole);
|
|
|
|
row->setData(getCountString(count), FilterBarComboBox::CountStringRole);
|
|
|
|
row->setData(QIcon(favicons.findFromHost(host)), Qt::DecorationRole);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// rows to remove
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QString const& host : oldHosts - newHosts)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const name = readableHostName(host);
|
2017-04-19 12:04:45 +00:00
|
|
|
QStandardItem* item = myTrackerModel->findItems(name).front();
|
|
|
|
|
|
|
|
if (!item->data(TrackerRole).toString().isEmpty()) // don't remove "All"
|
|
|
|
{
|
|
|
|
myTrackerModel->removeRows(item->row(), 1);
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// rows to add
|
|
|
|
bool anyAdded = false;
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QString const& host : newHosts - oldHosts)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const name = readableHostName(host);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!myTrackerModel->findItems(name).isEmpty())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// find the sorted position to add this row
|
|
|
|
int i = firstTrackerRow;
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
for (int n = myTrackerModel->rowCount(); i < n; ++i)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const rowName = myTrackerModel->index(i, 0).data(Qt::DisplayRole).toString();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (rowName >= name)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// add the row
|
|
|
|
QStandardItem* row = new QStandardItem(favicons.findFromHost(host), name);
|
2017-04-20 16:02:19 +00:00
|
|
|
int const count = torrentsPerHost[host];
|
2017-04-19 12:04:45 +00:00
|
|
|
row->setData(count, FilterBarComboBox::CountRole);
|
|
|
|
row->setData(getCountString(count), FilterBarComboBox::CountStringRole);
|
|
|
|
row->setData(QIcon(favicons.findFromHost(host)), Qt::DecorationRole);
|
|
|
|
row->setData(host, TrackerRole);
|
|
|
|
myTrackerModel->insertRow(i, row);
|
|
|
|
anyAdded = true;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (anyAdded) // the one added might match our filter...
|
|
|
|
{
|
|
|
|
refreshPref(Prefs::FILTER_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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
FilterBarComboBox* c = new FilterBarComboBox(this);
|
|
|
|
FilterBarComboBoxDelegate* delegate = new FilterBarComboBoxDelegate(this, c);
|
|
|
|
c->setItemDelegate(delegate);
|
|
|
|
|
|
|
|
QStandardItem* row = new QStandardItem(tr("All"));
|
|
|
|
row->setData(QString(), TrackerRole);
|
2017-04-20 16:02:19 +00:00
|
|
|
int const count = myTorrents.rowCount();
|
2017-04-19 12:04:45 +00:00
|
|
|
row->setData(count, FilterBarComboBox::CountRole);
|
|
|
|
row->setData(getCountString(count), FilterBarComboBox::CountStringRole);
|
|
|
|
model->appendRow(row);
|
|
|
|
|
|
|
|
model->appendRow(new QStandardItem); // separator
|
|
|
|
delegate->setSeparator(model, model->index(1, 0));
|
|
|
|
|
|
|
|
c->setModel(model);
|
|
|
|
return c;
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
FilterBar::FilterBar(Prefs& prefs, TorrentModel const& torrents, TorrentFilter const& filter, QWidget* parent) :
|
2017-04-19 12:04:45 +00:00
|
|
|
QWidget(parent),
|
|
|
|
myPrefs(prefs),
|
|
|
|
myTorrents(torrents),
|
|
|
|
myFilter(filter),
|
|
|
|
myRecountTimer(new QTimer(this)),
|
|
|
|
myIsBootstrapping(true)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QHBoxLayout* h = new QHBoxLayout(this);
|
|
|
|
h->setContentsMargins(3, 3, 3, 3);
|
|
|
|
|
|
|
|
myCountLabel = new QLabel(tr("Show:"), this);
|
|
|
|
h->addWidget(myCountLabel);
|
|
|
|
|
|
|
|
myActivityCombo = createActivityCombo();
|
|
|
|
h->addWidget(myActivityCombo);
|
|
|
|
|
|
|
|
myTrackerModel = new QStandardItemModel(this);
|
|
|
|
myTrackerCombo = createTrackerCombo(myTrackerModel);
|
|
|
|
h->addWidget(myTrackerCombo);
|
|
|
|
|
|
|
|
h->addStretch();
|
|
|
|
|
|
|
|
myLineEdit = new QLineEdit(this);
|
|
|
|
myLineEdit->setClearButtonEnabled(true);
|
|
|
|
myLineEdit->setPlaceholderText(tr("Search..."));
|
|
|
|
myLineEdit->setMaximumWidth(250);
|
|
|
|
h->addWidget(myLineEdit, 1);
|
|
|
|
connect(myLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onTextChanged(QString)));
|
|
|
|
|
|
|
|
// listen for changes from the other players
|
|
|
|
connect(&myPrefs, SIGNAL(changed(int)), this, SLOT(refreshPref(int)));
|
|
|
|
connect(myActivityCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onActivityIndexChanged(int)));
|
|
|
|
connect(myTrackerCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onTrackerIndexChanged(int)));
|
|
|
|
connect(&myTorrents, SIGNAL(modelReset()), this, SLOT(recountSoon()));
|
|
|
|
connect(&myTorrents, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(recountSoon()));
|
|
|
|
connect(&myTorrents, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(recountSoon()));
|
|
|
|
connect(&myTorrents, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(recountSoon()));
|
|
|
|
connect(myRecountTimer, SIGNAL(timeout()), this, SLOT(recount()));
|
|
|
|
|
|
|
|
recountSoon();
|
|
|
|
refreshTrackers();
|
|
|
|
myIsBootstrapping = false;
|
|
|
|
|
|
|
|
// initialize our state
|
|
|
|
QList<int> initKeys;
|
|
|
|
initKeys << Prefs::FILTER_MODE << Prefs::FILTER_TRACKERS;
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (int const key : initKeys)
|
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
|
|
|
FilterBar::~FilterBar()
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
delete myRecountTimer;
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myActivityCombo->setCurrentIndex(0);
|
|
|
|
myTrackerCombo->setCurrentIndex(0);
|
|
|
|
myLineEdit->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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
FilterMode const m = myPrefs.get<FilterMode>(key);
|
2017-04-19 12:04:45 +00:00
|
|
|
QAbstractItemModel* model = myActivityCombo->model();
|
|
|
|
QModelIndexList indices = model->match(model->index(0, 0), ActivityRole, m.mode());
|
|
|
|
myActivityCombo->setCurrentIndex(indices.isEmpty() ? 0 : indices.first().row());
|
|
|
|
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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const tracker = myPrefs.getString(key);
|
|
|
|
QString const name = readableHostName(tracker);
|
2017-04-19 12:04:45 +00:00
|
|
|
QList<QStandardItem*> rows = myTrackerModel->findItems(name);
|
|
|
|
|
|
|
|
if (!rows.isEmpty())
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myTrackerCombo->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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
bool const isBootstrapping = myTrackerModel->rowCount() <= 2;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!isBootstrapping)
|
|
|
|
{
|
|
|
|
myPrefs.set(key, QString());
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void FilterBar::onTextChanged(QString const& str)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!myIsBootstrapping)
|
|
|
|
{
|
|
|
|
myPrefs.set(Prefs::FILTER_TEXT, str.trimmed());
|
|
|
|
}
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!myIsBootstrapping)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QString str;
|
2017-04-20 16:02:19 +00:00
|
|
|
bool const isTracker = !myTrackerCombo->itemData(i, TrackerRole).toString().isEmpty();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!isTracker)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
// show all
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = myTrackerCombo->itemData(i, TrackerRole).toString();
|
2017-04-20 16:02:19 +00:00
|
|
|
int const pos = str.lastIndexOf(QLatin1Char('.'));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (pos >= 0)
|
|
|
|
{
|
|
|
|
str.truncate(pos + 1);
|
|
|
|
}
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
myPrefs.set(Prefs::FILTER_TRACKERS, str);
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!myIsBootstrapping)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
FilterMode const mode = myActivityCombo->itemData(i, ActivityRole).toInt();
|
2017-04-19 12:04:45 +00:00
|
|
|
myPrefs.set(Prefs::FILTER_MODE, mode);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void FilterBar::recountSoon()
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!myRecountTimer->isActive())
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
myRecountTimer->setSingleShot(true);
|
|
|
|
myRecountTimer->start(800);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
void FilterBar::recount()
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QAbstractItemModel* model = myActivityCombo->model();
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
int torrentsPerMode[FilterMode::NUM_MODES] = {};
|
|
|
|
myFilter.countTorrentsPerMode(torrentsPerMode);
|
2015-06-10 21:27:11 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
for (int row = 0, n = model->rowCount(); row < n; ++row)
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QModelIndex index = model->index(row, 0);
|
2017-04-20 16:02:19 +00:00
|
|
|
int const mode = index.data(ActivityRole).toInt();
|
|
|
|
int const count = torrentsPerMode[mode];
|
2017-04-19 12:04:45 +00:00
|
|
|
model->setData(index, count, FilterBarComboBox::CountRole);
|
|
|
|
model->setData(index, getCountString(count), FilterBarComboBox::CountStringRole);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
refreshTrackers();
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QString FilterBar::getCountString(int n) const
|
2015-06-10 21:27:11 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return QString::fromLatin1("%L1").arg(n);
|
2015-06-10 21:27:11 +00:00
|
|
|
}
|