diff --git a/src/httpconnection.cpp b/src/httpconnection.cpp index aa7e25f9b..4a69244de 100644 --- a/src/httpconnection.cpp +++ b/src/httpconnection.cpp @@ -305,7 +305,7 @@ void HttpConnection::respondPreferencesJson() { void HttpConnection::respondGlobalTransferInfoJson() { QVariantMap info; - session_status sessionStatus = parent->getBTSession()->getSessionStatus(); + session_status sessionStatus = BTSession->getSessionStatus(); info["DlInfos"] = tr("D: %1/s - T: %2", "Download speed: x KiB/s - Transferred: x MiB").arg(misc::friendlyUnit(sessionStatus.payload_download_rate)).arg(misc::friendlyUnit(sessionStatus.total_payload_download)); info["UpInfos"] = tr("U: %1/s - T: %2", "Upload speed: x KiB/s - Transferred: x MiB").arg(misc::friendlyUnit(sessionStatus.payload_upload_rate)).arg(misc::friendlyUnit(sessionStatus.total_payload_upload)); QString string = json::toJson(info); @@ -454,6 +454,18 @@ void HttpConnection::respondCommand(QString command) h.set_download_limit(limit); } } + if(command == "setGlobalUpLimit") { + qlonglong limit = parser.post("limit").toLongLong(); + if(limit == 0) limit = -1; + BTSession->getSession()->set_upload_rate_limit(limit); + Preferences::setGlobalUploadLimit(limit/1024.); + } + if(command == "setGlobalDlLimit") { + qlonglong limit = parser.post("limit").toLongLong(); + if(limit == 0) limit = -1; + BTSession->getSession()->set_download_rate_limit(limit); + Preferences::setGlobalDownloadLimit(limit/1024.); + } if(command == "pause") { emit pauseTorrent(parser.post("hash")); return; diff --git a/src/httpserver.h b/src/httpserver.h index 6966accbf..373708efe 100644 --- a/src/httpserver.h +++ b/src/httpserver.h @@ -60,7 +60,6 @@ class HttpServer : public QTcpServer { EventManager *eventManager() const; QString generateNonce() const; QHash client_failed_attempts; - Bittorrent *getBTSession() const { return BTSession; } private slots: void newHttpConnection(); diff --git a/src/webui/downloadlimit.html b/src/webui/downloadlimit.html index 75a152743..011206018 100644 --- a/src/webui/downloadlimit.html +++ b/src/webui/downloadlimit.html @@ -24,13 +24,23 @@ var hash = new URI().getData('hash'); setDlLimit = function() { var limit = $("dllimitUpdatevalue").get('html').toInt() * 1024; - new Request({url: '/command/setTorrentDlLimit', - method: 'post', - data: {'hash': hash, 'limit': limit}, - onComplete: function() { - window.parent.closeWindows(); - } - }).send(); + if(hash == "global") { + new Request({url: '/command/setGlobalDlLimit', + method: 'post', + data: {'limit': limit}, + onComplete: function() { + window.parent.closeWindows(); + } + }).send(); + } else { + new Request({url: '/command/setTorrentDlLimit', + method: 'post', + data: {'hash': hash, 'limit': limit}, + onComplete: function() { + window.parent.closeWindows(); + } + }).send(); + } } diff --git a/src/webui/index.html b/src/webui/index.html index 6b5e0665f..142cc6d8f 100644 --- a/src/webui/index.html +++ b/src/webui/index.html @@ -100,7 +100,7 @@
- +
diff --git a/src/webui/scripts/client.js b/src/webui/scripts/client.js index 8f719df9e..7ad7ca472 100644 --- a/src/webui/scripts/client.js +++ b/src/webui/scripts/client.js @@ -135,6 +135,9 @@ window.addEvent('load', function(){ }).send(); } }; + $('DlInfos').addEvent('click', globalDownloadLimitFN); + $('UpInfos').addEvent('click', globalUploadLimitFN); + var ajaxfn = function(){ var queueing_enabled = false; var url = 'json/events'; diff --git a/src/webui/scripts/mocha-init.js b/src/webui/scripts/mocha-init.js index 62decf397..64a852b3a 100644 --- a/src/webui/scripts/mocha-init.js +++ b/src/webui/scripts/mocha-init.js @@ -76,6 +76,22 @@ initializeWindows = function(){ }); }); + globalUploadLimitFN = function() { + new MochaUI.Window({ + id: 'uploadLimitPage', + title: "_(Global Upload Speed Limiting)", + loadMethod: 'iframe', + contentURL:'uploadlimit.html?hash=global', + scrollbars: false, + resizable: false, + maximizable: false, + paddingVertical: 0, + paddingHorizontal: 0, + width: 424, + height: 80 + }); + } + uploadLimitFN = function() { var h = myTable.selectedIds(); if(h.length){ @@ -96,6 +112,22 @@ initializeWindows = function(){ } }; + globalDownloadLimitFN = function() { + new MochaUI.Window({ + id: 'downloadLimitPage', + title: "_(Global Download Speed Limiting)", + loadMethod: 'iframe', + contentURL:'downloadlimit.html?hash=global', + scrollbars: false, + resizable: false, + maximizable: false, + paddingVertical: 0, + paddingHorizontal: 0, + width: 424, + height: 80 + }); + } + downloadLimitFN = function() { var h = myTable.selectedIds(); if(h.length){ diff --git a/src/webui/scripts/parametrics.js b/src/webui/scripts/parametrics.js index 3cbb148bf..b6fc2e95e 100644 --- a/src/webui/scripts/parametrics.js +++ b/src/webui/scripts/parametrics.js @@ -32,40 +32,68 @@ MochaUI.extend({ maximum = tmp / 1024. } } - } - }).send(); - // Get torrent upload limit - // And create slider - var req = new Request({ - url: '/command/getTorrentUpLimit', - method: 'post', - data: {hash: hash}, - onSuccess: function(data) { - if(data){ - var up_limit = data.toInt(); + // Get torrent upload limit + // And create slider + if(hash == 'global') { + var up_limit = maximum; if(up_limit < 0) up_limit = 0; + maximum = 1000; var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), { - steps: maximum, - offset: 0, - initialStep: (up_limit/1024.).round(), - onChange: function(pos){ - if(pos > 0) { - $('uplimitUpdatevalue').set('html', pos); - $('upLimitUnit').set('html', "_(KiB/s)"); - } else { - $('uplimitUpdatevalue').set('html', '∞'); - $('upLimitUnit').set('html', ""); - } - }.bind(this) - }); + steps: maximum, + offset: 0, + initialStep: up_limit.round(), + onChange: function(pos){ + if(pos > 0) { + $('uplimitUpdatevalue').set('html', pos); + $('upLimitUnit').set('html', "_(KiB/s)"); + } else { + $('uplimitUpdatevalue').set('html', '∞'); + $('upLimitUnit').set('html', ""); + } + }.bind(this) + }); // Set default value if(up_limit == 0) { $('uplimitUpdatevalue').set('html', '∞'); $('upLimitUnit').set('html', ""); } else { - $('uplimitUpdatevalue').set('html', (up_limit/1024.).round()); + $('uplimitUpdatevalue').set('html', up_limit.round()); $('upLimitUnit').set('html', "_(KiB/s)"); } + } else { + var req = new Request({ + url: '/command/getTorrentUpLimit', + method: 'post', + data: {hash: hash}, + onSuccess: function(data) { + if(data){ + var up_limit = data.toInt(); + if(up_limit < 0) up_limit = 0; + var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), { + steps: maximum, + offset: 0, + initialStep: (up_limit/1024.).round(), + onChange: function(pos){ + if(pos > 0) { + $('uplimitUpdatevalue').set('html', pos); + $('upLimitUnit').set('html', "_(KiB/s)"); + } else { + $('uplimitUpdatevalue').set('html', '∞'); + $('upLimitUnit').set('html', ""); + } + }.bind(this) + }); + // Set default value + if(up_limit == 0) { + $('uplimitUpdatevalue').set('html', '∞'); + $('upLimitUnit').set('html', ""); + } else { + $('uplimitUpdatevalue').set('html', (up_limit/1024.).round()); + $('upLimitUnit').set('html', "_(KiB/s)"); + } + } + } + }).send(); } } }).send(); @@ -89,22 +117,16 @@ MochaUI.extend({ maximum = tmp / 1024. } } - } - }).send(); - // Get torrent download limit - // And create slider - var req = new Request({ - url: '/command/getTorrentDlLimit', - method: 'post', - data: {hash: hash}, - onSuccess: function(data) { - if(data){ - var dl_limit = data.toInt(); + // Get torrent download limit + // And create slider + if(hash == "global") { + var dl_limit = maximum; if(dl_limit < 0) dl_limit = 0; + maximum = 1000; var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), { steps: maximum, offset: 0, - initialStep: (dl_limit/1024.).round(), + initialStep: dl_limit.round(), onChange: function(pos){ if(pos > 0) { $('dllimitUpdatevalue').set('html', pos); @@ -120,9 +142,43 @@ MochaUI.extend({ $('dllimitUpdatevalue').set('html', '∞'); $('dlLimitUnit').set('html', ""); } else { - $('dllimitUpdatevalue').set('html', (dl_limit/1024.).round()); + $('dllimitUpdatevalue').set('html', dl_limit.round()); $('dlLimitUnit').set('html', "_(KiB/s)"); } + } else { + var req = new Request({ + url: '/command/getTorrentDlLimit', + method: 'post', + data: {hash: hash}, + onSuccess: function(data) { + if(data){ + var dl_limit = data.toInt(); + if(dl_limit < 0) dl_limit = 0; + var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), { + steps: maximum, + offset: 0, + initialStep: (dl_limit/1024.).round(), + onChange: function(pos){ + if(pos > 0) { + $('dllimitUpdatevalue').set('html', pos); + $('dlLimitUnit').set('html', "_(KiB/s)"); + } else { + $('dllimitUpdatevalue').set('html', '∞'); + $('dlLimitUnit').set('html', ""); + } + }.bind(this) + }); + // Set default value + if(dl_limit == 0) { + $('dllimitUpdatevalue').set('html', '∞'); + $('dlLimitUnit').set('html', ""); + } else { + $('dllimitUpdatevalue').set('html', (dl_limit/1024.).round()); + $('dlLimitUnit').set('html', "_(KiB/s)"); + } + } + } + }).send(); } } }).send(); diff --git a/src/webui/uploadlimit.html b/src/webui/uploadlimit.html index eb3ac2280..43c57070f 100644 --- a/src/webui/uploadlimit.html +++ b/src/webui/uploadlimit.html @@ -24,13 +24,23 @@ var hash = new URI().getData('hash'); setUpLimit = function() { var limit = $("uplimitUpdatevalue").get('html').toInt() * 1024; - new Request({url: '/command/setTorrentUpLimit', - method: 'post', - data: {'hash': hash, 'limit': limit}, - onComplete: function() { - window.parent.closeWindows(); - } - }).send(); + if(hash == "global") { + new Request({url: '/command/setGlobalUpLimit', + method: 'post', + data: {'limit': limit}, + onComplete: function() { + window.parent.closeWindows(); + } + }).send(); + }else { + new Request({url: '/command/setTorrentUpLimit', + method: 'post', + data: {'hash': hash, 'limit': limit}, + onComplete: function() { + window.parent.closeWindows(); + } + }).send(); + } }