Browse Source

- Global Upload/Download rates can be set by clicking on the status bar values

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
13493e1afe
  1. 14
      src/httpconnection.cpp
  2. 1
      src/httpserver.h
  3. 24
      src/webui/downloadlimit.html
  4. 2
      src/webui/index.html
  5. 3
      src/webui/scripts/client.js
  6. 32
      src/webui/scripts/mocha-init.js
  7. 132
      src/webui/scripts/parametrics.js
  8. 24
      src/webui/uploadlimit.html

14
src/httpconnection.cpp

@ -305,7 +305,7 @@ void HttpConnection::respondPreferencesJson() {
void HttpConnection::respondGlobalTransferInfoJson() { void HttpConnection::respondGlobalTransferInfoJson() {
QVariantMap info; 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["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)); 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); QString string = json::toJson(info);
@ -454,6 +454,18 @@ void HttpConnection::respondCommand(QString command)
h.set_download_limit(limit); 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") { if(command == "pause") {
emit pauseTorrent(parser.post("hash")); emit pauseTorrent(parser.post("hash"));
return; return;

1
src/httpserver.h

@ -60,7 +60,6 @@ class HttpServer : public QTcpServer {
EventManager *eventManager() const; EventManager *eventManager() const;
QString generateNonce() const; QString generateNonce() const;
QHash<QString, int> client_failed_attempts; QHash<QString, int> client_failed_attempts;
Bittorrent *getBTSession() const { return BTSession; }
private slots: private slots:
void newHttpConnection(); void newHttpConnection();

24
src/webui/downloadlimit.html

@ -24,13 +24,23 @@
var hash = new URI().getData('hash'); var hash = new URI().getData('hash');
setDlLimit = function() { setDlLimit = function() {
var limit = $("dllimitUpdatevalue").get('html').toInt() * 1024; var limit = $("dllimitUpdatevalue").get('html').toInt() * 1024;
new Request({url: '/command/setTorrentDlLimit', if(hash == "global") {
method: 'post', new Request({url: '/command/setGlobalDlLimit',
data: {'hash': hash, 'limit': limit}, method: 'post',
onComplete: function() { data: {'limit': limit},
window.parent.closeWindows(); onComplete: function() {
} window.parent.closeWindows();
}).send(); }
}).send();
} else {
new Request({url: '/command/setTorrentDlLimit',
method: 'post',
data: {'hash': hash, 'limit': limit},
onComplete: function() {
window.parent.closeWindows();
}
}).send();
}
} }
</script> </script>
<input type="button" value="_(Apply)" onclick="setDlLimit()"/> <input type="button" value="_(Apply)" onclick="setDlLimit()"/>

2
src/webui/index.html

@ -100,7 +100,7 @@
<div id="desktopFooterWrapper"> <div id="desktopFooterWrapper">
<div id="desktopFooter"> <div id="desktopFooter">
<table style="position: absolute; right: 5px;"> <table style="position: absolute; right: 5px;">
<tr><td id="DlInfos"></td><td style="width: 2px;margin:0;"><img src="images/skin/toolbox-divider.gif" style="height: 18px; padding-left: 10px; padding-right: 10px; margin-bottom: -2px;"/></td><td id="UpInfos"></td></tr> <tr><td id="DlInfos" style="cursor:pointer;"></td><td style="width: 2px;margin:0;"><img src="images/skin/toolbox-divider.gif" 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>

3
src/webui/scripts/client.js

@ -135,6 +135,9 @@ window.addEvent('load', function(){
}).send(); }).send();
} }
}; };
$('DlInfos').addEvent('click', globalDownloadLimitFN);
$('UpInfos').addEvent('click', globalUploadLimitFN);
var ajaxfn = function(){ var ajaxfn = function(){
var queueing_enabled = false; var queueing_enabled = false;
var url = 'json/events'; var url = 'json/events';

32
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() { uploadLimitFN = function() {
var h = myTable.selectedIds(); var h = myTable.selectedIds();
if(h.length){ 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() { downloadLimitFN = function() {
var h = myTable.selectedIds(); var h = myTable.selectedIds();
if(h.length){ if(h.length){

132
src/webui/scripts/parametrics.js

@ -32,40 +32,68 @@ MochaUI.extend({
maximum = tmp / 1024. maximum = tmp / 1024.
} }
} }
} // Get torrent upload limit
}).send(); // And create slider
// Get torrent upload limit if(hash == 'global') {
// And create slider var up_limit = maximum;
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; if(up_limit < 0) up_limit = 0;
maximum = 1000;
var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), { var mochaSlide = new Slider($('uplimitSliderarea'), $('uplimitSliderknob'), {
steps: maximum, steps: maximum,
offset: 0, offset: 0,
initialStep: (up_limit/1024.).round(), initialStep: up_limit.round(),
onChange: function(pos){ onChange: function(pos){
if(pos > 0) { if(pos > 0) {
$('uplimitUpdatevalue').set('html', pos); $('uplimitUpdatevalue').set('html', pos);
$('upLimitUnit').set('html', "_(KiB/s)"); $('upLimitUnit').set('html', "_(KiB/s)");
} else { } else {
$('uplimitUpdatevalue').set('html', '∞'); $('uplimitUpdatevalue').set('html', '∞');
$('upLimitUnit').set('html', ""); $('upLimitUnit').set('html', "");
} }
}.bind(this) }.bind(this)
}); });
// Set default value // Set default value
if(up_limit == 0) { if(up_limit == 0) {
$('uplimitUpdatevalue').set('html', '∞'); $('uplimitUpdatevalue').set('html', '∞');
$('upLimitUnit').set('html', ""); $('upLimitUnit').set('html', "");
} else { } else {
$('uplimitUpdatevalue').set('html', (up_limit/1024.).round()); $('uplimitUpdatevalue').set('html', up_limit.round());
$('upLimitUnit').set('html', "_(KiB/s)"); $('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(); }).send();
@ -89,22 +117,16 @@ MochaUI.extend({
maximum = tmp / 1024. maximum = tmp / 1024.
} }
} }
} // Get torrent download limit
}).send(); // And create slider
// Get torrent download limit if(hash == "global") {
// And create slider var dl_limit = maximum;
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; if(dl_limit < 0) dl_limit = 0;
maximum = 1000;
var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), { var mochaSlide = new Slider($('dllimitSliderarea'), $('dllimitSliderknob'), {
steps: maximum, steps: maximum,
offset: 0, offset: 0,
initialStep: (dl_limit/1024.).round(), initialStep: dl_limit.round(),
onChange: function(pos){ onChange: function(pos){
if(pos > 0) { if(pos > 0) {
$('dllimitUpdatevalue').set('html', pos); $('dllimitUpdatevalue').set('html', pos);
@ -120,9 +142,43 @@ MochaUI.extend({
$('dllimitUpdatevalue').set('html', '∞'); $('dllimitUpdatevalue').set('html', '∞');
$('dlLimitUnit').set('html', ""); $('dlLimitUnit').set('html', "");
} else { } else {
$('dllimitUpdatevalue').set('html', (dl_limit/1024.).round()); $('dllimitUpdatevalue').set('html', dl_limit.round());
$('dlLimitUnit').set('html', "_(KiB/s)"); $('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(); }).send();

24
src/webui/uploadlimit.html

@ -24,13 +24,23 @@
var hash = new URI().getData('hash'); var hash = new URI().getData('hash');
setUpLimit = function() { setUpLimit = function() {
var limit = $("uplimitUpdatevalue").get('html').toInt() * 1024; var limit = $("uplimitUpdatevalue").get('html').toInt() * 1024;
new Request({url: '/command/setTorrentUpLimit', if(hash == "global") {
method: 'post', new Request({url: '/command/setGlobalUpLimit',
data: {'hash': hash, 'limit': limit}, method: 'post',
onComplete: function() { data: {'limit': limit},
window.parent.closeWindows(); onComplete: function() {
} window.parent.closeWindows();
}).send(); }
}).send();
}else {
new Request({url: '/command/setTorrentUpLimit',
method: 'post',
data: {'hash': hash, 'limit': limit},
onComplete: function() {
window.parent.closeWindows();
}
}).send();
}
} }
</script> </script>
<input type="button" value="_(Apply)" onclick="setUpLimit()"/> <input type="button" value="_(Apply)" onclick="setUpLimit()"/>

Loading…
Cancel
Save