move updating the statusbar into the deluge-bars module

show/hide the additional statusbar info when connected/disconnected
This commit is contained in:
Damien Churchill 2009-02-19 21:07:14 +00:00
parent fda01f59a7
commit eae92d78eb
2 changed files with 120 additions and 103 deletions

View File

@ -180,29 +180,16 @@ Deluge.SideBar = {
Deluge.StatusBar = { Deluge.StatusBar = {
onRender: function() { onRender: function() {
this.bound = { this.bound = {
onConnect: this.onConnect.bindWithEvent(this) onConnect: this.onConnect.bindWithEvent(this),
onDisconnect: this.onDisconnect.bindWithEvent(this)
} }
Deluge.Events.on('connect', this.bound.onConnect); Deluge.Events.on('connect', this.bound.onConnect);
Deluge.Events.on('disconnect', this.bound.onDisconnect); Deluge.Events.on('disconnect', this.bound.onDisconnect);
}, },
onConnect: function() { createButtons: function() {
this.Bar.setStatus({ this.Bar.add({
iconCls: 'x-connected',
text: ''
});
},
onDisconnect: function() {
this.Bar.clearStatus({useDefaults:true});
}
}
Deluge.StatusBar.Bar = new Ext.StatusBar({
id: 'deluge-statusbar',
defaultIconCls: 'x-not-connected',
defaultText: _('Not Connected'),
/*items: [{
id: 'statusbar-connections', id: 'statusbar-connections',
text: '200 (200)', text: '200 (200)',
cls: 'x-btn-text-icon', cls: 'x-btn-text-icon',
@ -230,6 +217,108 @@ Deluge.StatusBar.Bar = new Ext.StatusBar({
text: '161', text: '161',
cls: 'x-btn-text-icon', cls: 'x-btn-text-icon',
icon: '/icons/16/dht.png' icon: '/icons/16/dht.png'
}]*/ });
this.created = true;
},
onConnect: function() {
this.Bar.setStatus({
iconCls: 'x-connected',
text: ''
});
if (!this.created) this.createButtons();
else {
this.Bar.items.each(function(item) {
item.show();
item.enable();
});
}
},
onDisconnect: function() {
this.Bar.clearStatus({useDefaults:true});
this.Bar.items.each(function(item) {
item.hide();
item.disable();
});
},
update: function(stats) {
function addSpeed(val) {return val + ' KiB/s'}
var updateStat = function(name, config) {
var item = this.Bar.items.get('statusbar-' + name);
if (config.limit.value == -1) {
var str = (config.value.formatter) ? config.value.formatter(config.value.value) : config.value.value;
} else {
var value = (config.value.formatter) ? config.value.formatter(config.value.value) : config.value.value;
var limit = (config.limit.formatter) ? config.limit.formatter(config.limit.value) : config.limit.value;
var str = String.format(config.format, value, limit);
}
item.setText(str);
}.bind(this);
updateStat('connections', {
value: {value: stats.num_connections},
limit: {value: stats.max_num_connections},
format: '{0} ({1})'
});
updateStat('downspeed', {
value: {
value: stats.download_rate,
formatter: Deluge.Formatters.speed
},
limit: {
value: stats.max_download,
formatter: addSpeed
},
format: '{0} ({1})'
});
updateStat('upspeed', {
value: {
value: stats.upload_rate,
formatter: Deluge.Formatters.speed
},
limit: {
value: stats.max_upload,
formatter: addSpeed
},
format: '{0} ({1})'
});
updateStat('traffic', {
value: {
value: stats.payload_download_rate,
formatter: Deluge.Formatters.speed
},
limit: {
value: stats.payload_upload_rate,
formatter: Deluge.Formatters.speed
},
format: '{0}/{1}'
});
this.Bar.items.get('statusbar-dht').setText(stats.dht_nodes);
function updateMenu(menu, stat) {
var item = menu.items.get(stat)
if (!item) {
item = menu.items.get('other')
}
item.setChecked(true);
}
updateMenu(Deluge.Menus.Connections, stats.max_num_connections);
updateMenu(Deluge.Menus.Download, stats.max_download);
updateMenu(Deluge.Menus.Upload, stats.max_upload);
}
}
Deluge.StatusBar.Bar = new Ext.StatusBar({
id: 'deluge-statusbar',
defaultIconCls: 'x-not-connected',
defaultText: _('Not Connected'),
listeners: {'render': {scope: Deluge.StatusBar, fn: Deluge.StatusBar.onRender}} listeners: {'render': {scope: Deluge.StatusBar, fn: Deluge.StatusBar.onRender}}
}); });

View File

@ -65,82 +65,10 @@ Deluge.Ui = {
]); ]);
}); });
Deluge.Torrents.store.loadData(torrents); Deluge.Torrents.store.loadData(torrents);
//this.updateStatusBar(data['stats']); Deluge.StatusBar.update(data['stats']);
this.errorCount = 0; this.errorCount = 0;
}, },
updateStatusBar: function(stats) {
function addSpeed(val) {return val + " KiB/s"}
function updateStat(name, config) {
var item = Deluge.StatusBar.items.get("statusbar-" + name);
if (config.limit.value == -1) {
var str = (config.value.formatter) ? config.value.formatter(config.value.value) : config.value.value;
} else {
var value = (config.value.formatter) ? config.value.formatter(config.value.value) : config.value.value;
var limit = (config.limit.formatter) ? config.limit.formatter(config.limit.value) : config.limit.value;
var str = String.format(config.format, value, limit);
}
item.setText(str);
}
updateStat("connections", {
value: {value: stats.num_connections},
limit: {value: stats.max_num_connections},
format: "{0} ({1})"
});
updateStat("downspeed", {
value: {
value: stats.download_rate,
formatter: Deluge.Formatters.speed
},
limit: {
value: stats.max_download,
formatter: addSpeed
},
format: "{0} ({1})"
});
updateStat("upspeed", {
value: {
value: stats.upload_rate,
formatter: Deluge.Formatters.speed
},
limit: {
value: stats.max_upload,
formatter: addSpeed
},
format: "{0} ({1})"
});
updateStat("traffic", {
value: {
value: stats.payload_download_rate,
formatter: Deluge.Formatters.speed
},
limit: {
value: stats.payload_upload_rate,
formatter: Deluge.Formatters.speed
},
format: "{0}/{1}"
});
Deluge.StatusBar.items.get('statusbar-dht').setText(stats.dht_nodes);
function updateMenu(menu, stat) {
var item = menu.items.get(stat)
if (!item) {
item = menu.items.get("other")
}
item.setChecked(true);
}
updateMenu(Deluge.Menus.Connections, stats.max_num_connections);
updateMenu(Deluge.Menus.Download, stats.max_download);
updateMenu(Deluge.Menus.Upload, stats.max_upload);
},
/* /*
Property: run Property: run
Start the Deluge UI polling the server to get the updated torrent Start the Deluge UI polling the server to get the updated torrent