Revise tag related implementations

Fix #12690.
This commit is contained in:
Chocobo1
2021-04-02 13:45:50 +08:00
parent ab6141edb7
commit fdc186c92f
20 changed files with 257 additions and 50 deletions

View File

@@ -30,10 +30,10 @@
#include <optional>
#include <QSet>
#include <QString>
#include <QVector>
#include "base/tagset.h"
#include "torrent.h"
#include "torrentcontentlayout.h"
@@ -45,7 +45,7 @@ namespace BitTorrent
{
QString name;
QString category;
QSet<QString> tags;
TagSet tags;
QString savePath;
bool disableTempPath = false; // e.g. for imported torrents
bool sequential = false;

View File

@@ -45,6 +45,7 @@
#include "base/global.h"
#include "base/logger.h"
#include "base/profile.h"
#include "base/tagset.h"
#include "base/utils/fs.h"
#include "base/utils/io.h"
#include "base/utils/string.h"
@@ -82,7 +83,7 @@ namespace
using ListType = lt::entry::list_type;
ListType setToEntryList(const QSet<QString> &input)
ListType setToEntryList(const TagSet &input)
{
ListType entryList;
entryList.reserve(input.size());

View File

@@ -30,9 +30,9 @@
#include <libtorrent/add_torrent_params.hpp>
#include <QSet>
#include <QString>
#include "base/tagset.h"
#include "torrent.h"
#include "torrentcontentlayout.h"
@@ -44,7 +44,7 @@ namespace BitTorrent
QString name;
QString category;
QSet<QString> tags;
TagSet tags;
QString savePath;
TorrentContentLayout contentLayout = TorrentContentLayout::Original;
TorrentOperatingMode operatingMode = TorrentOperatingMode::AutoManaged;

View File

@@ -33,6 +33,7 @@
#include <QString>
#include <QtContainerFwd>
#include "base/tagset.h"
#include "abstractfilestorage.h"
class QBitArray;
@@ -168,7 +169,7 @@ namespace BitTorrent
virtual bool belongsToCategory(const QString &category) const = 0;
virtual bool setCategory(const QString &category) = 0;
virtual QSet<QString> tags() const = 0;
virtual TagSet tags() const = 0;
virtual bool hasTag(const QString &tag) const = 0;
virtual bool addTag(const QString &tag) = 0;
virtual bool removeTag(const QString &tag) = 0;

View File

@@ -703,7 +703,7 @@ bool TorrentImpl::belongsToCategory(const QString &category) const
return false;
}
QSet<QString> TorrentImpl::tags() const
TagSet TorrentImpl::tags() const
{
return m_tags;
}
@@ -717,18 +717,18 @@ bool TorrentImpl::addTag(const QString &tag)
{
if (!Session::isValidTag(tag))
return false;
if (hasTag(tag))
return false;
if (!hasTag(tag))
if (!m_session->hasTag(tag))
{
if (!m_session->hasTag(tag))
if (!m_session->addTag(tag))
return false;
m_tags.insert(tag);
m_session->handleTorrentNeedSaveResumeData(this);
m_session->handleTorrentTagAdded(this, tag);
return true;
if (!m_session->addTag(tag))
return false;
}
return false;
m_tags.insert(tag);
m_session->handleTorrentNeedSaveResumeData(this);
m_session->handleTorrentTagAdded(this, tag);
return true;
}
bool TorrentImpl::removeTag(const QString &tag)

View File

@@ -42,10 +42,10 @@
#include <QMap>
#include <QObject>
#include <QQueue>
#include <QSet>
#include <QString>
#include <QVector>
#include "base/tagset.h"
#include "infohash.h"
#include "speedmonitor.h"
#include "torrent.h"
@@ -115,7 +115,7 @@ namespace BitTorrent
bool belongsToCategory(const QString &category) const override;
bool setCategory(const QString &category) override;
QSet<QString> tags() const override;
TagSet tags() const override;
bool hasTag(const QString &tag) const override;
bool addTag(const QString &tag) override;
bool removeTag(const QString &tag) override;
@@ -247,7 +247,7 @@ namespace BitTorrent
QString actualStorageLocation() const;
private:
typedef std::function<void ()> EventTrigger;
using EventTrigger = std::function<void ()>;
void updateStatus();
void updateStatus(const lt::torrent_status &nativeStatus);
@@ -315,7 +315,7 @@ namespace BitTorrent
QString m_name;
QString m_savePath;
QString m_category;
QSet<QString> m_tags;
TagSet m_tags;
qreal m_ratioLimit;
int m_seedingTimeLimit;
TorrentOperatingMode m_operatingMode;