Browse Source

Replace hard-coded numbers in TrackerFiltersList class

adaptive-webui-19844
Chocobo1 5 years ago
parent
commit
723668ba46
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 56
      src/gui/transferlistfilterswidget.cpp

56
src/gui/transferlistfilterswidget.cpp

@ -56,6 +56,14 @@
namespace namespace
{ {
enum TRACKER_FILTER_ROW
{
ALL_ROW,
TRACKERLESS_ROW,
ERROR_ROW,
WARNING_ROW
};
QString getScheme(const QString &tracker) QString getScheme(const QString &tracker)
{ {
const QUrl url {tracker}; const QUrl url {tracker};
@ -140,7 +148,7 @@ void BaseFilterWidget::toggleFilter(bool checked)
if (checked) if (checked)
applyFilter(currentRow()); applyFilter(currentRow());
else else
applyFilter(0); applyFilter(ALL_ROW);
} }
StatusFilterWidget::StatusFilterWidget(QWidget *parent, TransferListWidget *transferList) StatusFilterWidget::StatusFilterWidget(QWidget *parent, TransferListWidget *transferList)
@ -290,7 +298,7 @@ void TrackerFiltersList::addItem(const QString &tracker, const QString &hash)
trackerItem = item(rowFromTracker(host)); trackerItem = item(rowFromTracker(host));
} }
else { else {
trackerItem = item(1); trackerItem = item(TRACKERLESS_ROW);
} }
} }
else { else {
@ -306,8 +314,8 @@ void TrackerFiltersList::addItem(const QString &tracker, const QString &hash)
m_trackers.insert(host, tmp); m_trackers.insert(host, tmp);
if (host == "") { if (host == "") {
trackerItem->setText(tr("Trackerless (%1)").arg(tmp.size())); trackerItem->setText(tr("Trackerless (%1)").arg(tmp.size()));
if (currentRow() == 1) if (currentRow() == TRACKERLESS_ROW)
applyFilter(1); applyFilter(TRACKERLESS_ROW);
return; return;
} }
@ -359,7 +367,7 @@ void TrackerFiltersList::removeItem(const QString &tracker, const QString &hash)
} }
else { else {
row = 1; row = 1;
trackerItem = item(1); trackerItem = item(TRACKERLESS_ROW);
trackerItem->setText(tr("Trackerless (%1)").arg(tmp.size())); trackerItem->setText(tr("Trackerless (%1)").arg(tmp.size()));
} }
@ -402,9 +410,9 @@ void TrackerFiltersList::trackerSuccess(const QString &hash, const QString &trac
errored.removeAll(tracker); errored.removeAll(tracker);
if (errored.empty()) { if (errored.empty()) {
m_errors.remove(hash); m_errors.remove(hash);
item(2)->setText(tr("Error (%1)").arg(m_errors.size())); item(ERROR_ROW)->setText(tr("Error (%1)").arg(m_errors.size()));
if (currentRow() == 2) if (currentRow() == ERROR_ROW)
applyFilter(2); applyFilter(ERROR_ROW);
} }
else { else {
m_errors.insert(hash, errored); m_errors.insert(hash, errored);
@ -415,9 +423,9 @@ void TrackerFiltersList::trackerSuccess(const QString &hash, const QString &trac
warned.removeAll(tracker); warned.removeAll(tracker);
if (warned.empty()) { if (warned.empty()) {
m_warnings.remove(hash); m_warnings.remove(hash);
item(3)->setText(tr("Warning (%1)").arg(m_warnings.size())); item(WARNING_ROW)->setText(tr("Warning (%1)").arg(m_warnings.size()));
if (currentRow() == 3) if (currentRow() == WARNING_ROW)
applyFilter(3); applyFilter(WARNING_ROW);
} }
else { else {
m_warnings.insert(hash, warned); m_warnings.insert(hash, warned);
@ -434,10 +442,10 @@ void TrackerFiltersList::trackerError(const QString &hash, const QString &tracke
trackers.append(tracker); trackers.append(tracker);
m_errors.insert(hash, trackers); m_errors.insert(hash, trackers);
item(2)->setText(tr("Error (%1)").arg(m_errors.size())); item(ERROR_ROW)->setText(tr("Error (%1)").arg(m_errors.size()));
if (currentRow() == 2) if (currentRow() == ERROR_ROW)
applyFilter(2); applyFilter(ERROR_ROW);
} }
void TrackerFiltersList::trackerWarning(const QString &hash, const QString &tracker) void TrackerFiltersList::trackerWarning(const QString &hash, const QString &tracker)
@ -449,10 +457,10 @@ void TrackerFiltersList::trackerWarning(const QString &hash, const QString &trac
trackers.append(tracker); trackers.append(tracker);
m_warnings.insert(hash, trackers); m_warnings.insert(hash, trackers);
item(3)->setText(tr("Warning (%1)").arg(m_warnings.size())); item(WARNING_ROW)->setText(tr("Warning (%1)").arg(m_warnings.size()));
if (currentRow() == 3) if (currentRow() == WARNING_ROW)
applyFilter(3); applyFilter(WARNING_ROW);
} }
void TrackerFiltersList::downloadFavicon(const QString &url) void TrackerFiltersList::downloadFavicon(const QString &url)
@ -513,9 +521,9 @@ void TrackerFiltersList::showMenu(const QPoint &)
menu->popup(QCursor::pos()); menu->popup(QCursor::pos());
} }
void TrackerFiltersList::applyFilter(int row) void TrackerFiltersList::applyFilter(const int row)
{ {
if (row == 0) if (row == ALL_ROW)
transferList->applyTrackerFilterAll(); transferList->applyTrackerFilterAll();
else if (isVisible()) else if (isVisible())
transferList->applyTrackerFilter(getHashes(row)); transferList->applyTrackerFilter(getHashes(row));
@ -532,7 +540,7 @@ void TrackerFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torre
if (trackers.isEmpty()) if (trackers.isEmpty())
addItem("", hash); addItem("", hash);
item(0)->setText(tr("All (%1)", "this is for the tracker filter").arg(++m_totalTorrents)); item(ALL_ROW)->setText(tr("All (%1)", "this is for the tracker filter").arg(++m_totalTorrents));
} }
void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const torrent) void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const torrent)
@ -546,7 +554,7 @@ void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *cons
if (trackers.isEmpty()) if (trackers.isEmpty())
removeItem("", hash); removeItem("", hash);
item(0)->setText(tr("All (%1)", "this is for the tracker filter").arg(--m_totalTorrents)); item(ALL_ROW)->setText(tr("All (%1)", "this is for the tracker filter").arg(--m_totalTorrents));
} }
QString TrackerFiltersList::trackerFromRow(int row) const QString TrackerFiltersList::trackerFromRow(int row) const
@ -586,11 +594,11 @@ QString TrackerFiltersList::getHost(const QString &tracker) const
QStringList TrackerFiltersList::getHashes(const int row) const QStringList TrackerFiltersList::getHashes(const int row) const
{ {
switch (row) { switch (row) {
case 1: case TRACKERLESS_ROW:
return m_trackers.value(""); return m_trackers.value("");
case 2: case ERROR_ROW:
return m_errors.keys(); return m_errors.keys();
case 3: case WARNING_ROW:
return m_warnings.keys(); return m_warnings.keys();
default: default:
return m_trackers.value(trackerFromRow(row)); return m_trackers.value(trackerFromRow(row));

Loading…
Cancel
Save