qBittorrent
TorrentFilter Class Reference

#include <torrentfilter.h>

Collaboration diagram for TorrentFilter:

Public Types

enum  Type {
  All , Downloading , Seeding , Completed ,
  Resumed , Paused , Active , Inactive ,
  Stalled , StalledUploading , StalledDownloading , Checking ,
  Errored
}
 

Public Member Functions

 TorrentFilter ()=default
 
 TorrentFilter (Type type, const TorrentIDSet &idSet=AnyID, const QString &category=AnyCategory, const QString &tag=AnyTag)
 
 TorrentFilter (const QString &filter, const TorrentIDSet &idSet=AnyID, const QString &category=AnyCategory, const QString &tags=AnyTag)
 
bool setType (Type type)
 
bool setTypeByName (const QString &filter)
 
bool setTorrentIDSet (const TorrentIDSet &idSet)
 
bool setCategory (const QString &category)
 
bool setTag (const QString &tag)
 
bool match (const BitTorrent::Torrent *torrent) const
 

Static Public Attributes

static const QString AnyCategory
 
static const TorrentIDSet AnyID {{}}
 
static const QString AnyTag
 
static const TorrentFilter DownloadingTorrent
 
static const TorrentFilter SeedingTorrent
 
static const TorrentFilter CompletedTorrent
 
static const TorrentFilter PausedTorrent
 
static const TorrentFilter ResumedTorrent
 
static const TorrentFilter ActiveTorrent
 
static const TorrentFilter InactiveTorrent
 
static const TorrentFilter StalledTorrent
 
static const TorrentFilter StalledUploadingTorrent
 
static const TorrentFilter StalledDownloadingTorrent
 
static const TorrentFilter CheckingTorrent
 
static const TorrentFilter ErroredTorrent
 

Private Member Functions

bool matchState (const BitTorrent::Torrent *torrent) const
 
bool matchHash (const BitTorrent::Torrent *torrent) const
 
bool matchCategory (const BitTorrent::Torrent *torrent) const
 
bool matchTag (const BitTorrent::Torrent *torrent) const
 

Private Attributes

Type m_type {All}
 
QString m_category
 
QString m_tag
 
TorrentIDSet m_idSet
 

Detailed Description

Definition at line 43 of file torrentfilter.h.

Member Enumeration Documentation

◆ Type

Enumerator
All 
Downloading 
Seeding 
Completed 
Resumed 
Paused 
Active 
Inactive 
Stalled 
StalledUploading 
StalledDownloading 
Checking 
Errored 

Definition at line 46 of file torrentfilter.h.

Constructor & Destructor Documentation

◆ TorrentFilter() [1/3]

TorrentFilter::TorrentFilter ( )
default

◆ TorrentFilter() [2/3]

TorrentFilter::TorrentFilter ( Type  type,
const TorrentIDSet idSet = AnyID,
const QString &  category = AnyCategory,
const QString &  tag = AnyTag 
)

Definition at line 53 of file torrentfilter.cpp.

54  : m_type(type)
55  , m_category(category)
56  , m_tag(tag)
57  , m_idSet(idSet)
58 {
59 }
QString m_category
TorrentIDSet m_idSet

◆ TorrentFilter() [3/3]

TorrentFilter::TorrentFilter ( const QString &  filter,
const TorrentIDSet idSet = AnyID,
const QString &  category = AnyCategory,
const QString &  tags = AnyTag 
)

Definition at line 61 of file torrentfilter.cpp.

62  : m_type(All)
63  , m_category(category)
64  , m_tag(tag)
65  , m_idSet(idSet)
66 {
67  setTypeByName(filter);
68 }
bool setTypeByName(const QString &filter)

References setTypeByName().

Here is the call graph for this function:

Member Function Documentation

◆ match()

bool TorrentFilter::match ( const BitTorrent::Torrent torrent) const

Definition at line 152 of file torrentfilter.cpp.

153 {
154  if (!torrent) return false;
155 
156  return (matchState(torrent) && matchHash(torrent) && matchCategory(torrent) && matchTag(torrent));
157 }
bool matchTag(const BitTorrent::Torrent *torrent) const
bool matchHash(const BitTorrent::Torrent *torrent) const
bool matchState(const BitTorrent::Torrent *torrent) const
bool matchCategory(const BitTorrent::Torrent *torrent) const

References matchCategory(), matchHash(), matchState(), and matchTag().

Referenced by TorrentsController::infoAction(), and TransferListSortModel::matchFilter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ matchCategory()

bool TorrentFilter::matchCategory ( const BitTorrent::Torrent torrent) const
private

Definition at line 204 of file torrentfilter.cpp.

205 {
206  if (m_category.isNull()) return true;
207 
208  return (torrent->belongsToCategory(m_category));
209 }
virtual bool belongsToCategory(const QString &category) const =0

