Skip to content

Commit

Permalink
Merge pull request #13912 from Chocobo1/infohash
Browse files Browse the repository at this point in the history
Use the correct type when referring to info hash
  • Loading branch information
Chocobo1 authored Dec 8, 2020
2 parents 5c1c561 + 9f0429c commit d484c0e
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 160 deletions.
5 changes: 0 additions & 5 deletions src/base/bittorrent/infohash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ using namespace BitTorrent;

const int InfoHashTypeId = qRegisterMetaType<InfoHash>();

InfoHash::InfoHash()
: m_valid(false)
{
}

InfoHash::InfoHash(const lt::sha1_hash &nativeHash)
: m_valid(true)
, m_nativeHash(nativeHash)
Expand Down
4 changes: 2 additions & 2 deletions src/base/bittorrent/infohash.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace BitTorrent
class InfoHash
{
public:
InfoHash();
InfoHash() = default;
InfoHash(const lt::sha1_hash &nativeHash);
InfoHash(const QString &hashString);
InfoHash(const InfoHash &other) = default;
Expand All @@ -54,7 +54,7 @@ namespace BitTorrent
operator QString() const;

private:
bool m_valid;
bool m_valid = false;
lt::sha1_hash m_nativeHash;
QString m_hashString;
};
Expand Down
13 changes: 4 additions & 9 deletions src/base/torrentfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "bittorrent/torrenthandle.h"

const QString TorrentFilter::AnyCategory;
const QStringSet TorrentFilter::AnyHash = (QStringSet() << QString());
const InfoHashSet TorrentFilter::AnyHash {{}};
const QString TorrentFilter::AnyTag;

const TorrentFilter TorrentFilter::DownloadingTorrent(TorrentFilter::Downloading);
Expand All @@ -49,20 +49,15 @@ const TorrentFilter TorrentFilter::ErroredTorrent(TorrentFilter::Errored);

using BitTorrent::TorrentHandle;

TorrentFilter::TorrentFilter()
: m_type(All)
{
}

TorrentFilter::TorrentFilter(const Type type, const QStringSet &hashSet, const QString &category, const QString &tag)
TorrentFilter::TorrentFilter(const Type type, const InfoHashSet &hashSet, const QString &category, const QString &tag)
: m_type(type)
, m_category(category)
, m_tag(tag)
, m_hashSet(hashSet)
{
}

TorrentFilter::TorrentFilter(const QString &filter, const QStringSet &hashSet, const QString &category, const QString &tag)
TorrentFilter::TorrentFilter(const QString &filter, const InfoHashSet &hashSet, const QString &category, const QString &tag)
: m_type(All)
, m_category(category)
, m_tag(tag)
Expand Down Expand Up @@ -112,7 +107,7 @@ bool TorrentFilter::setTypeByName(const QString &filter)
return setType(type);
}

bool TorrentFilter::setHashSet(const QStringSet &hashSet)
bool TorrentFilter::setHashSet(const InfoHashSet &hashSet)
{
if (m_hashSet != hashSet)
{
Expand Down
18 changes: 10 additions & 8 deletions src/base/torrentfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
#include <QSet>
#include <QString>

typedef QSet<QString> QStringSet;
#include "base/bittorrent/infohash.h"

namespace BitTorrent
{
class TorrentHandle;
}

using InfoHashSet = QSet<BitTorrent::InfoHash>;

class TorrentFilter
{
public:
Expand All @@ -60,7 +62,7 @@ class TorrentFilter

// These mean any permutation, including no category / tag.
static const QString AnyCategory;
static const QStringSet AnyHash;
static const InfoHashSet AnyHash;
static const QString AnyTag;

static const TorrentFilter DownloadingTorrent;
Expand All @@ -75,15 +77,15 @@ class TorrentFilter
static const TorrentFilter StalledDownloadingTorrent;
static const TorrentFilter ErroredTorrent;

TorrentFilter();
TorrentFilter() = default;
// category & tags: pass empty string for uncategorized / untagged torrents.
// Pass null string (QString()) to disable filtering (i.e. all torrents).
TorrentFilter(Type type, const QStringSet &hashSet = AnyHash, const QString &category = AnyCategory, const QString &tag = AnyTag);
TorrentFilter(const QString &filter, const QStringSet &hashSet = AnyHash, const QString &category = AnyCategory, const QString &tags = AnyTag);
TorrentFilter(Type type, const InfoHashSet &hashSet = AnyHash, const QString &category = AnyCategory, const QString &tag = AnyTag);
TorrentFilter(const QString &filter, const InfoHashSet &hashSet = AnyHash, const QString &category = AnyCategory, const QString &tags = AnyTag);

bool setType(Type type);
bool setTypeByName(const QString &filter);
bool setHashSet(const QStringSet &hashSet);
bool setHashSet(const InfoHashSet &hashSet);
bool setCategory(const QString &category);
bool setTag(const QString &tag);

Expand All @@ -95,10 +97,10 @@ class TorrentFilter
bool matchCategory(const BitTorrent::TorrentHandle *torrent) const;
bool matchTag(const BitTorrent::TorrentHandle *torrent) const;

Type m_type;
Type m_type {All};
QString m_category;
QString m_tag;
QStringSet m_hashSet;
InfoHashSet m_hashSet;
};

#endif // TORRENTFILTER_H
6 changes: 3 additions & 3 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ MainWindow::MainWindow(QWidget *parent)
connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerlessStateChanged, m_transferListFiltersWidget, &TransferListFiltersWidget::changeTrackerless);

connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerSuccess
, m_transferListFiltersWidget, qOverload<BitTorrent::TorrentHandle *const, const QString &>(&TransferListFiltersWidget::trackerSuccess));
, m_transferListFiltersWidget, qOverload<const BitTorrent::TorrentHandle *, const QString &>(&TransferListFiltersWidget::trackerSuccess));
connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerError
, m_transferListFiltersWidget, qOverload<BitTorrent::TorrentHandle *const, const QString &>(&TransferListFiltersWidget::trackerError));
, m_transferListFiltersWidget, qOverload<const BitTorrent::TorrentHandle *, const QString &>(&TransferListFiltersWidget::trackerError));
connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackerWarning
, m_transferListFiltersWidget, qOverload<BitTorrent::TorrentHandle *const, const QString &>(&TransferListFiltersWidget::trackerWarning));
, m_transferListFiltersWidget, qOverload<const BitTorrent::TorrentHandle *, const QString &>(&TransferListFiltersWidget::trackerWarning));

#ifdef Q_OS_MACOS
// Increase top spacing to avoid tab overlapping
Expand Down
Loading

0 comments on commit d484c0e

Please sign in to comment.