mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-28 21:38:51 +03: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:
parent
25e8cad16c
commit
c53b19d6c1
4 changed files with 63 additions and 3 deletions
|
@ -100,6 +100,8 @@ QMap<QString, QMap<QString, RequestHandler::Action> > 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("|");
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -117,7 +117,12 @@
|
|||
<div id="desktopFooter">
|
||||
<span id="error_div"></span>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue