      1 /*
      2 Script: Deluge.Details.Status.js
      3     The status tab displayed in the details panel.
      4
      5 Copyright:
      6 	(C) Damien Churchill 2009 <damoxc@gmail.com>
      7 	This program is free software; you can redistribute it and/or modify
      8 	it under the terms of the GNU General Public License as published by
      9 	the Free Software Foundation; either version 3, or (at your option)
     10 	any later version.
     11
     12 	This program is distributed in the hope that it will be useful,
     13 	but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 	GNU General Public License for more details.
     16
     17 	You should have received a copy of the GNU General Public License
     18 	along with this program.  If not, write to:
     19 		The Free Software Foundation, Inc.,
     20 		51 Franklin Street, Fifth Floor
     21 		Boston, MA  02110-1301, USA.
     22 #
     23 #    In addition, as a special exception, the copyright holders give
     24 #    permission to link the code of portions of this program with the OpenSSL
     25 #    library.
     26 #    You must obey the GNU General Public License in all respects for all of
     27 #    the code used other than OpenSSL. If you modify file(s) with this
     28 #    exception, you may extend this exception to your version of the file(s),
     29 #    but you are not obligated to do so. If you do not wish to do so, delete
     30 #    this exception statement from your version. If you delete this exception
     31 #    statement from all source files in the program, then also delete it here.
     32 #
     33 */
     34
     35 Ext.deluge.details.StatusTab = Ext.extend(Ext.Panel, {
     36 	title: _('Status'),
     37
     38 	onRender: function(ct, position) {
     39 		Ext.deluge.details.StatusTab.superclass.onRender.call(this, ct, position);
     40
     41 		this.progressBar = this.add({
     42 			xtype: 'fullprogressbar',
     43 			cls: 'x-deluge-status-progressbar'
     44 		});
     45
     46 		this.status = this.add({
     47 			cls: 'x-deluge-status',
     48 			border: false,
     49 			listeners: {
     50 				'render': {
     51 					fn: function(panel) {
     52 						panel.load({
     53 							url: '/render/tab_status.html',
     54 							text: _('Loading') + '...'
     55 						});
     56 						panel.getUpdater().on('update', this.onPanelUpdate, this);
     57 					},
     58 					scope: this
     59 				}
     60 			}
     61 		});
     62 	},
     63
     64 	clear: function() {
     65 		if (!this.fields) return;
     66 		this.progressBar.updateProgress(0, ' ');
     67 		for (var k in this.fields) {
     68 			this.fields[k].innerHTML = '';
     69 		}
     70 	},
     71
     72 	update: function(torrentId) {
     73 		if (!this.fields) this.getFields();
     74 		Deluge.Client.core.get_torrent_status(torrentId, Deluge.Keys.Status, {
     75 			success: this.onRequestComplete,
     76 			scope: this
     77 		});
     78 	},
     79
     80 	onPanelUpdate: function(el, response) {
     81 		this.fields = {};
     82 		Ext.each(Ext.query('dd', this.status.body.dom), function(field) {
     83 			this.fields[field.className] = field;
     84 		}, this);
     85 	},
     86
     87 	onRequestComplete: function(status) {
     88 		seeders = status.total_seeds > -1 ? status.num_seeds + ' (' + status.total_seeds + ')' : status.num_seeds
     89 		peers = status.total_peers > -1 ? status.num_peers + ' (' + status.total_peers + ')' : status.num_peers
     90 		var data = {
     91 			downloaded: fsize(status.total_done) + ' (' + fsize(status.total_payload_download) + ')',
     92 			uploaded: fsize(status.total_uploaded) + ' (' + fsize(status.total_payload_upload) + ')',
     93 			share: status.ratio.toFixed(3),
     94 			announce: ftime(status.next_announce),
     95 			tracker_status: status.tracker_status,
     96 			downspeed: fspeed(status.download_payload_rate),
     97 			upspeed: fspeed(status.upload_payload_rate),
     98 			eta: ftime(status.eta),
     99 			pieces: status.num_pieces + ' (' + fsize(status.piece_length) + ')',
    100 			seeders: seeders,
    101 			peers: peers,
    102 			avail: status.distributed_copies.toFixed(3),
    103 			active_time: ftime(status.active_time),
    104 			seeding_time: ftime(status.seeding_time),
    105 			seed_rank: status.seed_rank,
    106 			auto_managed: 'False',
    107 			time_added: fdate(status.time_added)
    108 		}
    109 		if (status.is_auto_managed) {data.auto_managed = 'True'}
    110
    111 		for (var field in this.fields) {
    112 			this.fields[field].innerHTML = data[field];
    113 		}
    114 		var text = status.state + ' ' + status.progress.toFixed(2) + '%';
    115 		this.progressBar.updateProgress(status.progress, text);
    116 	}
    117 });
    118 Deluge.Details.add(new Ext.deluge.details.StatusTab());