milestone number 1, web interface loads now

This commit is contained in:
Damien Churchill 2011-07-02 17:09:10 +01:00
commit 42b8af25aa
16 changed files with 218 additions and 179 deletions

View file

@ -52,10 +52,22 @@ Ext.define('Deluge.AddConnectionWindow', {
this.addEvents('hostadded'); this.addEvents('hostadded');
this.addButton(_('Close'), this.hide, this); this.addDocked({
this.addButton(_('Add'), this.onAddClick, this); xtype: 'toolbar',
dock: 'bottom',
defaultType: 'button',
items: [
'->',
{text: _('Close'), handler: function() {
this.setVisible(false);
}, scope: this},
{text: _('Add'), handler: this.onAddClick, scope: this}
]
});
this.on('hide', this.onHide, this); this.on('hide', function() {
this.form.getForm().reset();
}, this);
this.form = this.add({ this.form = this.add({
xtype: 'form', xtype: 'form',
@ -65,28 +77,22 @@ Ext.define('Deluge.AddConnectionWindow', {
items: [{ items: [{
fieldLabel: _('Host'), fieldLabel: _('Host'),
name: 'host', name: 'host',
anchor: '75%',
value: '' value: ''
}, { }, {
xtype: 'spinnerfield', xtype: 'numberfield',
fieldLabel: _('Port'), fieldLabel: _('Port'),
name: 'port', name: 'port',
strategy: { width: 175,
xtype: 'number', value: 58846,
decimalPrecision: 0, minValue: -1,
minValue: -1, maxValue: 65535,
maxValue: 65535 decimalPrecision: 0,
},
value: '58846',
anchor: '40%'
}, { }, {
fieldLabel: _('Username'), fieldLabel: _('Username'),
name: 'username', name: 'username',
anchor: '75%',
value: '' value: ''
}, { }, {
fieldLabel: _('Password'), fieldLabel: _('Password'),
anchor: '75%',
name: 'password', name: 'password',
inputType: 'password', inputType: 'password',
value: '' value: ''
@ -114,9 +120,5 @@ Ext.define('Deluge.AddConnectionWindow', {
}, },
scope: this scope: this
}); });
},
onHide: function() {
this.form.getForm().reset();
} }
}); });

View file

@ -72,7 +72,8 @@ Ext.define('Deluge.ConnectionManager', {
type: 'memory', type: 'memory',
reader: { reader: {
type: 'json', type: 'json',
root: 'hosts' root: 'hosts',
idProperty: 'id'
} }
} }
}), }),
@ -102,7 +103,7 @@ Ext.define('Deluge.ConnectionManager', {
{xtype: 'button', text: _('Add'), iconCls: 'icon-add', handler: this.onAddClick, scope: this}, {xtype: 'button', text: _('Add'), iconCls: 'icon-add', handler: this.onAddClick, scope: this},
{xtype: 'button', text: _('Remove'), iconCls: 'icon-remove', handler: this.onRemoveClick, scope: this}, {xtype: 'button', text: _('Remove'), iconCls: 'icon-remove', handler: this.onRemoveClick, scope: this},
'->', '->',
{xtype: 'button', text: _('Stop Daemon'), iconCls: 'icon-error', handler: this.onStopClick, scope: this} {xtype: 'button', text: _('Stop Daemon'), iconCls: 'icon-error', handler: this.onStopClick, scope: this, disabled: true}
] ]
}); });
@ -143,7 +144,7 @@ Ext.define('Deluge.ConnectionManager', {
update: function() { update: function() {
this.grid.getStore().each(function(r) { this.grid.getStore().each(function(r) {
deluge.client.web.get_host_status(r.id, { deluge.client.web.get_host_status(r.getId(), {
success: this.onGetHostStatus, success: this.onGetHostStatus,
scope: this scope: this
}); });
@ -156,21 +157,23 @@ Ext.define('Deluge.ConnectionManager', {
* @param {Ext.data.Record} record The hosts record to update the UI for * @param {Ext.data.Record} record The hosts record to update the UI for
*/ */
updateButtons: function(record) { updateButtons: function(record) {
var button = this.buttons[1], status = record.get('status'); var btns = this.query('toolbar[dock=bottom] button'),
btn = btns[4],
s = record.get('status');
// Update the Connect/Disconnect button // Update the Connect/Disconnect button
if (status == _('Connected')) { if (s == _('Connected')) {
button.enable(); btn.enable();
button.setText(_('Disconnect')); btn.setText(_('Disconnect'));
} else if (status == _('Offline')) { } else if (s == _('Offline')) {
button.disable(); btn.disable();
} else { } else {
button.enable(); btn.enable();
button.setText(_('Connect')); btn.setText(_('Connect'));
} }
// Update the Stop/Start Daemon button // Update the Stop/Start Daemon button
if (status == _('Offline')) { if (s == _('Offline')) {
if (record.get('host') == '127.0.0.1' || record.get('host') == 'localhost') { if (record.get('host') == '127.0.0.1' || record.get('host') == 'localhost') {
this.stopHostButton.enable(); this.stopHostButton.enable();
this.stopHostButton.setText(_('Start Daemon')); this.stopHostButton.setText(_('Start Daemon'));
@ -204,7 +207,9 @@ Ext.define('Deluge.ConnectionManager', {
// private // private
onConnect: function(e) { onConnect: function(e) {
var selected = this.grid.getSelectedRecords()[0]; var sm = this.grid.getSelectionModel(),
selected = sm.getLastSelected();
if (!selected) return; if (!selected) return;
if (selected.get('status') == _('Connected')) { if (selected.get('status') == _('Connected')) {
@ -216,8 +221,7 @@ Ext.define('Deluge.ConnectionManager', {
scope: this scope: this
}); });
} else { } else {
var id = selected.id; deluge.client.web.connect(selected.getId(), {
deluge.client.web.connect(id, {
success: function(methods) { success: function(methods) {
deluge.client.reloadMethods(); deluge.client.reloadMethods();
deluge.client.on('connected', function(e) { deluge.client.on('connected', function(e) {
@ -231,9 +235,13 @@ Ext.define('Deluge.ConnectionManager', {
// private // private
onGetHosts: function(hosts) { onGetHosts: function(hosts) {
this.grid.getStore().loadData(hosts); // FIXME: Why on earth do I need to do it like this?!
var store = this.grid.getStore(),
results = store.proxy.reader.readRecords(hosts);
store.loadRecords(results.records);
Ext.each(hosts, function(host) { Ext.each(hosts, function(host) {
deluge.client.web.get_host_status(host[0], { deluge.client.web.get_host_status(host['id'], {
success: this.onGetHostStatus, success: this.onGetHostStatus,
scope: this scope: this
}); });
@ -242,11 +250,14 @@ Ext.define('Deluge.ConnectionManager', {
// private // private
onGetHostStatus: function(host) { onGetHostStatus: function(host) {
var record = this.grid.getStore().getById(host[0]); var record = this.grid.getStore().getById(host['id']);
record.set('status', host[3]) record.set('status', host['status'])
record.set('version', host[4]) record.set('version', host['version'])
record.commit(); record.commit();
if (this.grid.getSelectedRecords()[0] == record) this.updateButtons(record);
if (this.grid.getSelectionModel().isSelected(record)) {
this.updateButtons(record);
}
}, },
// private // private
@ -283,10 +294,12 @@ Ext.define('Deluge.ConnectionManager', {
// private // private
onRemoveClick: function(button) { onRemoveClick: function(button) {
var connection = this.grid.getSelectedRecords()[0]; var sm = this.grid.getSelectionModel(),
if (!connection) return; selected = sm.getLastSelected();
deluge.client.web.remove_host(connection.id, { if (!selected) return;
deluge.client.web.remove_host(selected.getId(), {
success: function(result) { success: function(result) {
if (!result) { if (!result) {
Ext.MessageBox.show({ Ext.MessageBox.show({
@ -298,7 +311,7 @@ Ext.define('Deluge.ConnectionManager', {
iconCls: 'x-deluge-icon-error' iconCls: 'x-deluge-icon-error'
}); });
} else { } else {
this.grid.getStore().remove(connection); this.grid.getStore().remove(selected);
} }
}, },
scope: this scope: this
@ -306,12 +319,12 @@ Ext.define('Deluge.ConnectionManager', {
}, },
// private // private
onSelectionChanged: function(list, selections) { onSelectionChanged: function(grid, selections) {
if (selections[0]) { if (selections[0]) {
this.removeHostButton.enable(); this.removeHostButton.enable();
this.stopHostButton.enable(); this.stopHostButton.enable();
this.stopHostButton.setText(_('Stop Daemon')); this.stopHostButton.setText(_('Stop Daemon'));
this.updateButtons(this.grid.getRecord(selections[0])); this.updateButtons(selections[0]);
} else { } else {
this.removeHostButton.disable(); this.removeHostButton.disable();
this.stopHostButton.disable(); this.stopHostButton.disable();
@ -322,10 +335,10 @@ Ext.define('Deluge.ConnectionManager', {
// private // private
onShow: function() { onShow: function() {
if (!this.addHostButton) { if (!this.addHostButton) {
var bbar = this.grid.getDockedItems()[0]; var buttons = this.grid.query('button');
this.addHostButton = bbar.items.get('cm-add'); this.addHostButton = buttons[0];
this.removeHostButton = bbar.items.get('cm-remove'); this.removeHostButton = buttons[1];
this.stopHostButton = bbar.items.get('cm-stop'); this.stopHostButton = buttons[2];
} }
this.loadHosts(); this.loadHosts();
if (this.running) return; if (this.running) return;

View file

@ -1,6 +1,6 @@
/*! /*!
* Deluge.js * Deluge.js
* *
* Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -56,7 +56,7 @@ Ext.apply(Ext, {
} }
return equal; return equal;
}, },
keys: function(obj) { keys: function(obj) {
var keys = []; var keys = [];
for (var i in obj) if (obj.hasOwnProperty(i)) for (var i in obj) if (obj.hasOwnProperty(i))
@ -75,7 +75,7 @@ Ext.apply(Ext, {
} }
return values; return values;
}, },
splat: function(obj) { splat: function(obj) {
var type = Ext.type(obj); var type = Ext.type(obj);
return (type) ? ((type != 'array') ? [obj] : obj) : []; return (type) ? ((type != 'array') ? [obj] : obj) : [];
@ -90,7 +90,7 @@ Ext.apply(Deluge, {
// private // private
pluginStore: {}, pluginStore: {},
// private // private
progressTpl: '<div class="x-progress-wrap x-progress-renderered">' + progressTpl: '<div class="x-progress-wrap x-progress-renderered">' +
'<div class="x-progress-inner">' + '<div class="x-progress-inner">' +
@ -105,7 +105,7 @@ Ext.apply(Deluge, {
'</div>' + '</div>' +
'</div>', '</div>',
/** /**
* A method to create a progress bar that can be used by renderers * A method to create a progress bar that can be used by renderers
* to display a bar within a grid or tree. * to display a bar within a grid or tree.
@ -119,7 +119,7 @@ Ext.apply(Deluge, {
var progressWidth = ((width / 100.0) * progress).toFixed(0); var progressWidth = ((width / 100.0) * progress).toFixed(0);
var barWidth = progressWidth - 1; var barWidth = progressWidth - 1;
var textWidth = ((progressWidth - modifier) > 0 ? progressWidth - modifier : 0); var textWidth = ((progressWidth - modifier) > 0 ? progressWidth - modifier : 0);
return String.format(Deluge.progressTpl, text, width, barWidth, textWidth); return Ext.String.format(Deluge.progressTpl, text, width, barWidth, textWidth);
}, },
/** /**
@ -146,7 +146,7 @@ Ext.apply(Deluge, {
registerPlugin: function(name, plugin) { registerPlugin: function(name, plugin) {
Deluge.pluginStore[name] = plugin; Deluge.pluginStore[name] = plugin;
} }
}); });
// Setup a space for plugins to insert themselves // Setup a space for plugins to insert themselves

View file

@ -36,10 +36,11 @@
* <p>Deluge.EventsManager is instantated as <tt>deluge.events</tt> and can be used by components of the UI to fire global events</p> * <p>Deluge.EventsManager is instantated as <tt>deluge.events</tt> and can be used by components of the UI to fire global events</p>
* Class for holding global events that occur within the UI. * Class for holding global events that occur within the UI.
*/ */
Deluge.EventsManager = Ext.extend(Ext.util.Observable, { Ext.define('Deluge.EventsManager', {
extend: 'Ext.util.Observable',
toRegister: [],
constructor: function() { constructor: function() {
this.toRegister = [];
this.on('login', this.onLogin, this); this.on('login', this.onLogin, this);
this.callParent(arguments); this.callParent(arguments);
}, },
@ -55,8 +56,9 @@ Deluge.EventsManager = Ext.extend(Ext.util.Observable, {
} else { } else {
deluge.client.web.register_event_listener(eventName); deluge.client.web.register_event_listener(eventName);
} }
} else {
this.callParent(arguments);
} }
this.callParent(arguments);
}, },
getEvents: function() { getEvents: function() {

View file

@ -1,7 +1,7 @@
/*! /*!
* Deluge.FilterPanel.js * Deluge.FilterPanel.js
* *
* Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> * Copyright (c) Damien Churchill 2009-2011 <damoxc@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -35,16 +35,15 @@ Ext.ns('Deluge');
* @class Deluge.FilterPanel * @class Deluge.FilterPanel
* @extends Ext.list.ListView * @extends Ext.list.ListView
*/ */
Deluge.FilterPanel = Ext.extend(Ext.Panel, { Ext.define('Deluge.FilterPanel', {
extend: 'Ext.Panel',
autoScroll: true, autoScroll: true,
border: false, border: false,
show_zero: null, show_zero: null,
initComponent: function() { initComponent: function() {
Deluge.FilterPanel.superclass.initComponent.call(this); this.callParent(arguments);
this.filterType = this.initialConfig.filter; this.filterType = this.initialConfig.filter;
var title = this.filterType.replace('_', ' '), var title = this.filterType.replace('_', ' '),
@ -62,8 +61,8 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, {
var tpl = '<div class="x-deluge-filter x-deluge-{filter:lowercase}">{filter} ({count})</div>'; var tpl = '<div class="x-deluge-filter x-deluge-{filter:lowercase}">{filter} ({count})</div>';
} }
this.list = this.add({ this.grid = this.add({
xtype: 'listview', xtype: 'grid',
singleSelect: true, singleSelect: true,
hideHeaders: true, hideHeaders: true,
reserveScrollOffset: true, reserveScrollOffset: true,
@ -78,7 +77,7 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, {
dataIndex: 'filter' dataIndex: 'filter'
}] }]
}); });
this.relayEvents(this.list, ['selectionchange']); this.relayEvents(this.grid, ['selectionchange']);
}, },
/** /**
@ -86,11 +85,13 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, {
* @returns {String} the current filter state * @returns {String} the current filter state
*/ */
getState: function() { getState: function() {
if (!this.list.getSelectionCount()) return; var sm = this.grid.getSelectionModel()
if (!sm.hasSelection()) return;
var state = this.list.getSelectedRecords()[0]; var state = sm.getLastSelected(),
if (state.id == 'All') return; stateId = state.getId();
return state.id; if (stateId == 'All') return;
return stateId;
}, },
/** /**
@ -105,7 +106,7 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, {
* @returns {Ext.data.Store} the ListView store * @returns {Ext.data.Store} the ListView store
*/ */
getStore: function() { getStore: function() {
return this.list.getStore(); return this.grid.getStore();
}, },
/** /**
@ -128,16 +129,17 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, {
states = newStates; states = newStates;
} }
var store = this.getStore(); var store = this.getStore(),
var filters = {}; sm = this.grid.getSelectionModel(),
filters = {};
Ext.each(states, function(s, i) { Ext.each(states, function(s, i) {
var record = store.getById(s[0]); var record = store.getById(s[0]);
if (!record) { if (!record) {
record = new store.recordType({ var record = store.add({
filter: s[0], filter: s[0],
count: s[1] count: s[1]
}); })[0];
record.id = s[0]; record.setId(s[0]);
store.insert(i, record); store.insert(i, record);
} }
record.beginEdit(); record.beginEdit();
@ -148,18 +150,18 @@ Deluge.FilterPanel = Ext.extend(Ext.Panel, {
}, this); }, this);
store.each(function(record) { store.each(function(record) {
if (filters[record.id]) return; if (filters[record.getId()]) return;
var r = this.list.getSelectedRecords()[0]; var r = sm.getLastSelected();
store.remove(record); store.remove(record);
if (r.id == record.id) { if (r.id == record.id) {
this.list.select(0); sm.select(0);
} }
}, this); }, this);
store.commitChanges(); store.sync();
if (!this.list.getSelectionCount()) { if (!sm.hasSelection()) {
this.list.select(0); sm.select(0);
} }
} }

View file

@ -1,6 +1,6 @@
/*! /*!
* Deluge.Formatters.js * Deluge.Formatters.js
* *
* Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -56,11 +56,11 @@ Deluge.Formatters = {
} }
timestamp = timestamp * 1000; timestamp = timestamp * 1000;
var date = new Date(timestamp); var date = new Date(timestamp);
return String.format('{0}/{1}/{2} {3}:{4}:{5}', return Ext.String.format('{0}/{1}/{2} {3}:{4}:{5}',
zeroPad(date.getDate(), 2), zeroPad(date.getMonth() + 1, 2), date.getFullYear(), zeroPad(date.getDate(), 2), zeroPad(date.getMonth() + 1, 2), date.getFullYear(),
zeroPad(date.getHours(), 2), zeroPad(date.getMinutes(), 2), zeroPad(date.getSeconds(), 2)); zeroPad(date.getHours(), 2), zeroPad(date.getMinutes(), 2), zeroPad(date.getSeconds(), 2));
}, },
/** /**
* Formats the bytes value into a string with KiB, MiB or GiB units. * Formats the bytes value into a string with KiB, MiB or GiB units.
* *
@ -71,16 +71,16 @@ Deluge.Formatters = {
size: function(bytes, showZero) { size: function(bytes, showZero) {
if (!bytes && !showZero) return ''; if (!bytes && !showZero) return '';
bytes = bytes / 1024.0; bytes = bytes / 1024.0;
if (bytes < 1024) { return bytes.toFixed(1) + ' KiB'; } if (bytes < 1024) { return bytes.toFixed(1) + ' KiB'; }
else { bytes = bytes / 1024; } else { bytes = bytes / 1024; }
if (bytes < 1024) { return bytes.toFixed(1) + ' MiB'; } if (bytes < 1024) { return bytes.toFixed(1) + ' MiB'; }
else { bytes = bytes / 1024; } else { bytes = bytes / 1024; }
return bytes.toFixed(1) + ' GiB' return bytes.toFixed(1) + ' GiB'
}, },
/** /**
* Formats a string to display a transfer speed utilizing {@link #size} * Formats a string to display a transfer speed utilizing {@link #size}
* *
@ -91,7 +91,7 @@ Deluge.Formatters = {
speed: function(bytes, showZero) { speed: function(bytes, showZero) {
return (!bytes && !showZero) ? '' : fsize(bytes, showZero) + '/s'; return (!bytes && !showZero) ? '' : fsize(bytes, showZero) + '/s';
}, },
/** /**
* Formats a string to show time in a human readable form. * Formats a string to show time in a human readable form.
* *
@ -103,7 +103,7 @@ Deluge.Formatters = {
time = time.toFixed(0); time = time.toFixed(0);
if (time < 60) { return time + 's'; } if (time < 60) { return time + 's'; }
else { time = time / 60; } else { time = time / 60; }
if (time < 60) { if (time < 60) {
var minutes = Math.floor(time) var minutes = Math.floor(time)
var seconds = Math.round(60 * (time - minutes)) var seconds = Math.round(60 * (time - minutes))
@ -113,18 +113,18 @@ Deluge.Formatters = {
return minutes + 'm'; } return minutes + 'm'; }
} }
else { time = time / 60; } else { time = time / 60; }
if (time < 24) { if (time < 24) {
var hours = Math.floor(time) var hours = Math.floor(time)
var minutes = Math.round(60 * (time - hours)) var minutes = Math.round(60 * (time - hours))
if (minutes > 0) { if (minutes > 0) {
return hours + 'h ' + minutes + 'm'; return hours + 'h ' + minutes + 'm';
} else { } else {
return hours + 'h'; return hours + 'h';
} }
} }
else { time = time / 24; } else { time = time / 24; }
var days = Math.floor(time) var days = Math.floor(time)
var hours = Math.round(24 * (time - days)) var hours = Math.round(24 * (time - days))
if (hours > 0) { if (hours > 0) {
@ -133,7 +133,7 @@ Deluge.Formatters = {
return days + 'd'; return days + 'd';
} }
}, },
/** /**
* Simply returns the value untouched, for when no formatting is required. * Simply returns the value untouched, for when no formatting is required.
* *

View file

@ -1,7 +1,7 @@
/*! /*!
* Deluge.OtherLimitWindow.js * Deluge.OtherLimitWindow.js
* *
* Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> * Copyright (c) Damien Churchill 2009-2011 <damoxc@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -29,14 +29,14 @@
* this exception statement from your version. If you delete this exception * this exception statement from your version. If you delete this exception
* statement from all source files in the program, then also delete it here. * statement from all source files in the program, then also delete it here.
*/ */
Ext.ns('Deluge');
/** /**
* @class Deluge.OtherLimitWindow * @class Deluge.OtherLimitWindow
* @extends Ext.Window * @extends Ext.Window
*/ */
Deluge.OtherLimitWindow = Ext.extend(Ext.Window, { Ext.define('Deluge.OtherLimitWindow', {
extend: 'Ext.Window',
layout: 'fit', layout: 'fit',
width: 210, width: 210,
height: 100, height: 100,
@ -44,7 +44,7 @@ Deluge.OtherLimitWindow = Ext.extend(Ext.Window, {
closeAction: 'hide', closeAction: 'hide',
initComponent: function() { initComponent: function() {
Deluge.OtherLimitWindow.superclass.initComponent.call(this); this.callParent(arguments);
this.form = this.add({ this.form = this.add({
xtype: 'form', xtype: 'form',
baseCls: 'x-plain', baseCls: 'x-plain',
@ -69,8 +69,17 @@ Deluge.OtherLimitWindow = Ext.extend(Ext.Window, {
this.setSize(180, 100); this.setSize(180, 100);
} }
this.addButton(_('Cancel'), this.onCancelClick, this); this.addDocked({
this.addButton(_('Ok'), this.onOkClick, this); xtype: 'toolbar',
dock: 'bottom',
defaultType: 'button',
items: [
'->',
{text: _('Cancel'), handler: this.onCancelClick, scope: this},
{text: _('Ok'), handler: this.onOkClick, scope: this}
]
});
this.afterMethod('show', this.doFocusField, this); this.afterMethod('show', this.doFocusField, this);
}, },

View file

@ -40,7 +40,19 @@
* @version 1.3 * @version 1.3
*/ */
Ext.define('Deluge.Sidebar', { Ext.define('Deluge.Sidebar', {
extend: 'Ext.Panel', extend: 'Ext.panel.Panel',
id: 'sidebar',
region: 'west',
cls: 'deluge-sidebar',
title: _('Filters'),
layout: 'accordion',
split: true,
width: 200,
minSize: 175,
collapsible: true,
margins: '5 0 0 5',
cmargins: '5 0 0 5',
// private // private
panels: {}, panels: {},
@ -48,23 +60,6 @@ Ext.define('Deluge.Sidebar', {
// private // private
selected: null, selected: null,
constructor: function(config) {
config = Ext.apply({
id: 'sidebar',
region: 'west',
cls: 'deluge-sidebar',
title: _('Filters'),
layout: 'accordion',
split: true,
width: 200,
minSize: 175,
collapsible: true,
margins: '5 0 0 5',
cmargins: '5 0 0 5'
}, config);
this.callParent(arguments);
},
// private // private
initComponent: function() { initComponent: function() {
this.callParent(arguments); this.callParent(arguments);

View file

@ -1,7 +1,7 @@
/*! /*!
* Deluge.Statusbar.js * Deluge.Statusbar.js
* *
* Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> * Copyright (c) Damien Churchill 2009-2011 <damoxc@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -29,25 +29,21 @@
* this exception statement from your version. If you delete this exception * this exception statement from your version. If you delete this exception
* statement from all source files in the program, then also delete it here. * statement from all source files in the program, then also delete it here.
*/ */
Ext.namespace('Deluge');
Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { Ext.define('Deluge.StatusBar', {
constructor: function(config) { extend: 'Ext.ux.statusbar.StatusBar',
config = Ext.apply({
id: 'deluge-statusbar', id: 'deluge-statusbar',
defaultIconCls: 'x-deluge-statusbar x-not-connected', defaultIconCls: 'x-deluge-statusbar x-not-connected',
defaultText: _('Not Connected') defaultText: _('Not Connected'),
}, config);
Deluge.Statusbar.superclass.constructor.call(this, config);
},
initComponent: function() { initComponent: function() {
Deluge.Statusbar.superclass.initComponent.call(this); this.callParent(arguments);
deluge.events.on('connect', this.onConnect, this); deluge.events.on('connect', this.onConnect, this);
deluge.events.on('disconnect', this.onDisconnect, this); deluge.events.on('disconnect', this.onDisconnect, this);
}, },
createButtons: function() { createButtons: function() {
this.buttons = this.add({ this.buttons = this.add({
id: 'statusbar-connections', id: 'statusbar-connections',
@ -221,7 +217,7 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, {
}); });
this.created = true; this.created = true;
}, },
onConnect: function() { onConnect: function() {
this.setStatus({ this.setStatus({
iconCls: 'x-connected', iconCls: 'x-connected',
@ -246,18 +242,18 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, {
}); });
this.doLayout(); this.doLayout();
}, },
update: function(stats) { update: function(stats) {
if (!stats) return; if (!stats) return;
function addSpeed(val) {return val + ' KiB/s'} function addSpeed(val) {return val + ' KiB/s'}
var updateStat = function(name, config) { var updateStat = Ext.bind(function(name, config) {
var item = this.items.get('statusbar-' + name); var item = this.items.get('statusbar-' + name);
if (config.limit.value > 0) { if (config.limit.value > 0) {
var value = (config.value.formatter) ? config.value.formatter(config.value.value, true) : config.value.value; var value = (config.value.formatter) ? config.value.formatter(config.value.value, true) : config.value.value;
var limit = (config.limit.formatter) ? config.limit.formatter(config.limit.value, true) : config.limit.value; var limit = (config.limit.formatter) ? config.limit.formatter(config.limit.value, true) : config.limit.value;
var str = String.format(config.format, value, limit); var str = Ext.String.format(config.format, value, limit);
} else { } else {
var str = (config.value.formatter) ? config.value.formatter(config.value.value, true) : config.value.value; var str = (config.value.formatter) ? config.value.formatter(config.value.value, true) : config.value.value;
} }
@ -265,8 +261,8 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, {
if (!item.menu) return; if (!item.menu) return;
item.menu.setValue(config.limit.value); item.menu.setValue(config.limit.value);
}.createDelegate(this); }, this);
updateStat('connections', { updateStat('connections', {
value: {value: stats.num_connections}, value: {value: stats.num_connections},
limit: {value: stats.max_num_connections}, limit: {value: stats.max_num_connections},

View file

@ -35,29 +35,29 @@ function queueRenderer(value) {
return (value == -1) ? '' : value + 1; return (value == -1) ? '' : value + 1;
} }
function torrentNameRenderer(value, p, r) { function torrentNameRenderer(value, p, r) {
return String.format('<div class="torrent-name x-deluge-{0}">{1}</div>', r.data['state'].toLowerCase(), value); return Ext.String.format('<div class="torrent-name x-deluge-{0}">{1}</div>', r.data['state'].toLowerCase(), value);
} }
function torrentSpeedRenderer(value) { function torrentSpeedRenderer(value) {
if (!value) return; if (!value) return;
return fspeed(value); return fspeed(value);
} }
function torrentProgressRenderer(value, p, r) { function torrentProgressRenderer(value, md, r) {
value = new Number(value); value = new Number(value);
var progress = value; var width = this.query('gridcolumn[dataIndex=progress]')[0].getWidth(),
var text = r.data['state'] + ' ' + value.toFixed(2) + '%'; progress = value,
var width = new Number(this.style.match(/\w+:\s*(\d+)\w+/)[1]); text = r.data['state'] + ' ' + value.toFixed(2) + '%';
return Deluge.progressBar(value, width - 8, text); return Deluge.progressBar(value, width - 8, text);
} }
function seedsRenderer(value, p, r) { function seedsRenderer(value, p, r) {
if (r.data['total_seeds'] > -1) { if (r.data['total_seeds'] > -1) {
return String.format('{0} ({1})', value, r.data['total_seeds']); return Ext.String.format('{0} ({1})', value, r.data['total_seeds']);
} else { } else {
return value; return value;
} }
} }
function peersRenderer(value, p, r) { function peersRenderer(value, p, r) {
if (r.data['total_peers'] > -1) { if (r.data['total_peers'] > -1) {
return String.format('{0} ({1})', value, r.data['total_peers']); return Ext.String.format('{0} ({1})', value, r.data['total_peers']);
} else { } else {
return value; return value;
} }
@ -66,7 +66,7 @@ function availRenderer(value, p, r) {
return (value < 0) ? '&infin;' : new Number(value).toFixed(3); return (value < 0) ? '&infin;' : new Number(value).toFixed(3);
} }
function trackerRenderer(value, p, r) { function trackerRenderer(value, p, r) {
return String.format('<div style="background: url(' + deluge.config.base + 'tracker/{0}) no-repeat; padding-left: 20px;">{0}</div>', value); return Ext.String.format('<div style="background: url(' + deluge.config.base + 'tracker/{0}) no-repeat; padding-left: 20px;">{0}</div>', value);
} }
function etaSorter(eta) { function etaSorter(eta) {
@ -84,7 +84,7 @@ function dateOrNever(date) {
* @version 1.3 * @version 1.3
* *
* @class Deluge.TorrentGrid * @class Deluge.TorrentGrid
* @extends Ext.grid.GridPanel * @extends Ext.grid.Panel
* @constructor * @constructor
* @param {Object} config Configuration options * @param {Object} config Configuration options
*/ */
@ -231,7 +231,7 @@ Ext.define('Deluge.TorrentGrid', {
}, },
store: Ext.create('Ext.data.Store', { store: Ext.create('Ext.data.Store', {
model: 'Deluge.data.TorrentRecord', model: 'Deluge.data.Torrent',
proxy: { proxy: {
type: 'memory', type: 'memory',
reader: { reader: {
@ -281,14 +281,14 @@ Ext.define('Deluge.TorrentGrid', {
* @ return {Array/Ext.data.Record} The record(s) representing the rows * @ return {Array/Ext.data.Record} The record(s) representing the rows
*/ */
getSelected: function() { getSelected: function() {
return this.getSelectionModel().getSelected(); return this.getSelectionModel().getLastSelected();
}, },
/** /**
* Returns the currently selected records. * Returns the currently selected records.
*/ */
getSelections: function() { getSelections: function() {
return this.getSelectionModel().getSelections(); return this.getSelectionModel().getSelection();
}, },
/** /**
@ -296,7 +296,7 @@ Ext.define('Deluge.TorrentGrid', {
* @return {String} The currently selected id. * @return {String} The currently selected id.
*/ */
getSelectedId: function() { getSelectedId: function() {
return this.getSelectionModel().getSelected().id return this.getSelected().getId()
}, },
/** /**
@ -305,8 +305,8 @@ Ext.define('Deluge.TorrentGrid', {
*/ */
getSelectedIds: function() { getSelectedIds: function() {
var ids = []; var ids = [];
Ext.each(this.getSelectionModel().getSelections(), function(r) { Ext.each(this.getSelections(), function(r) {
ids.push(r.id); ids.push(r.getId());
}); });
return ids; return ids;
}, },
@ -337,7 +337,7 @@ Ext.define('Deluge.TorrentGrid', {
record.endEdit(); record.endEdit();
} else { } else {
var record = new Deluge.data.Torrent(torrent); var record = new Deluge.data.Torrent(torrent);
record.id = t; record.setId(t);
this.torrents[t] = 1; this.torrents[t] = 1;
newTorrents.push(record); newTorrents.push(record);
} }
@ -346,16 +346,15 @@ Ext.define('Deluge.TorrentGrid', {
// Remove any torrents that should not be in the store. // Remove any torrents that should not be in the store.
store.each(function(record) { store.each(function(record) {
if (!torrents[record.id]) { if (!torrents[record.getId()]) {
store.remove(record); store.remove(record);
delete this.torrents[record.id]; delete this.torrents[record.getId()];
} }
}, this); }, this);
store.commitChanges(); store.sync();
var sortState = store.getSortState() // TODO: re-enable this is it's required.
if (!sortState) return; //store.sort(store.sorters);
store.sort(sortState.field, sortState.direction);
}, },
// private // private

View file

@ -56,7 +56,7 @@ deluge.ui = {
deluge.login = Ext.create('Deluge.LoginWindow'); deluge.login = Ext.create('Deluge.LoginWindow');
deluge.preferences = Ext.create('Deluge.preferences.PreferencesWindow'); deluge.preferences = Ext.create('Deluge.preferences.PreferencesWindow');
deluge.sidebar = Ext.create('Deluge.Sidebar'); deluge.sidebar = Ext.create('Deluge.Sidebar');
deluge.statusbar = Ext.create('Deluge.Statusbar'); deluge.statusbar = Ext.create('Deluge.StatusBar');
deluge.toolbar = Ext.create('Deluge.Toolbar'); deluge.toolbar = Ext.create('Deluge.Toolbar');
deluge.torrents = Ext.create('Deluge.TorrentGrid'); deluge.torrents = Ext.create('Deluge.TorrentGrid');

View file

@ -57,7 +57,7 @@ Ext.define('Deluge.details.DetailsPanel', {
clear: function() { clear: function() {
this.items.each(function(panel) { this.items.each(function(panel) {
if (panel.clear) { if (panel.clear) {
panel.clear.defer(100, panel); Ext.defer(panel.clear, 100, panel);
panel.disable(); panel.disable();
} }
}); });

View file

@ -352,9 +352,9 @@ Ext.define('Deluge.details.OptionsTab', {
this.callParent(arguments); this.callParent(arguments);
// This is another hack I think, so keep an eye out here when upgrading. // This is another hack I think, so keep an eye out here when upgrading.
this.layout = new Ext.layout.ColumnLayout(); //this.layout = new Ext.layout.ColumnLayout();
this.layout.setContainer(this); //this.layout.setContainer(this);
this.doLayout(); //this.doLayout();
}, },
clear: function() { clear: function() {

View file

@ -54,6 +54,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
), ),
initComponent: function() { initComponent: function() {
console.log('Plugins preferences page created');
this.callParent(arguments); this.callParent(arguments);
this.defaultValues = { this.defaultValues = {
'version': '', 'version': '',

View file

@ -1,3 +1,17 @@
/*
This file is part of Ext JS 4
Copyright (c) 2011 Sencha Inc
Contact: http://www.sencha.com/contact
GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
*/
/** /**
* @class Ext.ux.StatusBar * @class Ext.ux.StatusBar
* <p>Basic status bar component that can be used as the bottom toolbar of any {@link Ext.Panel}. In addition to * <p>Basic status bar component that can be used as the bottom toolbar of any {@link Ext.Panel}. In addition to
@ -416,3 +430,4 @@ statusBar.setStatus({
return this.setStatus(o); return this.setStatus(o);
} }
}); });

View file

@ -727,8 +727,7 @@ class WebApi(JSONComponent):
""" """
Return the hosts in the hostlist. Return the hosts in the hostlist.
""" """
log.debug("get_hosts called") return [dict(zip(('id', 'host', 'port', 'status'), tuple(host[HOSTS_ID:HOSTS_PORT+1]) + (_("Offline"),))) for host in self.host_list["hosts"]]
return [(tuple(host[HOSTS_ID:HOSTS_PORT+1]) + (_("Offline"),)) for host in self.host_list["hosts"]]
@export @export
def get_host_status(self, host_id): def get_host_status(self, host_id):
@ -740,12 +739,18 @@ class WebApi(JSONComponent):
""" """
def response(status, info=None): def response(status, info=None):
return host_id, host, port, status, info return dict (
id = host_id,
host = host,
port = port,
status = status,
version = info
)
try: try:
host_id, host, port, user, password = self.get_host(host_id) host_id, host, port, user, password = self.get_host(host_id)
except TypeError, e: except TypeError, e:
return response(_("Offline")) return None
def on_connect(connected, c, host_id): def on_connect(connected, c, host_id):
def on_info(info, c): def on_info(info, c):