diff --git a/src/webui/btjson.cpp b/src/webui/btjson.cpp index 699bf5165..e02423efb 100644 --- a/src/webui/btjson.cpp +++ b/src/webui/btjson.cpp @@ -539,6 +539,21 @@ QVariantMap getTranserInfoMap() return map; } +QByteArray btjson::getTorrentsRatesLimits(QStringList &hashes, bool downloadLimits) +{ + QVariantMap map; + + foreach (const QString &hash, hashes) { + int limit = -1; + QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash); + if (h.is_valid()) + limit = downloadLimits ? h.download_limit() : h.upload_limit(); + map[hash] = limit; + } + + return json::toJson(map); +} + QVariantMap toMap(const QTorrentHandle& h) { libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters); diff --git a/src/webui/btjson.h b/src/webui/btjson.h index 2d5f7e8eb..fb9faf434 100644 --- a/src/webui/btjson.h +++ b/src/webui/btjson.h @@ -52,6 +52,7 @@ public: static QByteArray getPropertiesForTorrent(const QString& hash); static QByteArray getFilesForTorrent(const QString& hash); static QByteArray getTransferInfo(); + static QByteArray getTorrentsRatesLimits(QStringList& hashes, bool downloadLimits); }; // class btjson #endif // BTJSON_H diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 545e1ef52..c2d55d5f9 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -94,9 +94,9 @@ QMap > WebApplication::initialize ADD_ACTION(command, getGlobalDlLimit); ADD_ACTION(command, setGlobalUpLimit); ADD_ACTION(command, setGlobalDlLimit); - ADD_ACTION(command, getTorrentUpLimit); + ADD_ACTION(command, getTorrentsUpLimit); ADD_ACTION(command, getTorrentDlLimit); - ADD_ACTION(command, setTorrentUpLimit); + ADD_ACTION(command, setTorrentsUpLimit); ADD_ACTION(command, setTorrentDlLimit); ADD_ACTION(command, alternativeSpeedLimitsEnabled); ADD_ACTION(command, toggleAlternativeSpeedLimits); @@ -454,15 +454,12 @@ void WebApplication::action_command_setGlobalDlLimit() Preferences::instance()->setGlobalDownloadLimit(limit / 1024.); } -void WebApplication::action_command_getTorrentUpLimit() +void WebApplication::action_command_getTorrentsUpLimit() { CHECK_URI(0); - CHECK_PARAMETERS("hash"); - QString hash = request().posts["hash"]; - QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash); - - if (h.is_valid()) - print(QByteArray::number(h.upload_limit())); + CHECK_PARAMETERS("hashes"); + QStringList hashes = request().posts["hashes"].split("|"); + print(btjson::getTorrentsRatesLimits(hashes, false), Http::CONTENT_TYPE_JS); } void WebApplication::action_command_getTorrentDlLimit() @@ -476,17 +473,21 @@ void WebApplication::action_command_getTorrentDlLimit() print(QByteArray::number(h.download_limit())); } -void WebApplication::action_command_setTorrentUpLimit() +void WebApplication::action_command_setTorrentsUpLimit() { CHECK_URI(0); - CHECK_PARAMETERS("hash" << "limit"); - QString hash = request().posts["hash"]; - qlonglong limit = request().posts["limit"].toLongLong(); - if (limit == 0) limit = -1; - QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash); + CHECK_PARAMETERS("hashes" << "limit"); - if (h.is_valid()) + qlonglong limit = request().posts["limit"].toLongLong(); + if (limit == 0) + limit = -1; + + QStringList hashes = request().posts["hashes"].split("|"); + foreach (const QString &hash, hashes) { + QTorrentHandle h = QBtSession::instance()->getTorrentHandle(hash); + if (h.is_valid()) h.set_upload_limit(limit); + } } void WebApplication::action_command_setTorrentDlLimit() diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 4b2e31b6d..96b4be35c 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -68,9 +68,9 @@ private: void action_command_getGlobalDlLimit(); void action_command_setGlobalUpLimit(); void action_command_setGlobalDlLimit(); - void action_command_getTorrentUpLimit(); + void action_command_getTorrentsUpLimit(); void action_command_getTorrentDlLimit(); - void action_command_setTorrentUpLimit(); + void action_command_setTorrentsUpLimit(); void action_command_setTorrentDlLimit(); void action_command_alternativeSpeedLimitsEnabled(); void action_command_toggleAlternativeSpeedLimits(); diff --git a/src/webui/www/public/scripts/mocha-init.js b/src/webui/www/public/scripts/mocha-init.js index b09dc4fc9..050be0eb3 100644 --- a/src/webui/www/public/scripts/mocha-init.js +++ b/src/webui/www/public/scripts/mocha-init.js @@ -107,7 +107,7 @@ initializeWindows = function() { id: 'uploadLimitPage', title: "QBT_TR(Global Upload Speed Limit)QBT_TR", loadMethod: 'iframe', - contentURL: 'uploadlimit.html?hash=global', + contentURL: 'uploadlimit.html?hashes=global', scrollbars: false, resizable: false, maximizable: false, @@ -126,7 +126,7 @@ initializeWindows = function() { id: 'uploadLimitPage', title: "QBT_TR(Torrent Upload Speed Limiting)QBT_TR", loadMethod: 'iframe', - contentURL: 'uploadlimit.html?hash=' + hash, + contentURL: 'uploadlimit.html?hashes=' + h.join("|"), scrollbars: false, resizable: false, maximizable: false, diff --git a/src/webui/www/public/scripts/parametrics.js b/src/webui/www/public/scripts/parametrics.js index 07b7ca379..f87d0ec14 100644 --- a/src/webui/www/public/scripts/parametrics.js +++ b/src/webui/www/public/scripts/parametrics.js @@ -14,7 +14,7 @@ Requires: */ MochaUI.extend({ - addUpLimitSlider: function(hash) { + addUpLimitSlider: function(hashes) { if ($('uplimitSliderarea')) { var windowOptions = MochaUI.Windows.windowOptions; var sliderFirst = true; @@ -31,15 +31,15 @@ MochaUI.extend({ maximum = tmp / 1024. } else { - if (hash == "global") + if (hashes[0] == "global") maximum = 10000; else maximum = 1000; } } - // Get torrent upload limit + // Get torrents upload limit // And create slider - if (hash == 'global') { + if (hashes[0] == 'global') { var up_limit = maximum; if (up_limit < 0) up_limit = 0; maximum = 10000; @@ -69,15 +69,21 @@ MochaUI.extend({ } } else { - var req = new Request({ - url: 'command/getTorrentUpLimit', + var req = new Request.JSON({ + url: 'command/getTorrentsUpLimit', + noCache : true, method: 'post', data: { - hash: hash + hashes: hashes.join('|') }, onSuccess: function(data) { if (data) { - var up_limit = data.toInt(); + var up_limit = data[hashes[0]]; + for(var key in data) + if (up_limit != data[key]) { + up_limit = 0; + break; + } if (up_limit < 0) up_limit = 0; var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), { steps: maximum, diff --git a/src/webui/www/public/uploadlimit.html b/src/webui/www/public/uploadlimit.html index 4b63183b3..733ce393c 100644 --- a/src/webui/www/public/uploadlimit.html +++ b/src/webui/www/public/uploadlimit.html @@ -20,10 +20,10 @@