mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-22 22:33:34 -07:00
WebAPI: torrents setTags (upsert tags on torrents)
This commit is contained in:
parent
f9f4b60b83
commit
c04703750e
7 changed files with 43 additions and 0 deletions
|
@ -49,6 +49,7 @@
|
||||||
|
|
||||||
#include "base/path.h"
|
#include "base/path.h"
|
||||||
#include "base/settingvalue.h"
|
#include "base/settingvalue.h"
|
||||||
|
#include "base/tagset.h"
|
||||||
#include "base/utils/thread.h"
|
#include "base/utils/thread.h"
|
||||||
#include "addtorrentparams.h"
|
#include "addtorrentparams.h"
|
||||||
#include "cachestatus.h"
|
#include "cachestatus.h"
|
||||||
|
|
|
@ -209,6 +209,7 @@ namespace BitTorrent
|
||||||
virtual TagSet tags() const = 0;
|
virtual TagSet tags() const = 0;
|
||||||
virtual bool hasTag(const Tag &tag) const = 0;
|
virtual bool hasTag(const Tag &tag) const = 0;
|
||||||
virtual bool addTag(const Tag &tag) = 0;
|
virtual bool addTag(const Tag &tag) = 0;
|
||||||
|
virtual bool setTags(const TagSet &newTags) = 0;
|
||||||
virtual bool removeTag(const Tag &tag) = 0;
|
virtual bool removeTag(const Tag &tag) = 0;
|
||||||
virtual void removeAllTags() = 0;
|
virtual void removeAllTags() = 0;
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
#include "base/logger.h"
|
#include "base/logger.h"
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
|
#include "base/tagset.h"
|
||||||
#include "base/types.h"
|
#include "base/types.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/utils/io.h"
|
#include "base/utils/io.h"
|
||||||
|
@ -937,6 +938,24 @@ bool TorrentImpl::addTag(const Tag &tag)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TorrentImpl::setTags(const TagSet &newTags)
|
||||||
|
{
|
||||||
|
// Identify tags to add
|
||||||
|
for (const Tag &tag : newTags)
|
||||||
|
{
|
||||||
|
if (!hasTag(tag))
|
||||||
|
addTag(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Identify tags to remove
|
||||||
|
for (const Tag &tag : asConst(m_tags))
|
||||||
|
{
|
||||||
|
if (!newTags.contains(tag))
|
||||||
|
removeTag(tag);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool TorrentImpl::removeTag(const Tag &tag)
|
bool TorrentImpl::removeTag(const Tag &tag)
|
||||||
{
|
{
|
||||||
if (m_tags.remove(tag))
|
if (m_tags.remove(tag))
|
||||||
|
|
|
@ -131,6 +131,7 @@ namespace BitTorrent
|
||||||
TagSet tags() const override;
|
TagSet tags() const override;
|
||||||
bool hasTag(const Tag &tag) const override;
|
bool hasTag(const Tag &tag) const override;
|
||||||
bool addTag(const Tag &tag) override;
|
bool addTag(const Tag &tag) override;
|
||||||
|
bool setTags(const TagSet &newTags) override;
|
||||||
bool removeTag(const Tag &tag) override;
|
bool removeTag(const Tag &tag) override;
|
||||||
void removeAllTags() override;
|
void removeAllTags() override;
|
||||||
|
|
||||||
|
|
|
@ -1475,6 +1475,25 @@ void TorrentsController::addTagsAction()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TorrentsController::setTagsAction()
|
||||||
|
{
|
||||||
|
requireParams({u"hashes"_s, u"tags"_s});
|
||||||
|
|
||||||
|
const QStringList hashes {params()[u"hashes"_s].split(u'|')};
|
||||||
|
const QStringList tags {params()[u"tags"_s].split(u',', Qt::SkipEmptyParts)};
|
||||||
|
|
||||||
|
// Convert QStringList to TagSet
|
||||||
|
TagSet newTags;
|
||||||
|
for (const QString &tagStr : tags)
|
||||||
|
newTags.insert(Tag(tagStr));
|
||||||
|
|
||||||
|
// Apply the new tags to the selected torrents
|
||||||
|
applyToTorrents(hashes, [&newTags](BitTorrent::Torrent *const torrent)
|
||||||
|
{
|
||||||
|
torrent->setTags(newTags);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void TorrentsController::removeTagsAction()
|
void TorrentsController::removeTagsAction()
|
||||||
{
|
{
|
||||||
requireParams({u"hashes"_s});
|
requireParams({u"hashes"_s});
|
||||||
|
|
|
@ -61,6 +61,7 @@ private slots:
|
||||||
void removeCategoriesAction();
|
void removeCategoriesAction();
|
||||||
void categoriesAction();
|
void categoriesAction();
|
||||||
void addTagsAction();
|
void addTagsAction();
|
||||||
|
void setTagsAction();
|
||||||
void removeTagsAction();
|
void removeTagsAction();
|
||||||
void createTagsAction();
|
void createTagsAction();
|
||||||
void deleteTagsAction();
|
void deleteTagsAction();
|
||||||
|
|
|
@ -212,6 +212,7 @@ private:
|
||||||
{{u"torrents"_s, u"setShareLimits"_s}, Http::METHOD_POST},
|
{{u"torrents"_s, u"setShareLimits"_s}, Http::METHOD_POST},
|
||||||
{{u"torrents"_s, u"setSSLParameters"_s}, Http::METHOD_POST},
|
{{u"torrents"_s, u"setSSLParameters"_s}, Http::METHOD_POST},
|
||||||
{{u"torrents"_s, u"setSuperSeeding"_s}, Http::METHOD_POST},
|
{{u"torrents"_s, u"setSuperSeeding"_s}, Http::METHOD_POST},
|
||||||
|
{{u"torrents"_s, u"setTags"_s}, Http::METHOD_POST},
|
||||||
{{u"torrents"_s, u"setUploadLimit"_s}, Http::METHOD_POST},
|
{{u"torrents"_s, u"setUploadLimit"_s}, Http::METHOD_POST},
|
||||||
{{u"transfer"_s, u"setDownloadLimit"_s}, Http::METHOD_POST},
|
{{u"transfer"_s, u"setDownloadLimit"_s}, Http::METHOD_POST},
|
||||||
{{u"transfer"_s, u"setSpeedLimitsMode"_s}, Http::METHOD_POST},
|
{{u"transfer"_s, u"setSpeedLimitsMode"_s}, Http::METHOD_POST},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue