From 76d93c23b7739140379cae725282e137521fdd5d Mon Sep 17 00:00:00 2001 From: Felipe Barriga Richards Date: Thu, 26 Feb 2015 22:52:38 -0300 Subject: [PATCH] webui (c++): feature: added labels support. #648 --- src/webui/btjson.cpp | 1 + src/webui/prefjson.cpp | 1 + src/webui/webapplication.cpp | 19 +++++++++++++++++++ src/webui/webapplication.h | 1 + 4 files changed, 22 insertions(+) diff --git a/src/webui/btjson.cpp b/src/webui/btjson.cpp index 44addf7f0..fdbb65661 100644 --- a/src/webui/btjson.cpp +++ b/src/webui/btjson.cpp @@ -255,6 +255,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/prefjson.cpp b/src/webui/prefjson.cpp index bf206df39..c82fa782d 100644 --- a/src/webui/prefjson.cpp +++ b/src/webui/prefjson.cpp @@ -396,3 +396,4 @@ void prefjson::setPreferences(const QString& json) // Save preferences pref->apply(); } + diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 1b2dfee6f..16916b6eb 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -110,6 +110,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 +665,24 @@ void WebApplication::action_command_recheck() torrent->forceRecheck(); } +void WebApplication::action_command_setLabel() +{ + CHECK_URI(0); + CHECK_PARAMETERS("hash" << "label_obj"); + + QString hash = request().posts["hash"]; + QString label_obj = request().posts["label_obj"]; + + const QVariantMap m = json::fromJson(label_obj).toMap(); + if( m.contains("value") ) { + QString label = m["value"].toString(); + if (!hash.isEmpty()) { + QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash); + QBtSession::instance()->setLabel(h, 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();