From c53b19d6c18f7761013f1bae5a8dde57123119ab Mon Sep 17 00:00:00 2001 From: Gabriele Date: Sun, 14 Dec 2014 10:00:00 +0100 Subject: [PATCH] WebUI: Allow to control the alternative speed limits setGlobalDownloadLimit and setGlobalUploadLimit will now modify the alternative speed limits if they are currently enabled and the regular speed limits otherwise. Add also two new commands to toggle the state of the alternative speed limits and get their current state. Closes #2203. --- src/webui/requesthandler.cpp | 22 ++++++++++++++-- src/webui/requesthandler.h | 2 ++ src/webui/www/private/index.html | 7 +++++- src/webui/www/public/scripts/client.js | 35 ++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/webui/requesthandler.cpp b/src/webui/requesthandler.cpp index 0276dbf4b..a17413dc8 100644 --- a/src/webui/requesthandler.cpp +++ b/src/webui/requesthandler.cpp @@ -100,6 +100,8 @@ QMap > RequestHandler::initialize ADD_ACTION(command, getTorrentDlLimit); ADD_ACTION(command, setTorrentUpLimit); ADD_ACTION(command, setTorrentDlLimit); + ADD_ACTION(command, alternativeSpeedLimitsEnabled); + ADD_ACTION(command, toggleAlternativeSpeedLimits); ADD_ACTION(command, toggleSequentialDownload); ADD_ACTION(command, toggleFirstLastPiecePrio); ADD_ACTION(command, delete); @@ -376,7 +378,10 @@ void RequestHandler::action_command_setGlobalUpLimit() if (limit == 0) limit = -1; QBtSession::instance()->setUploadRateLimit(limit); - Preferences::instance()->setGlobalUploadLimit(limit / 1024.); + if (Preferences::instance()->isAltBandwidthEnabled()) + Preferences::instance()->setAltGlobalUploadLimit(limit / 1024.); + else + Preferences::instance()->setGlobalUploadLimit(limit / 1024.); } void RequestHandler::action_command_setGlobalDlLimit() @@ -385,7 +390,10 @@ void RequestHandler::action_command_setGlobalDlLimit() if (limit == 0) limit = -1; QBtSession::instance()->setDownloadRateLimit(limit); - Preferences::instance()->setGlobalDownloadLimit(limit / 1024.); + if (Preferences::instance()->isAltBandwidthEnabled()) + Preferences::instance()->setAltGlobalDownloadLimit(limit / 1024.); + else + Preferences::instance()->setGlobalDownloadLimit(limit / 1024.); } void RequestHandler::action_command_getTorrentUpLimit() @@ -428,6 +436,16 @@ void RequestHandler::action_command_setTorrentDlLimit() h.set_download_limit(limit); } +void RequestHandler::action_command_toggleAlternativeSpeedLimits() +{ + QBtSession::instance()->useAlternativeSpeedsLimit(!Preferences::instance()->isAltBandwidthEnabled()); +} + +void RequestHandler::action_command_alternativeSpeedLimitsEnabled() +{ + print(QByteArray::number(Preferences::instance()->isAltBandwidthEnabled())); +} + void RequestHandler::action_command_toggleSequentialDownload() { QStringList hashes = request().posts["hashes"].split("|"); diff --git a/src/webui/requesthandler.h b/src/webui/requesthandler.h index ec34385e1..5597dc4bf 100644 --- a/src/webui/requesthandler.h +++ b/src/webui/requesthandler.h @@ -74,6 +74,8 @@ private: void action_command_getTorrentDlLimit(); void action_command_setTorrentUpLimit(); void action_command_setTorrentDlLimit(); + void action_command_alternativeSpeedLimitsEnabled(); + void action_command_toggleAlternativeSpeedLimits(); void action_command_toggleSequentialDownload(); void action_command_toggleFirstLastPiecePrio(); void action_command_delete(); diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index ae086863d..fa60de0de 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -117,7 +117,12 @@
- + + + + + +
_(Alternative speed limits)
diff --git a/src/webui/www/public/scripts/client.js b/src/webui/www/public/scripts/client.js index a01eed5d4..9f5c33445 100644 --- a/src/webui/www/public/scripts/client.js +++ b/src/webui/www/public/scripts/client.js @@ -27,6 +27,7 @@ myTable = new dynamicTable(); var updatePropertiesPanel = function(){}; var updateTransferInfo = function(){}; var updateTransferList = function(){}; +var alternativeSpeedsLimit = false; var stateToImg = function (state) { if (state == "pausedUP" || state == "pausedDL") { @@ -278,6 +279,40 @@ window.addEvent('load', function () { // Start fetching data now loadTransferInfo(); + var updateAltSpeedIcon = function(enabled) { + if (enabled) + $('alternativeSpeedLimits').src = "images/slow.png"; + else + $('alternativeSpeedLimits').src = "images/slow_off.png" + } + + // Determine whether the alternative speed limits are enabled or not + new Request({url: 'command/alternativeSpeedLimitsEnabled', + method: 'get', + onSuccess : function (isEnabled) { + alternativeSpeedsLimit = !!isEnabled; + if (alternativeSpeedsLimit) + $('alternativeSpeedLimits').src = "images/slow.png" + } + }).send(); + + $('alternativeSpeedLimits').addEvent('click', function() { + // Change icon immediately to give some feedback + updateAltSpeedIcon(!alternativeSpeedsLimit); + + new Request({url: 'command/toggleAlternativeSpeedLimits', + method: 'post', + onComplete: function() { + alternativeSpeedsLimit = !alternativeSpeedsLimit; + updateTransferInfo(); + }, + onFailure: function() { + // Restore icon in case of failure + updateAltSpeedIcon(alternativeSpeedsLimit) + } + }).send(); + }); + $('DlInfos').addEvent('click', globalDownloadLimitFN); $('UpInfos').addEvent('click', globalUploadLimitFN);