mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-26 10:05:19 +00:00
add the peers tab
This commit is contained in:
parent
d916d36603
commit
a63e5c594c
@ -0,0 +1,135 @@
|
||||
/*
|
||||
Script: Deluge.Details.Peers.js
|
||||
The peers tab displayed in the details panel.
|
||||
|
||||
Copyright:
|
||||
(C) Damien Churchill 2009 <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.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
function flagRenderer(value) {
|
||||
return String.format('<img src="/flag/{0}" />', value);
|
||||
}
|
||||
function peerAddressRenderer(value, p, record) {
|
||||
var seed = (record.data['seed'] == 1024) ? 'x-deluge-seed' : 'x-deluge-peer'
|
||||
return String.format('<div class="{0}">{1}</div>', seed, value);
|
||||
}
|
||||
function peerProgressRenderer(value) {
|
||||
var progress = (value * 100).toFixed(0);
|
||||
var width = new Number(this.style.match(/\w+:\s*(\d+)\w+/)[1]).toFixed(0) - 8;
|
||||
return Deluge.progressBar(progress, width, progress + '%');
|
||||
}
|
||||
function sort_address(value) {
|
||||
var m = value.match(/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\:(\d+)/);
|
||||
var address = 0;
|
||||
var parts = [m[1], m[2], m[3], m[4]];
|
||||
Ext.each(parts, function(part, index) {
|
||||
part = parseInt(part);
|
||||
address = address | part << ((3 - index) * 8);
|
||||
//alert("Total: " + address + "\nPart: " + part + "\nIndex: " + index + "\nCalc: " + (part << ((3 - index) * 8)));
|
||||
});
|
||||
return address;
|
||||
}
|
||||
|
||||
Ext.deluge.details.PeersTab = Ext.extend(Ext.grid.GridPanel, {
|
||||
|
||||
constructor: function(config) {
|
||||
config = Ext.apply({
|
||||
title: _('Peers'),
|
||||
cls: 'x-deluge-peers',
|
||||
store: new Ext.data.SimpleStore({
|
||||
fields: [
|
||||
{name: 'country'},
|
||||
{name: 'address', sortType: sort_address},
|
||||
{name: 'client'},
|
||||
{name: 'progress', type: 'float'},
|
||||
{name: 'downspeed', type: 'int'},
|
||||
{name: 'upspeed', type: 'int'},
|
||||
{name: 'seed', type: 'int'}
|
||||
],
|
||||
id: 0
|
||||
}),
|
||||
columns: [{
|
||||
header: ' ',
|
||||
width: 30,
|
||||
sortable: true,
|
||||
renderer: flagRenderer,
|
||||
dataIndex: 'country'
|
||||
}, {
|
||||
header: 'Address',
|
||||
width: 125,
|
||||
sortable: true,
|
||||
renderer: peerAddressRenderer,
|
||||
dataIndex: 'address'
|
||||
}, {
|
||||
header: 'Client',
|
||||
width: 125,
|
||||
sortable: true,
|
||||
renderer: fplain,
|
||||
dataIndex: 'client'
|
||||
}, {
|
||||
header: 'Progress',
|
||||
width: 150,
|
||||
sortable: true,
|
||||
renderer: peerProgressRenderer,
|
||||
dataIndex: 'progress'
|
||||
}, {
|
||||
header: 'Down Speed',
|
||||
width: 100,
|
||||
sortable: true,
|
||||
renderer: fspeed,
|
||||
dataIndex: 'downspeed'
|
||||
}, {
|
||||
header: 'Up Speed',
|
||||
width: 100,
|
||||
sortable: true,
|
||||
renderer: fspeed,
|
||||
dataIndex: 'upspeed'
|
||||
}],
|
||||
stripeRows: true,
|
||||
deferredRender:false,
|
||||
autoScroll:true
|
||||
}, config);
|
||||
Ext.deluge.details.PeersTab.superclass.constructor.call(this, config);
|
||||
},
|
||||
|
||||
onRender: function(ct, position) {
|
||||
Ext.deluge.details.PeersTab.superclass.onRender.call(this, ct, position);
|
||||
},
|
||||
|
||||
clear: function() {
|
||||
this.getStore().loadData([]);
|
||||
},
|
||||
|
||||
update: function(torrentId) {
|
||||
Deluge.Client.core.get_torrent_status(torrentId, Deluge.Keys.Peers, {
|
||||
success: this.onRequestComplete,
|
||||
scope: this
|
||||
});
|
||||
},
|
||||
|
||||
onRequestComplete: function(torrent, options) {
|
||||
var peers = new Array();
|
||||
Ext.each(torrent.peers, function(peer) {
|
||||
peers.push([peer.country, peer.ip, peer.client, peer.progress, peer.down_speed, peer.up_speed, peer.seed]);
|
||||
}, this);
|
||||
this.getStore().loadData(peers);
|
||||
}
|
||||
});
|
||||
Deluge.Details.add(new Ext.deluge.details.PeersTab());
|
||||
})();
|
@ -79,151 +79,6 @@ Copyright:
|
||||
})();
|
||||
|
||||
/*
|
||||
Deluge.Details.Files = {
|
||||
onRender: function(panel) {
|
||||
this.panel = panel;
|
||||
this.panel.clear = this.clear.bind(this);
|
||||
this.panel.update = this.update.bind(this);
|
||||
|
||||
new Ext.tree.TreeSorter(this.panel, {
|
||||
folderSort: true
|
||||
});
|
||||
Deluge.Menus.FilePriorities.on('itemclick', this.onItemClick.bindWithEvent(this));
|
||||
},
|
||||
|
||||
onContextMenu: function(node, e) {
|
||||
e.stopEvent();
|
||||
var selModel = this.panel.getSelectionModel();
|
||||
if (selModel.getSelectedNodes().length < 2) {
|
||||
selModel.clearSelections();
|
||||
node.select();
|
||||
}
|
||||
Deluge.Menus.FilePriorities.showAt(e.getPoint());
|
||||
},
|
||||
|
||||
onItemClick: function(baseItem, e) {
|
||||
switch (baseItem.id) {
|
||||
case 'expandAll':
|
||||
this.panel.expandAll();
|
||||
break;
|
||||
default:
|
||||
var indexes = new Hash();
|
||||
function walk(node) {
|
||||
if (!$defined(node.attributes.fileIndex)) return;
|
||||
indexes[node.attributes.fileIndex] = node.attributes.priority;
|
||||
}
|
||||
this.panel.getRootNode().cascade(walk);
|
||||
|
||||
var nodes = this.panel.getSelectionModel().getSelectedNodes();
|
||||
$each(nodes, function(node) {
|
||||
if (!$defined(node.attributes.fileIndex)) return;
|
||||
indexes[node.attributes.fileIndex] = baseItem.filePriority;
|
||||
});
|
||||
|
||||
priorities = new Array(indexes.getLength());
|
||||
indexes.each(function(priority, index) {
|
||||
priorities[index] = priority;
|
||||
});
|
||||
|
||||
Deluge.Client.core.set_torrent_file_priorities(this.torrentId, priorities, {
|
||||
onSuccess: function() {
|
||||
$each(nodes, function(node) {
|
||||
node.setColumnValue(3, baseItem.filePriority);
|
||||
});
|
||||
}.bind(this)
|
||||
});
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
onRequestComplete: function(files, torrentId) {
|
||||
if (this.torrentId != torrentId) {
|
||||
this.clear();
|
||||
this.torrentId = torrentId;
|
||||
}
|
||||
function walk(files, parent) {
|
||||
$each(files, function(item, file) {
|
||||
var child = parent.findChild('id', file);
|
||||
if ($type(item) == 'object') {
|
||||
if (!child) {
|
||||
child = new Ext.tree.TreeNode({
|
||||
id: file,
|
||||
text: file
|
||||
});
|
||||
parent.appendChild(child);
|
||||
}
|
||||
walk(item, child);
|
||||
} else {
|
||||
if (!child) {
|
||||
child = new Ext.tree.ColumnTreeNode({
|
||||
id: file,
|
||||
filename: file,
|
||||
text: file, // this needs to be here for sorting
|
||||
fileIndex: item[0],
|
||||
size: item[1],
|
||||
progress: item[2],
|
||||
priority: item[3],
|
||||
leaf: true,
|
||||
iconCls: 'x-deluge-file',
|
||||
uiProvider: Ext.tree.ColumnNodeUI
|
||||
});
|
||||
parent.appendChild(child);
|
||||
}
|
||||
child.setColumnValue(1, item[1]);
|
||||
child.setColumnValue(2, item[2]);
|
||||
child.setColumnValue(3, item[3]);
|
||||
}
|
||||
});
|
||||
}
|
||||
var root = this.panel.getRootNode();
|
||||
walk(files, root);
|
||||
root.firstChild.expand();
|
||||
},
|
||||
|
||||
clear: function() {
|
||||
var root = this.panel.getRootNode();
|
||||
if (!root.hasChildNodes()) return;
|
||||
root.cascade(function(node) {
|
||||
var parent = node.parentNode;
|
||||
if (!parent) return;
|
||||
if (!parent.ownerTree) return;
|
||||
parent.removeChild(node);
|
||||
});
|
||||
},
|
||||
|
||||
update: function(torrentId) {
|
||||
Deluge.Client.web.get_torrent_files(torrentId, {
|
||||
onSuccess: this.onRequestComplete.bindWithEvent(this, torrentId)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Deluge.Details.Peers = {
|
||||
onRender: function(panel) {
|
||||
this.panel = panel;
|
||||
this.panel.update = this.update.bind(this);
|
||||
this.panel.clear = this.clear.bind(this);
|
||||
},
|
||||
|
||||
onRequestComplete: function(torrent) {
|
||||
var peers = new Array();
|
||||
torrent.peers.each(function(peer) {
|
||||
peers.include([peer.country, peer.ip, peer.client, peer.progress, peer.down_speed, peer.up_speed, peer.seed]);
|
||||
}, this);
|
||||
this.Store.loadData(peers);
|
||||
},
|
||||
|
||||
clear: function() {
|
||||
this.Store.loadData([]);
|
||||
},
|
||||
|
||||
update: function(torrentId) {
|
||||
Deluge.Client.core.get_torrent_status(torrentId, Deluge.Keys.Peers, {
|
||||
onSuccess: this.onRequestComplete.bindWithEvent(this, torrentId)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Deluge.Details.Options = {
|
||||
onRender: function(panel) {
|
||||
panel.layout = new Ext.layout.FormLayout();
|
||||
@ -262,139 +117,9 @@ Deluge.Details.Options = {
|
||||
}
|
||||
}
|
||||
|
||||
function flag(value) {
|
||||
return String.format('<img src="/flag/{0}" />', value);
|
||||
}
|
||||
|
||||
function peer_address(value, p, record) {
|
||||
var seed = (record.data['seed'] == 1024) ? 'x-deluge-seed' : 'x-deluge-peer'
|
||||
return String.format('<div class="{0}">{1}</div>', seed, value);
|
||||
}
|
||||
|
||||
function file_progress(value) {
|
||||
var progress = value * 100;
|
||||
return progressBar(progress, this.width - 50, progress.toFixed(2) + '%');
|
||||
}
|
||||
|
||||
function peer_progress(value) {
|
||||
var progress = (value * 100).toInt();
|
||||
var width = this.style.match(/\w+:\s*(\d+)\w+/)[1].toInt() - 8;
|
||||
return progressBar(progress, width, progress + '%');
|
||||
}
|
||||
|
||||
FILE_PRIORITY_CSS = {
|
||||
0: 'x-no-download',
|
||||
1: 'x-normal-download',
|
||||
2: 'x-high-download',
|
||||
5: 'x-highest-download'
|
||||
}
|
||||
|
||||
function priority_renderer(value) {
|
||||
return String.format('<div class="{0}">{1}</div>', FILE_PRIORITY_CSS[value], _(FILE_PRIORITY[value]));
|
||||
}
|
||||
|
||||
function sort_address(value) {
|
||||
var m = value.match(/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\:(\d+)/);
|
||||
var address = 0;
|
||||
var parts = [m[1], m[2], m[3], m[4]];
|
||||
$each(parts, function(part, index) {
|
||||
part = parseInt(part);
|
||||
address = address | part << ((3 - index) * 8);
|
||||
alert("Total: " + address + "\nPart: " + part + "\nIndex: " + index + "\nCalc: " + (part << ((3 - index) * 8)));
|
||||
});
|
||||
return address;
|
||||
}
|
||||
|
||||
Deluge.Details.Peers.Store = new Ext.data.SimpleStore({
|
||||
fields: [
|
||||
{name: 'country'},
|
||||
{name: 'address', sortType: sort_address},
|
||||
{name: 'client'},
|
||||
{name: 'progress', type: 'float'},
|
||||
{name: 'downspeed', type: 'int'},
|
||||
{name: 'upspeed', type: 'int'},
|
||||
{name: 'seed', type: 'int'}
|
||||
],
|
||||
id: 0
|
||||
});
|
||||
|
||||
Deluge.Details.Panel = new Ext.TabPanel({
|
||||
,
|
||||
items: [{
|
||||
id: 'details',
|
||||
title: _('Details'),
|
||||
cls: 'deluge-status',
|
||||
listeners: {
|
||||
'render': {
|
||||
fn: Deluge.Details.Details.onRender,
|
||||
scope: Deluge.Details.Details
|
||||
}
|
||||
}
|
||||
}, new Ext.tree.ColumnTree({
|
||||
id: 'files',
|
||||
title: _('Files'),
|
||||
rootVisible: false,
|
||||
autoScroll: true,
|
||||
selModel: new Ext.tree.MultiSelectionModel(),
|
||||
|
||||
columns: [{
|
||||
header: _('Filename'),
|
||||
width: 330,
|
||||
dataIndex: 'filename'
|
||||
}, {
|
||||
header: _('Size'),
|
||||
width: 150,
|
||||
dataIndex: 'size',
|
||||
renderer: fsize
|
||||
}, {
|
||||
header: _('Progress'),
|
||||
width: 150,
|
||||
dataIndex: 'progress',
|
||||
renderer: file_progress
|
||||
}, {
|
||||
header: _('Priority'),
|
||||
width: 150,
|
||||
dataIndex: 'priority',
|
||||
renderer: priority_renderer
|
||||
}],
|
||||
|
||||
root: new Ext.tree.TreeNode({
|
||||
text: 'Files'
|
||||
}),
|
||||
listeners: {
|
||||
'render': {
|
||||
fn: Deluge.Details.Files.onRender,
|
||||
scope: Deluge.Details.Files
|
||||
},
|
||||
'contextmenu': {
|
||||
fn: Deluge.Details.Files.onContextMenu,
|
||||
scope: Deluge.Details.Files
|
||||
}
|
||||
}
|
||||
}), new Ext.grid.GridPanel({
|
||||
id: 'peers',
|
||||
title: _('Peers'),
|
||||
cls: 'x-deluge-peers',
|
||||
store: Deluge.Details.Peers.Store,
|
||||
columns: [
|
||||
{header: ' ', width: 30, sortable: true, renderer: flag, dataIndex: 'country'},
|
||||
{header: 'Address', width: 125, sortable: true, renderer: peer_address, dataIndex: 'address'},
|
||||
{header: 'Client', width: 125, sortable: true, renderer: Deluge.Formatters.plain, dataIndex: 'client'},
|
||||
{header: 'Progress', width: 150, sortable: true, renderer: peer_progress, dataIndex: 'progress'},
|
||||
{header: 'Down Speed', width: 100, sortable: true, renderer: fspeed, dataIndex: 'downspeed'},
|
||||
{header: 'Up Speed', width: 100, sortable: true, renderer: fspeed, dataIndex: 'upspeed'}
|
||||
],
|
||||
stripeRows: true,
|
||||
deferredRender:false,
|
||||
autoScroll:true,
|
||||
margins: '0 0 0 0',
|
||||
listeners: {
|
||||
'render': {
|
||||
fn: Deluge.Details.Peers.onRender,
|
||||
scope: Deluge.Details.Peers
|
||||
}
|
||||
}
|
||||
}), new Ext.form.FormPanel({
|
||||
items: [new Ext.form.FormPanel({
|
||||
id: 'options',
|
||||
title: _('Options'),
|
||||
frame: true,
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user