Module: deluge
Branch: master
Commit: c8c5e3449a990e850302328144c2c2084e3c5d17

Author: Damien Churchill <[email protected]>
Date:   Wed Apr 28 13:28:47 2010 +0100

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

---

 deluge/ui/web/js/deluge-all/OtherLimitWindow.js |   95 +++++++++++++++++++++++
 deluge/ui/web/js/deluge-all/Statusbar.js        |   17 ++++-
 deluge/ui/web/js/deluge-all/StatusbarMenu.js    |    8 ++-
 3 files changed, 115 insertions(+), 5 deletions(-)

diff --git a/deluge/ui/web/js/deluge-all/OtherLimitWindow.js 
b/deluge/ui/web/js/deluge-all/OtherLimitWindow.js
new file mode 100644
index 0000000..8769fe0
--- /dev/null
+++ b/deluge/ui/web/js/deluge-all/OtherLimitWindow.js
@@ -0,0 +1,95 @@
+/*!
+ * Deluge.OtherLimitWindow.js
+ * 
+ * Copyright (c) Damien Churchill 2009-2010 <[email protected]>
+ *
+ * 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();
+       }
+});
diff --git a/deluge/ui/web/js/deluge-all/Statusbar.js 
b/deluge/ui/web/js/deluge-all/Statusbar.js
index 77614bb..a578d92 100644
--- a/deluge/ui/web/js/deluge-all/Statusbar.js
+++ b/deluge/ui/web/js/deluge-all/Statusbar.js
@@ -91,7 +91,10 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, {
                                        value: 'other',
                                        group: 'max_connections_global',
                                        checked: false
-                               }]
+                               }],
+                               otherWin: {
+                                       title: _('Set Maximum Connections')
+                               }
                        }),
                }, '-', {
                        id: 'statusbar-downspeed',
@@ -135,7 +138,11 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, {
                                        text: _('Other'),
                                        group: 'max_download_speed',
                                        checked: false
-                               }]
+                               }],
+                               otherWin: {
+                                       title: _('Set Maximum Download Speed'),
+                                       unit: _('Kib/s')
+                               }
                        }),
                }, '-', {
                        id: 'statusbar-upspeed',
@@ -179,7 +186,11 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, {
                                        text: _('Other'),
                                        group: 'max_upload_speed',
                                        checked: false
-                               }]
+                               }],
+                               otherWin: {
+                                       title: _('Set Maximum Upload Speed'),
+                                       unit: _('Kib/s')
+                               }
                        })
                }, '-', {
                        id: 'statusbar-traffic',
diff --git a/deluge/ui/web/js/deluge-all/StatusbarMenu.js 
b/deluge/ui/web/js/deluge-all/StatusbarMenu.js
index b7f3948..092181e 100644
--- a/deluge/ui/web/js/deluge-all/StatusbarMenu.js
+++ b/deluge/ui/web/js/deluge-all/StatusbarMenu.js
@@ -40,6 +40,8 @@ Deluge.StatusbarMenu = Ext.extend(Ext.menu.Menu, {
        
        initComponent: function() {
                Deluge.StatusbarMenu.superclass.initComponent.call(this);
+               this.otherWin = new 
Deluge.OtherLimitWindow(this.initialConfig.otherWin || {});
+
                this.items.each(function(item) {
                        if (item.getXType() != 'menucheckitem') return;
                        item.on('checkchange', this.onLimitChanged, this);
@@ -49,7 +51,7 @@ Deluge.StatusbarMenu = Ext.extend(Ext.menu.Menu, {
     setValue: function(value) {
         var beenSet = false;
         // set the new value
-        value = (value == 0) ? -1 : value;
+        this.value = value = (value == 0) ? -1 : value;
 
         var other = null;
         // uncheck all items
@@ -79,7 +81,9 @@ Deluge.StatusbarMenu = Ext.extend(Ext.menu.Menu, {
                if (!checked) return; // we don't care about unchecks
 
                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 {
                        config = {}
                        config[item.group] = item.value

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to