Fix alternative speed limits toggle behavior

This commit is contained in:
buinsky 2015-01-29 19:56:14 +03:00
parent 135599acc4
commit 0f56440dec
2 changed files with 7 additions and 10 deletions

View file

@ -146,6 +146,7 @@ static const char KEY_TRANSFER_CONNECTION_STATUS[] = "connection_status";
// Sync main data keys // Sync main data keys
static const char KEY_SYNC_MAINDATA_QUEUEING[] = "queueing"; static const char KEY_SYNC_MAINDATA_QUEUEING[] = "queueing";
static const char KEY_SYNC_MAINDATA_USE_ALT_SPEED_LIMITS[] = "use_alt_speed_limits";
static const char KEY_FULL_UPDATE[] = "full_update"; static const char KEY_FULL_UPDATE[] = "full_update";
static const char KEY_RESPONSE_ID[] = "rid"; static const char KEY_RESPONSE_ID[] = "rid";
@ -333,6 +334,7 @@ QByteArray btjson::getSyncMainData(int acceptedResponseId, QVariantMap &lastData
QVariantMap serverState = getTranserInfoMap(); QVariantMap serverState = getTranserInfoMap();
serverState[KEY_SYNC_MAINDATA_QUEUEING] = QBtSession::instance()->isQueueingEnabled(); serverState[KEY_SYNC_MAINDATA_QUEUEING] = QBtSession::instance()->isQueueingEnabled();
serverState[KEY_SYNC_MAINDATA_USE_ALT_SPEED_LIMITS] = Preferences::instance()->isAltBandwidthEnabled();
data["server_state"] = serverState; data["server_state"] = serverState;
return json::toJson(generateSyncData(acceptedResponseId, data, lastAcceptedData, lastData)); return json::toJson(generateSyncData(acceptedResponseId, data, lastAcceptedData, lastData));

View file

@ -222,6 +222,11 @@ window.addEvent('load', function () {
$('queueingMenuItems').addClass('invisible'); $('queueingMenuItems').addClass('invisible');
} }
} }
if (alternativeSpeedLimits != serverState.use_alt_speed_limits) {
alternativeSpeedLimits = serverState.use_alt_speed_limits;
updateAltSpeedIcon(alternativeSpeedLimits);
}
}; };
var updateAltSpeedIcon = function(enabled) { var updateAltSpeedIcon = function(enabled) {
@ -231,16 +236,6 @@ window.addEvent('load', function () {
$('alternativeSpeedLimits').src = "images/slow_off.png" $('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) {
alternativeSpeedLimits = !!parseInt(isEnabled);
if (alternativeSpeedLimits)
$('alternativeSpeedLimits').src = "images/slow.png"
}
}).send();
$('alternativeSpeedLimits').addEvent('click', function() { $('alternativeSpeedLimits').addEvent('click', function() {
// Change icon immediately to give some feedback // Change icon immediately to give some feedback
updateAltSpeedIcon(!alternativeSpeedLimits); updateAltSpeedIcon(!alternativeSpeedLimits);