1 /*
  2 Script: deluge-menus.js
  3     Contains all the menus contained within the UI for easy access and editing.
  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 Deluge.Menus = {
 36 	onTorrentAction: function(item, e) {
 37 		var selection = Deluge.Torrents.getSelections();
 38 		var ids = [];
 39 		Ext.each(selection, function(record) {
 40 			ids.push(record.id);
 41 		});
 42 		
 43 		switch (item.id) {
 44 			case 'pause':
 45 			case 'resume':
 46 				Deluge.Client.core[item.id + '_torrent'](ids, {
 47 					success: function() {
 48 						Deluge.UI.update();
 49 					}
 50 				});
 51 				break;
 52 			case 'top':
 53 			case 'up':
 54 			case 'down':
 55 			case 'bottom':
 56 				Deluge.Client.core['queue_' + item.id](ids, {
 57 					success: function() {
 58 						Deluge.UI.update();
 59 					}
 60 				});
 61 				break;
 62 			case 'edit_trackers':
 63 				Deluge.EditTrackers.show();
 64 				break;
 65 			case 'update':
 66 				Deluge.Client.core.force_reannounce(ids, {
 67 					success: function() {
 68 						Deluge.UI.update();
 69 					}
 70 				});
 71 				break;
 72 			case 'remove':
 73 				Deluge.Events.fire('torrentRemoved', ids);
 74 				Deluge.Client.core.remove_torrent(ids, null, {
 75 					success: function() {
 76 						Deluge.UI.update();
 77 					}
 78 				});
 79 				break;
 80 			case 'recheck':
 81 				Deluge.Client.core.force_recheck(ids, {
 82 					success: function() {	
 83 						Deluge.UI.update();
 84 					}
 85 				});
 86 				break;
 87 		}
 88 	}
 89 }
 90 
 91 Deluge.Menus.Torrent = new Ext.menu.Menu({
 92 	id: 'torrentMenu',
 93 	items: [{
 94 		id: 'pause',
 95 		text: _('Pause'),
 96 		icon: '/icons/pause.png',
 97 		handler: Deluge.Menus.onTorrentAction,
 98 		scope: Deluge.Menus
 99 	}, {
100 		id: 'resume',
101 		text: _('Resume'),
102 		icon: '/icons/start.png',
103 		handler: Deluge.Menus.onTorrentAction,
104 		scope: Deluge.Menus
105 	}, '-', {
106 		id: 'options',
107 		text: _('Options'),
108 		icon: '/icons/preferences.png',
109 		menu: new Ext.menu.Menu({
110 			items: [{
111 				text: _('D/L Speed Limit'),
112 				iconCls: 'x-deluge-downloading',
113 				menu: new Ext.menu.Menu({
114 					items: [{
115 						text: _('5 KiB/s')
116 					}, {
117 						text: _('10 KiB/s')
118 					}, {
119 						text: _('30 KiB/s')
120 					}, {
121 						text: _('80 KiB/s')
122 					}, {
123 						text: _('300 KiB/s')
124 					},{
125 						text: _('Unlimited')
126 					}]
127 				})
128 			}, {
129 				text: _('U/L Speed Limit'),
130 				iconCls: 'x-deluge-seeding',
131 				menu: new Ext.menu.Menu({
132 					items: [{
133 						text: _('5 KiB/s')
134 					}, {
135 						text: _('10 KiB/s')
136 					}, {
137 						text: _('30 KiB/s')
138 					}, {
139 						text: _('80 KiB/s')
140 					}, {
141 						text: _('300 KiB/s')
142 					},{
143 						text: _('Unlimited')
144 					}]
145 				})
146 			}, {
147 				text: _('Connection Limit'),
148 				iconCls: 'x-deluge-connections',
149 				menu: new Ext.menu.Menu({
150 					items: [{
151 						text: _('50')
152 					}, {
153 						text: _('100')
154 					}, {
155 						text: _('200')
156 					}, {
157 						text: _('300')
158 					}, {
159 						text: _('500')
160 					},{
161 						text: _('Unlimited')
162 					}]
163 				})
164 			}, {
165 				text: _('Upload Slot Limit'),
166 				icon: '/icons/upload_slots.png',
167 				menu: new Ext.menu.Menu({
168 					items: [{
169 						text: _('0')
170 					}, {
171 						text: _('1')
172 					}, {
173 						text: _('2')
174 					}, {
175 						text: _('3')
176 					}, {
177 						text: _('5')
178 					},{
179 						text: _('Unlimited')
180 					}]
181 				})
182 			}, {
183 				id: 'auto_managed',
184 				text: _('Auto Managed'),
185 				checked: false
186 			}]
187 		})
188 	}, '-', {
189 		text: _('Queue'),
190 		icon: '/icons/queue.png',
191 		menu: new Ext.menu.Menu({
192 			items: [{
193 				id: 'top',
194 				text: _('Top'),
195 				icon: '/icons/top.png',
196 				handler: Deluge.Menus.onTorrentAction,
197 				scope: Deluge.Menus
198 			},{
199 				id: 'up',
200 				text: _('Up'),
201 				icon: '/icons/up.png',
202 				handler: Deluge.Menus.onTorrentAction,
203 				scope: Deluge.Menus
204 			},{
205 				id: 'down',
206 				text: _('Down'),
207 				icon: '/icons/down.png',
208 				handler: Deluge.Menus.onTorrentAction,
209 				scope: Deluge.Menus
210 			},{
211 				id: 'bottom',
212 				text: _('Bottom'),
213 				icon: '/icons/bottom.png',
214 				handler: Deluge.Menus.onTorrentAction,
215 				scope: Deluge.Menus
216 			}]
217 		})
218 	}, '-', {
219 		id: 'update',
220 		text: _('Update Tracker'),
221 		icon: '/icons/update.png',
222 		handler: Deluge.Menus.onTorrentAction,
223 		scope: Deluge.Menus
224 	}, {
225 		id: 'edit_trackers',
226 		text: _('Edit Trackers'),
227 		icon: '/icons/edit_trackers.png',
228 		handler: Deluge.Menus.onTorrentAction,
229 		scope: Deluge.Menus
230 	}, '-', {
231 		id: 'remove',
232 		text: _('Remove Torrent'),
233 		icon: '/icons/remove.png',
234 		handler: Deluge.Menus.onTorrentAction,
235 		scope: Deluge.Menus
236 	}, '-', {
237 		id: 'recheck',
238 		text: _('Force Recheck'),
239 		icon: '/icons/recheck.png',
240 		handler: Deluge.Menus.onTorrentAction,
241 		scope: Deluge.Menus
242 	/*}, {
243 		id: 'move',
244 		text: _('Move Storage'),
245 		icon: '/icons/move.png',
246 		handler: Deluge.Menus.onTorrentAction,
247 		scope: Deluge.Menus*/
248 	}]
249 });
250 
251 Deluge.Menus.Connections = new Ext.menu.Menu({
252 	id: 'connectionsMenu',
253 	items: [{
254 		id: '50',
255 		text: '50',
256 		group: 'max_connections_global',
257 		checked: false,
258 		checkHandler: onLimitChanged
259 	},{
260 		id: '100',
261 		text: '100',
262 		group: 'max_connections_global',
263 		checked: false,
264 		checkHandler: onLimitChanged
265 	},{
266 		id: '200',
267 		text: '200',
268 		group: 'max_connections_global',
269 		checked: false,
270 		checkHandler: onLimitChanged
271 	},{
272 		id: '300',
273 		text: '300',
274 		group: 'max_connections_global',
275 		checked: false,
276 		checkHandler: onLimitChanged
277 	},{
278 		id: '500',
279 		text: '500',
280 		group: 'max_connections_global',
281 		checked: false,
282 		checkHandler: onLimitChanged
283 	},{
284 		id: '-1',
285 		text: _('Unlimited'),
286 		group: 'max_connections_global',
287 		checked: false,
288 		checkHandler: onLimitChanged
289 	},'-',{
290 		id: 'other',
291 		text: _('Other'),
292 		group: 'max_connections_global',
293 		checked: false,
294 		checkHandler: onLimitChanged
295 	}]
296 });
297 
298 Deluge.Menus.Download = new Ext.menu.Menu({
299 	id: 'downspeedMenu',
300 	items: [{
301 		id: '5',
302 		text: '5 KiB/s',
303 		group: 'max_download_speed',
304 		checked: false,
305 		checkHandler: onLimitChanged
306 	},{
307 		id: '10',
308 		text: '10 KiB/s',
309 		group: 'max_download_speed',
310 		checked: false,
311 		checkHandler: onLimitChanged
312 	},{
313 		id: '30',
314 		text: '30 KiB/s',
315 		group: 'max_download_speed',
316 		checked: false,
317 		checkHandler: onLimitChanged
318 	},{
319 		id: '80',
320 		text: '80 KiB/s',
321 		group: 'max_download_speed',
322 		checked: false,
323 		checkHandler: onLimitChanged
324 	},{
325 		id: '300',
326 		text: '300 KiB/s',
327 		group: 'max_download_speed',
328 		checked: false,
329 		checkHandler: onLimitChanged
330 	},{
331 		id: '-1',
332 		text: _('Unlimited'),
333 		group: 'max_download_speed',
334 		checked: false,
335 		checkHandler: onLimitChanged
336 	},'-',{
337 		id: 'other',
338 		text: _('Other'),
339 		group: 'max_download_speed',
340 		checked: false,
341 		checkHandler: onLimitChanged
342 	}]
343 });
344 
345 Deluge.Menus.Upload = new Ext.menu.Menu({
346 	id: 'upspeedMenu',
347 	items: [{
348 		id: '5',
349 		text: '5 KiB/s',
350 		group: 'max_upload_speed',
351 		checked: false,
352 		checkHandler: onLimitChanged
353 	},{
354 		id: '10',
355 		text: '10 KiB/s',
356 		group: 'max_upload_speed',
357 		checked: false,
358 		checkHandler: onLimitChanged
359 	},{
360 		id: '30',
361 		text: '30 KiB/s',
362 		group: 'max_upload_speed',
363 		checked: false,
364 		checkHandler: onLimitChanged
365 	},{
366 		id: '80',
367 		text: '80 KiB/s',
368 		group: 'max_upload_speed',
369 		checked: false,
370 		checkHandler: onLimitChanged
371 	},{
372 		id: '300',
373 		text: '300 KiB/s',
374 		group: 'max_upload_speed',
375 		checked: false,
376 		checkHandler: onLimitChanged
377 	},{
378 		id: '-1',
379 		text: _('Unlimited'),
380 		group: 'max_upload_speed',
381 		checked: false,
382 		checkHandler: onLimitChanged
383 	},'-',{
384 		id: 'other',
385 		text: _('Other'),
386 		group: 'max_upload_speed',
387 		checked: false,
388 		checkHandler: onLimitChanged
389 	}]
390 });
391 
392 Deluge.Menus.FilePriorities = new Ext.menu.Menu({
393 	id: 'filePrioritiesMenu',
394 	items: [{
395 		id: 'expandAll',
396 		text: _('Expand All'),
397 		icon: '/icons/expand_all.png'
398 	}, '-', {
399 		id: 'no_download',
400 		text: _('Do Not Download'),
401 		icon: '/icons/no_download.png',
402 		filePriority: 0
403 	}, {
404 		id: 'normal',
405 		text: _('Normal Priority'),
406 		icon: '/icons/normal.png',
407 		filePriority: 1
408 	}, {
409 		id: 'high',
410 		text: _('High Priority'),
411 		icon: '/icons/high.png',
412 		filePriority: 2
413 	}, {
414 		id: 'highest',
415 		text: _('Highest Priority'),
416 		icon: '/icons/highest.png',
417 		filePriority: 5
418 	}]
419 });
420 
421 function onLimitChanged(item, checked) {
422 	if (item.id == "other") {
423 	} else {
424 		config = {}
425 		config[item.group] = item.id
426 		Deluge.Client.core.set_config(config, {
427 			success: function() {
428 				Deluge.UI.update();
429 			}
430 		});
431 	}
432 }