add a window that allows you to quickly set a custom bandwidth limit

This commit is contained in:
Damien Churchill 2010-04-28 13:28:47 +01:00
parent 00dc5f0128
commit c8c5e3449a
3 changed files with 115 additions and 5 deletions

View File

@ -0,0 +1,95 @@
/*!
* Deluge.OtherLimitWindow.js
*
* Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the OpenSSL
* library.
* You must obey the GNU General Public License in all respects for all of
* the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete
* this exception statement from your version. If you delete this exception
* statement from all source files in the program, then also delete it here.
*/
Ext.ns('Deluge');
/**
* @class Deluge.OtherLimitWindow
* @extends Ext.Window
*/
Deluge.OtherLimitWindow = Ext.extend(Ext.Window, {
layout: 'fit',
width: 210,
height: 100,
closeAction: 'hide',
initComponent: function() {
Deluge.OtherLimitWindow.superclass.initComponent.call(this);
this.form = this.add({
xtype: 'form',
baseCls: 'x-plain',
bodyStyle: 'padding: 5px',
layout: 'hbox',
layoutConfig: {
pack: 'start'
},
items: [{
xtype: 'spinnerfield',
name: 'limit'
}]
});
if (this.initialConfig.unit) {
this.form.add({
border: false,
baseCls: 'x-plain',
bodyStyle: 'padding: 5px',
html: this.initialConfig.unit
});
} else {
this.setSize(180, 100);
}
this.addButton(_('Cancel'), this.onCancelClick, this);
this.addButton(_('Ok'), this.onOkClick, this);
},
setValue: function(value) {
this.form.getForm().setValues({limit: value});
},
onCancelClick: function() {
this.form.getForm().reset();
this.hide();
},
onOkClick: function() {
var config = {};
config[this.group] = this.form.getForm().getValues().limit;
deluge.client.core.set_config(config, {
success: function() {
deluge.ui.update();
}
});
this.hide();
}
});

View File

@ -91,7 +91,10 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, {
value: 'other', value: 'other',
group: 'max_connections_global', group: 'max_connections_global',
checked: false checked: false
}] }],
otherWin: {
title: _('Set Maximum Connections')
}
}), }),
}, '-', { }, '-', {
id: 'statusbar-downspeed', id: 'statusbar-downspeed',
@ -135,7 +138,11 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, {
text: _('Other'), text: _('Other'),
group: 'max_download_speed', group: 'max_download_speed',
checked: false checked: false
}] }],
otherWin: {
title: _('Set Maximum Download Speed'),
unit: _('Kib/s')
}
}), }),
}, '-', { }, '-', {
id: 'statusbar-upspeed', id: 'statusbar-upspeed',
@ -179,7 +186,11 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, {
text: _('Other'), text: _('Other'),
group: 'max_upload_speed', group: 'max_upload_speed',
checked: false checked: false
}] }],
otherWin: {
title: _('Set Maximum Upload Speed'),
unit: _('Kib/s')
}
}) })
}, '-', { }, '-', {
id: 'statusbar-traffic', id: 'statusbar-traffic',

View File

@ -40,6 +40,8 @@ Deluge.StatusbarMenu = Ext.extend(Ext.menu.Menu, {
initComponent: function() { initComponent: function() {
Deluge.StatusbarMenu.superclass.initComponent.call(this); Deluge.StatusbarMenu.superclass.initComponent.call(this);
this.otherWin = new Deluge.OtherLimitWindow(this.initialConfig.otherWin || {});
this.items.each(function(item) { this.items.each(function(item) {
if (item.getXType() != 'menucheckitem') return; if (item.getXType() != 'menucheckitem') return;
item.on('checkchange', this.onLimitChanged, this); item.on('checkchange', this.onLimitChanged, this);
@ -49,7 +51,7 @@ Deluge.StatusbarMenu = Ext.extend(Ext.menu.Menu, {
setValue: function(value) { setValue: function(value) {
var beenSet = false; var beenSet = false;
// set the new value // set the new value
value = (value == 0) ? -1 : value; this.value = value = (value == 0) ? -1 : value;
var other = null; var other = null;
// uncheck all items // uncheck all items
@ -79,7 +81,9 @@ Deluge.StatusbarMenu = Ext.extend(Ext.menu.Menu, {
if (!checked) return; // we don't care about unchecks if (!checked) return; // we don't care about unchecks
if (item.value == 'other') { if (item.value == 'other') {
// pop up other limit window in due course this.otherWin.group = item.group;
this.otherWin.setValue(this.value);
this.otherWin.show();
} else { } else {
config = {} config = {}
config[item.group] = item.value config[item.group] = item.value