From 902db2b9382f58a4d1f39d77600424c0223a3a81 Mon Sep 17 00:00:00 2001 From: buinsky Date: Sun, 1 Feb 2015 12:45:37 -0500 Subject: [PATCH] Group setting torrents download limit --- src/webui/webapplication.cpp | 33 +++++++++++---------- src/webui/webapplication.h | 4 +-- src/webui/www/public/downloadlimit.html | 10 +++---- src/webui/www/public/scripts/mocha-init.js | 4 +-- src/webui/www/public/scripts/parametrics.js | 22 +++++++++----- 5 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index c2d55d5f9..ed2d5b36c 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -95,9 +95,9 @@ QMap > WebApplication::initialize ADD_ACTION(command, setGlobalUpLimit); ADD_ACTION(command, setGlobalDlLimit); ADD_ACTION(command, getTorrentsUpLimit); - ADD_ACTION(command, getTorrentDlLimit); + ADD_ACTION(command, getTorrentsDlLimit); ADD_ACTION(command, setTorrentsUpLimit); - ADD_ACTION(command, setTorrentDlLimit); + ADD_ACTION(command, setTorrentsDlLimit); ADD_ACTION(command, alternativeSpeedLimitsEnabled); ADD_ACTION(command, toggleAlternativeSpeedLimits); ADD_ACTION(command, toggleSequentialDownload); @@ -462,15 +462,12 @@ void WebApplication::action_command_getTorrentsUpLimit() print(btjson::getTorrentsRatesLimits(hashes, false), Http::CONTENT_TYPE_JS); } -void WebApplication::action_command_getTorrentDlLimit() +void WebApplication::action_command_getTorrentsDlLimit() { 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.download_limit())); + CHECK_PARAMETERS("hashes"); + QStringList hashes = request().posts["hashes"].split("|"); + print(btjson::getTorrentsRatesLimits(hashes, true), Http::CONTENT_TYPE_JS); } void WebApplication::action_command_setTorrentsUpLimit() @@ -490,17 +487,21 @@ void WebApplication::action_command_setTorrentsUpLimit() } } -void WebApplication::action_command_setTorrentDlLimit() +void WebApplication::action_command_setTorrentsDlLimit() { 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_download_limit(limit); + } } void WebApplication::action_command_toggleAlternativeSpeedLimits() diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 96b4be35c..3100cb454 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -69,9 +69,9 @@ private: void action_command_setGlobalUpLimit(); void action_command_setGlobalDlLimit(); void action_command_getTorrentsUpLimit(); - void action_command_getTorrentDlLimit(); + void action_command_getTorrentsDlLimit(); void action_command_setTorrentsUpLimit(); - void action_command_setTorrentDlLimit(); + void action_command_setTorrentsDlLimit(); void action_command_alternativeSpeedLimitsEnabled(); void action_command_toggleAlternativeSpeedLimits(); void action_command_toggleSequentialDownload(); diff --git a/src/webui/www/public/downloadlimit.html b/src/webui/www/public/downloadlimit.html index ca1e521ab..43a54d97c 100644 --- a/src/webui/www/public/downloadlimit.html +++ b/src/webui/www/public/downloadlimit.html @@ -20,10 +20,10 @@
diff --git a/src/webui/www/public/scripts/mocha-init.js b/src/webui/www/public/scripts/mocha-init.js index 050be0eb3..81b746f96 100644 --- a/src/webui/www/public/scripts/mocha-init.js +++ b/src/webui/www/public/scripts/mocha-init.js @@ -186,7 +186,7 @@ initializeWindows = function() { id: 'downloadLimitPage', title: "QBT_TR(Global Download Speed Limit)QBT_TR", loadMethod: 'iframe', - contentURL: 'downloadlimit.html?hash=global', + contentURL: 'downloadlimit.html?hashes=global', scrollbars: false, resizable: false, maximizable: false, @@ -205,7 +205,7 @@ initializeWindows = function() { id: 'downloadLimitPage', title: "QBT_TR(Torrent Download Speed Limiting)QBT_TR", loadMethod: 'iframe', - contentURL: 'downloadlimit.html?hash=' + hash, + contentURL: 'downloadlimit.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 f87d0ec14..cda3272f5 100644 --- a/src/webui/www/public/scripts/parametrics.js +++ b/src/webui/www/public/scripts/parametrics.js @@ -118,7 +118,7 @@ MochaUI.extend({ } }, - addDlLimitSlider: function(hash) { + addDlLimitSlider: function(hashes) { if ($('dllimitSliderarea')) { var windowOptions = MochaUI.Windows.windowOptions; var sliderFirst = true; @@ -135,15 +135,15 @@ MochaUI.extend({ maximum = tmp / 1024. } else { - if (hash == "global") + if (hashes[0] == "global") maximum = 10000; else maximum = 1000; } } - // Get torrent download limit + // Get torrents download limit // And create slider - if (hash == "global") { + if (hashes[0] == 'global') { var dl_limit = maximum; if (dl_limit < 0) dl_limit = 0; maximum = 10000; @@ -173,15 +173,21 @@ MochaUI.extend({ } } else { - var req = new Request({ - url: 'command/getTorrentDlLimit', + var req = new Request.JSON({ + url: 'command/getTorrentsDlLimit', + noCache : true, method: 'post', data: { - hash: hash + hashes: hashes.join('|') }, onSuccess: function(data) { if (data) { - var dl_limit = data.toInt(); + var dl_limit = data[hashes[0]]; + for(var key in data) + if (dl_limit != data[key]) { + dl_limit = 0; + break; + } if (dl_limit < 0) dl_limit = 0; var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), { steps: maximum,