mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 21:28:07 -06:00
Add save path and editing to WebUI new category dialog
This commit is contained in:
@@ -399,16 +399,17 @@ void SyncController::maindataAction()
|
||||
|
||||
data["torrents"] = torrents;
|
||||
|
||||
QVariantList categoriesList;
|
||||
const auto categories = session->categories();
|
||||
for (auto key : categories.keys()) {
|
||||
categoriesList << QVariantMap {
|
||||
QVariantHash categories;
|
||||
const auto categoriesList = session->categories();
|
||||
for (auto it = categoriesList.cbegin(); it != categoriesList.cend(); ++it) {
|
||||
const auto key = it.key();
|
||||
categories[key] = QVariantMap {
|
||||
{"name", key},
|
||||
{"savePath", categories.value(key)},
|
||||
{"savePath", it.value()}
|
||||
};
|
||||
}
|
||||
|
||||
data["categories"] = categoriesList;
|
||||
data["categories"] = categories;
|
||||
|
||||
QVariantMap serverState = getTranserInfo();
|
||||
serverState[KEY_SYNC_MAINDATA_QUEUEING] = session->isQueueingSystemEnabled();
|
||||
|
||||
@@ -738,7 +738,7 @@ void TorrentsController::setLocationAction()
|
||||
const QString newLocation {params()["location"].trimmed()};
|
||||
|
||||
if (newLocation.isEmpty())
|
||||
throw APIError(APIErrorType::BadParams, tr("Save path is empty"));
|
||||
throw APIError(APIErrorType::BadParams, tr("Save path cannot be empty"));
|
||||
|
||||
// try to create the location if it does not exist
|
||||
if (!QDir(newLocation).mkpath("."))
|
||||
@@ -809,12 +809,9 @@ void TorrentsController::setCategoryAction()
|
||||
|
||||
const QStringList hashes {params()["hashes"].split('|')};
|
||||
const QString category {params()["category"].trimmed()};
|
||||
|
||||
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))
|
||||
throw APIError(APIErrorType::Conflict, tr("Incorrect category name"));
|
||||
});
|
||||
@@ -825,10 +822,30 @@ void TorrentsController::createCategoryAction()
|
||||
checkParams({"category"});
|
||||
|
||||
const QString category {params()["category"].trimmed()};
|
||||
if (!BitTorrent::Session::isValidCategoryName(category) && !category.isEmpty())
|
||||
const QString savePath {params()["savePath"]};
|
||||
|
||||
if (category.isEmpty())
|
||||
throw APIError(APIErrorType::BadParams, tr("Category cannot be empty"));
|
||||
|
||||
if (!BitTorrent::Session::isValidCategoryName(category))
|
||||
throw APIError(APIErrorType::Conflict, tr("Incorrect category name"));
|
||||
|
||||
BitTorrent::Session::instance()->addCategory(category);
|
||||
if (!BitTorrent::Session::instance()->addCategory(category, savePath))
|
||||
throw APIError(APIErrorType::Conflict, tr("Unable to create category"));
|
||||
}
|
||||
|
||||
void TorrentsController::editCategoryAction()
|
||||
{
|
||||
checkParams({"category", "savePath"});
|
||||
|
||||
const QString category {params()["category"].trimmed()};
|
||||
const QString savePath {params()["savePath"]};
|
||||
|
||||
if (category.isEmpty())
|
||||
throw APIError(APIErrorType::BadParams, tr("Category cannot be empty"));
|
||||
|
||||
if (!BitTorrent::Session::instance()->editCategory(category, savePath))
|
||||
throw APIError(APIErrorType::Conflict, tr("Unable to edit category"));
|
||||
}
|
||||
|
||||
void TorrentsController::removeCategoriesAction()
|
||||
|
||||
@@ -53,6 +53,7 @@ private slots:
|
||||
void renameAction();
|
||||
void setCategoryAction();
|
||||
void createCategoryAction();
|
||||
void editCategoryAction();
|
||||
void removeCategoriesAction();
|
||||
void addAction();
|
||||
void deleteAction();
|
||||
|
||||
Reference in New Issue
Block a user