diff --git a/src/webui/btjson.cpp b/src/webui/btjson.cpp index 99f386134..39e7745dd 100644 --- a/src/webui/btjson.cpp +++ b/src/webui/btjson.cpp @@ -256,6 +256,7 @@ private: * - "seq_dl": Torrent sequential download state * - "f_l_piece_prio": Torrent first last piece priority state * - "force_start": Torrent force start state + * - "label": Torrent label */ QByteArray btjson::getTorrents(QString filter, QString label, QString sortedColumn, bool reverse, int limit, int offset) diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index a7098f28a..5519005ee 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -39,6 +39,7 @@ #include "core/preferences.h" #include "btjson.h" #include "prefjson.h" +#include "jsonutils.h" #include "core/bittorrent/session.h" #include "core/bittorrent/trackerentry.h" #include "core/bittorrent/torrentinfo.h" @@ -110,6 +111,7 @@ QMap > WebApplication::initialize ADD_ACTION(command, topPrio); ADD_ACTION(command, bottomPrio); ADD_ACTION(command, recheck); + ADD_ACTION(command, setLabel); ADD_ACTION(version, api); ADD_ACTION(version, api_min); ADD_ACTION(version, qbittorrent); @@ -664,6 +666,25 @@ void WebApplication::action_command_recheck() torrent->forceRecheck(); } +void WebApplication::action_command_setLabel() +{ + CHECK_URI(0); + CHECK_PARAMETERS("hashes" << "label"); + + QStringList hashes = request().posts["hashes"].split("|"); + QString label = request().posts["label"].trimmed(); + if (!Utils::Fs::isValidFileSystemName(label)) { + status(400, "Labels must not contain special characters"); + return; + } + + foreach (const QString &hash, hashes) { + BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); + if (torrent) + torrent->setLabel(label); + } +} + bool WebApplication::isPublicScope() { return (scope_ == DEFAULT_SCOPE || scope_ == VERSION_INFO); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index e4bef1ab1..5424ce2c5 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -86,6 +86,7 @@ private: void action_command_topPrio(); void action_command_bottomPrio(); void action_command_recheck(); + void action_command_setLabel(); void action_version_api(); void action_version_api_min(); void action_version_qbittorrent(); diff --git a/src/webui/webui.qrc b/src/webui/webui.qrc index c77d04bdc..407b6b05f 100644 --- a/src/webui/webui.qrc +++ b/src/webui/webui.qrc @@ -27,6 +27,7 @@ www/public/download.html www/public/downloadlimit.html www/public/filters.html + www/public/newlabel.html www/public/preferences.html www/public/preferences_content.html www/public/properties.html diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index 0cfa52d54..c8d23def7 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -105,6 +105,10 @@
  • QBT_TR(Pause)QBT_TR QBT_TR(Pause)QBT_TR
  • QBT_TR(Force Resume)QBT_TR QBT_TR(Force Resume)QBT_TR
  • QBT_TR(Delete)QBT_TR QBT_TR(Delete)QBT_TR
  • +
  • + QBT_TR(Label)QBT_TR QBT_TR(Label)QBT_TR + +
  • QBT_TR(Priority)QBT_TR