mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-13 08:17:57 +00:00
Require torrent category creation to be explicit
This commit is contained in:
parent
ee57b68901
commit
d89ef22d85
@ -1214,10 +1214,8 @@ bool TorrentHandle::setCategory(const QString &category)
|
|||||||
{
|
{
|
||||||
if (m_category != category) {
|
if (m_category != category) {
|
||||||
if (!category.isEmpty()) {
|
if (!category.isEmpty()) {
|
||||||
if (!Session::isValidCategoryName(category)) return false;
|
if (!Session::isValidCategoryName(category) || !m_session->categories().contains(category))
|
||||||
if (!m_session->categories().contains(category))
|
return false;
|
||||||
if (!m_session->addCategory(category))
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString oldCategory = m_category;
|
QString oldCategory = m_category;
|
||||||
|
@ -811,6 +811,10 @@ void TorrentsController::setCategoryAction()
|
|||||||
const QString category {params()["category"].trimmed()};
|
const QString category {params()["category"].trimmed()};
|
||||||
applyToTorrents(hashes, [category](BitTorrent::TorrentHandle *torrent)
|
applyToTorrents(hashes, [category](BitTorrent::TorrentHandle *torrent)
|
||||||
{
|
{
|
||||||
|
auto *session = BitTorrent::Session::instance();
|
||||||
|
const QStringList categories = session->categories().keys();
|
||||||
|
if (!categories.contains(category) && !session->addCategory(category))
|
||||||
|
throw APIError(APIErrorType::Conflict, tr("Unable to create category"));
|
||||||
if (!torrent->setCategory(category))
|
if (!torrent->setCategory(category))
|
||||||
throw APIError(APIErrorType::Conflict, tr("Incorrect category name"));
|
throw APIError(APIErrorType::Conflict, tr("Incorrect category name"));
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user