mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-06 08:28:39 +00:00
convert spaces to tabs
This commit is contained in:
parent
708ad2e665
commit
f4cf3d9893
1 changed files with 289 additions and 290 deletions
|
@ -1,311 +1,310 @@
|
||||||
/*
|
/*
|
||||||
Script: Deluge.Torrents.js
|
Script: Deluge.Torrents.js
|
||||||
Contains all objects and functions related to the torrent grid.
|
Contains all objects and functions related to the torrent grid.
|
||||||
|
|
||||||
Copyright:
|
Copyright:
|
||||||
(C) Damien Churchill 2009 <damoxc@gmail.com>
|
(C) Damien Churchill 2009 <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
|
||||||
the Free Software Foundation; either version 3, or (at your option)
|
the Free Software Foundation; either version 3, or (at your option)
|
||||||
any later version.
|
any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, write to:
|
along with this program. If not, write to:
|
||||||
The Free Software Foundation, Inc.,
|
The Free Software Foundation, Inc.,
|
||||||
51 Franklin Street, Fifth Floor
|
51 Franklin Street, Fifth Floor
|
||||||
Boston, MA 02110-1301, USA.
|
Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
In addition, as a special exception, the copyright holders give
|
In addition, as a special exception, the copyright holders give
|
||||||
permission to link the code of portions of this program with the OpenSSL
|
permission to link the code of portions of this program with the OpenSSL
|
||||||
library.
|
library.
|
||||||
You must obey the GNU General Public License in all respects for all of
|
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
|
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),
|
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
|
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
|
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.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
/* Renderers for the Torrent Grid */
|
/* Renderers for the Torrent Grid */
|
||||||
function queueRenderer(value) {
|
function queueRenderer(value) {
|
||||||
return (value == 99999) ? '' : value + 1;
|
return (value == 99999) ? '' : 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 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, p, r) {
|
||||||
value = new Number(value);
|
value = new Number(value);
|
||||||
var progress = value;
|
var progress = value;
|
||||||
var text = r.data['state'] + ' ' + value.toFixed(2) + '%'
|
var text = r.data['state'] + ' ' + value.toFixed(2) + '%'
|
||||||
var width = new Number(this.style.match(/\w+:\s*(\d+)\w+/)[1]) - 8;
|
var width = new Number(this.style.match(/\w+:\s*(\d+)\w+/)[1]) - 8;
|
||||||
return Deluge.progressBar(value, width, text);
|
return Deluge.progressBar(value, width, 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 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 String.format('{0} ({1})', value, r.data['total_peers']);
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function availRenderer(value, p, r) {
|
function availRenderer(value, p, r) {
|
||||||
return (value < 0) ? '∞' : new Number(value).toFixed(3);
|
return (value < 0) ? '∞' : new Number(value).toFixed(3);
|
||||||
}
|
}
|
||||||
function trackerRenderer(value, p, r) {
|
function trackerRenderer(value, p, r) {
|
||||||
return String.format('<div style="background: url(/tracker/{0}) no-repeat; padding-left: 20px;">{0}</div>', value);
|
return String.format('<div style="background: url(/tracker/{0}) no-repeat; padding-left: 20px;">{0}</div>', value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function etaSorter(eta) {
|
function etaSorter(eta) {
|
||||||
return eta * -1;
|
return eta * -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ext.deluge.TorrentGrid Class
|
* Ext.deluge.TorrentGrid Class
|
||||||
*
|
*
|
||||||
* @author Damien Churchill <damoxc@gmail.com>
|
* @author Damien Churchill <damoxc@gmail.com>
|
||||||
* @version 1.2
|
* @version 1.2
|
||||||
*
|
*
|
||||||
* @class Ext.deluge.TorrentGrid
|
* @class Ext.deluge.TorrentGrid
|
||||||
* @extends Ext.grid.GridPanel
|
* @extends Ext.grid.GridPanel
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {Object} config Configuration options
|
* @param {Object} config Configuration options
|
||||||
*/
|
*/
|
||||||
Ext.deluge.TorrentGrid = Ext.extend(Ext.grid.GridPanel, {
|
Ext.deluge.TorrentGrid = Ext.extend(Ext.grid.GridPanel, {
|
||||||
constructor: function(config) {
|
constructor: function(config) {
|
||||||
config = Ext.apply({
|
config = Ext.apply({
|
||||||
id: 'torrentGrid',
|
id: 'torrentGrid',
|
||||||
store: new Ext.data.SimpleStore({
|
store: new Ext.data.SimpleStore({
|
||||||
fields: [
|
fields: [
|
||||||
{name: 'queue'},
|
{name: 'queue'},
|
||||||
{name: 'name'},
|
{name: 'name'},
|
||||||
{name: 'size', type: 'int'},
|
{name: 'size', type: 'int'},
|
||||||
{name: 'state'},
|
{name: 'state'},
|
||||||
{name: 'progress', type: 'float'},
|
{name: 'progress', type: 'float'},
|
||||||
{name: 'seeds', type: 'int'},
|
{name: 'seeds', type: 'int'},
|
||||||
{name: 'total_seeds', type: 'int'},
|
{name: 'total_seeds', type: 'int'},
|
||||||
{name: 'peers', type: 'int'},
|
{name: 'peers', type: 'int'},
|
||||||
{name: 'total_peers', type: 'int'},
|
{name: 'total_peers', type: 'int'},
|
||||||
{name: 'downspeed', type: 'int'},
|
{name: 'downspeed', type: 'int'},
|
||||||
{name: 'upspeed', type: 'int'},
|
{name: 'upspeed', type: 'int'},
|
||||||
{name: 'eta', type: 'int', sortType: etaSorter},
|
{name: 'eta', type: 'int', sortType: etaSorter},
|
||||||
{name: 'ratio', type: 'float'},
|
{name: 'ratio', type: 'float'},
|
||||||
{name: 'avail', type: 'float'},
|
{name: 'avail', type: 'float'},
|
||||||
{name: 'added', type: 'int'},
|
{name: 'added', type: 'int'},
|
||||||
{name: 'tracker'}
|
{name: 'tracker'}
|
||||||
],
|
],
|
||||||
id: 16
|
id: 16
|
||||||
}),
|
}),
|
||||||
columns: [{
|
columns: [{
|
||||||
id:'queue',
|
id:'queue',
|
||||||
header: _('#'),
|
header: _('#'),
|
||||||
width: 30,
|
width: 30,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: queueRenderer,
|
renderer: queueRenderer,
|
||||||
dataIndex: 'queue'
|
dataIndex: 'queue'
|
||||||
}, {
|
}, {
|
||||||
id:'name',
|
id:'name',
|
||||||
header: _('Name'),
|
header: _('Name'),
|
||||||
width: 150,
|
width: 150,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: torrentNameRenderer,
|
renderer: torrentNameRenderer,
|
||||||
dataIndex: 'name'
|
dataIndex: 'name'
|
||||||
}, {
|
}, {
|
||||||
header: _('Size'),
|
header: _('Size'),
|
||||||
width: 75,
|
width: 75,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: fsize,
|
renderer: fsize,
|
||||||
dataIndex: 'size'
|
dataIndex: 'size'
|
||||||
}, {
|
}, {
|
||||||
header: _('Progress'),
|
header: _('Progress'),
|
||||||
width: 150,
|
width: 150,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: torrentProgressRenderer,
|
renderer: torrentProgressRenderer,
|
||||||
dataIndex: 'progress'
|
dataIndex: 'progress'
|
||||||
}, {
|
}, {
|
||||||
header: _('Seeders'),
|
header: _('Seeders'),
|
||||||
width: 60,
|
width: 60,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: seedsRenderer,
|
renderer: seedsRenderer,
|
||||||
dataIndex: 'seeds'
|
dataIndex: 'seeds'
|
||||||
}, {
|
}, {
|
||||||
header: _('Peers'),
|
header: _('Peers'),
|
||||||
width: 60,
|
width: 60,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: peersRenderer,
|
renderer: peersRenderer,
|
||||||
dataIndex: 'peers'
|
dataIndex: 'peers'
|
||||||
}, {
|
}, {
|
||||||
header: _('Down Speed'),
|
header: _('Down Speed'),
|
||||||
width: 80,
|
width: 80,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: torrentSpeedRenderer,
|
renderer: torrentSpeedRenderer,
|
||||||
dataIndex: 'downspeed'
|
dataIndex: 'downspeed'
|
||||||
}, {
|
}, {
|
||||||
header: _('Up Speed'),
|
header: _('Up Speed'),
|
||||||
width: 80,
|
width: 80,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: torrentSpeedRenderer,
|
renderer: torrentSpeedRenderer,
|
||||||
dataIndex: 'upspeed'
|
dataIndex: 'upspeed'
|
||||||
}, {
|
}, {
|
||||||
header: _('ETA'),
|
header: _('ETA'),
|
||||||
width: 60,
|
width: 60,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: ftime,
|
renderer: ftime,
|
||||||
dataIndex: 'eta'
|
dataIndex: 'eta'
|
||||||
}, {
|
}, {
|
||||||
header: _('Ratio'),
|
header: _('Ratio'),
|
||||||
width: 60,
|
width: 60,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: availRenderer,
|
renderer: availRenderer,
|
||||||
dataIndex: 'ratio'
|
dataIndex: 'ratio'
|
||||||
}, {
|
}, {
|
||||||
header: _('Avail'),
|
header: _('Avail'),
|
||||||
width: 60,
|
width: 60,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: availRenderer,
|
renderer: availRenderer,
|
||||||
dataIndex: 'avail'
|
dataIndex: 'avail'
|
||||||
}, {
|
}, {
|
||||||
header: _('Added'),
|
header: _('Added'),
|
||||||
width: 80,
|
width: 80,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: fdate,
|
renderer: fdate,
|
||||||
dataIndex: 'added'
|
dataIndex: 'added'
|
||||||
}, {
|
}, {
|
||||||
header: _('Tracker'),
|
header: _('Tracker'),
|
||||||
width: 120,
|
width: 120,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
renderer: trackerRenderer,
|
renderer: trackerRenderer,
|
||||||
dataIndex: 'tracker'
|
dataIndex: 'tracker'
|
||||||
}],
|
}],
|
||||||
region: 'center',
|
region: 'center',
|
||||||
cls: 'deluge-torrents',
|
cls: 'deluge-torrents',
|
||||||
stripeRows: true,
|
stripeRows: true,
|
||||||
autoExpandColumn: 'name',
|
autoExpandColumn: 'name',
|
||||||
deferredRender:false,
|
deferredRender:false,
|
||||||
autoScroll:true,
|
autoScroll:true,
|
||||||
margins: '5 5 0 0',
|
margins: '5 5 0 0',
|
||||||
stateful: true
|
stateful: true
|
||||||
}, config);
|
}, config);
|
||||||
Ext.deluge.TorrentGrid.superclass.constructor.call(this, config);
|
Ext.deluge.TorrentGrid.superclass.constructor.call(this, config);
|
||||||
},
|
},
|
||||||
|
|
||||||
initComponent: function() {
|
initComponent: function() {
|
||||||
Ext.deluge.TorrentGrid.superclass.initComponent.call(this);
|
Ext.deluge.TorrentGrid.superclass.initComponent.call(this);
|
||||||
Deluge.Events.on('torrentRemoved', this.onTorrentRemoved, this);
|
Deluge.Events.on('torrentRemoved', this.onTorrentRemoved, this);
|
||||||
this.on('rowcontextmenu', function(grid, rowIndex, e) {
|
this.on('rowcontextmenu', function(grid, rowIndex, e) {
|
||||||
e.stopEvent();
|
e.stopEvent();
|
||||||
var selection = grid.getSelectionModel();
|
var selection = grid.getSelectionModel();
|
||||||
if (!selection.hasSelection()) {
|
if (!selection.hasSelection()) {
|
||||||
selection.selectRow(rowIndex);
|
selection.selectRow(rowIndex);
|
||||||
}
|
}
|
||||||
Deluge.Menus.Torrent.showAt(e.getPoint());
|
Deluge.Menus.Torrent.showAt(e.getPoint());
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the record representing the torrent at the specified index.
|
* Returns the record representing the torrent at the specified index.
|
||||||
*
|
*
|
||||||
* @param {int} The row index of the torrent you wish to retrieve.
|
* @param {int} The row index of the torrent you wish to retrieve.
|
||||||
* @return {Ext.data.Record} The record representing the torrent.
|
* @return {Ext.data.Record} The record representing the torrent.
|
||||||
*/
|
*/
|
||||||
getTorrent: function(rowIndex) {
|
getTorrent: function(rowIndex) {
|
||||||
return this.getStore().getAt(rowIndex);
|
return this.getStore().getAt(rowIndex);
|
||||||
},
|
},
|
||||||
|
|
||||||
getSelected: function() {
|
getSelected: function() {
|
||||||
return this.getSelectionModel().getSelected();
|
return this.getSelectionModel().getSelected();
|
||||||
},
|
},
|
||||||
|
|
||||||
getSelections: function() {
|
getSelections: function() {
|
||||||
return this.getSelectionModel().getSelections();
|
return this.getSelectionModel().getSelections();
|
||||||
},
|
},
|
||||||
|
|
||||||
update: function(torrents) {
|
update: function(torrents, bulk) {
|
||||||
//var torrents = [];
|
var store = this.getStore();
|
||||||
var store = this.getStore();
|
for (var torrentId in torrents) {
|
||||||
for (var torrentId in torrents) {
|
var record = store.getById(torrentId);
|
||||||
var record = store.getById(torrentId);
|
var torrent = torrents[torrentId];
|
||||||
var torrent = torrents[torrentId];
|
if (!record) {
|
||||||
if (!record) {
|
// We need to create a new record
|
||||||
// We need to create a new record
|
var data = [
|
||||||
var data = [
|
((torrent.queue == -1) ? 99999 : torrent.queue),
|
||||||
((torrent.queue == -1) ? 99999 : torrent.queue),
|
torrent.name,
|
||||||
torrent.name,
|
torrent.total_size,
|
||||||
torrent.total_size,
|
torrent.state,
|
||||||
torrent.state,
|
torrent.progress,
|
||||||
torrent.progress,
|
torrent.num_seeds,
|
||||||
torrent.num_seeds,
|
torrent.total_seeds,
|
||||||
torrent.total_seeds,
|
torrent.num_peers,
|
||||||
torrent.num_peers,
|
torrent.total_peers,
|
||||||
torrent.total_peers,
|
torrent.download_payload_rate,
|
||||||
torrent.download_payload_rate,
|
torrent.upload_payload_rate,
|
||||||
torrent.upload_payload_rate,
|
torrent.eta,
|
||||||
torrent.eta,
|
torrent.ratio,
|
||||||
torrent.ratio,
|
torrent.distributed_copies,
|
||||||
torrent.distributed_copies,
|
torrent.time_added,
|
||||||
torrent.time_added,
|
torrent.tracker_host,
|
||||||
torrent.tracker_host,
|
torrentId
|
||||||
torrentId
|
];
|
||||||
];
|
store.loadData([data], true);
|
||||||
store.loadData([data], true);
|
} else {
|
||||||
} else {
|
// We just need to do an update
|
||||||
// We just need to do an update
|
record.set('queue', ((torrent.queue == -1) ? 99999 : torrent.queue));
|
||||||
record.set('queue', ((torrent.queue == -1) ? 99999 : torrent.queue));
|
record.set('name', torrent.name);
|
||||||
record.set('name', torrent.name);
|
record.set('size', torrent.total_size);
|
||||||
record.set('size', torrent.total_size);
|
record.set('state', torrent.state);
|
||||||
record.set('state', torrent.state);
|
record.set('progress', torrent.progress);
|
||||||
record.set('progress', torrent.progress);
|
record.set('seeds', torrent.num_seeds);
|
||||||
record.set('seeds', torrent.num_seeds);
|
record.set('total_seeds', torrent.total_seeds);
|
||||||
record.set('total_seeds', torrent.total_seeds);
|
record.set('peers', torrent.num_peers);
|
||||||
record.set('peers', torrent.num_peers);
|
record.set('total_peers', torrent.total_peers);
|
||||||
record.set('total_peers', torrent.total_peers);
|
record.set('downspeed', torrent.download_payload_rate);
|
||||||
record.set('downspeed', torrent.download_payload_rate);
|
record.set('upspeed', torrent.upload_payload_rate);
|
||||||
record.set('upspeed', torrent.upload_payload_rate);
|
record.set('eta', torrent.eta);
|
||||||
record.set('eta', torrent.eta);
|
record.set('ratio', torrent.ratio);
|
||||||
record.set('ratio', torrent.ratio);
|
record.set('avail', torrent.distributed_copies);
|
||||||
record.set('avail', torrent.distributed_copies);
|
record.set('added', torrent.time_added);
|
||||||
record.set('added', torrent.time_added);
|
record.set('tracker', torrent.tracker_host);
|
||||||
record.set('tracker', torrent.tracker_host);
|
record.commit();
|
||||||
record.commit();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var torrentIds = Ext.keys(torrents);
|
var torrentIds = Ext.keys(torrents);
|
||||||
store.each(function(record) {
|
store.each(function(record) {
|
||||||
if (torrentIds.indexOf(record.id) == -1) {
|
if (torrentIds.indexOf(record.id) == -1) {
|
||||||
// Torrent is no longer in the grid so we must remove it.
|
// Torrent is no longer in the grid so we must remove it.
|
||||||
store.remove(record);
|
store.remove(record);
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
// private
|
// private
|
||||||
onTorrentRemoved: function(torrentIds) {
|
onTorrentRemoved: function(torrentIds) {
|
||||||
var selModel = this.getSelectionModel();
|
var selModel = this.getSelectionModel();
|
||||||
Ext.each(torrentIds, function(torrentId) {
|
Ext.each(torrentIds, function(torrentId) {
|
||||||
var record = this.getStore().getById(torrentId);
|
var record = this.getStore().getById(torrentId);
|
||||||
if (selModel.isSelected(record)) {
|
if (selModel.isSelected(record)) {
|
||||||
selModel.deselectRow(this.getStore().indexOf(record));
|
selModel.deselectRow(this.getStore().indexOf(record));
|
||||||
}
|
}
|
||||||
this.getStore().remove(record);
|
this.getStore().remove(record);
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Deluge.Torrents = new Ext.deluge.TorrentGrid();
|
Deluge.Torrents = new Ext.deluge.TorrentGrid();
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue