From 364e4277ecca1bd18bc83a0669d96a2dfe3a7573 Mon Sep 17 00:00:00 2001 From: buinsky Date: Sat, 13 Dec 2014 02:48:30 +0300 Subject: [PATCH] Show upload and download limits in status bar --- src/webui/btjson.cpp | 8 ++++++++ src/webui/www/public/scripts/client.js | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/webui/btjson.cpp b/src/webui/btjson.cpp index 0f422b4ad..1c8190fd2 100644 --- a/src/webui/btjson.cpp +++ b/src/webui/btjson.cpp @@ -45,6 +45,7 @@ #endif #include +#include using namespace libtorrent; @@ -135,8 +136,10 @@ static const char KEY_FILE_IS_SEED[] = "is_seed"; // TransferInfo keys static const char KEY_TRANSFER_DLSPEED[] = "dl_info_speed"; static const char KEY_TRANSFER_DLDATA[] = "dl_info_data"; +static const char KEY_TRANSFER_DLRATELIMIT[] = "dl_rate_limit"; static const char KEY_TRANSFER_UPSPEED[] = "up_info_speed"; static const char KEY_TRANSFER_UPDATA[] = "up_info_data"; +static const char KEY_TRANSFER_UPRATELIMIT[] = "up_rate_limit"; class QTorrentCompare { @@ -448,9 +451,14 @@ QByteArray btjson::getTransferInfo() { CACHED_VARIABLE(QVariantMap, info, CACHE_DURATION_MS); session_status sessionStatus = QBtSession::instance()->getSessionStatus(); + session_settings sessionSettings = QBtSession::instance()->getSession()->settings(); info[KEY_TRANSFER_DLSPEED] = sessionStatus.payload_download_rate; info[KEY_TRANSFER_DLDATA] = static_cast(sessionStatus.total_payload_download); info[KEY_TRANSFER_UPSPEED] = sessionStatus.payload_upload_rate; info[KEY_TRANSFER_UPDATA] = static_cast(sessionStatus.total_payload_upload); + if (sessionSettings.download_rate_limit) + info[KEY_TRANSFER_DLRATELIMIT] = sessionSettings.download_rate_limit; + if (sessionSettings.upload_rate_limit) + info[KEY_TRANSFER_UPRATELIMIT] = sessionSettings.upload_rate_limit; return json::toJson(info); } diff --git a/src/webui/www/public/scripts/client.js b/src/webui/www/public/scripts/client.js index e7bd8b652..8602f72a3 100644 --- a/src/webui/www/public/scripts/client.js +++ b/src/webui/www/public/scripts/client.js @@ -240,12 +240,20 @@ window.addEvent('load', function () { }, onSuccess : function (info) { if (info) { - $("DlInfos").set('html', "_(D: %1 - T: %2)" + dl_limit = ""; + if (info.dl_rate_limit != undefined) + dl_limit = "[%1] ".replace("%1", friendlyUnit(info.dl_rate_limit, true)); + $("DlInfos").set('html', "%3_(D: %1 - T: %2)" .replace("%1", friendlyUnit(info.dl_info_speed, true)) - .replace("%2", friendlyUnit(info.dl_info_data, false))); - $("UpInfos").set('html', "_(U: %1 - T: %2)" + .replace("%2", friendlyUnit(info.dl_info_data, false)) + .replace("%3", dl_limit)); + up_limit = ""; + if (info.up_rate_limit != undefined) + up_limit = "[%1] ".replace("%1", friendlyUnit(info.up_rate_limit, true)); + $("UpInfos").set('html', "%3_(U: %1 - T: %2)" .replace("%1", friendlyUnit(info.up_info_speed, true)) - .replace("%2", friendlyUnit(info.up_info_data, false))); + .replace("%2", friendlyUnit(info.up_info_data, false)) + .replace("%3", up_limit)); if (speedInTitle) document.title = "_(D:%1 U:%2)".replace("%1", friendlyUnit(info.dl_info_speed, true)).replace("%2", friendlyUnit(info.up_info_speed, true)); else