mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-10 17:35:00 -06:00
committed by
GitHub
parent
65771d66fc
commit
7a41192597
@@ -60,7 +60,7 @@ namespace
|
||||
{
|
||||
TagSet tags;
|
||||
for (const QJsonValue &jsonVal : jsonArr)
|
||||
tags.insert(jsonVal.toString());
|
||||
tags.insert(Tag(jsonVal.toString()));
|
||||
|
||||
return tags;
|
||||
}
|
||||
@@ -68,8 +68,8 @@ namespace
|
||||
QJsonArray serializeTagSet(const TagSet &tags)
|
||||
{
|
||||
QJsonArray arr;
|
||||
for (const QString &tag : tags)
|
||||
arr.append(tag);
|
||||
for (const Tag &tag : tags)
|
||||
arr.append(tag.toString());
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
@@ -85,8 +85,8 @@ namespace
|
||||
{
|
||||
ListType entryList;
|
||||
entryList.reserve(input.size());
|
||||
for (const QString &setValue : input)
|
||||
entryList.emplace_back(setValue.toStdString());
|
||||
for (const Tag &setValue : input)
|
||||
entryList.emplace_back(setValue.toString().toStdString());
|
||||
return entryList;
|
||||
}
|
||||
}
|
||||
@@ -263,7 +263,7 @@ BitTorrent::LoadResumeDataResult BitTorrent::BencodeResumeDataStorage::loadTorre
|
||||
{
|
||||
for (int i = 0; i < tagsNode.list_size(); ++i)
|
||||
{
|
||||
const QString tag = fromLTString(tagsNode.list_string_value_at(i));
|
||||
const Tag tag {fromLTString(tagsNode.list_string_value_at(i))};
|
||||
torrentParams.tags.insert(tag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -854,7 +854,7 @@ namespace
|
||||
query.bindValue(DB_COLUMN_NAME.placeholder, m_resumeData.name);
|
||||
query.bindValue(DB_COLUMN_CATEGORY.placeholder, m_resumeData.category);
|
||||
query.bindValue(DB_COLUMN_TAGS.placeholder, (m_resumeData.tags.isEmpty()
|
||||
? QString() : m_resumeData.tags.join(u","_s)));
|
||||
? QString() : QStringList(m_resumeData.tags.cbegin(), m_resumeData.tags.cend()).join(u","_s)));
|
||||
query.bindValue(DB_COLUMN_CONTENT_LAYOUT.placeholder, Utils::String::fromEnum(m_resumeData.contentLayout));
|
||||
query.bindValue(DB_COLUMN_RATIO_LIMIT.placeholder, static_cast<int>(m_resumeData.ratioLimit * 1000));
|
||||
query.bindValue(DB_COLUMN_SEEDING_TIME_LIMIT.placeholder, m_resumeData.seedingTimeLimit);
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <QObject>
|
||||
|
||||
#include "base/pathfwd.h"
|
||||
#include "base/tagset.h"
|
||||
#include "addtorrentparams.h"
|
||||
#include "categoryoptions.h"
|
||||
#include "trackerentry.h"
|
||||
@@ -177,11 +178,10 @@ namespace BitTorrent
|
||||
virtual Path suggestedSavePath(const QString &categoryName, std::optional<bool> useAutoTMM) const = 0;
|
||||
virtual Path suggestedDownloadPath(const QString &categoryName, std::optional<bool> useAutoTMM) const = 0;
|
||||
|
||||
static bool isValidTag(const QString &tag);
|
||||
virtual QSet<QString> 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;
|
||||
virtual TagSet tags() const = 0;
|
||||
virtual bool hasTag(const Tag &tag) const = 0;
|
||||
virtual bool addTag(const Tag &tag) = 0;
|
||||
virtual bool removeTag(const Tag &tag) = 0;
|
||||
|
||||
// Torrent Management Mode subsystem (TMM)
|
||||
//
|
||||
@@ -473,8 +473,8 @@ namespace BitTorrent
|
||||
void speedLimitModeChanged(bool alternative);
|
||||
void statsUpdated();
|
||||
void subcategoriesSupportChanged();
|
||||
void tagAdded(const QString &tag);
|
||||
void tagRemoved(const QString &tag);
|
||||
void tagAdded(const Tag &tag);
|
||||
void tagRemoved(const Tag &tag);
|
||||
void torrentAboutToBeRemoved(Torrent *torrent);
|
||||
void torrentAdded(Torrent *torrent);
|
||||
void torrentCategoryChanged(Torrent *torrent, const QString &oldCategory);
|
||||
@@ -487,8 +487,8 @@ namespace BitTorrent
|
||||
void torrentSavingModeChanged(Torrent *torrent);
|
||||
void torrentsLoaded(const QVector<Torrent *> &torrents);
|
||||
void torrentsUpdated(const QVector<Torrent *> &torrents);
|
||||
void torrentTagAdded(Torrent *torrent, const QString &tag);
|
||||
void torrentTagRemoved(Torrent *torrent, const QString &tag);
|
||||
void torrentTagAdded(Torrent *torrent, const Tag &tag);
|
||||
void torrentTagRemoved(Torrent *torrent, const Tag &tag);
|
||||
void trackerError(Torrent *torrent, const QString &tracker);
|
||||
void trackersAdded(Torrent *torrent, const QVector<TrackerEntry> &trackers);
|
||||
void trackersChanged(Torrent *torrent);
|
||||
|
||||
@@ -80,12 +80,9 @@
|
||||
#include "base/net/proxyconfigurationmanager.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/profile.h"
|
||||
#include "base/torrentfilter.h"
|
||||
#include "base/unicodestrings.h"
|
||||
#include "base/utils/bytearray.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/io.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "base/utils/net.h"
|
||||
#include "base/utils/random.h"
|
||||
#include "base/version.h"
|
||||
@@ -373,11 +370,6 @@ QString Session::parentCategoryName(const QString &category)
|
||||
return {};
|
||||
}
|
||||
|
||||
bool Session::isValidTag(const QString &tag)
|
||||
{
|
||||
return (!tag.trimmed().isEmpty() && !tag.contains(u','));
|
||||
}
|
||||
|
||||
QStringList Session::expandCategory(const QString &category)
|
||||
{
|
||||
QStringList result;
|
||||
@@ -560,7 +552,8 @@ SessionImpl::SessionImpl(QObject *parent)
|
||||
}
|
||||
|
||||
const QStringList storedTags = m_storedTags.get();
|
||||
m_tags = {storedTags.cbegin(), storedTags.cend()};
|
||||
m_tags.insert(storedTags.cbegin(), storedTags.cend());
|
||||
std::erase_if(m_tags, [](const Tag &tag) { return !tag.isValid(); });
|
||||
|
||||
updateSeedingLimitTimer();
|
||||
populateAdditionalTrackers();
|
||||
@@ -1022,34 +1015,37 @@ Path SessionImpl::suggestedDownloadPath(const QString &categoryName, std::option
|
||||
return path;
|
||||
}
|
||||
|
||||
QSet<QString> SessionImpl::tags() const
|
||||
TagSet SessionImpl::tags() const
|
||||
{
|
||||
return m_tags;
|
||||
}
|
||||
|
||||
bool SessionImpl::hasTag(const QString &tag) const
|
||||
bool SessionImpl::hasTag(const Tag &tag) const
|
||||
{
|
||||
return m_tags.contains(tag);
|
||||
}
|
||||
|
||||
bool SessionImpl::addTag(const QString &tag)
|
||||
bool SessionImpl::addTag(const Tag &tag)
|
||||
{
|
||||
if (!isValidTag(tag) || hasTag(tag))
|
||||
if (!tag.isValid() || hasTag(tag))
|
||||
return false;
|
||||
|
||||
m_tags.insert(tag);
|
||||
m_storedTags = m_tags.values();
|
||||
m_storedTags = QStringList(m_tags.cbegin(), m_tags.cend());
|
||||
|
||||
emit tagAdded(tag);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SessionImpl::removeTag(const QString &tag)
|
||||
bool SessionImpl::removeTag(const Tag &tag)
|
||||
{
|
||||
if (m_tags.remove(tag))
|
||||
{
|
||||
for (TorrentImpl *const torrent : asConst(m_torrents))
|
||||
torrent->removeTag(tag);
|
||||
m_storedTags = m_tags.values();
|
||||
|
||||
m_storedTags = QStringList(m_tags.cbegin(), m_tags.cend());
|
||||
|
||||
emit tagRemoved(tag);
|
||||
return true;
|
||||
}
|
||||
@@ -1472,7 +1468,7 @@ void SessionImpl::processNextResumeData(ResumeSessionContext *context)
|
||||
}
|
||||
}
|
||||
|
||||
std::erase_if(resumeData.tags, [this, &torrentID](const QString &tag)
|
||||
std::erase_if(resumeData.tags, [this, &torrentID](const Tag &tag)
|
||||
{
|
||||
if (hasTag(tag))
|
||||
return false;
|
||||
@@ -1481,12 +1477,12 @@ void SessionImpl::processNextResumeData(ResumeSessionContext *context)
|
||||
{
|
||||
LogMsg(tr("Detected inconsistent data: tag is missing from the configuration file."
|
||||
" Tag will be recovered."
|
||||
" Torrent: \"%1\". Tag: \"%2\"").arg(torrentID.toString(), tag), Log::WARNING);
|
||||
" Torrent: \"%1\". Tag: \"%2\"").arg(torrentID.toString(), tag.toString()), Log::WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
LogMsg(tr("Detected inconsistent data: invalid tag. Torrent: \"%1\". Tag: \"%2\"")
|
||||
.arg(torrentID.toString(), tag), Log::WARNING);
|
||||
.arg(torrentID.toString(), tag.toString()), Log::WARNING);
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -2701,7 +2697,7 @@ LoadTorrentParams SessionImpl::initLoadTorrentParams(const AddTorrentParams &add
|
||||
}
|
||||
}
|
||||
|
||||
for (const QString &tag : addTorrentParams.tags)
|
||||
for (const Tag &tag : addTorrentParams.tags)
|
||||
{
|
||||
if (hasTag(tag) || addTag(tag))
|
||||
loadTorrentParams.tags.insert(tag);
|
||||
@@ -4863,12 +4859,12 @@ void SessionImpl::handleTorrentCategoryChanged(TorrentImpl *const torrent, const
|
||||
emit torrentCategoryChanged(torrent, oldCategory);
|
||||
}
|
||||
|
||||
void SessionImpl::handleTorrentTagAdded(TorrentImpl *const torrent, const QString &tag)
|
||||
void SessionImpl::handleTorrentTagAdded(TorrentImpl *const torrent, const Tag &tag)
|
||||
{
|
||||
emit torrentTagAdded(torrent, tag);
|
||||
}
|
||||
|
||||
void SessionImpl::handleTorrentTagRemoved(TorrentImpl *const torrent, const QString &tag)
|
||||
void SessionImpl::handleTorrentTagRemoved(TorrentImpl *const torrent, const Tag &tag)
|
||||
{
|
||||
emit torrentTagRemoved(torrent, tag);
|
||||
}
|
||||
|
||||
@@ -156,10 +156,10 @@ namespace BitTorrent
|
||||
Path suggestedSavePath(const QString &categoryName, std::optional<bool> useAutoTMM) const override;
|
||||
Path suggestedDownloadPath(const QString &categoryName, std::optional<bool> useAutoTMM) const override;
|
||||
|
||||
QSet<QString> tags() const override;
|
||||
bool hasTag(const QString &tag) const override;
|
||||
bool addTag(const QString &tag) override;
|
||||
bool removeTag(const QString &tag) override;
|
||||
TagSet tags() const override;
|
||||
bool hasTag(const Tag &tag) const override;
|
||||
bool addTag(const Tag &tag) override;
|
||||
bool removeTag(const Tag &tag) override;
|
||||
|
||||
bool isAutoTMMDisabledByDefault() const override;
|
||||
void setAutoTMMDisabledByDefault(bool value) override;
|
||||
@@ -433,8 +433,8 @@ namespace BitTorrent
|
||||
void handleTorrentNameChanged(TorrentImpl *torrent);
|
||||
void handleTorrentSavePathChanged(TorrentImpl *torrent);
|
||||
void handleTorrentCategoryChanged(TorrentImpl *torrent, const QString &oldCategory);
|
||||
void handleTorrentTagAdded(TorrentImpl *torrent, const QString &tag);
|
||||
void handleTorrentTagRemoved(TorrentImpl *torrent, const QString &tag);
|
||||
void handleTorrentTagAdded(TorrentImpl *torrent, const Tag &tag);
|
||||
void handleTorrentTagRemoved(TorrentImpl *torrent, const Tag &tag);
|
||||
void handleTorrentSavingModeChanged(TorrentImpl *torrent);
|
||||
void handleTorrentMetadataReceived(TorrentImpl *torrent);
|
||||
void handleTorrentPaused(TorrentImpl *torrent);
|
||||
@@ -755,7 +755,7 @@ namespace BitTorrent
|
||||
QSet<TorrentID> m_needSaveResumeDataTorrents;
|
||||
QHash<TorrentID, TorrentID> m_changedTorrentIDs;
|
||||
QMap<QString, CategoryOptions> m_categories;
|
||||
QSet<QString> m_tags;
|
||||
TagSet m_tags;
|
||||
|
||||
// This field holds amounts of peers reported by trackers in their responses to announces
|
||||
// (torrent.tracker_name.tracker_local_endpoint.protocol_version.num_peers)
|
||||
|
||||
@@ -202,9 +202,9 @@ namespace BitTorrent
|
||||
virtual bool setCategory(const QString &category) = 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;
|
||||
virtual bool hasTag(const Tag &tag) const = 0;
|
||||
virtual bool addTag(const Tag &tag) = 0;
|
||||
virtual bool removeTag(const Tag &tag) = 0;
|
||||
virtual void removeAllTags() = 0;
|
||||
|
||||
virtual int piecesCount() const = 0;
|
||||
|
||||
@@ -863,14 +863,14 @@ TagSet TorrentImpl::tags() const
|
||||
return m_tags;
|
||||
}
|
||||
|
||||
bool TorrentImpl::hasTag(const QString &tag) const
|
||||
bool TorrentImpl::hasTag(const Tag &tag) const
|
||||
{
|
||||
return m_tags.contains(tag);
|
||||
}
|
||||
|
||||
bool TorrentImpl::addTag(const QString &tag)
|
||||
bool TorrentImpl::addTag(const Tag &tag)
|
||||
{
|
||||
if (!m_session->isValidTag(tag))
|
||||
if (!tag.isValid())
|
||||
return false;
|
||||
if (hasTag(tag))
|
||||
return false;
|
||||
@@ -886,7 +886,7 @@ bool TorrentImpl::addTag(const QString &tag)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TorrentImpl::removeTag(const QString &tag)
|
||||
bool TorrentImpl::removeTag(const Tag &tag)
|
||||
{
|
||||
if (m_tags.remove(tag))
|
||||
{
|
||||
@@ -899,7 +899,7 @@ bool TorrentImpl::removeTag(const QString &tag)
|
||||
|
||||
void TorrentImpl::removeAllTags()
|
||||
{
|
||||
for (const QString &tag : asConst(tags()))
|
||||
for (const Tag &tag : asConst(tags()))
|
||||
removeTag(tag);
|
||||
}
|
||||
|
||||
|
||||
@@ -128,9 +128,9 @@ namespace BitTorrent
|
||||
bool setCategory(const QString &category) override;
|
||||
|
||||
TagSet tags() const override;
|
||||
bool hasTag(const QString &tag) const override;
|
||||
bool addTag(const QString &tag) override;
|
||||
bool removeTag(const QString &tag) override;
|
||||
bool hasTag(const Tag &tag) const override;
|
||||
bool addTag(const Tag &tag) override;
|
||||
bool removeTag(const Tag &tag) override;
|
||||
void removeAllTags() override;
|
||||
|
||||
int filesCount() const override;
|
||||
|
||||
Reference in New Issue
Block a user