3
Contains the various bars (Sidebar, Toolbar, Statusbar) used within Deluge.
6
* Copyright (C) Damien Churchill 2008 <damoxc@gmail.com>
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 3, or (at your option)
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, write to:
20
* The Free Software Foundation, Inc.,
21
* 51 Franklin Street, Fifth Floor
22
* Boston, MA 02110-1301, USA.
24
# In addition, as a special exception, the copyright holders give
25
# permission to link the code of portions of this program with the OpenSSL
27
# You must obey the GNU General Public License in all respects for all of
28
# the code used other than OpenSSL. If you modify file(s) with this
29
# exception, you may extend this exception to your version of the file(s),
30
# but you are not obligated to do so. If you do not wish to do so, delete
31
# this exception statement from your version. If you delete this exception
32
# statement from all source files in the program, then also delete it here.
38
Class: Deluge.Widgets.Toolbar
39
Manages the top toolbar handling clicks and actions.
42
toolbar = new Deluge.Widgets.Toolbar();
45
An instance of the class wrapped about the toolbar.
48
Deluge.Widgets.Toolbar = new Class({
50
Extends: Widgets.Base,
52
initialize: function() {
53
this.parent($('toolbar'));
54
this.buttons = this.element.getFirst();
55
this.buttons.getElements('li').each(function(el) {
56
el.addEvent('click', function(e) {
58
this.fireEvent('buttonClick', e);
66
Class: Deluge.Widgets.StatusBar
67
Class to manage the bottom status bar
70
status = new Deluge.Widgets.StatusBar();
73
An instance of the class wrapped about the status div
75
Deluge.Widgets.StatusBar = new Class({
76
Extends: Widgets.Base,
78
initialize: function() {
79
this.parent($('status'));
81
onContextMenu: this.onContextMenu.bindWithEvent(this)
84
this.element.getElements('li').each(function(el) {
87
this.incoming_connections.setStyle('display', 'none');
89
this.connections.addEvent('contextmenu', this.bound.onContextMenu);
90
var menu = new Widgets.PopupMenu();
91
menu.add(Deluge.Menus.Connections);
92
menu.addEvent('action', this.onMenuAction);
93
this.connections.store('menu', menu);
95
this.downspeed.addEvent('contextmenu', this.bound.onContextMenu);
96
menu = new Widgets.PopupMenu();
97
menu.add(Deluge.Menus.Download);
98
menu.addEvent('action', this.onMenuAction);
99
this.downspeed.store('menu', menu);
101
this.upspeed.addEvent('contextmenu', this.bound.onContextMenu);
102
menu = new Widgets.PopupMenu();
103
menu.add(Deluge.Menus.Upload);
104
menu.addEvent('action', this.onMenuAction);
105
this.upspeed.store('menu', menu);
110
Takes thes stats part of the update_ui rpc call and
111
performs the required changes on the statusbar.
114
stats - A dictionary of the returned stats
117
statusbar.update(data['stats']);
119
update: function(stats) {
120
this.connections.set('text', stats.num_connections + ' (' + stats.max_num_connections + ')');
121
this.downspeed.set('text', stats.download_rate.toSpeed() + ' (' + stats.max_download + ' KiB/s)');
122
this.upspeed.set('text', stats.upload_rate.toSpeed() + ' (' + stats.max_upload + ' KiB/s)');
123
this.dht.set('text', stats.dht_nodes);
124
this.free_space.set('text', stats.free_space.toBytes());
125
if (stats.has_incoming_connections) {
126
this.incoming_connections.setStyle('display', 'none');
128
this.incoming_connections.setStyle('display', 'inline');
133
Property: onContextMenu
134
Event handler for when certain parts of the statusbar have been
141
el.addEvent('contextmenu', this.onContextMenu.bindWithEvent(this));
143
onContextMenu: function(e) {
145
var menu = e.target.retrieve('menu');
146
if (menu) menu.show(e);
150
Property: onMenuAction
151
Event handler for when an item in one of the menus is clicked.
152
Note that it does not need to be bound as it doesn't use `this`
153
anywhere within the method.
159
menu.addEvent('action', this.onMenuAction);
161
onMenuAction: function(e) {
162
if (e.action == 'max_connections') e.action = 'max_connections_global';
164
config[e.action] = e.value;
165
Deluge.Client.set_config(config);
172
Class: Deluge.Wdigets.Labels
173
Class to manage the filtering labels in the sidebar
176
labels = new Deluge.Widgets.Labels();
179
An instance of the class wrapped about the labels div
181
Deluge.Widgets.Labels = new Class({
183
Extends: Widgets.Base,
185
initialize: function() {
186
this.parent($('labels'));
188
labelClicked: this.labelClicked.bindWithEvent(this)
195
Takes thes filters part of the update_ui rpc call and
196
performs the required changes on the filtering
199
filters - A dictionary of the available filters
202
labels.update({'state': [['All', '3'], ['Downloading', '2']]);
204
update: function(filters) {
205
$each(filters, function(values, name) {
206
if ($defined(this.filters[name])) {
207
this.filters[name].update(values);
209
this.filters[name] = new Deluge.Widgets.LabelSection(name);
210
this.filters[name].addEvent('labelClicked', this.bound.labelClicked);
211
this.element.grab(this.filters[name]);
212
this.filters[name].update(values);
213
if (!this.filterType && !this.filterName) {
214
var el = this.filters[name].list.getElements('li')[0];
215
this.currentFilter = el;
216
this.filterType = name;
217
this.filterName = el.retrieve('filterName');
218
this.currentFilter.addClass('activestate');
225
Property: labelClicked
231
labelSection.addEvent('labelClicked', this.bound.labelClicked);
233
labelClicked: function(e) {
234
this.currentFilter.removeClass('activestate');
235
this.filterType = e.name;
236
this.filterName = e.filter;
237
this.currentFilter = e.target;
238
e.target.addClass('activestate');
239
this.fireEvent('filterChanged');
244
Class: Deluge.Widgets.LabelSection
245
Class to manage a section of filters within the labels block
248
string (the name of the section)
251
A widget with the ability to manage the filters
253
Deluge.Widgets.LabelSection = new Class({
255
Extends: Widgets.Base,
257
regex: /([\w]+)\s\((\d)\)/,
259
initialize: function(name) {
260
this.parent(new Element('div'));
263
'clicked': this.clicked.bindWithEvent(this)
266
name = name.replace('_', ' ');
267
parts = name.split(' ');
269
parts.each(function(part) {
270
firstLetter = part.substring(0, 1);
271
firstLetter = firstLetter.toUpperCase();
272
part = firstLetter + part.substring(1);
276
this.header = new Element('h3').set('text', name);
277
this.list = new Element('ul');
279
this.element.grab(this.header);
280
this.element.grab(this.list);
285
Updates the filters list
288
values - a list of name/count values for the filters
291
labelSection.update([['All', '3'], ['Downloading', '2']]);
293
update: function(values) {
295
$each(values, function(value) {
296
var name = value[0], count = value[1], lname = name.toLowerCase();
297
lname = lname.replace('.', '_');
298
names.include(lname);
299
var el = this.list.getElement('li.' + lname);
301
el = new Element('li').addClass(lname);
302
el.store('filterName', name)
303
el.addEvent('click', this.bound.clicked);
304
if (this.name == 'tracker_host') {
305
var icon = 'url(/tracker/icon/' + name + ')';
306
el.setStyle('background-image', icon);
310
el.set('text', name + ' (' + count +')');
313
// Clean out any labels that are no longer returned
314
this.list.getElements('li').each(function(el) {
316
names.each(function(name) {
318
hasName = el.hasClass(name);
329
Event handler for when a list item is clicked
335
listItem.addEvent('click', this.clicked.bindWithEvent(this));
337
clicked: function(e) {
338
e.filter = e.target.retrieve('filterName');
340
this.fireEvent('labelClicked', e);