Browse Source

Merge pull request #3447 from glassez/filters

Fix label filter. Closes #3429.
adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
256793aad7
  1. 8
      src/core/torrentfilter.cpp
  2. 15
      src/gui/transferlistfilterswidget.cpp
  3. 11
      src/gui/transferlistwidget.cpp
  4. 1
      src/gui/transferlistwidget.h

8
src/core/torrentfilter.cpp

@ -107,7 +107,10 @@ bool TorrentFilter::setHashSet(const QStringSet &hashSet)
bool TorrentFilter::setLabel(const QString &label) bool TorrentFilter::setLabel(const QString &label)
{ {
if (m_label != label) { // QString::operator==() doesn't distinguish between empty and null strings.
if ((m_label != label)
|| (m_label.isNull() && !label.isNull())
|| (!m_label.isNull() && label.isNull())) {
m_label = label; m_label = label;
return true; return true;
} }
@ -154,6 +157,7 @@ bool TorrentFilter::matchHash(BitTorrent::TorrentHandle *const torrent) const
bool TorrentFilter::matchLabel(BitTorrent::TorrentHandle *const torrent) const bool TorrentFilter::matchLabel(BitTorrent::TorrentHandle *const torrent) const
{ {
if (m_label == AnyLabel) return true; if (m_label.isNull()) return true;
else if (m_label.isEmpty()) return torrent->label().isEmpty();
else return (torrent->label() == m_label); else return (torrent->label() == m_label);
} }

15
src/gui/transferlistfilterswidget.cpp

@ -375,16 +375,7 @@ void LabelFiltersList::showMenu(QPoint)
void LabelFiltersList::applyFilter(int row) void LabelFiltersList::applyFilter(int row)
{ {
switch (row) { transferList->applyLabelFilter(labelFromRow(row));
case 0:
transferList->applyLabelFilterAll();
break;
case 1:
transferList->applyLabelFilter(QString());
break;
default:
transferList->applyLabelFilter(labelFromRow(row));
}
} }
void LabelFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torrent) void LabelFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torrent)
@ -407,7 +398,9 @@ void LabelFiltersList::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const
QString LabelFiltersList::labelFromRow(int row) const QString LabelFiltersList::labelFromRow(int row) const
{ {
Q_ASSERT(row > 1); if (row == 0) return QString(); // All
if (row == 1) return QLatin1String(""); // Unlabeled
const QString &label = item(row)->text(); const QString &label = item(row)->text();
QStringList parts = label.split(" "); QStringList parts = label.split(" ");
Q_ASSERT(parts.size() >= 2); Q_ASSERT(parts.size() >= 2);

11
src/gui/transferlistwidget.cpp

@ -832,15 +832,12 @@ void TransferListWidget::currentChanged(const QModelIndex& current, const QModel
emit currentTorrentChanged(torrent); emit currentTorrentChanged(torrent);
} }
void TransferListWidget::applyLabelFilterAll()
{
nameFilterModel->disableLabelFilter();
}
void TransferListWidget::applyLabelFilter(QString label) void TransferListWidget::applyLabelFilter(QString label)
{ {
qDebug("Applying Label filter: %s", qPrintable(label)); if (label.isNull())
nameFilterModel->setLabelFilter(label); nameFilterModel->disableLabelFilter();
else
nameFilterModel->setLabelFilter(label);
} }
void TransferListWidget::applyTrackerFilterAll() void TransferListWidget::applyTrackerFilterAll()

1
src/gui/transferlistwidget.h

@ -86,7 +86,6 @@ public slots:
void displayDLHoSMenu(const QPoint&); void displayDLHoSMenu(const QPoint&);
void applyNameFilter(const QString& name); void applyNameFilter(const QString& name);
void applyStatusFilter(int f); void applyStatusFilter(int f);
void applyLabelFilterAll();
void applyLabelFilter(QString label); void applyLabelFilter(QString label);
void applyTrackerFilterAll(); void applyTrackerFilterAll();
void applyTrackerFilter(const QStringList &hashes); void applyTrackerFilter(const QStringList &hashes);

Loading…
Cancel
Save