References BitTorrent::Torrent::belongsToCategory(), and m_category.

Referenced by match().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ matchHash()

bool TorrentFilter::matchHash ( const BitTorrent::Torrent torrent) const
private

Definition at line 197 of file torrentfilter.cpp.

198 {
199  if (m_idSet == AnyID) return true;
200 
201  return m_idSet.contains(torrent->id());
202 }
TorrentID id() const
Definition: torrent.cpp:54
static const TorrentIDSet AnyID
Definition: torrentfilter.h:65

References AnyID, BitTorrent::Torrent::id(), and m_idSet.

Referenced by match().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ matchState()

bool TorrentFilter::matchState ( const BitTorrent::Torrent torrent) const
private

Definition at line 159 of file torrentfilter.cpp.

160 {
161  switch (m_type)
162  {
163  case All:
164  return true;
165  case Downloading:
166  return torrent->isDownloading();
167  case Seeding:
168  return torrent->isUploading();
169  case Completed:
170  return torrent->isCompleted();
171  case Paused:
172  return torrent->isPaused();
173  case Resumed:
174  return torrent->isResumed();
175  case Active:
176  return torrent->isActive();
177  case Inactive:
178  return torrent->isInactive();
179  case Stalled:
182  case StalledUploading:
184  case StalledDownloading:
186  case Checking:
190  case Errored:
191  return torrent->isErrored();
192  default: // All
193  return true;
194  }
195 }
virtual bool isErrored() const =0
virtual bool isDownloading() const =0
virtual bool isCompleted() const =0
virtual bool isInactive() const =0
virtual TorrentState state() const =0
bool isResumed() const
Definition: torrent.cpp:59
virtual bool isActive() const =0
virtual bool isPaused() const =0
virtual bool isUploading() const =0

References Active, All, Checking, BitTorrent::CheckingDownloading, BitTorrent::CheckingResumeData, BitTorrent::CheckingUploading, Completed, Downloading, Errored, Inactive, BitTorrent::Torrent::isActive(), BitTorrent::Torrent::isCompleted(), BitTorrent::Torrent::isDownloading(), BitTorrent::Torrent::isErrored(), BitTorrent::Torrent::isInactive(), BitTorrent::Torrent::isPaused(), BitTorrent::Torrent::isResumed(), BitTorrent::Torrent::isUploading(), m_type, Paused, Resumed, Seeding, Stalled, BitTorrent::StalledDownloading, StalledDownloading, BitTorrent::StalledUploading, StalledUploading, and BitTorrent::Torrent::state().

Referenced by match().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ matchTag()

bool TorrentFilter::matchTag ( const BitTorrent::Torrent torrent) const
private

Definition at line 211 of file torrentfilter.cpp.

212 {
213  // Empty tag is a special value to indicate we're filtering for untagged torrents.
214  if (m_tag.isNull()) return true;
215  if (m_tag.isEmpty()) return torrent->tags().isEmpty();
216 
217  return (torrent->hasTag(m_tag));
218 }
virtual TagSet tags() const =0
virtual bool hasTag(const QString &tag) const =0
bool isEmpty() const
Definition: orderedset.h:74

References BitTorrent::Torrent::hasTag(), OrderedSet< T, Compare >::isEmpty(), m_tag, and BitTorrent::Torrent::tags().

Referenced by match().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCategory()

bool TorrentFilter::setCategory ( const QString &  category)

Definition at line 124 of file torrentfilter.cpp.

125 {
126  // QString::operator==() doesn't distinguish between empty and null strings.
127  if ((m_category != category)
128  || (m_category.isNull() && !category.isNull())
129  || (!m_category.isNull() && category.isNull()))
130  {
131  m_category = category;
132  return true;
133  }
134 
135  return false;
136 }

References m_category.

Referenced by TransferListSortModel::disableCategoryFilter(), and TransferListSortModel::setCategoryFilter().

Here is the caller graph for this function:

◆ setTag()

bool TorrentFilter::setTag ( const QString &  tag)

Definition at line 138 of file torrentfilter.cpp.

139 {
140  // QString::operator==() doesn't distinguish between empty and null strings.
141  if ((m_tag != tag)
142  || (m_tag.isNull() && !tag.isNull())
143  || (!m_tag.isNull() && tag.isNull()))
144  {
145  m_tag = tag;
146  return true;
147  }
148 
149  return false;
150 }

References m_tag.

Referenced by TransferListSortModel::disableTagFilter(), and TransferListSortModel::setTagFilter().

Here is the caller graph for this function:

◆ setTorrentIDSet()

bool TorrentFilter::setTorrentIDSet ( const TorrentIDSet idSet)

Definition at line 113 of file torrentfilter.cpp.

