1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-30 16:34:16 +00:00

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.
This commit is contained in:
Gabriele 2014-12-14 10:00:00 +01:00
parent 25e8cad16c
commit c53b19d6c1
4 changed files with 63 additions and 3 deletions

View File

@ -100,6 +100,8 @@ QMap<QString, QMap<QString, RequestHandler::Action> > RequestHandler::initialize
ADD_ACTION(command, getTorrentDlLimit); ADD_ACTION(command, getTorrentDlLimit);
ADD_ACTION(command, setTorrentUpLimit); ADD_ACTION(command, setTorrentUpLimit);
ADD_ACTION(command, setTorrentDlLimit); ADD_ACTION(command, setTorrentDlLimit);
ADD_ACTION(command, alternativeSpeedLimitsEnabled);
ADD_ACTION(command, toggleAlternativeSpeedLimits);
ADD_ACTION(command, toggleSequentialDownload); ADD_ACTION(command, toggleSequentialDownload);
ADD_ACTION(command, toggleFirstLastPiecePrio); ADD_ACTION(command, toggleFirstLastPiecePrio);
ADD_ACTION(command, delete); ADD_ACTION(command, delete);
@ -376,7 +378,10 @@ void RequestHandler::action_command_setGlobalUpLimit()
if (limit == 0) limit = -1; if (limit == 0) limit = -1;
QBtSession::instance()->setUploadRateLimit(limit); 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() void RequestHandler::action_command_setGlobalDlLimit()
@ -385,7 +390,10 @@ void RequestHandler::action_command_setGlobalDlLimit()
if (limit == 0) limit = -1; if (limit == 0) limit = -1;
QBtSession::instance()->setDownloadRateLimit(limit); 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() void RequestHandler::action_command_getTorrentUpLimit()
@ -428,6 +436,16 @@ void RequestHandler::action_command_setTorrentDlLimit()
h.set_download_limit(limit); 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() void RequestHandler::action_command_toggleSequentialDownload()
{ {
QStringList hashes = request().posts["hashes"].split("|"); QStringList hashes = request().posts["hashes"].split("|");

View File

@ -74,6 +74,8 @@ private:
void action_command_getTorrentDlLimit(); void action_command_getTorrentDlLimit();
void action_command_setTorrentUpLimit(); void action_command_setTorrentUpLimit();
void action_command_setTorrentDlLimit(); void action_command_setTorrentDlLimit();
void action_command_alternativeSpeedLimitsEnabled();
void action_command_toggleAlternativeSpeedLimits();
void action_command_toggleSequentialDownload(); void action_command_toggleSequentialDownload();
void action_command_toggleFirstLastPiecePrio(); void action_command_toggleFirstLastPiecePrio();
void action_command_delete(); void action_command_delete();

View File

@ -117,7 +117,12 @@
<div id="desktopFooter"> <div id="desktopFooter">
<span id="error_div"></span> <span id="error_div"></span>
<table style="position: absolute; right: 5px;"> <table style="position: absolute; right: 5px;">
<tr><td id="DlInfos" style="cursor:pointer;"></td><td style="width: 2px;margin:0;"><img src="images/skin/toolbox-divider.gif" alt="" style="height: 18px; padding-left: 10px; padding-right: 10px; margin-bottom: -2px;"/></td><td id="UpInfos" style="cursor:pointer;"></td></tr> <tr>
<td style="cursor:pointer;"><img id="alternativeSpeedLimits" alt="_(Alternative speed limits)" src="images/slow_off.png" /></td>
<td style="width: 2px;margin:0;"><img src="images/skin/toolbox-divider.gif" alt="" style="height: 18px; padding-left: 10px; padding-right: 10px; margin-bottom: -2px;"/></td>
<td id="DlInfos" style="cursor:pointer;"></td>
<td style="width: 2px;margin:0;"><img src="images/skin/toolbox-divider.gif" alt="" style="height: 18px; padding-left: 10px; padding-right: 10px; margin-bottom: -2px;"/></td>
<td id="UpInfos" style="cursor:pointer;"></td></tr>
</table> </table>
</div> </div>
</div> </div>

View File

@ -27,6 +27,7 @@ myTable = new dynamicTable();
var updatePropertiesPanel = function(){}; var updatePropertiesPanel = function(){};
var updateTransferInfo = function(){}; var updateTransferInfo = function(){};
var updateTransferList = function(){}; var updateTransferList = function(){};
var alternativeSpeedsLimit = false;
var stateToImg = function (state) { var stateToImg = function (state) {
if (state == "pausedUP" || state == "pausedDL") { if (state == "pausedUP" || state == "pausedDL") {
@ -278,6 +279,40 @@ window.addEvent('load', function () {
// Start fetching data now // Start fetching data now
loadTransferInfo(); 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); $('DlInfos').addEvent('click', globalDownloadLimitFN);
$('UpInfos').addEvent('click', globalUploadLimitFN); $('UpInfos').addEvent('click', globalUploadLimitFN);