      1 /*
      2 Script: Deluge.js
      3     Contains the keys for get_torrent(s)_status.
      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 Ext.namespace('Ext.deluge');
     35
     36 (function() {
     37 	/* Add some helper functions to Ext */
     38 	Ext.apply(Function.prototype, {
     39 		bind: function(scope) {
     40 			var self = this;
     41 			return function() {
     42 				return self.apply(scope, arguments);
     43 			}
     44 		}
     45 	});
     46
     47 	Ext.apply(Ext, {
     48 		keys: function(obj) {
     49 			var keys = [];
     50 			for (i in obj) if (obj.hasOwnProperty(i))
     51 			{
     52 				keys.push(i);
     53 			}
     54 			return keys;
     55 		},
     56
     57 		splat: function(obj) {
     58 			var type = Ext.type(obj);
     59 			return (type) ? ((type != 'array') ? [obj] : obj) : [];
     60 		}
     61 	});
     62 	Ext.getKeys = Ext.keys;
     63 })();
     64
     65 (function() {
     66 	var tpl = '<div class="x-progress-wrap x-progress-renderered">' +
     67 		'<div class="x-progress-inner">' +
     68 			'<div style="width: {2}px" class="x-progress-bar">' +
     69 				'<div style="z-index: 99; width: {3}px" class="x-progress-text">' +
     70 					'<div style="width: {1}px;">{0}</div>' +
     71 				'</div>' +
     72 			'</div>' +
     73 			'<div class="x-progress-text x-progress-text-back">' +
     74 				'<div style="width: {1}px;">{0}</div>' +
     75 			'</div>' +
     76 		'</div>' +
     77 	'</div>';
     78
     79 	Deluge.progressBar =  function(progress, width, text, modifier) {
     80 		modifier = Ext.value(modifier, 10);
     81 		var progressWidth = ((width / 100.0) * progress).toFixed(0);
     82 		var barWidth = progressWidth - 1;
     83 		var textWidth = ((progressWidth - modifier) > 0 ? progressWidth - modifier : 0);
     84 		return String.format(tpl, text, width, barWidth, textWidth);
     85 	}
     86 })();
     87
     88 // Hinting for gettext_gen.py
     89 // _('Do Not Download')
     90 // _('Normal Priority')
     91 // _('High Priority')
     92 // _('Highest Priority')
     93 FILE_PRIORITY = {
     94     0: 'Do Not Download',
     95     1: 'Normal Priority',
     96     2: 'High Priority',
     97     5: 'Highest Priority',
     98     'Do Not Download': 0,
     99     'Normal Priority': 1,
    100     'High Priority': 2,
    101     'Highest Priority': 5
    102 }
    103
    104 FILE_PRIORITY_CSS = {
    105 	0: 'x-no-download',
    106 	1: 'x-normal-download',
    107 	2: 'x-high-download',
    108 	5: 'x-highest-download'
    109 }
    110