114 {
115  if (m_idSet != idSet)
116  {
117  m_idSet = idSet;
118  return true;
119  }
120 
121  return false;
122 }

References m_idSet.

Referenced by TransferListSortModel::disableTrackerFilter(), and TransferListSortModel::setTrackerFilter().

Here is the caller graph for this function:

◆ setType()

bool TorrentFilter::setType ( Type  type)

Definition at line 70 of file torrentfilter.cpp.

71 {
72  if (m_type != type)
73  {
74  m_type = type;
75  return true;
76  }
77 
78  return false;
79 }

References m_type.

Referenced by TransferListSortModel::setStatusFilter(), and setTypeByName().

Here is the caller graph for this function:

◆ setTypeByName()

bool TorrentFilter::setTypeByName ( const QString &  filter)

Definition at line 81 of file torrentfilter.cpp.

82 {
83  Type type = All;
84 
85  if (filter == "downloading")
86  type = Downloading;
87  else if (filter == "seeding")
88  type = Seeding;
89  else if (filter == "completed")
90  type = Completed;
91  else if (filter == "paused")
92  type = Paused;
93  else if (filter == "resumed")
94  type = Resumed;
95  else if (filter == "active")
96  type = Active;
97  else if (filter == "inactive")
98  type = Inactive;
99  else if (filter == "stalled")
100  type = Stalled;
101  else if (filter == "stalled_uploading")
102  type = StalledUploading;
103  else if (filter == "stalled_downloading")
104  type = StalledDownloading;
105  else if (filter == "checking")
106  type = Checking;
107  else if (filter == "errored")
108  type = Errored;
109 
110  return setType(type);
111 }
bool setType(Type type)

References Active, All, Checking, Completed, Downloading, Errored, Inactive, Paused, Resumed, Seeding, setType(), Stalled, StalledDownloading, and StalledUploading.

Referenced by TorrentFilter().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ ActiveTorrent

const TorrentFilter TorrentFilter::ActiveTorrent
static

Definition at line 73 of file torrentfilter.h.

◆ AnyCategory

const QString TorrentFilter::AnyCategory
static

Definition at line 64 of file torrentfilter.h.

Referenced by TransferListSortModel::disableCategoryFilter().

◆ AnyID

const TorrentIDSet TorrentFilter::AnyID {{}}
static

◆ AnyTag

const QString TorrentFilter::AnyTag
static

Definition at line 66 of file torrentfilter.h.

Referenced by TransferListSortModel::disableTagFilter().

◆ CheckingTorrent

const TorrentFilter TorrentFilter::CheckingTorrent
static

Definition at line 78 of file torrentfilter.h.

◆ CompletedTorrent

const TorrentFilter TorrentFilter::CompletedTorrent
static

Definition at line 70 of file torrentfilter.h.

◆ DownloadingTorrent

const TorrentFilter TorrentFilter::DownloadingTorrent
static

Definition at line 68 of file torrentfilter.h.

◆ ErroredTorrent

const TorrentFilter TorrentFilter::ErroredTorrent
static

Definition at line 79 of file torrentfilter.h.

◆ InactiveTorrent

const TorrentFilter TorrentFilter::InactiveTorrent
static

Definition at line 74 of file torrentfilter.h.

◆ m_category

QString TorrentFilter::m_category
private

Definition at line 102 of file torrentfilter.h.

Referenced by matchCategory(), and setCategory().

◆ m_idSet

TorrentIDSet TorrentFilter::m_idSet
private

Definition at line 104 of file torrentfilter.h.

Referenced by matchHash(), and setTorrentIDSet().

◆ m_tag

QString TorrentFilter::m_tag
private

Definition at line 103 of file torrentfilter.h.

Referenced by matchTag(), and setTag().

◆ m_type

Type TorrentFilter::m_type {All}
private

Definition at line 101 of file torrentfilter.h.

Referenced by matchState(), and setType().

◆ PausedTorrent

const TorrentFilter TorrentFilter::PausedTorrent
static

Definition at line 71 of file torrentfilter.h.

◆ ResumedTorrent

const TorrentFilter TorrentFilter::ResumedTorrent
static

Definition at line 72 of file torrentfilter.h.

◆ SeedingTorrent

const TorrentFilter TorrentFilter::SeedingTorrent
static

Definition at line 69 of file torrentfilter.h.

◆ StalledDownloadingTorrent

const TorrentFilter TorrentFilter::StalledDownloadingTorrent
static

Definition at line 77 of file torrentfilter.h.

◆ StalledTorrent

const TorrentFilter TorrentFilter::StalledTorrent
static

Definition at line 75 of file torrentfilter.h.

◆ StalledUploadingTorrent

const TorrentFilter TorrentFilter::StalledUploadingTorrent
static

Definition at line 76 of file torrentfilter.h.


The documentation for this class was generated from the following files: