      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
     35 Ext.namespace('Ext.deluge');
     36
     37 (function() {
     38 	/* Add some helper functions to Ext */
     39 	Ext.apply(Function.prototype, {
     40 		bind: function(scope) {
     41 			var self = this;
     42 			return function() {
     43 				return self.apply(scope, arguments);
     44 			}
     45 		}
     46 	});
     47
     48 	Ext.apply(Ext, {
     49 		keys: function(obj) {
     50 			var keys = [];
     51 			for (i in obj) if (obj.hasOwnProperty(i))
     52 			{
     53 				keys.push(i);
     54 			}
     55 			return keys;
     56 		},
     57
     58 		splat: function(obj) {
     59 			var type = Ext.type(obj);
     60 			return (type) ? ((type != 'array') ? [obj] : obj) : [];
     61 		}
     62 	});
     63 	Ext.getKeys = Ext.keys;
     64 })();
     65
     66 (function() {
     67 	var tpl = '<div class="x-progress-wrap x-progress-renderered">' +
     68 		'<div class="x-progress-inner">' +
     69 			'<div style="width: {2}px" class="x-progress-bar">' +
     70 				'<div style="z-index: 99; width: {3}px" class="x-progress-text">' +
     71 					'<div style="width: {1}px;">{0}</div>' +
     72 				'</div>' +
     73 			'</div>' +
     74 			'<div class="x-progress-text x-progress-text-back">' +
     75 				'<div style="width: {1}px;">{0}</div>' +
     76 			'</div>' +
     77 		'</div>' +
     78 	'</div>';
     79
     80 	Deluge.progressBar =  function(progress, width, text) {
     81 		var progressWidth = ((width / 100.0) * progress).toFixed(0);
     82 		var barWidth = progressWidth - 1;
     83 		var textWidth = ((progressWidth - 10) > 0 ? progressWidth - 10 : 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 }