      1 /*
      2 Script: Deluge.Details.Options.js
      3     The options 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.OptionsTab = Ext.extend(Ext.form.FormPanel, {
     36
     37 	constructor: function(config) {
     38 		config = Ext.apply({
     39 			autoScroll: true,
     40 			bodyStyle: 'padding: 5px;',
     41 			border: false,
     42 			cls: 'x-deluge-options',
     43 			defaults: {
     44 				autoHeight: true,
     45 				labelWidth: 1,
     46 				defaultType: 'checkbox'
     47 			},
     48 			deferredRender: false,
     49 			layout: 'column',
     50 			title: _('Options')
     51 		}, config);
     52 		Ext.deluge.details.OptionsTab.superclass.constructor.call(this, config);
     53 	},
     54
     55 	initComponent: function() {
     56 		Ext.deluge.details.OptionsTab.superclass.initComponent.call(this);
     57
     58 		this.fieldsets = {}, this.fields = {};
     59
     60 		/*
     61 		 * Bandwidth Options
     62 		 */
     63 		this.fieldsets.bandwidth = this.add({
     64 			xtype: 'fieldset',
     65 			defaultType: 'uxspinner',
     66 			bodyStyle: 'padding: 5px',
     67
     68 			layout: 'table',
     69 			layoutConfig: {columns: 3},
     70 			labelWidth: 150,
     71
     72 			style: 'margin-left: 10px; margin-right: 5px; padding: 5px',
     73 			title: _('Bandwidth'),
     74 			width: 300
     75 		});
     76
     77 		/*
     78 		 * Max Download Speed
     79 		 */
     80 		this.fieldsets.bandwidth.add({
     81 			xtype: 'label',
     82 			text: _('Max Download Speed'),
     83 			forId: 'max_download_speed',
     84 			cls: 'x-deluge-options-label'
     85 		});
     86 		this.fields.max_download_speed = this.fieldsets.bandwidth.add({
     87 			id: 'max_download_speed',
     88 			name: 'max_download_speed',
     89 			width: 100,
     90 			value: -1,
     91 			stragegy: new Ext.ux.form.Spinner.NumberStrategy({
     92 				minValue: -1,
     93 				maxValue: 99999,
     94 				incrementValue: 1
     95 			})
     96 		});
     97 		this.fieldsets.bandwidth.add({
     98 			xtype: 'label',
     99 			text: _('KiB/s'),
    100 			style: 'margin-left: 10px'
    101 		});
    102
    103 		/*
    104 		 * Max Upload Speed
    105 		 */
    106 		this.fieldsets.bandwidth.add({
    107 			xtype: 'label',
    108 			text: _('Max Upload Speed'),
    109 			forId: 'max_upload_speed',
    110 			cls: 'x-deluge-options-label'
    111 		});
    112 		this.fields.max_upload_speed = this.fieldsets.bandwidth.add({
    113 			id: 'max_upload_speed',
    114 			name: 'max_upload_speed',
    115 			width: 100,
    116 			value: -1,
    117 			stragegy: new Ext.ux.form.Spinner.NumberStrategy({
    118 				minValue: -1,
    119 				maxValue: 99999,
    120 				incrementValue: 1
    121 			})
    122 		});
    123 		this.fieldsets.bandwidth.add({
    124 			xtype: 'label',
    125 			text: _('KiB/s'),
    126 			style: 'margin-left: 10px'
    127 		});
    128
    129 		/*
    130 		 * Max Connections
    131 		 */
    132 		this.fieldsets.bandwidth.add({
    133 			xtype: 'label',
    134 			text: _('Max Connections'),
    135 			forId: 'max_connections',
    136 			cls: 'x-deluge-options-label'
    137 		});
    138 		this.fields.max_connections = this.fieldsets.bandwidth.add({
    139 			id: 'max_connections',
    140 			name: 'max_connections',
    141 			width: 100,
    142 			value: -1,
    143 			stragegy: new Ext.ux.form.Spinner.NumberStrategy({
    144 				minValue: -1,
    145 				maxValue: 99999,
    146 				incrementValue: 1
    147 			})
    148 		});
    149 		this.fieldsets.bandwidth.add({xtype: 'label'});
    150
    151 		/*
    152 		 * Max Upload Slots
    153 		 */
    154 		this.fieldsets.bandwidth.add({
    155 			xtype: 'label',
    156 			text: _('Max Upload Slots'),
    157 			forId: 'max_upload_slots',
    158 			cls: 'x-deluge-options-label'
    159 		});
    160 		this.fields.max_upload_slots = this.fieldsets.bandwidth.add({
    161 			id: 'max_upload_slots',
    162 			name: 'max_upload_slots',
    163 			width: 100,
    164 			value: -1,
    165 			stragegy: new Ext.ux.form.Spinner.NumberStrategy({
    166 				minValue: -1,
    167 				maxValue: 99999,
    168 				incrementValue: 1
    169 			})
    170 		});
    171
    172 		/*
    173 		 * Queue Options
    174 		 */
    175 		this.fieldsets.queue = this.add({
    176 			xtype: 'fieldset',
    177 			title: _('Queue'),
    178 			style: 'margin-left: 5px; margin-right: 5px; padding: 5px',
    179 			width: 200,
    180 			defaults: {
    181 				fieldLabel: '',
    182 				labelSeparator: ''
    183 			}
    184 		});
    185
    186 		this.fields.is_auto_managed = this.fieldsets.queue.add({
    187 			fieldLabel: '',
    188 			labelSeparator: '',
    189 			id: 'is_auto_managed',
    190 			boxLabel: _('Auto Managed')
    191 		});
    192
    193 		this.fields.stop_at_ratio = this.fieldsets.queue.add({
    194 			fieldLabel: '',
    195 			labelSeparator: '',
    196 			id: 'stop_at_ratio',
    197 			boxLabel: _('Stop seed at ratio')
    198 		});
    199
    200 		this.fields.remove_at_ratio = this.fieldsets.queue.add({
    201 			fieldLabel: '',
    202 			labelSeparator: '',
    203 			id: 'remove_at_ratio',
    204 			style: 'margin-left: 10px',
    205 			boxLabel: _('Remove at ratio')
    206 		});
    207
    208 		this.fields.move_completed = this.fieldsets.queue.add({
    209 			fieldLabel: '',
    210 			labelSeparator: '',
    211 			id: 'move_completed',
    212 			boxLabel: _('Move Completed')
    213 		});
    214
    215
    216 		/*
    217 		 * General Options
    218 		 */
    219 		this.rightColumn =  this.add({
    220 			border: false,
    221 			autoHeight: true,
    222 			style: 'margin-left: 5px',
    223 			width: 200
    224 		});
    225
    226 		this.fieldsets.general = this.rightColumn.add({
    227 			xtype: 'fieldset',
    228 			autoHeight: true,
    229 			defaultType: 'checkbox',
    230 			title: _('General'),
    231 			layout: 'form'
    232 		});
    233
    234 		this.fields['private'] = this.fieldsets.general.add({
    235 			fieldLabel: '',
    236 			labelSeparator: '',
    237 			boxLabel: _('Private'),
    238 			id: 'private'
    239 		});
    240
    241 		this.fields.prioritize_first_last = this.fieldsets.general.add({
    242 			fieldLabel: '',
    243 			labelSeparator: '',
    244 			boxLabel: _('Prioritize First/Last'),
    245 			id: 'prioritize_first_last'
    246 		});
    247
    248 		/*
    249 		 * Buttons
    250 		 */
    251 		this.buttonPanel = this.rightColumn.add({
    252 			layout: 'column',
    253 			xtype: 'panel',
    254 			border: false
    255 		});
    256
    257 		// The buttons below are required to be added to a panel
    258 		// first as simply adding them to the column layout throws an
    259 		// error c.getSize() does not exist. This could be intentional
    260 		// or it may possible be a bug in ext-js. Take care when upgrading
    261 		// to ext-js 3.0.
    262
    263 		/*
    264 		 * Edit Trackers button
    265 		 */
    266 		this.buttonPanel.add({
    267 			xtype: 'panel',
    268 			border: false
    269 		}).add({
    270 			id: 'edit_trackers',
    271 			xtype: 'button',
    272 			text: _('Edit Trackers'),
    273 			cls: 'x-btn-text-icon',
    274 			iconCls: 'x-deluge-edit-trackers',
    275 			border: false,
    276 			width: 100,
    277 			handler: this.onEditTrackers,
    278 			scope: this
    279 		});
    280
    281 		/*
    282 		 * Apply button
    283 		 */
    284 		this.buttonPanel.add({
    285 			xtype: 'panel',
    286 			border: false
    287 		}).add({
    288 			id: 'apply',
    289 			xtype: 'button',
    290 			text: _('Apply'),
    291 			style: 'margin-left: 10px;',
    292 			border: false,
    293 			width: 100,
    294 		});
    295 	},
    296
    297 	onRender: function(ct, position) {
    298 		Ext.deluge.details.OptionsTab.superclass.onRender.call(this, ct, position);
    299
    300 		// This is another hack I think, so keep an eye out here when upgrading.
    301 		this.layout = new Ext.layout.ColumnLayout();
    302 		this.layout.setContainer(this);
    303 		this.doLayout();
    304 	},
    305
    306 	clear: function() {
    307 		this.fields.max_download_speed.setValue(0);
    308 		this.fields.max_upload_speed.setValue(0);
    309 		this.fields.max_connections.setValue(0);
    310 		this.fields.max_upload_slots.setValue(0);
    311 		this.fields.is_auto_managed.setValue(false);
    312 		this.fields.stop_at_ratio.setValue(false);
    313 		this.fields.remove_at_ratio.setValue(false);
    314 		this.fields['private'].setValue(false);
    315 		this.fields.prioritize_first_last.setValue(false);
    316 	},
    317
    318 	reset: function() {
    319 		if (this.torrentId) {
    320 			delete this.changed[this.torrentId];
    321 		}
    322 	},
    323
    324 	update: function(torrentId) {
    325 		this.torrentId = torrentId;
    326 		Deluge.Client.core.get_torrent_status(torrentId, Deluge.Keys.Options, {
    327 			success: this.onRequestComplete,
    328 			scope: this
    329 		});
    330 	},
    331
    332 	onEditTrackers: function() {
    333 		Deluge.EditTrackers.show();
    334 	},
    335
    336 	onRequestComplete: function(torrent, options) {
    337 		for (var key in torrent) {
    338 			if (this.fields[key]) {
    339 				this.fields[key].setValue(torrent[key])
    340 			} else {
    341 				//alert(key);
    342 			}
    343 		}
    344 	}
    345 });
    346 Deluge.Details.add(new Ext.deluge.details.OptionsTab());
    347