diff --git a/deluge/ui/web/js/deluge-all-debug.js b/deluge/ui/web/js/deluge-all-debug.js index c242a1974..d1c84856f 100644 --- a/deluge/ui/web/js/deluge-all-debug.js +++ b/deluge/ui/web/js/deluge-all-debug.js @@ -1,3241 +1,322 @@ -/* -Script: Deluge.js - Contains the keys for get_torrent(s)_status. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - - -// Setup the state manager -Ext.state.Manager.setProvider(new Ext.state.CookieProvider()); - -// Add some additional functions to ext and setup some of the -// configurable parameters -(function() { - - Ext.apply(Ext, { - escapeHTML: function(text) { - text = String(text).replace('<', '<').replace('>', '>'); - return text.replace('&', '&'); - }, - - isObjectEmpty: function(obj) { - for(var i in obj) { return false; } - return true; - }, - - isObjectsEqual: function(obj1, obj2) { - var equal = true; - if (!obj1 || !obj2) return false; - for (var i in obj1) { - if (obj1[i] != obj2[i]) { - equal = false; - } - } - return equal; - }, - - keys: function(obj) { - var keys = []; - for (var i in obj) if (obj.hasOwnProperty(i)) - { - keys.push(i); - } - return keys; - }, - - values: function(obj) { - var values = []; - for (var i in obj) { - if (obj.hasOwnProperty(i)) { - values.push(obj[i]); - } - } - return values; - }, - - splat: function(obj) { - var type = Ext.type(obj); - return (type) ? ((type != 'array') ? [obj] : obj) : []; - } - }); - Ext.getKeys = Ext.keys; - Ext.BLANK_IMAGE_URL = deluge.config.base + 'images/s.gif'; - Ext.USE_NATIVE_JSON = true; -})(); - -// Create the Deluge namespace -Deluge = { - - // private - progressTpl: '
' + - '
' + - '
' + - '
' + - '
{0}
' + - '
' + - '
' + - '
' + - '
{0}
' + - '
' + - '
' + - '
', - - - /** - * A method to create a progress bar that can be used by renderers - * to display a bar within a grid or tree. - * @param {Number} progress The bars progress - * @param {Number} width The width of the bar - * @param {String} text The text to display on the bar - * @param {Number} modified Amount to subtract from the width allowing for fixes - */ - progressBar: function(progress, width, text, modifier) { - modifier = Ext.value(modifier, 10); - var progressWidth = ((width / 100.0) * progress).toFixed(0); - var barWidth = progressWidth - 1; - var textWidth = ((progressWidth - modifier) > 0 ? progressWidth - modifier : 0); - return String.format(Deluge.progressTpl, text, width, barWidth, textWidth); - } - -} - -// Setup a space for plugins to insert themselves -deluge.plugins = {}; - -// Hinting for gettext_gen.py -// _('Do Not Download') -// _('Normal Priority') -// _('High Priority') -// _('Highest Priority') -FILE_PRIORITY = { - 9: 'Mixed', - 0: 'Do Not Download', - 1: 'Normal Priority', - 2: 'High Priority', - 5: 'Highest Priority', - 'Mixed': 9, - 'Do Not Download': 0, - 'Normal Priority': 1, - 'High Priority': 2, - 'Highest Priority': 5 -} - -FILE_PRIORITY_CSS = { - 9: 'x-mixed-download', - 0: 'x-no-download', - 1: 'x-normal-download', - 2: 'x-high-download', - 5: 'x-highest-download' -} -/* -Script: - Deluge.Formatters.js - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ +/*! + * Deluge.data.SortTypes.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Deluge.data'); /** - * A collection of functions for string formatting values. - * @class Deluge.Formatters + * Common sort functions that can be used for data Stores. + * * @author Damien Churchill * @version 1.3 + * + * @class Deluge.data.SortTypes * @singleton - */ -Deluge.Formatters = { - /** - * Formats a date string in the locale's date representation based on the - * systems timezone. - * - * @param {Number} timestamp time in seconds since the Epoch - * @return {String} a string in the locale's date representation or "" - * if seconds < 0 - */ - date: function(timestamp) { - function zeroPad(num, count) { - var numZeropad = num + ''; - while (numZeropad.length < count) { - numZeropad = '0' + numZeropad; - } - return numZeropad; - } - timestamp = timestamp * 1000; - var date = new Date(timestamp); - return String.format('{0}/{1}/{2}', zeroPad(date.getDate(), 2), zeroPad(date.getMonth() + 1, 2), date.getFullYear()); + */ +Deluge.data.SortTypes = { + asIPAddress: function(value) { + var d = value.match(/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\:(\d+)/); + return ((((((+d[1])*256)+(+d[2]))*256)+(+d[3]))*256)+(+d[4]); }, - - /** - * Formats the bytes value into a string with KiB, MiB or GiB units. - * - * @param {Number} bytes the filesize in bytes - * @param {Boolean} showZero pass in true to displays 0 values - * @return {String} formatted string with KiB, MiB or GiB units. - */ - size: function(bytes, showZero) { - if (!bytes && !showZero) return ''; - bytes = bytes / 1024.0; - - if (bytes < 1024) { return bytes.toFixed(1) + ' KiB'; } - else { bytes = bytes / 1024; } - - if (bytes < 1024) { return bytes.toFixed(1) + ' MiB'; } - else { bytes = bytes / 1024; } - - return bytes.toFixed(1) + ' GiB' - }, - - /** - * Formats a string to display a transfer speed utilizing {@link #size} - * - * @param {Number} bits the number of bits per second - * @param {Boolean} showZero pass in true to displays 0 values - * @return {String} formatted string with KiB, MiB or GiB units. - */ - speed: function(bits, showZero) { - return (!bits && !showZero) ? '' : fsize(bits, showZero) + '/s'; - }, - - /** - * Formats a string to show time in a human readable form. - * - * @param {Number} time the number of seconds - * @return {String} a formatted time string. will return '' if seconds == 0 - */ - timeRemaining: function(time) { - if (time == 0) { return '∞' } - time = time.toFixed(0); - if (time < 60) { return time + 's'; } - else { time = time / 60; } - - if (time < 60) { - var minutes = Math.floor(time) - var seconds = Math.round(60 * (time - minutes)) - if (seconds > 0) { - return minutes + 'm ' + seconds + 's'; - } else { - return minutes + 'm'; } - } - else { time = time / 60; } - - if (time < 24) { - var hours = Math.floor(time) - var minutes = Math.round(60 * (time - hours)) - if (minutes > 0) { - return hours + 'h ' + minutes + 'm'; - } else { - return hours + 'h'; - } - } - else { time = time / 24; } - - var days = Math.floor(time) - var hours = Math.round(24 * (time - days)) - if (hours > 0) { - return days + 'd ' + hours + 'h'; - } else { - return days + 'd'; - } - }, - - /** - * Simply returns the value untouched, for when no formatting is required. - * - * @param {Mixed} value the value to be displayed - * @return the untouched value. - */ - plain: function(value) { - return value; + + asQueuePosition: function(value) { + return (value > -1) ? value : Number.MAX_VALUE; } } -var fsize = Deluge.Formatters.size; -var fspeed = Deluge.Formatters.speed; -var ftime = Deluge.Formatters.timeRemaining; -var fdate = Deluge.Formatters.date; -var fplain = Deluge.Formatters.plain; -/* -Script: Deluge.Keys.js - The torrent status keys that are commonly used around the UI. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -/** - * @description The torrent status keys that are commonly used around the UI. - * @class Deluge.Keys - * @singleton +/*! + * Deluge.data.PeerRecord.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. */ -Deluge.Keys = { - - /** - * Keys that are used within the torrent grid. - *
['queue', 'name', 'total_size', 'state', 'progress', 'num_seeds',
-	 * 'total_seeds', 'num_peers', 'total_peers', 'download_payload_rate',
-	 * 'upload_payload_rate', 'eta', 'ratio', 'distributed_copies',
-	 * 'is_auto_managed', 'time_added', 'tracker_host']
- */ - Grid: [ - 'queue', 'name', 'total_size', 'state', 'progress', 'num_seeds', - 'total_seeds', 'num_peers', 'total_peers', 'download_payload_rate', - 'upload_payload_rate', 'eta', 'ratio', 'distributed_copies', - 'is_auto_managed', 'time_added', 'tracker_host' - ], - - /** - * Keys used in the status tab of the statistics panel. - * These get updated to include the keys in {@link #Grid}. - *
['total_done', 'total_payload_download', 'total_uploaded',
-	 * 'total_payload_upload', 'next_announce', 'tracker_status', 'num_pieces',
-	 * 'piece_length', 'is_auto_managed', 'active_time', 'seeding_time',
-	 * 'seed_rank']
- */ - Status: [ - 'total_done', 'total_payload_download', 'total_uploaded', - 'total_payload_upload', 'next_announce', 'tracker_status', 'num_pieces', - 'piece_length', 'is_auto_managed', 'active_time', 'seeding_time', - 'seed_rank' - ], - - /** - * Keys used in the files tab of the statistics panel. - *
['files', 'file_progress', 'file_priorities']
- */ - Files: [ - 'files', 'file_progress', 'file_priorities' - ], - - /** - * Keys used in the peers tab of the statistics panel. - *
['peers']
- */ - Peers: [ - 'peers' - ], - - /** - * Keys used in the details tab of the statistics panel. - */ - Details: [ - 'name', 'save_path', 'total_size', 'num_files', 'tracker_status', - 'tracker', 'comment' - ], - - /** - * Keys used in the options tab of the statistics panel. - *
['max_download_speed', 'max_upload_speed', 'max_connections', 'max_upload_slots',
-	 *  'is_auto_managed', 'stop_at_ratio', 'stop_ratio', 'remove_at_ratio', 'private',
-	 *  'prioritize_first_last']
- */ - Options: [ - 'max_download_speed', 'max_upload_speed', 'max_connections', - 'max_upload_slots','is_auto_managed', 'stop_at_ratio', 'stop_ratio', - 'remove_at_ratio', 'private', 'prioritize_first_last' - ] -}; - -// Merge the grid and status keys together as the status keys contain all the -// grid ones. -Ext.each(Deluge.Keys.Grid, function(key) { - Deluge.Keys.Status.push(key); -}); -/* -Script: deluge.menus.js - Contains all the menus contained within the UI for easy access and editing. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. - -*/ - -deluge.menus = { - onTorrentAction: function(item, e) { - var selection = deluge.torrents.getSelections(); - var ids = []; - Ext.each(selection, function(record) { - ids.push(record.id); - }); - var action = item.initialConfig.torrentAction; - - switch (action) { - case 'pause': - case 'resume': - deluge.client.core[action + '_torrent'](ids, { - success: function() { - deluge.ui.update(); - } - }); - break; - case 'top': - case 'up': - case 'down': - case 'bottom': - deluge.client.core['queue_' + action](ids, { - success: function() { - deluge.ui.update(); - } - }); - break; - case 'edit_trackers': - deluge.editTrackers.show(); - break; - case 'update': - deluge.client.core.force_reannounce(ids, { - success: function() { - deluge.ui.update(); - } - }); - break; - case 'remove': - deluge.removeWindow.show(ids); - break; - case 'recheck': - deluge.client.core.force_recheck(ids, { - success: function() { - deluge.ui.update(); - } - }); - break; - case 'move': - deluge.moveStorage.show(ids); - break; - } - } -} - -deluge.menus.torrent = new Ext.menu.Menu({ - id: 'torrentMenu', - items: [{ - torrentAction: 'pause', - text: _('Pause'), - iconCls: 'icon-pause', - handler: deluge.menus.onTorrentAction, - scope: deluge.menus - }, { - torrentAction: 'resume', - text: _('Resume'), - iconCls: 'icon-resume', - handler: deluge.menus.onTorrentAction, - scope: deluge.menus - }, '-', { - text: _('Options'), - iconCls: 'icon-options', - menu: new Ext.menu.Menu({ - items: [{ - text: _('D/L Speed Limit'), - iconCls: 'x-deluge-downloading', - menu: new Ext.menu.Menu({ - items: [{ - text: _('5 KiB/s') - }, { - text: _('10 KiB/s') - }, { - text: _('30 KiB/s') - }, { - text: _('80 KiB/s') - }, { - text: _('300 KiB/s') - },{ - text: _('Unlimited') - }] - }) - }, { - text: _('U/L Speed Limit'), - iconCls: 'x-deluge-seeding', - menu: new Ext.menu.Menu({ - items: [{ - text: _('5 KiB/s') - }, { - text: _('10 KiB/s') - }, { - text: _('30 KiB/s') - }, { - text: _('80 KiB/s') - }, { - text: _('300 KiB/s') - },{ - text: _('Unlimited') - }] - }) - }, { - text: _('Connection Limit'), - iconCls: 'x-deluge-connections', - menu: new Ext.menu.Menu({ - items: [{ - text: _('50') - }, { - text: _('100') - }, { - text: _('200') - }, { - text: _('300') - }, { - text: _('500') - },{ - text: _('Unlimited') - }] - }) - }, { - text: _('Upload Slot Limit'), - iconCls: 'icon-upload-slots', - menu: new Ext.menu.Menu({ - items: [{ - text: _('0') - }, { - text: _('1') - }, { - text: _('2') - }, { - text: _('3') - }, { - text: _('5') - },{ - text: _('Unlimited') - }] - }) - }, { - id: 'auto_managed', - text: _('Auto Managed'), - checked: false - }] - }) - }, '-', { - text: _('Queue'), - iconCls: 'icon-queue', - menu: new Ext.menu.Menu({ - items: [{ - torrentAction: 'top', - text: _('Top'), - iconCls: 'icon-top', - handler: deluge.menus.onTorrentAction, - scope: deluge.menus - },{ - torrentAction: 'up', - text: _('Up'), - iconCls: 'icon-up', - handler: deluge.menus.onTorrentAction, - scope: deluge.menus - },{ - torrentAction: 'down', - text: _('Down'), - iconCls: 'icon-down', - handler: deluge.menus.onTorrentAction, - scope: deluge.menus - },{ - torrentAction: 'bottom', - text: _('Bottom'), - iconCls: 'icon-bottom', - handler: deluge.menus.onTorrentAction, - scope: deluge.menus - }] - }) - }, '-', { - torrentAction: 'update', - text: _('Update Tracker'), - iconCls: 'icon-update-tracker', - handler: deluge.menus.onTorrentAction, - scope: deluge.menus - }, { - torrentAction: 'edit_trackers', - text: _('Edit Trackers'), - iconCls: 'icon-edit-trackers', - handler: deluge.menus.onTorrentAction, - scope: deluge.menus - }, '-', { - torrentAction: 'remove', - text: _('Remove Torrent'), - iconCls: 'icon-remove', - handler: deluge.menus.onTorrentAction, - scope: deluge.menus - }, '-', { - torrentAction: 'recheck', - text: _('Force Recheck'), - iconCls: 'icon-recheck', - handler: deluge.menus.onTorrentAction, - scope: deluge.menus - }, { - torrentAction: 'move', - text: _('Move Storage'), - iconCls: 'icon-move', - handler: deluge.menus.onTorrentAction, - scope: deluge.menus - }] -}); - -Deluge.StatusbarMenu = Ext.extend(Ext.menu.Menu, { - - setValue: function(value) { - var beenSet = false; - // set the new value - value = (value == 0) ? -1 : value; - - // uncheck all items - this.items.each(function(item) { - if (item.setChecked) { - item.suspendEvents(); - if (item.value == value) { - item.setChecked(true); - beenSet = true; - } else { - item.setChecked(false); - } - item.resumeEvents(); - } - }); - - if (beenSet) return; - - var item = this.items.get('other'); - item.suspendEvents(); - item.setChecked(true); - item.resumeEvents(); - } -}); - -deluge.menus.connections = new Deluge.StatusbarMenu({ - id: 'connectionsMenu', - items: [{ - text: '50', - value: '50', - group: 'max_connections_global', - checked: false, - checkHandler: onLimitChanged - },{ - text: '100', - value: '100', - group: 'max_connections_global', - checked: false, - checkHandler: onLimitChanged - },{ - text: '200', - value: '200', - group: 'max_connections_global', - checked: false, - checkHandler: onLimitChanged - },{ - text: '300', - value: '300', - group: 'max_connections_global', - checked: false, - checkHandler: onLimitChanged - },{ - text: '500', - value: '500', - group: 'max_connections_global', - checked: false, - checkHandler: onLimitChanged - },{ - text: _('Unlimited'), - value: '-1', - group: 'max_connections_global', - checked: false, - checkHandler: onLimitChanged - },'-',{ - text: _('Other'), - value: 'other', - group: 'max_connections_global', - checked: false, - checkHandler: onLimitChanged - }] -}); - -deluge.menus.download = new Deluge.StatusbarMenu({ - id: 'downspeedMenu', - items: [{ - value: '5', - text: '5 KiB/s', - group: 'max_download_speed', - checked: false, - checkHandler: onLimitChanged - },{ - value: '10', - text: '10 KiB/s', - group: 'max_download_speed', - checked: false, - checkHandler: onLimitChanged - },{ - value: '30', - text: '30 KiB/s', - group: 'max_download_speed', - checked: false, - checkHandler: onLimitChanged - },{ - value: '80', - text: '80 KiB/s', - group: 'max_download_speed', - checked: false, - checkHandler: onLimitChanged - },{ - value: '300', - text: '300 KiB/s', - group: 'max_download_speed', - checked: false, - checkHandler: onLimitChanged - },{ - value: '-1', - text: _('Unlimited'), - group: 'max_download_speed', - checked: false, - checkHandler: onLimitChanged - },'-',{ - value: 'other', - text: _('Other'), - group: 'max_download_speed', - checked: false, - checkHandler: onLimitChanged - }] -}); - -deluge.menus.upload = new Deluge.StatusbarMenu({ - id: 'upspeedMenu', - items: [{ - value: '5', - text: '5 KiB/s', - group: 'max_upload_speed', - checked: false, - checkHandler: onLimitChanged - },{ - value: '10', - text: '10 KiB/s', - group: 'max_upload_speed', - checked: false, - checkHandler: onLimitChanged - },{ - value: '30', - text: '30 KiB/s', - group: 'max_upload_speed', - checked: false, - checkHandler: onLimitChanged - },{ - value: '80', - text: '80 KiB/s', - group: 'max_upload_speed', - checked: false, - checkHandler: onLimitChanged - },{ - value: '300', - text: '300 KiB/s', - group: 'max_upload_speed', - checked: false, - checkHandler: onLimitChanged - },{ - value: '-1', - text: _('Unlimited'), - group: 'max_upload_speed', - checked: false, - checkHandler: onLimitChanged - },'-',{ - value: 'other', - text: _('Other'), - group: 'max_upload_speed', - checked: false, - checkHandler: onLimitChanged - }] -}); - -deluge.menus.filePriorities = new Ext.menu.Menu({ - id: 'filePrioritiesMenu', - items: [{ - id: 'expandAll', - text: _('Expand All'), - iconCls: 'icon-expand-all' - }, '-', { - id: 'no_download', - text: _('Do Not Download'), - iconCls: 'icon-do-not-download', - filePriority: 0 - }, { - id: 'normal', - text: _('Normal Priority'), - iconCls: 'icon-normal', - filePriority: 1 - }, { - id: 'high', - text: _('High Priority'), - iconCls: 'icon-high', - filePriority: 2 - }, { - id: 'highest', - text: _('Highest Priority'), - iconCls: 'icon-highest', - filePriority: 5 - }] -}); - -function onLimitChanged(item, checked) { - if (item.value == "other") { - } else { - config = {} - config[item.group] = item.value - deluge.client.core.set_config(config, { - success: function() { - deluge.ui.update(); - } - }); - } -} -/* -Script: Deluge.EventsManager.js - Class for holding global events that occur within the UI. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ +Ext.namespace('Deluge.data'); /** - * @class Deluge.EventsManager - * @extends Ext.util.Observable - *

Deluge.EventsManager is instantated as deluge.events and can be used by components of the UI to fire global events

- * Class for holding global events that occur within the UI. - */ -Deluge.EventsManager = Ext.extend(Ext.util.Observable, { - constructor: function() { - this.toRegister = []; - this.on('login', this.onLogin, this); - Deluge.EventsManager.superclass.constructor.call(this); - }, - - /** - * Append an event handler to this object. - */ - addListener: function(eventName, fn, scope, o) { - this.addEvents(eventName); - if (/[A-Z]/.test(eventName.substring(0, 1))) { - if (!deluge.client) { - this.toRegister.push(eventName); - } else { - deluge.client.web.register_event_listener(eventName); - } - } - Deluge.EventsManager.superclass.addListener.call(this, eventName, fn, scope, o); - }, - - getEvents: function() { - deluge.client.web.get_events({ - success: this.onGetEventsSuccess, - failure: this.onGetEventsFailure, - scope: this - }); - }, - - /** - * Starts the EventsManagerManager checking for events. - */ - start: function() { - Ext.each(this.toRegister, function(eventName) { - deluge.client.web.register_event_listener(eventName); - }); - this.running = true; - this.getEvents(); - }, - - /** - * Stops the EventsManagerManager checking for events. - */ - stop: function() { - this.running = false; - }, - - // private - onLogin: function() { - this.start(); - this.on('PluginEnabledEvent', this.onPluginEnabled, this); - this.on('PluginDisabledEvent', this.onPluginDisabled, this); - }, - - onGetEventsSuccess: function(events) { - if (!events) return; - Ext.each(events, function(event) { - var name = event[0], args = event[1]; - args.splice(0, 0, name); - this.fireEvent.apply(this, args); - }, this); - if (this.running) this.getEvents(); - }, - - // private - onGetEventsFailure: function(events) { - // the request timed out so we just want to open up another - // one. - if (this.running) this.getEvents(); - } -}); - -/** - * Appends an event handler to this object (shorthand for {@link #addListener}) - * @method - */ -Deluge.EventsManager.prototype.on = Deluge.EventsManager.prototype.addListener - -/** - * Fires the specified event with the passed parameters (minus the - * event name). - * @method - */ -Deluge.EventsManager.prototype.fire = Deluge.EventsManager.prototype.fireEvent -deluge.events = new Deluge.EventsManager(); -/* -Script: - Deluge.OptionsManager.js - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -Ext.namespace('Deluge'); - -/** - * @class Deluge.OptionsManager - * @extends Ext.util.Observable - * A class that can be used to manage options throughout the ui. + * Deluge.data.Peer record + * + * @author Damien Churchill + * @version 1.3 + * + * @class Deluge.data.Peer + * @extends Ext.data.Record * @constructor - * Creates a new OptionsManager - * @param {Object} config Configuration options + * @param {Object} data The peer data */ -Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { - - constructor: function(config) { - config = config || {}; - this.binds = {}; - this.changed = {}; - this.options = (config && config['options']) || {}; - this.focused = null; - - this.addEvents({ - /** - * @event add - * Fires when an option is added - */ - 'add': true, - - /** - * @event changed - * Fires when an option is changed - * @param {String} option The changed option - * @param {Mixed} value The options new value - * @param {Mixed} oldValue The options old value - */ - 'changed': true, - - /** - * @event reset - * Fires when the options are reset - */ - 'reset': true - }); - this.on('changed', this.onChange, this); - - Deluge.OptionsManager.superclass.constructor.call(this); - }, - - /** - * Add a set of default options and values to the options manager - * @param {Object} options The default options. - */ - addOptions: function(options) { - this.options = Ext.applyIf(this.options, options); - }, - - /** - * Binds a form field to the specified option. - * @param {String} option - * @param {Ext.form.Field} field - */ - bind: function(option, field) { - this.binds[option] = this.binds[option] || []; - this.binds[option].push(field); - field._doption = option; - - field.on('focus', this.onFieldFocus, this); - field.on('blur', this.onFieldBlur, this); - field.on('change', this.onFieldChange, this); - field.on('check', this.onFieldChange, this); - return field; - }, - - /** - * Changes all the changed values to be the default values - */ - commit: function() { - this.options = Ext.apply(this.options, this.changed); - this.reset(); - }, - - /** - * Converts the value so it matches the originals type - * @param {Mixed} oldValue The original value - * @param {Mixed} value The new value to convert - */ - convertValueType: function(oldValue, value) { - if (Ext.type(oldValue) != Ext.type(value)) { - switch (Ext.type(oldValue)) { - case 'string': - value = String(value); - break; - case 'number': - value = Number(value); - break; - case 'boolean': - if (Ext.type(value) == 'string') { - value = value.toLowerCase(); - value = (value == 'true' || value == '1' || value == 'on') ? true : false; - } else { - value = Boolean(value); - } - break; - } - } - return value; - }, - - /** - * Get the value for an option or options. - * @param {String} [option] A single option or an array of options to return. - * @returns {Object} the options value. - */ - get: function() { - if (arguments.length == 1) { - var option = arguments[0]; - return (this.isDirty(option)) ? this.changed[option] : this.options[option]; - } else { - var options = {}; - Ext.each(arguments, function(option) { - if (!this.has(option)) return; - options[option] = (this.isDirty(option)) ? this.changed[option] : this.options[option]; - }, this); - return options; - } - }, - - /** - * Get the default value for an option or options. - * @param {String|Array} [option] A single option or an array of options to return. - * @returns {Object} the value of the option - */ - getDefault: function(option) { - return this.options[option]; - }, - - /** - * Returns the dirty (changed) values. - * @returns {Object} the changed options - */ - getDirty: function() { - return this.changed; - }, - - /** - * @param {String} [option] The option to check - * @returns {Boolean} true if the option has been changed from the default. - */ - isDirty: function(option) { - return !Ext.isEmpty(this.changed[option]); - }, - - /** - * Check to see if an option exists in the options manager - * @param {String} option - * @returns {Boolean} true if the option exists, else false. - */ - has: function(option) { - return (this.options[option]); - }, - - /** - * Reset the options back to the default values. - */ - reset: function() { - this.changed = {}; - }, - - /** - * Sets the value of specified option(s) for the passed in id. - * @param {String} option - * @param {Object} value The value for the option - */ - set: function(option, value) { - if (option === undefined) { - return; - } else if (typeof option == 'object') { - var options = option; - this.options = Ext.apply(this.options, options); - for (var option in options) { - this.onChange(option, options[option]); - } - } else { - this.options[option] = value; - this.onChange(option, value) - } - }, - - /** - * Update the value for the specified option and id. - * @param {String/Object} option or options to update - * @param {Object} [value]; - */ - update: function(option, value) { - if (option === undefined) { - return; - } else if (value === undefined) { - for (var key in option) { - this.update(key, option[key]); - } - } else { - var defaultValue = this.getDefault(option); - value = this.convertValueType(defaultValue, value); - - var oldValue = this.get(option); - if (oldValue == value) return; - - if (defaultValue == value) { - if (this.isDirty(option)) delete this.changed[option]; - this.fireEvent('changed', option, value, oldValue); - return; - } - - this.changed[option] = value; - this.fireEvent('changed', option, value, oldValue); - } - }, - - /** - * Lets the option manager know when a field is blurred so if a value - * so value changing operations can continue on that field. - */ - onFieldBlur: function(field, event) { - if (this.focused == field) { - this.focused = null; - } - }, - - /** - * Stops a form fields value from being blocked by the change functions - * @param {Ext.form.Field} field - * @private - */ - onFieldChange: function(field, event) { - this.update(field._doption, field.getValue()); - }, - - /** - * Lets the option manager know when a field is focused so if a value - * changing operation is performed it won't change the value of the - * field. - */ - onFieldFocus: function(field, event) { - this.focused = field; - }, - - onChange: function(option, newValue, oldValue) { - // If we don't have a bind there's nothing to do. - if (Ext.isEmpty(this.binds[option])) return; - Ext.each(this.binds[option], function(bind) { - // The field is currently focused so we don't want to - // change it. - if (bind == this.focused) return; - // Set the form field to the new value. - bind.setValue(newValue); - }, this); +Deluge.data.Peer = Ext.data.Record.create([ + { + name: 'country', + type: 'string' + }, { + name: 'ip', + type: 'string', + sortType: Deluge.data.SortTypes.asIPAddress + }, { + name: 'client', + type: 'string' + }, { + name: 'progress', + type: 'float' + }, { + name: 'down_speed', + type: 'int' + }, { + name: 'up_speed', + type: 'int' + }, { + name: 'seed', + type: 'int' } -}); -/* -Script: - Deluge.MultiOptionsManager.js - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ +]); +/*! + * Deluge.data.TorrentRecord.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Deluge.data'); /** - * @description A class that can be used to manage options throughout the ui. - * @namespace Deluge - * @class Deluge.MultiOptionsManager - * @extends Deluge.OptionsManager + * Deluge.data.Torrent record + * + * @author Damien Churchill + * @version 1.3 + * + * @class Deluge.data.Torrent + * @extends Ext.data.Record + * @constructor + * @param {Object} data The torrents data */ -Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { - - constructor: function(config) { - this.currentId = null; - this.stored = {}; - Deluge.MultiOptionsManager.superclass.constructor.call(this, config); - }, - - /** - * Changes bound fields to use the specified id. - * @param {String} id - */ - changeId: function(id, dontUpdateBinds) { - var oldId = this.currentId; - this.currentId = id; - if (!dontUpdateBinds) { - for (var option in this.options) { - if (!this.binds[option]) continue; - Ext.each(this.binds[option], function(bind) { - bind.setValue(this.get(option)); - }, this); - } - } - return oldId; - }, - - /** - * Changes all the changed values to be the default values - * @param {String} id - */ - commit: function() { - this.stored[this.currentId] = Ext.apply(this.stored[this.currentId], this.changed[this.currentId]); - this.reset(); - }, - - /** - * Get the value for an option - * @param {String/Array} option A single option or an array of options to return. - * @returns {Object} the options value. - */ - get: function() { - if (arguments.length == 1) { - var option = arguments[0]; - return (this.isDirty(option)) ? this.changed[this.currentId][option] : this.getDefault(option); - } else if (arguments.length == 0) { - var options = {}; - for (var option in this.options) { - options[option] = (this.isDirty(option)) ? this.changed[this.currentId][option] : this.getDefault(option); - } - return options; - } else { - var options = {}; - Ext.each(arguments, function(option) { - options[option] = (this.isDirty(option)) ? this.changed[this.currentId][option] : this.getDefault(option); - }, this); - return options; - } - }, - - /** - * Get the default value for an option. - * @param {String} option A single option. - * @returns {Object} the value of the option - */ - getDefault: function(option) { - return (this.has(option)) ? this.stored[this.currentId][option] : this.options[option]; - }, - - /** - * Returns the dirty (changed) values. - * @returns {Object} the changed options - */ - getDirty: function() { - return (this.changed[this.currentId]) ? this.changed[this.currentId] : {}; - }, - - /** - * Check to see if the option has been changed. - * @param {String} option - * @returns {Boolean} true if the option has been changed, else false. - */ - isDirty: function(option) { - return (this.changed[this.currentId] && !Ext.isEmpty(this.changed[this.currentId][option])); - }, - - /** - * Check to see if an id has had an option set to something other than the - * default value. - * @param {String} option - * @returns {Boolean} true if the id has an option, else false. - */ - has: function(option) { - return (this.stored[this.currentId] && !Ext.isEmpty(this.stored[this.currentId][option])); - }, - - /** - * Reset the options back to the default values for the specified id. - */ - reset: function() { - if (this.changed[this.currentId]) delete this.changed[this.currentId]; - if (this.stored[this.currentId]) delete this.stored[this.currentId]; - }, - - /** - * Reset the options back to their defaults for all ids. - */ - resetAll: function() { - this.changed = {}; - this.stored = {}; - this.changeId(null); - }, - - /** - * Sets the value of specified option for the passed in id. - * @param {String} id - * @param {String} option - * @param {Object} value The value for the option - */ - setDefault: function(option, value) { - if (option === undefined) { - return; - } else if (value === undefined) { - for (var key in option) { - this.setDefault(key, option[key]); - } - } else { - var oldValue = this.getDefault(option); - value = this.convertValueType(oldValue, value); - - // If the value is the same as the old value there is - // no point in setting it again. - if (oldValue == value) return; - - // Store the new default - if (!this.stored[this.currentId]) this.stored[this.currentId] = {}; - this.stored[this.currentId][option] = value; - - if (!this.isDirty(option)) { - this.fireEvent('changed', this.currentId, option, value, oldValue); - } - } - }, - - /** - * Update the value for the specified option and id. - * @param {String} id - * @param {String/Object} option or options to update - * @param {Object} [value]; - */ - update: function(option, value) { - if (option === undefined) { - return; - } else if (value === undefined) { - for (var key in option) { - this.update(key, option[key]); - } - } else { - if (!this.changed[this.currentId]) this.changed[this.currentId] = {}; - - var defaultValue = this.getDefault(option); - value = this.convertValueType(defaultValue, value); - - var oldValue = this.get(option); - if (oldValue == value) return; - - if (defaultValue == value) { - if (this.isDirty(option)) delete this.changed[this.currentId][option]; - this.fireEvent('changed', this.currentId, option, value, oldValue); - return; - } else { - this.changed[this.currentId][option] = value; - this.fireEvent('changed', this.currentId, option, value, oldValue); - } - } - }, - - // Event Handlers - /** - * Stops a form fields value from being blocked by the change functions - * @param {Ext.form.Field} field - * @private - */ - onFieldChange: function(field, event) { - this.update(field._doption, field.getValue()); - }, - - /** - * Handles updating binds when an option's value is changed. - * @param {String} id The current option id - * @param {String} option The option that has changed. - * @param {Mixed} newValue The new value - * @private - */ - onChange: function(id, option, newValue, oldValue) { - // If we don't have a bind there's nothing to do. - if (Ext.isEmpty(this.binds[option])) return; - Ext.each(this.binds[option], function(bind) { - // The field is currently focused so we don't want to - // change it. - if (bind == this.focused) return; - // Set the form field to the new value. - bind.setValue(newValue); - }, this); +Deluge.data.Torrent = Ext.data.Record.create([{ + name: 'queue', + type: 'int' + }, { + name: 'name', + type: 'string' + }, { + name: 'total_size', + type: 'int' + }, { + name: 'state', + type: 'string' + }, { + name: 'progress', + type: 'int' + }, { + name: 'num_seeds', + type: 'int' + }, { + name: 'total_seeds', + type: 'int' + }, { + name: 'num_peers', + type: 'int' + }, { + name: 'total_peers', + type: 'int' + }, { + name: 'download_payload_rate', + type: 'int' + }, { + name: 'upload_payload_rate', + type: 'int' + }, { + name: 'eta', + type: 'int' + }, { + name: 'ratio', + type: 'float' + }, { + name: 'distributed_copies', + type: 'float' + }, { + name: 'time_added', + type: 'int' + }, { + name: 'tracker_host', + type: 'string' } -}); -/* -Script: Deluge.Add.js - Contains the Add Torrent window. +]); +/*! + * Deluge.details.DetailsPanel.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Deluge.details'); -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. - -*/ - -Ext.namespace('Deluge.add'); -Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, { - - torrents: {}, - - constructor: function(config) { - config = Ext.apply({ - region: 'south', - margins: '5 5 5 5', - activeTab: 0, - height: 220 - }, config); - Deluge.add.OptionsPanel.superclass.constructor.call(this, config); - }, - - initComponent: function() { - Deluge.add.OptionsPanel.superclass.initComponent.call(this); - this.files = this.add(new Ext.ux.tree.TreeGrid({ - layout: 'fit', - title: _('Files'), - rootVisible: false, - autoScroll: true, - height: 170, - border: false, - animate: false, - disabled: true, - - columns: [{ - header: _('Filename'), - width: 275, - dataIndex: 'filename' - },{ - xtype: 'tgrendercolumn', - header: _('Size'), - width: 80, - dataIndex: 'size', - renderer: fsize - }] - })); - new Ext.tree.TreeSorter(this.files, { - folderSort: true - }); - - this.optionsManager = new Deluge.MultiOptionsManager(); - - this.form = this.add({ - xtype: 'form', - labelWidth: 1, - title: _('Options'), - bodyStyle: 'padding: 5px;', - border: false, - height: 170, - disabled: true - }); - - var fieldset = this.form.add({ - xtype: 'fieldset', - title: _('Download Location'), - border: false, - autoHeight: true, - defaultType: 'textfield', - labelWidth: 1, - fieldLabel: '' - }); - this.optionsManager.bind('download_location', fieldset.add({ - fieldLabel: '', - name: 'download_location', - width: 400, - labelSeparator: '' - })); - - var panel = this.form.add({ - border: false, - layout: 'column', - defaultType: 'fieldset' - }); - fieldset = panel.add({ - title: _('Allocation'), - border: false, - autoHeight: true, - defaultType: 'radio', - width: 100 - }); - - this.optionsManager.bind('compact_allocation', fieldset.add({ - xtype: 'radiogroup', - columns: 1, - vertical: true, - labelSeparator: '', - items: [{ - name: 'compact_allocation', - value: false, - inputValue: false, - boxLabel: _('Full'), - fieldLabel: '', - labelSeparator: '' - }, { - name: 'compact_allocation', - value: true, - inputValue: true, - boxLabel: _('Compact'), - fieldLabel: '', - labelSeparator: '', - }] - })); - - fieldset = panel.add({ - title: _('Bandwidth'), - border: false, - autoHeight: true, - labelWidth: 100, - width: 200, - defaultType: 'spinnerfield' - }); - this.optionsManager.bind('max_download_speed', fieldset.add({ - fieldLabel: _('Max Down Speed'), - /*labelStyle: 'margin-left: 10px',*/ - name: 'max_download_speed', - width: 60 - })); - this.optionsManager.bind('max_upload_speed', fieldset.add({ - fieldLabel: _('Max Up Speed'), - /*labelStyle: 'margin-left: 10px',*/ - name: 'max_upload_speed', - width: 60 - })); - this.optionsManager.bind('max_connections', fieldset.add({ - fieldLabel: _('Max Connections'), - /*labelStyle: 'margin-left: 10px',*/ - name: 'max_connections', - width: 60 - })); - this.optionsManager.bind('max_upload_slots', fieldset.add({ - fieldLabel: _('Max Upload Slots'), - /*labelStyle: 'margin-left: 10px',*/ - name: 'max_upload_slots', - width: 60 - })); - - fieldset = panel.add({ - title: _('General'), - border: false, - autoHeight: true, - defaultType: 'checkbox' - }); - this.optionsManager.bind('add_paused', fieldset.add({ - name: 'add_paused', - boxLabel: _('Add In Paused State'), - fieldLabel: '', - labelSeparator: '', - })); - this.optionsManager.bind('prioritize_first_last_pieces', fieldset.add({ - name: 'prioritize_first_last_pieces', - boxLabel: _('Prioritize First/Last Pieces'), - fieldLabel: '', - labelSeparator: '', - })); - - this.form.on('render', this.onFormRender, this); - }, - - onFormRender: function(form) { - form.layout = new Ext.layout.FormLayout(); - form.layout.setContainer(form); - form.doLayout(); - }, - - addTorrent: function(torrent) { - this.torrents[torrent['info_hash']] = torrent; - var fileIndexes = {}; - this.walkFileTree(torrent['files_tree'], function(filename, type, entry, parent) { - if (type != 'file') return; - fileIndexes[entry[0]] = entry[2]; - }, this); - - var priorities = []; - Ext.each(Ext.keys(fileIndexes), function(index) { - priorities[index] = fileIndexes[index]; - }); - - var oldId = this.optionsManager.changeId(torrent['info_hash'], true); - this.optionsManager.setDefault('file_priorities', priorities); - this.optionsManager.changeId(oldId, true); - }, - - clear: function() { - this.clearFiles(); - this.optionsManager.resetAll(); - }, - - clearFiles: function() { - var root = this.files.getRootNode(); - if (!root.hasChildNodes()) return; - root.cascade(function(node) { - if (!node.parentNode || !node.getOwnerTree()) return; - node.remove(); - }); - }, - - getDefaults: function() { - var keys = ['add_paused','compact_allocation','download_location', - 'max_connections_per_torrent','max_download_speed_per_torrent', - 'max_upload_slots_per_torrent','max_upload_speed_per_torrent', - 'prioritize_first_last_pieces']; - - deluge.client.core.get_config_values(keys, { - success: function(config) { - var options = { - 'file_priorities': [], - 'add_paused': config.add_paused, - 'compact_allocation': config.compact_allocation, - 'download_location': config.download_location, - 'max_connections': config.max_connections_per_torrent, - 'max_download_speed': config.max_download_speed_per_torrent, - 'max_upload_slots': config.max_upload_slots_per_torrent, - 'max_upload_speed': config.max_upload_speed_per_torrent, - 'prioritize_first_last_pieces': config.prioritize_first_last_pieces - } - this.optionsManager.options = options; - this.optionsManager.resetAll(); - }, - scope: this - }); - }, - - getFilename: function(torrentId) { - return this.torrents[torrentId]['filename']; - }, - - getOptions: function(torrentId) { - var oldId = this.optionsManager.changeId(torrentId, true); - var options = this.optionsManager.get(); - this.optionsManager.changeId(oldId, true); - Ext.each(options['file_priorities'], function(priority, index) { - options['file_priorities'][index] = (priority) ? 1 : 0; - }); - return options; - }, - - setTorrent: function(torrentId) { - if (!torrentId) return; - - this.torrentId = torrentId; - this.optionsManager.changeId(torrentId); - - this.clearFiles(); - var root = this.files.getRootNode(); - var priorities = this.optionsManager.get('file_priorities'); - - this.walkFileTree(this.torrents[torrentId]['files_tree'], function(filename, type, entry, parent) { - if (type == 'dir') { - var folder = new Ext.tree.TreeNode({ - text: filename, - checked: true - }); - folder.on('checkchange', this.onFolderCheck, this); - parent.appendChild(folder); - return folder; - } else { - var node = new Ext.tree.TreeNode({ - filename: filename, - fileindex: entry[0], - text: filename, // this needs to be here for sorting reasons - size: fsize(entry[1]), - leaf: true, - checked: priorities[entry[0]], - iconCls: 'x-deluge-file', - uiProvider: Ext.tree.ColumnNodeUI - }); - node.on('checkchange', this.onNodeCheck, this); - parent.appendChild(node); - } - }, this, root); - root.firstChild.expand(); - }, - - walkFileTree: function(files, callback, scope, parent) { - for (var filename in files) { - var entry = files[filename]; - var type = (Ext.type(entry) == 'object') ? 'dir' : 'file'; - - if (scope) { - var ret = callback.apply(scope, [filename, type, entry, parent]); - } else { - var ret = callback(filename, type, entry, parent); - } - - if (type == 'dir') this.walkFileTree(entry, callback, scope, ret); - } - }, - - onFolderCheck: function(node, checked) { - var priorities = this.optionsManager.get('file_priorities'); - node.cascade(function(child) { - if (!child.ui.checkbox) { - child.attributes.checked = checked; - } else { - child.ui.checkbox.checked = checked; - } - priorities[child.attributes.fileindex] = checked; - }, this); - this.optionsManager.setDefault('file_priorities', priorities); - }, - - onNodeCheck: function(node, checked) { - var priorities = this.optionsManager.get('file_priorities'); - priorities[node.attributes.fileindex] = checked; - this.optionsManager.update('file_priorities', priorities); - } -}); - -Deluge.add.Window = Ext.extend(Ext.Window, { - initComponent: function() { - Deluge.add.Window.superclass.initComponent.call(this); - this.addEvents( - 'beforeadd', - 'add' - ); - }, - - createTorrentId: function() { - return new Date().getTime(); - } -}); - -Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { - - constructor: function(config) { - config = Ext.apply({ - title: _('Add Torrents'), - layout: 'border', - width: 470, - height: 450, - bodyStyle: 'padding: 10px 5px;', - buttonAlign: 'right', - closeAction: 'hide', - closable: true, - plain: true, - iconCls: 'x-deluge-add-window-icon' - }, config); - Deluge.add.AddWindow.superclass.constructor.call(this, config); - }, - - initComponent: function() { - Deluge.add.AddWindow.superclass.initComponent.call(this); - - this.addButton(_('Cancel'), this.onCancelClick, this); - this.addButton(_('Add'), this.onAddClick, this); - - function torrentRenderer(value, p, r) { - if (r.data['info_hash']) { - return String.format('
{0}
', value); - } else { - return String.format('
{0}
', value); - } - } - - this.grid = this.add({ - xtype: 'grid', - region: 'center', - store: new Ext.data.SimpleStore({ - fields: [ - {name: 'info_hash', mapping: 1}, - {name: 'text', mapping: 2} - ], - id: 0 - }), - columns: [{ - id: 'torrent', - width: 150, - sortable: true, - renderer: torrentRenderer, - dataIndex: 'text' - }], - stripeRows: true, - selModel: new Ext.grid.RowSelectionModel({ - singleSelect: true, - listeners: { - 'rowselect': { - fn: this.onSelect, - scope: this - } - } - }), - hideHeaders: true, - autoExpandColumn: 'torrent', - deferredRender: false, - autoScroll: true, - margins: '5 5 5 5', - bbar: new Ext.Toolbar({ - items: [{ - iconCls: 'x-deluge-add-file', - text: _('File'), - handler: this.onFile, - scope: this - }, { - text: _('Url'), - iconCls: 'icon-add-url', - handler: this.onUrl, - scope: this - }, { - text: _('Infohash'), - iconCls: 'icon-add-magnet', - disabled: true - }, '->', { - text: _('Remove'), - iconCls: 'icon-remove', - handler: this.onRemove, - scope: this - }] - }) - }); - - this.optionsPanel = this.add(new Deluge.add.OptionsPanel()); - this.on('hide', this.onHide, this); - this.on('show', this.onShow, this); - }, - - clear: function() { - this.grid.getStore().removeAll(); - this.optionsPanel.clear(); - }, - - onAddClick: function() { - var torrents = []; - if (!this.grid) return; - this.grid.getStore().each(function(r) { - var id = r.get('info_hash'); - torrents.push({ - path: this.optionsPanel.getFilename(id), - options: this.optionsPanel.getOptions(id) - }); - }, this); - - deluge.client.web.add_torrents(torrents, { - success: function(result) { - } - }) - this.clear(); - this.hide(); - }, - - onCancelClick: function() { - this.clear(); - this.hide(); - }, - - onFile: function() { - this.file.show(); - }, - - onHide: function() { - this.optionsPanel.setActiveTab(0); - this.optionsPanel.files.setDisabled(true); - this.optionsPanel.form.setDisabled(true); - }, - - onRemove: function() { - var selection = this.grid.getSelectionModel(); - if (!selection.hasSelection()) return; - var torrent = selection.getSelected(); - this.grid.getStore().remove(torrent); - this.optionsPanel.clear(); - - if (this.torrents && this.torrents[torrent.id]) delete this.torrents[torrent.id]; - }, - - onSelect: function(selModel, rowIndex, record) { - this.optionsPanel.setTorrent(record.get('info_hash')); - this.optionsPanel.files.setDisabled(false); - this.optionsPanel.form.setDisabled(false); - }, - - onShow: function() { - if (!this.url) { - this.url = new Deluge.add.UrlWindow(); - this.url.on('beforeadd', this.onTorrentBeforeAdd, this); - this.url.on('add', this.onTorrentAdd, this); - } - - if (!this.file) { - this.file = new Deluge.add.FileWindow(); - this.file.on('beforeadd', this.onTorrentBeforeAdd, this); - this.file.on('add', this.onTorrentAdd, this); - } - - this.optionsPanel.getDefaults(); - }, - - onTorrentBeforeAdd: function(torrentId, text) { - var store = this.grid.getStore(); - store.loadData([[torrentId, null, text]], true); - }, - - onTorrentAdd: function(torrentId, info) { - var r = this.grid.getStore().getById(torrentId); - if (!info) { - Ext.MessageBox.show({ - title: _('Error'), - msg: _('Not a valid torrent'), - buttons: Ext.MessageBox.OK, - modal: false, - icon: Ext.MessageBox.ERROR, - iconCls: 'x-deluge-icon-error' - }); - this.grid.getStore().remove(r); - } else { - r.set('info_hash', info['info_hash']); - r.set('text', info['name']); - this.grid.getStore().commitChanges(); - this.optionsPanel.addTorrent(info); - } - }, - - onUrl: function(button, event) { - this.url.show(); - } -}); -deluge.add = new Deluge.add.AddWindow(); -/* -Script: Deluge.Add.File.js - Contains the Add Torrent by file window. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. - -*/ - -Ext.namespace('Ext.deluge.add'); -Deluge.add.FileWindow = Ext.extend(Deluge.add.Window, { - constructor: function(config) { - config = Ext.apply({ - layout: 'fit', - width: 350, - height: 115, - bodyStyle: 'padding: 10px 5px;', - buttonAlign: 'center', - closeAction: 'hide', - modal: true, - plain: true, - title: _('Add from File'), - iconCls: 'x-deluge-add-file' - }, config); - Deluge.add.FileWindow.superclass.constructor.call(this, config); - }, - - initComponent: function() { - Deluge.add.FileWindow.superclass.initComponent.call(this); - this.addButton(_('Add'), this.onAddClick, this); - - this.form = this.add({ - xtype: 'form', - baseCls: 'x-plain', - labelWidth: 35, - autoHeight: true, - fileUpload: true, - items: [{ - xtype: 'fileuploadfield', - id: 'torrentFile', - width: 280, - emptyText: _('Select a torrent'), - fieldLabel: _('File'), - name: 'file', - buttonCfg: { - text: _('Browse') + '...' - } - }] - }); - }, - - onAddClick: function(field, e) { - if (this.form.getForm().isValid()) { - this.torrentId = this.createTorrentId(); - this.form.getForm().submit({ - url: '/upload', - waitMsg: _('Uploading your torrent...'), - failure: this.onUploadFailure, - success: this.onUploadSuccess, - scope: this - }); - var name = this.form.getForm().findField('torrentFile').value; - name = name.split('\\').slice(-1)[0]; - this.fireEvent('beforeadd', this.torrentId, name); - } - }, - - onGotInfo: function(info, obj, response, request) { - info['filename'] = request.options.filename; - this.fireEvent('add', this.torrentId, info); - }, - - onUploadFailure: function(form, action) { - this.hide(); - }, - - onUploadSuccess: function(fp, upload) { - this.hide(); - if (upload.result.success) { - var filename = upload.result.files[0]; - this.form.getForm().findField('torrentFile').setValue(''); - Deluge.Client.web.get_torrent_info(filename, { - success: this.onGotInfo, - scope: this, - filename: filename - }); - } - } -}); -/* -Script: Deluge.Add.Url.js - Contains the Add Torrent by url window. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. - -*/ - -Ext.namespace('Deluge.add'); -Deluge.add.UrlWindow = Ext.extend(Deluge.add.Window, { - constructor: function(config) { - config = Ext.apply({ - layout: 'fit', - width: 350, - height: 155, - bodyStyle: 'padding: 10px 5px;', - buttonAlign: 'center', - closeAction: 'hide', - modal: true, - plain: true, - title: _('Add from Url'), - iconCls: 'x-deluge-add-url-window-icon' - }, config); - Deluge.add.UrlWindow.superclass.constructor.call(this, config); - }, - - initComponent: function() { - Deluge.add.UrlWindow.superclass.initComponent.call(this); - this.addButton(_('Add'), this.onAddClick, this); - - var form = this.add({ - xtype: 'form', - defaultType: 'textfield', - baseCls: 'x-plain', - labelWidth: 55 - }); - - this.urlField = form.add({ - fieldLabel: _('Url'), - id: 'url', - name: 'url', - anchor: '100%' - }); - this.urlField.on('specialkey', this.onAdd, this); - - this.cookieField = form.add({ - fieldLabel: _('Cookies'), - id: 'cookies', - name: 'cookies', - anchor: '100%' - }); - this.cookieField.on('specialkey', this.onAdd, this); - }, - - onAddClick: function(field, e) { - if ((field.id == 'url' || field.id == 'cookies') && e.getKey() != e.ENTER) return; - - var field = this.urlField; - var url = field.getValue(); - var cookies = this.cookieField.getValue(); - var torrentId = this.createTorrentId(); - - deluge.client.web.download_torrent_from_url(url, cookies, { - success: this.onDownload, - scope: this, - torrentId: torrentId - }); - this.hide(); - this.fireEvent('beforeadd', torrentId, url); - }, - - onDownload: function(filename, obj, resp, req) { - this.urlField.setValue(''); - deluge.client.web.get_torrent_info(filename, { - success: this.onGotInfo, - scope: this, - filename: filename, - torrentId: req.options.torrentId - }); - }, - - onGotInfo: function(info, obj, response, request) { - info['filename'] = request.options.filename; - this.fireEvent('add', request.options.torrentId, info); - } -}); -/* -Script: Deluge.Client.js - A JSON-RPC proxy built on top of ext-core. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -Ext.namespace('Ext.ux.util'); /** - * A class that connects to a json-rpc resource and adds the available - * methods as functions to the class instance. - * @class Ext.ux.util.RpcClient - * @namespace Ext.ux.util + * @class Deluge.details.DetailsPanel */ -Ext.ux.util.RpcClient = Ext.extend(Ext.util.Observable, { +Deluge.details.DetailsPanel = Ext.extend(Ext.TabPanel, { - _components: [], + region: 'south', + id: 'torrentDetails', + split: true, + height: 210, + minSize: 100, + collapsible: true, + margins: '0 5 5 5', + activeTab: 0, - _methods: [], - - _requests: {}, - - _url: null, - - _optionKeys: ['scope', 'success', 'failure'], - - constructor: function(config) { - Ext.ux.util.RpcClient.superclass.constructor.call(this, config); - this._url = config.url || null; - this._id = 0; - - this.addEvents( - // raw events - /** - * @event connected - * Fires when the client has retrieved the list of methods from the server. - * @param {Ext.ux.util.RpcClient} this - */ - 'connected', - - 'error' - ); - this.reloadMethods(); + initComponent: function() { + Deluge.details.DetailsPanel.superclass.initComponent.call(this); + this.add(new Deluge.details.StatusTab()); + this.add(new Deluge.details.DetailsTab()); + this.add(new Deluge.details.FilesTab()); + this.add(new Deluge.details.PeersTab()); + this.add(new Deluge.details.OptionsTab()); }, - reloadMethods: function() { - Ext.each(this._components, function(component) { - delete this[component]; - }, this); - this._execute('system.listMethods', { - success: this._setMethods, - scope: this - }); - }, - - _execute: function(method, options) { - options = options || {}; - options.params = options.params || []; - options.id = this._id; - - var request = Ext.encode({ - method: method, - params: options.params, - id: options.id - }); - this._id++; - - return Ext.Ajax.request({ - url: this._url, - method: 'POST', - success: this._onSuccess, - failure: this._onFailure, - scope: this, - jsonData: request, - options: options + clear: function() { + this.items.each(function(panel) { + if (panel.clear) { + panel.clear.defer(100, panel); + panel.disable(); + } }); }, - _onFailure: function(response, requestOptions) { - var options = requestOptions.options; - errorObj = { - id: options.id, - result: null, - error: { - msg: 'HTTP: ' + response.status + ' ' + response.statusText, - code: 255 - } + + update: function(tab) { + var torrent = deluge.torrents.getSelected(); + if (!torrent) { + this.clear(); + return; } - this.fireEvent('error', errorObj, response, requestOptions) - - if (Ext.type(options.failure) != 'function') return; - if (options.scope) { - options.failure.call(options.scope, errorObj, response, requestOptions); - } else { - options.failure(errorObj, response, requestOptions); - } - }, - - _onSuccess: function(response, requestOptions) { - var responseObj = Ext.decode(response.responseText); - var options = requestOptions.options; - if (responseObj.error) { - this.fireEvent('error', responseObj, response, requestOptions); - - if (Ext.type(options.failure) != 'function') return; - if (options.scope) { - options.failure.call(options.scope, responseObj, response, requestOptions); - } else { - options.failure(responseObj, response, requestOptions); - } - } else { - if (Ext.type(options.success) != 'function') return; - if (options.scope) { - options.success.call(options.scope, responseObj.result, responseObj, response, requestOptions); - } else { - options.success(responseObj.result, responseObj, response, requestOptions); - } - } - }, - - _parseArgs: function(args) { - var params = []; - Ext.each(args, function(arg) { - params.push(arg); + this.items.each(function(tab) { + if (tab.disabled) tab.enable(); }); - var options = params[params.length - 1]; - if (Ext.type(options) == 'object') { - var keys = Ext.keys(options), isOption = false; - - Ext.each(this._optionKeys, function(key) { - if (keys.indexOf(key) > -1) isOption = true; - }); - - if (isOption) { - params.remove(options) - } else { - options = {} - } - } else { - options = {} - } - options.params = params; - return options; + tab = tab || this.getActiveTab(); + if (tab.update) tab.update(torrent.id); }, - - _setMethods: function(methods) { - var components = {}, self = this; - - Ext.each(methods, function(method) { - var parts = method.split('.'); - var component = components[parts[0]] || {}; - - var fn = function() { - var options = self._parseArgs(arguments); - return self._execute(method, options); - } - component[parts[1]] = fn; - components[parts[0]] = component; - }); - - for (var name in components) { - self[name] = components[name]; - } - - this._components = Ext.keys(components); - this.fireEvent('connected', this); - } -}); -/* -Script: Deluge.ConnectionManager.js - Contains all objects and functions related to the connection manager. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. - -*/ - -(function() { - var hostRenderer = function(value, p, r) { - return value + ':' + r.data['port'] - } - - Deluge.AddConnectionWindow = Ext.extend(Ext.Window, { - - constructor: function(config) { - config = Ext.apply({ - layout: 'fit', - width: 300, - height: 195, - bodyStyle: 'padding: 10px 5px;', - buttonAlign: 'right', - closeAction: 'hide', - closable: true, - plain: true, - title: _('Add Connection'), - iconCls: 'x-deluge-add-window-icon' - }, config); - Deluge.AddConnectionWindow.superclass.constructor.call(this, config); - }, - initComponent: function() { - Deluge.AddConnectionWindow.superclass.initComponent.call(this); - - this.addEvents('hostadded'); - - this.addButton(_('Close'), this.hide, this); - this.addButton(_('Add'), this.onAddClick, this); - - this.on('hide', this.onHide, this); - - this.form = this.add({ - xtype: 'form', - defaultType: 'textfield', - id: 'connectionAddForm', - baseCls: 'x-plain', - labelWidth: 55 - }); - - this.hostField = this.form.add({ - fieldLabel: _('Host'), - id: 'host', - name: 'host', - anchor: '100%', - value: '' - }); - - this.portField = this.form.add({ - fieldLabel: _('Port'), - id: 'port', - xtype: 'spinnerfield', - name: 'port', - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 65535 - }, - value: '58846', - anchor: '50%' - }); - - this.usernameField = this.form.add({ - fieldLabel: _('Username'), - id: 'username', - name: 'username', - anchor: '100%', - value: '' - }); - - this.passwordField = this.form.add({ - fieldLabel: _('Password'), - anchor: '100%', - id: '_password', - name: '_password', - inputType: 'password', - value: '' - }); - }, - - onAddClick: function() { - var host = this.hostField.getValue(); - var port = this.portField.getValue(); - var username = this.usernameField.getValue(); - var password = this.passwordField.getValue(); - - deluge.client.web.add_host(host, port, username, password, { - success: function(result) { - if (!result[0]) { - Ext.MessageBox.show({ - title: _('Error'), - msg: "Unable to add host: " + result[1], - buttons: Ext.MessageBox.OK, - modal: false, - icon: Ext.MessageBox.ERROR, - iconCls: 'x-deluge-icon-error' - }); - } else { - this.fireEvent('hostadded'); - } - this.hide(); - }, - scope: this - }); - }, - - onHide: function() { - this.form.getForm().reset(); - } - }); - - Deluge.ConnectionManager = Ext.extend(Ext.Window, { - - layout: 'fit', - width: 300, - height: 220, - bodyStyle: 'padding: 10px 5px;', - buttonAlign: 'right', - closeAction: 'hide', - closable: true, - plain: true, - title: _('Connection Manager'), - iconCls: 'x-deluge-connect-window-icon', - - initComponent: function() { - Deluge.ConnectionManager.superclass.initComponent.call(this); - this.on('hide', this.onHide, this); - this.on('show', this.onShow, this); - - deluge.events.on('disconnect', this.onDisconnect, this); - deluge.events.on('login', this.onLogin, this); - deluge.events.on('logout', this.onLogout, this); - - this.addButton(_('Close'), this.onClose, this); - this.addButton(_('Connect'), this.onConnect, this); - - this.grid = this.add({ - xtype: 'grid', - store: new Ext.data.SimpleStore({ - fields: [ - {name: 'status', mapping: 3}, - {name: 'host', mapping: 1}, - {name: 'port', mapping: 2}, - {name: 'version', mapping: 4} - ], - id: 0 - }), - columns: [{ - header: _('Status'), - width: 65, - sortable: true, - renderer: fplain, - dataIndex: 'status' - }, { - id:'host', - header: _('Host'), - width: 150, - sortable: true, - renderer: hostRenderer, - dataIndex: 'host' - }, { - header: _('Version'), - width: 75, - sortable: true, - renderer: fplain, - dataIndex: 'version' - }], - stripeRows: true, - selModel: new Ext.grid.RowSelectionModel({ - singleSelect: true, - listeners: { - 'rowselect': {fn: this.onSelect, scope: this}, - 'selectionchange': {fn: this.onSelectionChanged, scope: this} - } - }), - autoExpandColumn: 'host', - deferredRender:false, - autoScroll:true, - margins: '0 0 0 0', - bbar: new Ext.Toolbar({ - buttons: [ - { - id: 'cm-add', - cls: 'x-btn-text-icon', - text: _('Add'), - iconCls: 'icon-add', - handler: this.onAddClick, - scope: this - }, { - id: 'cm-remove', - cls: 'x-btn-text-icon', - text: _('Remove'), - iconCls: 'icon-remove', - handler: this.onRemove, - disabled: true, - scope: this - }, '->', { - id: 'cm-stop', - cls: 'x-btn-text-icon', - text: _('Stop Daemon'), - iconCls: 'icon-error', - handler: this.onStop, - disabled: true, - scope: this - } - ] - }) - }); - - this.update = this.update.createDelegate(this); - }, - - /** - * Check to see if the the web interface is currently connected - * to a Deluge Daemon and show the Connection Manager if not. - */ - checkConnected: function() { - deluge.client.web.connected({ - success: function(connected) { - if (connected) { - deluge.events.fire('connect'); - } else { - this.show(); - } - }, - scope: this - }); - }, - - disconnect: function() { - deluge.events.fire('disconnect'); - }, - - loadHosts: function() { - deluge.client.web.get_hosts({ - success: this.onGetHosts, - scope: this - }); - }, - - update: function() { - this.grid.getStore().each(function(r) { - deluge.client.web.get_host_status(r.id, { - success: this.onGetHostStatus, - scope: this - }); - }, this); - }, - - /** - * Updates the buttons in the Connection Manager UI according to the - * passed in records host state. - * @param {Ext.data.Record} record The hosts record to update the UI for - */ - updateButtons: function(record) { - var button = this.buttons[1], status = record.get('status'); - - // Update the Connect/Disconnect button - if (status == _('Connected')) { - button.enable(); - button.setText(_('Disconnect')); - } else if (status == _('Offline')) { - button.disable(); - } else { - button.enable(); - button.setText(_('Connect')); - } - - // Update the Stop/Start Daemon button - if (status == _('Offline')) { - if (record.get('host') == '127.0.0.1' || record.get('host') == 'localhost') { - this.stopHostButton.enable(); - this.stopHostButton.setText(_('Start Daemon')); - } else { - this.stopHostButton.disable(); - } - } else { - this.stopHostButton.enable(); - this.stopHostButton.setText(_('Stop Daemon')); - } - }, - - onAddClick: function(button, e) { - if (!this.addWindow) { - this.addWindow = new Deluge.AddConnectionWindow(); - this.addWindow.on('hostadded', this.onHostAdded, this); - } - this.addWindow.show(); - }, - - onHostAdded: function() { - this.loadHosts(); - }, - - // private - onClose: function(e) { - if (this.running) window.clearInterval(this.running); - this.hide(); - }, - - // private - onConnect: function(e) { - var selected = this.grid.getSelectionModel().getSelected(); - if (!selected) return; - - if (selected.get('status') == _('Connected')) { - deluge.client.web.disconnect({ - success: function(result) { - this.update(this); - Deluge.Events.fire('disconnect'); - }, - scope: this - }); - } else { - var id = selected.id; - deluge.client.web.connect(id, { - success: function(methods) { - deluge.client.reloadMethods(); - deluge.client.on('connected', function(e) { - deluge.events.fire('connect'); - }, this, {single: true}); - } - }); - this.hide(); - } - }, - - onDisconnect: function() { - if (this.isVisible()) return; - this.show(); - }, - - // private - onGetHosts: function(hosts) { - this.grid.getStore().loadData(hosts); - Ext.each(hosts, function(host) { - deluge.client.web.get_host_status(host[0], { - success: this.onGetHostStatus, - scope: this - }); - }, this); - }, - - // private - onGetHostStatus: function(host) { - var record = this.grid.getStore().getById(host[0]); - record.set('status', host[3]) - record.set('version', host[4]) - record.commit(); - if (this.grid.getSelectionModel().getSelected() == record) this.updateButtons(record); - }, - - // private - onHide: function() { - if (this.running) window.clearInterval(this.running); - }, - - // private - onLogin: function() { - if (deluge.config.first_login) { - Ext.MessageBox.confirm('Change password', - 'As this is your first login, we recommend that you ' + - 'change your password. Would you like to ' + - 'do this now?', function(res) { - this.checkConnected(); - if (res == 'yes') { - deluge.preferences.show(); - deluge.preferences.selectPage('Interface'); - } - deluge.client.web.set_config({first_login: false}); - }, this); - } else { - this.checkConnected(); - } - }, - - // private - onLogout: function() { - this.disconnect(); - if (!this.hidden && this.rendered) { - this.hide(); - } - }, - - // private - onRemove: function(button) { - var connection = this.grid.getSelectionModel().getSelected(); - if (!connection) return; - - deluge.client.web.remove_host(connection.id, { - success: function(result) { - if (!result) { - Ext.MessageBox.show({ - title: _('Error'), - msg: result[1], - buttons: Ext.MessageBox.OK, - modal: false, - icon: Ext.MessageBox.ERROR, - iconCls: 'x-deluge-icon-error' - }); - } else { - this.grid.getStore().remove(connection); - } - }, - scope: this - }); - }, - - // private - onSelect: function(selModel, rowIndex, record) { - this.selectedRow = rowIndex; - }, - - // private - onSelectionChanged: function(selModel) { - var record = selModel.getSelected(); - if (selModel.hasSelection()) { - this.removeHostButton.enable(); - this.stopHostButton.enable(); - this.stopHostButton.setText(_('Stop Daemon')); - } else { - this.removeHostButton.disable(); - this.stopHostButton.disable(); - } - this.updateButtons(record); - }, - - // private - onShow: function() { - if (!this.addHostButton) { - var bbar = this.grid.getBottomToolbar(); - this.addHostButton = bbar.items.get('cm-add'); - this.removeHostButton = bbar.items.get('cm-remove'); - this.stopHostButton = bbar.items.get('cm-stop'); - } - this.loadHosts(); - this.running = window.setInterval(this.update, 2000, this); - }, - - // private - onStop: function(button, e) { - var connection = this.grid.getSelectionModel().getSelected(); - if (!connection) return; - - if (connection.get('status') == 'Offline') { - // This means we need to start the daemon - deluge.client.web.start_daemon(connection.get('port')); - } else { - // This means we need to stop the daemon - deluge.client.web.stop_daemon(connection.id, { - success: function(result) { - if (!result[0]) { - Ext.MessageBox.show({ - title: _('Error'), - msg: result[1], - buttons: Ext.MessageBox.OK, - modal: false, - icon: Ext.MessageBox.ERROR, - iconCls: 'x-deluge-icon-error' - }); - } - } - }); - } - } - }); - deluge.connectionManager = new Deluge.ConnectionManager(); -})(); -/* -Script: Deluge.Details.js - Contains all objects and functions related to the lower details panel and - it's containing tabs. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -(function() { - Ext.namespace('Deluge.details'); - Deluge.details.TabPanel = Ext.extend(Ext.TabPanel, { - - constructor: function(config) { - config = Ext.apply({ - region: 'south', - id: 'torrentDetails', - split: true, - height: 220, - minSize: 100, - collapsible: true, - margins: '0 5 5 5', - activeTab: 0 - }, config); - Deluge.details.TabPanel.superclass.constructor.call(this, config); - }, - - clear: function() { - this.items.each(function(panel) { - if (panel.clear) { - panel.clear.defer(100, panel); - panel.disable(); - } - }); - }, - - - update: function(tab) { - var torrent = deluge.torrents.getSelected(); - if (!torrent) { - this.clear(); - return; - } - - this.items.each(function(tab) { - if (tab.disabled) tab.enable(); - }); - - tab = tab || this.getActiveTab(); - if (tab.update) tab.update(torrent.id); - }, - - /* Event Handlers */ - - // We need to add the events in onRender since Deluge.Torrents hasn't - // been created yet. - onRender: function(ct, position) { - Deluge.details.TabPanel.superclass.onRender.call(this, ct, position); - deluge.events.on('disconnect', this.clear, this); - deluge.torrents.on('rowclick', this.onTorrentsClick, this); - this.on('tabchange', this.onTabChange, this); - - deluge.torrents.getSelectionModel().on('selectionchange', function(selModel) { - if (!selModel.hasSelection()) this.clear(); - }, this); - }, - - onTabChange: function(panel, tab) { - this.update(tab); - }, - - onTorrentsClick: function(grid, rowIndex, e) { - this.update(); - } - }); - deluge.details = new Deluge.details.TabPanel(); -})(); -/* -Script: Deluge.Details.Status.js - The status tab displayed in the details panel. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -Deluge.details.StatusTab = Ext.extend(Ext.Panel, { - title: _('Status'), - autoScroll: true, + /* Event Handlers */ + // We need to add the events in onRender since Deluge.Torrents hasn't + // been created yet. onRender: function(ct, position) { - Deluge.details.StatusTab.superclass.onRender.call(this, ct, position); + Deluge.details.DetailsPanel.superclass.onRender.call(this, ct, position); + deluge.events.on('disconnect', this.clear, this); + deluge.torrents.on('rowclick', this.onTorrentsClick, this); + this.on('tabchange', this.onTabChange, this); - this.progressBar = this.add({ - xtype: 'progress', - cls: 'x-deluge-status-progressbar' - }); - - this.status = this.add({ - cls: 'x-deluge-status', - id: 'deluge-details-status', - - border: false, - width: 1000, - listeners: { - 'render': { - fn: function(panel) { - panel.load({ - url: deluge.config.base + 'render/tab_status.html', - text: _('Loading') + '...' - }); - panel.getUpdater().on('update', this.onPanelUpdate, this); - }, - scope: this - } - } - }); - }, - - clear: function() { - this.progressBar.updateProgress(0, ' '); - for (var k in this.fields) { - this.fields[k].innerHTML = ''; - } - }, - - update: function(torrentId) { - if (!this.fields) this.getFields(); - deluge.client.core.get_torrent_status(torrentId, Deluge.Keys.Status, { - success: this.onRequestComplete, - scope: this - }); - }, - - onPanelUpdate: function(el, response) { - this.fields = {}; - Ext.each(Ext.query('dd', this.status.body.dom), function(field) { - this.fields[field.className] = field; + deluge.torrents.getSelectionModel().on('selectionchange', function(selModel) { + if (!selModel.hasSelection()) this.clear(); }, this); }, - onRequestComplete: function(status) { - seeders = status.total_seeds > -1 ? status.num_seeds + ' (' + status.total_seeds + ')' : status.num_seeds - peers = status.total_peers > -1 ? status.num_peers + ' (' + status.total_peers + ')' : status.num_peers - var data = { - downloaded: fsize(status.total_done), - uploaded: fsize(status.total_uploaded), - share: status.ratio.toFixed(3), - announce: ftime(status.next_announce), - tracker_status: status.tracker_status, - downspeed: (status.download_payload_rate) ? fspeed(status.download_payload_rate) : '0.0 KiB/s', - upspeed: (status.upload_payload_rate) ? fspeed(status.upload_payload_rate) : '0.0 KiB/s', - eta: ftime(status.eta), - pieces: status.num_pieces + ' (' + fsize(status.piece_length) + ')', - seeders: seeders, - peers: peers, - avail: status.distributed_copies.toFixed(3), - active_time: ftime(status.active_time), - seeding_time: ftime(status.seeding_time), - seed_rank: status.seed_rank, - time_added: fdate(status.time_added) - } - data.auto_managed = _((status.is_auto_managed) ? 'True' : 'False'); - - data.downloaded += ' (' + ((status.total_payload_download) ? fsize(status.total_payload_download) : '0.0 KiB') + ')'; - data.uploaded += ' (' + ((status.total_payload_download) ? fsize(status.total_payload_download): '0.0 KiB') + ')'; - - for (var field in this.fields) { - this.fields[field].innerHTML = data[field]; - } - var text = status.state + ' ' + status.progress.toFixed(2) + '%'; - this.progressBar.updateProgress(status.progress / 100.0, text); + onTabChange: function(panel, tab) { + this.update(tab); + }, + + onTorrentsClick: function(grid, rowIndex, e) { + this.update(); } }); -deluge.details.add(new Deluge.details.StatusTab()); /* Script: Deluge.Details.Details.js The details tab displayed in the details panel. @@ -3320,10 +401,11 @@ Deluge.details.DetailsTab = Ext.extend(Ext.Panel, { for (var k in this.fields) { this.fields[k].dom.innerHTML = ''; } + this.oldData = {} }, update: function(torrentId) { - deluge.client.core.get_torrent_status(torrentId, Deluge.Keys.Details, { + deluge.client.web.get_torrent_status(torrentId, Deluge.Keys.Details, { success: this.onRequestComplete, scope: this, torrentId: torrentId @@ -3343,405 +425,272 @@ Deluge.details.DetailsTab = Ext.extend(Ext.Panel, { }; for (var field in this.fields) { - if (!data[field]) continue; // this is a field we aren't responsible for. + if (!Ext.isDefined(data[field])) continue; // this is a field we aren't responsible for. if (data[field] == this.oldData[field]) continue; this.fields[field].dom.innerHTML = Ext.escapeHTML(data[field]); } this.oldData = data; } }); -deluge.details.add(new Deluge.details.DetailsTab()); -/* -Script: Deluge.Details.Files.js - The files tab displayed in the details panel. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ -(function() { - /* Renderers for the column tree */ - function fileProgressRenderer(value) { - var progress = value * 100; - return Deluge.progressBar(progress, this.col.width, progress.toFixed(2) + '%', 0); - } - function priorityRenderer(value) { - if (isNaN(value)) return ''; - return String.format('
{1}
', FILE_PRIORITY_CSS[value], _(FILE_PRIORITY[value])); - } +/*! + * Deluge.details.FilesTab.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ - Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { - - constructor: function(config) { - config = Ext.apply({ - title: _('Files'), - rootVisible: false, - autoScroll: true, - selModel: new Ext.tree.MultiSelectionModel(), - - columns: [{ - header: _('Filename'), - width: 330, - dataIndex: 'filename' - }, { - xtype: 'tgrendercolumn', - header: _('Size'), - width: 150, - dataIndex: 'size', - renderer: fsize - }, { - xtype: 'tgrendercolumn', - header: _('Progress'), - width: 150, - dataIndex: 'progress', - renderer: fileProgressRenderer - }, { - xtype: 'tgrendercolumn', - header: _('Priority'), - width: 150, - dataIndex: 'priority', - renderer: priorityRenderer - }], - - root: new Ext.tree.TreeNode({ - text: 'Files' - }) - }, config); +Deluge.details.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { - Deluge.details.FilesTab.superclass.constructor.call(this, config); - }, + title: _('Files'), - initComponent: function() { - - Deluge.details.FilesTab.superclass.initComponent.call(this); - }, - - onRender: function(ct, position) { - Deluge.details.FilesTab.superclass.onRender.call(this, ct, position); - deluge.menus.filePriorities.on('itemclick', this.onItemClick, this); - this.on('contextmenu', this.onContextMenu, this); - this.sorter = new Ext.tree.TreeSorter(this, { - folderSort: true - }); - }, - - clear: function() { - var root = this.getRootNode(); - if (!root.hasChildNodes()) return; - root.cascade(function(node) { - var parent = node.parentNode; - if (!parent) return; - if (!parent.ownerTree) return; - parent.removeChild(node); - }); - }, - - update: function(torrentId) { - if (this.torrentId != torrentId) { - this.clear(); - this.torrentId = torrentId; + autoScroll: true, + rootVisible: false, + + columns: [{ + header: _('Filename'), + width: 330, + dataIndex: 'filename' + }, { + header: _('Size'), + width: 150, + dataIndex: 'size', + tpl: new Ext.XTemplate('{size:this.fsize}', { + fsize: function(v) { return fsize(v); } + }) + }, { + xtype: 'tgrendercolumn', + header: _('Progress'), + width: 150, + dataIndex: 'progress', + renderer: function(v) { + var progress = v * 100; + return Deluge.progressBar(progress, this.col.width, progress.toFixed(2) + '%', 0); + } + }, { + header: _('Priority'), + width: 150, + dataIndex: 'priority', + tpl: new Ext.XTemplate('' + + '
' + + '{priority:this.getName}' + + '
', { + getClass: function(v) { + return FILE_PRIORITY_CSS[v]; + }, + + getName: function(v) { + return _(FILE_PRIORITY[v]); } - - deluge.client.web.get_torrent_files(torrentId, { - success: this.onRequestComplete, - scope: this, - torrentId: torrentId - }); - }, - - onContextMenu: function(node, e) { - e.stopEvent(); - var selModel = this.getSelectionModel(); - if (selModel.getSelectedNodes().length < 2) { - selModel.clearSelections(); - node.select(); - } - deluge.menus.filePriorities.showAt(e.getPoint()); - }, - - onItemClick: function(baseItem, e) { - switch (baseItem.id) { - case 'expandAll': - this.expandAll(); - break; - default: - var indexes = {}; - function walk(node) { - if (Ext.isEmpty(node.attributes.fileIndex)) return; - indexes[node.attributes.fileIndex] = node.attributes.priority; - } - this.getRootNode().cascade(walk); + }) + }], + + selModel: new Ext.tree.MultiSelectionModel(), - var nodes = this.getSelectionModel().getSelectedNodes(); - Ext.each(nodes, function(node) { - if (!node.isLeaf()) { - function setPriorities(node) { - if (Ext.isEmpty(node.attributes.fileIndex)) return; - indexes[node.attributes.fileIndex] = baseItem.filePriority; - } - node.cascade(setPriorities); - } else if (!Ext.isEmpty(node.attributes.fileIndex)) { - indexes[node.attributes.fileIndex] = baseItem.filePriority; - return; - } - }); - - var priorities = new Array(Ext.keys(indexes).length); - for (var index in indexes) { - priorities[index] = indexes[index]; - } + initComponent: function() { + Deluge.details.FilesTab.superclass.initComponent.call(this); + this.setRootNode(new Ext.tree.TreeNode({text: 'Files'})); + }, - deluge.client.core.set_torrent_file_priorities(this.torrentId, priorities, { - success: function() { - Ext.each(nodes, function(node) { - node.setColumnValue(3, baseItem.filePriority); - }); - }, - scope: this - }); - break; - } - }, - - onRequestComplete: function(files, options) { - function walk(files, parent) { - for (var file in files.contents) { - var item = files.contents[file]; - var child = parent.findChild('id', file); - if (item.type == 'dir') { - if (!child) { - child = new Ext.tree.TreeNode({ - id: file, - text: file, - filename: file, - size: item['size'], - progress: item['progress'], - priority: item['priority'] - }); - parent.appendChild(child); - } - walk(item, child); - } else { - if (!child) { - child = new Ext.tree.TreeNode({ - id: file, - filename: file, - text: file, // this needs to be here for sorting - fileIndex: item['index'], - size: item['size'], - progress: item['progress'], - priority: item['priority'], - leaf: true, - iconCls: 'x-deluge-file', - uiProvider: Ext.ux.tree.TreeGridNodeUI - }); - parent.appendChild(child); - } - } + clear: function() { + var root = this.getRootNode(); + if (!root.hasChildNodes()) return; + root.cascade(function(node) { + var parentNode = node.parentNode; + if (!parentNode) return; + if (!parentNode.ownerTree) return; + parentNode.removeChild(node); + }); + }, + + createFileTree: function(files) { + function walk(files, parentNode) { + for (var file in files.contents) { + var item = files.contents[file]; + if (item.type == 'dir') { + walk(item, parentNode.appendChild(new Ext.tree.TreeNode({ + text: file, + filename: file, + size: item.size, + progress: item.progress, + priority: item.priority + }))); + } else { + parentNode.appendChild(new Ext.tree.TreeNode({ + text: file, + filename: file, + fileIndex: item.index, + size: item.size, + progress: item.progress, + priority: item.priority, + leaf: true, + iconCls: 'x-deluge-file', + uiProvider: Ext.ux.tree.TreeGridNodeUI + })); } } - var root = this.getRootNode(); - walk(files, root); - root.firstChild.expand(); } - }); - deluge.details.add(new Deluge.details.FilesTab()); -})(); -/* -Script: Deluge.Details.Peers.js - The peers tab displayed in the details panel. + var root = this.getRootNode(); + walk(files, root); + root.firstChild.expand(); + }, -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. - -*/ - -(function() { - function flagRenderer(value) { - return String.format('', value); - } - function peerAddressRenderer(value, p, record) { - var seed = (record.data['seed'] == 1024) ? 'x-deluge-seed' : 'x-deluge-peer' - return String.format('
{1}
', seed, value); - } - function peerProgressRenderer(value) { - var progress = (value * 100).toFixed(0); - return Deluge.progressBar(progress, this.width - 8, progress + '%'); - } - function sort_address(value) { - var d = value.match(/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\:(\d+)/); - return ((((((+d[1])*256)+(+d[2]))*256)+(+d[3]))*256)+(+d[4]); - } - - Deluge.details.PeersTab = Ext.extend(Ext.grid.GridPanel, { - - constructor: function(config) { - config = Ext.apply({ - title: _('Peers'), - cls: 'x-deluge-peers', - store: new Ext.data.SimpleStore({ - fields: [ - {name: 'country'}, - {name: 'address', sortType: sort_address}, - {name: 'client'}, - {name: 'progress', type: 'float'}, - {name: 'downspeed', type: 'int'}, - {name: 'upspeed', type: 'int'}, - {name: 'seed', type: 'int'} - ], - id: 0 - }), - columns: [{ - header: ' ', - width: 30, - sortable: true, - renderer: flagRenderer, - dataIndex: 'country' - }, { - header: 'Address', - width: 125, - sortable: true, - renderer: peerAddressRenderer, - dataIndex: 'address' - }, { - header: 'Client', - width: 125, - sortable: true, - renderer: fplain, - dataIndex: 'client' - }, { - header: 'Progress', - width: 150, - sortable: true, - renderer: peerProgressRenderer, - dataIndex: 'progress' - }, { - header: 'Down Speed', - width: 100, - sortable: true, - renderer: fspeed, - dataIndex: 'downspeed' - }, { - header: 'Up Speed', - width: 100, - sortable: true, - renderer: fspeed, - dataIndex: 'upspeed' - }], - stripeRows: true, - deferredRender:false, - autoScroll:true - }, config); - Deluge.details.PeersTab.superclass.constructor.call(this, config); - }, - - onRender: function(ct, position) { - Deluge.details.PeersTab.superclass.onRender.call(this, ct, position); - }, - - clear: function() { - this.getStore().loadData([]); - }, - - update: function(torrentId) { - deluge.client.core.get_torrent_status(torrentId, Deluge.Keys.Peers, { - success: this.onRequestComplete, - scope: this - }); - }, - - onRequestComplete: function(torrent, options) { - if (!torrent) return; - var peers = new Array(); - Ext.each(torrent.peers, function(peer) { - peers.push([peer.country, peer.ip, peer.client, peer.progress, peer.down_speed, peer.up_speed, peer.seed]); - }, this); - this.getStore().loadData(peers); + update: function(torrentId) { + if (this.torrentId != torrentId) { + this.clear(); + this.torrentId = torrentId; } - }); - deluge.details.add(new Deluge.details.PeersTab()); -})(); -/* -Script: Deluge.Details.Options.js - The options tab displayed in the details panel. + + deluge.client.web.get_torrent_files(torrentId, { + success: this.onRequestComplete, + scope: this, + torrentId: torrentId + }); + }, -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. + updateFileTree: function(files) { + function walk(files, parentNode) { + for (var file in files.contents) { + var item = files.contents[file]; + var node = parentNode.findChild('filename', file); + node.attributes.size = item.size; + node.attributes.progress = item.progress; + node.attributes.priority = item.priority; + node.ui.updateColumns(); + if (item.type == 'dir') { + walk(item, node); + } + } + } + walk(files, this.getRootNode()); + }, - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + onRender: function(ct, position) { + Deluge.details.FilesTab.superclass.onRender.call(this, ct, position); + deluge.menus.filePriorities.on('itemclick', this.onItemClick, this); + this.on('contextmenu', this.onContextMenu, this); + this.sorter = new Ext.tree.TreeSorter(this, { + folderSort: true + }); + }, + + onContextMenu: function(node, e) { + e.stopEvent(); + var selModel = this.getSelectionModel(); + if (selModel.getSelectedNodes().length < 2) { + selModel.clearSelections(); + node.select(); + } + deluge.menus.filePriorities.showAt(e.getPoint()); + }, + + onItemClick: function(baseItem, e) { + switch (baseItem.id) { + case 'expandAll': + this.expandAll(); + break; + default: + var indexes = {}; + function walk(node) { + if (Ext.isEmpty(node.attributes.fileIndex)) return; + indexes[node.attributes.fileIndex] = node.attributes.priority; + } + this.getRootNode().cascade(walk); - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. + var nodes = this.getSelectionModel().getSelectedNodes(); + Ext.each(nodes, function(node) { + if (!node.isLeaf()) { + function setPriorities(node) { + if (Ext.isEmpty(node.attributes.fileIndex)) return; + indexes[node.attributes.fileIndex] = baseItem.filePriority; + } + node.cascade(setPriorities); + } else if (!Ext.isEmpty(node.attributes.fileIndex)) { + indexes[node.attributes.fileIndex] = baseItem.filePriority; + return; + } + }); + + var priorities = new Array(Ext.keys(indexes).length); + for (var index in indexes) { + priorities[index] = indexes[index]; + } - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ + deluge.client.core.set_torrent_file_priorities(this.torrentId, priorities, { + success: function() { + Ext.each(nodes, function(node) { + node.setColumnValue(3, baseItem.filePriority); + }); + }, + scope: this + }); + break; + } + }, + + onRequestComplete: function(files, options) { + if (!this.getRootNode().hasChildNodes()) { + this.createFileTree(files); + } else { + this.updateFileTree(files); + } + } +}); +/*! + * Deluge.details.OptionsTab.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { @@ -4081,7 +1030,7 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { this.torrentId = torrentId; this.optionsManager.changeId(torrentId); } - deluge.client.core.get_torrent_status(torrentId, Deluge.Keys.Options, { + deluge.client.web.get_torrent_status(torrentId, Deluge.Keys.Options, { success: this.onRequestComplete, scope: this }); @@ -4126,974 +1075,1652 @@ Deluge.details.OptionsTab = Ext.extend(Ext.form.FormPanel, { this.fields.stop_ratio.setDisabled(!stop_at_ratio); } }); -deluge.details.add(new Deluge.details.OptionsTab()); -/* -Script: Deluge.EditTrackers.js - Contains the edit trackers window. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. - -*/ +/*! + * Deluge.details.PeersTab.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ (function() { - Deluge.AddTracker = Ext.extend(Ext.Window, { + function flagRenderer(value) { + if (!value) return ''; + return String.format('', value); + } + function peerAddressRenderer(value, p, record) { + var seed = (record.data['seed'] == 1024) ? 'x-deluge-seed' : 'x-deluge-peer' + return String.format('
{1}
', seed, value); + } + function peerProgressRenderer(value) { + var progress = (value * 100).toFixed(0); + return Deluge.progressBar(progress, this.width - 8, progress + '%'); + } + + Deluge.details.PeersTab = Ext.extend(Ext.grid.GridPanel, { + + // fast way to figure out if we have a peer already. + peers: {}, + constructor: function(config) { config = Ext.apply({ - title: _('Add Tracker'), - width: 375, - height: 150, - bodyStyle: 'padding: 5px', - layout: 'fit', - buttonAlign: 'right', - closeAction: 'hide', - closable: true, - iconCls: 'x-deluge-edit-trackers', - plain: true, - resizable: false - }, config); - Deluge.AddTracker.superclass.constructor.call(this, config); - }, - - initComponent: function() { - Deluge.AddTracker.superclass.initComponent.call(this); - - this.addButton(_('Cancel'), this.onCancelClick, this); - this.addButton(_('Add'), this.onAddClick, this); - this.addEvents('add'); - - this.form = this.add({ - xtype: 'form', - defaultType: 'textarea', - baseCls: 'x-plain', - labelWidth: 55, - items: [{ - fieldLabel: _('Trackers'), - name: 'trackers', - anchor: '100%' - }] - }) - }, - - onAddClick: function() { - var trackers = this.form.getForm().findField('trackers').getValue(); - trackers = trackers.split('\n'); - - var cleaned = []; - Ext.each(trackers, function(tracker) { - if (Ext.form.VTypes.url(tracker)) { - cleaned.push(tracker); - } - }, this); - this.fireEvent('add', cleaned); - this.hide(); - this.form.getForm().findField('trackers').setValue(''); - }, - - onCancelClick: function() { - this.form.getForm().findField('trackers').setValue(''); - this.hide(); - } - }); - - Deluge.EditTracker = Ext.extend(Ext.Window, { - constructor: function(config) { - config = Ext.apply({ - title: _('Edit Tracker'), - width: 375, - height: 110, - bodyStyle: 'padding: 5px', - layout: 'fit', - buttonAlign: 'right', - closeAction: 'hide', - closable: true, - iconCls: 'x-deluge-edit-trackers', - plain: true, - resizable: false - }, config); - Deluge.EditTracker.superclass.constructor.call(this, config); - }, - - initComponent: function() { - Deluge.EditTracker.superclass.initComponent.call(this); - - this.addButton(_('Cancel'), this.onCancelClick, this); - this.addButton(_('Save'), this.onSaveClick, this); - this.on('hide', this.onHide, this); - - this.form = this.add({ - xtype: 'form', - defaultType: 'textfield', - baseCls: 'x-plain', - labelWidth: 55, - items: [{ - fieldLabel: _('Tracker'), - name: 'tracker', - anchor: '100%' - }] - }); - }, - - show: function(record) { - Deluge.EditTracker.superclass.show.call(this); - - this.record = record; - this.form.getForm().findField('tracker').setValue(record.data['url']); - }, - - onCancelClick: function() { - this.hide(); - }, - - onHide: function() { - this.form.getForm().findField('tracker').setValue(''); - }, - - onSaveClick: function() { - var url = this.form.getForm().findField('tracker').getValue(); - this.record.set('url', url); - this.record.commit(); - this.hide(); - } - }); - - Deluge.EditTrackers = Ext.extend(Ext.Window, { - - constructor: function(config) { - config = Ext.apply({ - title: _('Edit Trackers'), - width: 350, - height: 220, - bodyStyle: 'padding: 5px', - layout: 'fit', - buttonAlign: 'right', - closeAction: 'hide', - closable: true, - iconCls: 'x-deluge-edit-trackers', - plain: true, - resizable: true - }, config); - Deluge.EditTrackers.superclass.constructor.call(this, config); - }, - - initComponent: function() { - Deluge.EditTrackers.superclass.initComponent.call(this); - - this.addButton(_('Cancel'), this.onCancelClick, this); - this.addButton(_('Ok'), this.onOkClick, this); - this.addEvents('save'); - - this.on('show', this.onShow, this); - this.on('save', this.onSave, this); - - this.addWindow = new Deluge.AddTracker(); - this.addWindow.on('add', this.onAddTrackers, this); - this.editWindow = new Deluge.EditTracker(); - - this.grid = this.add({ - xtype: 'grid', - store: new Ext.data.SimpleStore({ - fields: [ - {name: 'tier', mapping: 0}, - {name: 'url', mapping: 1} - ] + title: _('Peers'), + cls: 'x-deluge-peers', + store: new Ext.data.Store({ + reader: new Ext.data.JsonReader({ + idProperty: 'ip', + root: 'peers' + }, Deluge.data.Peer) }), columns: [{ - header: _('Tier'), - width: 50, + header: ' ', + width: 30, sortable: true, - renderer: fplain, - dataIndex: 'tier' + renderer: flagRenderer, + dataIndex: 'country' }, { - id:'tracker', - header: _('Tracker'), + header: 'Address', + width: 125, + sortable: true, + renderer: peerAddressRenderer, + dataIndex: 'ip' + }, { + header: 'Client', + width: 125, sortable: true, renderer: fplain, - dataIndex: 'url' - }], + dataIndex: 'client' + }, { + header: 'Progress', + width: 150, + sortable: true, + renderer: peerProgressRenderer, + dataIndex: 'progress' + }, { + header: 'Down Speed', + width: 100, + sortable: true, + renderer: fspeed, + dataIndex: 'down_speed' + }, { + header: 'Up Speed', + width: 100, + sortable: true, + renderer: fspeed, + dataIndex: 'up_speed' + }], stripeRows: true, - selModel: new Ext.grid.RowSelectionModel({ - singleSelect: true, - listeners: { - 'selectionchange': {fn: this.onSelect, scope: this} - } - }), - autoExpandColumn: 'tracker', deferredRender:false, - autoScroll:true, - margins: '0 0 0 0', - bbar: new Ext.Toolbar({ - items: [ - { - text: _('Up'), - iconCls: 'icon-up', - handler: this.onUpClick, - scope: this - }, { - text: _('Down'), - iconCls: 'icon-down', - handler: this.onDownClick, - scope: this - }, '->', { - text: _('Add'), - iconCls: 'icon-add', - handler: this.onAddClick, - scope: this - }, { - text: _('Edit'), - iconCls: 'icon-edit-trackers', - handler: this.onEditClick, - scope: this - }, { - text: _('Remove'), - iconCls: 'icon-remove', - handler: this.onRemoveClick, - scope: this - } - ] - }) - }); + autoScroll:true + }, config); + Deluge.details.PeersTab.superclass.constructor.call(this, config); }, - onAddClick: function() { - this.addWindow.show(); + clear: function() { + this.getStore().removeAll(); + this.peers = {}; }, - onAddTrackers: function(trackers) { - var store = this.grid.getStore(); - Ext.each(trackers, function(tracker) { - var duplicate = false, heightestTier = -1; - store.each(function(record) { - if (record.get('tier') > heightestTier) { - heightestTier = record.get('tier'); - } - if (tracker == record.get('tracker')) { - duplicate = true; - return false; - } - }, this); - if (!duplicate) { - store.loadData([[heightestTier + 1, tracker]], true); - } - }, this); - }, - - onCancelClick: function() { - this.hide(); - }, - - onEditClick: function() { - var r = this.grid.getSelectionModel().getSelected(); - this.editWindow.show(r); - }, - - onHide: function() { - this.grid.getStore().removeAll(); - }, - - onOkClick: function() { - var trackers = []; - this.grid.getStore().each(function(record) { - trackers.push({ - 'tier': record.get('tier'), - 'url': record.get('url') - }) - }, this); - - deluge.client.core.set_torrent_trackers(this.torrentId, trackers, { - failure: this.onSaveFail, - scope: this - }); - - this.hide(); - }, - - onRemove: function() { - // Remove from the grid - var r = this.grid.getSelectionModel().getSelected(); - this.grid.getStore().remove(r); - }, - - onRequestComplete: function(status) { - var trackers = []; - Ext.each(status['trackers'], function(tracker) { - trackers.push([tracker['tier'], tracker['url']]); - }); - this.grid.getStore().loadData(trackers); - }, - - onSaveFail: function() { - - }, - - onSelect: function(sm) { - if (sm.hasSelection()) { - this.grid.getBottomToolbar().items.get(4).enable(); - } - }, - - onShow: function() { - this.grid.getBottomToolbar().items.get(4).disable(); - var r = deluge.torrents.getSelected(); - this.torrentId = r.id; - deluge.client.core.get_torrent_status(r.id, ['trackers'], { + update: function(torrentId) { + deluge.client.web.get_torrent_status(torrentId, Deluge.Keys.Peers, { success: this.onRequestComplete, scope: this }); + }, + + onRequestComplete: function(torrent, options) { + if (!torrent) return; + + var store = this.getStore(); + var newPeers = []; + var addresses = {}; + + // Go through the peers updating and creating peer records + Ext.each(torrent.peers, function(peer) { + if (this.peers[peer.ip]) { + } else { + this.peers[peer.ip] = 1; + newPeers.push(new Deluge.data.Peer(peer, peer.ip)); + } + addresses[peer.ip] = 1; + }, this); + store.add(newPeers); + + // Remove any peers that shouldn't be left in the store + store.each(function(record) { + if (!addresses[record.id]) { + store.remove(record); + delete this.peers[record.id]; + } + }, this); + store.commitChanges(); + + var sortState = store.getSortState(); + if (!sortState) return; + store.sort(sortState.field, sortState.direction); } }); - deluge.editTrackers = new Deluge.EditTrackers(); })(); -Ext.namespace('Deluge'); -Deluge.FileBrowser = Ext.extend(Ext.Window, { +/*! + * Deluge.details.StatusTab.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge.details'); - title: _('File Browser'), - - width: 500, - height: 400, - - initComponent: function() { - Deluge.FileBrowser.superclass.initComponent.call(this); - - this.add({ - xtype: 'toolbar', - items: [{ - text: _('Back'), - iconCls: 'icon-back' - }, { - text: _('Forward'), - iconCls: 'icon-forward' - }, { - text: _('Up'), - iconCls: 'icon-up' - }, { - text: _('Home'), - iconCls: 'icon-home' - }] - }); - } - -}); -/* -Script: Deluge.Login.js - Contains all objects and functions related to the login system. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. - -*/ - -Deluge.LoginWindow = Ext.extend(Ext.Window, { +/** + * @class Deluge.details.StatusTab + * @extends Ext.Panel + */ +Deluge.details.StatusTab = Ext.extend(Ext.Panel, { + title: _('Status'), + autoScroll: true, - firstShow: true, - bodyStyle: 'padding: 10px 5px;', - buttonAlign: 'center', - closable: false, - closeAction: 'hide', - iconCls: 'x-deluge-login-window-icon', - layout: 'fit', - modal: true, - plain: true, - resizable: false, - title: _('Login'), - width: 300, - height: 120, - - initComponent: function() { - Deluge.LoginWindow.superclass.initComponent.call(this); - this.on('show', this.onShow, this); + onRender: function(ct, position) { + Deluge.details.StatusTab.superclass.onRender.call(this, ct, position); - this.addButton({ - text: _('Login'), - handler: this.onLogin, + this.progressBar = this.add({ + xtype: 'progress', + cls: 'x-deluge-status-progressbar' + }); + + this.status = this.add({ + cls: 'x-deluge-status', + id: 'deluge-details-status', + + border: false, + width: 1000, + listeners: { + 'render': { + fn: function(panel) { + panel.load({ + url: deluge.config.base + 'render/tab_status.html', + text: _('Loading') + '...' + }); + panel.getUpdater().on('update', this.onPanelUpdate, this); + }, + scope: this + } + } + }); + }, + + clear: function() { + this.progressBar.updateProgress(0, ' '); + for (var k in this.fields) { + this.fields[k].innerHTML = ''; + } + }, + + update: function(torrentId) { + if (!this.fields) this.getFields(); + deluge.client.web.get_torrent_status(torrentId, Deluge.Keys.Status, { + success: this.onRequestComplete, scope: this }); + }, + + onPanelUpdate: function(el, response) { + this.fields = {}; + Ext.each(Ext.query('dd', this.status.body.dom), function(field) { + this.fields[field.className] = field; + }, this); + }, + + onRequestComplete: function(status) { + seeders = status.total_seeds > -1 ? status.num_seeds + ' (' + status.total_seeds + ')' : status.num_seeds + peers = status.total_peers > -1 ? status.num_peers + ' (' + status.total_peers + ')' : status.num_peers + var data = { + downloaded: fsize(status.total_done, true), + uploaded: fsize(status.total_uploaded, true), + share: (status.ratio == -1) ? '∞' : status.ratio.toFixed(3), + announce: ftime(status.next_announce), + tracker_status: status.tracker_status, + downspeed: (status.download_payload_rate) ? fspeed(status.download_payload_rate) : '0.0 KiB/s', + upspeed: (status.upload_payload_rate) ? fspeed(status.upload_payload_rate) : '0.0 KiB/s', + eta: ftime(status.eta), + pieces: status.num_pieces + ' (' + fsize(status.piece_length) + ')', + seeders: seeders, + peers: peers, + avail: status.distributed_copies.toFixed(3), + active_time: ftime(status.active_time), + seeding_time: ftime(status.seeding_time), + seed_rank: status.seed_rank, + time_added: fdate(status.time_added) + } + data.auto_managed = _((status.is_auto_managed) ? 'True' : 'False'); + + data.downloaded += ' (' + ((status.total_payload_download) ? fsize(status.total_payload_download) : '0.0 KiB') + ')'; + data.uploaded += ' (' + ((status.total_payload_download) ? fsize(status.total_payload_download): '0.0 KiB') + ')'; + + for (var field in this.fields) { + this.fields[field].innerHTML = data[field]; + } + var text = status.state + ' ' + status.progress.toFixed(2) + '%'; + this.progressBar.updateProgress(status.progress / 100.0, text); + } +}); +/*! + * Deluge.add.Window.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge.add'); + +/** + * @class Deluge.add.Window + * @extends Ext.Window + * Base class for an add Window + */ +Deluge.add.Window = Ext.extend(Ext.Window, { + initComponent: function() { + Deluge.add.Window.superclass.initComponent.call(this); + this.addEvents( + 'beforeadd', + 'add' + ); + }, + + /** + * Create an id for the torrent before we have any info about it. + */ + createTorrentId: function() { + return new Date().getTime(); + } +}); +/*! + * Deluge.add.AddWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +Ext.namespace('Deluge.add'); + +Deluge.add.AddWindow = Ext.extend(Deluge.add.Window, { + + title: _('Add Torrents'), + layout: 'border', + width: 470, + height: 450, + bodyStyle: 'padding: 10px 5px;', + buttonAlign: 'right', + closeAction: 'hide', + closable: true, + plain: true, + iconCls: 'x-deluge-add-window-icon', + + initComponent: function() { + Deluge.add.AddWindow.superclass.initComponent.call(this); + + this.addButton(_('Cancel'), this.onCancelClick, this); + this.addButton(_('Add'), this.onAddClick, this); + + function torrentRenderer(value, p, r) { + if (r.data['info_hash']) { + return String.format('
{0}
', value); + } else { + return String.format('
{0}
', value); + } + } + + this.list = new Ext.list.ListView({ + store: new Ext.data.SimpleStore({ + fields: [ + {name: 'info_hash', mapping: 1}, + {name: 'text', mapping: 2} + ], + id: 0 + }), + columns: [{ + id: 'torrent', + width: 150, + sortable: true, + renderer: torrentRenderer, + dataIndex: 'text' + }], + stripeRows: true, + singleSelect: true, + listeners: { + 'selectionchange': { + fn: this.onSelect, + scope: this + } + }, + hideHeaders: true, + autoExpandColumn: 'torrent', + autoScroll: true + }); + + this.add({ + region: 'center', + items: [this.list], + margins: '5 5 5 5', + bbar: new Ext.Toolbar({ + items: [{ + iconCls: 'x-deluge-add-file', + text: _('File'), + handler: this.onFile, + scope: this + }, { + text: _('Url'), + iconCls: 'icon-add-url', + handler: this.onUrl, + scope: this + }, { + text: _('Infohash'), + iconCls: 'icon-add-magnet', + disabled: true + }, '->', { + text: _('Remove'), + iconCls: 'icon-remove', + handler: this.onRemove, + scope: this + }] + }) + }); + + this.optionsPanel = this.add(new Deluge.add.OptionsPanel()); + this.on('hide', this.onHide, this); + this.on('show', this.onShow, this); + }, + + clear: function() { + this.list.getStore().removeAll(); + this.optionsPanel.clear(); + }, + + onAddClick: function() { + var torrents = []; + if (!this.list) return; + this.list.getStore().each(function(r) { + var id = r.get('info_hash'); + torrents.push({ + path: this.optionsPanel.getFilename(id), + options: this.optionsPanel.getOptions(id) + }); + }, this); + + deluge.client.web.add_torrents(torrents, { + success: function(result) { + } + }) + this.clear(); + this.hide(); + }, + + onCancelClick: function() { + this.clear(); + this.hide(); + }, + + onFile: function() { + if (!this.file) this.file = new Deluge.add.FileWindow(); + this.file.show(); + }, + + onHide: function() { + this.optionsPanel.setActiveTab(0); + this.optionsPanel.files.setDisabled(true); + this.optionsPanel.form.setDisabled(true); + }, + + onRemove: function() { + if (!this.list.getSelectionCount()) return; + var torrent = this.list.getSelectedRecords()[0]; + this.list.getStore().remove(torrent); + this.optionsPanel.clear(); + + if (this.torrents && this.torrents[torrent.id]) delete this.torrents[torrent.id]; + }, + + onSelect: function(list, selections) { + if (selections.length) { + var record = this.list.getRecord(selections[0]); + this.optionsPanel.setTorrent(record.get('info_hash')); + this.optionsPanel.files.setDisabled(false); + this.optionsPanel.form.setDisabled(false); + } else { + this.optionsPanel.files.setDisabled(true); + this.optionsPanel.form.setDisabled(true); + } + }, + + onShow: function() { + if (!this.url) { + this.url = new Deluge.add.UrlWindow(); + this.url.on('beforeadd', this.onTorrentBeforeAdd, this); + this.url.on('add', this.onTorrentAdd, this); + } + + if (!this.file) { + this.file = new Deluge.add.FileWindow(); + this.file.on('beforeadd', this.onTorrentBeforeAdd, this); + this.file.on('add', this.onTorrentAdd, this); + } + + this.optionsPanel.form.getDefaults(); + }, + + onTorrentBeforeAdd: function(torrentId, text) { + var store = this.list.getStore(); + store.loadData([[torrentId, null, text]], true); + }, + + onTorrentAdd: function(torrentId, info) { + var r = this.list.getStore().getById(torrentId); + if (!info) { + Ext.MessageBox.show({ + title: _('Error'), + msg: _('Not a valid torrent'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error' + }); + this.list.getStore().remove(r); + } else { + r.set('info_hash', info['info_hash']); + r.set('text', info['name']); + this.list.getStore().commitChanges(); + this.optionsPanel.addTorrent(info); + } + }, + + onUrl: function(button, event) { + this.url.show(); + } +}); +/*! + * Deluge.add.File.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge.add'); + +/** + * @class Deluge.add.FileWindow + * @extends Deluge.add.Window + */ +Deluge.add.FileWindow = Ext.extend(Deluge.add.Window, { + + title: _('Add from File'), + layout: 'fit', + width: 350, + height: 115, + modal: true, + plain: true, + buttonAlign: 'center', + closeAction: 'hide', + bodyStyle: 'padding: 10px 5px;', + iconCls: 'x-deluge-add-file', + + initComponent: function() { + Deluge.add.FileWindow.superclass.initComponent.call(this); + this.addButton(_('Add'), this.onAddClick, this); this.form = this.add({ xtype: 'form', baseCls: 'x-plain', - labelWidth: 55, - width: 300, - defaults: {width: 200}, - defaultType: 'textfield', - }); - - this.passwordField = this.form.add({ - xtype: 'textfield', - fieldLabel: _('Password'), - id: '_password', - name: 'password', - inputType: 'password' - }); - this.passwordField.on('specialkey', this.onSpecialKey, this); - }, - - logout: function() { - deluge.events.fire('logout'); - deluge.client.auth.delete_session({ - success: function(result) { - this.show(true); - }, - scope: this - }); - }, - - show: function(skipCheck) { - if (this.firstShow) { - deluge.client.on('error', this.onClientError, this); - this.firstShow = false; - } - - if (skipCheck) { - return Deluge.LoginWindow.superclass.show.call(this); - } - - deluge.client.auth.check_session({ - success: function(result) { - if (result) { - deluge.events.fire('login'); - } else { - this.show(true); + labelWidth: 35, + autoHeight: true, + fileUpload: true, + items: [{ + xtype: 'fileuploadfield', + id: 'torrentFile', + width: 280, + emptyText: _('Select a torrent'), + fieldLabel: _('File'), + name: 'file', + buttonCfg: { + text: _('Browse') + '...' } - }, - failure: function(result) { - this.show(true); - }, - scope: this + }] }); }, - onSpecialKey: function(field, e) { - if (e.getKey() == 13) this.onLogin(); - }, - - onLogin: function() { - var passwordField = this.passwordField; - deluge.client.auth.login(passwordField.getValue(), { - success: function(result) { - if (result) { - deluge.events.fire('login'); - this.hide(); - passwordField.setRawValue(''); - } else { - Ext.MessageBox.show({ - title: _('Login Failed'), - msg: _('You entered an incorrect password'), - buttons: Ext.MessageBox.OK, - modal: false, - fn: function() { - passwordField.focus(); - }, - icon: Ext.MessageBox.WARNING, - iconCls: 'x-deluge-icon-warning' - }); - } - }, - scope: this - }); - }, - - onClientError: function(errorObj, response, requestOptions) { - if (errorObj.error.code == 1) { - deluge.events.fire('logout'); - this.show(true); - } - }, - - onShow: function() { - this.passwordField.focus(false, 150); - this.passwordField.setRawValue(''); - } -}); - -deluge.login = new Deluge.LoginWindow(); -/* -Script: Deluge.MoveStorage.js - Contains the move storage window. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -Ext.namespace('Deluge'); -Deluge.MoveStorage = Ext.extend(Ext.Window, { - - constructor: function(config) { - config = Ext.apply({ - title: _('Move Storage'), - width: 375, - height: 110, - layout: 'fit', - buttonAlign: 'right', - closeAction: 'hide', - closable: true, - iconCls: 'x-deluge-move-storage', - plain: true, - resizable: false - }, config); - Deluge.MoveStorage.superclass.constructor.call(this, config); - }, - - initComponent: function() { - Deluge.MoveStorage.superclass.initComponent.call(this); - - this.addButton(_('Cancel'), this.onCancel, this); - this.addButton(_('Move'), this.onMove, this); - - this.form = this.add({ - xtype: 'form', - border: false, - defaultType: 'textfield', - width: 300, - bodyStyle: 'padding: 5px' - }); - - this.moveLocation = this.form.add({ - fieldLabel: _('Location'), - name: 'location', - width: 240 - }); - this.form.add({ - xtype: 'button', - text: _('Browse'), - handler: function() { - if (!this.fileBrowser) { - this.fileBrowser = new Deluge.FileBrowser(); - } - this.fileBrowser.show(); - }, - scope: this - }); - }, - - hide: function() { - Deluge.MoveStorage.superclass.hide.call(this); - this.torrentIds = null; - }, - - show: function(torrentIds) { - Deluge.MoveStorage.superclass.show.call(this); - this.torrentIds = torrentIds; - }, - - onCancel: function() { - this.hide(); - }, - - onMove: function() { - var dest = this.moveLocation.getValue(); - deluge.client.core.move_storage(this.torrentIds, dest); - this.hide(); - } -}); -deluge.moveStorage = new Deluge.MoveStorage(); -/* -Script: Deluge.Plugin.js - Contains a base class for plugins to extend. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -/** - * @class Deluge.Plugin - * @extends Ext.util.Observable - */ -Deluge.Plugin = Ext.extend(Ext.util.Observable, { - - /** - * The plugins name - * @property name - * @type {String} - */ - name: null, - - constructor: function(config) { - this.name = config.name; - this.addEvents({ - - /** - * @event enabled - * @param {Plugin} plugin the plugin instance - */ - "enabled": true, - - /** - * @event disabled - * @param {Plugin} plugin the plugin instance - */ - "disabled": true - }); - this.isDelugePlugin = true; - Deluge.Plugins[this.name] = this; - Deluge.Plugin.superclass.constructor.call(this, config); - }, - - /** - * Disables the plugin, firing the "{@link #disabled}" event and - * then executing the plugins clean up method onDisabled. - */ - disable: function() { - this.fireEvent("disabled", this); - if (this.onDisable) this.onDisable(); - }, - - /** - * Enables the plugin, firing the "{@link #enabled}" event and - * then executes the plugins setup method, onEnabled. - */ - enable: function() { - this.fireEvent("enable", this); - if (this.onEnable) this.onEnable(); - } -}); -/* -Script: Deluge.Preferences.js - Contains the preferences window. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. - -*/ - -Ext.namespace('Deluge.preferences'); -PreferencesRecord = Ext.data.Record.create([{name:'name', type:'string'}]); - -/** - * @class Deluge.preferences.PreferencesWindow - * @extends Ext.Window - */ -Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { - - /** - * @property {String} currentPage The currently selected page. - */ - currentPage: null, - - title: _('Preferences'), - layout: 'border', - width: 485, - height: 500, - - buttonAlign: 'right', - closeAction: 'hide', - closable: true, - iconCls: 'x-deluge-preferences', - plain: true, - resizable: false, - - initComponent: function() { - Deluge.preferences.PreferencesWindow.superclass.initComponent.call(this); - - this.categoriesGrid = this.add({ - xtype: 'grid', - region: 'west', - title: _('Categories'), - store: new Ext.data.Store(), - columns: [{ - id: 'name', - renderer: fplain, - dataIndex: 'name' - }], - sm: new Ext.grid.RowSelectionModel({ - singleSelect: true, - listeners: { - 'rowselect': { - fn: this.onPageSelect, scope: this - } - } - }), - hideHeaders: true, - autoExpandColumn: 'name', - deferredRender: false, - autoScroll: true, - margins: '5 0 5 5', - cmargins: '5 0 5 5', - width: 120, - collapsible: true - }); - - this.configPanel = this.add({ - type: 'container', - autoDestroy: false, - region: 'center', - layout: 'card', - //height: 400, - //autoScroll: true, - margins: '5 5 5 5', - cmargins: '5 5 5 5' - }); - - this.addButton(_('Close'), this.onClose, this); - this.addButton(_('Apply'), this.onApply, this); - this.addButton(_('Ok'), this.onOk, this); - - this.pages = {}; - this.optionsManager = new Deluge.OptionsManager(); - this.on('afterrender', this.onAfterRender, this); - this.on('show', this.onShow, this); - }, - - onApply: function(e) { - var changed = this.optionsManager.getDirty(); - if (!Ext.isObjectEmpty(changed)) { - deluge.client.core.set_config(changed, { - success: this.onSetConfig, + // private + onAddClick: function(field, e) { + if (this.form.getForm().isValid()) { + this.torrentId = this.createTorrentId(); + this.form.getForm().submit({ + url: '/upload', + waitMsg: _('Uploading your torrent...'), + failure: this.onUploadFailure, + success: this.onUploadSuccess, scope: this }); - } - - for (var page in this.pages) { - if (this.pages[page].onApply) this.pages[page].onApply(); + var name = this.form.getForm().findField('torrentFile').value; + name = name.split('\\').slice(-1)[0]; + this.fireEvent('beforeadd', this.torrentId, name); } }, - - /** - * Return the options manager for the preferences window. - * @returns {Deluge.OptionsManager} the options manager - */ - getOptionsManager: function() { - return this.optionsManager; - }, - - /** - * Adds a page to the preferences window. - * @param {Mixed} page - */ - addPage: function(page) { - var store = this.categoriesGrid.getStore(); - var name = page.title; - store.add([new PreferencesRecord({name: name})]); - page['bodyStyle'] = 'margin: 5px'; - this.pages[name] = this.configPanel.add(page); - return this.pages[name]; - }, - - /** - * Removes a preferences page from the window. - * @param {mixed} name - */ - removePage: function(page) { - var name = page.title; - var store = this.categoriesGrid.getStore(); - store.removeAt(store.find('name', name)); - this.configPanel.remove(page); - delete this.pages[page.title]; - }, - - /** - * Select which preferences page is displayed. - * @param {String} page The page name to change to - */ - selectPage: function(page) { - var index = this.configPanel.items.indexOf(this.pages[page]); - this.configPanel.getLayout().setActiveItem(index); - this.currentPage = page; - }, - // private - onGotConfig: function(config) { - this.getOptionsManager().set(config); - }, - - // private - onPageSelect: function(selModel, rowIndex, r) { - this.selectPage(r.get('name')); - }, - - // private - onSetConfig: function() { - this.getOptionsManager().commit(); + onGotInfo: function(info, obj, response, request) { + info['filename'] = request.options.filename; + this.fireEvent('add', this.torrentId, info); }, // private - onAfterRender: function() { - if (!this.categoriesGrid.getSelectionModel().hasSelection()) { - this.categoriesGrid.getSelectionModel().selectFirstRow(); - } - this.configPanel.getLayout().setActiveItem(0); - }, - - // private - onShow: function() { - if (!deluge.client.core) return; - deluge.client.core.get_config({ - success: this.onGotConfig, - scope: this - }) - }, - - // private - onClose: function() { + onUploadFailure: function(form, action) { this.hide(); }, - + // private - onOk: function() { - deluge.client.core.set_config(this.optionsManager.getDirty()); + onUploadSuccess: function(fp, upload) { this.hide(); + if (upload.result.success) { + var filename = upload.result.files[0]; + this.form.getForm().findField('torrentFile').setValue(''); + deluge.client.web.get_torrent_info(filename, { + success: this.onGotInfo, + scope: this, + filename: filename + }); + } } }); -deluge.preferences = new Deluge.preferences.PreferencesWindow(); -/* -Script: Deluge.Preferences.Downloads.js - The downloads preferences page. +/*! + * Deluge.add.FilesTab.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge.add'); -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. +/** + * @class Deluge.add.FilesTab + * @extends Ext.ux.tree.TreeGrid + */ +Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + layout: 'fit', + title: _('Files'), - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. + autoScroll: true, + animate: false, + border: false, + disabled: true, + rootVisible: false, - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ + columns: [{ + header: _('Filename'), + width: 295, + dataIndex: 'filename' + },{ + header: _('Size'), + width: 60, + dataIndex: 'size', + tpl: new Ext.XTemplate('{size:this.fsize}', { + fsize: function(v) { + return fsize(v); + } + }) + },{ + header: _('Download'), + width: 65, + dataIndex: 'download', + tpl: new Ext.XTemplate('{download:this.format}', { + format: function(v) { + return '
'; + } + }) + }], + initComponent: function() { + Deluge.add.FilesTab.superclass.initComponent.call(this); + this.on('click', this.onNodeClick, this); + }, + + clearFiles: function() { + var root = this.getRootNode(); + if (!root.hasChildNodes()) return; + root.cascade(function(node) { + if (!node.parentNode || !node.getOwnerTree()) return; + node.remove(); + }); + }, + + setDownload: function(node, value, suppress) { + node.attributes.download = value; + node.ui.updateColumns(); + + if (node.isLeaf()) { + if (!suppress) { + return this.fireEvent('fileschecked', [node], value, !value); + } + } else { + var nodes = [node]; + node.cascade(function(n) { + n.attributes.download = value; + n.ui.updateColumns(); + nodes.push(n); + }, this); + if (!suppress) { + return this.fireEvent('fileschecked', nodes, value, !value); + } + } + }, + + onNodeClick: function(node, e) { + var el = new Ext.Element(e.target); + if (el.getAttribute('rel') == 'chkbox') { + this.setDownload(node, !node.attributes.download); + } + } +}); +/*! + * Deluge.add.Infohash.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Ext.deluge.add'); +/*! + * Deluge.add.OptionsPanel.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge.add'); + +Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, { + + torrents: {}, + + // layout options + region: 'south', + margins: '5 5 5 5', + activeTab: 0, + height: 220, + + initComponent: function() { + Deluge.add.OptionsPanel.superclass.initComponent.call(this); + this.files = this.add(new Deluge.add.FilesTab()); + this.form = this.add(new Deluge.add.OptionsTab()); + + this.files.on('fileschecked', this.onFilesChecked, this); + }, + + addTorrent: function(torrent) { + this.torrents[torrent['info_hash']] = torrent; + var fileIndexes = {}; + this.walkFileTree(torrent['files_tree'], function(filename, type, entry, parent) { + if (type != 'file') return; + fileIndexes[entry.index] = entry.download; + }, this); + + var priorities = []; + Ext.each(Ext.keys(fileIndexes), function(index) { + priorities[index] = fileIndexes[index]; + }); + + var oldId = this.form.optionsManager.changeId(torrent['info_hash'], true); + this.form.optionsManager.setDefault('file_priorities', priorities); + this.form.optionsManager.changeId(oldId, true); + }, + + clear: function() { + this.files.clearFiles(); + this.form.optionsManager.resetAll(); + }, + + getFilename: function(torrentId) { + return this.torrents[torrentId]['filename']; + }, + + getOptions: function(torrentId) { + var oldId = this.form.optionsManager.changeId(torrentId, true); + var options = this.form.optionsManager.get(); + this.form.optionsManager.changeId(oldId, true); + Ext.each(options['file_priorities'], function(priority, index) { + options['file_priorities'][index] = (priority) ? 1 : 0; + }); + return options; + }, + + setTorrent: function(torrentId) { + if (!torrentId) return; + + this.torrentId = torrentId; + this.form.optionsManager.changeId(torrentId); + + this.files.clearFiles(); + var root = this.files.getRootNode(); + var priorities = this.form.optionsManager.get('file_priorities'); + + this.walkFileTree(this.torrents[torrentId]['files_tree'], function(filename, type, entry, parentNode) { + var node = new Ext.tree.TreeNode({ + download: (entry.index) ? priorities[entry.index] : true, + filename: filename, + fileindex: entry.index, + leaf: type != 'dir', + size: entry.length + }); + parentNode.appendChild(node); + if (type == 'dir') return node; + }, this, root); + root.firstChild.expand(); + }, + + walkFileTree: function(files, callback, scope, parentNode) { + for (var filename in files.contents) { + var entry = files.contents[filename]; + var type = entry.type; + + if (scope) { + var ret = callback.apply(scope, [filename, type, entry, parentNode]); + } else { + var ret = callback(filename, type, entry, parentNode); + } + + if (type == 'dir') this.walkFileTree(entry, callback, scope, ret); + } + }, + + onFilesChecked: function(nodes, newValue, oldValue) { + if (this.form.optionsManager.get('compact_allocation')) { + Ext.Msg.show({ + title: _('Unable to set file priority!'), + msg: _('File prioritization is unavailable when using Compact allocation. Would you like to switch to Full allocation?'), + buttons: Ext.Msg.YESNO, + fn: function(result) { + if (result == 'yes') { + this.form.optionsManager.update('compact_allocation', false); + Ext.each(nodes, function(node) { + if (node.attributes.fileindex < 0) return; + var priorities = this.form.optionsManager.get('file_priorities'); + priorities[node.attributes.fileindex] = newValue; + this.form.optionsManager.update('file_priorities', priorities); + }, this); + } else { + this.files.setDownload(nodes[0], oldValue, true); + } + }, + scope: this, + icon: Ext.MessageBox.QUESTION + }); + } else { + Ext.each(nodes, function(node) { + if (node.attributes.fileindex < 0) return; + var priorities = this.form.optionsManager.get('file_priorities'); + priorities[node.attributes.fileindex] = newValue; + this.form.optionsManager.update('file_priorities', priorities); + }, this); + } + } +}); +/*! + * Deluge.add.OptionsPanel.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge.add'); + +/** + * @class Deluge.add.OptionsTab + * @extends Ext.form.FormPanel + */ +Deluge.add.OptionsTab = Ext.extend(Ext.form.FormPanel, { + + title: _('Options'), + height: 170, + + border: false, + bodyStyle: 'padding: 5px', + disabled: true, + labelWidth: 1, + + initComponent: function() { + Deluge.add.OptionsTab.superclass.initComponent.call(this); + + this.optionsManager = new Deluge.MultiOptionsManager(); + + var fieldset = this.add({ + xtype: 'fieldset', + title: _('Download Location'), + border: false, + autoHeight: true, + defaultType: 'textfield', + labelWidth: 1, + fieldLabel: '', + style: 'padding-bottom: 5px; margin-bottom: 0px;' + }); + + this.optionsManager.bind('download_location', fieldset.add({ + fieldLabel: '', + name: 'download_location', + width: 400, + labelSeparator: '' + })); + + var panel = this.add({ + border: false, + layout: 'column', + defaultType: 'fieldset' + }); + fieldset = panel.add({ + title: _('Allocation'), + border: false, + autoHeight: true, + defaultType: 'radio', + width: 100 + }); + + this.optionsManager.bind('compact_allocation', fieldset.add({ + xtype: 'radiogroup', + columns: 1, + vertical: true, + labelSeparator: '', + items: [{ + name: 'compact_allocation', + value: false, + inputValue: false, + boxLabel: _('Full'), + fieldLabel: '', + labelSeparator: '' + }, { + name: 'compact_allocation', + value: true, + inputValue: true, + boxLabel: _('Compact'), + fieldLabel: '', + labelSeparator: '' + }] + })); + + fieldset = panel.add({ + title: _('Bandwidth'), + border: false, + autoHeight: true, + labelWidth: 100, + width: 200, + defaultType: 'spinnerfield' + }); + this.optionsManager.bind('max_download_speed', fieldset.add({ + fieldLabel: _('Max Down Speed'), + labelStyle: 'margin-left: 10px', + name: 'max_download_speed', + width: 60 + })); + this.optionsManager.bind('max_upload_speed', fieldset.add({ + fieldLabel: _('Max Up Speed'), + labelStyle: 'margin-left: 10px', + name: 'max_upload_speed', + width: 60 + })); + this.optionsManager.bind('max_connections', fieldset.add({ + fieldLabel: _('Max Connections'), + labelStyle: 'margin-left: 10px', + name: 'max_connections', + width: 60 + })); + this.optionsManager.bind('max_upload_slots', fieldset.add({ + fieldLabel: _('Max Upload Slots'), + labelStyle: 'margin-left: 10px', + name: 'max_upload_slots', + width: 60 + })); + + fieldset = panel.add({ + title: _('General'), + border: false, + autoHeight: true, + defaultType: 'checkbox' + }); + this.optionsManager.bind('add_paused', fieldset.add({ + name: 'add_paused', + boxLabel: _('Add In Paused State'), + fieldLabel: '', + labelSeparator: '' + })); + this.optionsManager.bind('prioritize_first_last_pieces', fieldset.add({ + name: 'prioritize_first_last_pieces', + boxLabel: _('Prioritize First/Last Pieces'), + fieldLabel: '', + labelSeparator: '' + })); + }, + + getDefaults: function() { + var keys = ['add_paused','compact_allocation','download_location', + 'max_connections_per_torrent','max_download_speed_per_torrent', + 'max_upload_slots_per_torrent','max_upload_speed_per_torrent', + 'prioritize_first_last_pieces']; + + deluge.client.core.get_config_values(keys, { + success: function(config) { + var options = { + 'file_priorities': [], + 'add_paused': config.add_paused, + 'compact_allocation': config.compact_allocation, + 'download_location': config.download_location, + 'max_connections': config.max_connections_per_torrent, + 'max_download_speed': config.max_download_speed_per_torrent, + 'max_upload_slots': config.max_upload_slots_per_torrent, + 'max_upload_speed': config.max_upload_speed_per_torrent, + 'prioritize_first_last_pieces': config.prioritize_first_last_pieces + } + this.optionsManager.options = options; + this.optionsManager.resetAll(); + }, + scope: this + }); + } +}); +/*! + * Deluge.add.UrlWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +Ext.namespace('Deluge.add'); +Deluge.add.UrlWindow = Ext.extend(Deluge.add.Window, { + + title: _('Add from Url'), + modal: true, + plain: true, + layout: 'fit', + width: 350, + height: 155, + + buttonAlign: 'center', + closeAction: 'hide', + bodyStyle: 'padding: 10px 5px;', + iconCls: 'x-deluge-add-url-window-icon', + + initComponent: function() { + Deluge.add.UrlWindow.superclass.initComponent.call(this); + this.addButton(_('Add'), this.onAddClick, this); + + var form = this.add({ + xtype: 'form', + defaultType: 'textfield', + baseCls: 'x-plain', + labelWidth: 55 + }); + + this.urlField = form.add({ + fieldLabel: _('Url'), + id: 'url', + name: 'url', + anchor: '100%' + }); + this.urlField.on('specialkey', this.onAdd, this); + + this.cookieField = form.add({ + fieldLabel: _('Cookies'), + id: 'cookies', + name: 'cookies', + anchor: '100%' + }); + this.cookieField.on('specialkey', this.onAdd, this); + }, + + onAddClick: function(field, e) { + if ((field.id == 'url' || field.id == 'cookies') && e.getKey() != e.ENTER) return; + + var field = this.urlField; + var url = field.getValue(); + var cookies = this.cookieField.getValue(); + var torrentId = this.createTorrentId(); + + deluge.client.web.download_torrent_from_url(url, cookies, { + success: this.onDownload, + scope: this, + torrentId: torrentId + }); + this.hide(); + this.fireEvent('beforeadd', torrentId, url); + }, + + onDownload: function(filename, obj, resp, req) { + this.urlField.setValue(''); + deluge.client.web.get_torrent_info(filename, { + success: this.onGotInfo, + scope: this, + filename: filename, + torrentId: req.options.torrentId + }); + }, + + onGotInfo: function(info, obj, response, request) { + info['filename'] = request.options.filename; + this.fireEvent('add', request.options.torrentId, info); + } +}); +/*! + * Deluge.preferences.BandwidthPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Deluge.preferences'); + +/** + * @class Deluge.preferences.Bandwidth + * @extends Ext.form.FormPanel + */ +Deluge.preferences.Bandwidth = Ext.extend(Ext.form.FormPanel, { + constructor: function(config) { + config = Ext.apply({ + border: false, + title: _('Bandwidth'), + layout: 'form', + labelWidth: 10 + }, config); + Deluge.preferences.Bandwidth.superclass.constructor.call(this, config); + }, + + initComponent: function() { + Deluge.preferences.Bandwidth.superclass.initComponent.call(this); + + var om = deluge.preferences.getOptionsManager(); + var fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Global Bandwidth Usage'), + labelWidth: 200, + defaultType: 'spinnerfield', + defaults: { + minValue: -1, + maxValue: 99999 + }, + style: 'margin-bottom: 0px; padding-bottom: 0px;', + autoHeight: true + }); + om.bind('max_connections_global', fieldset.add({ + name: 'max_connections_global', + fieldLabel: _('Maximum Connections'), + width: 80, + value: -1, + decimalPrecision: 0 + })); + om.bind('max_upload_slots_global', fieldset.add({ + name: 'max_upload_slots_global', + fieldLabel: _('Maximum Upload Slots'), + width: 80, + value: -1, + decimalPrecision: 0 + })); + om.bind('max_download_speed', fieldset.add({ + name: 'max_download_speed', + fieldLabel: _('Maximum Download Speed (KiB/s)'), + width: 80, + value: -1.0, + decimalPrecision: 1 + })); + om.bind('max_upload_speed', fieldset.add({ + name: 'max_upload_speed', + fieldLabel: _('Maximum Upload Speed (KiB/s)'), + width: 80, + value: -1.0, + decimalPrecision: 1 + })); + om.bind('max_half_open_connections', fieldset.add({ + name: 'max_half_open_connections', + fieldLabel: _('Maximum Half-Open Connections'), + width: 80, + value: -1, + decimalPrecision: 0 + })); + om.bind('max_connections_per_second', fieldset.add({ + name: 'max_connections_per_second', + fieldLabel: _('Maximum Connection Attempts per Second'), + width: 80, + value: -1, + decimalPrecision: 0 + })); + + fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: '', + defaultType: 'checkbox', + style: 'padding-top: 0px; padding-bottom: 5px; margin-top: 0px; margin-bottom: 0px;', + autoHeight: true + }); + om.bind('ignore_limits_on_local_network', fieldset.add({ + name: 'ignore_limits_on_local_network', + height: 22, + fieldLabel: '', + labelSeparator: '', + boxLabel: _('Ignore limits on local network') + })); + om.bind('rate_limit_ip_overhead', fieldset.add({ + name: 'rate_limit_ip_overhead', + height: 22, + fieldLabel: '', + labelSeparator: '', + boxLabel: _('Rate limit IP overhead') + })); + + fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Per Torrent Bandwidth Usage'), + style: 'margin-bottom: 0px; padding-bottom: 0px;', + defaultType: 'spinnerfield', + labelWidth: 200, + defaults: { + minValue: -1, + maxValue: 99999 + }, + autoHeight: true + }); + om.bind('max_connections_per_torrent', fieldset.add({ + name: 'max_connections_per_torrent', + fieldLabel: _('Maximum Connections'), + width: 80, + value: -1, + decimalPrecision: 0 + })); + om.bind('max_upload_slots_per_torrent', fieldset.add({ + name: 'max_upload_slots_per_torrent', + fieldLabel: _('Maximum Upload Slots'), + width: 80, + value: -1, + decimalPrecision: 0 + })); + om.bind('max_download_speed_per_torrent', fieldset.add({ + name: 'max_download_speed_per_torrent', + fieldLabel: _('Maximum Download Speed (KiB/s)'), + width: 80, + value: -1, + decimalPrecision: 0 + })); + om.bind('max_upload_speed_per_torrent', fieldset.add({ + name: 'max_upload_speed_per_torrent', + fieldLabel: _('Maximum Upload Speed (KiB/s)'), + width: 80, + value: -1, + decimalPrecision: 0 + })); + } +}); +/*! + * Deluge.preferences.CachePage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Deluge.preferences'); + +/** + * @class Deluge.preferences.Cache + * @extends Ext.form.FormPanel + */ +Deluge.preferences.Cache = Ext.extend(Ext.form.FormPanel, { + + border: false, + title: _('Cache'), + layout: 'form', + + initComponent: function() { + Deluge.preferences.Cache.superclass.initComponent.call(this); + + var om = deluge.preferences.getOptionsManager(); + + var fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Settings'), + autoHeight: true, + labelWidth: 180, + defaultType: 'spinnerfield', + defaults: { + decimalPrecision: 0, + minValue: -1, + maxValue: 99999 + } + }); + om.bind('cache_size', fieldset.add({ + fieldLabel: _('Cache Size (16 KiB Blocks)'), + name: 'cache_size', + width: 60, + value: 512 + })); + om.bind('cache_expiry', fieldset.add({ + fieldLabel: _('Cache Expiry (seconds)'), + name: 'cache_expiry', + width: 60, + value: 60 + })); + } +}); +/*! + * Deluge.preferences.DaemonPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Deluge.preferences'); + +/** + * @class Deluge.preferences.Daemon + * @extends Ext.form.FormPanel + */ +Deluge.preferences.Daemon = Ext.extend(Ext.form.FormPanel, { + + border: false, + title: _('Daemon'), + layout: 'form', + + initComponent: function() { + Deluge.preferences.Daemon.superclass.initComponent.call(this); + + var om = deluge.preferences.getOptionsManager(); + + var fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Port'), + autoHeight: true, + defaultType: 'spinnerfield' + }); + om.bind('daemon_port', fieldset.add({ + fieldLabel: _('Daemon port'), + name: 'daemon_port', + value: 58846, + decimalPrecision: 0, + minValue: -1, + maxValue: 99999 + })); + + fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Connections'), + autoHeight: true, + labelWidth: 1, + defaultType: 'checkbox' + }); + om.bind('allow_remote', fieldset.add({ + fieldLabel: '', + height: 22, + labelSeparator: '', + boxLabel: _('Allow Remote Connections'), + name: 'allow_remote' + })); + + fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Other'), + autoHeight: true, + labelWidth: 1, + defaultType: 'checkbox' + }); + om.bind('new_release_check', fieldset.add({ + fieldLabel: '', + labelSeparator: '', + height: 40, + boxLabel: _('Periodically check the website for new releases'), + id: 'new_release_check' + })); + } +}); +/*! + * Deluge.preferences.DownloadsPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ Ext.namespace('Deluge.preferences'); /** @@ -5167,13 +2794,13 @@ Deluge.preferences.Downloads = Ext.extend(Ext.FormPanel, { labelWidth: 1, defaultType: 'radiogroup', style: 'margin-bottom: 5px; margin-top: 0; padding-bottom: 5px; padding-top: 0;', - width: 240, + width: 240 }); optMan.bind('compact_allocation', fieldset.add({ name: 'compact_allocation', width: 200, labelSeparator: '', - disabled: true, + //disabled: true, defaults: { width: 80, height: 22, @@ -5210,48 +2837,511 @@ Deluge.preferences.Downloads = Ext.extend(Ext.FormPanel, { height: 22, boxLabel: _('Add torrents in Paused state') })); - - this.on('show', this.onShow, this); - }, - - onShow: function() { - Deluge.preferences.Downloads.superclass.onShow.call(this); } }); -deluge.preferences.addPage(new Deluge.preferences.Downloads()); -/* -Script: deluge.preferences.Network.js - The network preferences page. +/*! + * Deluge.preferences.EncryptionPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Deluge.preferences'); -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. +/** + * @class Deluge.preferences.Encryption + * @extends Ext.form.FormPanel + */ +Deluge.preferences.Encryption = Ext.extend(Ext.form.FormPanel, { - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + border: false, + title: _('Encryption'), + + initComponent: function() { + Deluge.preferences.Encryption.superclass.initComponent.call(this); - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. + var optMan = deluge.preferences.getOptionsManager(); + + var fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Settings'), + autoHeight: true, + defaultType: 'combo', + width: 300 + }); + optMan.bind('enc_in_policy', fieldset.add({ + fieldLabel: _('Inbound'), + mode: 'local', + width: 150, + store: new Ext.data.ArrayStore({ + fields: ['id', 'text'], + data: [ + [0, _('Forced')], + [1, _('Enabled')], + [2, _('Disabled')] + ] + }), + editable: false, + triggerAction: 'all', + valueField: 'id', + displayField: 'text' + })); + optMan.bind('enc_out_policy', fieldset.add({ + fieldLabel: _('Outbound'), + mode: 'local', + width: 150, + store: new Ext.data.SimpleStore({ + fields: ['id', 'text'], + data: [ + [0, _('Forced')], + [1, _('Enabled')], + [2, _('Disabled')] + ] + }), + editable: false, + triggerAction: 'all', + valueField: 'id', + displayField: 'text' + })); + optMan.bind('enc_level', fieldset.add({ + fieldLabel: _('Level'), + mode: 'local', + width: 150, + store: new Ext.data.SimpleStore({ + fields: ['id', 'text'], + data: [ + [0, _('Handshake')], + [1, _('Full Stream')], + [2, _('Either')] + ] + }), + editable: false, + triggerAction: 'all', + valueField: 'id', + displayField: 'text' + })); + optMan.bind('enc_prefer_rc4', fieldset.add({ + xtype: 'checkbox', + name: 'enc_prefer_rc4', + height: 40, + hideLabel: true, + boxLabel: _('Encrypt entire stream') + })); + } +}); +/*! + * Deluge.preferences.InstallPluginWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Deluge.preferences'); - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ +/** + * @class Deluge.preferences.InstallPluginWindow + * @extends Ext.Window + */ +Deluge.preferences.InstallPluginWindow = Ext.extend(Ext.Window, { + title: _('Install Plugin'), + layout: 'fit', + height: 115, + width: 350, + + bodyStyle: 'padding: 10px 5px;', + buttonAlign: 'center', + closeAction: 'hide', + iconCls: 'x-deluge-install-plugin', + modal: true, + plain: true, + + initComponent: function() { + Deluge.add.FileWindow.superclass.initComponent.call(this); + this.addButton(_('Install'), this.onInstall, this); + + this.form = this.add({ + xtype: 'form', + baseCls: 'x-plain', + labelWidth: 70, + autoHeight: true, + fileUpload: true, + items: [{ + xtype: 'fileuploadfield', + width: 240, + emptyText: _('Select an egg'), + fieldLabel: _('Plugin Egg'), + name: 'file', + buttonCfg: { + text: _('Browse') + '...' + } + }] + }); + }, + + onInstall: function(field, e) { + this.form.getForm().submit({ + url: '/upload', + waitMsg: _('Uploading your plugin...'), + success: this.onUploadSuccess, + scope: this + }); + }, + + onUploadPlugin: function(info, obj, response, request) { + this.fireEvent('pluginadded'); + }, + + onUploadSuccess: function(fp, upload) { + this.hide(); + if (upload.result.success) { + var filename = this.form.getForm().getFieldValues().file; + filename = filename.split('\\').slice(-1)[0] + var path = upload.result.files[0]; + this.form.getForm().setValues({file: ''}); + deluge.client.web.upload_plugin(filename, path, { + success: this.onUploadPlugin, + scope: this, + filename: filename + }); + } + } +}); +/*! + * Deluge.preferences.InterfacePage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Deluge.preferences'); + +/** + * @class Deluge.preferences.Interface + * @extends Ext.form.FormPanel + */ +Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { + + border: false, + title: _('Interface'), + layout: 'form', + + initComponent: function() { + Deluge.preferences.Interface.superclass.initComponent.call(this); + + var om = this.optionsManager = new Deluge.OptionsManager(); + this.on('show', this.onPageShow, this); + + var fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Interface'), + style: 'margin-bottom: 0px; padding-bottom: 5px; padding-top: 5px', + autoHeight: true, + labelWidth: 1, + defaultType: 'checkbox' + }); + om.bind('show_session_speed', fieldset.add({ + name: 'show_session_speed', + height: 22, + fieldLabel: '', + labelSeparator: '', + boxLabel: _('Show session speed in titlebar') + })); + om.bind('sidebar_show_zero', fieldset.add({ + name: 'sidebar_show_zero', + height: 22, + fieldLabel: '', + labelSeparator: '', + boxLabel: _('Show filters with zero torrents') + })); + om.bind('sidebar_multiple_filters', fieldset.add({ + name: 'sidebar_multiple_filters', + height: 22, + fieldLabel: '', + labelSeparator: '', + boxLabel: _('Allow the use of multiple filters at once') + })); + + fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Password'), + style: 'margin-bottom: 0px; padding-bottom: 0px; padding-top: 5px', + autoHeight: true, + labelWidth: 110, + defaultType: 'textfield', + defaults: { + width: 180, + inputType: 'password' + } + }); + + this.oldPassword = fieldset.add({ + name: 'old_password', + fieldLabel: _('Old Password') + }); + this.newPassword = fieldset.add({ + name: 'new_password', + fieldLabel: _('New Password') + }); + this.confirmPassword = fieldset.add({ + name: 'confirm_password', + fieldLabel: _('Confirm Password') + }); + + var panel = fieldset.add({ + xtype: 'panel', + autoHeight: true, + border: false, + width: 320, + bodyStyle: 'padding-left: 230px' + }) + panel.add({ + xtype: 'button', + text: _('Change'), + listeners: { + 'click': { + fn: this.onPasswordChange, + scope: this + } + } + }); + + fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Server'), + style: 'margin-top: 0px; padding-top: 0px; margin-bottom: 0px; padding-bottom: 0px', + autoHeight: true, + labelWidth: 110, + defaultType: 'spinnerfield', + defaults: { + width: 80 + } + }); + om.bind('session_timeout', fieldset.add({ + name: 'session_timeout', + fieldLabel: _('Session Timeout'), + decimalPrecision: 0, + minValue: -1, + maxValue: 99999 + })); + om.bind('port', fieldset.add({ + name: 'port', + fieldLabel: _('Port'), + decimalPrecision: 0, + minValue: -1, + maxValue: 99999 + })); + this.httpsField = om.bind('https', fieldset.add({ + xtype: 'checkbox', + name: 'https', + hideLabel: true, + width: 280, + height: 22, + boxLabel: _('Use SSL (paths relative to Deluge config folder)') + })); + this.httpsField.on('check', this.onSSLCheck, this); + this.pkeyField = om.bind('pkey', fieldset.add({ + xtype: 'textfield', + disabled: true, + name: 'pkey', + width: 180, + fieldLabel: _('Private Key') + })); + this.certField = om.bind('cert', fieldset.add({ + xtype: 'textfield', + disabled: true, + name: 'cert', + width: 180, + fieldLabel: _('Certificate') + })); + }, + + onApply: function() { + var changed = this.optionsManager.getDirty(); + if (!Ext.isObjectEmpty(changed)) { + deluge.client.web.set_config(changed, { + success: this.onSetConfig, + scope: this + }); + + for (var key in deluge.config) { + deluge.config[key] = this.optionsManager.get(key); + } + } + }, + + onGotConfig: function(config) { + this.optionsManager.set(config); + }, + + onPasswordChange: function() { + var newPassword = this.newPassword.getValue(); + if (newPassword != this.confirmPassword.getValue()) { + Ext.MessageBox.show({ + title: _('Invalid Password'), + msg: _('Your passwords don\'t match!'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error' + }); + return; + } + + var oldPassword = this.oldPassword.getValue(); + deluge.client.auth.change_password(oldPassword, newPassword, { + success: function(result) { + if (!result) { + Ext.MessageBox.show({ + title: _('Password'), + msg: _('Your old password was incorrect!'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error' + }); + this.oldPassword.setValue(''); + } else { + Ext.MessageBox.show({ + title: _('Change Successful'), + msg: _('Your password was successfully changed!'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.INFO, + iconCls: 'x-deluge-icon-info' + }); + this.oldPassword.setValue(''); + this.newPassword.setValue(''); + this.confirmPassword.setValue(''); + } + }, + scope: this + }); + }, + + onSetConfig: function() { + this.optionsManager.commit(); + }, + + onPageShow: function() { + deluge.client.web.get_config({ + success: this.onGotConfig, + scope: this + }) + }, + + onSSLCheck: function(e, checked) { + this.pkeyField.setDisabled(!checked); + this.certField.setDisabled(!checked); + } +}); +/*! + * Deluge.preferences.NetworkPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ Ext.namespace('Deluge.preferences'); /** @@ -5259,15 +3349,11 @@ Ext.namespace('Deluge.preferences'); * @extends Ext.form.FormPanel */ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, { - constructor: function(config) { - config = Ext.apply({ - border: false, - title: _('Network'), - layout: 'form' - }, config); - Deluge.preferences.Network.superclass.constructor.call(this, config); - }, + border: false, + layout: 'form', + title: _('Network'), + initComponent: function() { Deluge.preferences.Network.superclass.initComponent.call(this); var optMan = deluge.preferences.getOptionsManager(); @@ -5297,7 +3383,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, { } })); this.listenPorts = fieldset.add({ - xtype: 'uxspinnergroup', + xtype: 'spinnergroup', name: 'listen_ports', fieldLabel: '', labelSeparator: '', @@ -5307,22 +3393,20 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, { }, items: [{ fieldLabel: 'From', - width: 80, strategy: { xtype: 'number', decimalPrecision: 0, minValue: -1, maxValue: 99999 - }, + } }, { fieldLabel: 'To', - width: 80, strategy: { xtype: 'number', decimalPrecision: 0, minValue: -1, maxValue: 99999 - }, + } }] }); optMan.bind('listen_ports', this.listenPorts); @@ -5352,7 +3436,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, { } })); this.outgoingPorts = fieldset.add({ - xtype: 'uxspinnergroup', + xtype: 'spinnergroup', name: 'outgoing_ports', fieldLabel: '', labelSeparator: '', @@ -5367,7 +3451,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, { decimalPrecision: 0, minValue: -1, maxValue: 99999 - }, + } }, { fieldLabel: 'To', strategy: { @@ -5375,7 +3459,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, { decimalPrecision: 0, minValue: -1, maxValue: 99999 - }, + } }] }); optMan.bind('outgoing_ports', this.outgoingPorts); @@ -5457,643 +3541,37 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, { })); } }); -deluge.preferences.addPage(new Deluge.preferences.Network()); -/* -Script: deluge.preferences.Encryption.js - The encryption preferences page. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -Ext.namespace('Deluge.preferences'); - -/** - * @class Deluge.preferences.Encryption - * @extends Ext.form.FormPanel +/*! + * Deluge.preferences.OtherPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. */ -Deluge.preferences.Encryption = Ext.extend(Ext.form.FormPanel, { - constructor: function(config) { - config = Ext.apply({ - border: false, - title: _('Encryption'), - layout: 'form' - }, config); - Deluge.preferences.Encryption.superclass.constructor.call(this, config); - }, - - initComponent: function() { - Deluge.preferences.Encryption.superclass.initComponent.call(this); - - var optMan = deluge.preferences.getOptionsManager(); - - var fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: _('Settings'), - autoHeight: true, - defaultType: 'combo' - }); - optMan.bind('enc_in_policy', fieldset.add({ - fieldLabel: _('Inbound'), - mode: 'local', - width: 150, - store: new Ext.data.SimpleStore({ - fields: ['id', 'text'], - data: [ - [0, _('Forced')], - [1, _('Enabled')], - [2, _('Disabled')] - ] - }), - triggerAction: 'all', - valueField: 'id', - displayField: 'text' - })); - optMan.bind('enc_out_policy', fieldset.add({ - fieldLabel: _('Outbound'), - mode: 'local', - width: 150, - store: new Ext.data.SimpleStore({ - fields: ['id', 'text'], - data: [ - [0, _('Forced')], - [1, _('Enabled')], - [2, _('Disabled')] - ] - }), - triggerAction: 'all', - valueField: 'id', - displayField: 'text' - })); - optMan.bind('enc_level', fieldset.add({ - fieldLabel: _('Level'), - mode: 'local', - width: 150, - store: new Ext.data.SimpleStore({ - fields: ['id', 'text'], - data: [ - [0, _('Handshake')], - [1, _('Full Stream')], - [2, _('Either')] - ] - }), - triggerAction: 'all', - valueField: 'id', - displayField: 'text' - })); - optMan.bind('enc_prefer_rc4', fieldset.add({ - xtype: 'checkbox', - name: 'enc_prefer_rc4', - height: 40, - hideLabel: true, - boxLabel: _('Encrypt entire stream') - })); - } -}); -deluge.preferences.addPage(new Deluge.preferences.Encryption()); -/* -Script: deluge.preferences.Bandwidth.js - The bandwidth preferences page. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -Ext.namespace('Deluge.preferences'); - -/** - * @class Deluge.preferences.Bandwidth - * @extends Ext.form.FormPanel - */ -Deluge.preferences.Bandwidth = Ext.extend(Ext.form.FormPanel, { - constructor: function(config) { - config = Ext.apply({ - border: false, - title: _('Bandwidth'), - layout: 'form', - labelWidth: 10 - }, config); - Deluge.preferences.Bandwidth.superclass.constructor.call(this, config); - }, - - initComponent: function() { - Deluge.preferences.Bandwidth.superclass.initComponent.call(this); - - var optMan = deluge.preferences.getOptionsManager(); - var fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: _('Global Bandwidth Usage'), - labelWidth: 200, - defaultType: 'spinnerfield', - style: 'margin-bottom: 0px; padding-bottom: 0px;', - autoHeight: true - }); - optMan.bind('max_connections_global', fieldset.add({ - name: 'max_connections_global', - fieldLabel: _('Maximum Connections'), - width: 80, - value: -1, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - } - })); - optMan.bind('max_upload_slots_global', fieldset.add({ - name: 'max_upload_slots_global', - fieldLabel: _('Maximum Upload Slots'), - width: 80, - value: -1, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - } - })); - optMan.bind('max_download_speed', fieldset.add({ - name: 'max_download_speed', - fieldLabel: _('Maximum Download Speed (KiB/s)'), - width: 80, - value: -1, - strategy: { - xtype: 'number', - decimalPrecision: 1, - minValue: -1, - maxValue: 99999 - } - })); - optMan.bind('max_upload_speed', fieldset.add({ - name: 'max_upload_speed', - fieldLabel: _('Maximum Upload Speed (KiB/s)'), - width: 80, - value: -1, - strategy: { - xtype: 'number', - decimalPrecision: 1, - minValue: -1, - maxValue: 99999 - } - })); - optMan.bind('max_half_open_connections', fieldset.add({ - name: 'max_half_open_connections', - fieldLabel: _('Maximum Half-Open Connections'), - width: 80, - value: -1, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - } - })); - optMan.bind('max_connections_per_second', fieldset.add({ - name: 'max_connections_per_second', - fieldLabel: _('Maximum Connection Attempts per Second'), - width: 80, - value: -1, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - } - })); - - fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: '', - defaultType: 'checkbox', - style: 'padding-top: 0px; padding-bottom: 5px; margin-top: 0px; margin-bottom: 0px;', - autoHeight: true - }); - optMan.bind('ignore_limits_on_local_network', fieldset.add({ - name: 'ignore_limits_on_local_network', - height: 22, - fieldLabel: '', - labelSeparator: '', - boxLabel: _('Ignore limits on local network'), - })); - optMan.bind('rate_limit_ip_overhead', fieldset.add({ - name: 'rate_limit_ip_overhead', - height: 22, - fieldLabel: '', - labelSeparator: '', - boxLabel: _('Rate limit IP overhead'), - })); - - fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: _('Per Torrent Bandwidth Usage'), - style: 'margin-bottom: 0px; padding-bottom: 0px;', - defaultType: 'spinnerfield', - labelWidth: 200, - autoHeight: true - }); - optMan.bind('max_connections_per_torrent', fieldset.add({ - name: 'max_connections_per_torrent', - fieldLabel: _('Maximum Connections'), - width: 80, - value: -1, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - } - })); - optMan.bind('max_upload_slots_per_torrent', fieldset.add({ - name: 'max_upload_slots_per_torrent', - fieldLabel: _('Maximum Upload Slots'), - width: 80, - value: -1, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - } - })); - optMan.bind('max_download_speed_per_torrent', fieldset.add({ - name: 'max_download_speed_per_torrent', - fieldLabel: _('Maximum Download Speed (KiB/s)'), - width: 80, - value: -1, - strategy: { - xtype: 'number', - decimalPrecision: 1, - minValue: -1, - maxValue: 99999 - } - })); - optMan.bind('max_upload_speed_per_torrent', fieldset.add({ - name: 'max_upload_speed_per_torrent', - fieldLabel: _('Maximum Upload Speed (KiB/s)'), - width: 80, - value: -1, - strategy: { - xtype: 'number', - decimalPrecision: 1, - minValue: -1, - maxValue: 99999 - } - })); - } -}); -deluge.preferences.addPage(new Deluge.preferences.Bandwidth()); -/* -Script: Deluge.Preferences.Interface.js - The interface preferences page. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -Ext.namespace('Deluge.preferences'); - -/** - * @class Deluge.preferences.Interface - * @extends Ext.form.FormPanel - */ -Deluge.preferences.Interface = Ext.extend(Ext.form.FormPanel, { - constructor: function(config) { - config = Ext.apply({ - border: false, - title: _('Interface'), - layout: 'form' - }, config); - Deluge.preferences.Interface.superclass.constructor.call(this, config); - }, - - initComponent: function() { - Deluge.preferences.Interface.superclass.initComponent.call(this); - - var optMan = this.optionsManager = new Deluge.OptionsManager(); - this.on('show', this.onShow, this); - - var fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: _('Interface'), - style: 'margin-bottom: 0px; padding-bottom: 5px; padding-top: 5px', - autoHeight: true, - labelWidth: 1, - defaultType: 'checkbox' - }); - optMan.bind('show_session_speed', fieldset.add({ - name: 'show_session_speed', - height: 22, - fieldLabel: '', - labelSeparator: '', - boxLabel: _('Show session speed in titlebar') - })); - optMan.bind('sidebar_show_zero', fieldset.add({ - name: 'sidebar_show_zero', - height: 22, - fieldLabel: '', - labelSeparator: '', - boxLabel: _('Show filters with zero torrents') - })); - optMan.bind('sidebar_show_trackers', fieldset.add({ - name: 'sidebar_show_trackers', - height: 22, - fieldLabel: '', - labelSeparator: '', - boxLabel: _('Show trackers with zero torrents') - })); - - fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: _('Password'), - style: 'margin-bottom: 0px; padding-bottom: 0px; padding-top: 5px', - autoHeight: true, - labelWidth: 110, - defaultType: 'textfield', - defaults: { - width: 180, - inputType: 'password' - } - }); - - this.oldPassword = fieldset.add({ - name: 'old_password', - fieldLabel: _('Old Password') - }); - this.newPassword = fieldset.add({ - name: 'new_password', - fieldLabel: _('New Password') - }); - this.confirmPassword = fieldset.add({ - name: 'confirm_password', - fieldLabel: _('Confirm Password') - }); - - var panel = fieldset.add({ - xtype: 'panel', - autoHeight: true, - border: false, - width: 320, - bodyStyle: 'padding-left: 230px' - }) - panel.add({ - xtype: 'button', - text: _('Change'), - listeners: { - 'click': { - fn: this.onPasswordChange, - scope: this - } - } - }); - - fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: _('Server'), - style: 'margin-top: 0px; padding-top: 0px; margin-bottom: 0px; padding-bottom: 0px', - autoHeight: true, - labelWidth: 110, - defaultType: 'spinnerfield', - defaults: { - width: 80, - } - }); - optMan.bind('session_timeout', fieldset.add({ - name: 'session_timeout', - fieldLabel: _('Session Timeout'), - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - } - })); - optMan.bind('port', fieldset.add({ - name: 'port', - fieldLabel: _('Port'), - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - } - })); - this.httpsField = optMan.bind('https', fieldset.add({ - xtype: 'checkbox', - name: 'https', - hideLabel: true, - width: 280, - height: 22, - boxLabel: _('Use SSL (paths relative to Deluge config folder)') - })); - this.httpsField.on('check', this.onSSLCheck, this); - this.pkeyField = optMan.bind('pkey', fieldset.add({ - xtype: 'textfield', - disabled: true, - name: 'pkey', - width: 180, - fieldLabel: _('Private Key') - })); - this.certField = optMan.bind('cert', fieldset.add({ - xtype: 'textfield', - disabled: true, - name: 'cert', - width: 180, - fieldLabel: _('Certificate') - })); - }, - - onApply: function() { - var changed = this.optionsManager.getDirty(); - if (!Ext.isObjectEmpty(changed)) { - deluge.client.web.set_config(changed, { - success: this.onSetConfig, - scope: this - }); - } - }, - - onGotConfig: function(config) { - this.optionsManager.set(config); - }, - - onPasswordChange: function() { - var newPassword = this.newPassword.getValue(); - if (newPassword != this.confirmPassword.getValue()) { - Ext.MessageBox.show({ - title: _('Invalid Password'), - msg: _('Your passwords don\'t match!'), - buttons: Ext.MessageBox.OK, - modal: false, - icon: Ext.MessageBox.ERROR, - iconCls: 'x-deluge-icon-error' - }); - return; - } - - var oldPassword = this.oldPassword.getValue(); - deluge.client.auth.change_password(oldPassword, newPassword, { - success: function(result) { - if (!result) { - Ext.MessageBox.show({ - title: _('Password'), - msg: _('Your old password was incorrect!'), - buttons: Ext.MessageBox.OK, - modal: false, - icon: Ext.MessageBox.ERROR, - iconCls: 'x-deluge-icon-error' - }); - this.oldPassword.setValue(''); - } else { - Ext.MessageBox.show({ - title: _('Change Successful'), - msg: _('Your password was successfully changed!'), - buttons: Ext.MessageBox.OK, - modal: false, - icon: Ext.MessageBox.INFO, - iconCls: 'x-deluge-icon-info' - }); - this.oldPassword.setValue(''); - this.newPassword.setValue(''); - this.confirmPassword.setValue(''); - } - }, - scope: this - }); - }, - - onSetConfig: function() { - this.optionsManager.commit(); - }, - - onShow: function() { - Deluge.preferences.Interface.superclass.onShow.call(this); - deluge.client.web.get_config({ - success: this.onGotConfig, - scope: this - }) - }, - - onSSLCheck: function(e, checked) { - this.pkeyField.setDisabled(!checked); - this.certField.setDisabled(!checked); - } -}); -deluge.preferences.addPage(new Deluge.preferences.Interface()); -/* -Script: Deluge.Preferences.Other.js - The other preferences page. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - Ext.namespace('Deluge.preferences'); /** @@ -6171,399 +3649,572 @@ Deluge.preferences.Other = Ext.extend(Ext.form.FormPanel, { })); } }); -deluge.preferences.addPage(new Deluge.preferences.Other()); -/* -Script: Deluge.Preferences.Daemon.js - The daemon preferences page. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - +/*! + * Deluge.preferences.PluginsPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ Ext.namespace('Deluge.preferences'); /** - * @class Deluge.preferences.Daemon - * @extends Ext.form.FormPanel + * @class Deluge.preferences.Plugins + * @extends Ext.Panel */ -Deluge.preferences.Daemon = Ext.extend(Ext.form.FormPanel, { - constructor: function(config) { - config = Ext.apply({ +Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { + + layout: 'border', + title: _('Plugins'), + border: false, + height: 400, + cls: 'x-deluge-plugins', + + pluginTemplate: new Ext.Template( + '
' + + '
Author:
{author}
' + + '
Version:
{version}
' + + '
Author Email:
{email}
' + + '
Homepage:
{homepage}
' + + '
Details:
{details}
' + + '
' + ), + + initComponent: function() { + Deluge.preferences.Plugins.superclass.initComponent.call(this); + this.defaultValues = { + 'version': '', + 'email': '', + 'homepage': '', + 'details': '' + }; + this.pluginTemplate.compile(); + + var checkboxRenderer = function(v, p, record){ + p.css += ' x-grid3-check-col-td'; + return '
'; + } + + this.list = this.add({ + xtype: 'listview', + store: new Ext.data.ArrayStore({ + fields: [ + {name: 'enabled', mapping: 0}, + {name: 'plugin', mapping: 1} + ] + }), + columns: [{ + id: 'enabled', + header: _('Enabled'), + width: .2, + sortable: true, + tpl: new Ext.XTemplate('{enabled:this.getCheckbox}', { + getCheckbox: function(v) { + return '
'; + } + }), + dataIndex: 'enabled' + }, { + id: 'plugin', + header: _('Plugin'), + width: .8, + sortable: true, + dataIndex: 'plugin' + }], + singleSelect: true, + autoExpandColumn: 'plugin', + listeners: { + selectionchange: {fn: this.onPluginSelect, scope: this} + } + }); + + this.panel = this.add({ + region: 'center', + autoScroll: true, + margins: '5 5 5 5', + items: [this.list], + bbar: new Ext.Toolbar({ + items: [{ + cls: 'x-btn-text-icon', + iconCls: 'x-deluge-install-plugin', + text: _('Install'), + handler: this.onInstallPluginWindow, + scope: this + }, '->', { + cls: 'x-btn-text-icon', + text: _('Find More'), + iconCls: 'x-deluge-find-more', + handler: this.onFindMorePlugins, + scope: this + }] + }) + }); + + var pp = this.pluginInfo = this.add({ + xtype: 'panel', + border: true, + height: 160, + region: 'south', + margins: '0 5 5 5' + }); + var fieldset = pp.add({ + xtype: 'fieldset', + title: _('Info'), + border: false, + autoHeight: true, + labelWidth: 1, + style: 'margin-top: 5px;' + }); + this.pluginInfo = fieldset.add({ + xtype: 'panel', border: false, - title: _('Daemon'), - layout: 'form' - }, config); - Deluge.preferences.Daemon.superclass.constructor.call(this, config); + bodyCfg: { + style: 'margin-left: 10px' + } + }); + + this.pluginInfo.on('render', this.onPluginInfoRender, this); + this.list.on('click', this.onNodeClick, this); + deluge.preferences.on('show', this.onPreferencesShow, this); + deluge.events.on('PluginDisabledEvent', this.onPluginDisabled, this); + deluge.events.on('PluginEnabledEvent', this.onPluginEnabled, this); + }, + + disablePlugin: function(plugin) { + deluge.client.core.disable_plugin(plugin); + }, + + enablePlugin: function(plugin) { + deluge.client.core.enable_plugin(plugin); + }, + + setInfo: function(plugin) { + if (!this.pluginInfo.rendered) return; + var values = plugin || this.defaultValues; + this.pluginInfo.body.dom.innerHTML = this.pluginTemplate.apply(values); }, - initComponent: function() { - Deluge.preferences.Daemon.superclass.initComponent.call(this); + updatePlugins: function() { + deluge.client.web.get_plugins({ + success: this.onGotPlugins, + scope: this + }); + }, - var optMan = deluge.preferences.getOptionsManager(); - - var fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: _('Port'), - autoHeight: true, - defaultType: 'spinnerfield' + updatePluginsGrid: function() { + var plugins = []; + Ext.each(this.availablePlugins, function(plugin) { + if (this.enabledPlugins.indexOf(plugin) > -1) { + plugins.push([true, plugin]); + } else { + plugins.push([false, plugin]); + } + }, this); + this.list.getStore().loadData(plugins); + }, + + onNodeClick: function(dv, index, node, e) { + var el = new Ext.Element(e.target); + if (el.getAttribute('rel') != 'chkbox') return; + + var r = dv.getStore().getAt(index); + r.set('enabled', !r.get('enabled')); + r.commit(); + if (r.get('enabled')) { + this.enablePlugin(r.get('plugin')); + } else { + this.disablePlugin(r.get('plugin')); + } + }, + + onFindMorePlugins: function() { + window.open('http://dev.deluge-torrent.org/wiki/Plugins'); + }, + + onGotPlugins: function(plugins) { + this.enabledPlugins = plugins.enabled_plugins; + this.availablePlugins = plugins.available_plugins; + this.setInfo(); + this.updatePluginsGrid(); + }, + + onGotPluginInfo: function(info) { + var values = { + author: info['Author'], + version: info['Version'], + email: info['Author-email'], + homepage: info['Home-page'], + details: info['Description'] + } + this.setInfo(values); + delete info; + }, + + onInstallPluginWindow: function() { + if (!this.installWindow) { + this.installWindow = new Deluge.preferences.InstallPluginWindow(); + this.installWindow.on('pluginadded', this.onPluginInstall, this); + } + this.installWindow.show(); + }, + + onPluginEnabled: function(pluginName) { + var index = this.grid.getStore().find('plugin', pluginName); + if (index == -1) return; + var plugin = this.grid.getStore().getAt(index); + plugin.set('enabled', true); + plugin.commit(); + }, + + onPluginDisabled: function(pluginName) { + var index = this.list.getStore().find('plugin', pluginName); + if (index == -1) return; + var plugin = this.list.getStore().getAt(index); + plugin.set('enabled', false); + plugin.commit(); + }, + + onPluginInstall: function() { + this.updatePlugins(); + }, + + onPluginSelect: function(dv, selections) { + var r = dv.getRecords(selections)[0]; + deluge.client.web.get_plugin_info(r.get('plugin'), { + success: this.onGotPluginInfo, + scope: this }); - optMan.bind('daemon_port', fieldset.add({ - fieldLabel: _('Daemon port'), - name: 'daemon_port', - value: 58846, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - }, - })); - - fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: _('Connections'), - autoHeight: true, - labelWidth: 1, - defaultType: 'checkbox' - }); - optMan.bind('allow_remote', fieldset.add({ - fieldLabel: '', - height: 22, - labelSeparator: '', - boxLabel: _('Allow Remote Connections'), - name: 'allow_remote' - })); - - fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: _('Other'), - autoHeight: true, - labelWidth: 1, - defaultType: 'checkbox' - }); - optMan.bind('new_release_check', fieldset.add({ - fieldLabel: '', - labelSeparator: '', - height: 40, - boxLabel: _('Periodically check the website for new releases'), - id: 'new_release_check' - })); + }, + + onPreferencesShow: function() { + this.updatePlugins(); + }, + + onPluginInfoRender: function(ct, position) { + this.setInfo(); } }); -deluge.preferences.addPage(new Deluge.preferences.Daemon()); -/* -Script: Deluge.Preferences.Queue.js - The queue preferences page. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - +/*! + * Deluge.preferences.PreferencesWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ Ext.namespace('Deluge.preferences'); +PreferencesRecord = Ext.data.Record.create([{name:'name', type:'string'}]); + /** - * @class Deluge.preferences.Queue - * @extends Ext.form.FormPanel + * @class Deluge.preferences.PreferencesWindow + * @extends Ext.Window */ -Deluge.preferences.Queue = Ext.extend(Ext.form.FormPanel, { - constructor: function(config) { - config = Ext.apply({ - border: false, - title: _('Queue'), - layout: 'form' - }, config); - Deluge.preferences.Queue.superclass.constructor.call(this, config); - }, - +Deluge.preferences.PreferencesWindow = Ext.extend(Ext.Window, { + + /** + * @property {String} currentPage The currently selected page. + */ + currentPage: null, + + title: _('Preferences'), + layout: 'border', + width: 485, + height: 500, + + buttonAlign: 'right', + closeAction: 'hide', + closable: true, + iconCls: 'x-deluge-preferences', + plain: true, + resizable: false, + + pages: {}, + initComponent: function() { - Deluge.preferences.Queue.superclass.initComponent.call(this); - - var optMan = deluge.preferences.getOptionsManager(); - - var fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: _('General'), - style: 'padding-top: 5px;', - autoHeight: true, - labelWidth: 1, - defaultType: 'checkbox' - }); - optMan.bind('queue_new_to_top', fieldset.add({ - fieldLabel: '', - labelSeparator: '', - height: 22, - boxLabel: _('Queue new torrents to top'), - name: 'queue_new_to_top' - })); - - fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: _('Active Torrents'), - autoHeight: true, - labelWidth: 150, - defaultType: 'spinnerfield', - style: 'margin-bottom: 0px; padding-bottom: 0px;', - }); - optMan.bind('max_active_limit', fieldset.add({ - fieldLabel: _('Total Active'), - name: 'max_active_limit', - value: 8, - width: 80, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 + Deluge.preferences.PreferencesWindow.superclass.initComponent.call(this); + + this.list = new Ext.list.ListView({ + store: new Ext.data.Store(), + columns: [{ + id: 'name', + renderer: fplain, + dataIndex: 'name' + }], + singleSelect: true, + listeners: { + 'selectionchange': { + fn: this.onPageSelect, scope: this + } }, - })); - optMan.bind('max_active_downloading', fieldset.add({ - fieldLabel: _('Total Active Downloading'), - name: 'max_active_downloading', - value: 3, - width: 80, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 + hideHeaders: true, + autoExpandColumn: 'name', + deferredRender: false, + autoScroll: true, + collapsible: true + }); + this.add({ + region: 'west', + title: _('Categories'), + items: [this.list], + width: 120, + margins: '5 0 5 5', + cmargins: '5 0 5 5' + }); + + this.configPanel = this.add({ + type: 'container', + autoDestroy: false, + region: 'center', + layout: 'card', + layoutConfig: { + deferredRender: true }, - })); - optMan.bind('max_active_seeding', fieldset.add({ - fieldLabel: _('Total Active Seeding'), - name: 'max_active_seeding', - value: 5, - width: 80, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - }, - })); - optMan.bind('dont_count_slow_torrents', fieldset.add({ - xtype: 'checkbox', - name: 'dont_count_slow_torrents', - height: 40, - hideLabel: true, - boxLabel: _('Do not count slow torrents') - })); + autoScroll: true, + width: 300, + margins: '5 5 5 5', + cmargins: '5 5 5 5' + }); + + this.addButton(_('Close'), this.onClose, this); + this.addButton(_('Apply'), this.onApply, this); + this.addButton(_('Ok'), this.onOk, this); - fieldset = this.add({ - xtype: 'fieldset', - border: false, - title: _('Seeding'), - autoHeight: true, - labelWidth: 150, - defaultType: 'spinnerfield', - style: 'margin-bottom: 0px; padding-bottom: 0px; margin-top: 0; padding-top: 0;', - }); - optMan.bind('share_ratio_limit', fieldset.add({ - fieldLabel: _('Share Ratio Limit'), - name: 'share_ratio_limit', - value: 8, - width: 80, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - }, - })); - optMan.bind('seed_time_ratio_limit', fieldset.add({ - fieldLabel: _('Share Time Ratio'), - name: 'seed_time_ratio_limit', - value: 3, - width: 80, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - }, - })); - optMan.bind('seed_time_limit', fieldset.add({ - fieldLabel: _('Seed Time (m)'), - name: 'seed_time_limit', - value: 5, - width: 80, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - }, - })); - - fieldset = this.add({ - xtype: 'fieldset', - border: false, - autoHeight: true, - - layout: 'table', - layoutConfig: {columns: 2}, - labelWidth: 0, - defaultType: 'checkbox', - - defaults: { - fieldLabel: '', - labelSeparator: '' - } - }); - this.stopAtRatio = fieldset.add({ - name: 'stop_seed_at_ratio', - boxLabel: _('Stop seeding when share ratio reaches:') - }); - this.stopAtRatio.on('check', this.onStopRatioCheck, this); - optMan.bind('stop_seed_at_ratio', this.stopAtRatio); - - this.stopRatio = fieldset.add({ - xtype: 'spinnerfield', - name: 'stop_seed_ratio', - ctCls: 'x-deluge-indent-checkbox', - disabled: true, - value: 2.0, - width: 60, - strategy: { - xtype: 'number', - minValue: -1, - maxValue: 99999, - incrementValue: 0.1, - alternateIncrementValue: 1, - decimalPrecision: 1 - } - }); - optMan.bind('stop_seed_ratio', this.stopRatio); - - this.removeAtRatio = fieldset.add({ - name: 'remove_seed_at_ratio', - ctCls: 'x-deluge-indent-checkbox', - boxLabel: _('Remove torrent when share ratio is reached'), - disabled: true, - colspan: 2 - }); - optMan.bind('remove_seed_at_ratio', this.removeAtRatio); + this.optionsManager = new Deluge.OptionsManager(); + this.on('afterrender', this.onAfterRender, this); + this.on('show', this.onShow, this); + + this.initPages(); + }, + + initPages: function() { + deluge.preferences = this; + this.addPage(new Deluge.preferences.Downloads()); + this.addPage(new Deluge.preferences.Network()); + this.addPage(new Deluge.preferences.Encryption()); + this.addPage(new Deluge.preferences.Bandwidth()); + this.addPage(new Deluge.preferences.Interface()); + this.addPage(new Deluge.preferences.Other()); + this.addPage(new Deluge.preferences.Daemon()); + this.addPage(new Deluge.preferences.Queue()); + this.addPage(new Deluge.preferences.Proxy()); + this.addPage(new Deluge.preferences.Cache()); + this.addPage(new Deluge.preferences.Plugins()); }, - onStopRatioCheck: function(e, checked) { - this.stopRatio.setDisabled(!checked); - this.removeAtRatio.setDisabled(!checked); + onApply: function(e) { + var changed = this.optionsManager.getDirty(); + if (!Ext.isObjectEmpty(changed)) { + deluge.client.core.set_config(changed, { + success: this.onSetConfig, + scope: this + }); + } + + for (var page in this.pages) { + if (this.pages[page].onApply) this.pages[page].onApply(); + } + }, + + + /** + * Return the options manager for the preferences window. + * @returns {Deluge.OptionsManager} the options manager + */ + getOptionsManager: function() { + return this.optionsManager; + }, + + /** + * Adds a page to the preferences window. + * @param {Mixed} page + */ + addPage: function(page) { + var store = this.list.getStore(); + var name = page.title; + store.add([new PreferencesRecord({name: name})]); + page['bodyStyle'] = 'padding: 5px'; + page.preferences = this; + this.pages[name] = this.configPanel.add(page); + this.pages[name].index = -1; + return this.pages[name]; + }, + + /** + * Removes a preferences page from the window. + * @param {mixed} name + */ + removePage: function(page) { + var name = page.title; + var store = this.list.getStore(); + store.removeAt(store.find('name', name)); + this.configPanel.remove(page); + delete this.pages[page.title]; + }, + + /** + * Select which preferences page is displayed. + * @param {String} page The page name to change to + */ + selectPage: function(page) { + if (this.pages[page].index < 0) { + this.pages[page].index = this.configPanel.items.indexOf(this.pages[page]); + } + this.list.select(this.pages[page].index); + }, + + // private + doSelectPage: function(page) { + if (this.pages[page].index < 0) { + this.pages[page].index = this.configPanel.items.indexOf(this.pages[page]); + } + this.configPanel.getLayout().setActiveItem(this.pages[page].index); + this.currentPage = page; + }, + + // private + onGotConfig: function(config) { + this.getOptionsManager().set(config); + }, + + // private + onPageSelect: function(list, selections) { + var r = list.getRecord(selections[0]); + this.doSelectPage(r.get('name')); + }, + + // private + onSetConfig: function() { + this.getOptionsManager().commit(); + }, + + // private + onAfterRender: function() { + if (!this.list.getSelectionCount()) { + this.list.select(0); + } + this.configPanel.getLayout().setActiveItem(0); + }, + + // private + onShow: function() { + if (!deluge.client.core) return; + deluge.client.core.get_config({ + success: this.onGotConfig, + scope: this + }) + }, + + // private + onClose: function() { + this.hide(); + }, + + // private + onOk: function() { + deluge.client.core.set_config(this.optionsManager.getDirty()); + this.hide(); } }); -deluge.preferences.addPage(new Deluge.preferences.Queue()); -/* -Script: Deluge.Preferences.Proxy.js - The proxy preferences page. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -Ext.namespace('Deluge.preferences'); +/*! + * Deluge.preferences.ProxyField.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge.preferences'); /** * @class Deluge.preferences.ProxyField - * @extends Ext.form.FormSet + * @extends Ext.form.FieldSet */ Deluge.preferences.ProxyField = Ext.extend(Ext.form.FieldSet, { - constructor: function(config) { - config = Ext.apply({ - border: false, - autoHeight: true, - labelWidth: 70 - }, config); - Deluge.preferences.ProxyField.superclass.constructor.call(this, config); - }, + border: false, + autoHeight: true, + labelWidth: 70, initComponent: function() { Deluge.preferences.ProxyField.superclass.initComponent.call(this); - this.type = this.add({ + this.proxyType = this.add({ xtype: 'combo', fieldLabel: _('Type'), - name: 'type', + name: 'proxytype', mode: 'local', width: 150, - store: new Ext.data.SimpleStore({ + store: new Ext.data.ArrayStore({ fields: ['id', 'text'], data: [ [0, _('None')], @@ -6571,41 +4222,38 @@ Deluge.preferences.ProxyField = Ext.extend(Ext.form.FieldSet, { [2, _('Socksv5')], [3, _('Socksv5 with Auth')], [4, _('HTTP')], - [5, _('HTTP with Auth')], - ] - }), - value: 0, + [5, _('HTTP with Auth')] + ] + }), + editable: false, triggerAction: 'all', valueField: 'id', displayField: 'text' - }) + }); this.hostname = this.add({ xtype: 'textfield', name: 'hostname', fieldLabel: _('Host'), width: 220 }); - + this.port = this.add({ xtype: 'spinnerfield', name: 'port', fieldLabel: _('Port'), width: 80, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - } + decimalPrecision: 0, + minValue: -1, + maxValue: 99999 }); - - this.username = this.add({ + + this.username = this.add({ xtype: 'textfield', name: 'username', fieldLabel: _('Username'), width: 220 }); - + this.password = this.add({ xtype: 'textfield', name: 'password', @@ -6613,19 +4261,19 @@ Deluge.preferences.ProxyField = Ext.extend(Ext.form.FieldSet, { inputType: 'password', width: 220 }); - - this.type.on('change', this.onFieldChange, this); - this.type.on('select', this.onTypeSelect, this); + + this.proxyType.on('change', this.onFieldChange, this); + this.proxyType.on('select', this.onTypeSelect, this); this.setting = false; }, - + getName: function() { return this.initialConfig.name; }, - + getValue: function() { return { - 'type': this.type.getValue(), + 'type': this.proxyType.getValue(), 'hostname': this.hostname.getValue(), 'port': Number(this.port.getValue()), 'username': this.username.getValue(), @@ -6636,10 +4284,10 @@ Deluge.preferences.ProxyField = Ext.extend(Ext.form.FieldSet, { // Set the values of the proxies setValue: function(value) { this.setting = true; - this.type.setValue(value['type']); - var index = this.type.getStore().find('id', value['type']); - var record = this.type.getStore().getAt(index); - + this.proxyType.setValue(value['type']); + var index = this.proxyType.getStore().find('id', value['type']); + var record = this.proxyType.getStore().getAt(index); + this.hostname.setValue(value['hostname']); this.port.setValue(value['port']); this.username.setValue(value['username']); @@ -6647,16 +4295,16 @@ Deluge.preferences.ProxyField = Ext.extend(Ext.form.FieldSet, { this.onTypeSelect(this.type, record, index); this.setting = false; }, - + onFieldChange: function(field, newValue, oldValue) { if (this.setting) return; var newValues = this.getValue(); var oldValues = Ext.apply({}, newValues); oldValues[field.getName()] = oldValue; - + this.fireEvent('change', this, newValues, oldValues); }, - + onTypeSelect: function(combo, record, index) { var typeId = record.get('id'); if (typeId > 0) { @@ -6666,7 +4314,7 @@ Deluge.preferences.ProxyField = Ext.extend(Ext.form.FieldSet, { this.hostname.hide(); this.port.hide(); } - + if (typeId == 3 || typeId == 5) { this.username.show(); this.password.show(); @@ -6676,6 +4324,38 @@ Deluge.preferences.ProxyField = Ext.extend(Ext.form.FieldSet, { } } }); +/*! + * Deluge.preferences.ProxyPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Deluge.preferences'); /** * @class Deluge.preferences.Proxy @@ -6743,499 +4423,3532 @@ Deluge.preferences.Proxy = Ext.extend(Ext.form.FormPanel, { this.fireEvent('change', this, newValues, oldValues); } }); -deluge.preferences.addPage(new Deluge.preferences.Proxy()); -/* -Script: deluge.preferences.Cache.js - The cache preferences page. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - +/*! + * Deluge.preferences.QueuePage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ Ext.namespace('Deluge.preferences'); /** - * @class Deluge.preferences.Cache + * @class Deluge.preferences.Queue * @extends Ext.form.FormPanel */ -Deluge.preferences.Cache = Ext.extend(Ext.form.FormPanel, { - constructor: function(config) { - config = Ext.apply({ - border: false, - title: _('Cache'), - layout: 'form' - }, config); - Deluge.preferences.Cache.superclass.constructor.call(this, config); - }, +Deluge.preferences.Queue = Ext.extend(Ext.form.FormPanel, { + + border: false, + title: _('Queue'), + layout: 'form', initComponent: function() { - Deluge.preferences.Cache.superclass.initComponent.call(this); - - var optMan = deluge.preferences.getOptionsManager(); + Deluge.preferences.Queue.superclass.initComponent.call(this); + + var om = deluge.preferences.getOptionsManager(); var fieldset = this.add({ xtype: 'fieldset', border: false, - title: _('Settings'), + title: _('General'), + style: 'padding-top: 5px;', autoHeight: true, - labelWidth: 180, - defaultType: 'spinnerfield' + labelWidth: 1, + defaultType: 'checkbox' }); - optMan.bind('cache_size', fieldset.add({ - fieldLabel: _('Cache Size (16 KiB Blocks)'), - name: 'cache_size', - width: 60, - value: 512, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - }, + om.bind('queue_new_to_top', fieldset.add({ + fieldLabel: '', + labelSeparator: '', + height: 22, + boxLabel: _('Queue new torrents to top'), + name: 'queue_new_to_top' })); - optMan.bind('cache_expiry', fieldset.add({ - fieldLabel: _('Cache Expiry (seconds)'), - name: 'cache_expiry', - width: 60, - value: 60, - strategy: { - xtype: 'number', - decimalPrecision: 0, - minValue: -1, - maxValue: 99999 - }, + + fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Active Torrents'), + autoHeight: true, + labelWidth: 150, + defaultType: 'spinnerfield', + style: 'margin-bottom: 0px; padding-bottom: 0px;' + }); + om.bind('max_active_limit', fieldset.add({ + fieldLabel: _('Total Active'), + name: 'max_active_limit', + value: 8, + width: 80, + decimalPrecision: 0, + minValue: -1, + maxValue: 99999 })); + om.bind('max_active_downloading', fieldset.add({ + fieldLabel: _('Total Active Downloading'), + name: 'max_active_downloading', + value: 3, + width: 80, + decimalPrecision: 0, + minValue: -1, + maxValue: 99999 + })); + om.bind('max_active_seeding', fieldset.add({ + fieldLabel: _('Total Active Seeding'), + name: 'max_active_seeding', + value: 5, + width: 80, + decimalPrecision: 0, + minValue: -1, + maxValue: 99999 + })); + om.bind('dont_count_slow_torrents', fieldset.add({ + xtype: 'checkbox', + name: 'dont_count_slow_torrents', + height: 40, + hideLabel: true, + boxLabel: _('Do not count slow torrents') + })); + + fieldset = this.add({ + xtype: 'fieldset', + border: false, + title: _('Seeding'), + autoHeight: true, + labelWidth: 150, + defaultType: 'spinnerfield', + style: 'margin-bottom: 0px; padding-bottom: 0px; margin-top: 0; padding-top: 0;' + }); + om.bind('share_ratio_limit', fieldset.add({ + fieldLabel: _('Share Ratio Limit'), + name: 'share_ratio_limit', + value: 8, + width: 80, + incrementValue: 0.1, + minValue: -1, + maxValue: 99999, + alternateIncrementValue: 1, + decimalPrecision: 2 + })); + om.bind('seed_time_ratio_limit', fieldset.add({ + fieldLabel: _('Share Time Ratio'), + name: 'seed_time_ratio_limit', + value: 3, + width: 80, + incrementValue: 0.1, + minValue: -1, + maxValue: 99999, + alternateIncrementValue: 1, + decimalPrecision: 2 + })); + om.bind('seed_time_limit', fieldset.add({ + fieldLabel: _('Seed Time (m)'), + name: 'seed_time_limit', + value: 5, + width: 80, + decimalPrecision: 0, + minValue: -1, + maxValue: 99999 + })); + + fieldset = this.add({ + xtype: 'fieldset', + border: false, + autoHeight: true, + + layout: 'table', + layoutConfig: {columns: 2}, + labelWidth: 0, + defaultType: 'checkbox', + + defaults: { + fieldLabel: '', + labelSeparator: '' + } + }); + this.stopAtRatio = fieldset.add({ + name: 'stop_seed_at_ratio', + boxLabel: _('Stop seeding when share ratio reaches:') + }); + this.stopAtRatio.on('check', this.onStopRatioCheck, this); + om.bind('stop_seed_at_ratio', this.stopAtRatio); + + this.stopRatio = fieldset.add({ + xtype: 'spinnerfield', + name: 'stop_seed_ratio', + ctCls: 'x-deluge-indent-checkbox', + disabled: true, + value: '2.0', + width: 60, + incrementValue: 0.1, + minValue: -1, + maxValue: 99999, + alternateIncrementValue: 1, + decimalPrecision: 2 + }); + om.bind('stop_seed_ratio', this.stopRatio); + + this.removeAtRatio = fieldset.add({ + name: 'remove_seed_at_ratio', + ctCls: 'x-deluge-indent-checkbox', + boxLabel: _('Remove torrent when share ratio is reached'), + disabled: true, + colspan: 2 + }); + om.bind('remove_seed_at_ratio', this.removeAtRatio); + }, + + onStopRatioCheck: function(e, checked) { + this.stopRatio.setDisabled(!checked); + this.removeAtRatio.setDisabled(!checked); } }); -deluge.preferences.addPage(new Deluge.preferences.Cache()); -/* -Script: Deluge.Preferences.Plugins.js - The plugins preferences page. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -Ext.namespace('Deluge.preferences'); +/*! + * Deluge.StatusbarMenu.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge'); /** - * @class Deluge.preferences.InstallPluginWindow + * Menu that handles setting the statusbar limits correctly. + * @class Deluge.StatusbarMenu + * @extends Ext.menu.Menu + */ +Deluge.StatusbarMenu = Ext.extend(Ext.menu.Menu, { + + initComponent: function() { + Deluge.StatusbarMenu.superclass.initComponent.call(this); + this.otherWin = new Deluge.OtherLimitWindow(this.initialConfig.otherWin || {}); + + this.items.each(function(item) { + if (item.getXType() != 'menucheckitem') return; + if (item.value == 'other') { + item.on('click', this.onOtherClicked, this); + } else { + item.on('checkchange', this.onLimitChanged, this); + } + }, this); + }, + + setValue: function(value) { + var beenSet = false; + // set the new value + this.value = value = (value == 0) ? -1 : value; + + var other = null; + // uncheck all items + this.items.each(function(item) { + if (item.setChecked) { + item.suspendEvents(); + if (item.value == value) { + item.setChecked(true); + beenSet = true; + } else { + item.setChecked(false); + } + item.resumeEvents(); + } + + if (item.value == 'other') other = item; + }); + + if (beenSet) return; + + other.suspendEvents(); + other.setChecked(true); + other.resumeEvents(); + }, + + onLimitChanged: function(item, checked) { + if (!checked || item.value == 'other') return; // we don't care about unchecks or other + var config = {} + config[item.group] = item.value + deluge.client.core.set_config(config, { + success: function() { + deluge.ui.update(); + } + }); + }, + + onOtherClicked: function(item, e) { + this.otherWin.group = item.group; + this.otherWin.setValue(this.value); + this.otherWin.show(); + } +}); +/*! + * Deluge.OptionsManager.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Deluge'); + +/** + * @class Deluge.OptionsManager + * @extends Ext.util.Observable + * A class that can be used to manage options throughout the ui. + * @constructor + * Creates a new OptionsManager + * @param {Object} config Configuration options + */ +Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { + + constructor: function(config) { + config = config || {}; + this.binds = {}; + this.changed = {}; + this.options = (config && config['options']) || {}; + this.focused = null; + + this.addEvents({ + /** + * @event add + * Fires when an option is added + */ + 'add': true, + + /** + * @event changed + * Fires when an option is changed + * @param {String} option The changed option + * @param {Mixed} value The options new value + * @param {Mixed} oldValue The options old value + */ + 'changed': true, + + /** + * @event reset + * Fires when the options are reset + */ + 'reset': true + }); + this.on('changed', this.onChange, this); + + Deluge.OptionsManager.superclass.constructor.call(this); + }, + + /** + * Add a set of default options and values to the options manager + * @param {Object} options The default options. + */ + addOptions: function(options) { + this.options = Ext.applyIf(this.options, options); + }, + + /** + * Binds a form field to the specified option. + * @param {String} option + * @param {Ext.form.Field} field + */ + bind: function(option, field) { + this.binds[option] = this.binds[option] || []; + this.binds[option].push(field); + field._doption = option; + + field.on('focus', this.onFieldFocus, this); + field.on('blur', this.onFieldBlur, this); + field.on('change', this.onFieldChange, this); + field.on('check', this.onFieldChange, this); + field.on('spin', this.onFieldChange, this); + return field; + }, + + /** + * Changes all the changed values to be the default values + */ + commit: function() { + this.options = Ext.apply(this.options, this.changed); + this.reset(); + }, + + /** + * Converts the value so it matches the originals type + * @param {Mixed} oldValue The original value + * @param {Mixed} value The new value to convert + */ + convertValueType: function(oldValue, value) { + if (Ext.type(oldValue) != Ext.type(value)) { + switch (Ext.type(oldValue)) { + case 'string': + value = String(value); + break; + case 'number': + value = Number(value); + break; + case 'boolean': + if (Ext.type(value) == 'string') { + value = value.toLowerCase(); + value = (value == 'true' || value == '1' || value == 'on') ? true : false; + } else { + value = Boolean(value); + } + break; + } + } + return value; + }, + + /** + * Get the value for an option or options. + * @param {String} [option] A single option or an array of options to return. + * @returns {Object} the options value. + */ + get: function() { + if (arguments.length == 1) { + var option = arguments[0]; + return (this.isDirty(option)) ? this.changed[option] : this.options[option]; + } else { + var options = {}; + Ext.each(arguments, function(option) { + if (!this.has(option)) return; + options[option] = (this.isDirty(option)) ? this.changed[option] : this.options[option]; + }, this); + return options; + } + }, + + /** + * Get the default value for an option or options. + * @param {String|Array} [option] A single option or an array of options to return. + * @returns {Object} the value of the option + */ + getDefault: function(option) { + return this.options[option]; + }, + + /** + * Returns the dirty (changed) values. + * @returns {Object} the changed options + */ + getDirty: function() { + return this.changed; + }, + + /** + * @param {String} [option] The option to check + * @returns {Boolean} true if the option has been changed from the default. + */ + isDirty: function(option) { + return !Ext.isEmpty(this.changed[option]); + }, + + /** + * Check to see if an option exists in the options manager + * @param {String} option + * @returns {Boolean} true if the option exists, else false. + */ + has: function(option) { + return (this.options[option]); + }, + + /** + * Reset the options back to the default values. + */ + reset: function() { + this.changed = {}; + }, + + /** + * Sets the value of specified option(s) for the passed in id. + * @param {String} option + * @param {Object} value The value for the option + */ + set: function(option, value) { + if (option === undefined) { + return; + } else if (typeof option == 'object') { + var options = option; + this.options = Ext.apply(this.options, options); + for (var option in options) { + this.onChange(option, options[option]); + } + } else { + this.options[option] = value; + this.onChange(option, value) + } + }, + + /** + * Update the value for the specified option and id. + * @param {String/Object} option or options to update + * @param {Object} [value]; + */ + update: function(option, value) { + if (option === undefined) { + return; + } else if (value === undefined) { + for (var key in option) { + this.update(key, option[key]); + } + } else { + var defaultValue = this.getDefault(option); + value = this.convertValueType(defaultValue, value); + + var oldValue = this.get(option); + if (oldValue == value) return; + + if (defaultValue == value) { + if (this.isDirty(option)) delete this.changed[option]; + this.fireEvent('changed', option, value, oldValue); + return; + } + + this.changed[option] = value; + this.fireEvent('changed', option, value, oldValue); + } + }, + + /** + * Lets the option manager know when a field is blurred so if a value + * so value changing operations can continue on that field. + */ + onFieldBlur: function(field, event) { + if (this.focused == field) { + this.focused = null; + } + }, + + /** + * Stops a form fields value from being blocked by the change functions + * @param {Ext.form.Field} field + * @private + */ + onFieldChange: function(field, event) { + if (field.field) field = field.field // fix for spinners + this.update(field._doption, field.getValue()); + }, + + /** + * Lets the option manager know when a field is focused so if a value + * changing operation is performed it won't change the value of the + * field. + */ + onFieldFocus: function(field, event) { + this.focused = field; + }, + + onChange: function(option, newValue, oldValue) { + // If we don't have a bind there's nothing to do. + if (Ext.isEmpty(this.binds[option])) return; + Ext.each(this.binds[option], function(bind) { + // The field is currently focused so we don't want to + // change it. + if (bind == this.focused) return; + // Set the form field to the new value. + bind.setValue(newValue); + }, this); + } +}); +/*! + * Deluge.AddConnectionWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge'); + +/** + * @class Deluge.AddConnectionWindow * @extends Ext.Window */ -Deluge.preferences.InstallPluginWindow = Ext.extend(Ext.Window, { +Deluge.AddConnectionWindow = Ext.extend(Ext.Window, { - height: 115, - width: 350, - - bodyStyle: 'padding: 10px 5px;', - - buttonAlign: 'center', - - closeAction: 'hide', - - iconCls: 'x-deluge-install-plugin', + title: _('Add Connection'), + iconCls: 'x-deluge-add-window-icon', layout: 'fit', + width: 300, + height: 195, - modal: true, - - plain: true, - - title: _('Install Plugin'), + bodyStyle: 'padding: 10px 5px;', + closeAction: 'hide', initComponent: function() { - Deluge.add.FileWindow.superclass.initComponent.call(this); - this.addButton(_('Install'), this.onInstall, this); - + Deluge.AddConnectionWindow.superclass.initComponent.call(this); + + this.addEvents('hostadded'); + + this.addButton(_('Close'), this.hide, this); + this.addButton(_('Add'), this.onAddClick, this); + + this.on('hide', this.onHide, this); + this.form = this.add({ xtype: 'form', + defaultType: 'textfield', baseCls: 'x-plain', - labelWidth: 70, - autoHeight: true, - fileUpload: true, + labelWidth: 60, items: [{ - xtype: 'fileuploadfield', - id: 'pluginEgg', - emptyText: _('Select an egg'), - fieldLabel: _('Plugin Egg'), - name: 'file', - buttonCfg: { - text: _('Browse') + '...' - } + fieldLabel: _('Host'), + name: 'host', + anchor: '75%', + value: '' + }, { + xtype: 'spinnerfield', + fieldLabel: _('Port'), + name: 'port', + strategy: { + xtype: 'number', + decimalPrecision: 0, + minValue: -1, + maxValue: 65535 + }, + value: '58846', + anchor: '40%' + }, { + fieldLabel: _('Username'), + name: 'username', + anchor: '75%', + value: '' + }, { + fieldLabel: _('Password'), + anchor: '75%', + name: 'password', + inputType: 'password', + value: '' }] }); }, - onInstall: function(field, e) { - this.form.getForm().submit({ - url: '/upload', - waitMsg: _('Uploading your plugin...'), - success: this.onUploadSuccess, + onAddClick: function() { + var values = this.form.getForm().getValues(); + deluge.client.web.add_host(values.host, values.port, values.username, values.password, { + success: function(result) { + if (!result[0]) { + Ext.MessageBox.show({ + title: _('Error'), + msg: "Unable to add host: " + result[1], + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error' + }); + } else { + this.fireEvent('hostadded'); + } + this.hide(); + }, scope: this - }); + }); }, - onUploadPlugin: function(info, obj, response, request) { - this.fireEvent('pluginadded'); + onHide: function() { + this.form.getForm().reset(); + } +}); +/*! + * Deluge.AddTrackerWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge'); + +/** + * @class Deluge.AddTrackerWindow + * @extends Ext.Window + */ +Deluge.AddTrackerWindow = Ext.extend(Ext.Window, { + + title: _('Add Tracker'), + layout: 'fit', + width: 375, + height: 150, + plain: true, + closable: true, + resizable: false, + + bodyStyle: 'padding: 5px', + buttonAlign: 'right', + closeAction: 'hide', + iconCls: 'x-deluge-edit-trackers', + + initComponent: function() { + Deluge.AddTrackerWindow.superclass.initComponent.call(this); + + this.addButton(_('Cancel'), this.onCancelClick, this); + this.addButton(_('Add'), this.onAddClick, this); + this.addEvents('add'); + + this.form = this.add({ + xtype: 'form', + defaultType: 'textarea', + baseCls: 'x-plain', + labelWidth: 55, + items: [{ + fieldLabel: _('Trackers'), + name: 'trackers', + anchor: '100%' + }] + }) }, - onUploadSuccess: function(fp, upload) { + onAddClick: function() { + var trackers = this.form.getForm().findField('trackers').getValue(); + trackers = trackers.split('\n'); + + var cleaned = []; + Ext.each(trackers, function(tracker) { + if (Ext.form.VTypes.url(tracker)) { + cleaned.push(tracker); + } + }, this); + this.fireEvent('add', cleaned); this.hide(); - if (upload.result.success) { - var filename = this.form.getForm().findField('pluginEgg').value; - var path = upload.result.files[0] - this.form.getForm().findField('pluginEgg').setValue(''); - deluge.client.web.upload_plugin(filename, path, { - success: this.onUploadPlugin, - scope: this, - filename: filename + this.form.getForm().findField('trackers').setValue(''); + }, + + onCancelClick: function() { + this.form.getForm().findField('trackers').setValue(''); + this.hide(); + } +}); +/*! + * Deluge.Client.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Ext.ux.util'); + +/** + * A class that connects to a json-rpc resource and adds the available + * methods as functions to the class instance. + * @class Ext.ux.util.RpcClient + * @namespace Ext.ux.util + */ +Ext.ux.util.RpcClient = Ext.extend(Ext.util.Observable, { + + _components: [], + + _methods: [], + + _requests: {}, + + _url: null, + + _optionKeys: ['scope', 'success', 'failure'], + + constructor: function(config) { + Ext.ux.util.RpcClient.superclass.constructor.call(this, config); + this._url = config.url || null; + this._id = 0; + + this.addEvents( + // raw events + /** + * @event connected + * Fires when the client has retrieved the list of methods from the server. + * @param {Ext.ux.util.RpcClient} this + */ + 'connected', + + 'error' + ); + this.reloadMethods(); + }, + + reloadMethods: function() { + Ext.each(this._components, function(component) { + delete this[component]; + }, this); + this._execute('system.listMethods', { + success: this._setMethods, + scope: this + }); + }, + + _execute: function(method, options) { + options = options || {}; + options.params = options.params || []; + options.id = this._id; + + var request = Ext.encode({ + method: method, + params: options.params, + id: options.id + }); + this._id++; + + return Ext.Ajax.request({ + url: this._url, + method: 'POST', + success: this._onSuccess, + failure: this._onFailure, + scope: this, + jsonData: request, + options: options + }); + }, + + _onFailure: function(response, requestOptions) { + var options = requestOptions.options; + errorObj = { + id: options.id, + result: null, + error: { + msg: 'HTTP: ' + response.status + ' ' + response.statusText, + code: 255 + } + } + + this.fireEvent('error', errorObj, response, requestOptions) + + if (Ext.type(options.failure) != 'function') return; + if (options.scope) { + options.failure.call(options.scope, errorObj, response, requestOptions); + } else { + options.failure(errorObj, response, requestOptions); + } + }, + + _onSuccess: function(response, requestOptions) { + var responseObj = Ext.decode(response.responseText); + var options = requestOptions.options; + if (responseObj.error) { + this.fireEvent('error', responseObj, response, requestOptions); + + if (Ext.type(options.failure) != 'function') return; + if (options.scope) { + options.failure.call(options.scope, responseObj, response, requestOptions); + } else { + options.failure(responseObj, response, requestOptions); + } + } else { + if (Ext.type(options.success) != 'function') return; + if (options.scope) { + options.success.call(options.scope, responseObj.result, responseObj, response, requestOptions); + } else { + options.success(responseObj.result, responseObj, response, requestOptions); + } + } + }, + + _parseArgs: function(args) { + var params = []; + Ext.each(args, function(arg) { + params.push(arg); + }); + + var options = params[params.length - 1]; + if (Ext.type(options) == 'object') { + var keys = Ext.keys(options), isOption = false; + + Ext.each(this._optionKeys, function(key) { + if (keys.indexOf(key) > -1) isOption = true; + }); + + if (isOption) { + params.remove(options) + } else { + options = {} + } + } else { + options = {} + } + options.params = params; + return options; + }, + + _setMethods: function(methods) { + var components = {}, self = this; + + Ext.each(methods, function(method) { + var parts = method.split('.'); + var component = components[parts[0]] || {}; + + var fn = function() { + var options = self._parseArgs(arguments); + return self._execute(method, options); + } + component[parts[1]] = fn; + components[parts[0]] = component; + }); + + for (var name in components) { + self[name] = components[name]; + } + + this._components = Ext.keys(components); + this.fireEvent('connected', this); + } +}); +/*! + * Deluge.ConnectionManager.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +Deluge.ConnectionManager = Ext.extend(Ext.Window, { + + layout: 'fit', + width: 300, + height: 220, + bodyStyle: 'padding: 10px 5px;', + buttonAlign: 'right', + closeAction: 'hide', + closable: true, + plain: true, + title: _('Connection Manager'), + iconCls: 'x-deluge-connect-window-icon', + + initComponent: function() { + Deluge.ConnectionManager.superclass.initComponent.call(this); + this.on('hide', this.onHide, this); + this.on('show', this.onShow, this); + + deluge.events.on('login', this.onLogin, this); + deluge.events.on('logout', this.onLogout, this); + + this.addButton(_('Close'), this.onClose, this); + this.addButton(_('Connect'), this.onConnect, this); + + this.list = new Ext.list.ListView({ + store: new Ext.data.ArrayStore({ + fields: [ + {name: 'status', mapping: 3}, + {name: 'host', mapping: 1}, + {name: 'port', mapping: 2}, + {name: 'version', mapping: 4} + ], + id: 0 + }), + columns: [{ + header: _('Status'), + width: .24, + sortable: true, + dataIndex: 'status' + }, { + id:'host', + header: _('Host'), + width: .51, + sortable: true, + tpl: '{host}:{port}', + dataIndex: 'host' + }, { + header: _('Version'), + width: .25, + sortable: true, + tpl: '{version}', + dataIndex: 'version' + }], + singleSelect: true, + listeners: { + 'selectionchange': {fn: this.onSelectionChanged, scope: this} + } + }); + + this.panel = this.add({ + autoScroll: true, + items: [this.list], + bbar: new Ext.Toolbar({ + buttons: [ + { + id: 'cm-add', + cls: 'x-btn-text-icon', + text: _('Add'), + iconCls: 'icon-add', + handler: this.onAddClick, + scope: this + }, { + id: 'cm-remove', + cls: 'x-btn-text-icon', + text: _('Remove'), + iconCls: 'icon-remove', + handler: this.onRemoveClick, + disabled: true, + scope: this + }, '->', { + id: 'cm-stop', + cls: 'x-btn-text-icon', + text: _('Stop Daemon'), + iconCls: 'icon-error', + handler: this.onStopClick, + disabled: true, + scope: this + } + ] + }) + }); + this.update = this.update.createDelegate(this); + }, + + /** + * Check to see if the the web interface is currently connected + * to a Deluge Daemon and show the Connection Manager if not. + */ + checkConnected: function() { + deluge.client.web.connected({ + success: function(connected) { + if (connected) { + deluge.events.fire('connect'); + } else { + this.show(); + } + }, + scope: this + }); + }, + + disconnect: function(show) { + deluge.events.fire('disconnect'); + if (show) { + if (this.isVisible()) return; + this.show(); + } + }, + + loadHosts: function() { + deluge.client.web.get_hosts({ + success: this.onGetHosts, + scope: this + }); + }, + + update: function() { + this.list.getStore().each(function(r) { + deluge.client.web.get_host_status(r.id, { + success: this.onGetHostStatus, + scope: this + }); + }, this); + }, + + /** + * Updates the buttons in the Connection Manager UI according to the + * passed in records host state. + * @param {Ext.data.Record} record The hosts record to update the UI for + */ + updateButtons: function(record) { + var button = this.buttons[1], status = record.get('status'); + + // Update the Connect/Disconnect button + if (status == _('Connected')) { + button.enable(); + button.setText(_('Disconnect')); + } else if (status == _('Offline')) { + button.disable(); + } else { + button.enable(); + button.setText(_('Connect')); + } + + // Update the Stop/Start Daemon button + if (status == _('Offline')) { + if (record.get('host') == '127.0.0.1' || record.get('host') == 'localhost') { + this.stopHostButton.enable(); + this.stopHostButton.setText(_('Start Daemon')); + } else { + this.stopHostButton.disable(); + } + } else { + this.stopHostButton.enable(); + this.stopHostButton.setText(_('Stop Daemon')); + } + }, + + // private + onAddClick: function(button, e) { + if (!this.addWindow) { + this.addWindow = new Deluge.AddConnectionWindow(); + this.addWindow.on('hostadded', this.onHostAdded, this); + } + this.addWindow.show(); + }, + + // private + onHostAdded: function() { + this.loadHosts(); + }, + + // private + onClose: function(e) { + this.hide(); + }, + + // private + onConnect: function(e) { + var selected = this.list.getSelectedRecords()[0]; + if (!selected) return; + + if (selected.get('status') == _('Connected')) { + deluge.client.web.disconnect({ + success: function(result) { + this.update(this); + deluge.events.fire('disconnect'); + }, + scope: this + }); + } else { + var id = selected.id; + deluge.client.web.connect(id, { + success: function(methods) { + deluge.client.reloadMethods(); + deluge.client.on('connected', function(e) { + deluge.events.fire('connect'); + }, this, {single: true}); + } + }); + this.hide(); + } + }, + + // private + onGetHosts: function(hosts) { + this.list.getStore().loadData(hosts); + Ext.each(hosts, function(host) { + deluge.client.web.get_host_status(host[0], { + success: this.onGetHostStatus, + scope: this + }); + }, this); + }, + + // private + onGetHostStatus: function(host) { + var record = this.list.getStore().getById(host[0]); + record.set('status', host[3]) + record.set('version', host[4]) + record.commit(); + if (this.list.getSelectedRecords()[0] == record) this.updateButtons(record); + }, + + // private + onHide: function() { + if (this.running) window.clearInterval(this.running); + }, + + // private + onLogin: function() { + if (deluge.config.first_login) { + Ext.MessageBox.confirm('Change password', + 'As this is your first login, we recommend that you ' + + 'change your password. Would you like to ' + + 'do this now?', function(res) { + this.checkConnected(); + if (res == 'yes') { + deluge.preferences.show(); + deluge.preferences.selectPage('Interface'); + } + deluge.client.web.set_config({first_login: false}); + }, this); + } else { + this.checkConnected(); + } + }, + + // private + onLogout: function() { + this.disconnect(); + if (!this.hidden && this.rendered) { + this.hide(); + } + }, + + // private + onRemoveClick: function(button) { + var connection = this.list.getSelectedRecords()[0]; + if (!connection) return; + + deluge.client.web.remove_host(connection.id, { + success: function(result) { + if (!result) { + Ext.MessageBox.show({ + title: _('Error'), + msg: result[1], + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error' + }); + } else { + this.list.getStore().remove(connection); + } + }, + scope: this + }); + }, + + // private + onSelectionChanged: function(list, selections) { + if (selections[0]) { + this.removeHostButton.enable(); + this.stopHostButton.enable(); + this.stopHostButton.setText(_('Stop Daemon')); + this.updateButtons(this.list.getRecord(selections[0])); + } else { + this.removeHostButton.disable(); + this.stopHostButton.disable(); + } + }, + + // private + onShow: function() { + if (!this.addHostButton) { + var bbar = this.panel.getBottomToolbar(); + this.addHostButton = bbar.items.get('cm-add'); + this.removeHostButton = bbar.items.get('cm-remove'); + this.stopHostButton = bbar.items.get('cm-stop'); + } + this.loadHosts(); + this.running = window.setInterval(this.update, 2000, this); + }, + + // private + onStopClick: function(button, e) { + var connection = this.list.getSelectedRecords()[0]; + if (!connection) return; + + if (connection.get('status') == 'Offline') { + // This means we need to start the daemon + deluge.client.web.start_daemon(connection.get('port')); + } else { + // This means we need to stop the daemon + deluge.client.web.stop_daemon(connection.id, { + success: function(result) { + if (!result[0]) { + Ext.MessageBox.show({ + title: _('Error'), + msg: result[1], + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error' + }); + } + } }); } } }); - -/** - * @class Deluge.preferences.Plugins - * @extends Ext.Panel +/*! + * Deluge.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. */ -Deluge.preferences.Plugins = Ext.extend(Ext.Panel, { - constructor: function(config) { - config = Ext.apply({ - border: false, - title: _('Plugins'), - layout: 'border', - height: 400, - cls: 'x-deluge-plugins' - }, config); - Deluge.preferences.Plugins.superclass.constructor.call(this, config); + +// Setup the state manager +Ext.state.Manager.setProvider(new Ext.state.CookieProvider()); + +// Add some additional functions to ext and setup some of the +// configurable parameters +Ext.apply(Ext, { + escapeHTML: function(text) { + text = String(text).replace('<', '<').replace('>', '>'); + return text.replace('&', '&'); }, - pluginTemplate: new Ext.Template( - '
' + - '
Author:
{author}
' + - '
Version:
{version}
' + - '
Author Email:
{email}
' + - '
Homepage:
{homepage}
' + - '
Details:
{details}
' + - '
' - ), + isObjectEmpty: function(obj) { + for(var i in obj) { return false; } + return true; + }, - initComponent: function() { - Deluge.preferences.Plugins.superclass.initComponent.call(this); - this.defaultValues = { - 'version': '', - 'email': '', - 'homepage': '', - 'details': '' - }; - this.pluginTemplate.compile(); - - var checkboxRenderer = function(v, p, record){ - p.css += ' x-grid3-check-col-td'; - return '
'; + isObjectsEqual: function(obj1, obj2) { + var equal = true; + if (!obj1 || !obj2) return false; + for (var i in obj1) { + if (obj1[i] != obj2[i]) { + equal = false; + } } + return equal; + }, - this.grid = this.add({ - xtype: 'grid', - region: 'center', - store: new Ext.data.SimpleStore({ + keys: function(obj) { + var keys = []; + for (var i in obj) if (obj.hasOwnProperty(i)) + { + keys.push(i); + } + return keys; + }, + + values: function(obj) { + var values = []; + for (var i in obj) { + if (obj.hasOwnProperty(i)) { + values.push(obj[i]); + } + } + return values; + }, + + splat: function(obj) { + var type = Ext.type(obj); + return (type) ? ((type != 'array') ? [obj] : obj) : []; + } +}); +Ext.getKeys = Ext.keys; +Ext.BLANK_IMAGE_URL = deluge.config.base + 'images/s.gif'; +Ext.USE_NATIVE_JSON = true; + +// Create the Deluge namespace +Ext.apply(Deluge, { + + // private + pluginStore: {}, + + // private + progressTpl: '
' + + '
' + + '
' + + '
' + + '
{0}
' + + '
' + + '
' + + '
' + + '
{0}
' + + '
' + + '
' + + '
', + + + /** + * A method to create a progress bar that can be used by renderers + * to display a bar within a grid or tree. + * @param {Number} progress The bars progress + * @param {Number} width The width of the bar + * @param {String} text The text to display on the bar + * @param {Number} modified Amount to subtract from the width allowing for fixes + */ + progressBar: function(progress, width, text, modifier) { + modifier = Ext.value(modifier, 10); + var progressWidth = ((width / 100.0) * progress).toFixed(0); + var barWidth = progressWidth - 1; + var textWidth = ((progressWidth - modifier) > 0 ? progressWidth - modifier : 0); + return String.format(Deluge.progressTpl, text, width, barWidth, textWidth); + }, + + /** + * Constructs a new instance of the specified plugin. + * @param {String} name The plugin name to create + */ + createPlugin: function(name) { + return new Deluge.pluginStore[name](); + }, + + /** + * Check to see if a plugin has been registered. + * @param {String} name The plugin name to check + */ + hasPlugin: function(name) { + return (Deluge.pluginStore[name]) ? true : false; + }, + + /** + * Register a plugin with the Deluge interface. + * @param {String} name The plugin name to register + * @param {Plugin} plugin The plugin to register + */ + registerPlugin: function(name, plugin) { + Deluge.pluginStore[name] = plugin; + } + +}); + +// Setup a space for plugins to insert themselves +deluge.plugins = {}; + +// Hinting for gettext_gen.py +// _('Do Not Download') +// _('Normal Priority') +// _('High Priority') +// _('Highest Priority') +FILE_PRIORITY = { + 9: 'Mixed', + 0: 'Do Not Download', + 1: 'Normal Priority', + 2: 'High Priority', + 5: 'Highest Priority', + 'Mixed': 9, + 'Do Not Download': 0, + 'Normal Priority': 1, + 'High Priority': 2, + 'Highest Priority': 5 +} + +FILE_PRIORITY_CSS = { + 9: 'x-mixed-download', + 0: 'x-no-download', + 1: 'x-normal-download', + 2: 'x-high-download', + 5: 'x-highest-download' +} +/*! + * Deluge.EditTrackerWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge'); + +/** + * @class Deluge.EditTrackerWindow + * @extends Ext.Window + */ +Deluge.EditTrackerWindow = Ext.extend(Ext.Window, { + + title: _('Edit Tracker'), + layout: 'fit', + width: 375, + height: 110, + plain: true, + closable: true, + resizable: false, + + bodyStyle: 'padding: 5px', + buttonAlign: 'right', + closeAction: 'hide', + iconCls: 'x-deluge-edit-trackers', + + initComponent: function() { + Deluge.EditTrackerWindow.superclass.initComponent.call(this); + + this.addButton(_('Cancel'), this.onCancelClick, this); + this.addButton(_('Save'), this.onSaveClick, this); + this.on('hide', this.onHide, this); + + this.form = this.add({ + xtype: 'form', + defaultType: 'textfield', + baseCls: 'x-plain', + labelWidth: 55, + items: [{ + fieldLabel: _('Tracker'), + name: 'tracker', + anchor: '100%' + }] + }); + }, + + show: function(record) { + Deluge.EditTrackerWindow.superclass.show.call(this); + + this.record = record; + this.form.getForm().findField('tracker').setValue(record.data['url']); + }, + + onCancelClick: function() { + this.hide(); + }, + + onHide: function() { + this.form.getForm().findField('tracker').setValue(''); + }, + + onSaveClick: function() { + var url = this.form.getForm().findField('tracker').getValue(); + this.record.set('url', url); + this.record.commit(); + this.hide(); + } +}); +/*! + * Deluge.EditTrackers.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge'); + +/** + * @class Deluge.EditTrackerWindow + * @extends Ext.Window + */ +Deluge.EditTrackersWindow = Ext.extend(Ext.Window, { + + title: _('Edit Trackers'), + layout: 'fit', + width: 350, + height: 220, + plain: true, + closable: true, + resizable: false, + + bodyStyle: 'padding: 5px', + buttonAlign: 'right', + closeAction: 'hide', + iconCls: 'x-deluge-edit-trackers', + + initComponent: function() { + Deluge.EditTrackersWindow.superclass.initComponent.call(this); + + this.addButton(_('Cancel'), this.onCancelClick, this); + this.addButton(_('Ok'), this.onOkClick, this); + this.addEvents('save'); + + this.on('show', this.onShow, this); + this.on('save', this.onSave, this); + + this.addWindow = new Deluge.AddTrackerWindow(); + this.addWindow.on('add', this.onAddTrackers, this); + this.editWindow = new Deluge.EditTrackerWindow(); + + this.list = new Ext.list.ListView({ + store: new Ext.data.JsonStore({ + root: 'trackers', fields: [ - {name: 'enabled', mapping: 0}, - {name: 'plugin', mapping: 1} + 'tier', + 'url' ] }), columns: [{ - id: 'enabled', - header: _('Enabled'), - width: 50, - sortable: true, - renderer: checkboxRenderer, - dataIndex: 'enabled' + header: _('Tier'), + width: .1, + dataIndex: 'tier' }, { - id: 'plugin', - header: _('Plugin'), - sortable: true, - dataIndex: 'plugin' - }], + header: _('Tracker'), + width: .9, + dataIndex: 'url' + }], + columnSort: { + sortClasses: ['', ''] + }, stripeRows: true, - selModel: new Ext.grid.RowSelectionModel({ - singleSelect: true, - listeners: { - 'rowselect': { - fn: this.onPluginSelect, + singleSelect: true, + autoScroll: true, + listeners: { + 'dblclick': {fn: this.onListNodeDblClicked, scope: this}, + 'selectionchange': {fn: this.onSelect, scope: this} + } + }); + + this.panel = this.add({ + margins: '0 0 0 0', + items: [this.list], + bbar: new Ext.Toolbar({ + items: [ + { + text: _('Up'), + iconCls: 'icon-up', + handler: this.onUpClick, + scope: this + }, { + text: _('Down'), + iconCls: 'icon-down', + handler: this.onDownClick, + scope: this + }, '->', { + text: _('Add'), + iconCls: 'icon-add', + handler: this.onAddClick, + scope: this + }, { + text: _('Edit'), + iconCls: 'icon-edit-trackers', + handler: this.onEditClick, + scope: this + }, { + text: _('Remove'), + iconCls: 'icon-remove', + handler: this.onRemoveClick, scope: this } - } - }), - autoExpandColumn: 'plugin', - deferredRender: false, - autoScroll: true, - margins: '5 5 5 5', - bbar: new Ext.Toolbar({ - items: [{ - cls: 'x-btn-text-icon', - iconCls: 'x-deluge-install-plugin', - text: _('Install'), - handler: this.onInstallPluginWindow, - scope: this - }, '->', { - cls: 'x-btn-text-icon', - text: _('Find More'), - iconCls: 'x-deluge-find-more', - handler: this.onFindMorePlugins, - scope: this - }] + ] }) }); - - var fieldset = this.add({ - xtype: 'fieldset', - border: false, - region: 'south', - title: _('Info'), - autoHeight: true, - labelWidth: 1 - }); - this.pluginInfo = fieldset.add({ - xtype: 'panel', - border: false, - bodyCfg: { - style: 'margin-left: 10px' - } - }); - - this.on('show', this.onShow, this); - this.pluginInfo.on('render', this.onPluginInfoRender, this); - this.grid.on('cellclick', this.onCellClick, this); - deluge.preferences.on('show', this.onPreferencesShow, this); - deluge.events.on('PluginDisabledEvent', this.onPluginDisabled, this); - deluge.events.on('PluginEnabledEvent', this.onPluginEnabled, this); - }, - - disablePlugin: function(plugin) { - deluge.client.core.disable_plugin(plugin); - }, - - enablePlugin: function(plugin) { - deluge.client.core.enable_plugin(plugin); - }, - - setInfo: function(plugin) { - if (!this.pluginInfo.rendered) return; - var values = plugin || this.defaultValues; - this.pluginInfo.body.dom.innerHTML = this.pluginTemplate.apply(values); }, - updatePlugins: function() { - deluge.client.web.get_plugins({ - success: this.onGotPlugins, - scope: this - }); + onAddClick: function() { + this.addWindow.show(); }, - - updatePluginsGrid: function() { - var plugins = []; - Ext.each(this.availablePlugins, function(plugin) { - if (this.enabledPlugins.indexOf(plugin) > -1) { - plugins.push([true, plugin]); - } else { - plugins.push([false, plugin]); - } + + onAddTrackers: function(trackers) { + var store = this.list.getStore(); + Ext.each(trackers, function(tracker) { + var duplicate = false, heightestTier = -1; + store.each(function(record) { + if (record.get('tier') > heightestTier) { + heightestTier = record.get('tier'); + } + if (tracker == record.get('tracker')) { + duplicate = true; + return false; + } + }, this); + if (duplicate) return; + store.add(new store.recordType({'tier': heightestTier + 1, 'url': tracker})); }, this); - this.grid.getStore().loadData(plugins); - }, - - onCellClick: function(grid, rowIndex, colIndex, e) { - if (colIndex != 0) return; - var r = grid.getStore().getAt(rowIndex); - r.set('enabled', !r.get('enabled')); - r.commit(); - if (r.get('enabled')) { - this.enablePlugin(r.get('plugin')); - } else { - this.disablePlugin(r.get('plugin')); - } - }, - - onFindMorePlugins: function() { - window.open('http://dev.deluge-torrent.org/wiki/Plugins'); - }, - - onGotPlugins: function(plugins) { - this.enabledPlugins = plugins.enabled_plugins; - this.availablePlugins = plugins.available_plugins; - this.setInfo(); - this.updatePluginsGrid(); - }, - - onGotPluginInfo: function(info) { - var values = { - author: info['Author'], - version: info['Version'], - email: info['Author-email'], - homepage: info['Home-page'], - details: info['Description'] - } - this.setInfo(values); - delete info; - }, - - onInstallPluginWindow: function() { - if (!this.installWindow) { - this.installWindow = new Deluge.preferences.InstallPluginWindow(); - this.installWindow.on('pluginadded', this.onPluginInstall, this); - } - this.installWindow.show(); - }, - - onPluginEnabled: function(pluginName) { - var index = this.grid.getStore().find('plugin', pluginName); - var plugin = this.grid.getStore().getAt(index); - plugin.set('enabled', true); - plugin.commit(); }, - onPluginDisabled: function(pluginName) { - var index = this.grid.getStore().find('plugin', pluginName); - var plugin = this.grid.getStore().getAt(index); - plugin.set('enabled', false); - plugin.commit(); + onCancelClick: function() { + this.hide(); + }, + + onEditClick: function() { + this.editWindow.show(this.list.getSelectedRecords()[0]); + }, + + onHide: function() { + this.list.getStore().removeAll(); }, - onPluginInstall: function() { - this.updatePlugins(); + onListNodeDblClicked: function(list, index, node, e) { + this.editWindow.show(this.list.getRecord(node)); }, + + onOkClick: function() { + var trackers = []; + this.list.getStore().each(function(record) { + trackers.push({ + 'tier': record.get('tier'), + 'url': record.get('url') + }) + }, this); + + deluge.client.core.set_torrent_trackers(this.torrentId, trackers, { + failure: this.onSaveFail, + scope: this + }); - onPluginSelect: function(selmodel, rowIndex, r) { - deluge.client.web.get_plugin_info(r.get('plugin'), { - success: this.onGotPluginInfo, + this.hide(); + }, + + onRemoveClick: function() { + // Remove from the grid + this.list.getStore().remove(this.list.getSelectedRecords()[0]); + }, + + onRequestComplete: function(status) { + this.list.getStore().loadData(status); + this.list.getStore().sort('tier', 'ASC'); + }, + + onSaveFail: function() { + + }, + + onSelect: function(list) { + if (list.getSelectionCount()) { + this.panel.getBottomToolbar().items.get(4).enable(); + } + }, + + onShow: function() { + this.panel.getBottomToolbar().items.get(4).disable(); + var r = deluge.torrents.getSelected(); + this.torrentId = r.id; + deluge.client.core.get_torrent_status(r.id, ['trackers'], { + success: this.onRequestComplete, scope: this }); }, - onPreferencesShow: function() { - this.updatePlugins(); + onDownClick: function() { + var r = this.list.getSelectedRecords()[0]; + r.set('tier', r.get('tier') + 1); + r.commit(); + r.store.sort('tier', 'ASC'); }, - onPluginInfoRender: function(ct, position) { - this.setInfo(); + onUpClick: function() { + var r = this.list.getSelectedRecords()[0]; + if (r.get('tier') == 0) return; + r.set('tier', r.get('tier') - 1); + r.commit(); + r.store.sort('tier', 'ASC'); } }); -deluge.preferences.addPage(new Deluge.preferences.Plugins()); -/* -Script: - Deluge.Remove.js - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ +/*! + * Deluge.EventsManager.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ /** - * @class Deluge.RemoveWindow + * @class Deluge.EventsManager + * @extends Ext.util.Observable + *

Deluge.EventsManager is instantated as deluge.events and can be used by components of the UI to fire global events

+ * Class for holding global events that occur within the UI. */ -Deluge.RemoveWindow = Ext.extend(Ext.Window, { +Deluge.EventsManager = Ext.extend(Ext.util.Observable, { + constructor: function() { + this.toRegister = []; + this.on('login', this.onLogin, this); + Deluge.EventsManager.superclass.constructor.call(this); + }, + + /** + * Append an event handler to this object. + */ + addListener: function(eventName, fn, scope, o) { + this.addEvents(eventName); + if (/[A-Z]/.test(eventName.substring(0, 1))) { + if (!deluge.client) { + this.toRegister.push(eventName); + } else { + deluge.client.web.register_event_listener(eventName); + } + } + Deluge.EventsManager.superclass.addListener.call(this, eventName, fn, scope, o); + }, + getEvents: function() { + deluge.client.web.get_events({ + success: this.onGetEventsSuccess, + failure: this.onGetEventsFailure, + scope: this + }); + }, + + /** + * Starts the EventsManagerManager checking for events. + */ + start: function() { + Ext.each(this.toRegister, function(eventName) { + deluge.client.web.register_event_listener(eventName); + }); + this.running = true; + this.errorCount = 0; + this.getEvents(); + }, + + /** + * Stops the EventsManagerManager checking for events. + */ + stop: function() { + this.running = false; + }, + + // private + onLogin: function() { + this.start(); + }, + + onGetEventsSuccess: function(events) { + if (!events) return; + Ext.each(events, function(event) { + var name = event[0], args = event[1]; + args.splice(0, 0, name); + this.fireEvent.apply(this, args); + }, this); + if (this.running) this.getEvents(); + }, + + // private + onGetEventsFailure: function(result, error) { + // the request timed out or we had a communication failure + if (!this.running) return; + if (!error.isTimeout && this.errorCount++ >= 3) { + this.stop(); + return; + } + this.getEvents(); + } +}); + +/** + * Appends an event handler to this object (shorthand for {@link #addListener}) + * @method + */ +Deluge.EventsManager.prototype.on = Deluge.EventsManager.prototype.addListener + +/** + * Fires the specified event with the passed parameters (minus the + * event name). + * @method + */ +Deluge.EventsManager.prototype.fire = Deluge.EventsManager.prototype.fireEvent +deluge.events = new Deluge.EventsManager(); +/*! + * Deluge.FileBrowser.js + * + * Copyright (c) Damien Churchill 2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +Ext.namespace('Deluge'); +Deluge.FileBrowser = Ext.extend(Ext.Window, { + + title: _('File Browser'), + + width: 500, + height: 400, + + initComponent: function() { + Deluge.FileBrowser.superclass.initComponent.call(this); + + this.add({ + xtype: 'toolbar', + items: [{ + text: _('Back'), + iconCls: 'icon-back' + }, { + text: _('Forward'), + iconCls: 'icon-forward' + }, { + text: _('Up'), + iconCls: 'icon-up' + }, { + text: _('Home'), + iconCls: 'icon-home' + }] + }); + } + +}); +/*! + * Deluge.FilterPanel.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge'); + +/** + * @class Deluge.FilterPanel + * @extends Ext.list.ListView + */ +Deluge.FilterPanel = Ext.extend(Ext.Panel, { + + border: false, + + show_zero: null, + + initComponent: function() { + Deluge.FilterPanel.superclass.initComponent.call(this); + this.filterType = this.initialConfig.filter; + + var title = this.filterType.replace('_', ' '), + parts = title.split(' '), + title = ''; + Ext.each(parts, function(p) { + fl = p.substring(0, 1).toUpperCase(); + title += fl + p.substring(1) + ' '; + }); + this.setTitle(_(title)); + + if (Deluge.FilterPanel.templates[this.filterType]) { + var tpl = Deluge.FilterPanel.templates[this.filterType]; + } else { + var tpl = '
{filter} ({count})
'; + } + + this.list = this.add({ + xtype: 'listview', + singleSelect: true, + hideHeaders: true, + reserveScrollOffset: true, + store: new Ext.data.ArrayStore({ + idIndex: 0, + fields: ['filter', 'count'] + }), + columns: [{ + id: 'filter', + sortable: false, + tpl: tpl, + dataIndex: 'filter' + }] + }); + this.relayEvents(this.list, ['selectionchange']); + }, + + /** + * Return the currently selected filter state + * @returns {String} the current filter state + */ + getState: function() { + if (!this.list.getSelectionCount()) return; + + var state = this.list.getSelectedRecords()[0]; + if (state.id == 'All') return; + return state.id; + }, + + /** + * Return the current states in the filter + */ + getStates: function() { + return this.states; + }, + + /** + * Return the Store for the ListView of the FilterPanel + * @returns {Ext.data.Store} the ListView store + */ + getStore: function() { + return this.list.getStore(); + }, + + /** + * Update the states in the FilterPanel + */ + updateStates: function(states) { + this.states = {}; + Ext.each(states, function(state) { + this.states[state[0]] = state[1]; + }, this); + + var show_zero = (this.show_zero == null) ? deluge.config.sidebar_show_zero : this.show_zero; + if (!show_zero) { + var newStates = []; + Ext.each(states, function(state) { + if (state[1] > 0 || state[0] == _('All')) { + newStates.push(state); + } + }); + states = newStates; + } + + var store = this.getStore(); + var filters = {}; + Ext.each(states, function(s, i) { + var record = store.getById(s[0]); + if (!record) { + record = new store.recordType({ + filter: s[0], + count: s[1] + }); + record.id = s[0]; + store.insert(i, record); + } + record.beginEdit(); + record.set('filter', s[0]); + record.set('count', s[1]); + record.endEdit(); + filters[s[0]] = true; + }, this); + + store.each(function(record) { + if (filters[record.id]) return; + var r = this.list.getSelectedRecords()[0]; + store.remove(record); + if (r.id == record.id) { + this.list.select(0); + } + }, this); + + store.commitChanges(); + + if (!this.list.getSelectionCount()) { + this.list.select(0); + } + } + +}); + +Deluge.FilterPanel.templates = { + 'tracker_host': '
{filter} ({count})
' +} +/*! + * Deluge.Formatters.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +/** + * A collection of functions for string formatting values. + * @class Deluge.Formatters + * @author Damien Churchill + * @version 1.3 + * @singleton + */ +Deluge.Formatters = { + /** + * Formats a date string in the locale's date representation based on the + * systems timezone. + * + * @param {Number} timestamp time in seconds since the Epoch + * @return {String} a string in the locale's date representation or "" + * if seconds < 0 + */ + date: function(timestamp) { + function zeroPad(num, count) { + var numZeropad = num + ''; + while (numZeropad.length < count) { + numZeropad = '0' + numZeropad; + } + return numZeropad; + } + timestamp = timestamp * 1000; + var date = new Date(timestamp); + return String.format('{0}/{1}/{2} {3}:{4}:{5}', + zeroPad(date.getDate(), 2), zeroPad(date.getMonth() + 1, 2), date.getFullYear(), + zeroPad(date.getHours(), 2), zeroPad(date.getMinutes(), 2), zeroPad(date.getSeconds(), 2)); + }, + + /** + * Formats the bytes value into a string with KiB, MiB or GiB units. + * + * @param {Number} bytes the filesize in bytes + * @param {Boolean} showZero pass in true to displays 0 values + * @return {String} formatted string with KiB, MiB or GiB units. + */ + size: function(bytes, showZero) { + if (!bytes && !showZero) return ''; + bytes = bytes / 1024.0; + + if (bytes < 1024) { return bytes.toFixed(1) + ' KiB'; } + else { bytes = bytes / 1024; } + + if (bytes < 1024) { return bytes.toFixed(1) + ' MiB'; } + else { bytes = bytes / 1024; } + + return bytes.toFixed(1) + ' GiB' + }, + + /** + * Formats a string to display a transfer speed utilizing {@link #size} + * + * @param {Number} bits the number of bits per second + * @param {Boolean} showZero pass in true to displays 0 values + * @return {String} formatted string with KiB, MiB or GiB units. + */ + speed: function(bits, showZero) { + return (!bits && !showZero) ? '' : fsize(bits, showZero) + '/s'; + }, + + /** + * Formats a string to show time in a human readable form. + * + * @param {Number} time the number of seconds + * @return {String} a formatted time string. will return '' if seconds == 0 + */ + timeRemaining: function(time) { + if (time == 0) { return '∞' } + time = time.toFixed(0); + if (time < 60) { return time + 's'; } + else { time = time / 60; } + + if (time < 60) { + var minutes = Math.floor(time) + var seconds = Math.round(60 * (time - minutes)) + if (seconds > 0) { + return minutes + 'm ' + seconds + 's'; + } else { + return minutes + 'm'; } + } + else { time = time / 60; } + + if (time < 24) { + var hours = Math.floor(time) + var minutes = Math.round(60 * (time - hours)) + if (minutes > 0) { + return hours + 'h ' + minutes + 'm'; + } else { + return hours + 'h'; + } + } + else { time = time / 24; } + + var days = Math.floor(time) + var hours = Math.round(24 * (time - days)) + if (hours > 0) { + return days + 'd ' + hours + 'h'; + } else { + return days + 'd'; + } + }, + + /** + * Simply returns the value untouched, for when no formatting is required. + * + * @param {Mixed} value the value to be displayed + * @return the untouched value. + */ + plain: function(value) { + return value; + }, + + cssClassEscape: function(value) { + return value.toLowerCase().replace('.', '_'); + } +} +var fsize = Deluge.Formatters.size; +var fspeed = Deluge.Formatters.speed; +var ftime = Deluge.Formatters.timeRemaining; +var fdate = Deluge.Formatters.date; +var fplain = Deluge.Formatters.plain; +Ext.util.Format.cssClassEscape = Deluge.Formatters.cssClassEscape; +/*! + * Deluge.Keys.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +/** + * @description The torrent status keys that are commonly used around the UI. + * @class Deluge.Keys + * @singleton + */ +Deluge.Keys = { + + /** + * Keys that are used within the torrent grid. + *
['queue', 'name', 'total_size', 'state', 'progress', 'num_seeds',
+	 * 'total_seeds', 'num_peers', 'total_peers', 'download_payload_rate',
+	 * 'upload_payload_rate', 'eta', 'ratio', 'distributed_copies',
+	 * 'is_auto_managed', 'time_added', 'tracker_host']
+ */ + Grid: [ + 'queue', 'name', 'total_size', 'state', 'progress', 'num_seeds', + 'total_seeds', 'num_peers', 'total_peers', 'download_payload_rate', + 'upload_payload_rate', 'eta', 'ratio', 'distributed_copies', + 'is_auto_managed', 'time_added', 'tracker_host', 'save_path' + ], + + /** + * Keys used in the status tab of the statistics panel. + * These get updated to include the keys in {@link #Grid}. + *
['total_done', 'total_payload_download', 'total_uploaded',
+	 * 'total_payload_upload', 'next_announce', 'tracker_status', 'num_pieces',
+	 * 'piece_length', 'is_auto_managed', 'active_time', 'seeding_time',
+	 * 'seed_rank']
+ */ + Status: [ + 'total_done', 'total_payload_download', 'total_uploaded', + 'total_payload_upload', 'next_announce', 'tracker_status', 'num_pieces', + 'piece_length', 'is_auto_managed', 'active_time', 'seeding_time', + 'seed_rank' + ], + + /** + * Keys used in the files tab of the statistics panel. + *
['files', 'file_progress', 'file_priorities']
+ */ + Files: [ + 'files', 'file_progress', 'file_priorities' + ], + + /** + * Keys used in the peers tab of the statistics panel. + *
['peers']
+ */ + Peers: [ + 'peers' + ], + + /** + * Keys used in the details tab of the statistics panel. + */ + Details: [ + 'name', 'save_path', 'total_size', 'num_files', 'tracker_status', + 'tracker', 'comment' + ], + + /** + * Keys used in the options tab of the statistics panel. + *
['max_download_speed', 'max_upload_speed', 'max_connections', 'max_upload_slots',
+	 *  'is_auto_managed', 'stop_at_ratio', 'stop_ratio', 'remove_at_ratio', 'private',
+	 *  'prioritize_first_last']
+ */ + Options: [ + 'max_download_speed', 'max_upload_speed', 'max_connections', + 'max_upload_slots','is_auto_managed', 'stop_at_ratio', 'stop_ratio', + 'remove_at_ratio', 'private', 'prioritize_first_last' + ] +}; + +// Merge the grid and status keys together as the status keys contain all the +// grid ones. +Ext.each(Deluge.Keys.Grid, function(key) { + Deluge.Keys.Status.push(key); +}); +/*! + * Deluge.LoginWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +Deluge.LoginWindow = Ext.extend(Ext.Window, { + + firstShow: true, + bodyStyle: 'padding: 10px 5px;', + buttonAlign: 'center', + closable: false, + closeAction: 'hide', + iconCls: 'x-deluge-login-window-icon', + layout: 'fit', + modal: true, + plain: true, + resizable: false, + title: _('Login'), + width: 300, + height: 120, + + initComponent: function() { + Deluge.LoginWindow.superclass.initComponent.call(this); + this.on('show', this.onShow, this); + + this.addButton({ + text: _('Login'), + handler: this.onLogin, + scope: this + }); + + this.form = this.add({ + xtype: 'form', + baseCls: 'x-plain', + labelWidth: 55, + width: 300, + defaults: {width: 200}, + defaultType: 'textfield' + }); + + this.passwordField = this.form.add({ + xtype: 'textfield', + fieldLabel: _('Password'), + id: '_password', + name: 'password', + inputType: 'password' + }); + this.passwordField.on('specialkey', this.onSpecialKey, this); + }, + + logout: function() { + deluge.events.fire('logout'); + deluge.client.auth.delete_session({ + success: function(result) { + this.show(true); + }, + scope: this + }); + }, + + show: function(skipCheck) { + if (this.firstShow) { + deluge.client.on('error', this.onClientError, this); + this.firstShow = false; + } + + if (skipCheck) { + return Deluge.LoginWindow.superclass.show.call(this); + } + + deluge.client.auth.check_session({ + success: function(result) { + if (result) { + deluge.events.fire('login'); + } else { + this.show(true); + } + }, + failure: function(result) { + this.show(true); + }, + scope: this + }); + }, + + onSpecialKey: function(field, e) { + if (e.getKey() == 13) this.onLogin(); + }, + + onLogin: function() { + var passwordField = this.passwordField; + deluge.client.auth.login(passwordField.getValue(), { + success: function(result) { + if (result) { + deluge.events.fire('login'); + this.hide(); + passwordField.setRawValue(''); + } else { + Ext.MessageBox.show({ + title: _('Login Failed'), + msg: _('You entered an incorrect password'), + buttons: Ext.MessageBox.OK, + modal: false, + fn: function() { + passwordField.focus(true, 10); + }, + icon: Ext.MessageBox.WARNING, + iconCls: 'x-deluge-icon-warning' + }); + } + }, + scope: this + }); + }, + + onClientError: function(errorObj, response, requestOptions) { + if (errorObj.error.code == 1) { + deluge.events.fire('logout'); + this.show(true); + } + }, + + onShow: function() { + this.passwordField.focus(true, true); + } +}); +/*! + * Deluge.Menus.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +deluge.menus = { + onTorrentAction: function(item, e) { + var ids = deluge.torrents.getSelectedIds(); + var action = item.initialConfig.torrentAction; + + switch (action) { + case 'pause': + case 'resume': + deluge.client.core[action + '_torrent'](ids, { + success: function() { + deluge.ui.update(); + } + }); + break; + case 'top': + case 'up': + case 'down': + case 'bottom': + deluge.client.core['queue_' + action](ids, { + success: function() { + deluge.ui.update(); + } + }); + break; + case 'edit_trackers': + deluge.editTrackers.show(); + break; + case 'update': + deluge.client.core.force_reannounce(ids, { + success: function() { + deluge.ui.update(); + } + }); + break; + case 'remove': + deluge.removeWindow.show(ids); + break; + case 'recheck': + deluge.client.core.force_recheck(ids, { + success: function() { + deluge.ui.update(); + } + }); + break; + case 'move': + deluge.moveStorage.show(ids); + break; + } + } +} + +deluge.menus.torrent = new Ext.menu.Menu({ + id: 'torrentMenu', + items: [{ + torrentAction: 'pause', + text: _('Pause'), + iconCls: 'icon-pause', + handler: deluge.menus.onTorrentAction, + scope: deluge.menus + }, { + torrentAction: 'resume', + text: _('Resume'), + iconCls: 'icon-resume', + handler: deluge.menus.onTorrentAction, + scope: deluge.menus + }, '-', { + text: _('Options'), + iconCls: 'icon-options', + menu: new Ext.menu.Menu({ + items: [{ + text: _('D/L Speed Limit'), + iconCls: 'x-deluge-downloading', + menu: new Ext.menu.Menu({ + items: [{ + text: _('5 KiB/s') + }, { + text: _('10 KiB/s') + }, { + text: _('30 KiB/s') + }, { + text: _('80 KiB/s') + }, { + text: _('300 KiB/s') + },{ + text: _('Unlimited') + }] + }) + }, { + text: _('U/L Speed Limit'), + iconCls: 'x-deluge-seeding', + menu: new Ext.menu.Menu({ + items: [{ + text: _('5 KiB/s') + }, { + text: _('10 KiB/s') + }, { + text: _('30 KiB/s') + }, { + text: _('80 KiB/s') + }, { + text: _('300 KiB/s') + },{ + text: _('Unlimited') + }] + }) + }, { + text: _('Connection Limit'), + iconCls: 'x-deluge-connections', + menu: new Ext.menu.Menu({ + items: [{ + text: _('50') + }, { + text: _('100') + }, { + text: _('200') + }, { + text: _('300') + }, { + text: _('500') + },{ + text: _('Unlimited') + }] + }) + }, { + text: _('Upload Slot Limit'), + iconCls: 'icon-upload-slots', + menu: new Ext.menu.Menu({ + items: [{ + text: _('0') + }, { + text: _('1') + }, { + text: _('2') + }, { + text: _('3') + }, { + text: _('5') + },{ + text: _('Unlimited') + }] + }) + }, { + id: 'auto_managed', + text: _('Auto Managed'), + checked: false + }] + }) + }, '-', { + text: _('Queue'), + iconCls: 'icon-queue', + menu: new Ext.menu.Menu({ + items: [{ + torrentAction: 'top', + text: _('Top'), + iconCls: 'icon-top', + handler: deluge.menus.onTorrentAction, + scope: deluge.menus + },{ + torrentAction: 'up', + text: _('Up'), + iconCls: 'icon-up', + handler: deluge.menus.onTorrentAction, + scope: deluge.menus + },{ + torrentAction: 'down', + text: _('Down'), + iconCls: 'icon-down', + handler: deluge.menus.onTorrentAction, + scope: deluge.menus + },{ + torrentAction: 'bottom', + text: _('Bottom'), + iconCls: 'icon-bottom', + handler: deluge.menus.onTorrentAction, + scope: deluge.menus + }] + }) + }, '-', { + torrentAction: 'update', + text: _('Update Tracker'), + iconCls: 'icon-update-tracker', + handler: deluge.menus.onTorrentAction, + scope: deluge.menus + }, { + torrentAction: 'edit_trackers', + text: _('Edit Trackers'), + iconCls: 'icon-edit-trackers', + handler: deluge.menus.onTorrentAction, + scope: deluge.menus + }, '-', { + torrentAction: 'remove', + text: _('Remove Torrent'), + iconCls: 'icon-remove', + handler: deluge.menus.onTorrentAction, + scope: deluge.menus + }, '-', { + torrentAction: 'recheck', + text: _('Force Recheck'), + iconCls: 'icon-recheck', + handler: deluge.menus.onTorrentAction, + scope: deluge.menus + }, { + torrentAction: 'move', + text: _('Move Storage'), + iconCls: 'icon-move', + handler: deluge.menus.onTorrentAction, + scope: deluge.menus + }] +}); + +deluge.menus.filePriorities = new Ext.menu.Menu({ + id: 'filePrioritiesMenu', + items: [{ + id: 'expandAll', + text: _('Expand All'), + iconCls: 'icon-expand-all' + }, '-', { + id: 'no_download', + text: _('Do Not Download'), + iconCls: 'icon-do-not-download', + filePriority: 0 + }, { + id: 'normal', + text: _('Normal Priority'), + iconCls: 'icon-normal', + filePriority: 1 + }, { + id: 'high', + text: _('High Priority'), + iconCls: 'icon-high', + filePriority: 2 + }, { + id: 'highest', + text: _('Highest Priority'), + iconCls: 'icon-highest', + filePriority: 5 + }] +}); +/*! + * Deluge.MoveStorage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +Ext.namespace('Deluge'); +Deluge.MoveStorage = Ext.extend(Ext.Window, { + constructor: function(config) { config = Ext.apply({ - title: _('Remove Torrent'), + title: _('Move Storage'), + width: 375, + height: 110, layout: 'fit', - width: 350, - height: 100, buttonAlign: 'right', closeAction: 'hide', closable: true, + iconCls: 'x-deluge-move-storage', plain: true, - iconCls: 'x-deluge-remove-window-icon' + resizable: false }, config); - Deluge.RemoveWindow.superclass.constructor.call(this, config); + Deluge.MoveStorage.superclass.constructor.call(this, config); }, + + initComponent: function() { + Deluge.MoveStorage.superclass.initComponent.call(this); + + this.addButton(_('Cancel'), this.onCancel, this); + this.addButton(_('Move'), this.onMove, this); + + this.form = this.add({ + xtype: 'form', + border: false, + defaultType: 'textfield', + width: 300, + bodyStyle: 'padding: 5px' + }); + + this.moveLocation = this.form.add({ + fieldLabel: _('Location'), + name: 'location', + width: 240 + }); + //this.form.add({ + // xtype: 'button', + // text: _('Browse'), + // handler: function() { + // if (!this.fileBrowser) { + // this.fileBrowser = new Deluge.FileBrowser(); + // } + // this.fileBrowser.show(); + // }, + // scope: this + //}); + }, + + hide: function() { + Deluge.MoveStorage.superclass.hide.call(this); + this.torrentIds = null; + }, + + show: function(torrentIds) { + Deluge.MoveStorage.superclass.show.call(this); + this.torrentIds = torrentIds; + }, + + onCancel: function() { + this.hide(); + }, + + onMove: function() { + var dest = this.moveLocation.getValue(); + deluge.client.core.move_storage(this.torrentIds, dest); + this.hide(); + } +}); +deluge.moveStorage = new Deluge.MoveStorage(); +/*! + * Deluge.MultiOptionsManager.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +/** + * @description A class that can be used to manage options throughout the ui. + * @namespace Deluge + * @class Deluge.MultiOptionsManager + * @extends Deluge.OptionsManager + */ +Deluge.MultiOptionsManager = Ext.extend(Deluge.OptionsManager, { + + constructor: function(config) { + this.currentId = null; + this.stored = {}; + Deluge.MultiOptionsManager.superclass.constructor.call(this, config); + }, + + /** + * Changes bound fields to use the specified id. + * @param {String} id + */ + changeId: function(id, dontUpdateBinds) { + var oldId = this.currentId; + this.currentId = id; + if (!dontUpdateBinds) { + for (var option in this.options) { + if (!this.binds[option]) continue; + Ext.each(this.binds[option], function(bind) { + bind.setValue(this.get(option)); + }, this); + } + } + return oldId; + }, + + /** + * Changes all the changed values to be the default values + * @param {String} id + */ + commit: function() { + this.stored[this.currentId] = Ext.apply(this.stored[this.currentId], this.changed[this.currentId]); + this.reset(); + }, + + /** + * Get the value for an option + * @param {String/Array} option A single option or an array of options to return. + * @returns {Object} the options value. + */ + get: function() { + if (arguments.length == 1) { + var option = arguments[0]; + return (this.isDirty(option)) ? this.changed[this.currentId][option] : this.getDefault(option); + } else if (arguments.length == 0) { + var options = {}; + for (var option in this.options) { + options[option] = (this.isDirty(option)) ? this.changed[this.currentId][option] : this.getDefault(option); + } + return options; + } else { + var options = {}; + Ext.each(arguments, function(option) { + options[option] = (this.isDirty(option)) ? this.changed[this.currentId][option] : this.getDefault(option); + }, this); + return options; + } + }, + + /** + * Get the default value for an option. + * @param {String} option A single option. + * @returns {Object} the value of the option + */ + getDefault: function(option) { + return (this.has(option)) ? this.stored[this.currentId][option] : this.options[option]; + }, + + /** + * Returns the dirty (changed) values. + * @returns {Object} the changed options + */ + getDirty: function() { + return (this.changed[this.currentId]) ? this.changed[this.currentId] : {}; + }, + + /** + * Check to see if the option has been changed. + * @param {String} option + * @returns {Boolean} true if the option has been changed, else false. + */ + isDirty: function(option) { + return (this.changed[this.currentId] && !Ext.isEmpty(this.changed[this.currentId][option])); + }, + + /** + * Check to see if an id has had an option set to something other than the + * default value. + * @param {String} option + * @returns {Boolean} true if the id has an option, else false. + */ + has: function(option) { + return (this.stored[this.currentId] && !Ext.isEmpty(this.stored[this.currentId][option])); + }, + + /** + * Reset the options back to the default values for the specified id. + */ + reset: function() { + if (this.changed[this.currentId]) delete this.changed[this.currentId]; + if (this.stored[this.currentId]) delete this.stored[this.currentId]; + }, + + /** + * Reset the options back to their defaults for all ids. + */ + resetAll: function() { + this.changed = {}; + this.stored = {}; + this.changeId(null); + }, + + /** + * Sets the value of specified option for the passed in id. + * @param {String} id + * @param {String} option + * @param {Object} value The value for the option + */ + setDefault: function(option, value) { + if (option === undefined) { + return; + } else if (value === undefined) { + for (var key in option) { + this.setDefault(key, option[key]); + } + } else { + var oldValue = this.getDefault(option); + value = this.convertValueType(oldValue, value); + + // If the value is the same as the old value there is + // no point in setting it again. + if (oldValue == value) return; + + // Store the new default + if (!this.stored[this.currentId]) this.stored[this.currentId] = {}; + this.stored[this.currentId][option] = value; + + if (!this.isDirty(option)) { + this.fireEvent('changed', this.currentId, option, value, oldValue); + } + } + }, + + /** + * Update the value for the specified option and id. + * @param {String} id + * @param {String/Object} option or options to update + * @param {Object} [value]; + */ + update: function(option, value) { + if (option === undefined) { + return; + } else if (value === undefined) { + for (var key in option) { + this.update(key, option[key]); + } + } else { + if (!this.changed[this.currentId]) this.changed[this.currentId] = {}; + + var defaultValue = this.getDefault(option); + value = this.convertValueType(defaultValue, value); + + var oldValue = this.get(option); + if (oldValue == value) return; + + if (defaultValue == value) { + if (this.isDirty(option)) delete this.changed[this.currentId][option]; + this.fireEvent('changed', option, value, oldValue); + return; + } else { + this.changed[this.currentId][option] = value; + this.fireEvent('changed', option, value, oldValue); + } + } + } +}); +/*! + * Deluge.OtherLimitWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge'); + +/** + * @class Deluge.OtherLimitWindow + * @extends Ext.Window + */ +Deluge.OtherLimitWindow = Ext.extend(Ext.Window, { + + layout: 'fit', + width: 210, + height: 100, + + closeAction: 'hide', + + initComponent: function() { + Deluge.OtherLimitWindow.superclass.initComponent.call(this); + this.form = this.add({ + xtype: 'form', + baseCls: 'x-plain', + bodyStyle: 'padding: 5px', + layout: 'hbox', + layoutConfig: { + pack: 'start' + }, + items: [{ + xtype: 'spinnerfield', + name: 'limit' + }] + }); + if (this.initialConfig.unit) { + this.form.add({ + border: false, + baseCls: 'x-plain', + bodyStyle: 'padding: 5px', + html: this.initialConfig.unit + }); + } else { + this.setSize(180, 100); + } + + this.addButton(_('Cancel'), this.onCancelClick, this); + this.addButton(_('Ok'), this.onOkClick, this); + this.afterMethod('show', this.doFocusField, this); + }, + + setValue: function(value) { + this.form.getForm().setValues({limit: value}); + }, + + onCancelClick: function() { + this.form.getForm().reset(); + this.hide(); + }, + + onOkClick: function() { + var config = {}; + config[this.group] = this.form.getForm().getValues().limit; + deluge.client.core.set_config(config, { + success: function() { + deluge.ui.update(); + } + }); + this.hide(); + }, + + doFocusField: function() { + this.form.getForm().findField('limit').focus(true, 10); + } +}); +/*! + * Deluge.Plugin.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Deluge'); + +/** + * @class Deluge.Plugin + * @extends Ext.util.Observable + */ +Deluge.Plugin = Ext.extend(Ext.util.Observable, { + + /** + * The plugins name + * @property name + * @type {String} + */ + name: null, + + constructor: function(config) { + this.isDelugePlugin = true; + this.addEvents({ + /** + * @event enabled + * @param {Plugin} plugin the plugin instance + */ + "enabled": true, + + /** + * @event disabled + * @param {Plugin} plugin the plugin instance + */ + "disabled": true + }); + Deluge.Plugin.superclass.constructor.call(this, config); + }, + + /** + * Disables the plugin, firing the "{@link #disabled}" event and + * then executing the plugins clean up method onDisabled. + */ + disable: function() { + this.fireEvent("disabled", this); + if (this.onDisable) this.onDisable(); + }, + + /** + * Enables the plugin, firing the "{@link #enabled}" event and + * then executes the plugins setup method, onEnabled. + */ + enable: function() { + this.fireEvent("enable", this); + if (this.onEnable) this.onEnable(); + }, + + registerTorrentStatus: function(key, header, options) { + options = options || {}; + var cc = options.colCfg || {}, sc = options.storeCfg || {}; + sc = Ext.apply(sc, {name: key}); + deluge.torrents.meta.fields.push(sc); + deluge.torrents.getStore().reader.onMetaChange(deluge.torrents.meta); + + cc = Ext.apply(cc, { + header: header, + dataIndex: key + }); + var cols = deluge.torrents.columns.slice(0); + cols.push(cc); + deluge.torrents.colModel.setConfig(cols); + deluge.torrents.columns = cols; + + Deluge.Keys.Grid.push(key); + deluge.torrents.getView().refresh(true); + }, + + deregisterTorrentStatus: function(key) { + var fields = []; + Ext.each(deluge.torrents.meta.fields, function(field) { + if (field.name != key) fields.push(field); + }); + deluge.torrents.meta.fields = fields; + deluge.torrents.getStore().reader.onMetaChange(deluge.torrents.meta); + + var cols = []; + Ext.each(deluge.torrents.columns, function(col) { + if (col.dataIndex != key) cols.push(col); + }); + deluge.torrents.colModel.setConfig(cols); + deluge.torrents.columns = cols; + + var keys = []; + Ext.each(Deluge.Keys.Grid, function(k) { + if (k == key) keys.push(k); + }); + Deluge.Keys.Grid = keys; + deluge.torrents.getView().refresh(true); + } +}); + +Ext.ns('Deluge.plugins'); +/*! + * Deluge.RemoveWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +/** + * @class Deluge.RemoveWindow + * @extends Ext.Window + */ +Deluge.RemoveWindow = Ext.extend(Ext.Window, { + + title: _('Remove Torrent'), + layout: 'fit', + width: 350, + height: 100, + + buttonAlign: 'right', + closeAction: 'hide', + closable: true, + iconCls: 'x-deluge-remove-window-icon', + plain: true, + + bodyStyle: 'padding: 5px; padding-left: 10px;', + html: 'Are you sure you wish to remove the torrent (s)?', initComponent: function() { Deluge.RemoveWindow.superclass.initComponent.call(this); this.addButton(_('Cancel'), this.onCancel, this); this.addButton(_('Remove With Data'), this.onRemoveData, this); this.addButton(_('Remove Torrent'), this.onRemove, this); - - this.add({ - border: false, - bodyStyle: 'padding: 5px; padding-left: 10px;', - html: 'Are you sure you wish to remove the torrent(s)?' - }); }, remove: function(removeData) { @@ -7277,262 +7990,206 @@ Deluge.RemoveWindow = Ext.extend(Ext.Window, { }); deluge.removeWindow = new Deluge.RemoveWindow(); -/* -Script: Deluge.Sidebar.js - Contains all objects and functions related to the statusbar, toolbar and - sidebar. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. - -*/ +/*! + * Deluge.Sidebar.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ // These are just so gen_gettext.py will pick up the strings // _('State') // _('Tracker Host') -(function() { - // Renderer for the items in the filter grids. - function filterRenderer(value, p, r) { - var lname = value.toLowerCase().replace('.', '_'); +/** + * @class Deluge.Sidebar + * @author Damien Churchill + * @version 1.3 + */ +Deluge.Sidebar = Ext.extend(Ext.Panel, { - var image = ''; - if (r.store.id == 'tracker_host') { - if (value != 'Error') { - image = String.format('url(' + deluge.config.base + 'tracker/{0})', value); - } else { - lname = null; - } - } - if (image) { - return String.format('
{0} ({1})
', value, r.data['count'], image); - } else if (lname) { - return String.format('
{0} ({1})
', value, r.data['count'], lname); - } else { - return String.format('
{0} ({1})
', value, r.data['count']); - } - } + // private + panels: {}, - /** - * @class Deluge.Sidebar - * @author Damien Churchill - * @version 1.3 - */ - Deluge.Sidebar = Ext.extend(Ext.Panel, { + // private + selected: null, - // private - panels: {}, - - // private - selected: null, - - constructor: function(config) { - config = Ext.apply({ - id: 'sidebar', - region: 'west', - cls: 'deluge-sidebar', - title: _('Filters'), - layout: 'accordion', - split: true, - width: 200, - minSize: 175, - collapsible: true, - margins: '5 0 0 5', - cmargins: '5 0 0 5' - }, config); - Deluge.Sidebar.superclass.constructor.call(this, config); - }, - - // private - initComponent: function() { - Deluge.Sidebar.superclass.initComponent.call(this); - deluge.events.on("disconnect", this.onDisconnect, this); - }, - - createFilter: function(filter, states) { - var store = new Ext.data.ArrayStore({ - idIndex: 0, - fields: [ - {name: 'filter'}, - {name: 'count'} - ] - }); - store.id = filter; - - var title = filter.replace('_', ' '); - var parts = title.split(' '); - title = ''; - Ext.each(parts, function(part) { - firstLetter = part.substring(0, 1); - firstLetter = firstLetter.toUpperCase(); - part = firstLetter + part.substring(1); - title += part + ' '; - }); - - var panel = new Ext.grid.GridPanel({ - id: filter + '-panel', - border: false, - store: store, - title: _(title), - columns: [ - {id: 'filter', sortable: false, renderer: filterRenderer, dataIndex: 'filter'} - ], - stripeRows: false, - selModel: new Ext.grid.RowSelectionModel({ - singleSelect: true, - listeners: { - 'rowselect': {fn: this.onFilterSelect, scope: this} - } - }), - hideHeaders: true, - autoExpandColumn: 'filter', - deferredRender: false, - autoScroll: true - }); - - if (deluge.config['sidebar_show_zero'] == false) { - states = this.removeZero(states); - } - - store.loadData(states); - this.add(panel); - - this.doLayout(); - this.panels[filter] = panel; - - panel.getSelectionModel().selectFirstRow(); - }, - - getFilters: function() { - var filters = {} + constructor: function(config) { + config = Ext.apply({ + id: 'sidebar', + region: 'west', + cls: 'deluge-sidebar', + title: _('Filters'), + layout: 'accordion', + split: true, + width: 200, + minSize: 175, + collapsible: true, + margins: '5 0 0 5', + cmargins: '5 0 0 5' + }, config); + Deluge.Sidebar.superclass.constructor.call(this, config); + }, + // private + initComponent: function() { + Deluge.Sidebar.superclass.initComponent.call(this); + deluge.events.on("disconnect", this.onDisconnect, this); + }, + + createFilter: function(filter, states) { + var panel = new Deluge.FilterPanel({ + filter: filter + }); + panel.on('selectionchange', function(view, nodes) { + deluge.ui.update(); + }); + this.add(panel); + + this.doLayout(); + this.panels[filter] = panel; + + panel.header.on('click', function(header) { + if (!deluge.config.sidebar_multiple_filters) { + deluge.ui.update(); + } + if (!panel.list.getSelectionCount()) { + panel.list.select(0); + } + }); + this.fireEvent('filtercreate', this, panel); + + panel.updateStates(states); + this.fireEvent('afterfiltercreate', this, panel); + }, + + getFilter: function(filter) { + return this.panels[filter]; + }, + + getFilterStates: function() { + var states = {} + + if (deluge.config.sidebar_multiple_filters) { // Grab the filters from each of the filter panels this.items.each(function(panel) { - var sm = panel.getSelectionModel(); - - if (!sm.hasSelection()) return; - - var filter = sm.getSelected(); - var filterType = panel.getStore().id; - - if (filter.id == "All") return; - - filters[filterType] = filter.id; + var state = panel.getState(); + if (state == null) return; + states[panel.filterType] = state; }, this); + } else { + var panel = this.getLayout().activeItem; + if (panel) { + var state = panel.getState(); + if (!state == null) return; + states[panel.filterType] = state; + } + } - return filters; - }, - - // private - onDisconnect: function() { - Ext.each(Ext.getKeys(this.panels), function(filter) { - this.remove(filter + '-panel'); - }, this); - this.panels = {}; - this.selected = null; - }, - - onFilterSelect: function(selModel, rowIndex, record) { - deluge.ui.update(); - }, - - /** - * Remove the states with zero torrents in them. - */ - removeZero: function(states) { - var newStates = []; - Ext.each(states, function(state) { - if (state[1] > 0 || state[0] == _('All')) { - newStates.push(state); - } - }); - return newStates; - }, - - update: function(filters) { - for (var filter in filters) { - var states = filters[filter]; - if (Ext.getKeys(this.panels).indexOf(filter) > -1) { - this.updateFilter(filter, states); - } else { - this.createFilter(filter, states); - } - } - - // Perform a cleanup of fitlers that aren't enabled any more - Ext.each(Ext.keys(this.panels), function(filter) { - if (Ext.keys(filters).indexOf(filter) == -1) { - // We need to remove the panel - this.panels[filter] - } - }, this); - }, - - updateFilter: function(filter, states) { - if (deluge.config.sidebar_show_zero == false) { - states = this.removeZero(states); - } + return states; + }, - var store = this.panels[filter].getStore(); - var filters = []; - Ext.each(states, function(s, i) { - var record = store.getById(s[0]); - if (!record) { - record = new store.recordType({ - filter: s[0], - count: s[1] - }); - record.id = s[0]; - store.insert(i, [record]); - } - record.beginEdit(); - record.set('filter', s[0]); - record.set('count', s[1]); - record.endEdit(); - filters[s[0]] = true; - }, this); + hasFilter: function(filter) { + return (this.panels[filter]) ? true : false; + }, - store.each(function(record) { - if (filters[record.id]) return; + // private + onDisconnect: function() { + for (var filter in this.panels) { + this.remove(this.panels[filter]); + } + this.panels = {}; + this.selected = null; + }, - store.remove(record); - }, this); + onFilterSelect: function(selModel, rowIndex, record) { + deluge.ui.update(); + }, + + update: function(filters) { + for (var filter in filters) { + var states = filters[filter]; + if (Ext.getKeys(this.panels).indexOf(filter) > -1) { + this.panels[filter].updateStates(states); + } else { + this.createFilter(filter, states); + } + } + + // Perform a cleanup of fitlers that aren't enabled any more + Ext.each(Ext.keys(this.panels), function(filter) { + if (Ext.keys(filters).indexOf(filter) == -1) { + // We need to remove the panel + this.remove(this.panels[filter]); + this.doLayout(); + delete this.panels[filter]; + } + }, this); + } +}); +/*! + * Deluge.Statusbar.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace('Deluge'); - store.commitChanges(); - } - }); - deluge.sidebar = new Deluge.Sidebar(); -})(); Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { constructor: function(config) { config = Ext.apply({ id: 'deluge-statusbar', - defaultIconCls: 'x-not-connected', + defaultIconCls: 'x-deluge-statusbar x-not-connected', defaultText: _('Not Connected') }, config); Deluge.Statusbar.superclass.constructor.call(this, config); @@ -7552,27 +8209,153 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { cls: 'x-btn-text-icon', iconCls: 'x-deluge-connections', tooltip: _('Connections'), - menu: deluge.menus.connections + menu: new Deluge.StatusbarMenu({ + items: [{ + text: '50', + value: '50', + group: 'max_connections_global', + checked: false + },{ + text: '100', + value: '100', + group: 'max_connections_global', + checked: false + },{ + text: '200', + value: '200', + group: 'max_connections_global', + checked: false + },{ + text: '300', + value: '300', + group: 'max_connections_global', + checked: false + },{ + text: '500', + value: '500', + group: 'max_connections_global', + checked: false + },{ + text: _('Unlimited'), + value: '-1', + group: 'max_connections_global', + checked: false + },'-',{ + text: _('Other'), + value: 'other', + group: 'max_connections_global', + checked: false + }], + otherWin: { + title: _('Set Maximum Connections') + } + }) }, '-', { id: 'statusbar-downspeed', text: ' ', cls: 'x-btn-text-icon', iconCls: 'x-deluge-downloading', tooltip: _('Download Speed'), - menu: deluge.menus.download + menu: new Deluge.StatusbarMenu({ + items: [{ + value: '5', + text: '5 KiB/s', + group: 'max_download_speed', + checked: false + },{ + value: '10', + text: '10 KiB/s', + group: 'max_download_speed', + checked: false + },{ + value: '30', + text: '30 KiB/s', + group: 'max_download_speed', + checked: false + },{ + value: '80', + text: '80 KiB/s', + group: 'max_download_speed', + checked: false + },{ + value: '300', + text: '300 KiB/s', + group: 'max_download_speed', + checked: false + },{ + value: '-1', + text: _('Unlimited'), + group: 'max_download_speed', + checked: false + },'-',{ + value: 'other', + text: _('Other'), + group: 'max_download_speed', + checked: false + }], + otherWin: { + title: _('Set Maximum Download Speed'), + unit: _('Kib/s') + } + }) }, '-', { id: 'statusbar-upspeed', text: ' ', cls: 'x-btn-text-icon', iconCls: 'x-deluge-seeding', tooltip: _('Upload Speed'), - menu: deluge.menus.upload + menu: new Deluge.StatusbarMenu({ + items: [{ + value: '5', + text: '5 KiB/s', + group: 'max_upload_speed', + checked: false + },{ + value: '10', + text: '10 KiB/s', + group: 'max_upload_speed', + checked: false + },{ + value: '30', + text: '30 KiB/s', + group: 'max_upload_speed', + checked: false + },{ + value: '80', + text: '80 KiB/s', + group: 'max_upload_speed', + checked: false + },{ + value: '300', + text: '300 KiB/s', + group: 'max_upload_speed', + checked: false + },{ + value: '-1', + text: _('Unlimited'), + group: 'max_upload_speed', + checked: false + },'-',{ + value: 'other', + text: _('Other'), + group: 'max_upload_speed', + checked: false + }], + otherWin: { + title: _('Set Maximum Upload Speed'), + unit: _('Kib/s') + } + }) }, '-', { id: 'statusbar-traffic', text: ' ', cls: 'x-btn-text-icon', iconCls: 'x-deluge-traffic', - tooltip: _('Protocol Traffic Download/Upload') + tooltip: _('Protocol Traffic Download/Upload'), + handler: function() { + deluge.preferences.show(); + deluge.preferences.selectPage('Network'); + } }, '-', { id: 'statusbar-dht', text: ' ', @@ -7584,7 +8367,11 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { text: ' ', cls: 'x-btn-text-icon', iconCls: 'x-deluge-freespace', - tooltip: _('Freespace in download location') + tooltip: _('Freespace in download location'), + handler: function() { + deluge.preferences.show(); + deluge.preferences.selectPage('Downloads'); + } }); this.created = true; }, @@ -7629,6 +8416,9 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { var str = (config.value.formatter) ? config.value.formatter(config.value.value, true) : config.value.value; } item.setText(str); + + if (!item.menu) return; + item.menu.setValue(config.limit.value); }.createDelegate(this); updateStat('connections', { @@ -7660,7 +8450,7 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { }, format: '{0} ({1})' }); - + updateStat('traffic', { value: { value: stats.download_protocol_rate, @@ -7675,46 +8465,39 @@ Deluge.Statusbar = Ext.extend(Ext.ux.StatusBar, { this.items.get('statusbar-dht').setText(stats.dht_nodes); this.items.get('statusbar-freespace').setText(fsize(stats.free_space)); - - deluge.menus.connections.setValue(stats.max_num_connections); - deluge.menus.download.setValue(stats.max_download); - deluge.menus.upload.setValue(stats.max_upload); } }); -deluge.statusbar = new Deluge.Statusbar(); -/* -Script: Deluge.Toolbar.js - Contains the Deluge toolbar. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. - -*/ +/*! + * Deluge.Toolbar.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ /** * An extension of the Ext.Toolbar class that provides an extensible toolbar for Deluge. @@ -7878,139 +8661,43 @@ Deluge.Toolbar = Ext.extend(Ext.Toolbar, { }); deluge.toolbar = new Deluge.Toolbar(); -/* -Script: Deluge.Torrent.js - Contains the Deluge.Torrent record. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ - -/** - * Deluge.Torrent record +/*! + * Deluge.TorrentGrid.js + * + * Copyright (c) Damien Churchill 2009-2010 * - * @author Damien Churchill - * @version 1.3 + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. * - * @class Deluge.Torrent - * @extends Ext.data.Record - * @constructor - * @param {Object} data The torrents data + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. */ -Deluge.Torrent = Ext.data.Record.create([{ - name: 'queue', - type: 'int' - }, { - name: 'name', - type: 'string' - }, { - name: 'total_size', - type: 'int' - }, { - name: 'state', - type: 'string' - }, { - name: 'progress', - type: 'int' - }, { - name: 'num_seeds', - type: 'int' - }, { - name: 'total_seeds', - type: 'int' - }, { - name: 'num_peers', - type: 'int' - }, { - name: 'total_peers', - type: 'int' - }, { - name: 'download_payload_rate', - type: 'int' - }, { - name: 'upload_payload_rate', - type: 'int' - }, { - name: 'eta', - type: 'int' - }, { - name: 'ratio', - type: 'float' - }, { - name: 'distributed_copies', - type: 'float' - }, { - name: 'time_added', - type: 'int' - }, { - name: 'tracker_host', - type: 'string' - } -]); -/* -Script: Deluge.Torrents.js - Contains all objects and functions related to the torrent grid. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. - -*/ (function() { /* Renderers for the Torrent Grid */ function queueRenderer(value) { - return (value == 99999) ? '' : value + 1; + return (value == -1) ? '' : value + 1; } function torrentNameRenderer(value, p, r) { return String.format('
{1}
', r.data['state'].toLowerCase(), value); @@ -8041,7 +8728,7 @@ Copyright: } } function availRenderer(value, p, r) { - return (value < 0) ? '∞' : new Number(value).toFixed(3); + return (value < 0) ? '∞' : new Number(value).toFixed(3); } function trackerRenderer(value, p, r) { return String.format('
{0}
', value); @@ -8067,112 +8754,123 @@ Copyright: // object to store contained torrent ids torrents: {}, + columns: [{ + id:'queue', + header: _('#'), + width: 30, + sortable: true, + renderer: queueRenderer, + dataIndex: 'queue' + }, { + id:'name', + header: _('Name'), + width: 150, + sortable: true, + renderer: torrentNameRenderer, + dataIndex: 'name' + }, { + header: _('Size'), + width: 75, + sortable: true, + renderer: fsize, + dataIndex: 'total_size' + }, { + header: _('Progress'), + width: 150, + sortable: true, + renderer: torrentProgressRenderer, + dataIndex: 'progress' + }, { + header: _('Seeders'), + width: 60, + sortable: true, + renderer: seedsRenderer, + dataIndex: 'num_seeds' + }, { + header: _('Peers'), + width: 60, + sortable: true, + renderer: peersRenderer, + dataIndex: 'num_peers' + }, { + header: _('Down Speed'), + width: 80, + sortable: true, + renderer: torrentSpeedRenderer, + dataIndex: 'download_payload_rate' + }, { + header: _('Up Speed'), + width: 80, + sortable: true, + renderer: torrentSpeedRenderer, + dataIndex: 'upload_payload_rate' + }, { + header: _('ETA'), + width: 60, + sortable: true, + renderer: ftime, + dataIndex: 'eta' + }, { + header: _('Ratio'), + width: 60, + sortable: true, + renderer: availRenderer, + dataIndex: 'ratio' + }, { + header: _('Avail'), + width: 60, + sortable: true, + renderer: availRenderer, + dataIndex: 'distributed_copies' + }, { + header: _('Added'), + width: 80, + sortable: true, + renderer: fdate, + dataIndex: 'time_added' + }, { + header: _('Tracker'), + width: 120, + sortable: true, + renderer: trackerRenderer, + dataIndex: 'tracker_host' + }, { + header: _('Save Path'), + width: 120, + sortable: true, + renderer: fplain, + dataIndex: 'save_path' + }], + + meta: { + root: 'torrents', + idProperty: 'id', + fields: [ + {name: 'queue', sortType: Deluge.data.SortTypes.asQueuePosition}, + {name: 'name'}, + {name: 'total_size', type: 'int'}, + {name: 'state'}, + {name: 'progress', type: 'float'}, + {name: 'num_seeds', type: 'int'}, + {name: 'total_seeds', type: 'int'}, + {name: 'num_peers', type: 'int'}, + {name: 'total_peers', type: 'int'}, + {name: 'download_payload_rate', type: 'int'}, + {name: 'upload_payload_speed', type: 'int'}, + {name: 'eta', type: 'int', sortType: etaSorter}, + {name: 'ratio', type: 'float'}, + {name: 'distributed_copies', type: 'float'}, + {name: 'time_added', type: 'int'}, + {name: 'tracker_host'}, + {name: 'save_path'} + ] + }, + constructor: function(config) { config = Ext.apply({ id: 'torrentGrid', - store: new Ext.data.JsonStore({ - root: 'torrents', - idProperty: 'id', - fields: [ - {name: 'queue'}, - {name: 'name'}, - {name: 'total_size', type: 'int'}, - {name: 'state'}, - {name: 'progress', type: 'float'}, - {name: 'num_seeds', type: 'int'}, - {name: 'total_seeds', type: 'int'}, - {name: 'num_peers', type: 'int'}, - {name: 'total_peers', type: 'int'}, - {name: 'download_payload_rate', type: 'int'}, - {name: 'upload_payload_speed', type: 'int'}, - {name: 'eta', type: 'int', sortType: etaSorter}, - {name: 'ratio', type: 'float'}, - {name: 'distributed_copies', type: 'float'}, - {name: 'time_added', type: 'int'}, - {name: 'tracker_host'} - ] - }), - columns: [{ - id:'queue', - header: _('#'), - width: 30, - sortable: true, - renderer: queueRenderer, - dataIndex: 'queue' - }, { - id:'name', - header: _('Name'), - width: 150, - sortable: true, - renderer: torrentNameRenderer, - dataIndex: 'name' - }, { - header: _('Size'), - width: 75, - sortable: true, - renderer: fsize, - dataIndex: 'total_size' - }, { - header: _('Progress'), - width: 150, - sortable: true, - renderer: torrentProgressRenderer, - dataIndex: 'progress' - }, { - header: _('Seeders'), - width: 60, - sortable: true, - renderer: seedsRenderer, - dataIndex: 'num_seeds' - }, { - header: _('Peers'), - width: 60, - sortable: true, - renderer: peersRenderer, - dataIndex: 'num_peers' - }, { - header: _('Down Speed'), - width: 80, - sortable: true, - renderer: torrentSpeedRenderer, - dataIndex: 'download_payload_rate' - }, { - header: _('Up Speed'), - width: 80, - sortable: true, - renderer: torrentSpeedRenderer, - dataIndex: 'upload_payload_rate' - }, { - header: _('ETA'), - width: 60, - sortable: true, - renderer: ftime, - dataIndex: 'eta' - }, { - header: _('Ratio'), - width: 60, - sortable: true, - renderer: availRenderer, - dataIndex: 'ratio' - }, { - header: _('Avail'), - width: 60, - sortable: true, - renderer: availRenderer, - dataIndex: 'distributed_copies' - }, { - header: _('Added'), - width: 80, - sortable: true, - renderer: fdate, - dataIndex: 'time_added' - }, { - header: _('Tracker'), - width: 120, - sortable: true, - renderer: trackerRenderer, - dataIndex: 'tracker_host' - }], + store: new Ext.data.JsonStore(this.meta), + columns: this.columns, region: 'center', cls: 'deluge-torrents', stripeRows: true, @@ -8192,7 +8890,7 @@ Copyright: initComponent: function() { Deluge.TorrentGrid.superclass.initComponent.call(this); deluge.events.on('torrentRemoved', this.onTorrentRemoved, this); - deluge.events.on('logout', this.onDisconnect, this); + deluge.events.on('disconnect', this.onDisconnect, this); this.on('rowcontextmenu', function(grid, rowIndex, e) { e.stopEvent(); @@ -8219,7 +8917,7 @@ Copyright: * @ return {Array/Ext.data.Record} The record(s) representing the rows */ getSelected: function() { - return this.getSelectionModel().getSelected(); + return this.getSelectionModel().getSelected(); }, /** @@ -8229,6 +8927,26 @@ Copyright: return this.getSelectionModel().getSelections(); }, + /** + * Return the currently selected torrent id. + * @return {String} The currently selected id. + */ + getSelectedId: function() { + return this.getSelectionModel().getSelected().id + }, + + /** + * Return the currently selected torrent ids. + * @return {Array} The currently selected ids. + */ + getSelectedIds: function() { + var ids = []; + Ext.each(this.getSelectionModel().getSelections(), function(r) { + ids.push(r.id); + }); + return ids; + }, + update: function(torrents) { var store = this.getStore(); var newTorrents = []; @@ -8247,7 +8965,7 @@ Copyright: } record.endEdit(); } else { - var record = new Deluge.Torrent(torrent); + var record = new Deluge.data.Torrent(torrent); record.id = t; this.torrents[t] = 1; newTorrents.push(record); @@ -8284,44 +9002,43 @@ Copyright: selModel.deselectRow(this.getStore().indexOf(record)); } this.getStore().remove(record); + delete this.torrents[torrentId]; }, this); } }); deluge.torrents = new Deluge.TorrentGrid(); })(); -/* -Script: Deluge.UI.js - The core ui module that builds up the ui layout and controls the polling - of the server. - -Copyright: - (C) Damien Churchill 2009-2010 - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, write to: - The Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor - Boston, MA 02110-1301, USA. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the OpenSSL - library. - You must obey the GNU General Public License in all respects for all of - the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the file(s), - but you are not obligated to do so. If you do not wish to do so, delete - this exception statement from your version. If you delete this exception - statement from all source files in the program, then also delete it here. -*/ +/*! + * Deluge.UI.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ /** * @static @@ -8340,6 +9057,15 @@ deluge.ui = { * and set up various events that the UI will utilise. */ initialize: function() { + deluge.add = new Deluge.add.AddWindow(); + deluge.details = new Deluge.details.DetailsPanel(); + deluge.connectionManager = new Deluge.ConnectionManager(); + deluge.editTrackers = new Deluge.EditTrackersWindow(); + deluge.login = new Deluge.LoginWindow(); + deluge.preferences = new Deluge.preferences.PreferencesWindow(); + deluge.sidebar = new Deluge.Sidebar(); + deluge.statusbar = new Deluge.Statusbar(); + this.MainPanel = new Ext.Panel({ id: 'mainPanel', iconCls: 'x-deluge-main-panel', @@ -8361,13 +9087,17 @@ deluge.ui = { deluge.events.on("connect", this.onConnect, this); deluge.events.on("disconnect", this.onDisconnect, this); + deluge.events.on('PluginDisabledEvent', this.onPluginDisabled, this); + deluge.events.on('PluginEnabledEvent', this.onPluginEnabled, this); deluge.client = new Ext.ux.util.RpcClient({ url: deluge.config.base + 'json' }); - for (var plugin in deluge.dlugins) { - plugin = deluge.plugins[plugin]; + // enable all the already active plugins + for (var plugin in Deluge.pluginStore) { + plugin = Deluge.createPlugin(plugin); plugin.enable(); + deluge.plugins[plugin.name] = plugin; } // Initialize quicktips so all the tooltip configs start working. @@ -8378,12 +9108,21 @@ deluge.ui = { }, this, {single: true}); this.update = this.update.createDelegate(this); + this.checkConnection = this.checkConnection.createDelegate(this); this.originalTitle = document.title; }, + checkConnection: function() { + deluge.client.web.connected({ + success: this.onConnectionSuccess, + failure: this.onConnectionError, + scope: this + }); + }, + update: function() { - var filters = deluge.sidebar.getFilters(); + var filters = deluge.sidebar.getFilterStates(); deluge.client.web.update_ui(Deluge.Keys.Grid, filters, { success: this.onUpdate, failure: this.onUpdateError, @@ -8392,6 +9131,21 @@ deluge.ui = { deluge.details.update(); }, + onConnectionError: function(error) { + + }, + + onConnectionSuccess: function(result) { + deluge.statusbar.setStatus({ + iconCls: 'x-deluge-statusbar icon-ok', + text: _('Connection restored') + }); + clearInterval(this.checking); + if (!result) { + deluge.connectionManager.show(); + } + }, + onUpdateError: function(error) { if (this.errorCount == 2) { Ext.MessageBox.show({ @@ -8400,6 +9154,11 @@ deluge.ui = { buttons: Ext.MessageBox.OK, icon: Ext.MessageBox.ERROR }); + deluge.events.fire('disconnect'); + deluge.statusbar.setStatus({ + text: 'Lost connection to webserver'} + ); + this.checking = setInterval(this.checkConnection, 2000); } this.errorCount++; }, @@ -8410,7 +9169,10 @@ deluge.ui = { * Updates the various components in the interface. */ onUpdate: function(data) { - if (!data['connected']) deluge.events.fire('disconnect'); + if (!data['connected']) { + deluge.connectionManager.disconnect(true); + return; + } if (deluge.config.show_session_speed) { document.title = this.originalTitle + @@ -8433,6 +9195,10 @@ deluge.ui = { this.running = setInterval(this.update, 2000); this.update(); } + deluge.client.web.get_plugins({ + success: this.onGotPlugins, + scope: this + }); }, /** @@ -8443,15 +9209,29 @@ deluge.ui = { this.stop(); }, + onGotPlugins: function(plugins) { + Ext.each(plugins.enabled_plugins, function(plugin) { + if (deluge.plugins[plugin]) return; + deluge.client.web.get_plugin_resources(plugin, { + success: this.onGotPluginResources, + scope: this + }); + }, this); + }, + onPluginEnabled: function(pluginName) { - deluge.client.web.get_plugin_resources(pluginName, { - success: this.onGotPluginResources, - scope: this - }) + if (deluge.plugins[pluginName]) { + deluge.plugins[pluginName].enable(); + } else { + deluge.client.web.get_plugin_resources(pluginName, { + success: this.onGotPluginResources, + scope: this + }); + } }, onGotPluginResources: function(resources) { - var scripts = (deluge.debug) ? resources.debug_scripts : resources.scripts; + var scripts = (Deluge.debug) ? resources.debug_scripts : resources.scripts; Ext.each(scripts, function(script) { Ext.ux.JSLoader({ url: script, @@ -8467,10 +9247,12 @@ deluge.ui = { onPluginLoaded: function(options) { // This could happen if the plugin has multiple scripts - if (!deluge.plugins[options.pluginName]) return; + if (!Deluge.hasPlugin(options.pluginName)) return; // Enable the plugin - deluge.plugins[options.pluginName].enable(); + plugin = Deluge.createPlugin(options.pluginName); + plugin.enable(); + deluge.plugins[plugin.name] = plugin; }, /** diff --git a/deluge/ui/web/js/deluge-all.js b/deluge/ui/web/js/deluge-all.js index 05991d1b0..8cdee9383 100644 --- a/deluge/ui/web/js/deluge-all.js +++ b/deluge/ui/web/js/deluge-all.js @@ -1 +1,1792 @@ -Ext.state.Manager.setProvider(new Ext.state.CookieProvider());(function(){Ext.apply(Ext,{escapeHTML:function(a){a=String(a).replace("<","<").replace(">",">");return a.replace("&","&")},isObjectEmpty:function(b){for(var a in b){return false}return true},isObjectsEqual:function(d,c){var b=true;if(!d||!c){return false}for(var a in d){if(d[a]!=c[a]){b=false}}return b},keys:function(c){var b=[];for(var a in c){if(c.hasOwnProperty(a)){b.push(a)}}return b},values:function(c){var a=[];for(var b in c){if(c.hasOwnProperty(b)){a.push(c[b])}}return a},splat:function(b){var a=Ext.type(b);return(a)?((a!="array")?[b]:b):[]}});Ext.getKeys=Ext.keys;Ext.BLANK_IMAGE_URL=deluge.config.base+"images/s.gif";Ext.USE_NATIVE_JSON=true})();Deluge={progressTpl:'
{0}
{0}
',progressBar:function(c,e,g,a){a=Ext.value(a,10);var b=((e/100)*c).toFixed(0);var d=b-1;var f=((b-a)>0?b-a:0);return String.format(Deluge.progressTpl,g,e,d,f)}};deluge.plugins={};FILE_PRIORITY={9:"Mixed",0:"Do Not Download",1:"Normal Priority",2:"High Priority",5:"Highest Priority",Mixed:9,"Do Not Download":0,"Normal Priority":1,"High Priority":2,"Highest Priority":5};FILE_PRIORITY_CSS={9:"x-mixed-download",0:"x-no-download",1:"x-normal-download",2:"x-high-download",5:"x-highest-download"};Deluge.Formatters={date:function(c){function b(d,e){var f=d+"";while(f.length0){return b+"m "+d+"s"}else{return b+"m"}}else{c=c/60}if(c<24){var a=Math.floor(c);var b=Math.round(60*(c-a));if(b>0){return a+"h "+b+"m"}else{return a+"h"}}else{c=c/24}var e=Math.floor(c);var a=Math.round(24*(c-e));if(a>0){return e+"d "+a+"h"}else{return e+"d"}},plain:function(a){return a}};var fsize=Deluge.Formatters.size;var fspeed=Deluge.Formatters.speed;var ftime=Deluge.Formatters.timeRemaining;var fdate=Deluge.Formatters.date;var fplain=Deluge.Formatters.plain;Deluge.Keys={Grid:["queue","name","total_size","state","progress","num_seeds","total_seeds","num_peers","total_peers","download_payload_rate","upload_payload_rate","eta","ratio","distributed_copies","is_auto_managed","time_added","tracker_host"],Status:["total_done","total_payload_download","total_uploaded","total_payload_upload","next_announce","tracker_status","num_pieces","piece_length","is_auto_managed","active_time","seeding_time","seed_rank"],Files:["files","file_progress","file_priorities"],Peers:["peers"],Details:["name","save_path","total_size","num_files","tracker_status","tracker","comment"],Options:["max_download_speed","max_upload_speed","max_connections","max_upload_slots","is_auto_managed","stop_at_ratio","stop_ratio","remove_at_ratio","private","prioritize_first_last"]};Ext.each(Deluge.Keys.Grid,function(a){Deluge.Keys.Status.push(a)});deluge.menus={onTorrentAction:function(c,f){var b=deluge.torrents.getSelections();var a=[];Ext.each(b,function(e){a.push(e.id)});var d=c.initialConfig.torrentAction;switch(d){case"pause":case"resume":deluge.client.core[d+"_torrent"](a,{success:function(){deluge.ui.update()}});break;case"top":case"up":case"down":case"bottom":deluge.client.core["queue_"+d](a,{success:function(){deluge.ui.update()}});break;case"edit_trackers":deluge.editTrackers.show();break;case"update":deluge.client.core.force_reannounce(a,{success:function(){deluge.ui.update()}});break;case"remove":deluge.removeWindow.show(a);break;case"recheck":deluge.client.core.force_recheck(a,{success:function(){deluge.ui.update()}});break;case"move":deluge.moveStorage.show(a);break}}};deluge.menus.torrent=new Ext.menu.Menu({id:"torrentMenu",items:[{torrentAction:"pause",text:_("Pause"),iconCls:"icon-pause",handler:deluge.menus.onTorrentAction,scope:deluge.menus},{torrentAction:"resume",text:_("Resume"),iconCls:"icon-resume",handler:deluge.menus.onTorrentAction,scope:deluge.menus},"-",{text:_("Options"),iconCls:"icon-options",menu:new Ext.menu.Menu({items:[{text:_("D/L Speed Limit"),iconCls:"x-deluge-downloading",menu:new Ext.menu.Menu({items:[{text:_("5 KiB/s")},{text:_("10 KiB/s")},{text:_("30 KiB/s")},{text:_("80 KiB/s")},{text:_("300 KiB/s")},{text:_("Unlimited")}]})},{text:_("U/L Speed Limit"),iconCls:"x-deluge-seeding",menu:new Ext.menu.Menu({items:[{text:_("5 KiB/s")},{text:_("10 KiB/s")},{text:_("30 KiB/s")},{text:_("80 KiB/s")},{text:_("300 KiB/s")},{text:_("Unlimited")}]})},{text:_("Connection Limit"),iconCls:"x-deluge-connections",menu:new Ext.menu.Menu({items:[{text:_("50")},{text:_("100")},{text:_("200")},{text:_("300")},{text:_("500")},{text:_("Unlimited")}]})},{text:_("Upload Slot Limit"),iconCls:"icon-upload-slots",menu:new Ext.menu.Menu({items:[{text:_("0")},{text:_("1")},{text:_("2")},{text:_("3")},{text:_("5")},{text:_("Unlimited")}]})},{id:"auto_managed",text:_("Auto Managed"),checked:false}]})},"-",{text:_("Queue"),iconCls:"icon-queue",menu:new Ext.menu.Menu({items:[{torrentAction:"top",text:_("Top"),iconCls:"icon-top",handler:deluge.menus.onTorrentAction,scope:deluge.menus},{torrentAction:"up",text:_("Up"),iconCls:"icon-up",handler:deluge.menus.onTorrentAction,scope:deluge.menus},{torrentAction:"down",text:_("Down"),iconCls:"icon-down",handler:deluge.menus.onTorrentAction,scope:deluge.menus},{torrentAction:"bottom",text:_("Bottom"),iconCls:"icon-bottom",handler:deluge.menus.onTorrentAction,scope:deluge.menus}]})},"-",{torrentAction:"update",text:_("Update Tracker"),iconCls:"icon-update-tracker",handler:deluge.menus.onTorrentAction,scope:deluge.menus},{torrentAction:"edit_trackers",text:_("Edit Trackers"),iconCls:"icon-edit-trackers",handler:deluge.menus.onTorrentAction,scope:deluge.menus},"-",{torrentAction:"remove",text:_("Remove Torrent"),iconCls:"icon-remove",handler:deluge.menus.onTorrentAction,scope:deluge.menus},"-",{torrentAction:"recheck",text:_("Force Recheck"),iconCls:"icon-recheck",handler:deluge.menus.onTorrentAction,scope:deluge.menus},{torrentAction:"move",text:_("Move Storage"),iconCls:"icon-move",handler:deluge.menus.onTorrentAction,scope:deluge.menus}]});Deluge.StatusbarMenu=Ext.extend(Ext.menu.Menu,{setValue:function(b){var c=false;b=(b==0)?-1:b;this.items.each(function(d){if(d.setChecked){d.suspendEvents();if(d.value==b){d.setChecked(true);c=true}else{d.setChecked(false)}d.resumeEvents()}});if(c){return}var a=this.items.get("other");a.suspendEvents();a.setChecked(true);a.resumeEvents()}});deluge.menus.connections=new Deluge.StatusbarMenu({id:"connectionsMenu",items:[{text:"50",value:"50",group:"max_connections_global",checked:false,checkHandler:onLimitChanged},{text:"100",value:"100",group:"max_connections_global",checked:false,checkHandler:onLimitChanged},{text:"200",value:"200",group:"max_connections_global",checked:false,checkHandler:onLimitChanged},{text:"300",value:"300",group:"max_connections_global",checked:false,checkHandler:onLimitChanged},{text:"500",value:"500",group:"max_connections_global",checked:false,checkHandler:onLimitChanged},{text:_("Unlimited"),value:"-1",group:"max_connections_global",checked:false,checkHandler:onLimitChanged},"-",{text:_("Other"),value:"other",group:"max_connections_global",checked:false,checkHandler:onLimitChanged}]});deluge.menus.download=new Deluge.StatusbarMenu({id:"downspeedMenu",items:[{value:"5",text:"5 KiB/s",group:"max_download_speed",checked:false,checkHandler:onLimitChanged},{value:"10",text:"10 KiB/s",group:"max_download_speed",checked:false,checkHandler:onLimitChanged},{value:"30",text:"30 KiB/s",group:"max_download_speed",checked:false,checkHandler:onLimitChanged},{value:"80",text:"80 KiB/s",group:"max_download_speed",checked:false,checkHandler:onLimitChanged},{value:"300",text:"300 KiB/s",group:"max_download_speed",checked:false,checkHandler:onLimitChanged},{value:"-1",text:_("Unlimited"),group:"max_download_speed",checked:false,checkHandler:onLimitChanged},"-",{value:"other",text:_("Other"),group:"max_download_speed",checked:false,checkHandler:onLimitChanged}]});deluge.menus.upload=new Deluge.StatusbarMenu({id:"upspeedMenu",items:[{value:"5",text:"5 KiB/s",group:"max_upload_speed",checked:false,checkHandler:onLimitChanged},{value:"10",text:"10 KiB/s",group:"max_upload_speed",checked:false,checkHandler:onLimitChanged},{value:"30",text:"30 KiB/s",group:"max_upload_speed",checked:false,checkHandler:onLimitChanged},{value:"80",text:"80 KiB/s",group:"max_upload_speed",checked:false,checkHandler:onLimitChanged},{value:"300",text:"300 KiB/s",group:"max_upload_speed",checked:false,checkHandler:onLimitChanged},{value:"-1",text:_("Unlimited"),group:"max_upload_speed",checked:false,checkHandler:onLimitChanged},"-",{value:"other",text:_("Other"),group:"max_upload_speed",checked:false,checkHandler:onLimitChanged}]});deluge.menus.filePriorities=new Ext.menu.Menu({id:"filePrioritiesMenu",items:[{id:"expandAll",text:_("Expand All"),iconCls:"icon-expand-all"},"-",{id:"no_download",text:_("Do Not Download"),iconCls:"icon-do-not-download",filePriority:0},{id:"normal",text:_("Normal Priority"),iconCls:"icon-normal",filePriority:1},{id:"high",text:_("High Priority"),iconCls:"icon-high",filePriority:2},{id:"highest",text:_("Highest Priority"),iconCls:"icon-highest",filePriority:5}]});function onLimitChanged(b,a){if(b.value=="other"){}else{config={};config[b.group]=b.value;deluge.client.core.set_config(config,{success:function(){deluge.ui.update()}})}}Deluge.EventsManager=Ext.extend(Ext.util.Observable,{constructor:function(){this.toRegister=[];this.on("login",this.onLogin,this);Deluge.EventsManager.superclass.constructor.call(this)},addListener:function(a,c,b,d){this.addEvents(a);if(/[A-Z]/.test(a.substring(0,1))){if(!deluge.client){this.toRegister.push(a)}else{deluge.client.web.register_event_listener(a)}}Deluge.EventsManager.superclass.addListener.call(this,a,c,b,d)},getEvents:function(){deluge.client.web.get_events({success:this.onGetEventsSuccess,failure:this.onGetEventsFailure,scope:this})},start:function(){Ext.each(this.toRegister,function(a){deluge.client.web.register_event_listener(a)});this.running=true;this.getEvents()},stop:function(){this.running=false},onLogin:function(){this.start();this.on("PluginEnabledEvent",this.onPluginEnabled,this);this.on("PluginDisabledEvent",this.onPluginDisabled,this)},onGetEventsSuccess:function(a){if(!a){return}Ext.each(a,function(d){var c=d[0],b=d[1];b.splice(0,0,c);this.fireEvent.apply(this,b)},this);if(this.running){this.getEvents()}},onGetEventsFailure:function(a){if(this.running){this.getEvents()}}});Deluge.EventsManager.prototype.on=Deluge.EventsManager.prototype.addListener;Deluge.EventsManager.prototype.fire=Deluge.EventsManager.prototype.fireEvent;deluge.events=new Deluge.EventsManager();Ext.namespace("Deluge");Deluge.OptionsManager=Ext.extend(Ext.util.Observable,{constructor:function(a){a=a||{};this.binds={};this.changed={};this.options=(a&&a.options)||{};this.focused=null;this.addEvents({add:true,changed:true,reset:true});this.on("changed",this.onChange,this);Deluge.OptionsManager.superclass.constructor.call(this)},addOptions:function(a){this.options=Ext.applyIf(this.options,a)},bind:function(a,b){this.binds[a]=this.binds[a]||[];this.binds[a].push(b);b._doption=a;b.on("focus",this.onFieldFocus,this);b.on("blur",this.onFieldBlur,this);b.on("change",this.onFieldChange,this);b.on("check",this.onFieldChange,this);return b},commit:function(){this.options=Ext.apply(this.options,this.changed);this.reset()},convertValueType:function(a,b){if(Ext.type(a)!=Ext.type(b)){switch(Ext.type(a)){case"string":b=String(b);break;case"number":b=Number(b);break;case"boolean":if(Ext.type(b)=="string"){b=b.toLowerCase();b=(b=="true"||b=="1"||b=="on")?true:false}else{b=Boolean(b)}break}}return b},get:function(){if(arguments.length==1){var b=arguments[0];return(this.isDirty(b))?this.changed[b]:this.options[b]}else{var a={};Ext.each(arguments,function(c){if(!this.has(c)){return}a[c]=(this.isDirty(c))?this.changed[c]:this.options[c]},this);return a}},getDefault:function(a){return this.options[a]},getDirty:function(){return this.changed},isDirty:function(a){return !Ext.isEmpty(this.changed[a])},has:function(a){return(this.options[a])},reset:function(){this.changed={}},set:function(b,c){if(b===undefined){return}else{if(typeof b=="object"){var a=b;this.options=Ext.apply(this.options,a);for(var b in a){this.onChange(b,a[b])}}else{this.options[b]=c;this.onChange(b,c)}}},update:function(d,e){if(d===undefined){return}else{if(e===undefined){for(var c in d){this.update(c,d[c])}}else{var a=this.getDefault(d);e=this.convertValueType(a,e);var b=this.get(d);if(b==e){return}if(a==e){if(this.isDirty(d)){delete this.changed[d]}this.fireEvent("changed",d,e,b);return}this.changed[d]=e;this.fireEvent("changed",d,e,b)}}},onFieldBlur:function(b,a){if(this.focused==b){this.focused=null}},onFieldChange:function(b,a){this.update(b._doption,b.getValue())},onFieldFocus:function(b,a){this.focused=b},onChange:function(b,c,a){if(Ext.isEmpty(this.binds[b])){return}Ext.each(this.binds[b],function(d){if(d==this.focused){return}d.setValue(c)},this)}});Deluge.MultiOptionsManager=Ext.extend(Deluge.OptionsManager,{constructor:function(a){this.currentId=null;this.stored={};Deluge.MultiOptionsManager.superclass.constructor.call(this,a)},changeId:function(d,b){var c=this.currentId;this.currentId=d;if(!b){for(var a in this.options){if(!this.binds[a]){continue}Ext.each(this.binds[a],function(e){e.setValue(this.get(a))},this)}}return c},commit:function(){this.stored[this.currentId]=Ext.apply(this.stored[this.currentId],this.changed[this.currentId]);this.reset()},get:function(){if(arguments.length==1){var b=arguments[0];return(this.isDirty(b))?this.changed[this.currentId][b]:this.getDefault(b)}else{if(arguments.length==0){var a={};for(var b in this.options){a[b]=(this.isDirty(b))?this.changed[this.currentId][b]:this.getDefault(b)}return a}else{var a={};Ext.each(arguments,function(c){a[c]=(this.isDirty(c))?this.changed[this.currentId][c]:this.getDefault(c)},this);return a}}},getDefault:function(a){return(this.has(a))?this.stored[this.currentId][a]:this.options[a]},getDirty:function(){return(this.changed[this.currentId])?this.changed[this.currentId]:{}},isDirty:function(a){return(this.changed[this.currentId]&&!Ext.isEmpty(this.changed[this.currentId][a]))},has:function(a){return(this.stored[this.currentId]&&!Ext.isEmpty(this.stored[this.currentId][a]))},reset:function(){if(this.changed[this.currentId]){delete this.changed[this.currentId]}if(this.stored[this.currentId]){delete this.stored[this.currentId]}},resetAll:function(){this.changed={};this.stored={};this.changeId(null)},setDefault:function(c,d){if(c===undefined){return}else{if(d===undefined){for(var b in c){this.setDefault(b,c[b])}}else{var a=this.getDefault(c);d=this.convertValueType(a,d);if(a==d){return}if(!this.stored[this.currentId]){this.stored[this.currentId]={}}this.stored[this.currentId][c]=d;if(!this.isDirty(c)){this.fireEvent("changed",this.currentId,c,d,a)}}}},update:function(d,e){if(d===undefined){return}else{if(e===undefined){for(var c in d){this.update(c,d[c])}}else{if(!this.changed[this.currentId]){this.changed[this.currentId]={}}var a=this.getDefault(d);e=this.convertValueType(a,e);var b=this.get(d);if(b==e){return}if(a==e){if(this.isDirty(d)){delete this.changed[this.currentId][d]}this.fireEvent("changed",this.currentId,d,e,b);return}else{this.changed[this.currentId][d]=e;this.fireEvent("changed",this.currentId,d,e,b)}}}},onFieldChange:function(b,a){this.update(b._doption,b.getValue())},onChange:function(d,b,c,a){if(Ext.isEmpty(this.binds[b])){return}Ext.each(this.binds[b],function(e){if(e==this.focused){return}e.setValue(c)},this)}});Ext.namespace("Deluge.add");Deluge.add.OptionsPanel=Ext.extend(Ext.TabPanel,{torrents:{},constructor:function(a){a=Ext.apply({region:"south",margins:"5 5 5 5",activeTab:0,height:220},a);Deluge.add.OptionsPanel.superclass.constructor.call(this,a)},initComponent:function(){Deluge.add.OptionsPanel.superclass.initComponent.call(this);this.files=this.add(new Ext.ux.tree.TreeGrid({layout:"fit",title:_("Files"),rootVisible:false,autoScroll:true,height:170,border:false,animate:false,disabled:true,columns:[{header:_("Filename"),width:275,dataIndex:"filename"},{xtype:"tgrendercolumn",header:_("Size"),width:80,dataIndex:"size",renderer:fsize}]}));new Ext.tree.TreeSorter(this.files,{folderSort:true});this.optionsManager=new Deluge.MultiOptionsManager();this.form=this.add({xtype:"form",labelWidth:1,title:_("Options"),bodyStyle:"padding: 5px;",border:false,height:170,disabled:true});var a=this.form.add({xtype:"fieldset",title:_("Download Location"),border:false,autoHeight:true,defaultType:"textfield",labelWidth:1,fieldLabel:""});this.optionsManager.bind("download_location",a.add({fieldLabel:"",name:"download_location",width:400,labelSeparator:""}));var b=this.form.add({border:false,layout:"column",defaultType:"fieldset"});a=b.add({title:_("Allocation"),border:false,autoHeight:true,defaultType:"radio",width:100});this.optionsManager.bind("compact_allocation",a.add({xtype:"radiogroup",columns:1,vertical:true,labelSeparator:"",items:[{name:"compact_allocation",value:false,inputValue:false,boxLabel:_("Full"),fieldLabel:"",labelSeparator:""},{name:"compact_allocation",value:true,inputValue:true,boxLabel:_("Compact"),fieldLabel:"",labelSeparator:"",}]}));a=b.add({title:_("Bandwidth"),border:false,autoHeight:true,labelWidth:100,width:200,defaultType:"spinnerfield"});this.optionsManager.bind("max_download_speed",a.add({fieldLabel:_("Max Down Speed"),name:"max_download_speed",width:60}));this.optionsManager.bind("max_upload_speed",a.add({fieldLabel:_("Max Up Speed"),name:"max_upload_speed",width:60}));this.optionsManager.bind("max_connections",a.add({fieldLabel:_("Max Connections"),name:"max_connections",width:60}));this.optionsManager.bind("max_upload_slots",a.add({fieldLabel:_("Max Upload Slots"),name:"max_upload_slots",width:60}));a=b.add({title:_("General"),border:false,autoHeight:true,defaultType:"checkbox"});this.optionsManager.bind("add_paused",a.add({name:"add_paused",boxLabel:_("Add In Paused State"),fieldLabel:"",labelSeparator:"",}));this.optionsManager.bind("prioritize_first_last_pieces",a.add({name:"prioritize_first_last_pieces",boxLabel:_("Prioritize First/Last Pieces"),fieldLabel:"",labelSeparator:"",}));this.form.on("render",this.onFormRender,this)},onFormRender:function(a){a.layout=new Ext.layout.FormLayout();a.layout.setContainer(a);a.doLayout()},addTorrent:function(c){this.torrents[c.info_hash]=c;var b={};this.walkFileTree(c.files_tree,function(e,g,h,f){if(g!="file"){return}b[h[0]]=h[2]},this);var a=[];Ext.each(Ext.keys(b),function(e){a[e]=b[e]});var d=this.optionsManager.changeId(c.info_hash,true);this.optionsManager.setDefault("file_priorities",a);this.optionsManager.changeId(d,true)},clear:function(){this.clearFiles();this.optionsManager.resetAll()},clearFiles:function(){var a=this.files.getRootNode();if(!a.hasChildNodes()){return}a.cascade(function(b){if(!b.parentNode||!b.getOwnerTree()){return}b.remove()})},getDefaults:function(){var a=["add_paused","compact_allocation","download_location","max_connections_per_torrent","max_download_speed_per_torrent","max_upload_slots_per_torrent","max_upload_speed_per_torrent","prioritize_first_last_pieces"];deluge.client.core.get_config_values(a,{success:function(c){var b={file_priorities:[],add_paused:c.add_paused,compact_allocation:c.compact_allocation,download_location:c.download_location,max_connections:c.max_connections_per_torrent,max_download_speed:c.max_download_speed_per_torrent,max_upload_slots:c.max_upload_slots_per_torrent,max_upload_speed:c.max_upload_speed_per_torrent,prioritize_first_last_pieces:c.prioritize_first_last_pieces};this.optionsManager.options=b;this.optionsManager.resetAll()},scope:this})},getFilename:function(a){return this.torrents[a]["filename"]},getOptions:function(a){var c=this.optionsManager.changeId(a,true);var b=this.optionsManager.get();this.optionsManager.changeId(c,true);Ext.each(b.file_priorities,function(e,d){b.file_priorities[d]=(e)?1:0});return b},setTorrent:function(b){if(!b){return}this.torrentId=b;this.optionsManager.changeId(b);this.clearFiles();var a=this.files.getRootNode();var c=this.optionsManager.get("file_priorities");this.walkFileTree(this.torrents[b]["files_tree"],function(d,f,i,e){if(f=="dir"){var h=new Ext.tree.TreeNode({text:d,checked:true});h.on("checkchange",this.onFolderCheck,this);e.appendChild(h);return h}else{var g=new Ext.tree.TreeNode({filename:d,fileindex:i[0],text:d,size:fsize(i[1]),leaf:true,checked:c[i[0]],iconCls:"x-deluge-file",uiProvider:Ext.tree.ColumnNodeUI});g.on("checkchange",this.onNodeCheck,this);e.appendChild(g)}},this,a);a.firstChild.expand()},walkFileTree:function(g,h,e,d){for(var a in g){var f=g[a];var c=(Ext.type(f)=="object")?"dir":"file";if(e){var b=h.apply(e,[a,c,f,d])}else{var b=h(a,c,f,d)}if(c=="dir"){this.walkFileTree(f,h,e,b)}}},onFolderCheck:function(c,b){var a=this.optionsManager.get("file_priorities");c.cascade(function(d){if(!d.ui.checkbox){d.attributes.checked=b}else{d.ui.checkbox.checked=b}a[d.attributes.fileindex]=b},this);this.optionsManager.setDefault("file_priorities",a)},onNodeCheck:function(c,b){var a=this.optionsManager.get("file_priorities");a[c.attributes.fileindex]=b;this.optionsManager.update("file_priorities",a)}});Deluge.add.Window=Ext.extend(Ext.Window,{initComponent:function(){Deluge.add.Window.superclass.initComponent.call(this);this.addEvents("beforeadd","add")},createTorrentId:function(){return new Date().getTime()}});Deluge.add.AddWindow=Ext.extend(Deluge.add.Window,{constructor:function(a){a=Ext.apply({title:_("Add Torrents"),layout:"border",width:470,height:450,bodyStyle:"padding: 10px 5px;",buttonAlign:"right",closeAction:"hide",closable:true,plain:true,iconCls:"x-deluge-add-window-icon"},a);Deluge.add.AddWindow.superclass.constructor.call(this,a)},initComponent:function(){Deluge.add.AddWindow.superclass.initComponent.call(this);this.addButton(_("Cancel"),this.onCancelClick,this);this.addButton(_("Add"),this.onAddClick,this);function a(c,d,b){if(b.data.info_hash){return String.format('
{0}
',c)}else{return String.format('
{0}
',c)}}this.grid=this.add({xtype:"grid",region:"center",store:new Ext.data.SimpleStore({fields:[{name:"info_hash",mapping:1},{name:"text",mapping:2}],id:0}),columns:[{id:"torrent",width:150,sortable:true,renderer:a,dataIndex:"text"}],stripeRows:true,selModel:new Ext.grid.RowSelectionModel({singleSelect:true,listeners:{rowselect:{fn:this.onSelect,scope:this}}}),hideHeaders:true,autoExpandColumn:"torrent",deferredRender:false,autoScroll:true,margins:"5 5 5 5",bbar:new Ext.Toolbar({items:[{iconCls:"x-deluge-add-file",text:_("File"),handler:this.onFile,scope:this},{text:_("Url"),iconCls:"icon-add-url",handler:this.onUrl,scope:this},{text:_("Infohash"),iconCls:"icon-add-magnet",disabled:true},"->",{text:_("Remove"),iconCls:"icon-remove",handler:this.onRemove,scope:this}]})});this.optionsPanel=this.add(new Deluge.add.OptionsPanel());this.on("hide",this.onHide,this);this.on("show",this.onShow,this)},clear:function(){this.grid.getStore().removeAll();this.optionsPanel.clear()},onAddClick:function(){var a=[];if(!this.grid){return}this.grid.getStore().each(function(b){var c=b.get("info_hash");a.push({path:this.optionsPanel.getFilename(c),options:this.optionsPanel.getOptions(c)})},this);deluge.client.web.add_torrents(a,{success:function(b){}});this.clear();this.hide()},onCancelClick:function(){this.clear();this.hide()},onFile:function(){this.file.show()},onHide:function(){this.optionsPanel.setActiveTab(0);this.optionsPanel.files.setDisabled(true);this.optionsPanel.form.setDisabled(true)},onRemove:function(){var a=this.grid.getSelectionModel();if(!a.hasSelection()){return}var b=a.getSelected();this.grid.getStore().remove(b);this.optionsPanel.clear();if(this.torrents&&this.torrents[b.id]){delete this.torrents[b.id]}},onSelect:function(b,c,a){this.optionsPanel.setTorrent(a.get("info_hash"));this.optionsPanel.files.setDisabled(false);this.optionsPanel.form.setDisabled(false)},onShow:function(){if(!this.url){this.url=new Deluge.add.UrlWindow();this.url.on("beforeadd",this.onTorrentBeforeAdd,this);this.url.on("add",this.onTorrentAdd,this)}if(!this.file){this.file=new Deluge.add.FileWindow();this.file.on("beforeadd",this.onTorrentBeforeAdd,this);this.file.on("add",this.onTorrentAdd,this)}this.optionsPanel.getDefaults()},onTorrentBeforeAdd:function(b,c){var a=this.grid.getStore();a.loadData([[b,null,c]],true)},onTorrentAdd:function(a,c){var b=this.grid.getStore().getById(a);if(!c){Ext.MessageBox.show({title:_("Error"),msg:_("Not a valid torrent"),buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"});this.grid.getStore().remove(b)}else{b.set("info_hash",c.info_hash);b.set("text",c.name);this.grid.getStore().commitChanges();this.optionsPanel.addTorrent(c)}},onUrl:function(a,b){this.url.show()}});deluge.add=new Deluge.add.AddWindow();Ext.namespace("Ext.deluge.add");Deluge.add.FileWindow=Ext.extend(Deluge.add.Window,{constructor:function(a){a=Ext.apply({layout:"fit",width:350,height:115,bodyStyle:"padding: 10px 5px;",buttonAlign:"center",closeAction:"hide",modal:true,plain:true,title:_("Add from File"),iconCls:"x-deluge-add-file"},a);Deluge.add.FileWindow.superclass.constructor.call(this,a)},initComponent:function(){Deluge.add.FileWindow.superclass.initComponent.call(this);this.addButton(_("Add"),this.onAddClick,this);this.form=this.add({xtype:"form",baseCls:"x-plain",labelWidth:35,autoHeight:true,fileUpload:true,items:[{xtype:"fileuploadfield",id:"torrentFile",width:280,emptyText:_("Select a torrent"),fieldLabel:_("File"),name:"file",buttonCfg:{text:_("Browse")+"..."}}]})},onAddClick:function(c,b){if(this.form.getForm().isValid()){this.torrentId=this.createTorrentId();this.form.getForm().submit({url:"/upload",waitMsg:_("Uploading your torrent..."),failure:this.onUploadFailure,success:this.onUploadSuccess,scope:this});var a=this.form.getForm().findField("torrentFile").value;a=a.split("\\").slice(-1)[0];this.fireEvent("beforeadd",this.torrentId,a)}},onGotInfo:function(d,c,a,b){d.filename=b.options.filename;this.fireEvent("add",this.torrentId,d)},onUploadFailure:function(a,b){this.hide()},onUploadSuccess:function(c,b){this.hide();if(b.result.success){var a=b.result.files[0];this.form.getForm().findField("torrentFile").setValue("");Deluge.Client.web.get_torrent_info(a,{success:this.onGotInfo,scope:this,filename:a})}}});Ext.namespace("Deluge.add");Deluge.add.UrlWindow=Ext.extend(Deluge.add.Window,{constructor:function(a){a=Ext.apply({layout:"fit",width:350,height:155,bodyStyle:"padding: 10px 5px;",buttonAlign:"center",closeAction:"hide",modal:true,plain:true,title:_("Add from Url"),iconCls:"x-deluge-add-url-window-icon"},a);Deluge.add.UrlWindow.superclass.constructor.call(this,a)},initComponent:function(){Deluge.add.UrlWindow.superclass.initComponent.call(this);this.addButton(_("Add"),this.onAddClick,this);var a=this.add({xtype:"form",defaultType:"textfield",baseCls:"x-plain",labelWidth:55});this.urlField=a.add({fieldLabel:_("Url"),id:"url",name:"url",anchor:"100%"});this.urlField.on("specialkey",this.onAdd,this);this.cookieField=a.add({fieldLabel:_("Cookies"),id:"cookies",name:"cookies",anchor:"100%"});this.cookieField.on("specialkey",this.onAdd,this)},onAddClick:function(f,d){if((f.id=="url"||f.id=="cookies")&&d.getKey()!=d.ENTER){return}var f=this.urlField;var b=f.getValue();var c=this.cookieField.getValue();var a=this.createTorrentId();deluge.client.web.download_torrent_from_url(b,c,{success:this.onDownload,scope:this,torrentId:a});this.hide();this.fireEvent("beforeadd",a,b)},onDownload:function(a,c,d,b){this.urlField.setValue("");deluge.client.web.get_torrent_info(a,{success:this.onGotInfo,scope:this,filename:a,torrentId:b.options.torrentId})},onGotInfo:function(d,c,a,b){d.filename=b.options.filename;this.fireEvent("add",b.options.torrentId,d)}});Ext.namespace("Ext.ux.util");Ext.ux.util.RpcClient=Ext.extend(Ext.util.Observable,{_components:[],_methods:[],_requests:{},_url:null,_optionKeys:["scope","success","failure"],constructor:function(a){Ext.ux.util.RpcClient.superclass.constructor.call(this,a);this._url=a.url||null;this._id=0;this.addEvents("connected","error");this.reloadMethods()},reloadMethods:function(){Ext.each(this._components,function(a){delete this[a]},this);this._execute("system.listMethods",{success:this._setMethods,scope:this})},_execute:function(c,a){a=a||{};a.params=a.params||[];a.id=this._id;var b=Ext.encode({method:c,params:a.params,id:a.id});this._id++;return Ext.Ajax.request({url:this._url,method:"POST",success:this._onSuccess,failure:this._onFailure,scope:this,jsonData:b,options:a})},_onFailure:function(b,a){var c=a.options;errorObj={id:c.id,result:null,error:{msg:"HTTP: "+b.status+" "+b.statusText,code:255}};this.fireEvent("error",errorObj,b,a);if(Ext.type(c.failure)!="function"){return}if(c.scope){c.failure.call(c.scope,errorObj,b,a)}else{c.failure(errorObj,b,a)}},_onSuccess:function(c,a){var b=Ext.decode(c.responseText);var d=a.options;if(b.error){this.fireEvent("error",b,c,a);if(Ext.type(d.failure)!="function"){return}if(d.scope){d.failure.call(d.scope,b,c,a)}else{d.failure(b,c,a)}}else{if(Ext.type(d.success)!="function"){return}if(d.scope){d.success.call(d.scope,b.result,b,c,a)}else{d.success(b.result,b,c,a)}}},_parseArgs:function(c){var e=[];Ext.each(c,function(f){e.push(f)});var b=e[e.length-1];if(Ext.type(b)=="object"){var d=Ext.keys(b),a=false;Ext.each(this._optionKeys,function(f){if(d.indexOf(f)>-1){a=true}});if(a){e.remove(b)}else{b={}}}else{b={}}b.params=e;return b},_setMethods:function(b){var d={},a=this;Ext.each(b,function(h){var g=h.split(".");var e=d[g[0]]||{};var f=function(){var i=a._parseArgs(arguments);return a._execute(h,i)};e[g[1]]=f;d[g[0]]=e});for(var c in d){a[c]=d[c]}this._components=Ext.keys(d);this.fireEvent("connected",this)}});(function(){var a=function(c,d,b){return c+":"+b.data.port};Deluge.AddConnectionWindow=Ext.extend(Ext.Window,{constructor:function(b){b=Ext.apply({layout:"fit",width:300,height:195,bodyStyle:"padding: 10px 5px;",buttonAlign:"right",closeAction:"hide",closable:true,plain:true,title:_("Add Connection"),iconCls:"x-deluge-add-window-icon"},b);Deluge.AddConnectionWindow.superclass.constructor.call(this,b)},initComponent:function(){Deluge.AddConnectionWindow.superclass.initComponent.call(this);this.addEvents("hostadded");this.addButton(_("Close"),this.hide,this);this.addButton(_("Add"),this.onAddClick,this);this.on("hide",this.onHide,this);this.form=this.add({xtype:"form",defaultType:"textfield",id:"connectionAddForm",baseCls:"x-plain",labelWidth:55});this.hostField=this.form.add({fieldLabel:_("Host"),id:"host",name:"host",anchor:"100%",value:""});this.portField=this.form.add({fieldLabel:_("Port"),id:"port",xtype:"spinnerfield",name:"port",strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:65535},value:"58846",anchor:"50%"});this.usernameField=this.form.add({fieldLabel:_("Username"),id:"username",name:"username",anchor:"100%",value:""});this.passwordField=this.form.add({fieldLabel:_("Password"),anchor:"100%",id:"_password",name:"_password",inputType:"password",value:""})},onAddClick:function(){var d=this.hostField.getValue();var b=this.portField.getValue();var e=this.usernameField.getValue();var c=this.passwordField.getValue();deluge.client.web.add_host(d,b,e,c,{success:function(f){if(!f[0]){Ext.MessageBox.show({title:_("Error"),msg:"Unable to add host: "+f[1],buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"})}else{this.fireEvent("hostadded")}this.hide()},scope:this})},onHide:function(){this.form.getForm().reset()}});Deluge.ConnectionManager=Ext.extend(Ext.Window,{layout:"fit",width:300,height:220,bodyStyle:"padding: 10px 5px;",buttonAlign:"right",closeAction:"hide",closable:true,plain:true,title:_("Connection Manager"),iconCls:"x-deluge-connect-window-icon",initComponent:function(){Deluge.ConnectionManager.superclass.initComponent.call(this);this.on("hide",this.onHide,this);this.on("show",this.onShow,this);deluge.events.on("disconnect",this.onDisconnect,this);deluge.events.on("login",this.onLogin,this);deluge.events.on("logout",this.onLogout,this);this.addButton(_("Close"),this.onClose,this);this.addButton(_("Connect"),this.onConnect,this);this.grid=this.add({xtype:"grid",store:new Ext.data.SimpleStore({fields:[{name:"status",mapping:3},{name:"host",mapping:1},{name:"port",mapping:2},{name:"version",mapping:4}],id:0}),columns:[{header:_("Status"),width:65,sortable:true,renderer:fplain,dataIndex:"status"},{id:"host",header:_("Host"),width:150,sortable:true,renderer:a,dataIndex:"host"},{header:_("Version"),width:75,sortable:true,renderer:fplain,dataIndex:"version"}],stripeRows:true,selModel:new Ext.grid.RowSelectionModel({singleSelect:true,listeners:{rowselect:{fn:this.onSelect,scope:this},selectionchange:{fn:this.onSelectionChanged,scope:this}}}),autoExpandColumn:"host",deferredRender:false,autoScroll:true,margins:"0 0 0 0",bbar:new Ext.Toolbar({buttons:[{id:"cm-add",cls:"x-btn-text-icon",text:_("Add"),iconCls:"icon-add",handler:this.onAddClick,scope:this},{id:"cm-remove",cls:"x-btn-text-icon",text:_("Remove"),iconCls:"icon-remove",handler:this.onRemove,disabled:true,scope:this},"->",{id:"cm-stop",cls:"x-btn-text-icon",text:_("Stop Daemon"),iconCls:"icon-error",handler:this.onStop,disabled:true,scope:this}]})});this.update=this.update.createDelegate(this)},checkConnected:function(){deluge.client.web.connected({success:function(b){if(b){deluge.events.fire("connect")}else{this.show()}},scope:this})},disconnect:function(){deluge.events.fire("disconnect")},loadHosts:function(){deluge.client.web.get_hosts({success:this.onGetHosts,scope:this})},update:function(){this.grid.getStore().each(function(b){deluge.client.web.get_host_status(b.id,{success:this.onGetHostStatus,scope:this})},this)},updateButtons:function(c){var d=this.buttons[1],b=c.get("status");if(b==_("Connected")){d.enable();d.setText(_("Disconnect"))}else{if(b==_("Offline")){d.disable()}else{d.enable();d.setText(_("Connect"))}}if(b==_("Offline")){if(c.get("host")=="127.0.0.1"||c.get("host")=="localhost"){this.stopHostButton.enable();this.stopHostButton.setText(_("Start Daemon"))}else{this.stopHostButton.disable()}}else{this.stopHostButton.enable();this.stopHostButton.setText(_("Stop Daemon"))}},onAddClick:function(b,c){if(!this.addWindow){this.addWindow=new Deluge.AddConnectionWindow();this.addWindow.on("hostadded",this.onHostAdded,this)}this.addWindow.show()},onHostAdded:function(){this.loadHosts()},onClose:function(b){if(this.running){window.clearInterval(this.running)}this.hide()},onConnect:function(c){var b=this.grid.getSelectionModel().getSelected();if(!b){return}if(b.get("status")==_("Connected")){deluge.client.web.disconnect({success:function(e){this.update(this);Deluge.Events.fire("disconnect")},scope:this})}else{var d=b.id;deluge.client.web.connect(d,{success:function(e){deluge.client.reloadMethods();deluge.client.on("connected",function(f){deluge.events.fire("connect")},this,{single:true})}});this.hide()}},onDisconnect:function(){if(this.isVisible()){return}this.show()},onGetHosts:function(b){this.grid.getStore().loadData(b);Ext.each(b,function(c){deluge.client.web.get_host_status(c[0],{success:this.onGetHostStatus,scope:this})},this)},onGetHostStatus:function(c){var b=this.grid.getStore().getById(c[0]);b.set("status",c[3]);b.set("version",c[4]);b.commit();if(this.grid.getSelectionModel().getSelected()==b){this.updateButtons(b)}},onHide:function(){if(this.running){window.clearInterval(this.running)}},onLogin:function(){if(deluge.config.first_login){Ext.MessageBox.confirm("Change password","As this is your first login, we recommend that you change your password. Would you like to do this now?",function(b){this.checkConnected();if(b=="yes"){deluge.preferences.show();deluge.preferences.selectPage("Interface")}deluge.client.web.set_config({first_login:false})},this)}else{this.checkConnected()}},onLogout:function(){this.disconnect();if(!this.hidden&&this.rendered){this.hide()}},onRemove:function(c){var b=this.grid.getSelectionModel().getSelected();if(!b){return}deluge.client.web.remove_host(b.id,{success:function(d){if(!d){Ext.MessageBox.show({title:_("Error"),msg:d[1],buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"})}else{this.grid.getStore().remove(b)}},scope:this})},onSelect:function(c,d,b){this.selectedRow=d},onSelectionChanged:function(c){var b=c.getSelected();if(c.hasSelection()){this.removeHostButton.enable();this.stopHostButton.enable();this.stopHostButton.setText(_("Stop Daemon"))}else{this.removeHostButton.disable();this.stopHostButton.disable()}this.updateButtons(b)},onShow:function(){if(!this.addHostButton){var b=this.grid.getBottomToolbar();this.addHostButton=b.items.get("cm-add");this.removeHostButton=b.items.get("cm-remove");this.stopHostButton=b.items.get("cm-stop")}this.loadHosts();this.running=window.setInterval(this.update,2000,this)},onStop:function(c,d){var b=this.grid.getSelectionModel().getSelected();if(!b){return}if(b.get("status")=="Offline"){deluge.client.web.start_daemon(b.get("port"))}else{deluge.client.web.stop_daemon(b.id,{success:function(e){if(!e[0]){Ext.MessageBox.show({title:_("Error"),msg:e[1],buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"})}}})}}});deluge.connectionManager=new Deluge.ConnectionManager()})();(function(){Ext.namespace("Deluge.details");Deluge.details.TabPanel=Ext.extend(Ext.TabPanel,{constructor:function(a){a=Ext.apply({region:"south",id:"torrentDetails",split:true,height:220,minSize:100,collapsible:true,margins:"0 5 5 5",activeTab:0},a);Deluge.details.TabPanel.superclass.constructor.call(this,a)},clear:function(){this.items.each(function(a){if(a.clear){a.clear.defer(100,a);a.disable()}})},update:function(a){var b=deluge.torrents.getSelected();if(!b){this.clear();return}this.items.each(function(c){if(c.disabled){c.enable()}});a=a||this.getActiveTab();if(a.update){a.update(b.id)}},onRender:function(b,a){Deluge.details.TabPanel.superclass.onRender.call(this,b,a);deluge.events.on("disconnect",this.clear,this);deluge.torrents.on("rowclick",this.onTorrentsClick,this);this.on("tabchange",this.onTabChange,this);deluge.torrents.getSelectionModel().on("selectionchange",function(c){if(!c.hasSelection()){this.clear()}},this)},onTabChange:function(a,b){this.update(b)},onTorrentsClick:function(a,c,b){this.update()}});deluge.details=new Deluge.details.TabPanel()})();Deluge.details.StatusTab=Ext.extend(Ext.Panel,{title:_("Status"),autoScroll:true,onRender:function(b,a){Deluge.details.StatusTab.superclass.onRender.call(this,b,a);this.progressBar=this.add({xtype:"progress",cls:"x-deluge-status-progressbar"});this.status=this.add({cls:"x-deluge-status",id:"deluge-details-status",border:false,width:1000,listeners:{render:{fn:function(c){c.load({url:deluge.config.base+"render/tab_status.html",text:_("Loading")+"..."});c.getUpdater().on("update",this.onPanelUpdate,this)},scope:this}}})},clear:function(){this.progressBar.updateProgress(0," ");for(var a in this.fields){this.fields[a].innerHTML=""}},update:function(a){if(!this.fields){this.getFields()}deluge.client.core.get_torrent_status(a,Deluge.Keys.Status,{success:this.onRequestComplete,scope:this})},onPanelUpdate:function(b,a){this.fields={};Ext.each(Ext.query("dd",this.status.body.dom),function(c){this.fields[c.className]=c},this)},onRequestComplete:function(a){seeders=a.total_seeds>-1?a.num_seeds+" ("+a.total_seeds+")":a.num_seeds;peers=a.total_peers>-1?a.num_peers+" ("+a.total_peers+")":a.num_peers;var b={downloaded:fsize(a.total_done),uploaded:fsize(a.total_uploaded),share:a.ratio.toFixed(3),announce:ftime(a.next_announce),tracker_status:a.tracker_status,downspeed:(a.download_payload_rate)?fspeed(a.download_payload_rate):"0.0 KiB/s",upspeed:(a.upload_payload_rate)?fspeed(a.upload_payload_rate):"0.0 KiB/s",eta:ftime(a.eta),pieces:a.num_pieces+" ("+fsize(a.piece_length)+")",seeders:seeders,peers:peers,avail:a.distributed_copies.toFixed(3),active_time:ftime(a.active_time),seeding_time:ftime(a.seeding_time),seed_rank:a.seed_rank,time_added:fdate(a.time_added)};b.auto_managed=_((a.is_auto_managed)?"True":"False");b.downloaded+=" ("+((a.total_payload_download)?fsize(a.total_payload_download):"0.0 KiB")+")";b.uploaded+=" ("+((a.total_payload_download)?fsize(a.total_payload_download):"0.0 KiB")+")";for(var c in this.fields){this.fields[c].innerHTML=b[c]}var d=a.state+" "+a.progress.toFixed(2)+"%";this.progressBar.updateProgress(a.progress/100,d)}});deluge.details.add(new Deluge.details.StatusTab());Deluge.details.DetailsTab=Ext.extend(Ext.Panel,{title:_("Details"),fields:{},queuedItems:{},oldData:{},initComponent:function(){Deluge.details.DetailsTab.superclass.initComponent.call(this);this.addItem("torrent_name",_("Name"));this.addItem("hash",_("Hash"));this.addItem("path",_("Path"));this.addItem("size",_("Total Size"));this.addItem("files",_("# of files"));this.addItem("comment",_("Comment"));this.addItem("status",_("Status"));this.addItem("tracker",_("Tracker"))},onRender:function(b,a){Deluge.details.DetailsTab.superclass.onRender.call(this,b,a);this.body.setStyle("padding","10px");this.dl=Ext.DomHelper.append(this.body,{tag:"dl"},true);for(var c in this.queuedItems){this.doAddItem(c,this.queuedItems[c])}},addItem:function(b,a){if(!this.rendered){this.queuedItems[b]=a}else{this.doAddItem(b,a)}},doAddItem:function(b,a){Ext.DomHelper.append(this.dl,{tag:"dt",cls:b,html:a+":"});this.fields[b]=Ext.DomHelper.append(this.dl,{tag:"dd",cls:b,html:""},true)},clear:function(){if(!this.fields){return}for(var a in this.fields){this.fields[a].dom.innerHTML=""}},update:function(a){deluge.client.core.get_torrent_status(a,Deluge.Keys.Details,{success:this.onRequestComplete,scope:this,torrentId:a})},onRequestComplete:function(e,c,a,b){var d={torrent_name:e.name,hash:b.options.torrentId,path:e.save_path,size:fsize(e.total_size),files:e.num_files,status:e.tracker_status,tracker:e.tracker,comment:e.comment};for(var f in this.fields){if(!d[f]){continue}if(d[f]==this.oldData[f]){continue}this.fields[f].dom.innerHTML=Ext.escapeHTML(d[f])}this.oldData=d}});deluge.details.add(new Deluge.details.DetailsTab());(function(){function b(d){var c=d*100;return Deluge.progressBar(c,this.col.width,c.toFixed(2)+"%",0)}function a(c){if(isNaN(c)){return""}return String.format('
{1}
',FILE_PRIORITY_CSS[c],_(FILE_PRIORITY[c]))}Deluge.details.FilesTab=Ext.extend(Ext.ux.tree.TreeGrid,{constructor:function(c){c=Ext.apply({title:_("Files"),rootVisible:false,autoScroll:true,selModel:new Ext.tree.MultiSelectionModel(),columns:[{header:_("Filename"),width:330,dataIndex:"filename"},{xtype:"tgrendercolumn",header:_("Size"),width:150,dataIndex:"size",renderer:fsize},{xtype:"tgrendercolumn",header:_("Progress"),width:150,dataIndex:"progress",renderer:b},{xtype:"tgrendercolumn",header:_("Priority"),width:150,dataIndex:"priority",renderer:a}],root:new Ext.tree.TreeNode({text:"Files"})},c);Deluge.details.FilesTab.superclass.constructor.call(this,c)},initComponent:function(){Deluge.details.FilesTab.superclass.initComponent.call(this)},onRender:function(d,c){Deluge.details.FilesTab.superclass.onRender.call(this,d,c);deluge.menus.filePriorities.on("itemclick",this.onItemClick,this);this.on("contextmenu",this.onContextMenu,this);this.sorter=new Ext.tree.TreeSorter(this,{folderSort:true})},clear:function(){var c=this.getRootNode();if(!c.hasChildNodes()){return}c.cascade(function(e){var d=e.parentNode;if(!d){return}if(!d.ownerTree){return}d.removeChild(e)})},update:function(c){if(this.torrentId!=c){this.clear();this.torrentId=c}deluge.client.web.get_torrent_files(c,{success:this.onRequestComplete,scope:this,torrentId:c})},onContextMenu:function(d,f){f.stopEvent();var c=this.getSelectionModel();if(c.getSelectedNodes().length<2){c.clearSelections();d.select()}deluge.menus.filePriorities.showAt(f.getPoint())},onItemClick:function(j,i){switch(j.id){case"expandAll":this.expandAll();break;default:var h={};function c(e){if(Ext.isEmpty(e.attributes.fileIndex)){return}h[e.attributes.fileIndex]=e.attributes.priority}this.getRootNode().cascade(c);var d=this.getSelectionModel().getSelectedNodes();Ext.each(d,function(k){if(!k.isLeaf()){function e(l){if(Ext.isEmpty(l.attributes.fileIndex)){return}h[l.attributes.fileIndex]=j.filePriority}k.cascade(e)}else{if(!Ext.isEmpty(k.attributes.fileIndex)){h[k.attributes.fileIndex]=j.filePriority;return}}});var g=new Array(Ext.keys(h).length);for(var f in h){g[f]=h[f]}deluge.client.core.set_torrent_file_priorities(this.torrentId,g,{success:function(){Ext.each(d,function(e){e.setColumnValue(3,j.filePriority)})},scope:this});break}},onRequestComplete:function(f,e){function d(j,h){for(var g in j.contents){var i=j.contents[g];var k=h.findChild("id",g);if(i.type=="dir"){if(!k){k=new Ext.tree.TreeNode({id:g,text:g,filename:g,size:i.size,progress:i.progress,priority:i.priority});h.appendChild(k)}d(i,k)}else{if(!k){k=new Ext.tree.TreeNode({id:g,filename:g,text:g,fileIndex:i.index,size:i.size,progress:i.progress,priority:i.priority,leaf:true,iconCls:"x-deluge-file",uiProvider:Ext.ux.tree.TreeGridNodeUI});h.appendChild(k)}}}}var c=this.getRootNode();d(f,c);c.firstChild.expand()}});deluge.details.add(new Deluge.details.FilesTab())})();(function(){function a(e){return String.format('',e)}function c(g,h,f){var e=(f.data.seed==1024)?"x-deluge-seed":"x-deluge-peer";return String.format('
{1}
',e,g)}function d(f){var e=(f*100).toFixed(0);return Deluge.progressBar(e,this.width-8,e+"%")}function b(e){var f=e.match(/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\:(\d+)/);return((((((+f[1])*256)+(+f[2]))*256)+(+f[3]))*256)+(+f[4])}Deluge.details.PeersTab=Ext.extend(Ext.grid.GridPanel,{constructor:function(e){e=Ext.apply({title:_("Peers"),cls:"x-deluge-peers",store:new Ext.data.SimpleStore({fields:[{name:"country"},{name:"address",sortType:b},{name:"client"},{name:"progress",type:"float"},{name:"downspeed",type:"int"},{name:"upspeed",type:"int"},{name:"seed",type:"int"}],id:0}),columns:[{header:" ",width:30,sortable:true,renderer:a,dataIndex:"country"},{header:"Address",width:125,sortable:true,renderer:c,dataIndex:"address"},{header:"Client",width:125,sortable:true,renderer:fplain,dataIndex:"client"},{header:"Progress",width:150,sortable:true,renderer:d,dataIndex:"progress"},{header:"Down Speed",width:100,sortable:true,renderer:fspeed,dataIndex:"downspeed"},{header:"Up Speed",width:100,sortable:true,renderer:fspeed,dataIndex:"upspeed"}],stripeRows:true,deferredRender:false,autoScroll:true},e);Deluge.details.PeersTab.superclass.constructor.call(this,e)},onRender:function(f,e){Deluge.details.PeersTab.superclass.onRender.call(this,f,e)},clear:function(){this.getStore().loadData([])},update:function(e){deluge.client.core.get_torrent_status(e,Deluge.Keys.Peers,{success:this.onRequestComplete,scope:this})},onRequestComplete:function(g,f){if(!g){return}var e=new Array();Ext.each(g.peers,function(h){e.push([h.country,h.ip,h.client,h.progress,h.down_speed,h.up_speed,h.seed])},this);this.getStore().loadData(e)}});deluge.details.add(new Deluge.details.PeersTab())})();Deluge.details.OptionsTab=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({autoScroll:true,bodyStyle:"padding: 5px;",border:false,cls:"x-deluge-options",defaults:{autoHeight:true,labelWidth:1,defaultType:"checkbox"},deferredRender:false,layout:"column",title:_("Options")},a);Deluge.details.OptionsTab.superclass.constructor.call(this,a)},initComponent:function(){Deluge.details.OptionsTab.superclass.initComponent.call(this);this.fieldsets={},this.fields={};this.optionsManager=new Deluge.MultiOptionsManager({options:{max_download_speed:-1,max_upload_speed:-1,max_connections:-1,max_upload_slots:-1,auto_managed:false,stop_at_ratio:false,stop_ratio:2,remove_at_ratio:false,move_completed:null,"private":false,prioritize_first_last:false}});this.fieldsets.bandwidth=this.add({xtype:"fieldset",defaultType:"spinnerfield",bodyStyle:"padding: 5px",layout:"table",layoutConfig:{columns:3},labelWidth:150,style:"margin-left: 10px; margin-right: 5px; padding: 5px",title:_("Bandwidth"),width:250});this.fieldsets.bandwidth.add({xtype:"label",text:_("Max Download Speed"),forId:"max_download_speed",cls:"x-deluge-options-label"});this.fields.max_download_speed=this.fieldsets.bandwidth.add({id:"max_download_speed",name:"max_download_speed",width:70,strategy:{xtype:"number",decimalPrecision:1,minValue:-1,maxValue:99999}});this.fieldsets.bandwidth.add({xtype:"label",text:_("KiB/s"),style:"margin-left: 10px"});this.fieldsets.bandwidth.add({xtype:"label",text:_("Max Upload Speed"),forId:"max_upload_speed",cls:"x-deluge-options-label"});this.fields.max_upload_speed=this.fieldsets.bandwidth.add({id:"max_upload_speed",name:"max_upload_speed",width:70,value:-1,strategy:{xtype:"number",decimalPrecision:1,minValue:-1,maxValue:99999}});this.fieldsets.bandwidth.add({xtype:"label",text:_("KiB/s"),style:"margin-left: 10px"});this.fieldsets.bandwidth.add({xtype:"label",text:_("Max Connections"),forId:"max_connections",cls:"x-deluge-options-label"});this.fields.max_connections=this.fieldsets.bandwidth.add({id:"max_connections",name:"max_connections",width:70,value:-1,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},colspan:2});this.fieldsets.bandwidth.add({xtype:"label",text:_("Max Upload Slots"),forId:"max_upload_slots",cls:"x-deluge-options-label"});this.fields.max_upload_slots=this.fieldsets.bandwidth.add({id:"max_upload_slots",name:"max_upload_slots",width:70,value:-1,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},colspan:2});this.fieldsets.queue=this.add({xtype:"fieldset",title:_("Queue"),style:"margin-left: 5px; margin-right: 5px; padding: 5px",width:210,layout:"table",layoutConfig:{columns:2},labelWidth:0,defaults:{fieldLabel:"",labelSeparator:""}});this.fields.auto_managed=this.fieldsets.queue.add({xtype:"checkbox",fieldLabel:"",labelSeparator:"",name:"is_auto_managed",boxLabel:_("Auto Managed"),width:200,colspan:2});this.fields.stop_at_ratio=this.fieldsets.queue.add({fieldLabel:"",labelSeparator:"",id:"stop_at_ratio",width:120,boxLabel:_("Stop seed at ratio"),handler:this.onStopRatioChecked,scope:this});this.fields.stop_ratio=this.fieldsets.queue.add({xtype:"spinnerfield",id:"stop_ratio",name:"stop_ratio",disabled:true,width:50,value:2,strategy:{xtype:"number",minValue:-1,maxValue:99999,incrementValue:0.1,alternateIncrementValue:1,decimalPrecision:1}});this.fields.remove_at_ratio=this.fieldsets.queue.add({fieldLabel:"",labelSeparator:"",id:"remove_at_ratio",ctCls:"x-deluge-indent-checkbox",bodyStyle:"padding-left: 10px",boxLabel:_("Remove at ratio"),disabled:true,colspan:2});this.fields.move_completed=this.fieldsets.queue.add({fieldLabel:"",labelSeparator:"",id:"move_completed",boxLabel:_("Move Completed"),colspan:2});this.rightColumn=this.add({border:false,autoHeight:true,style:"margin-left: 5px",width:210});this.fieldsets.general=this.rightColumn.add({xtype:"fieldset",autoHeight:true,defaultType:"checkbox",title:_("General"),layout:"form"});this.fields["private"]=this.fieldsets.general.add({fieldLabel:"",labelSeparator:"",boxLabel:_("Private"),id:"private",disabled:true});this.fields.prioritize_first_last=this.fieldsets.general.add({fieldLabel:"",labelSeparator:"",boxLabel:_("Prioritize First/Last"),id:"prioritize_first_last"});for(var a in this.fields){this.optionsManager.bind(a,this.fields[a])}this.buttonPanel=this.rightColumn.add({layout:"hbox",xtype:"panel",border:false});this.buttonPanel.add({id:"edit_trackers",xtype:"button",text:_("Edit Trackers"),cls:"x-btn-text-icon",iconCls:"x-deluge-edit-trackers",border:false,width:100,handler:this.onEditTrackers,scope:this});this.buttonPanel.add({id:"apply",xtype:"button",text:_("Apply"),style:"margin-left: 10px;",border:false,width:100,handler:this.onApply,scope:this})},onRender:function(b,a){Deluge.details.OptionsTab.superclass.onRender.call(this,b,a);this.layout=new Ext.layout.ColumnLayout();this.layout.setContainer(this);this.doLayout()},clear:function(){if(this.torrentId==null){return}this.torrentId=null;this.optionsManager.changeId(null)},reset:function(){if(this.torrentId){this.optionsManager.reset()}},update:function(a){if(this.torrentId&&!a){this.clear()}if(!a){return}if(this.torrentId!=a){this.torrentId=a;this.optionsManager.changeId(a)}deluge.client.core.get_torrent_status(a,Deluge.Keys.Options,{success:this.onRequestComplete,scope:this})},onApply:function(){var b=this.optionsManager.getDirty();if(!Ext.isEmpty(b.prioritize_first_last)){var a=b.prioritize_first_last;deluge.client.core.set_torrent_prioritize_first_last(this.torrentId,a,{success:function(){this.optionsManager.set("prioritize_first_last",a)},scope:this})}deluge.client.core.set_torrent_options([this.torrentId],b,{success:function(){this.optionsManager.commit()},scope:this})},onEditTrackers:function(){deluge.editTrackers.show()},onStopRatioChecked:function(b,a){this.fields.remove_at_ratio.setDisabled(!a);this.fields.stop_ratio.setDisabled(!a)},onRequestComplete:function(c,b){this.fields["private"].setValue(c["private"]);this.fields["private"].setDisabled(true);delete c["private"];c.auto_managed=c.is_auto_managed;this.optionsManager.setDefault(c);var a=this.optionsManager.get("stop_at_ratio");this.fields.remove_at_ratio.setDisabled(!a);this.fields.stop_ratio.setDisabled(!a)}});deluge.details.add(new Deluge.details.OptionsTab());(function(){Deluge.AddTracker=Ext.extend(Ext.Window,{constructor:function(a){a=Ext.apply({title:_("Add Tracker"),width:375,height:150,bodyStyle:"padding: 5px",layout:"fit",buttonAlign:"right",closeAction:"hide",closable:true,iconCls:"x-deluge-edit-trackers",plain:true,resizable:false},a);Deluge.AddTracker.superclass.constructor.call(this,a)},initComponent:function(){Deluge.AddTracker.superclass.initComponent.call(this);this.addButton(_("Cancel"),this.onCancelClick,this);this.addButton(_("Add"),this.onAddClick,this);this.addEvents("add");this.form=this.add({xtype:"form",defaultType:"textarea",baseCls:"x-plain",labelWidth:55,items:[{fieldLabel:_("Trackers"),name:"trackers",anchor:"100%"}]})},onAddClick:function(){var b=this.form.getForm().findField("trackers").getValue();b=b.split("\n");var a=[];Ext.each(b,function(c){if(Ext.form.VTypes.url(c)){a.push(c)}},this);this.fireEvent("add",a);this.hide();this.form.getForm().findField("trackers").setValue("")},onCancelClick:function(){this.form.getForm().findField("trackers").setValue("");this.hide()}});Deluge.EditTracker=Ext.extend(Ext.Window,{constructor:function(a){a=Ext.apply({title:_("Edit Tracker"),width:375,height:110,bodyStyle:"padding: 5px",layout:"fit",buttonAlign:"right",closeAction:"hide",closable:true,iconCls:"x-deluge-edit-trackers",plain:true,resizable:false},a);Deluge.EditTracker.superclass.constructor.call(this,a)},initComponent:function(){Deluge.EditTracker.superclass.initComponent.call(this);this.addButton(_("Cancel"),this.onCancelClick,this);this.addButton(_("Save"),this.onSaveClick,this);this.on("hide",this.onHide,this);this.form=this.add({xtype:"form",defaultType:"textfield",baseCls:"x-plain",labelWidth:55,items:[{fieldLabel:_("Tracker"),name:"tracker",anchor:"100%"}]})},show:function(a){Deluge.EditTracker.superclass.show.call(this);this.record=a;this.form.getForm().findField("tracker").setValue(a.data.url)},onCancelClick:function(){this.hide()},onHide:function(){this.form.getForm().findField("tracker").setValue("")},onSaveClick:function(){var a=this.form.getForm().findField("tracker").getValue();this.record.set("url",a);this.record.commit();this.hide()}});Deluge.EditTrackers=Ext.extend(Ext.Window,{constructor:function(a){a=Ext.apply({title:_("Edit Trackers"),width:350,height:220,bodyStyle:"padding: 5px",layout:"fit",buttonAlign:"right",closeAction:"hide",closable:true,iconCls:"x-deluge-edit-trackers",plain:true,resizable:true},a);Deluge.EditTrackers.superclass.constructor.call(this,a)},initComponent:function(){Deluge.EditTrackers.superclass.initComponent.call(this);this.addButton(_("Cancel"),this.onCancelClick,this);this.addButton(_("Ok"),this.onOkClick,this);this.addEvents("save");this.on("show",this.onShow,this);this.on("save",this.onSave,this);this.addWindow=new Deluge.AddTracker();this.addWindow.on("add",this.onAddTrackers,this);this.editWindow=new Deluge.EditTracker();this.grid=this.add({xtype:"grid",store:new Ext.data.SimpleStore({fields:[{name:"tier",mapping:0},{name:"url",mapping:1}]}),columns:[{header:_("Tier"),width:50,sortable:true,renderer:fplain,dataIndex:"tier"},{id:"tracker",header:_("Tracker"),sortable:true,renderer:fplain,dataIndex:"url"}],stripeRows:true,selModel:new Ext.grid.RowSelectionModel({singleSelect:true,listeners:{selectionchange:{fn:this.onSelect,scope:this}}}),autoExpandColumn:"tracker",deferredRender:false,autoScroll:true,margins:"0 0 0 0",bbar:new Ext.Toolbar({items:[{text:_("Up"),iconCls:"icon-up",handler:this.onUpClick,scope:this},{text:_("Down"),iconCls:"icon-down",handler:this.onDownClick,scope:this},"->",{text:_("Add"),iconCls:"icon-add",handler:this.onAddClick,scope:this},{text:_("Edit"),iconCls:"icon-edit-trackers",handler:this.onEditClick,scope:this},{text:_("Remove"),iconCls:"icon-remove",handler:this.onRemoveClick,scope:this}]})})},onAddClick:function(){this.addWindow.show()},onAddTrackers:function(b){var a=this.grid.getStore();Ext.each(b,function(d){var e=false,c=-1;a.each(function(f){if(f.get("tier")>c){c=f.get("tier")}if(d==f.get("tracker")){e=true;return false}},this);if(!e){a.loadData([[c+1,d]],true)}},this)},onCancelClick:function(){this.hide()},onEditClick:function(){var a=this.grid.getSelectionModel().getSelected();this.editWindow.show(a)},onHide:function(){this.grid.getStore().removeAll()},onOkClick:function(){var a=[];this.grid.getStore().each(function(b){a.push({tier:b.get("tier"),url:b.get("url")})},this);deluge.client.core.set_torrent_trackers(this.torrentId,a,{failure:this.onSaveFail,scope:this});this.hide()},onRemove:function(){var a=this.grid.getSelectionModel().getSelected();this.grid.getStore().remove(a)},onRequestComplete:function(a){var b=[];Ext.each(a.trackers,function(c){b.push([c.tier,c.url])});this.grid.getStore().loadData(b)},onSaveFail:function(){},onSelect:function(a){if(a.hasSelection()){this.grid.getBottomToolbar().items.get(4).enable()}},onShow:function(){this.grid.getBottomToolbar().items.get(4).disable();var a=deluge.torrents.getSelected();this.torrentId=a.id;deluge.client.core.get_torrent_status(a.id,["trackers"],{success:this.onRequestComplete,scope:this})}});deluge.editTrackers=new Deluge.EditTrackers()})();Ext.namespace("Deluge");Deluge.FileBrowser=Ext.extend(Ext.Window,{title:_("File Browser"),width:500,height:400,initComponent:function(){Deluge.FileBrowser.superclass.initComponent.call(this);this.add({xtype:"toolbar",items:[{text:_("Back"),iconCls:"icon-back"},{text:_("Forward"),iconCls:"icon-forward"},{text:_("Up"),iconCls:"icon-up"},{text:_("Home"),iconCls:"icon-home"}]})}});Deluge.LoginWindow=Ext.extend(Ext.Window,{firstShow:true,bodyStyle:"padding: 10px 5px;",buttonAlign:"center",closable:false,closeAction:"hide",iconCls:"x-deluge-login-window-icon",layout:"fit",modal:true,plain:true,resizable:false,title:_("Login"),width:300,height:120,initComponent:function(){Deluge.LoginWindow.superclass.initComponent.call(this);this.on("show",this.onShow,this);this.addButton({text:_("Login"),handler:this.onLogin,scope:this});this.form=this.add({xtype:"form",baseCls:"x-plain",labelWidth:55,width:300,defaults:{width:200},defaultType:"textfield",});this.passwordField=this.form.add({xtype:"textfield",fieldLabel:_("Password"),id:"_password",name:"password",inputType:"password"});this.passwordField.on("specialkey",this.onSpecialKey,this)},logout:function(){deluge.events.fire("logout");deluge.client.auth.delete_session({success:function(a){this.show(true)},scope:this})},show:function(a){if(this.firstShow){deluge.client.on("error",this.onClientError,this);this.firstShow=false}if(a){return Deluge.LoginWindow.superclass.show.call(this)}deluge.client.auth.check_session({success:function(b){if(b){deluge.events.fire("login")}else{this.show(true)}},failure:function(b){this.show(true)},scope:this})},onSpecialKey:function(b,a){if(a.getKey()==13){this.onLogin()}},onLogin:function(){var a=this.passwordField;deluge.client.auth.login(a.getValue(),{success:function(b){if(b){deluge.events.fire("login");this.hide();a.setRawValue("")}else{Ext.MessageBox.show({title:_("Login Failed"),msg:_("You entered an incorrect password"),buttons:Ext.MessageBox.OK,modal:false,fn:function(){a.focus()},icon:Ext.MessageBox.WARNING,iconCls:"x-deluge-icon-warning"})}},scope:this})},onClientError:function(c,b,a){if(c.error.code==1){deluge.events.fire("logout");this.show(true)}},onShow:function(){this.passwordField.focus(false,150);this.passwordField.setRawValue("")}});deluge.login=new Deluge.LoginWindow();Ext.namespace("Deluge");Deluge.MoveStorage=Ext.extend(Ext.Window,{constructor:function(a){a=Ext.apply({title:_("Move Storage"),width:375,height:110,layout:"fit",buttonAlign:"right",closeAction:"hide",closable:true,iconCls:"x-deluge-move-storage",plain:true,resizable:false},a);Deluge.MoveStorage.superclass.constructor.call(this,a)},initComponent:function(){Deluge.MoveStorage.superclass.initComponent.call(this);this.addButton(_("Cancel"),this.onCancel,this);this.addButton(_("Move"),this.onMove,this);this.form=this.add({xtype:"form",border:false,defaultType:"textfield",width:300,bodyStyle:"padding: 5px"});this.moveLocation=this.form.add({fieldLabel:_("Location"),name:"location",width:240});this.form.add({xtype:"button",text:_("Browse"),handler:function(){if(!this.fileBrowser){this.fileBrowser=new Deluge.FileBrowser()}this.fileBrowser.show()},scope:this})},hide:function(){Deluge.MoveStorage.superclass.hide.call(this);this.torrentIds=null},show:function(a){Deluge.MoveStorage.superclass.show.call(this);this.torrentIds=a},onCancel:function(){this.hide()},onMove:function(){var a=this.moveLocation.getValue();deluge.client.core.move_storage(this.torrentIds,a);this.hide()}});deluge.moveStorage=new Deluge.MoveStorage();Deluge.Plugin=Ext.extend(Ext.util.Observable,{name:null,constructor:function(a){this.name=a.name;this.addEvents({enabled:true,disabled:true});this.isDelugePlugin=true;Deluge.Plugins[this.name]=this;Deluge.Plugin.superclass.constructor.call(this,a)},disable:function(){this.fireEvent("disabled",this);if(this.onDisable){this.onDisable()}},enable:function(){this.fireEvent("enable",this);if(this.onEnable){this.onEnable()}}});Ext.namespace("Deluge.preferences");PreferencesRecord=Ext.data.Record.create([{name:"name",type:"string"}]);Deluge.preferences.PreferencesWindow=Ext.extend(Ext.Window,{currentPage:null,title:_("Preferences"),layout:"border",width:485,height:500,buttonAlign:"right",closeAction:"hide",closable:true,iconCls:"x-deluge-preferences",plain:true,resizable:false,initComponent:function(){Deluge.preferences.PreferencesWindow.superclass.initComponent.call(this);this.categoriesGrid=this.add({xtype:"grid",region:"west",title:_("Categories"),store:new Ext.data.Store(),columns:[{id:"name",renderer:fplain,dataIndex:"name"}],sm:new Ext.grid.RowSelectionModel({singleSelect:true,listeners:{rowselect:{fn:this.onPageSelect,scope:this}}}),hideHeaders:true,autoExpandColumn:"name",deferredRender:false,autoScroll:true,margins:"5 0 5 5",cmargins:"5 0 5 5",width:120,collapsible:true});this.configPanel=this.add({type:"container",autoDestroy:false,region:"center",layout:"card",margins:"5 5 5 5",cmargins:"5 5 5 5"});this.addButton(_("Close"),this.onClose,this);this.addButton(_("Apply"),this.onApply,this);this.addButton(_("Ok"),this.onOk,this);this.pages={};this.optionsManager=new Deluge.OptionsManager();this.on("afterrender",this.onAfterRender,this);this.on("show",this.onShow,this)},onApply:function(b){var c=this.optionsManager.getDirty();if(!Ext.isObjectEmpty(c)){deluge.client.core.set_config(c,{success:this.onSetConfig,scope:this})}for(var a in this.pages){if(this.pages[a].onApply){this.pages[a].onApply()}}},getOptionsManager:function(){return this.optionsManager},addPage:function(c){var a=this.categoriesGrid.getStore();var b=c.title;a.add([new PreferencesRecord({name:b})]);c.bodyStyle="margin: 5px";this.pages[b]=this.configPanel.add(c);return this.pages[b]},removePage:function(c){var b=c.title;var a=this.categoriesGrid.getStore();a.removeAt(a.find("name",b));this.configPanel.remove(c);delete this.pages[c.title]},selectPage:function(b){var a=this.configPanel.items.indexOf(this.pages[b]);this.configPanel.getLayout().setActiveItem(a);this.currentPage=b},onGotConfig:function(a){this.getOptionsManager().set(a)},onPageSelect:function(a,c,b){this.selectPage(b.get("name"))},onSetConfig:function(){this.getOptionsManager().commit()},onAfterRender:function(){if(!this.categoriesGrid.getSelectionModel().hasSelection()){this.categoriesGrid.getSelectionModel().selectFirstRow()}this.configPanel.getLayout().setActiveItem(0)},onShow:function(){if(!deluge.client.core){return}deluge.client.core.get_config({success:this.onGotConfig,scope:this})},onClose:function(){this.hide()},onOk:function(){deluge.client.core.set_config(this.optionsManager.getDirty());this.hide()}});deluge.preferences=new Deluge.preferences.PreferencesWindow();Ext.namespace("Deluge.preferences");Deluge.preferences.Downloads=Ext.extend(Ext.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Downloads"),layout:"form",autoHeight:true,width:320},a);Deluge.preferences.Downloads.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Downloads.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Folders"),labelWidth:150,defaultType:"togglefield",autoHeight:true,labelAlign:"top",width:300,style:"margin-bottom: 5px; padding-bottom: 5px;"});b.bind("download_location",a.add({xtype:"textfield",name:"download_location",fieldLabel:_("Download to"),width:280}));var c=a.add({name:"move_completed_path",fieldLabel:_("Move completed to"),width:280});b.bind("move_completed",c.toggle);b.bind("move_completed_path",c.input);c=a.add({name:"torrentfiles_location",fieldLabel:_("Copy of .torrent files to"),width:280});b.bind("copy_torrent_file",c.toggle);b.bind("torrentfiles_location",c.input);c=a.add({name:"autoadd_location",fieldLabel:_("Autoadd .torrent files from"),width:280});b.bind("autoadd_enable",c.toggle);b.bind("autoadd_location",c.input);a=this.add({xtype:"fieldset",border:false,title:_("Allocation"),autoHeight:true,labelWidth:1,defaultType:"radiogroup",style:"margin-bottom: 5px; margin-top: 0; padding-bottom: 5px; padding-top: 0;",width:240,});b.bind("compact_allocation",a.add({name:"compact_allocation",width:200,labelSeparator:"",disabled:true,defaults:{width:80,height:22,name:"compact_allocation"},items:[{boxLabel:_("Use Full"),inputValue:false},{boxLabel:_("Use Compact"),inputValue:true}]}));a=this.add({xtype:"fieldset",border:false,title:_("Options"),autoHeight:true,labelWidth:1,defaultType:"checkbox",style:"margin-bottom: 0; padding-bottom: 0;",width:280});b.bind("prioritize_first_last_pieces",a.add({name:"prioritize_first_last_pieces",labelSeparator:"",height:22,boxLabel:_("Prioritize first and last pieces of torrent")}));b.bind("add_paused",a.add({name:"add_paused",labelSeparator:"",height:22,boxLabel:_("Add torrents in Paused state")}));this.on("show",this.onShow,this)},onShow:function(){Deluge.preferences.Downloads.superclass.onShow.call(this)}});deluge.preferences.addPage(new Deluge.preferences.Downloads());Ext.namespace("Deluge.preferences");Deluge.preferences.Network=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Network"),layout:"form"},a);Deluge.preferences.Network.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Network.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Incoming Ports"),style:"margin-bottom: 5px; padding-bottom: 0px;",autoHeight:true,labelWidth:1,defaultType:"checkbox"});b.bind("random_port",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("Use Random Ports"),name:"random_port",height:22,listeners:{check:{fn:function(d,c){this.listenPorts.setDisabled(c)},scope:this}}}));this.listenPorts=a.add({xtype:"uxspinnergroup",name:"listen_ports",fieldLabel:"",labelSeparator:"",colCfg:{labelWidth:40,style:"margin-right: 10px;"},items:[{fieldLabel:"From",width:80,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},},{fieldLabel:"To",width:80,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},}]});b.bind("listen_ports",this.listenPorts);a=this.add({xtype:"fieldset",border:false,title:_("Outgoing Ports"),style:"margin-bottom: 5px; padding-bottom: 0px;",autoHeight:true,labelWidth:1,defaultType:"checkbox"});b.bind("random_outgoing_ports",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("Use Random Ports"),name:"random_outgoing_ports",height:22,listeners:{check:{fn:function(d,c){this.outgoingPorts.setDisabled(c)},scope:this}}}));this.outgoingPorts=a.add({xtype:"uxspinnergroup",name:"outgoing_ports",fieldLabel:"",labelSeparator:"",colCfg:{labelWidth:40,style:"margin-right: 10px;"},items:[{fieldLabel:"From",strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},},{fieldLabel:"To",strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},}]});b.bind("outgoing_ports",this.outgoingPorts);a=this.add({xtype:"fieldset",border:false,title:_("Network Interface"),style:"margin-bottom: 5px; padding-bottom: 0px;",autoHeight:true,labelWidth:1,defaultType:"textfield"});b.bind("listen_interface",a.add({name:"listen_interface",fieldLabel:"",labelSeparator:"",width:200}));a=this.add({xtype:"fieldset",border:false,title:_("TOS"),style:"margin-bottom: 5px; padding-bottom: 0px;",bodyStyle:"margin: 0px; padding: 0px",autoHeight:true,defaultType:"textfield"});b.bind("peer_tos",a.add({name:"peer_tos",fieldLabel:_("Peer TOS Byte"),width:80}));a=this.add({xtype:"fieldset",border:false,title:_("Network Extras"),autoHeight:true,layout:"table",layoutConfig:{columns:3},defaultType:"checkbox"});b.bind("upnp",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("UPnP"),name:"upnp"}));b.bind("natpmp",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("NAT-PMP"),ctCls:"x-deluge-indent-checkbox",name:"natpmp"}));b.bind("utpex",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("Peer Exchange"),ctCls:"x-deluge-indent-checkbox",name:"utpex"}));b.bind("lsd",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("LSD"),name:"lsd"}));b.bind("dht",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("DHT"),ctCls:"x-deluge-indent-checkbox",name:"dht"}))}});deluge.preferences.addPage(new Deluge.preferences.Network());Ext.namespace("Deluge.preferences");Deluge.preferences.Encryption=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Encryption"),layout:"form"},a);Deluge.preferences.Encryption.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Encryption.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Settings"),autoHeight:true,defaultType:"combo"});b.bind("enc_in_policy",a.add({fieldLabel:_("Inbound"),mode:"local",width:150,store:new Ext.data.SimpleStore({fields:["id","text"],data:[[0,_("Forced")],[1,_("Enabled")],[2,_("Disabled")]]}),triggerAction:"all",valueField:"id",displayField:"text"}));b.bind("enc_out_policy",a.add({fieldLabel:_("Outbound"),mode:"local",width:150,store:new Ext.data.SimpleStore({fields:["id","text"],data:[[0,_("Forced")],[1,_("Enabled")],[2,_("Disabled")]]}),triggerAction:"all",valueField:"id",displayField:"text"}));b.bind("enc_level",a.add({fieldLabel:_("Level"),mode:"local",width:150,store:new Ext.data.SimpleStore({fields:["id","text"],data:[[0,_("Handshake")],[1,_("Full Stream")],[2,_("Either")]]}),triggerAction:"all",valueField:"id",displayField:"text"}));b.bind("enc_prefer_rc4",a.add({xtype:"checkbox",name:"enc_prefer_rc4",height:40,hideLabel:true,boxLabel:_("Encrypt entire stream")}))}});deluge.preferences.addPage(new Deluge.preferences.Encryption());Ext.namespace("Deluge.preferences");Deluge.preferences.Bandwidth=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Bandwidth"),layout:"form",labelWidth:10},a);Deluge.preferences.Bandwidth.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Bandwidth.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Global Bandwidth Usage"),labelWidth:200,defaultType:"spinnerfield",style:"margin-bottom: 0px; padding-bottom: 0px;",autoHeight:true});b.bind("max_connections_global",a.add({name:"max_connections_global",fieldLabel:_("Maximum Connections"),width:80,value:-1,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}}));b.bind("max_upload_slots_global",a.add({name:"max_upload_slots_global",fieldLabel:_("Maximum Upload Slots"),width:80,value:-1,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}}));b.bind("max_download_speed",a.add({name:"max_download_speed",fieldLabel:_("Maximum Download Speed (KiB/s)"),width:80,value:-1,strategy:{xtype:"number",decimalPrecision:1,minValue:-1,maxValue:99999}}));b.bind("max_upload_speed",a.add({name:"max_upload_speed",fieldLabel:_("Maximum Upload Speed (KiB/s)"),width:80,value:-1,strategy:{xtype:"number",decimalPrecision:1,minValue:-1,maxValue:99999}}));b.bind("max_half_open_connections",a.add({name:"max_half_open_connections",fieldLabel:_("Maximum Half-Open Connections"),width:80,value:-1,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}}));b.bind("max_connections_per_second",a.add({name:"max_connections_per_second",fieldLabel:_("Maximum Connection Attempts per Second"),width:80,value:-1,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}}));a=this.add({xtype:"fieldset",border:false,title:"",defaultType:"checkbox",style:"padding-top: 0px; padding-bottom: 5px; margin-top: 0px; margin-bottom: 0px;",autoHeight:true});b.bind("ignore_limits_on_local_network",a.add({name:"ignore_limits_on_local_network",height:22,fieldLabel:"",labelSeparator:"",boxLabel:_("Ignore limits on local network"),}));b.bind("rate_limit_ip_overhead",a.add({name:"rate_limit_ip_overhead",height:22,fieldLabel:"",labelSeparator:"",boxLabel:_("Rate limit IP overhead"),}));a=this.add({xtype:"fieldset",border:false,title:_("Per Torrent Bandwidth Usage"),style:"margin-bottom: 0px; padding-bottom: 0px;",defaultType:"spinnerfield",labelWidth:200,autoHeight:true});b.bind("max_connections_per_torrent",a.add({name:"max_connections_per_torrent",fieldLabel:_("Maximum Connections"),width:80,value:-1,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}}));b.bind("max_upload_slots_per_torrent",a.add({name:"max_upload_slots_per_torrent",fieldLabel:_("Maximum Upload Slots"),width:80,value:-1,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}}));b.bind("max_download_speed_per_torrent",a.add({name:"max_download_speed_per_torrent",fieldLabel:_("Maximum Download Speed (KiB/s)"),width:80,value:-1,strategy:{xtype:"number",decimalPrecision:1,minValue:-1,maxValue:99999}}));b.bind("max_upload_speed_per_torrent",a.add({name:"max_upload_speed_per_torrent",fieldLabel:_("Maximum Upload Speed (KiB/s)"),width:80,value:-1,strategy:{xtype:"number",decimalPrecision:1,minValue:-1,maxValue:99999}}))}});deluge.preferences.addPage(new Deluge.preferences.Bandwidth());Ext.namespace("Deluge.preferences");Deluge.preferences.Interface=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Interface"),layout:"form"},a);Deluge.preferences.Interface.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Interface.superclass.initComponent.call(this);var c=this.optionsManager=new Deluge.OptionsManager();this.on("show",this.onShow,this);var a=this.add({xtype:"fieldset",border:false,title:_("Interface"),style:"margin-bottom: 0px; padding-bottom: 5px; padding-top: 5px",autoHeight:true,labelWidth:1,defaultType:"checkbox"});c.bind("show_session_speed",a.add({name:"show_session_speed",height:22,fieldLabel:"",labelSeparator:"",boxLabel:_("Show session speed in titlebar")}));c.bind("sidebar_show_zero",a.add({name:"sidebar_show_zero",height:22,fieldLabel:"",labelSeparator:"",boxLabel:_("Show filters with zero torrents")}));c.bind("sidebar_show_trackers",a.add({name:"sidebar_show_trackers",height:22,fieldLabel:"",labelSeparator:"",boxLabel:_("Show trackers with zero torrents")}));a=this.add({xtype:"fieldset",border:false,title:_("Password"),style:"margin-bottom: 0px; padding-bottom: 0px; padding-top: 5px",autoHeight:true,labelWidth:110,defaultType:"textfield",defaults:{width:180,inputType:"password"}});this.oldPassword=a.add({name:"old_password",fieldLabel:_("Old Password")});this.newPassword=a.add({name:"new_password",fieldLabel:_("New Password")});this.confirmPassword=a.add({name:"confirm_password",fieldLabel:_("Confirm Password")});var b=a.add({xtype:"panel",autoHeight:true,border:false,width:320,bodyStyle:"padding-left: 230px"});b.add({xtype:"button",text:_("Change"),listeners:{click:{fn:this.onPasswordChange,scope:this}}});a=this.add({xtype:"fieldset",border:false,title:_("Server"),style:"margin-top: 0px; padding-top: 0px; margin-bottom: 0px; padding-bottom: 0px",autoHeight:true,labelWidth:110,defaultType:"spinnerfield",defaults:{width:80,}});c.bind("session_timeout",a.add({name:"session_timeout",fieldLabel:_("Session Timeout"),strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}}));c.bind("port",a.add({name:"port",fieldLabel:_("Port"),strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}}));this.httpsField=c.bind("https",a.add({xtype:"checkbox",name:"https",hideLabel:true,width:280,height:22,boxLabel:_("Use SSL (paths relative to Deluge config folder)")}));this.httpsField.on("check",this.onSSLCheck,this);this.pkeyField=c.bind("pkey",a.add({xtype:"textfield",disabled:true,name:"pkey",width:180,fieldLabel:_("Private Key")}));this.certField=c.bind("cert",a.add({xtype:"textfield",disabled:true,name:"cert",width:180,fieldLabel:_("Certificate")}))},onApply:function(){var a=this.optionsManager.getDirty();if(!Ext.isObjectEmpty(a)){deluge.client.web.set_config(a,{success:this.onSetConfig,scope:this})}},onGotConfig:function(a){this.optionsManager.set(a)},onPasswordChange:function(){var b=this.newPassword.getValue();if(b!=this.confirmPassword.getValue()){Ext.MessageBox.show({title:_("Invalid Password"),msg:_("Your passwords don't match!"),buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"});return}var a=this.oldPassword.getValue();deluge.client.auth.change_password(a,b,{success:function(c){if(!c){Ext.MessageBox.show({title:_("Password"),msg:_("Your old password was incorrect!"),buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"});this.oldPassword.setValue("")}else{Ext.MessageBox.show({title:_("Change Successful"),msg:_("Your password was successfully changed!"),buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.INFO,iconCls:"x-deluge-icon-info"});this.oldPassword.setValue("");this.newPassword.setValue("");this.confirmPassword.setValue("")}},scope:this})},onSetConfig:function(){this.optionsManager.commit()},onShow:function(){Deluge.preferences.Interface.superclass.onShow.call(this);deluge.client.web.get_config({success:this.onGotConfig,scope:this})},onSSLCheck:function(b,a){this.pkeyField.setDisabled(!a);this.certField.setDisabled(!a)}});deluge.preferences.addPage(new Deluge.preferences.Interface());Ext.namespace("Deluge.preferences");Deluge.preferences.Other=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Other"),layout:"form"},a);Deluge.preferences.Other.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Other.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Updates"),autoHeight:true,labelWidth:1,defaultType:"checkbox"});b.bind("new_release_check",a.add({fieldLabel:"",labelSeparator:"",height:22,name:"new_release_check",boxLabel:_("Be alerted about new releases")}));a=this.add({xtype:"fieldset",border:false,title:_("System Information"),autoHeight:true,labelWidth:1,defaultType:"checkbox"});a.add({xtype:"panel",border:false,bodyCfg:{html:_("Help us improve Deluge by sending us your Python version, PyGTK version, OS and processor types. Absolutely no other information is sent.")}});b.bind("send_info",a.add({fieldLabel:"",labelSeparator:"",height:22,boxLabel:_("Yes, please send anonymous statistics"),name:"send_info"}));a=this.add({xtype:"fieldset",border:false,title:_("GeoIP Database"),autoHeight:true,labelWidth:80,defaultType:"textfield"});b.bind("geoip_db_location",a.add({name:"geoip_db_location",fieldLabel:_("Location"),width:200}))}});deluge.preferences.addPage(new Deluge.preferences.Other());Ext.namespace("Deluge.preferences");Deluge.preferences.Daemon=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Daemon"),layout:"form"},a);Deluge.preferences.Daemon.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Daemon.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Port"),autoHeight:true,defaultType:"spinnerfield"});b.bind("daemon_port",a.add({fieldLabel:_("Daemon port"),name:"daemon_port",value:58846,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},}));a=this.add({xtype:"fieldset",border:false,title:_("Connections"),autoHeight:true,labelWidth:1,defaultType:"checkbox"});b.bind("allow_remote",a.add({fieldLabel:"",height:22,labelSeparator:"",boxLabel:_("Allow Remote Connections"),name:"allow_remote"}));a=this.add({xtype:"fieldset",border:false,title:_("Other"),autoHeight:true,labelWidth:1,defaultType:"checkbox"});b.bind("new_release_check",a.add({fieldLabel:"",labelSeparator:"",height:40,boxLabel:_("Periodically check the website for new releases"),id:"new_release_check"}))}});deluge.preferences.addPage(new Deluge.preferences.Daemon());Ext.namespace("Deluge.preferences");Deluge.preferences.Queue=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Queue"),layout:"form"},a);Deluge.preferences.Queue.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Queue.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("General"),style:"padding-top: 5px;",autoHeight:true,labelWidth:1,defaultType:"checkbox"});b.bind("queue_new_to_top",a.add({fieldLabel:"",labelSeparator:"",height:22,boxLabel:_("Queue new torrents to top"),name:"queue_new_to_top"}));a=this.add({xtype:"fieldset",border:false,title:_("Active Torrents"),autoHeight:true,labelWidth:150,defaultType:"spinnerfield",style:"margin-bottom: 0px; padding-bottom: 0px;",});b.bind("max_active_limit",a.add({fieldLabel:_("Total Active"),name:"max_active_limit",value:8,width:80,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},}));b.bind("max_active_downloading",a.add({fieldLabel:_("Total Active Downloading"),name:"max_active_downloading",value:3,width:80,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},}));b.bind("max_active_seeding",a.add({fieldLabel:_("Total Active Seeding"),name:"max_active_seeding",value:5,width:80,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},}));b.bind("dont_count_slow_torrents",a.add({xtype:"checkbox",name:"dont_count_slow_torrents",height:40,hideLabel:true,boxLabel:_("Do not count slow torrents")}));a=this.add({xtype:"fieldset",border:false,title:_("Seeding"),autoHeight:true,labelWidth:150,defaultType:"spinnerfield",style:"margin-bottom: 0px; padding-bottom: 0px; margin-top: 0; padding-top: 0;",});b.bind("share_ratio_limit",a.add({fieldLabel:_("Share Ratio Limit"),name:"share_ratio_limit",value:8,width:80,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},}));b.bind("seed_time_ratio_limit",a.add({fieldLabel:_("Share Time Ratio"),name:"seed_time_ratio_limit",value:3,width:80,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},}));b.bind("seed_time_limit",a.add({fieldLabel:_("Seed Time (m)"),name:"seed_time_limit",value:5,width:80,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},}));a=this.add({xtype:"fieldset",border:false,autoHeight:true,layout:"table",layoutConfig:{columns:2},labelWidth:0,defaultType:"checkbox",defaults:{fieldLabel:"",labelSeparator:""}});this.stopAtRatio=a.add({name:"stop_seed_at_ratio",boxLabel:_("Stop seeding when share ratio reaches:")});this.stopAtRatio.on("check",this.onStopRatioCheck,this);b.bind("stop_seed_at_ratio",this.stopAtRatio);this.stopRatio=a.add({xtype:"spinnerfield",name:"stop_seed_ratio",ctCls:"x-deluge-indent-checkbox",disabled:true,value:2,width:60,strategy:{xtype:"number",minValue:-1,maxValue:99999,incrementValue:0.1,alternateIncrementValue:1,decimalPrecision:1}});b.bind("stop_seed_ratio",this.stopRatio);this.removeAtRatio=a.add({name:"remove_seed_at_ratio",ctCls:"x-deluge-indent-checkbox",boxLabel:_("Remove torrent when share ratio is reached"),disabled:true,colspan:2});b.bind("remove_seed_at_ratio",this.removeAtRatio)},onStopRatioCheck:function(b,a){this.stopRatio.setDisabled(!a);this.removeAtRatio.setDisabled(!a)}});deluge.preferences.addPage(new Deluge.preferences.Queue());Ext.namespace("Deluge.preferences");Deluge.preferences.ProxyField=Ext.extend(Ext.form.FieldSet,{constructor:function(a){a=Ext.apply({border:false,autoHeight:true,labelWidth:70},a);Deluge.preferences.ProxyField.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.ProxyField.superclass.initComponent.call(this);this.type=this.add({xtype:"combo",fieldLabel:_("Type"),name:"type",mode:"local",width:150,store:new Ext.data.SimpleStore({fields:["id","text"],data:[[0,_("None")],[1,_("Socksv4")],[2,_("Socksv5")],[3,_("Socksv5 with Auth")],[4,_("HTTP")],[5,_("HTTP with Auth")],]}),value:0,triggerAction:"all",valueField:"id",displayField:"text"});this.hostname=this.add({xtype:"textfield",name:"hostname",fieldLabel:_("Host"),width:220});this.port=this.add({xtype:"spinnerfield",name:"port",fieldLabel:_("Port"),width:80,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}});this.username=this.add({xtype:"textfield",name:"username",fieldLabel:_("Username"),width:220});this.password=this.add({xtype:"textfield",name:"password",fieldLabel:_("Password"),inputType:"password",width:220});this.type.on("change",this.onFieldChange,this);this.type.on("select",this.onTypeSelect,this);this.setting=false},getName:function(){return this.initialConfig.name},getValue:function(){return{type:this.type.getValue(),hostname:this.hostname.getValue(),port:Number(this.port.getValue()),username:this.username.getValue(),password:this.password.getValue()}},setValue:function(c){this.setting=true;this.type.setValue(c.type);var b=this.type.getStore().find("id",c.type);var a=this.type.getStore().getAt(b);this.hostname.setValue(c.hostname);this.port.setValue(c.port);this.username.setValue(c.username);this.password.setValue(c.password);this.onTypeSelect(this.type,a,b);this.setting=false},onFieldChange:function(e,d,c){if(this.setting){return}var b=this.getValue();var a=Ext.apply({},b);a[e.getName()]=c;this.fireEvent("change",this,b,a)},onTypeSelect:function(d,a,b){var c=a.get("id");if(c>0){this.hostname.show();this.port.show()}else{this.hostname.hide();this.port.hide()}if(c==3||c==5){this.username.show();this.password.show()}else{this.username.hide();this.password.hide()}}});Deluge.preferences.Proxy=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Proxy"),layout:"form"},a);Deluge.preferences.Proxy.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Proxy.superclass.initComponent.call(this);this.peer=this.add(new Deluge.preferences.ProxyField({title:_("Peer"),name:"peer"}));this.peer.on("change",this.onProxyChange,this);this.web_seed=this.add(new Deluge.preferences.ProxyField({title:_("Web Seed"),name:"web_seed"}));this.web_seed.on("change",this.onProxyChange,this);this.tracker=this.add(new Deluge.preferences.ProxyField({title:_("Tracker"),name:"tracker"}));this.tracker.on("change",this.onProxyChange,this);this.dht=this.add(new Deluge.preferences.ProxyField({title:_("DHT"),name:"dht"}));this.dht.on("change",this.onProxyChange,this);deluge.preferences.getOptionsManager().bind("proxies",this)},getValue:function(){return{dht:this.dht.getValue(),peer:this.peer.getValue(),tracker:this.tracker.getValue(),web_seed:this.web_seed.getValue()}},setValue:function(b){for(var a in b){this[a].setValue(b[a])}},onProxyChange:function(e,d,c){var b=this.getValue();var a=Ext.apply({},b);a[e.getName()]=c;this.fireEvent("change",this,b,a)}});deluge.preferences.addPage(new Deluge.preferences.Proxy());Ext.namespace("Deluge.preferences");Deluge.preferences.Cache=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Cache"),layout:"form"},a);Deluge.preferences.Cache.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Cache.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Settings"),autoHeight:true,labelWidth:180,defaultType:"spinnerfield"});b.bind("cache_size",a.add({fieldLabel:_("Cache Size (16 KiB Blocks)"),name:"cache_size",width:60,value:512,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},}));b.bind("cache_expiry",a.add({fieldLabel:_("Cache Expiry (seconds)"),name:"cache_expiry",width:60,value:60,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},}))}});deluge.preferences.addPage(new Deluge.preferences.Cache());Ext.namespace("Deluge.preferences");Deluge.preferences.InstallPluginWindow=Ext.extend(Ext.Window,{height:115,width:350,bodyStyle:"padding: 10px 5px;",buttonAlign:"center",closeAction:"hide",iconCls:"x-deluge-install-plugin",layout:"fit",modal:true,plain:true,title:_("Install Plugin"),initComponent:function(){Deluge.add.FileWindow.superclass.initComponent.call(this);this.addButton(_("Install"),this.onInstall,this);this.form=this.add({xtype:"form",baseCls:"x-plain",labelWidth:70,autoHeight:true,fileUpload:true,items:[{xtype:"fileuploadfield",id:"pluginEgg",emptyText:_("Select an egg"),fieldLabel:_("Plugin Egg"),name:"file",buttonCfg:{text:_("Browse")+"..."}}]})},onInstall:function(b,a){this.form.getForm().submit({url:"/upload",waitMsg:_("Uploading your plugin..."),success:this.onUploadSuccess,scope:this})},onUploadPlugin:function(d,c,a,b){this.fireEvent("pluginadded")},onUploadSuccess:function(c,b){this.hide();if(b.result.success){var a=this.form.getForm().findField("pluginEgg").value;var d=b.result.files[0];this.form.getForm().findField("pluginEgg").setValue("");deluge.client.web.upload_plugin(a,d,{success:this.onUploadPlugin,scope:this,filename:a})}}});Deluge.preferences.Plugins=Ext.extend(Ext.Panel,{constructor:function(a){a=Ext.apply({border:false,title:_("Plugins"),layout:"border",height:400,cls:"x-deluge-plugins"},a);Deluge.preferences.Plugins.superclass.constructor.call(this,a)},pluginTemplate:new Ext.Template('
Author:
{author}
Version:
{version}
Author Email:
{email}
Homepage:
{homepage}
Details:
{details}
'),initComponent:function(){Deluge.preferences.Plugins.superclass.initComponent.call(this);this.defaultValues={version:"",email:"",homepage:"",details:""};this.pluginTemplate.compile();var b=function(d,e,c){e.css+=" x-grid3-check-col-td";return'
'};this.grid=this.add({xtype:"grid",region:"center",store:new Ext.data.SimpleStore({fields:[{name:"enabled",mapping:0},{name:"plugin",mapping:1}]}),columns:[{id:"enabled",header:_("Enabled"),width:50,sortable:true,renderer:b,dataIndex:"enabled"},{id:"plugin",header:_("Plugin"),sortable:true,dataIndex:"plugin"}],stripeRows:true,selModel:new Ext.grid.RowSelectionModel({singleSelect:true,listeners:{rowselect:{fn:this.onPluginSelect,scope:this}}}),autoExpandColumn:"plugin",deferredRender:false,autoScroll:true,margins:"5 5 5 5",bbar:new Ext.Toolbar({items:[{cls:"x-btn-text-icon",iconCls:"x-deluge-install-plugin",text:_("Install"),handler:this.onInstallPluginWindow,scope:this},"->",{cls:"x-btn-text-icon",text:_("Find More"),iconCls:"x-deluge-find-more",handler:this.onFindMorePlugins,scope:this}]})});var a=this.add({xtype:"fieldset",border:false,region:"south",title:_("Info"),autoHeight:true,labelWidth:1});this.pluginInfo=a.add({xtype:"panel",border:false,bodyCfg:{style:"margin-left: 10px"}});this.on("show",this.onShow,this);this.pluginInfo.on("render",this.onPluginInfoRender,this);this.grid.on("cellclick",this.onCellClick,this);deluge.preferences.on("show",this.onPreferencesShow,this);deluge.events.on("PluginDisabledEvent",this.onPluginDisabled,this);deluge.events.on("PluginEnabledEvent",this.onPluginEnabled,this)},disablePlugin:function(a){deluge.client.core.disable_plugin(a)},enablePlugin:function(a){deluge.client.core.enable_plugin(a)},setInfo:function(b){if(!this.pluginInfo.rendered){return}var a=b||this.defaultValues;this.pluginInfo.body.dom.innerHTML=this.pluginTemplate.apply(a)},updatePlugins:function(){deluge.client.web.get_plugins({success:this.onGotPlugins,scope:this})},updatePluginsGrid:function(){var a=[];Ext.each(this.availablePlugins,function(b){if(this.enabledPlugins.indexOf(b)>-1){a.push([true,b])}else{a.push([false,b])}},this);this.grid.getStore().loadData(a)},onCellClick:function(b,f,a,d){if(a!=0){return}var c=b.getStore().getAt(f);c.set("enabled",!c.get("enabled"));c.commit();if(c.get("enabled")){this.enablePlugin(c.get("plugin"))}else{this.disablePlugin(c.get("plugin"))}},onFindMorePlugins:function(){window.open("http://dev.deluge-torrent.org/wiki/Plugins")},onGotPlugins:function(a){this.enabledPlugins=a.enabled_plugins;this.availablePlugins=a.available_plugins;this.setInfo();this.updatePluginsGrid()},onGotPluginInfo:function(b){var a={author:b.Author,version:b.Version,email:b["Author-email"],homepage:b["Home-page"],details:b.Description};this.setInfo(a);delete b},onInstallPluginWindow:function(){if(!this.installWindow){this.installWindow=new Deluge.preferences.InstallPluginWindow();this.installWindow.on("pluginadded",this.onPluginInstall,this)}this.installWindow.show()},onPluginEnabled:function(c){var a=this.grid.getStore().find("plugin",c);var b=this.grid.getStore().getAt(a);b.set("enabled",true);b.commit()},onPluginDisabled:function(c){var a=this.grid.getStore().find("plugin",c);var b=this.grid.getStore().getAt(a);b.set("enabled",false);b.commit()},onPluginInstall:function(){this.updatePlugins()},onPluginSelect:function(b,c,a){deluge.client.web.get_plugin_info(a.get("plugin"),{success:this.onGotPluginInfo,scope:this})},onPreferencesShow:function(){this.updatePlugins()},onPluginInfoRender:function(b,a){this.setInfo()}});deluge.preferences.addPage(new Deluge.preferences.Plugins());Deluge.RemoveWindow=Ext.extend(Ext.Window,{constructor:function(a){a=Ext.apply({title:_("Remove Torrent"),layout:"fit",width:350,height:100,buttonAlign:"right",closeAction:"hide",closable:true,plain:true,iconCls:"x-deluge-remove-window-icon"},a);Deluge.RemoveWindow.superclass.constructor.call(this,a)},initComponent:function(){Deluge.RemoveWindow.superclass.initComponent.call(this);this.addButton(_("Cancel"),this.onCancel,this);this.addButton(_("Remove With Data"),this.onRemoveData,this);this.addButton(_("Remove Torrent"),this.onRemove,this);this.add({border:false,bodyStyle:"padding: 5px; padding-left: 10px;",html:"Are you sure you wish to remove the torrent(s)?"})},remove:function(a){Ext.each(this.torrentIds,function(b){deluge.client.core.remove_torrent(b,a,{success:function(){this.onRemoved(b)},scope:this,torrentId:b})},this)},show:function(a){Deluge.RemoveWindow.superclass.show.call(this);this.torrentIds=a},onCancel:function(){this.hide();this.torrentIds=null},onRemove:function(){this.remove(false)},onRemoveData:function(){this.remove(true)},onRemoved:function(a){deluge.events.fire("torrentRemoved",a);this.hide();deluge.ui.update()}});deluge.removeWindow=new Deluge.RemoveWindow();(function(){function a(d,f,c){var b=d.toLowerCase().replace(".","_");var e="";if(c.store.id=="tracker_host"){if(d!="Error"){e=String.format("url("+deluge.config.base+"tracker/{0})",d)}else{b=null}}if(e){return String.format('
{0} ({1})
',d,c.data.count,e)}else{if(b){return String.format('
{0} ({1})
',d,c.data.count,b)}else{return String.format('
{0} ({1})
',d,c.data.count)}}}Deluge.Sidebar=Ext.extend(Ext.Panel,{panels:{},selected:null,constructor:function(b){b=Ext.apply({id:"sidebar",region:"west",cls:"deluge-sidebar",title:_("Filters"),layout:"accordion",split:true,width:200,minSize:175,collapsible:true,margins:"5 0 0 5",cmargins:"5 0 0 5"},b);Deluge.Sidebar.superclass.constructor.call(this,b)},initComponent:function(){Deluge.Sidebar.superclass.initComponent.call(this);deluge.events.on("disconnect",this.onDisconnect,this)},createFilter:function(e,d){var c=new Ext.data.ArrayStore({idIndex:0,fields:[{name:"filter"},{name:"count"}]});c.id=e;var g=e.replace("_"," ");var f=g.split(" ");g="";Ext.each(f,function(h){firstLetter=h.substring(0,1);firstLetter=firstLetter.toUpperCase();h=firstLetter+h.substring(1);g+=h+" "});var b=new Ext.grid.GridPanel({id:e+"-panel",border:false,store:c,title:_(g),columns:[{id:"filter",sortable:false,renderer:a,dataIndex:"filter"}],stripeRows:false,selModel:new Ext.grid.RowSelectionModel({singleSelect:true,listeners:{rowselect:{fn:this.onFilterSelect,scope:this}}}),hideHeaders:true,autoExpandColumn:"filter",deferredRender:false,autoScroll:true});if(deluge.config.sidebar_show_zero==false){d=this.removeZero(d)}c.loadData(d);this.add(b);this.doLayout();this.panels[e]=b;b.getSelectionModel().selectFirstRow()},getFilters:function(){var b={};this.items.each(function(c){var f=c.getSelectionModel();if(!f.hasSelection()){return}var d=f.getSelected();var e=c.getStore().id;if(d.id=="All"){return}b[e]=d.id},this);return b},onDisconnect:function(){Ext.each(Ext.getKeys(this.panels),function(b){this.remove(b+"-panel")},this);this.panels={};this.selected=null},onFilterSelect:function(c,d,b){deluge.ui.update()},removeZero:function(b){var c=[];Ext.each(b,function(d){if(d[1]>0||d[0]==_("All")){c.push(d)}});return c},update:function(d){for(var c in d){var b=d[c];if(Ext.getKeys(this.panels).indexOf(c)>-1){this.updateFilter(c,b)}else{this.createFilter(c,b)}}Ext.each(Ext.keys(this.panels),function(e){if(Ext.keys(d).indexOf(e)==-1){this.panels[e]}},this)},updateFilter:function(d,c){if(deluge.config.sidebar_show_zero==false){c=this.removeZero(c)}var b=this.panels[d].getStore();var e=[];Ext.each(c,function(h,g){var f=b.getById(h[0]);if(!f){f=new b.recordType({filter:h[0],count:h[1]});f.id=h[0];b.insert(g,[f])}f.beginEdit();f.set("filter",h[0]);f.set("count",h[1]);f.endEdit();e[h[0]]=true},this);b.each(function(f){if(e[f.id]){return}b.remove(f)},this);b.commitChanges()}});deluge.sidebar=new Deluge.Sidebar()})();Deluge.Statusbar=Ext.extend(Ext.ux.StatusBar,{constructor:function(a){a=Ext.apply({id:"deluge-statusbar",defaultIconCls:"x-not-connected",defaultText:_("Not Connected")},a);Deluge.Statusbar.superclass.constructor.call(this,a)},initComponent:function(){Deluge.Statusbar.superclass.initComponent.call(this);deluge.events.on("connect",this.onConnect,this);deluge.events.on("disconnect",this.onDisconnect,this)},createButtons:function(){this.buttons=this.add({id:"statusbar-connections",text:" ",cls:"x-btn-text-icon",iconCls:"x-deluge-connections",tooltip:_("Connections"),menu:deluge.menus.connections},"-",{id:"statusbar-downspeed",text:" ",cls:"x-btn-text-icon",iconCls:"x-deluge-downloading",tooltip:_("Download Speed"),menu:deluge.menus.download},"-",{id:"statusbar-upspeed",text:" ",cls:"x-btn-text-icon",iconCls:"x-deluge-seeding",tooltip:_("Upload Speed"),menu:deluge.menus.upload},"-",{id:"statusbar-traffic",text:" ",cls:"x-btn-text-icon",iconCls:"x-deluge-traffic",tooltip:_("Protocol Traffic Download/Upload")},"-",{id:"statusbar-dht",text:" ",cls:"x-btn-text-icon",iconCls:"x-deluge-dht",tooltip:_("DHT Nodes")},"-",{id:"statusbar-freespace",text:" ",cls:"x-btn-text-icon",iconCls:"x-deluge-freespace",tooltip:_("Freespace in download location")});this.created=true},onConnect:function(){this.setStatus({iconCls:"x-connected",text:""});if(!this.created){this.createButtons()}else{Ext.each(this.buttons,function(a){a.show();a.enable()})}this.doLayout()},onDisconnect:function(){this.clearStatus({useDefaults:true});Ext.each(this.buttons,function(a){a.hide();a.disable()});this.doLayout()},update:function(b){if(!b){return}function c(d){return d+" KiB/s"}var a=function(f,e){var g=this.items.get("statusbar-"+f);if(e.limit.value>0){var h=(e.value.formatter)?e.value.formatter(e.value.value,true):e.value.value;var d=(e.limit.formatter)?e.limit.formatter(e.limit.value,true):e.limit.value;var i=String.format(e.format,h,d)}else{var i=(e.value.formatter)?e.value.formatter(e.value.value,true):e.value.value}g.setText(i)}.createDelegate(this);a("connections",{value:{value:b.num_connections},limit:{value:b.max_num_connections},format:"{0} ({1})"});a("downspeed",{value:{value:b.download_rate,formatter:Deluge.Formatters.speed},limit:{value:b.max_download,formatter:c},format:"{0} ({1})"});a("upspeed",{value:{value:b.upload_rate,formatter:Deluge.Formatters.speed},limit:{value:b.max_upload,formatter:c},format:"{0} ({1})"});a("traffic",{value:{value:b.download_protocol_rate,formatter:Deluge.Formatters.speed},limit:{value:b.upload_protocol_rate,formatter:Deluge.Formatters.speed},format:"{0}/{1}"});this.items.get("statusbar-dht").setText(b.dht_nodes);this.items.get("statusbar-freespace").setText(fsize(b.free_space));deluge.menus.connections.setValue(b.max_num_connections);deluge.menus.download.setValue(b.max_download);deluge.menus.upload.setValue(b.max_upload)}});deluge.statusbar=new Deluge.Statusbar();Deluge.Toolbar=Ext.extend(Ext.Toolbar,{constructor:function(a){a=Ext.apply({items:[{id:"create",disabled:true,text:_("Create"),iconCls:"icon-create",handler:this.onTorrentAction},{id:"add",disabled:true,text:_("Add"),iconCls:"icon-add",handler:this.onTorrentAdd},{id:"remove",disabled:true,text:_("Remove"),iconCls:"icon-remove",handler:this.onTorrentAction},"|",{id:"pause",disabled:true,text:_("Pause"),iconCls:"icon-pause",handler:this.onTorrentAction},{id:"resume",disabled:true,text:_("Resume"),iconCls:"icon-resume",handler:this.onTorrentAction},"|",{id:"up",cls:"x-btn-text-icon",disabled:true,text:_("Up"),iconCls:"icon-up",handler:this.onTorrentAction},{id:"down",disabled:true,text:_("Down"),iconCls:"icon-down",handler:this.onTorrentAction},"|",{id:"preferences",text:_("Preferences"),iconCls:"x-deluge-preferences",handler:this.onPreferencesClick,scope:this},{id:"connectionman",text:_("Connection Manager"),iconCls:"x-deluge-connection-manager",handler:this.onConnectionManagerClick,scope:this},"->",{id:"help",iconCls:"icon-help",text:_("Help"),handler:this.onHelpClick,scope:this},{id:"logout",iconCls:"icon-logout",disabled:true,text:_("Logout"),handler:this.onLogout,scope:this}]},a);Deluge.Toolbar.superclass.constructor.call(this,a)},connectedButtons:["add","remove","pause","resume","up","down"],initComponent:function(){Deluge.Toolbar.superclass.initComponent.call(this);deluge.events.on("connect",this.onConnect,this);deluge.events.on("login",this.onLogin,this)},onConnect:function(){Ext.each(this.connectedButtons,function(a){this.items.get(a).enable()},this)},onDisconnect:function(){Ext.each(this.connectedButtons,function(a){this.items.get(a).disable()},this)},onLogin:function(){this.items.get("logout").enable()},onLogout:function(){this.items.get("logout").disable();deluge.login.logout()},onConnectionManagerClick:function(){deluge.connectionManager.show()},onHelpClick:function(){window.open("http://dev.deluge-torrent.org/wiki/UserGuide")},onPreferencesClick:function(){deluge.preferences.show()},onTorrentAction:function(c){var b=deluge.torrents.getSelections();var a=[];Ext.each(b,function(d){a.push(d.id)});switch(c.id){case"remove":deluge.removeWindow.show(a);break;case"pause":case"resume":deluge.client.core[c.id+"_torrent"](a,{success:function(){deluge.ui.update()}});break;case"up":case"down":deluge.client.core["queue_"+c.id](a,{success:function(){deluge.ui.update()}});break}},onTorrentAdd:function(){deluge.add.show()}});deluge.toolbar=new Deluge.Toolbar();Deluge.Torrent=Ext.data.Record.create([{name:"queue",type:"int"},{name:"name",type:"string"},{name:"total_size",type:"int"},{name:"state",type:"string"},{name:"progress",type:"int"},{name:"num_seeds",type:"int"},{name:"total_seeds",type:"int"},{name:"num_peers",type:"int"},{name:"total_peers",type:"int"},{name:"download_payload_rate",type:"int"},{name:"upload_payload_rate",type:"int"},{name:"eta",type:"int"},{name:"ratio",type:"float"},{name:"distributed_copies",type:"float"},{name:"time_added",type:"int"},{name:"tracker_host",type:"string"}]);(function(){function c(j){return(j==99999)?"":j+1}function e(k,l,j){return String.format('
{1}
',j.data.state.toLowerCase(),k)}function g(j){if(!j){return}return fspeed(j)}function i(m,n,l){m=new Number(m);var j=m;var o=l.data.state+" "+m.toFixed(2)+"%";var k=new Number(this.style.match(/\w+:\s*(\d+)\w+/)[1]);return Deluge.progressBar(m,k-8,o)}function a(k,l,j){if(j.data.total_seeds>-1){return String.format("{0} ({1})",k,j.data.total_seeds)}else{return k}}function d(k,l,j){if(j.data.total_peers>-1){return String.format("{0} ({1})",k,j.data.total_peers)}else{return k}}function b(k,l,j){return(k<0)?"∞":new Number(k).toFixed(3)}function f(k,l,j){return String.format('
{0}
',k)}function h(j){return j*-1}Deluge.TorrentGrid=Ext.extend(Ext.grid.GridPanel,{torrents:{},constructor:function(j){j=Ext.apply({id:"torrentGrid",store:new Ext.data.JsonStore({root:"torrents",idProperty:"id",fields:[{name:"queue"},{name:"name"},{name:"total_size",type:"int"},{name:"state"},{name:"progress",type:"float"},{name:"num_seeds",type:"int"},{name:"total_seeds",type:"int"},{name:"num_peers",type:"int"},{name:"total_peers",type:"int"},{name:"download_payload_rate",type:"int"},{name:"upload_payload_speed",type:"int"},{name:"eta",type:"int",sortType:h},{name:"ratio",type:"float"},{name:"distributed_copies",type:"float"},{name:"time_added",type:"int"},{name:"tracker_host"}]}),columns:[{id:"queue",header:_("#"),width:30,sortable:true,renderer:c,dataIndex:"queue"},{id:"name",header:_("Name"),width:150,sortable:true,renderer:e,dataIndex:"name"},{header:_("Size"),width:75,sortable:true,renderer:fsize,dataIndex:"total_size"},{header:_("Progress"),width:150,sortable:true,renderer:i,dataIndex:"progress"},{header:_("Seeders"),width:60,sortable:true,renderer:a,dataIndex:"num_seeds"},{header:_("Peers"),width:60,sortable:true,renderer:d,dataIndex:"num_peers"},{header:_("Down Speed"),width:80,sortable:true,renderer:g,dataIndex:"download_payload_rate"},{header:_("Up Speed"),width:80,sortable:true,renderer:g,dataIndex:"upload_payload_rate"},{header:_("ETA"),width:60,sortable:true,renderer:ftime,dataIndex:"eta"},{header:_("Ratio"),width:60,sortable:true,renderer:b,dataIndex:"ratio"},{header:_("Avail"),width:60,sortable:true,renderer:b,dataIndex:"distributed_copies"},{header:_("Added"),width:80,sortable:true,renderer:fdate,dataIndex:"time_added"},{header:_("Tracker"),width:120,sortable:true,renderer:f,dataIndex:"tracker_host"}],region:"center",cls:"deluge-torrents",stripeRows:true,autoExpandColumn:"name",deferredRender:false,autoScroll:true,margins:"5 5 0 0",stateful:true,view:new Ext.ux.grid.BufferView({rowHeight:26,scrollDelay:false})},j);Deluge.TorrentGrid.superclass.constructor.call(this,j)},initComponent:function(){Deluge.TorrentGrid.superclass.initComponent.call(this);deluge.events.on("torrentRemoved",this.onTorrentRemoved,this);deluge.events.on("logout",this.onDisconnect,this);this.on("rowcontextmenu",function(j,m,l){l.stopEvent();var k=j.getSelectionModel();if(!k.hasSelection()){k.selectRow(m)}deluge.menus.torrent.showAt(l.getPoint())})},getTorrent:function(j){return this.getStore().getAt(j)},getSelected:function(){return this.getSelectionModel().getSelected()},getSelections:function(){return this.getSelectionModel().getSelections()},update:function(q){var o=this.getStore();var m=[];for(var p in q){var r=q[p];if(this.torrents[p]){var l=o.getById(p);l.beginEdit();for(var n in r){if(l.get(n)!=r[n]){l.set(n,r[n])}}l.endEdit()}else{var l=new Deluge.Torrent(r);l.id=p;this.torrents[p]=1;m.push(l)}}o.add(m);o.each(function(k){if(!q[k.id]){o.remove(k);delete this.torrents[k.id]}},this);o.commitChanges();var j=o.getSortState();if(!j){return}o.sort(j.field,j.direction)},onDisconnect:function(){this.getStore().removeAll();this.torrents={}},onTorrentRemoved:function(k){var j=this.getSelectionModel();Ext.each(k,function(m){var l=this.getStore().getById(m);if(j.isSelected(l)){j.deselectRow(this.getStore().indexOf(l))}this.getStore().remove(l)},this)}});deluge.torrents=new Deluge.TorrentGrid()})();deluge.ui={errorCount:0,filters:null,initialize:function(){this.MainPanel=new Ext.Panel({id:"mainPanel",iconCls:"x-deluge-main-panel",title:"Deluge",layout:"border",tbar:deluge.toolbar,items:[deluge.sidebar,deluge.details,deluge.torrents],bbar:deluge.statusbar});this.Viewport=new Ext.Viewport({layout:"fit",items:[this.MainPanel]});deluge.events.on("connect",this.onConnect,this);deluge.events.on("disconnect",this.onDisconnect,this);deluge.client=new Ext.ux.util.RpcClient({url:deluge.config.base+"json"});for(var a in deluge.dlugins){a=deluge.plugins[a];a.enable()}Ext.QuickTips.init();deluge.client.on("connected",function(b){deluge.login.show()},this,{single:true});this.update=this.update.createDelegate(this);this.originalTitle=document.title},update:function(){var a=deluge.sidebar.getFilters();deluge.client.web.update_ui(Deluge.Keys.Grid,a,{success:this.onUpdate,failure:this.onUpdateError,scope:this});deluge.details.update()},onUpdateError:function(a){if(this.errorCount==2){Ext.MessageBox.show({title:"Lost Connection",msg:"The connection to the webserver has been lost!",buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.ERROR})}this.errorCount++},onUpdate:function(a){if(!a.connected){deluge.events.fire("disconnect")}if(deluge.config.show_session_speed){document.title=this.originalTitle+" (Down: "+fspeed(a.stats.download_rate,true)+" Up: "+fspeed(a.stats.upload_rate,true)+")"}deluge.torrents.update(a.torrents);deluge.statusbar.update(a.stats);deluge.sidebar.update(a.filters);this.errorCount=0},onConnect:function(){if(!this.running){this.running=setInterval(this.update,2000);this.update()}},onDisconnect:function(){this.stop()},onPluginEnabled:function(a){deluge.client.web.get_plugin_resources(a,{success:this.onGotPluginResources,scope:this})},onGotPluginResources:function(b){var a=(deluge.debug)?b.debug_scripts:b.scripts;Ext.each(a,function(c){Ext.ux.JSLoader({url:c,onLoad:this.onPluginLoaded,pluginName:b.name})},this)},onPluginDisabled:function(a){deluge.plugins[a].disable()},onPluginLoaded:function(a){if(!deluge.plugins[a.pluginName]){return}deluge.plugins[a.pluginName].enable()},stop:function(){if(this.running){clearInterval(this.running);this.running=false;deluge.torrents.getStore().removeAll()}}};Ext.onReady(function(a){deluge.ui.initialize()}); \ No newline at end of file +/* + * Deluge.data.SortTypes.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.data");Deluge.data.SortTypes={asIPAddress:function(a){var b=a.match(/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\:(\d+)/);return((((((+b[1])*256)+(+b[2]))*256)+(+b[3]))*256)+(+b[4])},asQueuePosition:function(a){return(a>-1)?a:Number.MAX_VALUE}} +/* + * Deluge.data.PeerRecord.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +;Ext.namespace("Deluge.data");Deluge.data.Peer=Ext.data.Record.create([{name:"country",type:"string"},{name:"ip",type:"string",sortType:Deluge.data.SortTypes.asIPAddress},{name:"client",type:"string"},{name:"progress",type:"float"},{name:"down_speed",type:"int"},{name:"up_speed",type:"int"},{name:"seed",type:"int"}]); +/* + * Deluge.data.TorrentRecord.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.data");Deluge.data.Torrent=Ext.data.Record.create([{name:"queue",type:"int"},{name:"name",type:"string"},{name:"total_size",type:"int"},{name:"state",type:"string"},{name:"progress",type:"int"},{name:"num_seeds",type:"int"},{name:"total_seeds",type:"int"},{name:"num_peers",type:"int"},{name:"total_peers",type:"int"},{name:"download_payload_rate",type:"int"},{name:"upload_payload_rate",type:"int"},{name:"eta",type:"int"},{name:"ratio",type:"float"},{name:"distributed_copies",type:"float"},{name:"time_added",type:"int"},{name:"tracker_host",type:"string"}]); +/* + * Deluge.details.DetailsPanel.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.details");Deluge.details.DetailsPanel=Ext.extend(Ext.TabPanel,{region:"south",id:"torrentDetails",split:true,height:210,minSize:100,collapsible:true,margins:"0 5 5 5",activeTab:0,initComponent:function(){Deluge.details.DetailsPanel.superclass.initComponent.call(this);this.add(new Deluge.details.StatusTab());this.add(new Deluge.details.DetailsTab());this.add(new Deluge.details.FilesTab());this.add(new Deluge.details.PeersTab());this.add(new Deluge.details.OptionsTab())},clear:function(){this.items.each(function(a){if(a.clear){a.clear.defer(100,a);a.disable()}})},update:function(a){var b=deluge.torrents.getSelected();if(!b){this.clear();return}this.items.each(function(c){if(c.disabled){c.enable()}});a=a||this.getActiveTab();if(a.update){a.update(b.id)}},onRender:function(b,a){Deluge.details.DetailsPanel.superclass.onRender.call(this,b,a);deluge.events.on("disconnect",this.clear,this);deluge.torrents.on("rowclick",this.onTorrentsClick,this);this.on("tabchange",this.onTabChange,this);deluge.torrents.getSelectionModel().on("selectionchange",function(c){if(!c.hasSelection()){this.clear()}},this)},onTabChange:function(a,b){this.update(b)},onTorrentsClick:function(a,c,b){this.update()}});Deluge.details.DetailsTab=Ext.extend(Ext.Panel,{title:_("Details"),fields:{},queuedItems:{},oldData:{},initComponent:function(){Deluge.details.DetailsTab.superclass.initComponent.call(this);this.addItem("torrent_name",_("Name"));this.addItem("hash",_("Hash"));this.addItem("path",_("Path"));this.addItem("size",_("Total Size"));this.addItem("files",_("# of files"));this.addItem("comment",_("Comment"));this.addItem("status",_("Status"));this.addItem("tracker",_("Tracker"))},onRender:function(b,a){Deluge.details.DetailsTab.superclass.onRender.call(this,b,a);this.body.setStyle("padding","10px");this.dl=Ext.DomHelper.append(this.body,{tag:"dl"},true);for(var c in this.queuedItems){this.doAddItem(c,this.queuedItems[c])}},addItem:function(b,a){if(!this.rendered){this.queuedItems[b]=a}else{this.doAddItem(b,a)}},doAddItem:function(b,a){Ext.DomHelper.append(this.dl,{tag:"dt",cls:b,html:a+":"});this.fields[b]=Ext.DomHelper.append(this.dl,{tag:"dd",cls:b,html:""},true)},clear:function(){if(!this.fields){return}for(var a in this.fields){this.fields[a].dom.innerHTML=""}this.oldData={}},update:function(a){deluge.client.web.get_torrent_status(a,Deluge.Keys.Details,{success:this.onRequestComplete,scope:this,torrentId:a})},onRequestComplete:function(e,c,a,b){var d={torrent_name:e.name,hash:b.options.torrentId,path:e.save_path,size:fsize(e.total_size),files:e.num_files,status:e.tracker_status,tracker:e.tracker,comment:e.comment};for(var f in this.fields){if(!Ext.isDefined(d[f])){continue}if(d[f]==this.oldData[f]){continue}this.fields[f].dom.innerHTML=Ext.escapeHTML(d[f])}this.oldData=d}}); +/* + * Deluge.details.FilesTab.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Deluge.details.FilesTab=Ext.extend(Ext.ux.tree.TreeGrid,{title:_("Files"),autoScroll:true,rootVisible:false,columns:[{header:_("Filename"),width:330,dataIndex:"filename"},{header:_("Size"),width:150,dataIndex:"size",tpl:new Ext.XTemplate("{size:this.fsize}",{fsize:function(a){return fsize(a)}})},{xtype:"tgrendercolumn",header:_("Progress"),width:150,dataIndex:"progress",renderer:function(a){var b=a*100;return Deluge.progressBar(b,this.col.width,b.toFixed(2)+"%",0)}},{header:_("Priority"),width:150,dataIndex:"priority",tpl:new Ext.XTemplate('
{priority:this.getName}
',{getClass:function(a){return FILE_PRIORITY_CSS[a]},getName:function(a){return _(FILE_PRIORITY[a])}})}],selModel:new Ext.tree.MultiSelectionModel(),initComponent:function(){Deluge.details.FilesTab.superclass.initComponent.call(this);this.setRootNode(new Ext.tree.TreeNode({text:"Files"}))},clear:function(){var a=this.getRootNode();if(!a.hasChildNodes()){return}a.cascade(function(c){var b=c.parentNode;if(!b){return}if(!b.ownerTree){return}b.removeChild(c)})},createFileTree:function(c){function b(g,d){for(var e in g.contents){var f=g.contents[e];if(f.type=="dir"){b(f,d.appendChild(new Ext.tree.TreeNode({text:e,filename:e,size:f.size,progress:f.progress,priority:f.priority})))}else{d.appendChild(new Ext.tree.TreeNode({text:e,filename:e,fileIndex:f.index,size:f.size,progress:f.progress,priority:f.priority,leaf:true,iconCls:"x-deluge-file",uiProvider:Ext.ux.tree.TreeGridNodeUI}))}}}var a=this.getRootNode();b(c,a);a.firstChild.expand()},update:function(a){if(this.torrentId!=a){this.clear();this.torrentId=a}deluge.client.web.get_torrent_files(a,{success:this.onRequestComplete,scope:this,torrentId:a})},updateFileTree:function(b){function a(g,c){for(var d in g.contents){var f=g.contents[d];var e=c.findChild("filename",d);e.attributes.size=f.size;e.attributes.progress=f.progress;e.attributes.priority=f.priority;e.ui.updateColumns();if(f.type=="dir"){a(f,e)}}}a(b,this.getRootNode())},onRender:function(b,a){Deluge.details.FilesTab.superclass.onRender.call(this,b,a);deluge.menus.filePriorities.on("itemclick",this.onItemClick,this);this.on("contextmenu",this.onContextMenu,this);this.sorter=new Ext.tree.TreeSorter(this,{folderSort:true})},onContextMenu:function(b,c){c.stopEvent();var a=this.getSelectionModel();if(a.getSelectedNodes().length<2){a.clearSelections();b.select()}deluge.menus.filePriorities.showAt(c.getPoint())},onItemClick:function(h,g){switch(h.id){case"expandAll":this.expandAll();break;default:var f={};function a(e){if(Ext.isEmpty(e.attributes.fileIndex)){return}f[e.attributes.fileIndex]=e.attributes.priority}this.getRootNode().cascade(a);var b=this.getSelectionModel().getSelectedNodes();Ext.each(b,function(i){if(!i.isLeaf()){function e(j){if(Ext.isEmpty(j.attributes.fileIndex)){return}f[j.attributes.fileIndex]=h.filePriority}i.cascade(e)}else{if(!Ext.isEmpty(i.attributes.fileIndex)){f[i.attributes.fileIndex]=h.filePriority;return}}});var d=new Array(Ext.keys(f).length);for(var c in f){d[c]=f[c]}deluge.client.core.set_torrent_file_priorities(this.torrentId,d,{success:function(){Ext.each(b,function(e){e.setColumnValue(3,h.filePriority)})},scope:this});break}},onRequestComplete:function(b,a){if(!this.getRootNode().hasChildNodes()){this.createFileTree(b)}else{this.updateFileTree(b)}}}); +/* + * Deluge.details.OptionsTab.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Deluge.details.OptionsTab=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({autoScroll:true,bodyStyle:"padding: 5px;",border:false,cls:"x-deluge-options",defaults:{autoHeight:true,labelWidth:1,defaultType:"checkbox"},deferredRender:false,layout:"column",title:_("Options")},a);Deluge.details.OptionsTab.superclass.constructor.call(this,a)},initComponent:function(){Deluge.details.OptionsTab.superclass.initComponent.call(this);this.fieldsets={},this.fields={};this.optionsManager=new Deluge.MultiOptionsManager({options:{max_download_speed:-1,max_upload_speed:-1,max_connections:-1,max_upload_slots:-1,auto_managed:false,stop_at_ratio:false,stop_ratio:2,remove_at_ratio:false,move_completed:null,"private":false,prioritize_first_last:false}});this.fieldsets.bandwidth=this.add({xtype:"fieldset",defaultType:"spinnerfield",bodyStyle:"padding: 5px",layout:"table",layoutConfig:{columns:3},labelWidth:150,style:"margin-left: 10px; margin-right: 5px; padding: 5px",title:_("Bandwidth"),width:250});this.fieldsets.bandwidth.add({xtype:"label",text:_("Max Download Speed"),forId:"max_download_speed",cls:"x-deluge-options-label"});this.fields.max_download_speed=this.fieldsets.bandwidth.add({id:"max_download_speed",name:"max_download_speed",width:70,strategy:{xtype:"number",decimalPrecision:1,minValue:-1,maxValue:99999}});this.fieldsets.bandwidth.add({xtype:"label",text:_("KiB/s"),style:"margin-left: 10px"});this.fieldsets.bandwidth.add({xtype:"label",text:_("Max Upload Speed"),forId:"max_upload_speed",cls:"x-deluge-options-label"});this.fields.max_upload_speed=this.fieldsets.bandwidth.add({id:"max_upload_speed",name:"max_upload_speed",width:70,value:-1,strategy:{xtype:"number",decimalPrecision:1,minValue:-1,maxValue:99999}});this.fieldsets.bandwidth.add({xtype:"label",text:_("KiB/s"),style:"margin-left: 10px"});this.fieldsets.bandwidth.add({xtype:"label",text:_("Max Connections"),forId:"max_connections",cls:"x-deluge-options-label"});this.fields.max_connections=this.fieldsets.bandwidth.add({id:"max_connections",name:"max_connections",width:70,value:-1,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},colspan:2});this.fieldsets.bandwidth.add({xtype:"label",text:_("Max Upload Slots"),forId:"max_upload_slots",cls:"x-deluge-options-label"});this.fields.max_upload_slots=this.fieldsets.bandwidth.add({id:"max_upload_slots",name:"max_upload_slots",width:70,value:-1,strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999},colspan:2});this.fieldsets.queue=this.add({xtype:"fieldset",title:_("Queue"),style:"margin-left: 5px; margin-right: 5px; padding: 5px",width:210,layout:"table",layoutConfig:{columns:2},labelWidth:0,defaults:{fieldLabel:"",labelSeparator:""}});this.fields.auto_managed=this.fieldsets.queue.add({xtype:"checkbox",fieldLabel:"",labelSeparator:"",name:"is_auto_managed",boxLabel:_("Auto Managed"),width:200,colspan:2});this.fields.stop_at_ratio=this.fieldsets.queue.add({fieldLabel:"",labelSeparator:"",id:"stop_at_ratio",width:120,boxLabel:_("Stop seed at ratio"),handler:this.onStopRatioChecked,scope:this});this.fields.stop_ratio=this.fieldsets.queue.add({xtype:"spinnerfield",id:"stop_ratio",name:"stop_ratio",disabled:true,width:50,value:2,strategy:{xtype:"number",minValue:-1,maxValue:99999,incrementValue:0.1,alternateIncrementValue:1,decimalPrecision:1}});this.fields.remove_at_ratio=this.fieldsets.queue.add({fieldLabel:"",labelSeparator:"",id:"remove_at_ratio",ctCls:"x-deluge-indent-checkbox",bodyStyle:"padding-left: 10px",boxLabel:_("Remove at ratio"),disabled:true,colspan:2});this.fields.move_completed=this.fieldsets.queue.add({fieldLabel:"",labelSeparator:"",id:"move_completed",boxLabel:_("Move Completed"),colspan:2});this.rightColumn=this.add({border:false,autoHeight:true,style:"margin-left: 5px",width:210});this.fieldsets.general=this.rightColumn.add({xtype:"fieldset",autoHeight:true,defaultType:"checkbox",title:_("General"),layout:"form"});this.fields["private"]=this.fieldsets.general.add({fieldLabel:"",labelSeparator:"",boxLabel:_("Private"),id:"private",disabled:true});this.fields.prioritize_first_last=this.fieldsets.general.add({fieldLabel:"",labelSeparator:"",boxLabel:_("Prioritize First/Last"),id:"prioritize_first_last"});for(var a in this.fields){this.optionsManager.bind(a,this.fields[a])}this.buttonPanel=this.rightColumn.add({layout:"hbox",xtype:"panel",border:false});this.buttonPanel.add({id:"edit_trackers",xtype:"button",text:_("Edit Trackers"),cls:"x-btn-text-icon",iconCls:"x-deluge-edit-trackers",border:false,width:100,handler:this.onEditTrackers,scope:this});this.buttonPanel.add({id:"apply",xtype:"button",text:_("Apply"),style:"margin-left: 10px;",border:false,width:100,handler:this.onApply,scope:this})},onRender:function(b,a){Deluge.details.OptionsTab.superclass.onRender.call(this,b,a);this.layout=new Ext.layout.ColumnLayout();this.layout.setContainer(this);this.doLayout()},clear:function(){if(this.torrentId==null){return}this.torrentId=null;this.optionsManager.changeId(null)},reset:function(){if(this.torrentId){this.optionsManager.reset()}},update:function(a){if(this.torrentId&&!a){this.clear()}if(!a){return}if(this.torrentId!=a){this.torrentId=a;this.optionsManager.changeId(a)}deluge.client.web.get_torrent_status(a,Deluge.Keys.Options,{success:this.onRequestComplete,scope:this})},onApply:function(){var b=this.optionsManager.getDirty();if(!Ext.isEmpty(b.prioritize_first_last)){var a=b.prioritize_first_last;deluge.client.core.set_torrent_prioritize_first_last(this.torrentId,a,{success:function(){this.optionsManager.set("prioritize_first_last",a)},scope:this})}deluge.client.core.set_torrent_options([this.torrentId],b,{success:function(){this.optionsManager.commit()},scope:this})},onEditTrackers:function(){deluge.editTrackers.show()},onStopRatioChecked:function(b,a){this.fields.remove_at_ratio.setDisabled(!a);this.fields.stop_ratio.setDisabled(!a)},onRequestComplete:function(c,b){this.fields["private"].setValue(c["private"]);this.fields["private"].setDisabled(true);delete c["private"];c.auto_managed=c.is_auto_managed;this.optionsManager.setDefault(c);var a=this.optionsManager.get("stop_at_ratio");this.fields.remove_at_ratio.setDisabled(!a);this.fields.stop_ratio.setDisabled(!a)}}); +/* + * Deluge.details.PeersTab.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +(function(){function a(d){if(!d){return""}return String.format('',d)}function b(f,g,e){var d=(e.data.seed==1024)?"x-deluge-seed":"x-deluge-peer";return String.format('
{1}
',d,f)}function c(e){var d=(e*100).toFixed(0);return Deluge.progressBar(d,this.width-8,d+"%")}Deluge.details.PeersTab=Ext.extend(Ext.grid.GridPanel,{peers:{},constructor:function(d){d=Ext.apply({title:_("Peers"),cls:"x-deluge-peers",store:new Ext.data.Store({reader:new Ext.data.JsonReader({idProperty:"ip",root:"peers"},Deluge.data.Peer)}),columns:[{header:" ",width:30,sortable:true,renderer:a,dataIndex:"country"},{header:"Address",width:125,sortable:true,renderer:b,dataIndex:"ip"},{header:"Client",width:125,sortable:true,renderer:fplain,dataIndex:"client"},{header:"Progress",width:150,sortable:true,renderer:c,dataIndex:"progress"},{header:"Down Speed",width:100,sortable:true,renderer:fspeed,dataIndex:"down_speed"},{header:"Up Speed",width:100,sortable:true,renderer:fspeed,dataIndex:"up_speed"}],stripeRows:true,deferredRender:false,autoScroll:true},d);Deluge.details.PeersTab.superclass.constructor.call(this,d)},clear:function(){this.getStore().removeAll();this.peers={}},update:function(d){deluge.client.web.get_torrent_status(d,Deluge.Keys.Peers,{success:this.onRequestComplete,scope:this})},onRequestComplete:function(h,g){if(!h){return}var f=this.getStore();var e=[];var i={};Ext.each(h.peers,function(j){if(this.peers[j.ip]){}else{this.peers[j.ip]=1;e.push(new Deluge.data.Peer(j,j.ip))}i[j.ip]=1},this);f.add(e);f.each(function(j){if(!i[j.id]){f.remove(j);delete this.peers[j.id]}},this);f.commitChanges();var d=f.getSortState();if(!d){return}f.sort(d.field,d.direction)}})})(); +/* + * Deluge.details.StatusTab.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge.details");Deluge.details.StatusTab=Ext.extend(Ext.Panel,{title:_("Status"),autoScroll:true,onRender:function(b,a){Deluge.details.StatusTab.superclass.onRender.call(this,b,a);this.progressBar=this.add({xtype:"progress",cls:"x-deluge-status-progressbar"});this.status=this.add({cls:"x-deluge-status",id:"deluge-details-status",border:false,width:1000,listeners:{render:{fn:function(c){c.load({url:deluge.config.base+"render/tab_status.html",text:_("Loading")+"..."});c.getUpdater().on("update",this.onPanelUpdate,this)},scope:this}}})},clear:function(){this.progressBar.updateProgress(0," ");for(var a in this.fields){this.fields[a].innerHTML=""}},update:function(a){if(!this.fields){this.getFields()}deluge.client.web.get_torrent_status(a,Deluge.Keys.Status,{success:this.onRequestComplete,scope:this})},onPanelUpdate:function(b,a){this.fields={};Ext.each(Ext.query("dd",this.status.body.dom),function(c){this.fields[c.className]=c},this)},onRequestComplete:function(a){seeders=a.total_seeds>-1?a.num_seeds+" ("+a.total_seeds+")":a.num_seeds;peers=a.total_peers>-1?a.num_peers+" ("+a.total_peers+")":a.num_peers;var b={downloaded:fsize(a.total_done,true),uploaded:fsize(a.total_uploaded,true),share:(a.ratio==-1)?"∞":a.ratio.toFixed(3),announce:ftime(a.next_announce),tracker_status:a.tracker_status,downspeed:(a.download_payload_rate)?fspeed(a.download_payload_rate):"0.0 KiB/s",upspeed:(a.upload_payload_rate)?fspeed(a.upload_payload_rate):"0.0 KiB/s",eta:ftime(a.eta),pieces:a.num_pieces+" ("+fsize(a.piece_length)+")",seeders:seeders,peers:peers,avail:a.distributed_copies.toFixed(3),active_time:ftime(a.active_time),seeding_time:ftime(a.seeding_time),seed_rank:a.seed_rank,time_added:fdate(a.time_added)};b.auto_managed=_((a.is_auto_managed)?"True":"False");b.downloaded+=" ("+((a.total_payload_download)?fsize(a.total_payload_download):"0.0 KiB")+")";b.uploaded+=" ("+((a.total_payload_download)?fsize(a.total_payload_download):"0.0 KiB")+")";for(var c in this.fields){this.fields[c].innerHTML=b[c]}var d=a.state+" "+a.progress.toFixed(2)+"%";this.progressBar.updateProgress(a.progress/100,d)}}); +/* + * Deluge.add.Window.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge.add");Deluge.add.Window=Ext.extend(Ext.Window,{initComponent:function(){Deluge.add.Window.superclass.initComponent.call(this);this.addEvents("beforeadd","add")},createTorrentId:function(){return new Date().getTime()}}); +/* + * Deluge.add.AddWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.add");Deluge.add.AddWindow=Ext.extend(Deluge.add.Window,{title:_("Add Torrents"),layout:"border",width:470,height:450,bodyStyle:"padding: 10px 5px;",buttonAlign:"right",closeAction:"hide",closable:true,plain:true,iconCls:"x-deluge-add-window-icon",initComponent:function(){Deluge.add.AddWindow.superclass.initComponent.call(this);this.addButton(_("Cancel"),this.onCancelClick,this);this.addButton(_("Add"),this.onAddClick,this);function a(c,d,b){if(b.data.info_hash){return String.format('
{0}
',c)}else{return String.format('
{0}
',c)}}this.list=new Ext.list.ListView({store:new Ext.data.SimpleStore({fields:[{name:"info_hash",mapping:1},{name:"text",mapping:2}],id:0}),columns:[{id:"torrent",width:150,sortable:true,renderer:a,dataIndex:"text"}],stripeRows:true,singleSelect:true,listeners:{selectionchange:{fn:this.onSelect,scope:this}},hideHeaders:true,autoExpandColumn:"torrent",autoScroll:true});this.add({region:"center",items:[this.list],margins:"5 5 5 5",bbar:new Ext.Toolbar({items:[{iconCls:"x-deluge-add-file",text:_("File"),handler:this.onFile,scope:this},{text:_("Url"),iconCls:"icon-add-url",handler:this.onUrl,scope:this},{text:_("Infohash"),iconCls:"icon-add-magnet",disabled:true},"->",{text:_("Remove"),iconCls:"icon-remove",handler:this.onRemove,scope:this}]})});this.optionsPanel=this.add(new Deluge.add.OptionsPanel());this.on("hide",this.onHide,this);this.on("show",this.onShow,this)},clear:function(){this.list.getStore().removeAll();this.optionsPanel.clear()},onAddClick:function(){var a=[];if(!this.list){return}this.list.getStore().each(function(b){var c=b.get("info_hash");a.push({path:this.optionsPanel.getFilename(c),options:this.optionsPanel.getOptions(c)})},this);deluge.client.web.add_torrents(a,{success:function(b){}});this.clear();this.hide()},onCancelClick:function(){this.clear();this.hide()},onFile:function(){if(!this.file){this.file=new Deluge.add.FileWindow()}this.file.show()},onHide:function(){this.optionsPanel.setActiveTab(0);this.optionsPanel.files.setDisabled(true);this.optionsPanel.form.setDisabled(true)},onRemove:function(){if(!this.list.getSelectionCount()){return}var a=this.list.getSelectedRecords()[0];this.list.getStore().remove(a);this.optionsPanel.clear();if(this.torrents&&this.torrents[a.id]){delete this.torrents[a.id]}},onSelect:function(c,b){if(b.length){var a=this.list.getRecord(b[0]);this.optionsPanel.setTorrent(a.get("info_hash"));this.optionsPanel.files.setDisabled(false);this.optionsPanel.form.setDisabled(false)}else{this.optionsPanel.files.setDisabled(true);this.optionsPanel.form.setDisabled(true)}},onShow:function(){if(!this.url){this.url=new Deluge.add.UrlWindow();this.url.on("beforeadd",this.onTorrentBeforeAdd,this);this.url.on("add",this.onTorrentAdd,this)}if(!this.file){this.file=new Deluge.add.FileWindow();this.file.on("beforeadd",this.onTorrentBeforeAdd,this);this.file.on("add",this.onTorrentAdd,this)}this.optionsPanel.form.getDefaults()},onTorrentBeforeAdd:function(b,c){var a=this.list.getStore();a.loadData([[b,null,c]],true)},onTorrentAdd:function(a,c){var b=this.list.getStore().getById(a);if(!c){Ext.MessageBox.show({title:_("Error"),msg:_("Not a valid torrent"),buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"});this.list.getStore().remove(b)}else{b.set("info_hash",c.info_hash);b.set("text",c.name);this.list.getStore().commitChanges();this.optionsPanel.addTorrent(c)}},onUrl:function(a,b){this.url.show()}}); +/* + * Deluge.add.File.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge.add");Deluge.add.FileWindow=Ext.extend(Deluge.add.Window,{title:_("Add from File"),layout:"fit",width:350,height:115,modal:true,plain:true,buttonAlign:"center",closeAction:"hide",bodyStyle:"padding: 10px 5px;",iconCls:"x-deluge-add-file",initComponent:function(){Deluge.add.FileWindow.superclass.initComponent.call(this);this.addButton(_("Add"),this.onAddClick,this);this.form=this.add({xtype:"form",baseCls:"x-plain",labelWidth:35,autoHeight:true,fileUpload:true,items:[{xtype:"fileuploadfield",id:"torrentFile",width:280,emptyText:_("Select a torrent"),fieldLabel:_("File"),name:"file",buttonCfg:{text:_("Browse")+"..."}}]})},onAddClick:function(c,b){if(this.form.getForm().isValid()){this.torrentId=this.createTorrentId();this.form.getForm().submit({url:"/upload",waitMsg:_("Uploading your torrent..."),failure:this.onUploadFailure,success:this.onUploadSuccess,scope:this});var a=this.form.getForm().findField("torrentFile").value;a=a.split("\\").slice(-1)[0];this.fireEvent("beforeadd",this.torrentId,a)}},onGotInfo:function(d,c,a,b){d.filename=b.options.filename;this.fireEvent("add",this.torrentId,d)},onUploadFailure:function(a,b){this.hide()},onUploadSuccess:function(c,b){this.hide();if(b.result.success){var a=b.result.files[0];this.form.getForm().findField("torrentFile").setValue("");deluge.client.web.get_torrent_info(a,{success:this.onGotInfo,scope:this,filename:a})}}}); +/* + * Deluge.add.FilesTab.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge.add");Deluge.add.FilesTab=Ext.extend(Ext.ux.tree.TreeGrid,{layout:"fit",title:_("Files"),autoScroll:true,animate:false,border:false,disabled:true,rootVisible:false,columns:[{header:_("Filename"),width:295,dataIndex:"filename"},{header:_("Size"),width:60,dataIndex:"size",tpl:new Ext.XTemplate("{size:this.fsize}",{fsize:function(a){return fsize(a)}})},{header:_("Download"),width:65,dataIndex:"download",tpl:new Ext.XTemplate("{download:this.format}",{format:function(a){return'
'}})}],initComponent:function(){Deluge.add.FilesTab.superclass.initComponent.call(this);this.on("click",this.onNodeClick,this)},clearFiles:function(){var a=this.getRootNode();if(!a.hasChildNodes()){return}a.cascade(function(b){if(!b.parentNode||!b.getOwnerTree()){return}b.remove()})},setDownload:function(b,c,d){b.attributes.download=c;b.ui.updateColumns();if(b.isLeaf()){if(!d){return this.fireEvent("fileschecked",[b],c,!c)}}else{var a=[b];b.cascade(function(e){e.attributes.download=c;e.ui.updateColumns();a.push(e)},this);if(!d){return this.fireEvent("fileschecked",a,c,!c)}}},onNodeClick:function(b,c){var a=new Ext.Element(c.target);if(a.getAttribute("rel")=="chkbox"){this.setDownload(b,!b.attributes.download)}}}); +/* + * Deluge.add.Infohash.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Ext.deluge.add"); +/* + * Deluge.add.OptionsPanel.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge.add");Deluge.add.OptionsPanel=Ext.extend(Ext.TabPanel,{torrents:{},region:"south",margins:"5 5 5 5",activeTab:0,height:220,initComponent:function(){Deluge.add.OptionsPanel.superclass.initComponent.call(this);this.files=this.add(new Deluge.add.FilesTab());this.form=this.add(new Deluge.add.OptionsTab());this.files.on("fileschecked",this.onFilesChecked,this)},addTorrent:function(c){this.torrents[c.info_hash]=c;var b={};this.walkFileTree(c.files_tree,function(e,g,h,f){if(g!="file"){return}b[h.index]=h.download},this);var a=[];Ext.each(Ext.keys(b),function(e){a[e]=b[e]});var d=this.form.optionsManager.changeId(c.info_hash,true);this.form.optionsManager.setDefault("file_priorities",a);this.form.optionsManager.changeId(d,true)},clear:function(){this.files.clearFiles();this.form.optionsManager.resetAll()},getFilename:function(a){return this.torrents[a]["filename"]},getOptions:function(a){var c=this.form.optionsManager.changeId(a,true);var b=this.form.optionsManager.get();this.form.optionsManager.changeId(c,true);Ext.each(b.file_priorities,function(e,d){b.file_priorities[d]=(e)?1:0});return b},setTorrent:function(b){if(!b){return}this.torrentId=b;this.form.optionsManager.changeId(b);this.files.clearFiles();var a=this.files.getRootNode();var c=this.form.optionsManager.get("file_priorities");this.walkFileTree(this.torrents[b]["files_tree"],function(e,f,h,d){var g=new Ext.tree.TreeNode({download:(h.index)?c[h.index]:true,filename:e,fileindex:h.index,leaf:f!="dir",size:h.length});d.appendChild(g);if(f=="dir"){return g}},this,a);a.firstChild.expand()},walkFileTree:function(g,h,e,a){for(var b in g.contents){var f=g.contents[b];var d=f.type;if(e){var c=h.apply(e,[b,d,f,a])}else{var c=h(b,d,f,a)}if(d=="dir"){this.walkFileTree(f,h,e,c)}}},onFilesChecked:function(a,c,b){if(this.form.optionsManager.get("compact_allocation")){Ext.Msg.show({title:_("Unable to set file priority!"),msg:_("File prioritization is unavailable when using Compact allocation. Would you like to switch to Full allocation?"),buttons:Ext.Msg.YESNO,fn:function(d){if(d=="yes"){this.form.optionsManager.update("compact_allocation",false);Ext.each(a,function(f){if(f.attributes.fileindex<0){return}var e=this.form.optionsManager.get("file_priorities");e[f.attributes.fileindex]=c;this.form.optionsManager.update("file_priorities",e)},this)}else{this.files.setDownload(a[0],b,true)}},scope:this,icon:Ext.MessageBox.QUESTION})}else{Ext.each(a,function(e){if(e.attributes.fileindex<0){return}var d=this.form.optionsManager.get("file_priorities");d[e.attributes.fileindex]=c;this.form.optionsManager.update("file_priorities",d)},this)}}}); +/* + * Deluge.add.OptionsPanel.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge.add");Deluge.add.OptionsTab=Ext.extend(Ext.form.FormPanel,{title:_("Options"),height:170,border:false,bodyStyle:"padding: 5px",disabled:true,labelWidth:1,initComponent:function(){Deluge.add.OptionsTab.superclass.initComponent.call(this);this.optionsManager=new Deluge.MultiOptionsManager();var a=this.add({xtype:"fieldset",title:_("Download Location"),border:false,autoHeight:true,defaultType:"textfield",labelWidth:1,fieldLabel:"",style:"padding-bottom: 5px; margin-bottom: 0px;"});this.optionsManager.bind("download_location",a.add({fieldLabel:"",name:"download_location",width:400,labelSeparator:""}));var b=this.add({border:false,layout:"column",defaultType:"fieldset"});a=b.add({title:_("Allocation"),border:false,autoHeight:true,defaultType:"radio",width:100});this.optionsManager.bind("compact_allocation",a.add({xtype:"radiogroup",columns:1,vertical:true,labelSeparator:"",items:[{name:"compact_allocation",value:false,inputValue:false,boxLabel:_("Full"),fieldLabel:"",labelSeparator:""},{name:"compact_allocation",value:true,inputValue:true,boxLabel:_("Compact"),fieldLabel:"",labelSeparator:""}]}));a=b.add({title:_("Bandwidth"),border:false,autoHeight:true,labelWidth:100,width:200,defaultType:"spinnerfield"});this.optionsManager.bind("max_download_speed",a.add({fieldLabel:_("Max Down Speed"),labelStyle:"margin-left: 10px",name:"max_download_speed",width:60}));this.optionsManager.bind("max_upload_speed",a.add({fieldLabel:_("Max Up Speed"),labelStyle:"margin-left: 10px",name:"max_upload_speed",width:60}));this.optionsManager.bind("max_connections",a.add({fieldLabel:_("Max Connections"),labelStyle:"margin-left: 10px",name:"max_connections",width:60}));this.optionsManager.bind("max_upload_slots",a.add({fieldLabel:_("Max Upload Slots"),labelStyle:"margin-left: 10px",name:"max_upload_slots",width:60}));a=b.add({title:_("General"),border:false,autoHeight:true,defaultType:"checkbox"});this.optionsManager.bind("add_paused",a.add({name:"add_paused",boxLabel:_("Add In Paused State"),fieldLabel:"",labelSeparator:""}));this.optionsManager.bind("prioritize_first_last_pieces",a.add({name:"prioritize_first_last_pieces",boxLabel:_("Prioritize First/Last Pieces"),fieldLabel:"",labelSeparator:""}))},getDefaults:function(){var a=["add_paused","compact_allocation","download_location","max_connections_per_torrent","max_download_speed_per_torrent","max_upload_slots_per_torrent","max_upload_speed_per_torrent","prioritize_first_last_pieces"];deluge.client.core.get_config_values(a,{success:function(c){var b={file_priorities:[],add_paused:c.add_paused,compact_allocation:c.compact_allocation,download_location:c.download_location,max_connections:c.max_connections_per_torrent,max_download_speed:c.max_download_speed_per_torrent,max_upload_slots:c.max_upload_slots_per_torrent,max_upload_speed:c.max_upload_speed_per_torrent,prioritize_first_last_pieces:c.prioritize_first_last_pieces};this.optionsManager.options=b;this.optionsManager.resetAll()},scope:this})}}); +/* + * Deluge.add.UrlWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.add");Deluge.add.UrlWindow=Ext.extend(Deluge.add.Window,{title:_("Add from Url"),modal:true,plain:true,layout:"fit",width:350,height:155,buttonAlign:"center",closeAction:"hide",bodyStyle:"padding: 10px 5px;",iconCls:"x-deluge-add-url-window-icon",initComponent:function(){Deluge.add.UrlWindow.superclass.initComponent.call(this);this.addButton(_("Add"),this.onAddClick,this);var a=this.add({xtype:"form",defaultType:"textfield",baseCls:"x-plain",labelWidth:55});this.urlField=a.add({fieldLabel:_("Url"),id:"url",name:"url",anchor:"100%"});this.urlField.on("specialkey",this.onAdd,this);this.cookieField=a.add({fieldLabel:_("Cookies"),id:"cookies",name:"cookies",anchor:"100%"});this.cookieField.on("specialkey",this.onAdd,this)},onAddClick:function(f,d){if((f.id=="url"||f.id=="cookies")&&d.getKey()!=d.ENTER){return}var f=this.urlField;var b=f.getValue();var c=this.cookieField.getValue();var a=this.createTorrentId();deluge.client.web.download_torrent_from_url(b,c,{success:this.onDownload,scope:this,torrentId:a});this.hide();this.fireEvent("beforeadd",a,b)},onDownload:function(a,c,d,b){this.urlField.setValue("");deluge.client.web.get_torrent_info(a,{success:this.onGotInfo,scope:this,filename:a,torrentId:b.options.torrentId})},onGotInfo:function(d,c,a,b){d.filename=b.options.filename;this.fireEvent("add",b.options.torrentId,d)}}); +/* + * Deluge.preferences.BandwidthPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");Deluge.preferences.Bandwidth=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Bandwidth"),layout:"form",labelWidth:10},a);Deluge.preferences.Bandwidth.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Bandwidth.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Global Bandwidth Usage"),labelWidth:200,defaultType:"spinnerfield",defaults:{minValue:-1,maxValue:99999},style:"margin-bottom: 0px; padding-bottom: 0px;",autoHeight:true});b.bind("max_connections_global",a.add({name:"max_connections_global",fieldLabel:_("Maximum Connections"),width:80,value:-1,decimalPrecision:0}));b.bind("max_upload_slots_global",a.add({name:"max_upload_slots_global",fieldLabel:_("Maximum Upload Slots"),width:80,value:-1,decimalPrecision:0}));b.bind("max_download_speed",a.add({name:"max_download_speed",fieldLabel:_("Maximum Download Speed (KiB/s)"),width:80,value:-1,decimalPrecision:1}));b.bind("max_upload_speed",a.add({name:"max_upload_speed",fieldLabel:_("Maximum Upload Speed (KiB/s)"),width:80,value:-1,decimalPrecision:1}));b.bind("max_half_open_connections",a.add({name:"max_half_open_connections",fieldLabel:_("Maximum Half-Open Connections"),width:80,value:-1,decimalPrecision:0}));b.bind("max_connections_per_second",a.add({name:"max_connections_per_second",fieldLabel:_("Maximum Connection Attempts per Second"),width:80,value:-1,decimalPrecision:0}));a=this.add({xtype:"fieldset",border:false,title:"",defaultType:"checkbox",style:"padding-top: 0px; padding-bottom: 5px; margin-top: 0px; margin-bottom: 0px;",autoHeight:true});b.bind("ignore_limits_on_local_network",a.add({name:"ignore_limits_on_local_network",height:22,fieldLabel:"",labelSeparator:"",boxLabel:_("Ignore limits on local network")}));b.bind("rate_limit_ip_overhead",a.add({name:"rate_limit_ip_overhead",height:22,fieldLabel:"",labelSeparator:"",boxLabel:_("Rate limit IP overhead")}));a=this.add({xtype:"fieldset",border:false,title:_("Per Torrent Bandwidth Usage"),style:"margin-bottom: 0px; padding-bottom: 0px;",defaultType:"spinnerfield",labelWidth:200,defaults:{minValue:-1,maxValue:99999},autoHeight:true});b.bind("max_connections_per_torrent",a.add({name:"max_connections_per_torrent",fieldLabel:_("Maximum Connections"),width:80,value:-1,decimalPrecision:0}));b.bind("max_upload_slots_per_torrent",a.add({name:"max_upload_slots_per_torrent",fieldLabel:_("Maximum Upload Slots"),width:80,value:-1,decimalPrecision:0}));b.bind("max_download_speed_per_torrent",a.add({name:"max_download_speed_per_torrent",fieldLabel:_("Maximum Download Speed (KiB/s)"),width:80,value:-1,decimalPrecision:0}));b.bind("max_upload_speed_per_torrent",a.add({name:"max_upload_speed_per_torrent",fieldLabel:_("Maximum Upload Speed (KiB/s)"),width:80,value:-1,decimalPrecision:0}))}}); +/* + * Deluge.preferences.CachePage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");Deluge.preferences.Cache=Ext.extend(Ext.form.FormPanel,{border:false,title:_("Cache"),layout:"form",initComponent:function(){Deluge.preferences.Cache.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Settings"),autoHeight:true,labelWidth:180,defaultType:"spinnerfield",defaults:{decimalPrecision:0,minValue:-1,maxValue:99999}});b.bind("cache_size",a.add({fieldLabel:_("Cache Size (16 KiB Blocks)"),name:"cache_size",width:60,value:512}));b.bind("cache_expiry",a.add({fieldLabel:_("Cache Expiry (seconds)"),name:"cache_expiry",width:60,value:60}))}}); +/* + * Deluge.preferences.DaemonPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");Deluge.preferences.Daemon=Ext.extend(Ext.form.FormPanel,{border:false,title:_("Daemon"),layout:"form",initComponent:function(){Deluge.preferences.Daemon.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Port"),autoHeight:true,defaultType:"spinnerfield"});b.bind("daemon_port",a.add({fieldLabel:_("Daemon port"),name:"daemon_port",value:58846,decimalPrecision:0,minValue:-1,maxValue:99999}));a=this.add({xtype:"fieldset",border:false,title:_("Connections"),autoHeight:true,labelWidth:1,defaultType:"checkbox"});b.bind("allow_remote",a.add({fieldLabel:"",height:22,labelSeparator:"",boxLabel:_("Allow Remote Connections"),name:"allow_remote"}));a=this.add({xtype:"fieldset",border:false,title:_("Other"),autoHeight:true,labelWidth:1,defaultType:"checkbox"});b.bind("new_release_check",a.add({fieldLabel:"",labelSeparator:"",height:40,boxLabel:_("Periodically check the website for new releases"),id:"new_release_check"}))}}); +/* + * Deluge.preferences.DownloadsPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");Deluge.preferences.Downloads=Ext.extend(Ext.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Downloads"),layout:"form",autoHeight:true,width:320},a);Deluge.preferences.Downloads.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Downloads.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Folders"),labelWidth:150,defaultType:"togglefield",autoHeight:true,labelAlign:"top",width:300,style:"margin-bottom: 5px; padding-bottom: 5px;"});b.bind("download_location",a.add({xtype:"textfield",name:"download_location",fieldLabel:_("Download to"),width:280}));var c=a.add({name:"move_completed_path",fieldLabel:_("Move completed to"),width:280});b.bind("move_completed",c.toggle);b.bind("move_completed_path",c.input);c=a.add({name:"torrentfiles_location",fieldLabel:_("Copy of .torrent files to"),width:280});b.bind("copy_torrent_file",c.toggle);b.bind("torrentfiles_location",c.input);c=a.add({name:"autoadd_location",fieldLabel:_("Autoadd .torrent files from"),width:280});b.bind("autoadd_enable",c.toggle);b.bind("autoadd_location",c.input);a=this.add({xtype:"fieldset",border:false,title:_("Allocation"),autoHeight:true,labelWidth:1,defaultType:"radiogroup",style:"margin-bottom: 5px; margin-top: 0; padding-bottom: 5px; padding-top: 0;",width:240});b.bind("compact_allocation",a.add({name:"compact_allocation",width:200,labelSeparator:"",defaults:{width:80,height:22,name:"compact_allocation"},items:[{boxLabel:_("Use Full"),inputValue:false},{boxLabel:_("Use Compact"),inputValue:true}]}));a=this.add({xtype:"fieldset",border:false,title:_("Options"),autoHeight:true,labelWidth:1,defaultType:"checkbox",style:"margin-bottom: 0; padding-bottom: 0;",width:280});b.bind("prioritize_first_last_pieces",a.add({name:"prioritize_first_last_pieces",labelSeparator:"",height:22,boxLabel:_("Prioritize first and last pieces of torrent")}));b.bind("add_paused",a.add({name:"add_paused",labelSeparator:"",height:22,boxLabel:_("Add torrents in Paused state")}))}}); +/* + * Deluge.preferences.EncryptionPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");Deluge.preferences.Encryption=Ext.extend(Ext.form.FormPanel,{border:false,title:_("Encryption"),initComponent:function(){Deluge.preferences.Encryption.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Settings"),autoHeight:true,defaultType:"combo",width:300});b.bind("enc_in_policy",a.add({fieldLabel:_("Inbound"),mode:"local",width:150,store:new Ext.data.ArrayStore({fields:["id","text"],data:[[0,_("Forced")],[1,_("Enabled")],[2,_("Disabled")]]}),editable:false,triggerAction:"all",valueField:"id",displayField:"text"}));b.bind("enc_out_policy",a.add({fieldLabel:_("Outbound"),mode:"local",width:150,store:new Ext.data.SimpleStore({fields:["id","text"],data:[[0,_("Forced")],[1,_("Enabled")],[2,_("Disabled")]]}),editable:false,triggerAction:"all",valueField:"id",displayField:"text"}));b.bind("enc_level",a.add({fieldLabel:_("Level"),mode:"local",width:150,store:new Ext.data.SimpleStore({fields:["id","text"],data:[[0,_("Handshake")],[1,_("Full Stream")],[2,_("Either")]]}),editable:false,triggerAction:"all",valueField:"id",displayField:"text"}));b.bind("enc_prefer_rc4",a.add({xtype:"checkbox",name:"enc_prefer_rc4",height:40,hideLabel:true,boxLabel:_("Encrypt entire stream")}))}}); +/* + * Deluge.preferences.InstallPluginWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");Deluge.preferences.InstallPluginWindow=Ext.extend(Ext.Window,{title:_("Install Plugin"),layout:"fit",height:115,width:350,bodyStyle:"padding: 10px 5px;",buttonAlign:"center",closeAction:"hide",iconCls:"x-deluge-install-plugin",modal:true,plain:true,initComponent:function(){Deluge.add.FileWindow.superclass.initComponent.call(this);this.addButton(_("Install"),this.onInstall,this);this.form=this.add({xtype:"form",baseCls:"x-plain",labelWidth:70,autoHeight:true,fileUpload:true,items:[{xtype:"fileuploadfield",width:240,emptyText:_("Select an egg"),fieldLabel:_("Plugin Egg"),name:"file",buttonCfg:{text:_("Browse")+"..."}}]})},onInstall:function(b,a){this.form.getForm().submit({url:"/upload",waitMsg:_("Uploading your plugin..."),success:this.onUploadSuccess,scope:this})},onUploadPlugin:function(d,c,a,b){this.fireEvent("pluginadded")},onUploadSuccess:function(c,b){this.hide();if(b.result.success){var a=this.form.getForm().getFieldValues().file;a=a.split("\\").slice(-1)[0];var d=b.result.files[0];this.form.getForm().setValues({file:""});deluge.client.web.upload_plugin(a,d,{success:this.onUploadPlugin,scope:this,filename:a})}}}); +/* + * Deluge.preferences.InterfacePage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");Deluge.preferences.Interface=Ext.extend(Ext.form.FormPanel,{border:false,title:_("Interface"),layout:"form",initComponent:function(){Deluge.preferences.Interface.superclass.initComponent.call(this);var c=this.optionsManager=new Deluge.OptionsManager();this.on("show",this.onPageShow,this);var a=this.add({xtype:"fieldset",border:false,title:_("Interface"),style:"margin-bottom: 0px; padding-bottom: 5px; padding-top: 5px",autoHeight:true,labelWidth:1,defaultType:"checkbox"});c.bind("show_session_speed",a.add({name:"show_session_speed",height:22,fieldLabel:"",labelSeparator:"",boxLabel:_("Show session speed in titlebar")}));c.bind("sidebar_show_zero",a.add({name:"sidebar_show_zero",height:22,fieldLabel:"",labelSeparator:"",boxLabel:_("Show filters with zero torrents")}));c.bind("sidebar_multiple_filters",a.add({name:"sidebar_multiple_filters",height:22,fieldLabel:"",labelSeparator:"",boxLabel:_("Allow the use of multiple filters at once")}));a=this.add({xtype:"fieldset",border:false,title:_("Password"),style:"margin-bottom: 0px; padding-bottom: 0px; padding-top: 5px",autoHeight:true,labelWidth:110,defaultType:"textfield",defaults:{width:180,inputType:"password"}});this.oldPassword=a.add({name:"old_password",fieldLabel:_("Old Password")});this.newPassword=a.add({name:"new_password",fieldLabel:_("New Password")});this.confirmPassword=a.add({name:"confirm_password",fieldLabel:_("Confirm Password")});var b=a.add({xtype:"panel",autoHeight:true,border:false,width:320,bodyStyle:"padding-left: 230px"});b.add({xtype:"button",text:_("Change"),listeners:{click:{fn:this.onPasswordChange,scope:this}}});a=this.add({xtype:"fieldset",border:false,title:_("Server"),style:"margin-top: 0px; padding-top: 0px; margin-bottom: 0px; padding-bottom: 0px",autoHeight:true,labelWidth:110,defaultType:"spinnerfield",defaults:{width:80}});c.bind("session_timeout",a.add({name:"session_timeout",fieldLabel:_("Session Timeout"),decimalPrecision:0,minValue:-1,maxValue:99999}));c.bind("port",a.add({name:"port",fieldLabel:_("Port"),decimalPrecision:0,minValue:-1,maxValue:99999}));this.httpsField=c.bind("https",a.add({xtype:"checkbox",name:"https",hideLabel:true,width:280,height:22,boxLabel:_("Use SSL (paths relative to Deluge config folder)")}));this.httpsField.on("check",this.onSSLCheck,this);this.pkeyField=c.bind("pkey",a.add({xtype:"textfield",disabled:true,name:"pkey",width:180,fieldLabel:_("Private Key")}));this.certField=c.bind("cert",a.add({xtype:"textfield",disabled:true,name:"cert",width:180,fieldLabel:_("Certificate")}))},onApply:function(){var b=this.optionsManager.getDirty();if(!Ext.isObjectEmpty(b)){deluge.client.web.set_config(b,{success:this.onSetConfig,scope:this});for(var a in deluge.config){deluge.config[a]=this.optionsManager.get(a)}}},onGotConfig:function(a){this.optionsManager.set(a)},onPasswordChange:function(){var b=this.newPassword.getValue();if(b!=this.confirmPassword.getValue()){Ext.MessageBox.show({title:_("Invalid Password"),msg:_("Your passwords don't match!"),buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"});return}var a=this.oldPassword.getValue();deluge.client.auth.change_password(a,b,{success:function(c){if(!c){Ext.MessageBox.show({title:_("Password"),msg:_("Your old password was incorrect!"),buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"});this.oldPassword.setValue("")}else{Ext.MessageBox.show({title:_("Change Successful"),msg:_("Your password was successfully changed!"),buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.INFO,iconCls:"x-deluge-icon-info"});this.oldPassword.setValue("");this.newPassword.setValue("");this.confirmPassword.setValue("")}},scope:this})},onSetConfig:function(){this.optionsManager.commit()},onPageShow:function(){deluge.client.web.get_config({success:this.onGotConfig,scope:this})},onSSLCheck:function(b,a){this.pkeyField.setDisabled(!a);this.certField.setDisabled(!a)}}); +/* + * Deluge.preferences.NetworkPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");Deluge.preferences.Network=Ext.extend(Ext.form.FormPanel,{border:false,layout:"form",title:_("Network"),initComponent:function(){Deluge.preferences.Network.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Incoming Ports"),style:"margin-bottom: 5px; padding-bottom: 0px;",autoHeight:true,labelWidth:1,defaultType:"checkbox"});b.bind("random_port",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("Use Random Ports"),name:"random_port",height:22,listeners:{check:{fn:function(d,c){this.listenPorts.setDisabled(c)},scope:this}}}));this.listenPorts=a.add({xtype:"spinnergroup",name:"listen_ports",fieldLabel:"",labelSeparator:"",colCfg:{labelWidth:40,style:"margin-right: 10px;"},items:[{fieldLabel:"From",strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}},{fieldLabel:"To",strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}}]});b.bind("listen_ports",this.listenPorts);a=this.add({xtype:"fieldset",border:false,title:_("Outgoing Ports"),style:"margin-bottom: 5px; padding-bottom: 0px;",autoHeight:true,labelWidth:1,defaultType:"checkbox"});b.bind("random_outgoing_ports",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("Use Random Ports"),name:"random_outgoing_ports",height:22,listeners:{check:{fn:function(d,c){this.outgoingPorts.setDisabled(c)},scope:this}}}));this.outgoingPorts=a.add({xtype:"spinnergroup",name:"outgoing_ports",fieldLabel:"",labelSeparator:"",colCfg:{labelWidth:40,style:"margin-right: 10px;"},items:[{fieldLabel:"From",strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}},{fieldLabel:"To",strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:99999}}]});b.bind("outgoing_ports",this.outgoingPorts);a=this.add({xtype:"fieldset",border:false,title:_("Network Interface"),style:"margin-bottom: 5px; padding-bottom: 0px;",autoHeight:true,labelWidth:1,defaultType:"textfield"});b.bind("listen_interface",a.add({name:"listen_interface",fieldLabel:"",labelSeparator:"",width:200}));a=this.add({xtype:"fieldset",border:false,title:_("TOS"),style:"margin-bottom: 5px; padding-bottom: 0px;",bodyStyle:"margin: 0px; padding: 0px",autoHeight:true,defaultType:"textfield"});b.bind("peer_tos",a.add({name:"peer_tos",fieldLabel:_("Peer TOS Byte"),width:80}));a=this.add({xtype:"fieldset",border:false,title:_("Network Extras"),autoHeight:true,layout:"table",layoutConfig:{columns:3},defaultType:"checkbox"});b.bind("upnp",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("UPnP"),name:"upnp"}));b.bind("natpmp",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("NAT-PMP"),ctCls:"x-deluge-indent-checkbox",name:"natpmp"}));b.bind("utpex",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("Peer Exchange"),ctCls:"x-deluge-indent-checkbox",name:"utpex"}));b.bind("lsd",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("LSD"),name:"lsd"}));b.bind("dht",a.add({fieldLabel:"",labelSeparator:"",boxLabel:_("DHT"),ctCls:"x-deluge-indent-checkbox",name:"dht"}))}}); +/* + * Deluge.preferences.OtherPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");Deluge.preferences.Other=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Other"),layout:"form"},a);Deluge.preferences.Other.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Other.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("Updates"),autoHeight:true,labelWidth:1,defaultType:"checkbox"});b.bind("new_release_check",a.add({fieldLabel:"",labelSeparator:"",height:22,name:"new_release_check",boxLabel:_("Be alerted about new releases")}));a=this.add({xtype:"fieldset",border:false,title:_("System Information"),autoHeight:true,labelWidth:1,defaultType:"checkbox"});a.add({xtype:"panel",border:false,bodyCfg:{html:_("Help us improve Deluge by sending us your Python version, PyGTK version, OS and processor types. Absolutely no other information is sent.")}});b.bind("send_info",a.add({fieldLabel:"",labelSeparator:"",height:22,boxLabel:_("Yes, please send anonymous statistics"),name:"send_info"}));a=this.add({xtype:"fieldset",border:false,title:_("GeoIP Database"),autoHeight:true,labelWidth:80,defaultType:"textfield"});b.bind("geoip_db_location",a.add({name:"geoip_db_location",fieldLabel:_("Location"),width:200}))}}); +/* + * Deluge.preferences.PluginsPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");Deluge.preferences.Plugins=Ext.extend(Ext.Panel,{layout:"border",title:_("Plugins"),border:false,height:400,cls:"x-deluge-plugins",pluginTemplate:new Ext.Template('
Author:
{author}
Version:
{version}
Author Email:
{email}
Homepage:
{homepage}
Details:
{details}
'),initComponent:function(){Deluge.preferences.Plugins.superclass.initComponent.call(this);this.defaultValues={version:"",email:"",homepage:"",details:""};this.pluginTemplate.compile();var c=function(e,f,d){f.css+=" x-grid3-check-col-td";return'
'};this.list=this.add({xtype:"listview",store:new Ext.data.ArrayStore({fields:[{name:"enabled",mapping:0},{name:"plugin",mapping:1}]}),columns:[{id:"enabled",header:_("Enabled"),width:0.2,sortable:true,tpl:new Ext.XTemplate("{enabled:this.getCheckbox}",{getCheckbox:function(d){return'
'}}),dataIndex:"enabled"},{id:"plugin",header:_("Plugin"),width:0.8,sortable:true,dataIndex:"plugin"}],singleSelect:true,autoExpandColumn:"plugin",listeners:{selectionchange:{fn:this.onPluginSelect,scope:this}}});this.panel=this.add({region:"center",autoScroll:true,margins:"5 5 5 5",items:[this.list],bbar:new Ext.Toolbar({items:[{cls:"x-btn-text-icon",iconCls:"x-deluge-install-plugin",text:_("Install"),handler:this.onInstallPluginWindow,scope:this},"->",{cls:"x-btn-text-icon",text:_("Find More"),iconCls:"x-deluge-find-more",handler:this.onFindMorePlugins,scope:this}]})});var b=this.pluginInfo=this.add({xtype:"panel",border:true,height:160,region:"south",margins:"0 5 5 5"});var a=b.add({xtype:"fieldset",title:_("Info"),border:false,autoHeight:true,labelWidth:1,style:"margin-top: 5px;"});this.pluginInfo=a.add({xtype:"panel",border:false,bodyCfg:{style:"margin-left: 10px"}});this.pluginInfo.on("render",this.onPluginInfoRender,this);this.list.on("click",this.onNodeClick,this);deluge.preferences.on("show",this.onPreferencesShow,this);deluge.events.on("PluginDisabledEvent",this.onPluginDisabled,this);deluge.events.on("PluginEnabledEvent",this.onPluginEnabled,this)},disablePlugin:function(a){deluge.client.core.disable_plugin(a)},enablePlugin:function(a){deluge.client.core.enable_plugin(a)},setInfo:function(b){if(!this.pluginInfo.rendered){return}var a=b||this.defaultValues;this.pluginInfo.body.dom.innerHTML=this.pluginTemplate.apply(a)},updatePlugins:function(){deluge.client.web.get_plugins({success:this.onGotPlugins,scope:this})},updatePluginsGrid:function(){var a=[];Ext.each(this.availablePlugins,function(b){if(this.enabledPlugins.indexOf(b)>-1){a.push([true,b])}else{a.push([false,b])}},this);this.list.getStore().loadData(a)},onNodeClick:function(b,a,f,g){var c=new Ext.Element(g.target);if(c.getAttribute("rel")!="chkbox"){return}var d=b.getStore().getAt(a);d.set("enabled",!d.get("enabled"));d.commit();if(d.get("enabled")){this.enablePlugin(d.get("plugin"))}else{this.disablePlugin(d.get("plugin"))}},onFindMorePlugins:function(){window.open("http://dev.deluge-torrent.org/wiki/Plugins")},onGotPlugins:function(a){this.enabledPlugins=a.enabled_plugins;this.availablePlugins=a.available_plugins;this.setInfo();this.updatePluginsGrid()},onGotPluginInfo:function(b){var a={author:b.Author,version:b.Version,email:b["Author-email"],homepage:b["Home-page"],details:b.Description};this.setInfo(a);delete b},onInstallPluginWindow:function(){if(!this.installWindow){this.installWindow=new Deluge.preferences.InstallPluginWindow();this.installWindow.on("pluginadded",this.onPluginInstall,this)}this.installWindow.show()},onPluginEnabled:function(c){var a=this.grid.getStore().find("plugin",c);if(a==-1){return}var b=this.grid.getStore().getAt(a);b.set("enabled",true);b.commit()},onPluginDisabled:function(c){var a=this.list.getStore().find("plugin",c);if(a==-1){return}var b=this.list.getStore().getAt(a);b.set("enabled",false);b.commit()},onPluginInstall:function(){this.updatePlugins()},onPluginSelect:function(a,b){var c=a.getRecords(b)[0];deluge.client.web.get_plugin_info(c.get("plugin"),{success:this.onGotPluginInfo,scope:this})},onPreferencesShow:function(){this.updatePlugins()},onPluginInfoRender:function(b,a){this.setInfo()}}); +/* + * Deluge.preferences.PreferencesWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");PreferencesRecord=Ext.data.Record.create([{name:"name",type:"string"}]);Deluge.preferences.PreferencesWindow=Ext.extend(Ext.Window,{currentPage:null,title:_("Preferences"),layout:"border",width:485,height:500,buttonAlign:"right",closeAction:"hide",closable:true,iconCls:"x-deluge-preferences",plain:true,resizable:false,pages:{},initComponent:function(){Deluge.preferences.PreferencesWindow.superclass.initComponent.call(this);this.list=new Ext.list.ListView({store:new Ext.data.Store(),columns:[{id:"name",renderer:fplain,dataIndex:"name"}],singleSelect:true,listeners:{selectionchange:{fn:this.onPageSelect,scope:this}},hideHeaders:true,autoExpandColumn:"name",deferredRender:false,autoScroll:true,collapsible:true});this.add({region:"west",title:_("Categories"),items:[this.list],width:120,margins:"5 0 5 5",cmargins:"5 0 5 5"});this.configPanel=this.add({type:"container",autoDestroy:false,region:"center",layout:"card",layoutConfig:{deferredRender:true},autoScroll:true,width:300,margins:"5 5 5 5",cmargins:"5 5 5 5"});this.addButton(_("Close"),this.onClose,this);this.addButton(_("Apply"),this.onApply,this);this.addButton(_("Ok"),this.onOk,this);this.optionsManager=new Deluge.OptionsManager();this.on("afterrender",this.onAfterRender,this);this.on("show",this.onShow,this);this.initPages()},initPages:function(){deluge.preferences=this;this.addPage(new Deluge.preferences.Downloads());this.addPage(new Deluge.preferences.Network());this.addPage(new Deluge.preferences.Encryption());this.addPage(new Deluge.preferences.Bandwidth());this.addPage(new Deluge.preferences.Interface());this.addPage(new Deluge.preferences.Other());this.addPage(new Deluge.preferences.Daemon());this.addPage(new Deluge.preferences.Queue());this.addPage(new Deluge.preferences.Proxy());this.addPage(new Deluge.preferences.Cache());this.addPage(new Deluge.preferences.Plugins())},onApply:function(b){var c=this.optionsManager.getDirty();if(!Ext.isObjectEmpty(c)){deluge.client.core.set_config(c,{success:this.onSetConfig,scope:this})}for(var a in this.pages){if(this.pages[a].onApply){this.pages[a].onApply()}}},getOptionsManager:function(){return this.optionsManager},addPage:function(c){var a=this.list.getStore();var b=c.title;a.add([new PreferencesRecord({name:b})]);c.bodyStyle="padding: 5px";c.preferences=this;this.pages[b]=this.configPanel.add(c);this.pages[b].index=-1;return this.pages[b]},removePage:function(c){var b=c.title;var a=this.list.getStore();a.removeAt(a.find("name",b));this.configPanel.remove(c);delete this.pages[c.title]},selectPage:function(a){if(this.pages[a].index<0){this.pages[a].index=this.configPanel.items.indexOf(this.pages[a])}this.list.select(this.pages[a].index)},doSelectPage:function(a){if(this.pages[a].index<0){this.pages[a].index=this.configPanel.items.indexOf(this.pages[a])}this.configPanel.getLayout().setActiveItem(this.pages[a].index);this.currentPage=a},onGotConfig:function(a){this.getOptionsManager().set(a)},onPageSelect:function(c,a){var b=c.getRecord(a[0]);this.doSelectPage(b.get("name"))},onSetConfig:function(){this.getOptionsManager().commit()},onAfterRender:function(){if(!this.list.getSelectionCount()){this.list.select(0)}this.configPanel.getLayout().setActiveItem(0)},onShow:function(){if(!deluge.client.core){return}deluge.client.core.get_config({success:this.onGotConfig,scope:this})},onClose:function(){this.hide()},onOk:function(){deluge.client.core.set_config(this.optionsManager.getDirty());this.hide()}}); +/* + * Deluge.preferences.ProxyField.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge.preferences");Deluge.preferences.ProxyField=Ext.extend(Ext.form.FieldSet,{border:false,autoHeight:true,labelWidth:70,initComponent:function(){Deluge.preferences.ProxyField.superclass.initComponent.call(this);this.proxyType=this.add({xtype:"combo",fieldLabel:_("Type"),name:"proxytype",mode:"local",width:150,store:new Ext.data.ArrayStore({fields:["id","text"],data:[[0,_("None")],[1,_("Socksv4")],[2,_("Socksv5")],[3,_("Socksv5 with Auth")],[4,_("HTTP")],[5,_("HTTP with Auth")]]}),editable:false,triggerAction:"all",valueField:"id",displayField:"text"});this.hostname=this.add({xtype:"textfield",name:"hostname",fieldLabel:_("Host"),width:220});this.port=this.add({xtype:"spinnerfield",name:"port",fieldLabel:_("Port"),width:80,decimalPrecision:0,minValue:-1,maxValue:99999});this.username=this.add({xtype:"textfield",name:"username",fieldLabel:_("Username"),width:220});this.password=this.add({xtype:"textfield",name:"password",fieldLabel:_("Password"),inputType:"password",width:220});this.proxyType.on("change",this.onFieldChange,this);this.proxyType.on("select",this.onTypeSelect,this);this.setting=false},getName:function(){return this.initialConfig.name},getValue:function(){return{type:this.proxyType.getValue(),hostname:this.hostname.getValue(),port:Number(this.port.getValue()),username:this.username.getValue(),password:this.password.getValue()}},setValue:function(c){this.setting=true;this.proxyType.setValue(c.type);var b=this.proxyType.getStore().find("id",c.type);var a=this.proxyType.getStore().getAt(b);this.hostname.setValue(c.hostname);this.port.setValue(c.port);this.username.setValue(c.username);this.password.setValue(c.password);this.onTypeSelect(this.type,a,b);this.setting=false},onFieldChange:function(e,d,c){if(this.setting){return}var b=this.getValue();var a=Ext.apply({},b);a[e.getName()]=c;this.fireEvent("change",this,b,a)},onTypeSelect:function(d,a,b){var c=a.get("id");if(c>0){this.hostname.show();this.port.show()}else{this.hostname.hide();this.port.hide()}if(c==3||c==5){this.username.show();this.password.show()}else{this.username.hide();this.password.hide()}}}); +/* + * Deluge.preferences.ProxyPage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");Deluge.preferences.Proxy=Ext.extend(Ext.form.FormPanel,{constructor:function(a){a=Ext.apply({border:false,title:_("Proxy"),layout:"form"},a);Deluge.preferences.Proxy.superclass.constructor.call(this,a)},initComponent:function(){Deluge.preferences.Proxy.superclass.initComponent.call(this);this.peer=this.add(new Deluge.preferences.ProxyField({title:_("Peer"),name:"peer"}));this.peer.on("change",this.onProxyChange,this);this.web_seed=this.add(new Deluge.preferences.ProxyField({title:_("Web Seed"),name:"web_seed"}));this.web_seed.on("change",this.onProxyChange,this);this.tracker=this.add(new Deluge.preferences.ProxyField({title:_("Tracker"),name:"tracker"}));this.tracker.on("change",this.onProxyChange,this);this.dht=this.add(new Deluge.preferences.ProxyField({title:_("DHT"),name:"dht"}));this.dht.on("change",this.onProxyChange,this);deluge.preferences.getOptionsManager().bind("proxies",this)},getValue:function(){return{dht:this.dht.getValue(),peer:this.peer.getValue(),tracker:this.tracker.getValue(),web_seed:this.web_seed.getValue()}},setValue:function(b){for(var a in b){this[a].setValue(b[a])}},onProxyChange:function(e,d,c){var b=this.getValue();var a=Ext.apply({},b);a[e.getName()]=c;this.fireEvent("change",this,b,a)}}); +/* + * Deluge.preferences.QueuePage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge.preferences");Deluge.preferences.Queue=Ext.extend(Ext.form.FormPanel,{border:false,title:_("Queue"),layout:"form",initComponent:function(){Deluge.preferences.Queue.superclass.initComponent.call(this);var b=deluge.preferences.getOptionsManager();var a=this.add({xtype:"fieldset",border:false,title:_("General"),style:"padding-top: 5px;",autoHeight:true,labelWidth:1,defaultType:"checkbox"});b.bind("queue_new_to_top",a.add({fieldLabel:"",labelSeparator:"",height:22,boxLabel:_("Queue new torrents to top"),name:"queue_new_to_top"}));a=this.add({xtype:"fieldset",border:false,title:_("Active Torrents"),autoHeight:true,labelWidth:150,defaultType:"spinnerfield",style:"margin-bottom: 0px; padding-bottom: 0px;"});b.bind("max_active_limit",a.add({fieldLabel:_("Total Active"),name:"max_active_limit",value:8,width:80,decimalPrecision:0,minValue:-1,maxValue:99999}));b.bind("max_active_downloading",a.add({fieldLabel:_("Total Active Downloading"),name:"max_active_downloading",value:3,width:80,decimalPrecision:0,minValue:-1,maxValue:99999}));b.bind("max_active_seeding",a.add({fieldLabel:_("Total Active Seeding"),name:"max_active_seeding",value:5,width:80,decimalPrecision:0,minValue:-1,maxValue:99999}));b.bind("dont_count_slow_torrents",a.add({xtype:"checkbox",name:"dont_count_slow_torrents",height:40,hideLabel:true,boxLabel:_("Do not count slow torrents")}));a=this.add({xtype:"fieldset",border:false,title:_("Seeding"),autoHeight:true,labelWidth:150,defaultType:"spinnerfield",style:"margin-bottom: 0px; padding-bottom: 0px; margin-top: 0; padding-top: 0;"});b.bind("share_ratio_limit",a.add({fieldLabel:_("Share Ratio Limit"),name:"share_ratio_limit",value:8,width:80,incrementValue:0.1,minValue:-1,maxValue:99999,alternateIncrementValue:1,decimalPrecision:2}));b.bind("seed_time_ratio_limit",a.add({fieldLabel:_("Share Time Ratio"),name:"seed_time_ratio_limit",value:3,width:80,incrementValue:0.1,minValue:-1,maxValue:99999,alternateIncrementValue:1,decimalPrecision:2}));b.bind("seed_time_limit",a.add({fieldLabel:_("Seed Time (m)"),name:"seed_time_limit",value:5,width:80,decimalPrecision:0,minValue:-1,maxValue:99999}));a=this.add({xtype:"fieldset",border:false,autoHeight:true,layout:"table",layoutConfig:{columns:2},labelWidth:0,defaultType:"checkbox",defaults:{fieldLabel:"",labelSeparator:""}});this.stopAtRatio=a.add({name:"stop_seed_at_ratio",boxLabel:_("Stop seeding when share ratio reaches:")});this.stopAtRatio.on("check",this.onStopRatioCheck,this);b.bind("stop_seed_at_ratio",this.stopAtRatio);this.stopRatio=a.add({xtype:"spinnerfield",name:"stop_seed_ratio",ctCls:"x-deluge-indent-checkbox",disabled:true,value:"2.0",width:60,incrementValue:0.1,minValue:-1,maxValue:99999,alternateIncrementValue:1,decimalPrecision:2});b.bind("stop_seed_ratio",this.stopRatio);this.removeAtRatio=a.add({name:"remove_seed_at_ratio",ctCls:"x-deluge-indent-checkbox",boxLabel:_("Remove torrent when share ratio is reached"),disabled:true,colspan:2});b.bind("remove_seed_at_ratio",this.removeAtRatio)},onStopRatioCheck:function(b,a){this.stopRatio.setDisabled(!a);this.removeAtRatio.setDisabled(!a)}}); +/* + * Deluge.StatusbarMenu.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge");Deluge.StatusbarMenu=Ext.extend(Ext.menu.Menu,{initComponent:function(){Deluge.StatusbarMenu.superclass.initComponent.call(this);this.otherWin=new Deluge.OtherLimitWindow(this.initialConfig.otherWin||{});this.items.each(function(a){if(a.getXType()!="menucheckitem"){return}if(a.value=="other"){a.on("click",this.onOtherClicked,this)}else{a.on("checkchange",this.onLimitChanged,this)}},this)},setValue:function(b){var c=false;this.value=b=(b==0)?-1:b;var a=null;this.items.each(function(d){if(d.setChecked){d.suspendEvents();if(d.value==b){d.setChecked(true);c=true}else{d.setChecked(false)}d.resumeEvents()}if(d.value=="other"){a=d}});if(c){return}a.suspendEvents();a.setChecked(true);a.resumeEvents()},onLimitChanged:function(c,b){if(!b||c.value=="other"){return}var a={};a[c.group]=c.value;deluge.client.core.set_config(a,{success:function(){deluge.ui.update()}})},onOtherClicked:function(a,b){this.otherWin.group=a.group;this.otherWin.setValue(this.value);this.otherWin.show()}}); +/* + * Deluge.OptionsManager.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge");Deluge.OptionsManager=Ext.extend(Ext.util.Observable,{constructor:function(a){a=a||{};this.binds={};this.changed={};this.options=(a&&a.options)||{};this.focused=null;this.addEvents({add:true,changed:true,reset:true});this.on("changed",this.onChange,this);Deluge.OptionsManager.superclass.constructor.call(this)},addOptions:function(a){this.options=Ext.applyIf(this.options,a)},bind:function(a,b){this.binds[a]=this.binds[a]||[];this.binds[a].push(b);b._doption=a;b.on("focus",this.onFieldFocus,this);b.on("blur",this.onFieldBlur,this);b.on("change",this.onFieldChange,this);b.on("check",this.onFieldChange,this);b.on("spin",this.onFieldChange,this);return b},commit:function(){this.options=Ext.apply(this.options,this.changed);this.reset()},convertValueType:function(a,b){if(Ext.type(a)!=Ext.type(b)){switch(Ext.type(a)){case"string":b=String(b);break;case"number":b=Number(b);break;case"boolean":if(Ext.type(b)=="string"){b=b.toLowerCase();b=(b=="true"||b=="1"||b=="on")?true:false}else{b=Boolean(b)}break}}return b},get:function(){if(arguments.length==1){var b=arguments[0];return(this.isDirty(b))?this.changed[b]:this.options[b]}else{var a={};Ext.each(arguments,function(c){if(!this.has(c)){return}a[c]=(this.isDirty(c))?this.changed[c]:this.options[c]},this);return a}},getDefault:function(a){return this.options[a]},getDirty:function(){return this.changed},isDirty:function(a){return !Ext.isEmpty(this.changed[a])},has:function(a){return(this.options[a])},reset:function(){this.changed={}},set:function(b,c){if(b===undefined){return}else{if(typeof b=="object"){var a=b;this.options=Ext.apply(this.options,a);for(var b in a){this.onChange(b,a[b])}}else{this.options[b]=c;this.onChange(b,c)}}},update:function(d,e){if(d===undefined){return}else{if(e===undefined){for(var c in d){this.update(c,d[c])}}else{var a=this.getDefault(d);e=this.convertValueType(a,e);var b=this.get(d);if(b==e){return}if(a==e){if(this.isDirty(d)){delete this.changed[d]}this.fireEvent("changed",d,e,b);return}this.changed[d]=e;this.fireEvent("changed",d,e,b)}}},onFieldBlur:function(b,a){if(this.focused==b){this.focused=null}},onFieldChange:function(b,a){if(b.field){b=b.field}this.update(b._doption,b.getValue())},onFieldFocus:function(b,a){this.focused=b},onChange:function(b,c,a){if(Ext.isEmpty(this.binds[b])){return}Ext.each(this.binds[b],function(d){if(d==this.focused){return}d.setValue(c)},this)}}); +/* + * Deluge.AddConnectionWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge");Deluge.AddConnectionWindow=Ext.extend(Ext.Window,{title:_("Add Connection"),iconCls:"x-deluge-add-window-icon",layout:"fit",width:300,height:195,bodyStyle:"padding: 10px 5px;",closeAction:"hide",initComponent:function(){Deluge.AddConnectionWindow.superclass.initComponent.call(this);this.addEvents("hostadded");this.addButton(_("Close"),this.hide,this);this.addButton(_("Add"),this.onAddClick,this);this.on("hide",this.onHide,this);this.form=this.add({xtype:"form",defaultType:"textfield",baseCls:"x-plain",labelWidth:60,items:[{fieldLabel:_("Host"),name:"host",anchor:"75%",value:""},{xtype:"spinnerfield",fieldLabel:_("Port"),name:"port",strategy:{xtype:"number",decimalPrecision:0,minValue:-1,maxValue:65535},value:"58846",anchor:"40%"},{fieldLabel:_("Username"),name:"username",anchor:"75%",value:""},{fieldLabel:_("Password"),anchor:"75%",name:"password",inputType:"password",value:""}]})},onAddClick:function(){var a=this.form.getForm().getValues();deluge.client.web.add_host(a.host,a.port,a.username,a.password,{success:function(b){if(!b[0]){Ext.MessageBox.show({title:_("Error"),msg:"Unable to add host: "+b[1],buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"})}else{this.fireEvent("hostadded")}this.hide()},scope:this})},onHide:function(){this.form.getForm().reset()}}); +/* + * Deluge.AddTrackerWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge");Deluge.AddTrackerWindow=Ext.extend(Ext.Window,{title:_("Add Tracker"),layout:"fit",width:375,height:150,plain:true,closable:true,resizable:false,bodyStyle:"padding: 5px",buttonAlign:"right",closeAction:"hide",iconCls:"x-deluge-edit-trackers",initComponent:function(){Deluge.AddTrackerWindow.superclass.initComponent.call(this);this.addButton(_("Cancel"),this.onCancelClick,this);this.addButton(_("Add"),this.onAddClick,this);this.addEvents("add");this.form=this.add({xtype:"form",defaultType:"textarea",baseCls:"x-plain",labelWidth:55,items:[{fieldLabel:_("Trackers"),name:"trackers",anchor:"100%"}]})},onAddClick:function(){var b=this.form.getForm().findField("trackers").getValue();b=b.split("\n");var a=[];Ext.each(b,function(c){if(Ext.form.VTypes.url(c)){a.push(c)}},this);this.fireEvent("add",a);this.hide();this.form.getForm().findField("trackers").setValue("")},onCancelClick:function(){this.form.getForm().findField("trackers").setValue("");this.hide()}}); +/* + * Deluge.Client.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Ext.ux.util");Ext.ux.util.RpcClient=Ext.extend(Ext.util.Observable,{_components:[],_methods:[],_requests:{},_url:null,_optionKeys:["scope","success","failure"],constructor:function(a){Ext.ux.util.RpcClient.superclass.constructor.call(this,a);this._url=a.url||null;this._id=0;this.addEvents("connected","error");this.reloadMethods()},reloadMethods:function(){Ext.each(this._components,function(a){delete this[a]},this);this._execute("system.listMethods",{success:this._setMethods,scope:this})},_execute:function(c,a){a=a||{};a.params=a.params||[];a.id=this._id;var b=Ext.encode({method:c,params:a.params,id:a.id});this._id++;return Ext.Ajax.request({url:this._url,method:"POST",success:this._onSuccess,failure:this._onFailure,scope:this,jsonData:b,options:a})},_onFailure:function(b,a){var c=a.options;errorObj={id:c.id,result:null,error:{msg:"HTTP: "+b.status+" "+b.statusText,code:255}};this.fireEvent("error",errorObj,b,a);if(Ext.type(c.failure)!="function"){return}if(c.scope){c.failure.call(c.scope,errorObj,b,a)}else{c.failure(errorObj,b,a)}},_onSuccess:function(c,a){var b=Ext.decode(c.responseText);var d=a.options;if(b.error){this.fireEvent("error",b,c,a);if(Ext.type(d.failure)!="function"){return}if(d.scope){d.failure.call(d.scope,b,c,a)}else{d.failure(b,c,a)}}else{if(Ext.type(d.success)!="function"){return}if(d.scope){d.success.call(d.scope,b.result,b,c,a)}else{d.success(b.result,b,c,a)}}},_parseArgs:function(c){var e=[];Ext.each(c,function(f){e.push(f)});var b=e[e.length-1];if(Ext.type(b)=="object"){var d=Ext.keys(b),a=false;Ext.each(this._optionKeys,function(f){if(d.indexOf(f)>-1){a=true}});if(a){e.remove(b)}else{b={}}}else{b={}}b.params=e;return b},_setMethods:function(b){var d={},a=this;Ext.each(b,function(h){var g=h.split(".");var e=d[g[0]]||{};var f=function(){var i=a._parseArgs(arguments);return a._execute(h,i)};e[g[1]]=f;d[g[0]]=e});for(var c in d){a[c]=d[c]}this._components=Ext.keys(d);this.fireEvent("connected",this)}}); +/* + * Deluge.ConnectionManager.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Deluge.ConnectionManager=Ext.extend(Ext.Window,{layout:"fit",width:300,height:220,bodyStyle:"padding: 10px 5px;",buttonAlign:"right",closeAction:"hide",closable:true,plain:true,title:_("Connection Manager"),iconCls:"x-deluge-connect-window-icon",initComponent:function(){Deluge.ConnectionManager.superclass.initComponent.call(this);this.on("hide",this.onHide,this);this.on("show",this.onShow,this);deluge.events.on("login",this.onLogin,this);deluge.events.on("logout",this.onLogout,this);this.addButton(_("Close"),this.onClose,this);this.addButton(_("Connect"),this.onConnect,this);this.list=new Ext.list.ListView({store:new Ext.data.ArrayStore({fields:[{name:"status",mapping:3},{name:"host",mapping:1},{name:"port",mapping:2},{name:"version",mapping:4}],id:0}),columns:[{header:_("Status"),width:0.24,sortable:true,dataIndex:"status"},{id:"host",header:_("Host"),width:0.51,sortable:true,tpl:"{host}:{port}",dataIndex:"host"},{header:_("Version"),width:0.25,sortable:true,tpl:'{version}',dataIndex:"version"}],singleSelect:true,listeners:{selectionchange:{fn:this.onSelectionChanged,scope:this}}});this.panel=this.add({autoScroll:true,items:[this.list],bbar:new Ext.Toolbar({buttons:[{id:"cm-add",cls:"x-btn-text-icon",text:_("Add"),iconCls:"icon-add",handler:this.onAddClick,scope:this},{id:"cm-remove",cls:"x-btn-text-icon",text:_("Remove"),iconCls:"icon-remove",handler:this.onRemoveClick,disabled:true,scope:this},"->",{id:"cm-stop",cls:"x-btn-text-icon",text:_("Stop Daemon"),iconCls:"icon-error",handler:this.onStopClick,disabled:true,scope:this}]})});this.update=this.update.createDelegate(this)},checkConnected:function(){deluge.client.web.connected({success:function(a){if(a){deluge.events.fire("connect")}else{this.show()}},scope:this})},disconnect:function(a){deluge.events.fire("disconnect");if(a){if(this.isVisible()){return}this.show()}},loadHosts:function(){deluge.client.web.get_hosts({success:this.onGetHosts,scope:this})},update:function(){this.list.getStore().each(function(a){deluge.client.web.get_host_status(a.id,{success:this.onGetHostStatus,scope:this})},this)},updateButtons:function(b){var c=this.buttons[1],a=b.get("status");if(a==_("Connected")){c.enable();c.setText(_("Disconnect"))}else{if(a==_("Offline")){c.disable()}else{c.enable();c.setText(_("Connect"))}}if(a==_("Offline")){if(b.get("host")=="127.0.0.1"||b.get("host")=="localhost"){this.stopHostButton.enable();this.stopHostButton.setText(_("Start Daemon"))}else{this.stopHostButton.disable()}}else{this.stopHostButton.enable();this.stopHostButton.setText(_("Stop Daemon"))}},onAddClick:function(a,b){if(!this.addWindow){this.addWindow=new Deluge.AddConnectionWindow();this.addWindow.on("hostadded",this.onHostAdded,this)}this.addWindow.show()},onHostAdded:function(){this.loadHosts()},onClose:function(a){this.hide()},onConnect:function(b){var a=this.list.getSelectedRecords()[0];if(!a){return}if(a.get("status")==_("Connected")){deluge.client.web.disconnect({success:function(d){this.update(this);deluge.events.fire("disconnect")},scope:this})}else{var c=a.id;deluge.client.web.connect(c,{success:function(d){deluge.client.reloadMethods();deluge.client.on("connected",function(f){deluge.events.fire("connect")},this,{single:true})}});this.hide()}},onGetHosts:function(a){this.list.getStore().loadData(a);Ext.each(a,function(b){deluge.client.web.get_host_status(b[0],{success:this.onGetHostStatus,scope:this})},this)},onGetHostStatus:function(b){var a=this.list.getStore().getById(b[0]);a.set("status",b[3]);a.set("version",b[4]);a.commit();if(this.list.getSelectedRecords()[0]==a){this.updateButtons(a)}},onHide:function(){if(this.running){window.clearInterval(this.running)}},onLogin:function(){if(deluge.config.first_login){Ext.MessageBox.confirm("Change password","As this is your first login, we recommend that you change your password. Would you like to do this now?",function(a){this.checkConnected();if(a=="yes"){deluge.preferences.show();deluge.preferences.selectPage("Interface")}deluge.client.web.set_config({first_login:false})},this)}else{this.checkConnected()}},onLogout:function(){this.disconnect();if(!this.hidden&&this.rendered){this.hide()}},onRemoveClick:function(b){var a=this.list.getSelectedRecords()[0];if(!a){return}deluge.client.web.remove_host(a.id,{success:function(c){if(!c){Ext.MessageBox.show({title:_("Error"),msg:c[1],buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"})}else{this.list.getStore().remove(a)}},scope:this})},onSelectionChanged:function(b,a){if(a[0]){this.removeHostButton.enable();this.stopHostButton.enable();this.stopHostButton.setText(_("Stop Daemon"));this.updateButtons(this.list.getRecord(a[0]))}else{this.removeHostButton.disable();this.stopHostButton.disable()}},onShow:function(){if(!this.addHostButton){var a=this.panel.getBottomToolbar();this.addHostButton=a.items.get("cm-add");this.removeHostButton=a.items.get("cm-remove");this.stopHostButton=a.items.get("cm-stop")}this.loadHosts();this.running=window.setInterval(this.update,2000,this)},onStopClick:function(b,c){var a=this.list.getSelectedRecords()[0];if(!a){return}if(a.get("status")=="Offline"){deluge.client.web.start_daemon(a.get("port"))}else{deluge.client.web.stop_daemon(a.id,{success:function(d){if(!d[0]){Ext.MessageBox.show({title:_("Error"),msg:d[1],buttons:Ext.MessageBox.OK,modal:false,icon:Ext.MessageBox.ERROR,iconCls:"x-deluge-icon-error"})}}})}}}); +/* + * Deluge.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.state.Manager.setProvider(new Ext.state.CookieProvider());Ext.apply(Ext,{escapeHTML:function(a){a=String(a).replace("<","<").replace(">",">");return a.replace("&","&")},isObjectEmpty:function(b){for(var a in b){return false}return true},isObjectsEqual:function(d,c){var b=true;if(!d||!c){return false}for(var a in d){if(d[a]!=c[a]){b=false}}return b},keys:function(c){var b=[];for(var a in c){if(c.hasOwnProperty(a)){b.push(a)}}return b},values:function(c){var a=[];for(var b in c){if(c.hasOwnProperty(b)){a.push(c[b])}}return a},splat:function(b){var a=Ext.type(b);return(a)?((a!="array")?[b]:b):[]}});Ext.getKeys=Ext.keys;Ext.BLANK_IMAGE_URL=deluge.config.base+"images/s.gif";Ext.USE_NATIVE_JSON=true;Ext.apply(Deluge,{pluginStore:{},progressTpl:'
{0}
{0}
',progressBar:function(c,e,g,a){a=Ext.value(a,10);var b=((e/100)*c).toFixed(0);var d=b-1;var f=((b-a)>0?b-a:0);return String.format(Deluge.progressTpl,g,e,d,f)},createPlugin:function(a){return new Deluge.pluginStore[a]()},hasPlugin:function(a){return(Deluge.pluginStore[a])?true:false},registerPlugin:function(a,b){Deluge.pluginStore[a]=b}});deluge.plugins={};FILE_PRIORITY={9:"Mixed",0:"Do Not Download",1:"Normal Priority",2:"High Priority",5:"Highest Priority",Mixed:9,"Do Not Download":0,"Normal Priority":1,"High Priority":2,"Highest Priority":5};FILE_PRIORITY_CSS={9:"x-mixed-download",0:"x-no-download",1:"x-normal-download",2:"x-high-download",5:"x-highest-download"} +/* + * Deluge.EditTrackerWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +;Ext.ns("Deluge");Deluge.EditTrackerWindow=Ext.extend(Ext.Window,{title:_("Edit Tracker"),layout:"fit",width:375,height:110,plain:true,closable:true,resizable:false,bodyStyle:"padding: 5px",buttonAlign:"right",closeAction:"hide",iconCls:"x-deluge-edit-trackers",initComponent:function(){Deluge.EditTrackerWindow.superclass.initComponent.call(this);this.addButton(_("Cancel"),this.onCancelClick,this);this.addButton(_("Save"),this.onSaveClick,this);this.on("hide",this.onHide,this);this.form=this.add({xtype:"form",defaultType:"textfield",baseCls:"x-plain",labelWidth:55,items:[{fieldLabel:_("Tracker"),name:"tracker",anchor:"100%"}]})},show:function(a){Deluge.EditTrackerWindow.superclass.show.call(this);this.record=a;this.form.getForm().findField("tracker").setValue(a.data.url)},onCancelClick:function(){this.hide()},onHide:function(){this.form.getForm().findField("tracker").setValue("")},onSaveClick:function(){var a=this.form.getForm().findField("tracker").getValue();this.record.set("url",a);this.record.commit();this.hide()}}); +/* + * Deluge.EditTrackers.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge");Deluge.EditTrackersWindow=Ext.extend(Ext.Window,{title:_("Edit Trackers"),layout:"fit",width:350,height:220,plain:true,closable:true,resizable:false,bodyStyle:"padding: 5px",buttonAlign:"right",closeAction:"hide",iconCls:"x-deluge-edit-trackers",initComponent:function(){Deluge.EditTrackersWindow.superclass.initComponent.call(this);this.addButton(_("Cancel"),this.onCancelClick,this);this.addButton(_("Ok"),this.onOkClick,this);this.addEvents("save");this.on("show",this.onShow,this);this.on("save",this.onSave,this);this.addWindow=new Deluge.AddTrackerWindow();this.addWindow.on("add",this.onAddTrackers,this);this.editWindow=new Deluge.EditTrackerWindow();this.list=new Ext.list.ListView({store:new Ext.data.JsonStore({root:"trackers",fields:["tier","url"]}),columns:[{header:_("Tier"),width:0.1,dataIndex:"tier"},{header:_("Tracker"),width:0.9,dataIndex:"url"}],columnSort:{sortClasses:["",""]},stripeRows:true,singleSelect:true,autoScroll:true,listeners:{dblclick:{fn:this.onListNodeDblClicked,scope:this},selectionchange:{fn:this.onSelect,scope:this}}});this.panel=this.add({margins:"0 0 0 0",items:[this.list],bbar:new Ext.Toolbar({items:[{text:_("Up"),iconCls:"icon-up",handler:this.onUpClick,scope:this},{text:_("Down"),iconCls:"icon-down",handler:this.onDownClick,scope:this},"->",{text:_("Add"),iconCls:"icon-add",handler:this.onAddClick,scope:this},{text:_("Edit"),iconCls:"icon-edit-trackers",handler:this.onEditClick,scope:this},{text:_("Remove"),iconCls:"icon-remove",handler:this.onRemoveClick,scope:this}]})})},onAddClick:function(){this.addWindow.show()},onAddTrackers:function(b){var a=this.list.getStore();Ext.each(b,function(d){var e=false,c=-1;a.each(function(f){if(f.get("tier")>c){c=f.get("tier")}if(d==f.get("tracker")){e=true;return false}},this);if(e){return}a.add(new a.recordType({tier:c+1,url:d}))},this)},onCancelClick:function(){this.hide()},onEditClick:function(){this.editWindow.show(this.list.getSelectedRecords()[0])},onHide:function(){this.list.getStore().removeAll()},onListNodeDblClicked:function(c,a,b,d){this.editWindow.show(this.list.getRecord(b))},onOkClick:function(){var a=[];this.list.getStore().each(function(b){a.push({tier:b.get("tier"),url:b.get("url")})},this);deluge.client.core.set_torrent_trackers(this.torrentId,a,{failure:this.onSaveFail,scope:this});this.hide()},onRemoveClick:function(){this.list.getStore().remove(this.list.getSelectedRecords()[0])},onRequestComplete:function(a){this.list.getStore().loadData(a);this.list.getStore().sort("tier","ASC")},onSaveFail:function(){},onSelect:function(a){if(a.getSelectionCount()){this.panel.getBottomToolbar().items.get(4).enable()}},onShow:function(){this.panel.getBottomToolbar().items.get(4).disable();var a=deluge.torrents.getSelected();this.torrentId=a.id;deluge.client.core.get_torrent_status(a.id,["trackers"],{success:this.onRequestComplete,scope:this})},onDownClick:function(){var a=this.list.getSelectedRecords()[0];a.set("tier",a.get("tier")+1);a.commit();a.store.sort("tier","ASC")},onUpClick:function(){var a=this.list.getSelectedRecords()[0];if(a.get("tier")==0){return}a.set("tier",a.get("tier")-1);a.commit();a.store.sort("tier","ASC")}}); +/* + * Deluge.EventsManager.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Deluge.EventsManager=Ext.extend(Ext.util.Observable,{constructor:function(){this.toRegister=[];this.on("login",this.onLogin,this);Deluge.EventsManager.superclass.constructor.call(this)},addListener:function(a,c,b,d){this.addEvents(a);if(/[A-Z]/.test(a.substring(0,1))){if(!deluge.client){this.toRegister.push(a)}else{deluge.client.web.register_event_listener(a)}}Deluge.EventsManager.superclass.addListener.call(this,a,c,b,d)},getEvents:function(){deluge.client.web.get_events({success:this.onGetEventsSuccess,failure:this.onGetEventsFailure,scope:this})},start:function(){Ext.each(this.toRegister,function(a){deluge.client.web.register_event_listener(a)});this.running=true;this.errorCount=0;this.getEvents()},stop:function(){this.running=false},onLogin:function(){this.start()},onGetEventsSuccess:function(a){if(!a){return}Ext.each(a,function(d){var c=d[0],b=d[1];b.splice(0,0,c);this.fireEvent.apply(this,b)},this);if(this.running){this.getEvents()}},onGetEventsFailure:function(a,b){if(!this.running){return}if(!b.isTimeout&&this.errorCount++>=3){this.stop();return}this.getEvents()}});Deluge.EventsManager.prototype.on=Deluge.EventsManager.prototype.addListener;Deluge.EventsManager.prototype.fire=Deluge.EventsManager.prototype.fireEvent;deluge.events=new Deluge.EventsManager(); +/* + * Deluge.FileBrowser.js + * + * Copyright (c) Damien Churchill 2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge");Deluge.FileBrowser=Ext.extend(Ext.Window,{title:_("File Browser"),width:500,height:400,initComponent:function(){Deluge.FileBrowser.superclass.initComponent.call(this);this.add({xtype:"toolbar",items:[{text:_("Back"),iconCls:"icon-back"},{text:_("Forward"),iconCls:"icon-forward"},{text:_("Up"),iconCls:"icon-up"},{text:_("Home"),iconCls:"icon-home"}]})}}); +/* + * Deluge.FilterPanel.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge");Deluge.FilterPanel=Ext.extend(Ext.Panel,{border:false,show_zero:null,initComponent:function(){Deluge.FilterPanel.superclass.initComponent.call(this);this.filterType=this.initialConfig.filter;var c=this.filterType.replace("_"," "),b=c.split(" "),c="";Ext.each(b,function(d){fl=d.substring(0,1).toUpperCase();c+=fl+d.substring(1)+" "});this.setTitle(_(c));if(Deluge.FilterPanel.templates[this.filterType]){var a=Deluge.FilterPanel.templates[this.filterType]}else{var a='
{filter} ({count})
'}this.list=this.add({xtype:"listview",singleSelect:true,hideHeaders:true,reserveScrollOffset:true,store:new Ext.data.ArrayStore({idIndex:0,fields:["filter","count"]}),columns:[{id:"filter",sortable:false,tpl:a,dataIndex:"filter"}]});this.relayEvents(this.list,["selectionchange"])},getState:function(){if(!this.list.getSelectionCount()){return}var a=this.list.getSelectedRecords()[0];if(a.id=="All"){return}return a.id},getStates:function(){return this.states},getStore:function(){return this.list.getStore()},updateStates:function(b){this.states={};Ext.each(b,function(f){this.states[f[0]]=f[1]},this);var e=(this.show_zero==null)?deluge.config.sidebar_show_zero:this.show_zero;if(!e){var c=[];Ext.each(b,function(f){if(f[1]>0||f[0]==_("All")){c.push(f)}});b=c}var a=this.getStore();var d={};Ext.each(b,function(h,g){var f=a.getById(h[0]);if(!f){f=new a.recordType({filter:h[0],count:h[1]});f.id=h[0];a.insert(g,f)}f.beginEdit();f.set("filter",h[0]);f.set("count",h[1]);f.endEdit();d[h[0]]=true},this);a.each(function(f){if(d[f.id]){return}var g=this.list.getSelectedRecords()[0];a.remove(f);if(g.id==f.id){this.list.select(0)}},this);a.commitChanges();if(!this.list.getSelectionCount()){this.list.select(0)}}});Deluge.FilterPanel.templates={tracker_host:'
{filter} ({count})
'} +/* + * Deluge.Formatters.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +;Deluge.Formatters={date:function(c){function b(d,e){var f=d+"";while(f.length0){return b+"m "+d+"s"}else{return b+"m"}}else{c=c/60}if(c<24){var a=Math.floor(c);var b=Math.round(60*(c-a));if(b>0){return a+"h "+b+"m"}else{return a+"h"}}else{c=c/24}var e=Math.floor(c);var a=Math.round(24*(c-e));if(a>0){return e+"d "+a+"h"}else{return e+"d"}},plain:function(a){return a},cssClassEscape:function(a){return a.toLowerCase().replace(".","_")}};var fsize=Deluge.Formatters.size;var fspeed=Deluge.Formatters.speed;var ftime=Deluge.Formatters.timeRemaining;var fdate=Deluge.Formatters.date;var fplain=Deluge.Formatters.plain;Ext.util.Format.cssClassEscape=Deluge.Formatters.cssClassEscape; +/* + * Deluge.Keys.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Deluge.Keys={Grid:["queue","name","total_size","state","progress","num_seeds","total_seeds","num_peers","total_peers","download_payload_rate","upload_payload_rate","eta","ratio","distributed_copies","is_auto_managed","time_added","tracker_host","save_path"],Status:["total_done","total_payload_download","total_uploaded","total_payload_upload","next_announce","tracker_status","num_pieces","piece_length","is_auto_managed","active_time","seeding_time","seed_rank"],Files:["files","file_progress","file_priorities"],Peers:["peers"],Details:["name","save_path","total_size","num_files","tracker_status","tracker","comment"],Options:["max_download_speed","max_upload_speed","max_connections","max_upload_slots","is_auto_managed","stop_at_ratio","stop_ratio","remove_at_ratio","private","prioritize_first_last"]};Ext.each(Deluge.Keys.Grid,function(a){Deluge.Keys.Status.push(a)}); +/* + * Deluge.LoginWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Deluge.LoginWindow=Ext.extend(Ext.Window,{firstShow:true,bodyStyle:"padding: 10px 5px;",buttonAlign:"center",closable:false,closeAction:"hide",iconCls:"x-deluge-login-window-icon",layout:"fit",modal:true,plain:true,resizable:false,title:_("Login"),width:300,height:120,initComponent:function(){Deluge.LoginWindow.superclass.initComponent.call(this);this.on("show",this.onShow,this);this.addButton({text:_("Login"),handler:this.onLogin,scope:this});this.form=this.add({xtype:"form",baseCls:"x-plain",labelWidth:55,width:300,defaults:{width:200},defaultType:"textfield"});this.passwordField=this.form.add({xtype:"textfield",fieldLabel:_("Password"),id:"_password",name:"password",inputType:"password"});this.passwordField.on("specialkey",this.onSpecialKey,this)},logout:function(){deluge.events.fire("logout");deluge.client.auth.delete_session({success:function(a){this.show(true)},scope:this})},show:function(a){if(this.firstShow){deluge.client.on("error",this.onClientError,this);this.firstShow=false}if(a){return Deluge.LoginWindow.superclass.show.call(this)}deluge.client.auth.check_session({success:function(b){if(b){deluge.events.fire("login")}else{this.show(true)}},failure:function(b){this.show(true)},scope:this})},onSpecialKey:function(b,a){if(a.getKey()==13){this.onLogin()}},onLogin:function(){var a=this.passwordField;deluge.client.auth.login(a.getValue(),{success:function(b){if(b){deluge.events.fire("login");this.hide();a.setRawValue("")}else{Ext.MessageBox.show({title:_("Login Failed"),msg:_("You entered an incorrect password"),buttons:Ext.MessageBox.OK,modal:false,fn:function(){a.focus(true,10)},icon:Ext.MessageBox.WARNING,iconCls:"x-deluge-icon-warning"})}},scope:this})},onClientError:function(c,b,a){if(c.error.code==1){deluge.events.fire("logout");this.show(true)}},onShow:function(){this.passwordField.focus(true,true)}}); +/* + * Deluge.Menus.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +deluge.menus={onTorrentAction:function(b,d){var a=deluge.torrents.getSelectedIds();var c=b.initialConfig.torrentAction;switch(c){case"pause":case"resume":deluge.client.core[c+"_torrent"](a,{success:function(){deluge.ui.update()}});break;case"top":case"up":case"down":case"bottom":deluge.client.core["queue_"+c](a,{success:function(){deluge.ui.update()}});break;case"edit_trackers":deluge.editTrackers.show();break;case"update":deluge.client.core.force_reannounce(a,{success:function(){deluge.ui.update()}});break;case"remove":deluge.removeWindow.show(a);break;case"recheck":deluge.client.core.force_recheck(a,{success:function(){deluge.ui.update()}});break;case"move":deluge.moveStorage.show(a);break}}};deluge.menus.torrent=new Ext.menu.Menu({id:"torrentMenu",items:[{torrentAction:"pause",text:_("Pause"),iconCls:"icon-pause",handler:deluge.menus.onTorrentAction,scope:deluge.menus},{torrentAction:"resume",text:_("Resume"),iconCls:"icon-resume",handler:deluge.menus.onTorrentAction,scope:deluge.menus},"-",{text:_("Options"),iconCls:"icon-options",menu:new Ext.menu.Menu({items:[{text:_("D/L Speed Limit"),iconCls:"x-deluge-downloading",menu:new Ext.menu.Menu({items:[{text:_("5 KiB/s")},{text:_("10 KiB/s")},{text:_("30 KiB/s")},{text:_("80 KiB/s")},{text:_("300 KiB/s")},{text:_("Unlimited")}]})},{text:_("U/L Speed Limit"),iconCls:"x-deluge-seeding",menu:new Ext.menu.Menu({items:[{text:_("5 KiB/s")},{text:_("10 KiB/s")},{text:_("30 KiB/s")},{text:_("80 KiB/s")},{text:_("300 KiB/s")},{text:_("Unlimited")}]})},{text:_("Connection Limit"),iconCls:"x-deluge-connections",menu:new Ext.menu.Menu({items:[{text:_("50")},{text:_("100")},{text:_("200")},{text:_("300")},{text:_("500")},{text:_("Unlimited")}]})},{text:_("Upload Slot Limit"),iconCls:"icon-upload-slots",menu:new Ext.menu.Menu({items:[{text:_("0")},{text:_("1")},{text:_("2")},{text:_("3")},{text:_("5")},{text:_("Unlimited")}]})},{id:"auto_managed",text:_("Auto Managed"),checked:false}]})},"-",{text:_("Queue"),iconCls:"icon-queue",menu:new Ext.menu.Menu({items:[{torrentAction:"top",text:_("Top"),iconCls:"icon-top",handler:deluge.menus.onTorrentAction,scope:deluge.menus},{torrentAction:"up",text:_("Up"),iconCls:"icon-up",handler:deluge.menus.onTorrentAction,scope:deluge.menus},{torrentAction:"down",text:_("Down"),iconCls:"icon-down",handler:deluge.menus.onTorrentAction,scope:deluge.menus},{torrentAction:"bottom",text:_("Bottom"),iconCls:"icon-bottom",handler:deluge.menus.onTorrentAction,scope:deluge.menus}]})},"-",{torrentAction:"update",text:_("Update Tracker"),iconCls:"icon-update-tracker",handler:deluge.menus.onTorrentAction,scope:deluge.menus},{torrentAction:"edit_trackers",text:_("Edit Trackers"),iconCls:"icon-edit-trackers",handler:deluge.menus.onTorrentAction,scope:deluge.menus},"-",{torrentAction:"remove",text:_("Remove Torrent"),iconCls:"icon-remove",handler:deluge.menus.onTorrentAction,scope:deluge.menus},"-",{torrentAction:"recheck",text:_("Force Recheck"),iconCls:"icon-recheck",handler:deluge.menus.onTorrentAction,scope:deluge.menus},{torrentAction:"move",text:_("Move Storage"),iconCls:"icon-move",handler:deluge.menus.onTorrentAction,scope:deluge.menus}]});deluge.menus.filePriorities=new Ext.menu.Menu({id:"filePrioritiesMenu",items:[{id:"expandAll",text:_("Expand All"),iconCls:"icon-expand-all"},"-",{id:"no_download",text:_("Do Not Download"),iconCls:"icon-do-not-download",filePriority:0},{id:"normal",text:_("Normal Priority"),iconCls:"icon-normal",filePriority:1},{id:"high",text:_("High Priority"),iconCls:"icon-high",filePriority:2},{id:"highest",text:_("Highest Priority"),iconCls:"icon-highest",filePriority:5}]}); +/* + * Deluge.MoveStorage.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge");Deluge.MoveStorage=Ext.extend(Ext.Window,{constructor:function(a){a=Ext.apply({title:_("Move Storage"),width:375,height:110,layout:"fit",buttonAlign:"right",closeAction:"hide",closable:true,iconCls:"x-deluge-move-storage",plain:true,resizable:false},a);Deluge.MoveStorage.superclass.constructor.call(this,a)},initComponent:function(){Deluge.MoveStorage.superclass.initComponent.call(this);this.addButton(_("Cancel"),this.onCancel,this);this.addButton(_("Move"),this.onMove,this);this.form=this.add({xtype:"form",border:false,defaultType:"textfield",width:300,bodyStyle:"padding: 5px"});this.moveLocation=this.form.add({fieldLabel:_("Location"),name:"location",width:240})},hide:function(){Deluge.MoveStorage.superclass.hide.call(this);this.torrentIds=null},show:function(a){Deluge.MoveStorage.superclass.show.call(this);this.torrentIds=a},onCancel:function(){this.hide()},onMove:function(){var a=this.moveLocation.getValue();deluge.client.core.move_storage(this.torrentIds,a);this.hide()}});deluge.moveStorage=new Deluge.MoveStorage(); +/* + * Deluge.MultiOptionsManager.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Deluge.MultiOptionsManager=Ext.extend(Deluge.OptionsManager,{constructor:function(a){this.currentId=null;this.stored={};Deluge.MultiOptionsManager.superclass.constructor.call(this,a)},changeId:function(d,b){var c=this.currentId;this.currentId=d;if(!b){for(var a in this.options){if(!this.binds[a]){continue}Ext.each(this.binds[a],function(e){e.setValue(this.get(a))},this)}}return c},commit:function(){this.stored[this.currentId]=Ext.apply(this.stored[this.currentId],this.changed[this.currentId]);this.reset()},get:function(){if(arguments.length==1){var b=arguments[0];return(this.isDirty(b))?this.changed[this.currentId][b]:this.getDefault(b)}else{if(arguments.length==0){var a={};for(var b in this.options){a[b]=(this.isDirty(b))?this.changed[this.currentId][b]:this.getDefault(b)}return a}else{var a={};Ext.each(arguments,function(c){a[c]=(this.isDirty(c))?this.changed[this.currentId][c]:this.getDefault(c)},this);return a}}},getDefault:function(a){return(this.has(a))?this.stored[this.currentId][a]:this.options[a]},getDirty:function(){return(this.changed[this.currentId])?this.changed[this.currentId]:{}},isDirty:function(a){return(this.changed[this.currentId]&&!Ext.isEmpty(this.changed[this.currentId][a]))},has:function(a){return(this.stored[this.currentId]&&!Ext.isEmpty(this.stored[this.currentId][a]))},reset:function(){if(this.changed[this.currentId]){delete this.changed[this.currentId]}if(this.stored[this.currentId]){delete this.stored[this.currentId]}},resetAll:function(){this.changed={};this.stored={};this.changeId(null)},setDefault:function(c,d){if(c===undefined){return}else{if(d===undefined){for(var b in c){this.setDefault(b,c[b])}}else{var a=this.getDefault(c);d=this.convertValueType(a,d);if(a==d){return}if(!this.stored[this.currentId]){this.stored[this.currentId]={}}this.stored[this.currentId][c]=d;if(!this.isDirty(c)){this.fireEvent("changed",this.currentId,c,d,a)}}}},update:function(d,e){if(d===undefined){return}else{if(e===undefined){for(var c in d){this.update(c,d[c])}}else{if(!this.changed[this.currentId]){this.changed[this.currentId]={}}var a=this.getDefault(d);e=this.convertValueType(a,e);var b=this.get(d);if(b==e){return}if(a==e){if(this.isDirty(d)){delete this.changed[this.currentId][d]}this.fireEvent("changed",d,e,b);return}else{this.changed[this.currentId][d]=e;this.fireEvent("changed",d,e,b)}}}}}); +/* + * Deluge.OtherLimitWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge");Deluge.OtherLimitWindow=Ext.extend(Ext.Window,{layout:"fit",width:210,height:100,closeAction:"hide",initComponent:function(){Deluge.OtherLimitWindow.superclass.initComponent.call(this);this.form=this.add({xtype:"form",baseCls:"x-plain",bodyStyle:"padding: 5px",layout:"hbox",layoutConfig:{pack:"start"},items:[{xtype:"spinnerfield",name:"limit"}]});if(this.initialConfig.unit){this.form.add({border:false,baseCls:"x-plain",bodyStyle:"padding: 5px",html:this.initialConfig.unit})}else{this.setSize(180,100)}this.addButton(_("Cancel"),this.onCancelClick,this);this.addButton(_("Ok"),this.onOkClick,this);this.afterMethod("show",this.doFocusField,this)},setValue:function(a){this.form.getForm().setValues({limit:a})},onCancelClick:function(){this.form.getForm().reset();this.hide()},onOkClick:function(){var a={};a[this.group]=this.form.getForm().getValues().limit;deluge.client.core.set_config(a,{success:function(){deluge.ui.update()}});this.hide()},doFocusField:function(){this.form.getForm().findField("limit").focus(true,10)}}); +/* + * Deluge.Plugin.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Deluge");Deluge.Plugin=Ext.extend(Ext.util.Observable,{name:null,constructor:function(a){this.isDelugePlugin=true;this.addEvents({enabled:true,disabled:true});Deluge.Plugin.superclass.constructor.call(this,a)},disable:function(){this.fireEvent("disabled",this);if(this.onDisable){this.onDisable()}},enable:function(){this.fireEvent("enable",this);if(this.onEnable){this.onEnable()}},registerTorrentStatus:function(b,f,a){a=a||{};var e=a.colCfg||{},d=a.storeCfg||{};d=Ext.apply(d,{name:b});deluge.torrents.meta.fields.push(d);deluge.torrents.getStore().reader.onMetaChange(deluge.torrents.meta);e=Ext.apply(e,{header:f,dataIndex:b});var c=deluge.torrents.columns.slice(0);c.push(e);deluge.torrents.colModel.setConfig(c);deluge.torrents.columns=c;Deluge.Keys.Grid.push(b);deluge.torrents.getView().refresh(true)},deregisterTorrentStatus:function(b){var a=[];Ext.each(deluge.torrents.meta.fields,function(e){if(e.name!=b){a.push(e)}});deluge.torrents.meta.fields=a;deluge.torrents.getStore().reader.onMetaChange(deluge.torrents.meta);var d=[];Ext.each(deluge.torrents.columns,function(e){if(e.dataIndex!=b){d.push(e)}});deluge.torrents.colModel.setConfig(d);deluge.torrents.columns=d;var c=[];Ext.each(Deluge.Keys.Grid,function(e){if(e==b){c.push(e)}});Deluge.Keys.Grid=c;deluge.torrents.getView().refresh(true)}});Ext.ns("Deluge.plugins"); +/* + * Deluge.RemoveWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Deluge.RemoveWindow=Ext.extend(Ext.Window,{title:_("Remove Torrent"),layout:"fit",width:350,height:100,buttonAlign:"right",closeAction:"hide",closable:true,iconCls:"x-deluge-remove-window-icon",plain:true,bodyStyle:"padding: 5px; padding-left: 10px;",html:"Are you sure you wish to remove the torrent (s)?",initComponent:function(){Deluge.RemoveWindow.superclass.initComponent.call(this);this.addButton(_("Cancel"),this.onCancel,this);this.addButton(_("Remove With Data"),this.onRemoveData,this);this.addButton(_("Remove Torrent"),this.onRemove,this)},remove:function(a){Ext.each(this.torrentIds,function(b){deluge.client.core.remove_torrent(b,a,{success:function(){this.onRemoved(b)},scope:this,torrentId:b})},this)},show:function(a){Deluge.RemoveWindow.superclass.show.call(this);this.torrentIds=a},onCancel:function(){this.hide();this.torrentIds=null},onRemove:function(){this.remove(false)},onRemoveData:function(){this.remove(true)},onRemoved:function(a){deluge.events.fire("torrentRemoved",a);this.hide();deluge.ui.update()}});deluge.removeWindow=new Deluge.RemoveWindow(); +/* + * Deluge.Sidebar.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Deluge.Sidebar=Ext.extend(Ext.Panel,{panels:{},selected:null,constructor:function(a){a=Ext.apply({id:"sidebar",region:"west",cls:"deluge-sidebar",title:_("Filters"),layout:"accordion",split:true,width:200,minSize:175,collapsible:true,margins:"5 0 0 5",cmargins:"5 0 0 5"},a);Deluge.Sidebar.superclass.constructor.call(this,a)},initComponent:function(){Deluge.Sidebar.superclass.initComponent.call(this);deluge.events.on("disconnect",this.onDisconnect,this)},createFilter:function(c,b){var a=new Deluge.FilterPanel({filter:c});a.on("selectionchange",function(d,e){deluge.ui.update()});this.add(a);this.doLayout();this.panels[c]=a;a.header.on("click",function(d){if(!deluge.config.sidebar_multiple_filters){deluge.ui.update()}if(!a.list.getSelectionCount()){a.list.select(0)}});this.fireEvent("filtercreate",this,a);a.updateStates(b);this.fireEvent("afterfiltercreate",this,a)},getFilter:function(a){return this.panels[a]},getFilterStates:function(){var b={};if(deluge.config.sidebar_multiple_filters){this.items.each(function(d){var e=d.getState();if(e==null){return}b[d.filterType]=e},this)}else{var a=this.getLayout().activeItem;if(a){var c=a.getState();if(!c==null){return}b[a.filterType]=c}}return b},hasFilter:function(a){return(this.panels[a])?true:false},onDisconnect:function(){for(var a in this.panels){this.remove(this.panels[a])}this.panels={};this.selected=null},onFilterSelect:function(b,c,a){deluge.ui.update()},update:function(c){for(var b in c){var a=c[b];if(Ext.getKeys(this.panels).indexOf(b)>-1){this.panels[b].updateStates(a)}else{this.createFilter(b,a)}}Ext.each(Ext.keys(this.panels),function(d){if(Ext.keys(c).indexOf(d)==-1){this.remove(this.panels[d]);this.doLayout();delete this.panels[d]}},this)}}); +/* + * Deluge.Statusbar.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Deluge");Deluge.Statusbar=Ext.extend(Ext.ux.StatusBar,{constructor:function(a){a=Ext.apply({id:"deluge-statusbar",defaultIconCls:"x-deluge-statusbar x-not-connected",defaultText:_("Not Connected")},a);Deluge.Statusbar.superclass.constructor.call(this,a)},initComponent:function(){Deluge.Statusbar.superclass.initComponent.call(this);deluge.events.on("connect",this.onConnect,this);deluge.events.on("disconnect",this.onDisconnect,this)},createButtons:function(){this.buttons=this.add({id:"statusbar-connections",text:" ",cls:"x-btn-text-icon",iconCls:"x-deluge-connections",tooltip:_("Connections"),menu:new Deluge.StatusbarMenu({items:[{text:"50",value:"50",group:"max_connections_global",checked:false},{text:"100",value:"100",group:"max_connections_global",checked:false},{text:"200",value:"200",group:"max_connections_global",checked:false},{text:"300",value:"300",group:"max_connections_global",checked:false},{text:"500",value:"500",group:"max_connections_global",checked:false},{text:_("Unlimited"),value:"-1",group:"max_connections_global",checked:false},"-",{text:_("Other"),value:"other",group:"max_connections_global",checked:false}],otherWin:{title:_("Set Maximum Connections")}})},"-",{id:"statusbar-downspeed",text:" ",cls:"x-btn-text-icon",iconCls:"x-deluge-downloading",tooltip:_("Download Speed"),menu:new Deluge.StatusbarMenu({items:[{value:"5",text:"5 KiB/s",group:"max_download_speed",checked:false},{value:"10",text:"10 KiB/s",group:"max_download_speed",checked:false},{value:"30",text:"30 KiB/s",group:"max_download_speed",checked:false},{value:"80",text:"80 KiB/s",group:"max_download_speed",checked:false},{value:"300",text:"300 KiB/s",group:"max_download_speed",checked:false},{value:"-1",text:_("Unlimited"),group:"max_download_speed",checked:false},"-",{value:"other",text:_("Other"),group:"max_download_speed",checked:false}],otherWin:{title:_("Set Maximum Download Speed"),unit:_("Kib/s")}})},"-",{id:"statusbar-upspeed",text:" ",cls:"x-btn-text-icon",iconCls:"x-deluge-seeding",tooltip:_("Upload Speed"),menu:new Deluge.StatusbarMenu({items:[{value:"5",text:"5 KiB/s",group:"max_upload_speed",checked:false},{value:"10",text:"10 KiB/s",group:"max_upload_speed",checked:false},{value:"30",text:"30 KiB/s",group:"max_upload_speed",checked:false},{value:"80",text:"80 KiB/s",group:"max_upload_speed",checked:false},{value:"300",text:"300 KiB/s",group:"max_upload_speed",checked:false},{value:"-1",text:_("Unlimited"),group:"max_upload_speed",checked:false},"-",{value:"other",text:_("Other"),group:"max_upload_speed",checked:false}],otherWin:{title:_("Set Maximum Upload Speed"),unit:_("Kib/s")}})},"-",{id:"statusbar-traffic",text:" ",cls:"x-btn-text-icon",iconCls:"x-deluge-traffic",tooltip:_("Protocol Traffic Download/Upload"),handler:function(){deluge.preferences.show();deluge.preferences.selectPage("Network")}},"-",{id:"statusbar-dht",text:" ",cls:"x-btn-text-icon",iconCls:"x-deluge-dht",tooltip:_("DHT Nodes")},"-",{id:"statusbar-freespace",text:" ",cls:"x-btn-text-icon",iconCls:"x-deluge-freespace",tooltip:_("Freespace in download location"),handler:function(){deluge.preferences.show();deluge.preferences.selectPage("Downloads")}});this.created=true},onConnect:function(){this.setStatus({iconCls:"x-connected",text:""});if(!this.created){this.createButtons()}else{Ext.each(this.buttons,function(a){a.show();a.enable()})}this.doLayout()},onDisconnect:function(){this.clearStatus({useDefaults:true});Ext.each(this.buttons,function(a){a.hide();a.disable()});this.doLayout()},update:function(b){if(!b){return}function c(d){return d+" KiB/s"}var a=function(f,e){var g=this.items.get("statusbar-"+f);if(e.limit.value>0){var h=(e.value.formatter)?e.value.formatter(e.value.value,true):e.value.value;var d=(e.limit.formatter)?e.limit.formatter(e.limit.value,true):e.limit.value;var i=String.format(e.format,h,d)}else{var i=(e.value.formatter)?e.value.formatter(e.value.value,true):e.value.value}g.setText(i);if(!g.menu){return}g.menu.setValue(e.limit.value)}.createDelegate(this);a("connections",{value:{value:b.num_connections},limit:{value:b.max_num_connections},format:"{0} ({1})"});a("downspeed",{value:{value:b.download_rate,formatter:Deluge.Formatters.speed},limit:{value:b.max_download,formatter:c},format:"{0} ({1})"});a("upspeed",{value:{value:b.upload_rate,formatter:Deluge.Formatters.speed},limit:{value:b.max_upload,formatter:c},format:"{0} ({1})"});a("traffic",{value:{value:b.download_protocol_rate,formatter:Deluge.Formatters.speed},limit:{value:b.upload_protocol_rate,formatter:Deluge.Formatters.speed},format:"{0}/{1}"});this.items.get("statusbar-dht").setText(b.dht_nodes);this.items.get("statusbar-freespace").setText(fsize(b.free_space))}}); +/* + * Deluge.Toolbar.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Deluge.Toolbar=Ext.extend(Ext.Toolbar,{constructor:function(a){a=Ext.apply({items:[{id:"create",disabled:true,text:_("Create"),iconCls:"icon-create",handler:this.onTorrentAction},{id:"add",disabled:true,text:_("Add"),iconCls:"icon-add",handler:this.onTorrentAdd},{id:"remove",disabled:true,text:_("Remove"),iconCls:"icon-remove",handler:this.onTorrentAction},"|",{id:"pause",disabled:true,text:_("Pause"),iconCls:"icon-pause",handler:this.onTorrentAction},{id:"resume",disabled:true,text:_("Resume"),iconCls:"icon-resume",handler:this.onTorrentAction},"|",{id:"up",cls:"x-btn-text-icon",disabled:true,text:_("Up"),iconCls:"icon-up",handler:this.onTorrentAction},{id:"down",disabled:true,text:_("Down"),iconCls:"icon-down",handler:this.onTorrentAction},"|",{id:"preferences",text:_("Preferences"),iconCls:"x-deluge-preferences",handler:this.onPreferencesClick,scope:this},{id:"connectionman",text:_("Connection Manager"),iconCls:"x-deluge-connection-manager",handler:this.onConnectionManagerClick,scope:this},"->",{id:"help",iconCls:"icon-help",text:_("Help"),handler:this.onHelpClick,scope:this},{id:"logout",iconCls:"icon-logout",disabled:true,text:_("Logout"),handler:this.onLogout,scope:this}]},a);Deluge.Toolbar.superclass.constructor.call(this,a)},connectedButtons:["add","remove","pause","resume","up","down"],initComponent:function(){Deluge.Toolbar.superclass.initComponent.call(this);deluge.events.on("connect",this.onConnect,this);deluge.events.on("login",this.onLogin,this)},onConnect:function(){Ext.each(this.connectedButtons,function(a){this.items.get(a).enable()},this)},onDisconnect:function(){Ext.each(this.connectedButtons,function(a){this.items.get(a).disable()},this)},onLogin:function(){this.items.get("logout").enable()},onLogout:function(){this.items.get("logout").disable();deluge.login.logout()},onConnectionManagerClick:function(){deluge.connectionManager.show()},onHelpClick:function(){window.open("http://dev.deluge-torrent.org/wiki/UserGuide")},onPreferencesClick:function(){deluge.preferences.show()},onTorrentAction:function(c){var b=deluge.torrents.getSelections();var a=[];Ext.each(b,function(d){a.push(d.id)});switch(c.id){case"remove":deluge.removeWindow.show(a);break;case"pause":case"resume":deluge.client.core[c.id+"_torrent"](a,{success:function(){deluge.ui.update()}});break;case"up":case"down":deluge.client.core["queue_"+c.id](a,{success:function(){deluge.ui.update()}});break}},onTorrentAdd:function(){deluge.add.show()}});deluge.toolbar=new Deluge.Toolbar(); +/* + * Deluge.TorrentGrid.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +(function(){function c(j){return(j==-1)?"":j+1}function e(k,l,j){return String.format('
{1}
',j.data.state.toLowerCase(),k)}function g(j){if(!j){return}return fspeed(j)}function i(m,n,l){m=new Number(m);var j=m;var o=l.data.state+" "+m.toFixed(2)+"%";var k=new Number(this.style.match(/\w+:\s*(\d+)\w+/)[1]);return Deluge.progressBar(m,k-8,o)}function a(k,l,j){if(j.data.total_seeds>-1){return String.format("{0} ({1})",k,j.data.total_seeds)}else{return k}}function d(k,l,j){if(j.data.total_peers>-1){return String.format("{0} ({1})",k,j.data.total_peers)}else{return k}}function b(k,l,j){return(k<0)?"∞":new Number(k).toFixed(3)}function f(k,l,j){return String.format('
{0}
',k)}function h(j){return j*-1}Deluge.TorrentGrid=Ext.extend(Ext.grid.GridPanel,{torrents:{},columns:[{id:"queue",header:_("#"),width:30,sortable:true,renderer:c,dataIndex:"queue"},{id:"name",header:_("Name"),width:150,sortable:true,renderer:e,dataIndex:"name"},{header:_("Size"),width:75,sortable:true,renderer:fsize,dataIndex:"total_size"},{header:_("Progress"),width:150,sortable:true,renderer:i,dataIndex:"progress"},{header:_("Seeders"),width:60,sortable:true,renderer:a,dataIndex:"num_seeds"},{header:_("Peers"),width:60,sortable:true,renderer:d,dataIndex:"num_peers"},{header:_("Down Speed"),width:80,sortable:true,renderer:g,dataIndex:"download_payload_rate"},{header:_("Up Speed"),width:80,sortable:true,renderer:g,dataIndex:"upload_payload_rate"},{header:_("ETA"),width:60,sortable:true,renderer:ftime,dataIndex:"eta"},{header:_("Ratio"),width:60,sortable:true,renderer:b,dataIndex:"ratio"},{header:_("Avail"),width:60,sortable:true,renderer:b,dataIndex:"distributed_copies"},{header:_("Added"),width:80,sortable:true,renderer:fdate,dataIndex:"time_added"},{header:_("Tracker"),width:120,sortable:true,renderer:f,dataIndex:"tracker_host"},{header:_("Save Path"),width:120,sortable:true,renderer:fplain,dataIndex:"save_path"}],meta:{root:"torrents",idProperty:"id",fields:[{name:"queue",sortType:Deluge.data.SortTypes.asQueuePosition},{name:"name"},{name:"total_size",type:"int"},{name:"state"},{name:"progress",type:"float"},{name:"num_seeds",type:"int"},{name:"total_seeds",type:"int"},{name:"num_peers",type:"int"},{name:"total_peers",type:"int"},{name:"download_payload_rate",type:"int"},{name:"upload_payload_speed",type:"int"},{name:"eta",type:"int",sortType:h},{name:"ratio",type:"float"},{name:"distributed_copies",type:"float"},{name:"time_added",type:"int"},{name:"tracker_host"},{name:"save_path"}]},constructor:function(j){j=Ext.apply({id:"torrentGrid",store:new Ext.data.JsonStore(this.meta),columns:this.columns,region:"center",cls:"deluge-torrents",stripeRows:true,autoExpandColumn:"name",deferredRender:false,autoScroll:true,margins:"5 5 0 0",stateful:true,view:new Ext.ux.grid.BufferView({rowHeight:26,scrollDelay:false})},j);Deluge.TorrentGrid.superclass.constructor.call(this,j)},initComponent:function(){Deluge.TorrentGrid.superclass.initComponent.call(this);deluge.events.on("torrentRemoved",this.onTorrentRemoved,this);deluge.events.on("disconnect",this.onDisconnect,this);this.on("rowcontextmenu",function(j,m,l){l.stopEvent();var k=j.getSelectionModel();if(!k.hasSelection()){k.selectRow(m)}deluge.menus.torrent.showAt(l.getPoint())})},getTorrent:function(j){return this.getStore().getAt(j)},getSelected:function(){return this.getSelectionModel().getSelected()},getSelections:function(){return this.getSelectionModel().getSelections()},getSelectedId:function(){return this.getSelectionModel().getSelected().id},getSelectedIds:function(){var j=[];Ext.each(this.getSelectionModel().getSelections(),function(k){j.push(k.id)});return j},update:function(q){var o=this.getStore();var m=[];for(var p in q){var r=q[p];if(this.torrents[p]){var l=o.getById(p);l.beginEdit();for(var n in r){if(l.get(n)!=r[n]){l.set(n,r[n])}}l.endEdit()}else{var l=new Deluge.data.Torrent(r);l.id=p;this.torrents[p]=1;m.push(l)}}o.add(m);o.each(function(k){if(!q[k.id]){o.remove(k);delete this.torrents[k.id]}},this);o.commitChanges();var j=o.getSortState();if(!j){return}o.sort(j.field,j.direction)},onDisconnect:function(){this.getStore().removeAll();this.torrents={}},onTorrentRemoved:function(k){var j=this.getSelectionModel();Ext.each(k,function(m){var l=this.getStore().getById(m);if(j.isSelected(l)){j.deselectRow(this.getStore().indexOf(l))}this.getStore().remove(l);delete this.torrents[m]},this)}});deluge.torrents=new Deluge.TorrentGrid()})(); +/* + * Deluge.UI.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +deluge.ui={errorCount:0,filters:null,initialize:function(){deluge.add=new Deluge.add.AddWindow();deluge.details=new Deluge.details.DetailsPanel();deluge.connectionManager=new Deluge.ConnectionManager();deluge.editTrackers=new Deluge.EditTrackersWindow();deluge.login=new Deluge.LoginWindow();deluge.preferences=new Deluge.preferences.PreferencesWindow();deluge.sidebar=new Deluge.Sidebar();deluge.statusbar=new Deluge.Statusbar();this.MainPanel=new Ext.Panel({id:"mainPanel",iconCls:"x-deluge-main-panel",title:"Deluge",layout:"border",tbar:deluge.toolbar,items:[deluge.sidebar,deluge.details,deluge.torrents],bbar:deluge.statusbar});this.Viewport=new Ext.Viewport({layout:"fit",items:[this.MainPanel]});deluge.events.on("connect",this.onConnect,this);deluge.events.on("disconnect",this.onDisconnect,this);deluge.events.on("PluginDisabledEvent",this.onPluginDisabled,this);deluge.events.on("PluginEnabledEvent",this.onPluginEnabled,this);deluge.client=new Ext.ux.util.RpcClient({url:deluge.config.base+"json"});for(var a in Deluge.pluginStore){a=Deluge.createPlugin(a);a.enable();deluge.plugins[a.name]=a}Ext.QuickTips.init();deluge.client.on("connected",function(b){deluge.login.show()},this,{single:true});this.update=this.update.createDelegate(this);this.checkConnection=this.checkConnection.createDelegate(this);this.originalTitle=document.title},checkConnection:function(){deluge.client.web.connected({success:this.onConnectionSuccess,failure:this.onConnectionError,scope:this})},update:function(){var a=deluge.sidebar.getFilterStates();deluge.client.web.update_ui(Deluge.Keys.Grid,a,{success:this.onUpdate,failure:this.onUpdateError,scope:this});deluge.details.update()},onConnectionError:function(a){},onConnectionSuccess:function(a){deluge.statusbar.setStatus({iconCls:"x-deluge-statusbar icon-ok",text:_("Connection restored")});clearInterval(this.checking);if(!a){deluge.connectionManager.show()}},onUpdateError:function(a){if(this.errorCount==2){Ext.MessageBox.show({title:"Lost Connection",msg:"The connection to the webserver has been lost!",buttons:Ext.MessageBox.OK,icon:Ext.MessageBox.ERROR});deluge.events.fire("disconnect");deluge.statusbar.setStatus({text:"Lost connection to webserver"});this.checking=setInterval(this.checkConnection,2000)}this.errorCount++},onUpdate:function(a){if(!a.connected){deluge.connectionManager.disconnect(true);return}if(deluge.config.show_session_speed){document.title=this.originalTitle+" (Down: "+fspeed(a.stats.download_rate,true)+" Up: "+fspeed(a.stats.upload_rate,true)+")"}deluge.torrents.update(a.torrents);deluge.statusbar.update(a.stats);deluge.sidebar.update(a.filters);this.errorCount=0},onConnect:function(){if(!this.running){this.running=setInterval(this.update,2000);this.update()}deluge.client.web.get_plugins({success:this.onGotPlugins,scope:this})},onDisconnect:function(){this.stop()},onGotPlugins:function(a){Ext.each(a.enabled_plugins,function(b){if(deluge.plugins[b]){return}deluge.client.web.get_plugin_resources(b,{success:this.onGotPluginResources,scope:this})},this)},onPluginEnabled:function(a){if(deluge.plugins[a]){deluge.plugins[a].enable()}else{deluge.client.web.get_plugin_resources(a,{success:this.onGotPluginResources,scope:this})}},onGotPluginResources:function(b){var a=(Deluge.debug)?b.debug_scripts:b.scripts;Ext.each(a,function(c){Ext.ux.JSLoader({url:c,onLoad:this.onPluginLoaded,pluginName:b.name})},this)},onPluginDisabled:function(a){deluge.plugins[a].disable()},onPluginLoaded:function(a){if(!Deluge.hasPlugin(a.pluginName)){return}plugin=Deluge.createPlugin(a.pluginName);plugin.enable();deluge.plugins[plugin.name]=plugin},stop:function(){if(this.running){clearInterval(this.running);this.running=false;deluge.torrents.getStore().removeAll()}}};Ext.onReady(function(a){deluge.ui.initialize()}); \ No newline at end of file diff --git a/deluge/ui/web/js/ext-extensions-debug.js b/deluge/ui/web/js/ext-extensions-debug.js index 31e64ea94..7b4a485d7 100644 --- a/deluge/ui/web/js/ext-extensions-debug.js +++ b/deluge/ui/web/js/ext-extensions-debug.js @@ -1,4 +1,931 @@ /*! + * Ext.ux.layout.FormLayoutFix.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +// Taken from http://extjs.com/forum/showthread.php?t=75273 +// remove spaces for hidden elements and make show(), hide(), enable() and disable() act on +// the label. don't use hideLabel with this. +Ext.override(Ext.layout.FormLayout, { + renderItem : function(c, position, target){ + if(c && !c.rendered && (c.isFormField || c.fieldLabel) && c.inputType != 'hidden'){ + var args = this.getTemplateArgs(c); + if(typeof position == 'number'){ + position = target.dom.childNodes[position] || null; + } + if(position){ + c.formItem = this.fieldTpl.insertBefore(position, args, true); + }else{ + c.formItem = this.fieldTpl.append(target, args, true); + } + c.actionMode = 'formItem'; + c.render('x-form-el-'+c.id); + c.container = c.formItem; + c.actionMode = 'container'; + }else { + Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments); + } + } +}); +/*! + * Ext JS Library 3.1.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +Ext.ns('Ext.ux.tree'); + +/** + * @class Ext.ux.tree.TreeGrid + * @extends Ext.tree.TreePanel + * + * @xtype treegrid + */ +Ext.ux.tree.TreeGrid = Ext.extend(Ext.tree.TreePanel, { + rootVisible : false, + useArrows : true, + lines : false, + borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell + cls : 'x-treegrid', + + columnResize : true, + enableSort : true, + reserveScrollOffset : true, + enableHdMenu : true, + + columnsText : 'Columns', + + initComponent : function() { + if(!this.root) { + this.root = new Ext.tree.AsyncTreeNode({text: 'Root'}); + } + + // initialize the loader + var l = this.loader; + if(!l){ + l = new Ext.ux.tree.TreeGridLoader({ + dataUrl: this.dataUrl, + requestMethod: this.requestMethod, + store: this.store + }); + }else if(Ext.isObject(l) && !l.load){ + l = new Ext.ux.tree.TreeGridLoader(l); + } + else if(l) { + l.createNode = function(attr) { + if (!attr.uiProvider) { + attr.uiProvider = Ext.ux.tree.TreeGridNodeUI; + } + return Ext.tree.TreeLoader.prototype.createNode.call(this, attr); + } + } + this.loader = l; + + Ext.ux.tree.TreeGrid.superclass.initComponent.call(this); + + this.initColumns(); + + if(this.enableSort) { + this.treeGridSorter = new Ext.ux.tree.TreeGridSorter(this, this.enableSort); + } + + if(this.columnResize){ + this.colResizer = new Ext.tree.ColumnResizer(this.columnResize); + this.colResizer.init(this); + } + + var c = this.columns; + if(!this.internalTpl){ + this.internalTpl = new Ext.XTemplate( + '
', + '
', + '
', + '', + '', + '', + '', + '', + '
', + '
', + this.enableHdMenu ? '' : '', + '{header}', + '
', + '
', + '
', + '
', + '
', + '
', + '
' + ); + } + + if(!this.colgroupTpl) { + this.colgroupTpl = new Ext.XTemplate( + '' + ); + } + }, + + initColumns : function() { + var cs = this.columns, + len = cs.length, + columns = [], + i, c; + + for(i = 0; i < len; i++){ + c = cs[i]; + if(!c.isColumn) { + c.xtype = c.xtype ? (/^tg/.test(c.xtype) ? c.xtype : 'tg' + c.xtype) : 'tgcolumn'; + c = Ext.create(c); + } + c.init(this); + columns.push(c); + + if(this.enableSort !== false && c.sortable !== false) { + c.sortable = true; + this.enableSort = true; + } + } + + this.columns = columns; + }, + + onRender : function(){ + Ext.tree.TreePanel.superclass.onRender.apply(this, arguments); + + this.el.addClass('x-treegrid'); + + this.outerCt = this.body.createChild({ + cls:'x-tree-root-ct x-treegrid-ct ' + (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines') + }); + + this.internalTpl.overwrite(this.outerCt, {columns: this.columns}); + + this.mainHd = Ext.get(this.outerCt.dom.firstChild); + this.innerHd = Ext.get(this.mainHd.dom.firstChild); + this.innerBody = Ext.get(this.outerCt.dom.lastChild); + this.innerCt = Ext.get(this.innerBody.dom.firstChild); + + this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns}); + + if(this.hideHeaders){ + this.header.dom.style.display = 'none'; + } + else if(this.enableHdMenu !== false){ + this.hmenu = new Ext.menu.Menu({id: this.id + '-hctx'}); + if(this.enableColumnHide !== false){ + this.colMenu = new Ext.menu.Menu({id: this.id + '-hcols-menu'}); + this.colMenu.on({ + scope: this, + beforeshow: this.beforeColMenuShow, + itemclick: this.handleHdMenuClick + }); + this.hmenu.add({ + itemId:'columns', + hideOnClick: false, + text: this.columnsText, + menu: this.colMenu, + iconCls: 'x-cols-icon' + }); + } + this.hmenu.on('itemclick', this.handleHdMenuClick, this); + } + }, + + setRootNode : function(node){ + node.attributes.uiProvider = Ext.ux.tree.TreeGridRootNodeUI; + node = Ext.ux.tree.TreeGrid.superclass.setRootNode.call(this, node); + if(this.innerCt) { + this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns}); + } + return node; + }, + + initEvents : function() { + Ext.ux.tree.TreeGrid.superclass.initEvents.apply(this, arguments); + + this.mon(this.innerBody, 'scroll', this.syncScroll, this); + this.mon(this.innerHd, 'click', this.handleHdDown, this); + this.mon(this.mainHd, { + scope: this, + mouseover: this.handleHdOver, + mouseout: this.handleHdOut + }); + }, + + onResize : function(w, h) { + Ext.ux.tree.TreeGrid.superclass.onResize.apply(this, arguments); + + var bd = this.innerBody.dom; + var hd = this.innerHd.dom; + + if(!bd){ + return; + } + + if(Ext.isNumber(h)){ + bd.style.height = this.body.getHeight(true) - hd.offsetHeight + 'px'; + } + + if(Ext.isNumber(w)){ + var sw = Ext.num(this.scrollOffset, Ext.getScrollBarWidth()); + if(this.reserveScrollOffset || ((bd.offsetWidth - bd.clientWidth) > 10)){ + this.setScrollOffset(sw); + }else{ + var me = this; + setTimeout(function(){ + me.setScrollOffset(bd.offsetWidth - bd.clientWidth > 10 ? sw : 0); + }, 10); + } + } + }, + + updateColumnWidths : function() { + var cols = this.columns, + colCount = cols.length, + groups = this.outerCt.query('colgroup'), + groupCount = groups.length, + c, g, i, j; + + for(i = 0; i 0 && this.columns[index]) { + this.setColumnVisible(index, !item.checked); + } + } + + return true; + }, + + setColumnVisible : function(index, visible) { + this.columns[index].hidden = !visible; + this.updateColumnWidths(); + }, + + /** + * Scrolls the grid to the top + */ + scrollToTop : function(){ + this.innerBody.dom.scrollTop = 0; + this.innerBody.dom.scrollLeft = 0; + }, + + // private + syncScroll : function(){ + this.syncHeaderScroll(); + var mb = this.innerBody.dom; + this.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop); + }, + + // private + syncHeaderScroll : function(){ + var mb = this.innerBody.dom; + this.innerHd.dom.scrollLeft = mb.scrollLeft; + this.innerHd.dom.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore) + }, + + registerNode : function(n) { + Ext.ux.tree.TreeGrid.superclass.registerNode.call(this, n); + if(!n.uiProvider && !n.isRoot && !n.ui.isTreeGridNodeUI) { + n.ui = new Ext.ux.tree.TreeGridNodeUI(n); + } + } +}); + +Ext.reg('treegrid', Ext.ux.tree.TreeGrid); +/*! + * Ext JS Library 3.1.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +/** + * @class Ext.tree.ColumnResizer + * @extends Ext.util.Observable + */ +Ext.tree.ColumnResizer = Ext.extend(Ext.util.Observable, { + /** + * @cfg {Number} minWidth The minimum width the column can be dragged to. + * Defaults to 14. + */ + minWidth: 14, + + constructor: function(config){ + Ext.apply(this, config); + Ext.tree.ColumnResizer.superclass.constructor.call(this); + }, + + init : function(tree){ + this.tree = tree; + tree.on('render', this.initEvents, this); + }, + + initEvents : function(tree){ + tree.mon(tree.innerHd, 'mousemove', this.handleHdMove, this); + this.tracker = new Ext.dd.DragTracker({ + onBeforeStart: this.onBeforeStart.createDelegate(this), + onStart: this.onStart.createDelegate(this), + onDrag: this.onDrag.createDelegate(this), + onEnd: this.onEnd.createDelegate(this), + tolerance: 3, + autoStart: 300 + }); + this.tracker.initEl(tree.innerHd); + tree.on('beforedestroy', this.tracker.destroy, this.tracker); + }, + + handleHdMove : function(e, t){ + var hw = 5, + x = e.getPageX(), + hd = e.getTarget('.x-treegrid-hd', 3, true); + + if(hd){ + var r = hd.getRegion(), + ss = hd.dom.style, + pn = hd.dom.parentNode; + + if(x - r.left <= hw && hd.dom !== pn.firstChild) { + var ps = hd.dom.previousSibling; + while(ps && Ext.fly(ps).hasClass('x-treegrid-hd-hidden')) { + ps = ps.previousSibling; + } + if(ps) { + this.activeHd = Ext.get(ps); + ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize'; + } + } else if(r.right - x <= hw) { + var ns = hd.dom; + while(ns && Ext.fly(ns).hasClass('x-treegrid-hd-hidden')) { + ns = ns.previousSibling; + } + if(ns) { + this.activeHd = Ext.get(ns); + ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize'; + } + } else{ + delete this.activeHd; + ss.cursor = ''; + } + } + }, + + onBeforeStart : function(e){ + this.dragHd = this.activeHd; + return !!this.dragHd; + }, + + onStart : function(e){ + this.tree.headersDisabled = true; + this.proxy = this.tree.body.createChild({cls:'x-treegrid-resizer'}); + this.proxy.setHeight(this.tree.body.getHeight()); + + var x = this.tracker.getXY()[0]; + + this.hdX = this.dragHd.getX(); + this.hdIndex = this.tree.findHeaderIndex(this.dragHd); + + this.proxy.setX(this.hdX); + this.proxy.setWidth(x-this.hdX); + + this.maxWidth = this.tree.outerCt.getWidth() - this.tree.innerBody.translatePoints(this.hdX).left; + }, + + onDrag : function(e){ + var cursorX = this.tracker.getXY()[0]; + this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth)); + }, + + onEnd : function(e){ + var nw = this.proxy.getWidth(), + tree = this.tree; + + this.proxy.remove(); + delete this.dragHd; + + tree.columns[this.hdIndex].width = nw; + tree.updateColumnWidths(); + + setTimeout(function(){ + tree.headersDisabled = false; + }, 100); + } +});/*! + * Ext JS Library 3.1.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +(function() { + Ext.override(Ext.list.Column, { + init : function() { + if(!this.type){ + this.type = "auto"; + } + + var st = Ext.data.SortTypes; + // named sortTypes are supported, here we look them up + if(typeof this.sortType == "string"){ + this.sortType = st[this.sortType]; + } + + // set default sortType for strings and dates + if(!this.sortType){ + switch(this.type){ + case "string": + this.sortType = st.asUCString; + break; + case "date": + this.sortType = st.asDate; + break; + default: + this.sortType = st.none; + } + } + } + }); + + Ext.tree.Column = Ext.extend(Ext.list.Column, {}); + Ext.tree.NumberColumn = Ext.extend(Ext.list.NumberColumn, {}); + Ext.tree.DateColumn = Ext.extend(Ext.list.DateColumn, {}); + Ext.tree.BooleanColumn = Ext.extend(Ext.list.BooleanColumn, {}); + + Ext.reg('tgcolumn', Ext.tree.Column); + Ext.reg('tgnumbercolumn', Ext.tree.NumberColumn); + Ext.reg('tgdatecolumn', Ext.tree.DateColumn); + Ext.reg('tgbooleancolumn', Ext.tree.BooleanColumn); +})(); +/*! + * Ext JS Library 3.1.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +/** + * @class Ext.ux.tree.TreeGridLoader + * @extends Ext.tree.TreeLoader + */ +Ext.ux.tree.TreeGridLoader = Ext.extend(Ext.tree.TreeLoader, { + createNode : function(attr) { + if (!attr.uiProvider) { + attr.uiProvider = Ext.ux.tree.TreeGridNodeUI; + } + return Ext.tree.TreeLoader.prototype.createNode.call(this, attr); + } +});/*! + * Ext JS Library 3.1.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +/** + * @class Ext.ux.tree.TreeGridNodeUI + * @extends Ext.tree.TreeNodeUI + */ +Ext.ux.tree.TreeGridNodeUI = Ext.extend(Ext.tree.TreeNodeUI, { + isTreeGridNodeUI: true, + + renderElements : function(n, a, targetNode, bulkRender){ + var t = n.getOwnerTree(), + cols = t.columns, + c = cols[0], + i, buf, len; + + this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : ''; + + buf = [ + '', + '', + '', + '', this.indentMarkup, "", + '', + '', + '', + '', (c.tpl ? c.tpl.apply(a) : a[c.dataIndex] || c.text), '', + '' + ]; + + for(i = 1, len = cols.length; i < len; i++){ + c = cols[i]; + buf.push( + '', + '
', + (c.tpl ? c.tpl.apply(a) : a[c.dataIndex]), + '
', + '' + ); + } + + buf.push( + '', + '' + ); + for(i = 0, len = cols.length; i'); + } + buf.push(''); + + if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){ + this.wrap = Ext.DomHelper.insertHtml("beforeBegin", n.nextSibling.ui.getEl(), buf.join('')); + }else{ + this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join('')); + } + + this.elNode = this.wrap.childNodes[0]; + this.ctNode = this.wrap.childNodes[1].firstChild.firstChild; + var cs = this.elNode.firstChild.childNodes; + this.indentNode = cs[0]; + this.ecNode = cs[1]; + this.iconNode = cs[2]; + this.anchor = cs[3]; + this.textNode = cs[3].firstChild; + }, + + // private + animExpand : function(cb){ + this.ctNode.style.display = ""; + Ext.ux.tree.TreeGridNodeUI.superclass.animExpand.call(this, cb); + } +}); + +Ext.ux.tree.TreeGridRootNodeUI = Ext.extend(Ext.tree.TreeNodeUI, { + isTreeGridNodeUI: true, + + // private + render : function(){ + if(!this.rendered){ + this.wrap = this.ctNode = this.node.ownerTree.innerCt.dom; + this.node.expanded = true; + } + + if(Ext.isWebKit) { + // weird table-layout: fixed issue in webkit + var ct = this.ctNode; + ct.style.tableLayout = null; + (function() { + ct.style.tableLayout = 'fixed'; + }).defer(1); + } + }, + + destroy : function(){ + if(this.elNode){ + Ext.dd.Registry.unregister(this.elNode.id); + } + delete this.node; + }, + + collapse : Ext.emptyFn, + expand : Ext.emptyFn +});/*! + * Ext.ux.tree.TreeGridNodeUIFix.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +Ext.override(Ext.ux.tree.TreeGridNodeUI, { + + updateColumns: function() { + if (!this.rendered) return; + + var a = this.node.attributes, + t = this.node.getOwnerTree(), + cols = t.columns, + c = cols[0]; + + // Update the first column + this.anchor.firstChild.innerHTML = (c.tpl ? c.tpl.apply(a) : a[c.dataIndex] || c.text); + + // Update the remaining columns + for(i = 1, len = cols.length; i < len; i++) { + c = cols[i]; + this.elNode.childNodes[i].firstChild.innerHTML = (c.tpl ? c.tpl.apply(a) : a[c.dataIndex] || c.text); + } + } + +}); +Ext.tree.RenderColumn = Ext.extend(Ext.tree.Column, { + + constructor: function(c) { + c.tpl = c.tpl || new Ext.XTemplate('{' + c.dataIndex + ':this.format}'); + c.tpl.format = c.renderer; + c.tpl.col = this; + Ext.tree.RenderColumn.superclass.constructor.call(this, c); + } +}); +Ext.reg('tgrendercolumn', Ext.tree.RenderColumn); +/*! + * Ext JS Library 3.1.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +Ext.ns('Ext.ux.tree'); + +/** + * @class Ext.ux.tree.TreeGridSorter + * @extends Ext.tree.TreeSorter + */ +Ext.ux.tree.TreeGridSorter = Ext.extend(Ext.tree.TreeSorter, { + /** + * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to ['sort-asc', 'sort-desc']) + */ + sortClasses : ['sort-asc', 'sort-desc'], + /** + * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to 'Sort Ascending') + */ + sortAscText : 'Sort Ascending', + /** + * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to 'Sort Descending') + */ + sortDescText : 'Sort Descending', + + constructor : function(tree, config) { + if(!Ext.isObject(config)) { + config = { + property: tree.columns[0].dataIndex || 'text', + folderSort: true + } + } + + Ext.ux.tree.TreeGridSorter.superclass.constructor.apply(this, arguments); + + this.tree = tree; + tree.on('headerclick', this.onHeaderClick, this); + tree.ddAppendOnly = true; + + me = this; + this.defaultSortFn = function(n1, n2){ + + var dsc = me.dir && me.dir.toLowerCase() == 'desc'; + var p = me.property || 'text'; + var sortType = me.sortType; + var fs = me.folderSort; + var cs = me.caseSensitive === true; + var leafAttr = me.leafAttr || 'leaf'; + + if(fs){ + if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){ + return 1; + } + if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){ + return -1; + } + } + var v1 = sortType ? sortType(n1.attributes[p]) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase()); + var v2 = sortType ? sortType(n2.attributes[p]) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase()); + if(v1 < v2){ + return dsc ? +1 : -1; + }else if(v1 > v2){ + return dsc ? -1 : +1; + }else{ + return 0; + } + }; + + tree.on('afterrender', this.onAfterTreeRender, this, {single: true}); + tree.on('headermenuclick', this.onHeaderMenuClick, this); + }, + + onAfterTreeRender : function() { + var hmenu = this.tree.hmenu; + hmenu.insert(0, + {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'}, + {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'} + ); + this.updateSortIcon(0, 'asc'); + }, + + onHeaderMenuClick : function(c, id, index) { + if(id === 'asc' || id === 'desc') { + this.onHeaderClick(c, null, index); + return false; + } + }, + + onHeaderClick : function(c, el, i) { + if(c && !this.tree.headersDisabled){ + var me = this; + + me.property = c.dataIndex; + me.dir = c.dir = (c.dir === 'desc' ? 'asc' : 'desc'); + me.sortType = c.sortType; + me.caseSensitive === Ext.isBoolean(c.caseSensitive) ? c.caseSensitive : this.caseSensitive; + me.sortFn = c.sortFn || this.defaultSortFn; + + this.tree.root.cascade(function(n) { + if(!n.isLeaf()) { + me.updateSort(me.tree, n); + } + }); + + this.updateSortIcon(i, c.dir); + } + }, + + // private + updateSortIcon : function(col, dir){ + var sc = this.sortClasses; + var hds = this.tree.innerHd.select('td').removeClass(sc); + hds.item(col).addClass(sc[dir == 'desc' ? 1 : 0]); + } +});/*! * Ext JS Library 3.1.0 * Copyright(c) 2006-2009 Ext JS, LLC * licensing@extjs.com @@ -399,6 +1326,452 @@ Ext.reg('fileuploadfield', Ext.ux.form.FileUploadField); // backwards compat Ext.form.FileUploadField = Ext.ux.form.FileUploadField; +/*! + * Ext.ux.form.RadioGroup.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ + +// Allow radiogroups to be treated as a single form element. +Ext.override(Ext.form.RadioGroup, { + + afterRender: function() { + this.items.each(function(i) { + this.relayEvents(i, ['check']); + }, this); + if (this.lazyValue) { + this.setValue(this.value); + delete this.value; + delete this.lazyValue; + } + Ext.form.RadioGroup.superclass.afterRender.call(this) + }, + + getName: function() { + return this.items.first().getName(); + }, + + getValue: function() { + return this.items.first().getGroupValue(); + }, + + setValue: function(v) { + if (!this.items.each) { + this.value = v; + this.lazyValue = true; + return; + } + this.items.each(function(item) { + if (item.rendered) { + var checked = (item.el.getValue() == String(v)); + item.el.dom.checked = checked; + item.el.dom.defaultChecked = checked; + item.wrap[checked ? 'addClass' : 'removeClass'](item.checkedCls); + } + }); + } +}); +/*! + * Ext JS Library 3.1.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +Ext.ns('Ext.ux.form'); + +/** + * @class Ext.ux.form.SpinnerField + * @extends Ext.form.NumberField + * Creates a field utilizing Ext.ux.Spinner + * @xtype spinnerfield + */ +Ext.ux.form.SpinnerField = Ext.extend(Ext.form.NumberField, { + actionMode: 'wrap', + deferHeight: true, + autoSize: Ext.emptyFn, + onBlur: Ext.emptyFn, + adjustSize: Ext.BoxComponent.prototype.adjustSize, + + constructor: function(config) { + var spinnerConfig = Ext.copyTo({}, config, 'incrementValue,alternateIncrementValue,accelerate,defaultValue,triggerClass,splitterClass'); + + var spl = this.spinner = new Ext.ux.Spinner(spinnerConfig); + + var plugins = config.plugins + ? (Ext.isArray(config.plugins) + ? config.plugins.push(spl) + : [config.plugins, spl]) + : spl; + + Ext.ux.form.SpinnerField.superclass.constructor.call(this, Ext.apply(config, {plugins: plugins})); + }, + + // private + getResizeEl: function(){ + return this.wrap; + }, + + // private + getPositionEl: function(){ + return this.wrap; + }, + + // private + alignErrorIcon: function(){ + if (this.wrap) { + this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]); + } + }, + + validateBlur: function(){ + return true; + } +}); + +Ext.reg('spinnerfield', Ext.ux.form.SpinnerField); + +//backwards compat +Ext.form.SpinnerField = Ext.ux.form.SpinnerField; +/*! + * Ext.ux.form.SpinnerGroup.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns('Ext.ux.form'); + +/** + * + */ +Ext.ux.form.SpinnerGroup = Ext.extend(Ext.form.CheckboxGroup, { + + // private + defaultType: 'spinnerfield', + + // private + groupCls: 'x-form-spinner-group', + + colCfg: {}, + + // private + onRender : function(ct, position){ + if(!this.el){ + var panelCfg = { + cls: this.groupCls, + layout: 'column', + border: false, + renderTo: ct + }; + var colCfg = Ext.apply({ + defaultType: this.defaultType, + layout: 'form', + border: false, + labelWidth: 60, + defaults: { + hideLabel: true, + anchor: '60%' + } + }, this.colCfg); + + if(this.items[0].items){ + + // The container has standard ColumnLayout configs, so pass them in directly + + Ext.apply(panelCfg, { + layoutConfig: {columns: this.items.length}, + defaults: this.defaults, + items: this.items + }) + for(var i=0, len=this.items.length; i0 && i%rows==0){ + ri++; + } + if(this.items[i].fieldLabel){ + this.items[i].hideLabel = false; + } + cols[ri].items.push(this.items[i]); + }; + }else{ + for(var i=0, len=this.items.length; i + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Ext.ux.form"); + +/** + * Ext.ux.form.ToggleField class + * + * @author Damien Churchill + * @version v0.1 + * + * @class Ext.ux.form.ToggleField + * @extends Ext.form.TriggerField + */ +Ext.ux.form.ToggleField = Ext.extend(Ext.form.Field, { + + cls: 'x-toggle-field', + + initComponent: function() { + Ext.ux.form.ToggleField.superclass.initComponent.call(this); + + this.toggle = new Ext.form.Checkbox(); + this.toggle.on('check', this.onToggleCheck, this); + + this.input = new Ext.form.TextField({ + disabled: true + }); + }, + + onRender: function(ct, position) { + if (!this.el) { + this.panel = new Ext.Panel({ + cls: this.groupCls, + layout: 'table', + layoutConfig: { + columns: 2 + }, + border: false, + renderTo: ct + }); + this.panel.ownerCt = this; + this.el = this.panel.getEl(); + + this.panel.add(this.toggle); + this.panel.add(this.input); + this.panel.doLayout(); + + this.toggle.getEl().parent().setStyle('padding-right', '10px'); + } + Ext.ux.form.ToggleField.superclass.onRender.call(this, ct, position); + }, + + // private + onResize: function(w, h) { + this.panel.setSize(w, h); + this.panel.doLayout(); + + // we substract 10 for the padding :-) + var inputWidth = w - this.toggle.getSize().width - 25; + this.input.setSize(inputWidth, h); + }, + + onToggleCheck: function(toggle, checked) { + this.input.setDisabled(!checked); + } +}); +Ext.reg('togglefield', Ext.ux.form.ToggleField); Ext.ux.JSLoader = function(options) { Ext.ux.JSLoader.scripts[++Ext.ux.JSLoader.index] = { url: options.url, @@ -875,67 +2248,6 @@ Ext.ux.Spinner = Ext.extend(Ext.util.Observable, { //backwards compat Ext.form.Spinner = Ext.ux.Spinner; -/*! - * Ext JS Library 3.1.0 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license - */ -Ext.ns('Ext.ux.form'); - -/** - * @class Ext.ux.form.SpinnerField - * @extends Ext.form.NumberField - * Creates a field utilizing Ext.ux.Spinner - * @xtype spinnerfield - */ -Ext.ux.form.SpinnerField = Ext.extend(Ext.form.NumberField, { - actionMode: 'wrap', - deferHeight: true, - autoSize: Ext.emptyFn, - onBlur: Ext.emptyFn, - adjustSize: Ext.BoxComponent.prototype.adjustSize, - - constructor: function(config) { - var spinnerConfig = Ext.copyTo({}, config, 'incrementValue,alternateIncrementValue,accelerate,defaultValue,triggerClass,splitterClass'); - - var spl = this.spinner = new Ext.ux.Spinner(spinnerConfig); - - var plugins = config.plugins - ? (Ext.isArray(config.plugins) - ? config.plugins.push(spl) - : [config.plugins, spl]) - : spl; - - Ext.ux.form.SpinnerField.superclass.constructor.call(this, Ext.apply(config, {plugins: plugins})); - }, - - // private - getResizeEl: function(){ - return this.wrap; - }, - - // private - getPositionEl: function(){ - return this.wrap; - }, - - // private - alignErrorIcon: function(){ - if (this.wrap) { - this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]); - } - }, - - validateBlur: function(){ - return true; - } -}); - -Ext.reg('spinnerfield', Ext.ux.form.SpinnerField); - -//backwards compat -Ext.form.SpinnerField = Ext.ux.form.SpinnerField; /*! * Ext JS Library 3.1.0 * Copyright(c) 2006-2009 Ext JS, LLC @@ -1365,883 +2677,3 @@ statusBar.setStatus({ } }); Ext.reg('statusbar', Ext.ux.StatusBar); -Ext.namespace("Ext.ux.form"); - -/** - * Ext.ux.form.ToggleField class - * - * @author Damien Churchill - * @version v0.1 - * - * @class Ext.ux.form.ToggleField - * @extends Ext.form.TriggerField - */ -Ext.ux.form.ToggleField = Ext.extend(Ext.form.Field, { - - cls: 'x-toggle-field', - - initComponent: function() { - Ext.ux.form.ToggleField.superclass.initComponent.call(this); - - this.toggle = new Ext.form.Checkbox(); - this.toggle.on('check', this.onToggleCheck, this); - - this.input = new Ext.form.TextField({ - disabled: true - }); - }, - - onRender: function(ct, position) { - if (!this.el) { - this.panel = new Ext.Panel({ - cls: this.groupCls, - layout: 'table', - layoutConfig: { - columns: 2 - }, - border: false, - renderTo: ct - }); - this.panel.ownerCt = this; - this.el = this.panel.getEl(); - - this.panel.add(this.toggle); - this.panel.add(this.input); - this.panel.doLayout(); - - this.toggle.getEl().parent().setStyle('padding-right', '10px'); - } - Ext.ux.form.ToggleField.superclass.onRender.call(this, ct, position); - }, - - // private - onResize: function(w, h) { - this.panel.setSize(w, h); - this.panel.doLayout(); - - // we substract 10 for the padding :-) - var inputWidth = w - this.toggle.getSize().width - 10; - this.input.setSize(inputWidth, h); - }, - - onToggleCheck: function(toggle, checked) { - this.input.setDisabled(!checked); - } -}); -Ext.reg('togglefield', Ext.ux.form.ToggleField); -/*! - * Ext JS Library 3.1.0 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license - */ -Ext.ns('Ext.ux.tree'); - -/** - * @class Ext.ux.tree.TreeGridSorter - * @extends Ext.tree.TreeSorter - */ -Ext.ux.tree.TreeGridSorter = Ext.extend(Ext.tree.TreeSorter, { - /** - * @cfg {Array} sortClasses The CSS classes applied to a header when it is sorted. (defaults to ['sort-asc', 'sort-desc']) - */ - sortClasses : ['sort-asc', 'sort-desc'], - /** - * @cfg {String} sortAscText The text displayed in the 'Sort Ascending' menu item (defaults to 'Sort Ascending') - */ - sortAscText : 'Sort Ascending', - /** - * @cfg {String} sortDescText The text displayed in the 'Sort Descending' menu item (defaults to 'Sort Descending') - */ - sortDescText : 'Sort Descending', - - constructor : function(tree, config) { - if(!Ext.isObject(config)) { - config = { - property: tree.columns[0].dataIndex || 'text', - folderSort: true - } - } - - Ext.ux.tree.TreeGridSorter.superclass.constructor.apply(this, arguments); - - this.tree = tree; - tree.on('headerclick', this.onHeaderClick, this); - tree.ddAppendOnly = true; - - me = this; - this.defaultSortFn = function(n1, n2){ - - var dsc = me.dir && me.dir.toLowerCase() == 'desc'; - var p = me.property || 'text'; - var sortType = me.sortType; - var fs = me.folderSort; - var cs = me.caseSensitive === true; - var leafAttr = me.leafAttr || 'leaf'; - - if(fs){ - if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){ - return 1; - } - if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){ - return -1; - } - } - var v1 = sortType ? sortType(n1.attributes[p]) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase()); - var v2 = sortType ? sortType(n2.attributes[p]) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase()); - if(v1 < v2){ - return dsc ? +1 : -1; - }else if(v1 > v2){ - return dsc ? -1 : +1; - }else{ - return 0; - } - }; - - tree.on('afterrender', this.onAfterTreeRender, this, {single: true}); - tree.on('headermenuclick', this.onHeaderMenuClick, this); - }, - - onAfterTreeRender : function() { - var hmenu = this.tree.hmenu; - hmenu.insert(0, - {itemId:'asc', text: this.sortAscText, cls: 'xg-hmenu-sort-asc'}, - {itemId:'desc', text: this.sortDescText, cls: 'xg-hmenu-sort-desc'} - ); - this.updateSortIcon(0, 'asc'); - }, - - onHeaderMenuClick : function(c, id, index) { - if(id === 'asc' || id === 'desc') { - this.onHeaderClick(c, null, index); - return false; - } - }, - - onHeaderClick : function(c, el, i) { - if(c && !this.tree.headersDisabled){ - var me = this; - - me.property = c.dataIndex; - me.dir = c.dir = (c.dir === 'desc' ? 'asc' : 'desc'); - me.sortType = c.sortType; - me.caseSensitive === Ext.isBoolean(c.caseSensitive) ? c.caseSensitive : this.caseSensitive; - me.sortFn = c.sortFn || this.defaultSortFn; - - this.tree.root.cascade(function(n) { - if(!n.isLeaf()) { - me.updateSort(me.tree, n); - } - }); - - this.updateSortIcon(i, c.dir); - } - }, - - // private - updateSortIcon : function(col, dir){ - var sc = this.sortClasses; - var hds = this.tree.innerHd.select('td').removeClass(sc); - hds.item(col).addClass(sc[dir == 'desc' ? 1 : 0]); - } -});/*! - * Ext JS Library 3.1.0 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license - */ -/** - * @class Ext.tree.ColumnResizer - * @extends Ext.util.Observable - */ -Ext.tree.ColumnResizer = Ext.extend(Ext.util.Observable, { - /** - * @cfg {Number} minWidth The minimum width the column can be dragged to. - * Defaults to 14. - */ - minWidth: 14, - - constructor: function(config){ - Ext.apply(this, config); - Ext.tree.ColumnResizer.superclass.constructor.call(this); - }, - - init : function(tree){ - this.tree = tree; - tree.on('render', this.initEvents, this); - }, - - initEvents : function(tree){ - tree.mon(tree.innerHd, 'mousemove', this.handleHdMove, this); - this.tracker = new Ext.dd.DragTracker({ - onBeforeStart: this.onBeforeStart.createDelegate(this), - onStart: this.onStart.createDelegate(this), - onDrag: this.onDrag.createDelegate(this), - onEnd: this.onEnd.createDelegate(this), - tolerance: 3, - autoStart: 300 - }); - this.tracker.initEl(tree.innerHd); - tree.on('beforedestroy', this.tracker.destroy, this.tracker); - }, - - handleHdMove : function(e, t){ - var hw = 5, - x = e.getPageX(), - hd = e.getTarget('.x-treegrid-hd', 3, true); - - if(hd){ - var r = hd.getRegion(), - ss = hd.dom.style, - pn = hd.dom.parentNode; - - if(x - r.left <= hw && hd.dom !== pn.firstChild) { - var ps = hd.dom.previousSibling; - while(ps && Ext.fly(ps).hasClass('x-treegrid-hd-hidden')) { - ps = ps.previousSibling; - } - if(ps) { - this.activeHd = Ext.get(ps); - ss.cursor = Ext.isWebKit ? 'e-resize' : 'col-resize'; - } - } else if(r.right - x <= hw) { - var ns = hd.dom; - while(ns && Ext.fly(ns).hasClass('x-treegrid-hd-hidden')) { - ns = ns.previousSibling; - } - if(ns) { - this.activeHd = Ext.get(ns); - ss.cursor = Ext.isWebKit ? 'w-resize' : 'col-resize'; - } - } else{ - delete this.activeHd; - ss.cursor = ''; - } - } - }, - - onBeforeStart : function(e){ - this.dragHd = this.activeHd; - return !!this.dragHd; - }, - - onStart : function(e){ - this.tree.headersDisabled = true; - this.proxy = this.tree.body.createChild({cls:'x-treegrid-resizer'}); - this.proxy.setHeight(this.tree.body.getHeight()); - - var x = this.tracker.getXY()[0]; - - this.hdX = this.dragHd.getX(); - this.hdIndex = this.tree.findHeaderIndex(this.dragHd); - - this.proxy.setX(this.hdX); - this.proxy.setWidth(x-this.hdX); - - this.maxWidth = this.tree.outerCt.getWidth() - this.tree.innerBody.translatePoints(this.hdX).left; - }, - - onDrag : function(e){ - var cursorX = this.tracker.getXY()[0]; - this.proxy.setWidth((cursorX-this.hdX).constrain(this.minWidth, this.maxWidth)); - }, - - onEnd : function(e){ - var nw = this.proxy.getWidth(), - tree = this.tree; - - this.proxy.remove(); - delete this.dragHd; - - tree.columns[this.hdIndex].width = nw; - tree.updateColumnWidths(); - - setTimeout(function(){ - tree.headersDisabled = false; - }, 100); - } -});/*! - * Ext JS Library 3.1.0 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license - */ -/** - * @class Ext.ux.tree.TreeGridNodeUI - * @extends Ext.tree.TreeNodeUI - */ -Ext.ux.tree.TreeGridNodeUI = Ext.extend(Ext.tree.TreeNodeUI, { - isTreeGridNodeUI: true, - - renderElements : function(n, a, targetNode, bulkRender){ - var t = n.getOwnerTree(), - cols = t.columns, - c = cols[0], - i, buf, len; - - this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : ''; - - buf = [ - '', - '', - '', - '', this.indentMarkup, "", - '', - '', - '', - '', (c.tpl ? c.tpl.apply(a) : a[c.dataIndex] || c.text), '', - '' - ]; - - for(i = 1, len = cols.length; i < len; i++){ - c = cols[i]; - buf.push( - '', - '
', - (c.tpl ? c.tpl.apply(a) : a[c.dataIndex]), - '
', - '' - ); - } - - buf.push( - '', - '' - ); - for(i = 0, len = cols.length; i'); - } - buf.push(''); - - if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){ - this.wrap = Ext.DomHelper.insertHtml("beforeBegin", n.nextSibling.ui.getEl(), buf.join('')); - }else{ - this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join('')); - } - - this.elNode = this.wrap.childNodes[0]; - this.ctNode = this.wrap.childNodes[1].firstChild.firstChild; - var cs = this.elNode.firstChild.childNodes; - this.indentNode = cs[0]; - this.ecNode = cs[1]; - this.iconNode = cs[2]; - this.anchor = cs[3]; - this.textNode = cs[3].firstChild; - }, - - // private - animExpand : function(cb){ - this.ctNode.style.display = ""; - Ext.ux.tree.TreeGridNodeUI.superclass.animExpand.call(this, cb); - } -}); - -Ext.ux.tree.TreeGridRootNodeUI = Ext.extend(Ext.tree.TreeNodeUI, { - isTreeGridNodeUI: true, - - // private - render : function(){ - if(!this.rendered){ - this.wrap = this.ctNode = this.node.ownerTree.innerCt.dom; - this.node.expanded = true; - } - - if(Ext.isWebKit) { - // weird table-layout: fixed issue in webkit - var ct = this.ctNode; - ct.style.tableLayout = null; - (function() { - ct.style.tableLayout = 'fixed'; - }).defer(1); - } - }, - - destroy : function(){ - if(this.elNode){ - Ext.dd.Registry.unregister(this.elNode.id); - } - delete this.node; - }, - - collapse : Ext.emptyFn, - expand : Ext.emptyFn -});/*! - * Ext JS Library 3.1.0 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license - */ -/** - * @class Ext.ux.tree.TreeGridLoader - * @extends Ext.tree.TreeLoader - */ -Ext.ux.tree.TreeGridLoader = Ext.extend(Ext.tree.TreeLoader, { - createNode : function(attr) { - if (!attr.uiProvider) { - attr.uiProvider = Ext.ux.tree.TreeGridNodeUI; - } - return Ext.tree.TreeLoader.prototype.createNode.call(this, attr); - } -});/*! - * Ext JS Library 3.1.0 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license - */ -(function() { - Ext.override(Ext.list.Column, { - init : function() { - if(!this.type){ - this.type = "auto"; - } - - var st = Ext.data.SortTypes; - // named sortTypes are supported, here we look them up - if(typeof this.sortType == "string"){ - this.sortType = st[this.sortType]; - } - - // set default sortType for strings and dates - if(!this.sortType){ - switch(this.type){ - case "string": - this.sortType = st.asUCString; - break; - case "date": - this.sortType = st.asDate; - break; - default: - this.sortType = st.none; - } - } - } - }); - - Ext.tree.Column = Ext.extend(Ext.list.Column, {}); - Ext.tree.NumberColumn = Ext.extend(Ext.list.NumberColumn, {}); - Ext.tree.DateColumn = Ext.extend(Ext.list.DateColumn, {}); - Ext.tree.BooleanColumn = Ext.extend(Ext.list.BooleanColumn, {}); - - Ext.reg('tgcolumn', Ext.tree.Column); - Ext.reg('tgnumbercolumn', Ext.tree.NumberColumn); - Ext.reg('tgdatecolumn', Ext.tree.DateColumn); - Ext.reg('tgbooleancolumn', Ext.tree.BooleanColumn); -})(); -Ext.tree.RenderColumn = Ext.extend(Ext.tree.Column, { - - constructor: function(c) { - c.tpl = c.tpl || new Ext.XTemplate('{' + c.dataIndex + ':this.format}'); - c.tpl.format = c.renderer; - c.tpl.col = this; - Ext.tree.RenderColumn.superclass.constructor.call(this, c); - } -}); -Ext.reg('tgrendercolumn', Ext.tree.RenderColumn); -/*! - * Ext JS Library 3.1.0 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license - */ -/** - * @class Ext.ux.tree.TreeGrid - * @extends Ext.tree.TreePanel - * - * @xtype treegrid - */ -Ext.ux.tree.TreeGrid = Ext.extend(Ext.tree.TreePanel, { - rootVisible : false, - useArrows : true, - lines : false, - borderWidth : Ext.isBorderBox ? 0 : 2, // the combined left/right border for each cell - cls : 'x-treegrid', - - columnResize : true, - enableSort : true, - reserveScrollOffset : true, - enableHdMenu : true, - - columnsText : 'Columns', - - initComponent : function() { - if(!this.root) { - this.root = new Ext.tree.AsyncTreeNode({text: 'Root'}); - } - - // initialize the loader - var l = this.loader; - if(!l){ - l = new Ext.ux.tree.TreeGridLoader({ - dataUrl: this.dataUrl, - requestMethod: this.requestMethod, - store: this.store - }); - }else if(Ext.isObject(l) && !l.load){ - l = new Ext.ux.tree.TreeGridLoader(l); - } - else if(l) { - l.createNode = function(attr) { - if (!attr.uiProvider) { - attr.uiProvider = Ext.ux.tree.TreeGridNodeUI; - } - return Ext.tree.TreeLoader.prototype.createNode.call(this, attr); - } - } - this.loader = l; - - Ext.ux.tree.TreeGrid.superclass.initComponent.call(this); - - this.initColumns(); - - if(this.enableSort) { - this.treeGridSorter = new Ext.ux.tree.TreeGridSorter(this, this.enableSort); - } - - if(this.columnResize){ - this.colResizer = new Ext.tree.ColumnResizer(this.columnResize); - this.colResizer.init(this); - } - - var c = this.columns; - if(!this.internalTpl){ - this.internalTpl = new Ext.XTemplate( - '
', - '
', - '
', - '', - '', - '', - '', - '', - '
', - '
', - this.enableHdMenu ? '' : '', - '{header}', - '
', - '
', - '
', - '
', - '
', - '
', - '
' - ); - } - - if(!this.colgroupTpl) { - this.colgroupTpl = new Ext.XTemplate( - '' - ); - } - }, - - initColumns : function() { - var cs = this.columns, - len = cs.length, - columns = [], - i, c; - - for(i = 0; i < len; i++){ - c = cs[i]; - if(!c.isColumn) { - c.xtype = c.xtype ? (/^tg/.test(c.xtype) ? c.xtype : 'tg' + c.xtype) : 'tgcolumn'; - c = Ext.create(c); - } - c.init(this); - columns.push(c); - - if(this.enableSort !== false && c.sortable !== false) { - c.sortable = true; - this.enableSort = true; - } - } - - this.columns = columns; - }, - - onRender : function(){ - Ext.tree.TreePanel.superclass.onRender.apply(this, arguments); - - this.el.addClass('x-treegrid'); - - this.outerCt = this.body.createChild({ - cls:'x-tree-root-ct x-treegrid-ct ' + (this.useArrows ? 'x-tree-arrows' : this.lines ? 'x-tree-lines' : 'x-tree-no-lines') - }); - - this.internalTpl.overwrite(this.outerCt, {columns: this.columns}); - - this.mainHd = Ext.get(this.outerCt.dom.firstChild); - this.innerHd = Ext.get(this.mainHd.dom.firstChild); - this.innerBody = Ext.get(this.outerCt.dom.lastChild); - this.innerCt = Ext.get(this.innerBody.dom.firstChild); - - this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns}); - - if(this.hideHeaders){ - this.header.dom.style.display = 'none'; - } - else if(this.enableHdMenu !== false){ - this.hmenu = new Ext.menu.Menu({id: this.id + '-hctx'}); - if(this.enableColumnHide !== false){ - this.colMenu = new Ext.menu.Menu({id: this.id + '-hcols-menu'}); - this.colMenu.on({ - scope: this, - beforeshow: this.beforeColMenuShow, - itemclick: this.handleHdMenuClick - }); - this.hmenu.add({ - itemId:'columns', - hideOnClick: false, - text: this.columnsText, - menu: this.colMenu, - iconCls: 'x-cols-icon' - }); - } - this.hmenu.on('itemclick', this.handleHdMenuClick, this); - } - }, - - setRootNode : function(node){ - node.attributes.uiProvider = Ext.ux.tree.TreeGridRootNodeUI; - node = Ext.ux.tree.TreeGrid.superclass.setRootNode.call(this, node); - if(this.innerCt) { - this.colgroupTpl.insertFirst(this.innerCt, {columns: this.columns}); - } - return node; - }, - - initEvents : function() { - Ext.ux.tree.TreeGrid.superclass.initEvents.apply(this, arguments); - - this.mon(this.innerBody, 'scroll', this.syncScroll, this); - this.mon(this.innerHd, 'click', this.handleHdDown, this); - this.mon(this.mainHd, { - scope: this, - mouseover: this.handleHdOver, - mouseout: this.handleHdOut - }); - }, - - onResize : function(w, h) { - Ext.ux.tree.TreeGrid.superclass.onResize.apply(this, arguments); - - var bd = this.innerBody.dom; - var hd = this.innerHd.dom; - - if(!bd){ - return; - } - - if(Ext.isNumber(h)){ - bd.style.height = this.body.getHeight(true) - hd.offsetHeight + 'px'; - } - - if(Ext.isNumber(w)){ - var sw = Ext.num(this.scrollOffset, Ext.getScrollBarWidth()); - if(this.reserveScrollOffset || ((bd.offsetWidth - bd.clientWidth) > 10)){ - this.setScrollOffset(sw); - }else{ - var me = this; - setTimeout(function(){ - me.setScrollOffset(bd.offsetWidth - bd.clientWidth > 10 ? sw : 0); - }, 10); - } - } - }, - - updateColumnWidths : function() { - var cols = this.columns, - colCount = cols.length, - groups = this.outerCt.query('colgroup'), - groupCount = groups.length, - c, g, i, j; - - for(i = 0; i 0 && this.columns[index]) { - this.setColumnVisible(index, !item.checked); - } - } - - return true; - }, - - setColumnVisible : function(index, visible) { - this.columns[index].hidden = !visible; - this.updateColumnWidths(); - }, - - /** - * Scrolls the grid to the top - */ - scrollToTop : function(){ - this.innerBody.dom.scrollTop = 0; - this.innerBody.dom.scrollLeft = 0; - }, - - // private - syncScroll : function(){ - this.syncHeaderScroll(); - var mb = this.innerBody.dom; - this.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop); - }, - - // private - syncHeaderScroll : function(){ - var mb = this.innerBody.dom; - this.innerHd.dom.scrollLeft = mb.scrollLeft; - this.innerHd.dom.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore) - }, - - registerNode : function(n) { - Ext.ux.tree.TreeGrid.superclass.registerNode.call(this, n); - if(!n.uiProvider && !n.isRoot && !n.ui.isTreeGridNodeUI) { - n.ui = new Ext.ux.tree.TreeGridNodeUI(n); - } - } -}); - -Ext.reg('treegrid', Ext.ux.tree.TreeGrid); \ No newline at end of file diff --git a/deluge/ui/web/js/ext-extensions.js b/deluge/ui/web/js/ext-extensions.js index a24cf0557..d1ba552c0 100644 --- a/deluge/ui/web/js/ext-extensions.js +++ b/deluge/ui/web/js/ext-extensions.js @@ -1,59 +1,56 @@ +/* + * Ext.ux.layout.FormLayoutFix.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.override(Ext.layout.FormLayout,{renderItem:function(e,a,d){if(e&&!e.rendered&&(e.isFormField||e.fieldLabel)&&e.inputType!="hidden"){var b=this.getTemplateArgs(e);if(typeof a=="number"){a=d.dom.childNodes[a]||null}if(a){e.formItem=this.fieldTpl.insertBefore(a,b,true)}else{e.formItem=this.fieldTpl.append(d,b,true)}e.actionMode="formItem";e.render("x-form-el-"+e.id);e.container=e.formItem;e.actionMode="container"}else{Ext.layout.FormLayout.superclass.renderItem.apply(this,arguments)}}}); /* * Ext JS Library 3.1.0 * Copyright(c) 2006-2009 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license */ -Ext.ns("Ext.ux.grid");Ext.ux.grid.BufferView=Ext.extend(Ext.grid.GridView,{rowHeight:19,borderHeight:2,scrollDelay:100,cacheSize:20,cleanDelay:500,initTemplates:function(){Ext.ux.grid.BufferView.superclass.initTemplates.call(this);var a=this.templates;a.rowHolder=new Ext.Template('
');a.rowHolder.disableFormats=true;a.rowHolder.compile();a.rowBody=new Ext.Template('',"{cells}",(this.enableRowBody?'':""),"
{body}
");a.rowBody.disableFormats=true;a.rowBody.compile()},getStyleRowHeight:function(){return Ext.isBorderBox?(this.rowHeight+this.borderHeight):this.rowHeight},getCalculatedRowHeight:function(){return this.rowHeight+this.borderHeight},getVisibleRowCount:function(){var b=this.getCalculatedRowHeight();var a=this.scroller.dom.clientHeight;return(a<1)?0:Math.ceil(a/b)},getVisibleRows:function(){var a=this.getVisibleRowCount();var b=this.scroller.dom.scrollTop;var c=(b==0?0:Math.floor(b/this.getCalculatedRowHeight())-1);return{first:Math.max(c,0),last:Math.min(c+a+2,this.ds.getCount()-1)}},doRender:function(g,k,u,a,s,A,l){var b=this.templates,f=b.cell,h=b.row,x=b.rowBody,n=s-1;var t=this.getStyleRowHeight();var z=this.getVisibleRows();var d="width:"+this.getTotalWidth()+";height:"+t+"px;";var D=[],w,E,v={},m={tstyle:d},q;for(var y=0,C=k.length;y=z.first&&o<=z.last;if(e){for(var B=0;B0},syncScroll:function(){Ext.ux.grid.BufferView.superclass.syncScroll.apply(this,arguments);this.update()},update:function(){if(this.scrollDelay){if(!this.renderTask){this.renderTask=new Ext.util.DelayedTask(this.doUpdate,this)}this.renderTask.delay(this.scrollDelay)}else{this.doUpdate()}},onRemove:function(d,a,b,c){Ext.ux.grid.BufferView.superclass.onRemove.apply(this,arguments);if(c!==true){this.update()}},doUpdate:function(){if(this.getVisibleRowCount()>0){var f=this.grid,b=f.colModel,h=f.store;var e=this.getColumnData();var a=this.getVisibleRows();for(var d=a.first;d<=a.last;d++){if(!this.isRowRendered(d)){var c=this.doRender(e,[h.getAt(d)],h,d,b.getColumnCount(),f.stripeRows,true);this.getRow(d).innerHTML=c}}this.clean()}},clean:function(){if(!this.cleanTask){this.cleanTask=new Ext.util.DelayedTask(this.doClean,this)}this.cleanTask.delay(this.cleanDelay)},doClean:function(){if(this.getVisibleRowCount()>0){var b=this.getVisibleRows();b.first-=this.cacheSize;b.last+=this.cacheSize;var c=0,d=this.getRows();if(b.first<=0){c=b.last+1}for(var a=this.ds.getCount();cb.last)&&d[c].innerHTML){d[c].innerHTML=""}}}},layout:function(){Ext.ux.grid.BufferView.superclass.layout.call(this);this.update()}}); +Ext.ns("Ext.ux.tree");Ext.ux.tree.TreeGrid=Ext.extend(Ext.tree.TreePanel,{rootVisible:false,useArrows:true,lines:false,borderWidth:Ext.isBorderBox?0:2,cls:"x-treegrid",columnResize:true,enableSort:true,reserveScrollOffset:true,enableHdMenu:true,columnsText:"Columns",initComponent:function(){if(!this.root){this.root=new Ext.tree.AsyncTreeNode({text:"Root"})}var a=this.loader;if(!a){a=new Ext.ux.tree.TreeGridLoader({dataUrl:this.dataUrl,requestMethod:this.requestMethod,store:this.store})}else{if(Ext.isObject(a)&&!a.load){a=new Ext.ux.tree.TreeGridLoader(a)}else{if(a){a.createNode=function(c){if(!c.uiProvider){c.uiProvider=Ext.ux.tree.TreeGridNodeUI}return Ext.tree.TreeLoader.prototype.createNode.call(this,c)}}}}this.loader=a;Ext.ux.tree.TreeGrid.superclass.initComponent.call(this);this.initColumns();if(this.enableSort){this.treeGridSorter=new Ext.ux.tree.TreeGridSorter(this,this.enableSort)}if(this.columnResize){this.colResizer=new Ext.tree.ColumnResizer(this.columnResize);this.colResizer.init(this)}var b=this.columns;if(!this.internalTpl){this.internalTpl=new Ext.XTemplate('
','
','
','','','','","","
','
',this.enableHdMenu?'':"",'{header}',"
","
","
","
",'
','
',"
")}if(!this.colgroupTpl){this.colgroupTpl=new Ext.XTemplate('')}},initColumns:function(){var e=this.columns,a=e.length,d=[],b,f;for(b=0;b10)){this.setScrollOffset(a)}else{var d=this;setTimeout(function(){d.setScrollOffset(e.offsetWidth-e.clientWidth>10?a:0)},10)}}},updateColumnWidths:function(){var k=this.columns,m=k.length,a=this.outerCt.query("colgroup"),l=a.length,h,e,d,b;for(d=0;d0&&this.columns[a]){this.setColumnVisible(a,!b.checked)}}return true},setColumnVisible:function(a,b){this.columns[a].hidden=!b;this.updateColumnWidths()},scrollToTop:function(){this.innerBody.dom.scrollTop=0;this.innerBody.dom.scrollLeft=0},syncScroll:function(){this.syncHeaderScroll();var a=this.innerBody.dom;this.fireEvent("bodyscroll",a.scrollLeft,a.scrollTop)},syncHeaderScroll:function(){var a=this.innerBody.dom;this.innerHd.dom.scrollLeft=a.scrollLeft;this.innerHd.dom.scrollLeft=a.scrollLeft},registerNode:function(a){Ext.ux.tree.TreeGrid.superclass.registerNode.call(this,a);if(!a.uiProvider&&!a.isRoot&&!a.ui.isTreeGridNodeUI){a.ui=new Ext.ux.tree.TreeGridNodeUI(a)}}});Ext.reg("treegrid",Ext.ux.tree.TreeGrid); /* * Ext JS Library 3.1.0 * Copyright(c) 2006-2009 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license */ -Ext.ns("Ext.ux.form");Ext.ux.form.FileUploadField=Ext.extend(Ext.form.TextField,{buttonText:"Browse...",buttonOnly:false,buttonOffset:3,readOnly:true,autoSize:Ext.emptyFn,initComponent:function(){Ext.ux.form.FileUploadField.superclass.initComponent.call(this);this.addEvents("fileselected")},onRender:function(c,a){Ext.ux.form.FileUploadField.superclass.onRender.call(this,c,a);this.wrap=this.el.wrap({cls:"x-form-field-wrap x-form-file-wrap"});this.el.addClass("x-form-file-text");this.el.dom.removeAttribute("name");this.createFileInput();var b=Ext.applyIf(this.buttonCfg||{},{text:this.buttonText});this.button=new Ext.Button(Ext.apply(b,{renderTo:this.wrap,cls:"x-form-file-btn"+(b.iconCls?" x-btn-icon":"")}));if(this.buttonOnly){this.el.hide();this.wrap.setWidth(this.button.getEl().getWidth())}this.bindListeners();this.resizeEl=this.positionEl=this.wrap},bindListeners:function(){this.fileInput.on({scope:this,mouseenter:function(){this.button.addClass(["x-btn-over","x-btn-focus"])},mouseleave:function(){this.button.removeClass(["x-btn-over","x-btn-focus","x-btn-click"])},mousedown:function(){this.button.addClass("x-btn-click")},mouseup:function(){this.button.removeClass(["x-btn-over","x-btn-focus","x-btn-click"])},change:function(){var a=this.fileInput.dom.value;this.setValue(a);this.fireEvent("fileselected",this,a)}})},createFileInput:function(){this.fileInput=this.wrap.createChild({id:this.getFileInputId(),name:this.name||this.getId(),cls:"x-form-file",tag:"input",type:"file",size:1})},reset:function(){this.fileInput.remove();this.createFileInput();this.bindListeners();Ext.ux.form.FileUploadField.superclass.reset.call(this)},getFileInputId:function(){return this.id+"-file"},onResize:function(a,b){Ext.ux.form.FileUploadField.superclass.onResize.call(this,a,b);this.wrap.setWidth(a);if(!this.buttonOnly){var a=this.wrap.getWidth()-this.button.getEl().getWidth()-this.buttonOffset;this.el.setWidth(a)}},onDestroy:function(){Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);Ext.destroy(this.fileInput,this.button,this.wrap)},onDisable:function(){Ext.ux.form.FileUploadField.superclass.onDisable.call(this);this.doDisable(true)},onEnable:function(){Ext.ux.form.FileUploadField.superclass.onEnable.call(this);this.doDisable(false)},doDisable:function(a){this.fileInput.dom.disabled=a;this.button.setDisabled(a)},preFocus:Ext.emptyFn,alignErrorIcon:function(){this.errorIcon.alignTo(this.wrap,"tl-tr",[2,0])}});Ext.reg("fileuploadfield",Ext.ux.form.FileUploadField);Ext.form.FileUploadField=Ext.ux.form.FileUploadField;Ext.ux.JSLoader=function(options){Ext.ux.JSLoader.scripts[++Ext.ux.JSLoader.index]={url:options.url,success:true,jsLoadObj:null,options:options,onLoad:options.onLoad||Ext.emptyFn,onError:options.onError||Ext.ux.JSLoader.stdError,scope:options.scope||this};Ext.Ajax.request({url:options.url,scriptIndex:Ext.ux.JSLoader.index,success:function(response,options){var script=Ext.ux.JSLoader.scripts[options.scriptIndex];try{eval(response.responseText)}catch(e){script.success=false;script.onError(script.options,e)}if(script.success){script.onLoad.call(script.scope,script.options)}},failure:function(response,options){var script=Ext.ux.JSLoader.scripts[options.scriptIndex];script.success=false;script.onError(script.options,response.status)}})};Ext.ux.JSLoader.index=0;Ext.ux.JSLoader.scripts=[];Ext.ux.JSLoader.stdError=function(a,b){window.alert("Error loading script:\n\n"+a.url+"\n\nstatus: "+b)} +Ext.tree.ColumnResizer=Ext.extend(Ext.util.Observable,{minWidth:14,constructor:function(a){Ext.apply(this,a);Ext.tree.ColumnResizer.superclass.constructor.call(this)},init:function(a){this.tree=a;a.on("render",this.initEvents,this)},initEvents:function(a){a.mon(a.innerHd,"mousemove",this.handleHdMove,this);this.tracker=new Ext.dd.DragTracker({onBeforeStart:this.onBeforeStart.createDelegate(this),onStart:this.onStart.createDelegate(this),onDrag:this.onDrag.createDelegate(this),onEnd:this.onEnd.createDelegate(this),tolerance:3,autoStart:300});this.tracker.initEl(a.innerHd);a.on("beforedestroy",this.tracker.destroy,this.tracker)},handleHdMove:function(f,k){var g=5,j=f.getPageX(),d=f.getTarget(".x-treegrid-hd",3,true);if(d){var b=d.getRegion(),l=d.dom.style,c=d.dom.parentNode;if(j-b.left<=g&&d.dom!==c.firstChild){var a=d.dom.previousSibling;while(a&&Ext.fly(a).hasClass("x-treegrid-hd-hidden")){a=a.previousSibling}if(a){this.activeHd=Ext.get(a);l.cursor=Ext.isWebKit?"e-resize":"col-resize"}}else{if(b.right-j<=g){var h=d.dom;while(h&&Ext.fly(h).hasClass("x-treegrid-hd-hidden")){h=h.previousSibling}if(h){this.activeHd=Ext.get(h);l.cursor=Ext.isWebKit?"w-resize":"col-resize"}}else{delete this.activeHd;l.cursor=""}}}},onBeforeStart:function(a){this.dragHd=this.activeHd;return !!this.dragHd},onStart:function(b){this.tree.headersDisabled=true;this.proxy=this.tree.body.createChild({cls:"x-treegrid-resizer"});this.proxy.setHeight(this.tree.body.getHeight());var a=this.tracker.getXY()[0];this.hdX=this.dragHd.getX();this.hdIndex=this.tree.findHeaderIndex(this.dragHd);this.proxy.setX(this.hdX);this.proxy.setWidth(a-this.hdX);this.maxWidth=this.tree.outerCt.getWidth()-this.tree.innerBody.translatePoints(this.hdX).left},onDrag:function(b){var a=this.tracker.getXY()[0];this.proxy.setWidth((a-this.hdX).constrain(this.minWidth,this.maxWidth))},onEnd:function(c){var b=this.proxy.getWidth(),a=this.tree;this.proxy.remove();delete this.dragHd;a.columns[this.hdIndex].width=b;a.updateColumnWidths();setTimeout(function(){a.headersDisabled=false},100)}}); /* * Ext JS Library 3.1.0 * Copyright(c) 2006-2009 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license */ -;Ext.ux.Spinner=Ext.extend(Ext.util.Observable,{incrementValue:1,alternateIncrementValue:5,triggerClass:"x-form-spinner-trigger",splitterClass:"x-form-spinner-splitter",alternateKey:Ext.EventObject.shiftKey,defaultValue:0,accelerate:false,constructor:function(a){Ext.ux.Spinner.superclass.constructor.call(this,a);Ext.apply(this,a);this.mimicing=false},init:function(a){this.field=a;a.afterMethod("onRender",this.doRender,this);a.afterMethod("onEnable",this.doEnable,this);a.afterMethod("onDisable",this.doDisable,this);a.afterMethod("afterRender",this.doAfterRender,this);a.afterMethod("onResize",this.doResize,this);a.afterMethod("onFocus",this.doFocus,this);a.beforeMethod("onDestroy",this.doDestroy,this)},doRender:function(b,a){var c=this.el=this.field.getEl();var d=this.field;if(!d.wrap){d.wrap=this.wrap=c.wrap({cls:"x-form-field-wrap"})}else{this.wrap=d.wrap.addClass("x-form-field-wrap")}this.trigger=this.wrap.createChild({tag:"img",src:Ext.BLANK_IMAGE_URL,cls:"x-form-trigger "+this.triggerClass});if(!d.width){this.wrap.setWidth(c.getWidth()+this.trigger.getWidth())}this.splitter=this.wrap.createChild({tag:"div",cls:this.splitterClass,style:"width:13px; height:2px;"});this.splitter.setRight((Ext.isIE)?1:2).setTop(10).show();this.proxy=this.trigger.createProxy("",this.splitter,true);this.proxy.addClass("x-form-spinner-proxy");this.proxy.setStyle("left","0px");this.proxy.setSize(14,1);this.proxy.hide();this.dd=new Ext.dd.DDProxy(this.splitter.dom.id,"SpinnerDrag",{dragElId:this.proxy.id});this.initTrigger();this.initSpinner()},doAfterRender:function(){var a;if(Ext.isIE&&this.el.getY()!=(a=this.trigger.getY())){this.el.position();this.el.setY(a)}},doEnable:function(){if(this.wrap){this.wrap.removeClass(this.field.disabledClass)}},doDisable:function(){if(this.wrap){this.wrap.addClass(this.field.disabledClass);this.el.removeClass(this.field.disabledClass)}},doResize:function(a,b){if(typeof a=="number"){this.el.setWidth(a-this.trigger.getWidth())}this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth())},doFocus:function(){if(!this.mimicing){this.wrap.addClass("x-trigger-wrap-focus");this.mimicing=true;Ext.get(Ext.isIE?document.body:document).on("mousedown",this.mimicBlur,this,{delay:10});this.el.on("keydown",this.checkTab,this)}},checkTab:function(a){if(a.getKey()==a.TAB){this.triggerBlur()}},mimicBlur:function(a){if(!this.wrap.contains(a.target)&&this.field.validateBlur(a)){this.triggerBlur()}},triggerBlur:function(){this.mimicing=false;Ext.get(Ext.isIE?document.body:document).un("mousedown",this.mimicBlur,this);this.el.un("keydown",this.checkTab,this);this.field.beforeBlur();this.wrap.removeClass("x-trigger-wrap-focus");this.field.onBlur.call(this.field)},initTrigger:function(){this.trigger.addClassOnOver("x-form-trigger-over");this.trigger.addClassOnClick("x-form-trigger-click")},initSpinner:function(){this.field.addEvents({spin:true,spinup:true,spindown:true});this.keyNav=new Ext.KeyNav(this.el,{up:function(a){a.preventDefault();this.onSpinUp()},down:function(a){a.preventDefault();this.onSpinDown()},pageUp:function(a){a.preventDefault();this.onSpinUpAlternate()},pageDown:function(a){a.preventDefault();this.onSpinDownAlternate()},scope:this});this.repeater=new Ext.util.ClickRepeater(this.trigger,{accelerate:this.accelerate});this.field.mon(this.repeater,"click",this.onTriggerClick,this,{preventDefault:true});this.field.mon(this.trigger,{mouseover:this.onMouseOver,mouseout:this.onMouseOut,mousemove:this.onMouseMove,mousedown:this.onMouseDown,mouseup:this.onMouseUp,scope:this,preventDefault:true});this.field.mon(this.wrap,"mousewheel",this.handleMouseWheel,this);this.dd.setXConstraint(0,0,10);this.dd.setYConstraint(1500,1500,10);this.dd.endDrag=this.endDrag.createDelegate(this);this.dd.startDrag=this.startDrag.createDelegate(this);this.dd.onDrag=this.onDrag.createDelegate(this)},onMouseOver:function(){if(this.disabled){return}var a=this.getMiddle();this.tmpHoverClass=(Ext.EventObject.getPageY()a)&&this.tmpHoverClass=="x-form-spinner-overup")||((Ext.EventObject.getPageY()0){this.onSpinUp();a.stopEvent()}else{if(b<0){this.onSpinDown();a.stopEvent()}}},startDrag:function(){this.proxy.show();this._previousY=Ext.fly(this.dd.getDragEl()).getTop()},endDrag:function(){this.proxy.hide()},onDrag:function(){if(this.disabled){return}var b=Ext.fly(this.dd.getDragEl()).getTop();var a="";if(this._previousY>b){a="Up"}if(this._previousYthis.field.maxValue){a=this.field.maxValue}return this.fixPrecision(a)},fixPrecision:function(b){var a=isNaN(b);if(!this.field.allowDecimals||this.field.decimalPrecision==-1||a||!b){return a?"":b}return parseFloat(parseFloat(b).toFixed(this.field.decimalPrecision))},doDestroy:function(){if(this.trigger){this.trigger.remove()}if(this.wrap){this.wrap.remove();delete this.field.wrap}if(this.splitter){this.splitter.remove()}if(this.dd){this.dd.unreg();this.dd=null}if(this.proxy){this.proxy.remove()}if(this.repeater){this.repeater.purgeListeners()}}});Ext.form.Spinner=Ext.ux.Spinner; -/* - * Ext JS Library 3.1.0 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license - */ -Ext.ns("Ext.ux.form");Ext.ux.form.SpinnerField=Ext.extend(Ext.form.NumberField,{actionMode:"wrap",deferHeight:true,autoSize:Ext.emptyFn,onBlur:Ext.emptyFn,adjustSize:Ext.BoxComponent.prototype.adjustSize,constructor:function(c){var b=Ext.copyTo({},c,"incrementValue,alternateIncrementValue,accelerate,defaultValue,triggerClass,splitterClass");var d=this.spinner=new Ext.ux.Spinner(b);var a=c.plugins?(Ext.isArray(c.plugins)?c.plugins.push(d):[c.plugins,d]):d;Ext.ux.form.SpinnerField.superclass.constructor.call(this,Ext.apply(c,{plugins:a}))},getResizeEl:function(){return this.wrap},getPositionEl:function(){return this.wrap},alignErrorIcon:function(){if(this.wrap){this.errorIcon.alignTo(this.wrap,"tl-tr",[2,0])}},validateBlur:function(){return true}});Ext.reg("spinnerfield",Ext.ux.form.SpinnerField);Ext.form.SpinnerField=Ext.ux.form.SpinnerField; -/* - * Ext JS Library 3.1.0 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license - */ -Ext.ux.StatusBar=Ext.extend(Ext.Toolbar,{cls:"x-statusbar",busyIconCls:"x-status-busy",busyText:"Loading...",autoClear:5000,emptyText:" ",activeThreadId:0,initComponent:function(){if(this.statusAlign=="right"){this.cls+=" x-status-right"}Ext.ux.StatusBar.superclass.initComponent.call(this)},afterRender:function(){Ext.ux.StatusBar.superclass.afterRender.call(this);var a=this.statusAlign=="right";this.currIconCls=this.iconCls||this.defaultIconCls;this.statusEl=new Ext.Toolbar.TextItem({cls:"x-status-text "+(this.currIconCls||""),text:this.text||this.defaultText||""});if(a){this.add("->");this.add(this.statusEl)}else{this.insert(0,this.statusEl);this.insert(1,"->")}},setStatus:function(d){d=d||{};if(typeof d=="string"){d={text:d}}if(d.text!==undefined){this.setText(d.text)}if(d.iconCls!==undefined){this.setIcon(d.iconCls)}if(d.clear){var e=d.clear,b=this.autoClear,a={useDefaults:true,anim:true};if(typeof e=="object"){e=Ext.applyIf(e,a);if(e.wait){b=e.wait}}else{if(typeof e=="number"){b=e;e=a}else{if(typeof e=="boolean"){e=a}}}e.threadId=this.activeThreadId;this.clearStatus.defer(b,this,[e])}return this},clearStatus:function(c){c=c||{};if(c.threadId&&c.threadId!==this.activeThreadId){return this}var b=c.useDefaults?this.defaultText:this.emptyText,a=c.useDefaults?(this.defaultIconCls?this.defaultIconCls:""):"";if(c.anim){this.statusEl.el.fadeOut({remove:false,useDisplay:true,scope:this,callback:function(){this.setStatus({text:b,iconCls:a});this.statusEl.el.show()}})}else{this.statusEl.hide();this.setStatus({text:b,iconCls:a});this.statusEl.show()}return this},setText:function(a){this.activeThreadId++;this.text=a||"";if(this.rendered){this.statusEl.setText(this.text)}return this},getText:function(){return this.text},setIcon:function(a){this.activeThreadId++;a=a||"";if(this.rendered){if(this.currIconCls){this.statusEl.removeClass(this.currIconCls);this.currIconCls=null}if(a.length>0){this.statusEl.addClass(a);this.currIconCls=a}}else{this.currIconCls=a}return this},showBusy:function(a){if(typeof a=="string"){a={text:a}}a=Ext.applyIf(a||{},{text:this.busyText,iconCls:this.busyIconCls});return this.setStatus(a)}});Ext.reg("statusbar",Ext.ux.StatusBar);Ext.namespace("Ext.ux.form");Ext.ux.form.ToggleField=Ext.extend(Ext.form.Field,{cls:"x-toggle-field",initComponent:function(){Ext.ux.form.ToggleField.superclass.initComponent.call(this);this.toggle=new Ext.form.Checkbox();this.toggle.on("check",this.onToggleCheck,this);this.input=new Ext.form.TextField({disabled:true})},onRender:function(b,a){if(!this.el){this.panel=new Ext.Panel({cls:this.groupCls,layout:"table",layoutConfig:{columns:2},border:false,renderTo:b});this.panel.ownerCt=this;this.el=this.panel.getEl();this.panel.add(this.toggle);this.panel.add(this.input);this.panel.doLayout();this.toggle.getEl().parent().setStyle("padding-right","10px")}Ext.ux.form.ToggleField.superclass.onRender.call(this,b,a)},onResize:function(a,b){this.panel.setSize(a,b);this.panel.doLayout();var c=a-this.toggle.getSize().width-10;this.input.setSize(c,b)},onToggleCheck:function(a,b){this.input.setDisabled(!b)}});Ext.reg("togglefield",Ext.ux.form.ToggleField); -/* - * Ext JS Library 3.1.0 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license - */ -Ext.ns("Ext.ux.tree");Ext.ux.tree.TreeGridSorter=Ext.extend(Ext.tree.TreeSorter,{sortClasses:["sort-asc","sort-desc"],sortAscText:"Sort Ascending",sortDescText:"Sort Descending",constructor:function(a,b){if(!Ext.isObject(b)){b={property:a.columns[0].dataIndex||"text",folderSort:true}}Ext.ux.tree.TreeGridSorter.superclass.constructor.apply(this,arguments);this.tree=a;a.on("headerclick",this.onHeaderClick,this);a.ddAppendOnly=true;me=this;this.defaultSortFn=function(j,i){var f=me.dir&&me.dir.toLowerCase()=="desc";var c=me.property||"text";var e=me.sortType;var g=me.folderSort;var h=me.caseSensitive===true;var d=me.leafAttr||"leaf";if(g){if(j.attributes[d]&&!i.attributes[d]){return 1}if(!j.attributes[d]&&i.attributes[d]){return -1}}var l=e?e(j.attributes[c]):(h?j.attributes[c]:j.attributes[c].toUpperCase());var k=e?e(i.attributes[c]):(h?i.attributes[c]:i.attributes[c].toUpperCase());if(lk){return f?-1:+1}else{return 0}}};a.on("afterrender",this.onAfterTreeRender,this,{single:true});a.on("headermenuclick",this.onHeaderMenuClick,this)},onAfterTreeRender:function(){var a=this.tree.hmenu;a.insert(0,{itemId:"asc",text:this.sortAscText,cls:"xg-hmenu-sort-asc"},{itemId:"desc",text:this.sortDescText,cls:"xg-hmenu-sort-desc"});this.updateSortIcon(0,"asc")},onHeaderMenuClick:function(d,b,a){if(b==="asc"||b==="desc"){this.onHeaderClick(d,null,a);return false}},onHeaderClick:function(e,b,a){if(e&&!this.tree.headersDisabled){var d=this;d.property=e.dataIndex;d.dir=e.dir=(e.dir==="desc"?"asc":"desc");d.sortType=e.sortType;d.caseSensitive===Ext.isBoolean(e.caseSensitive)?e.caseSensitive:this.caseSensitive;d.sortFn=e.sortFn||this.defaultSortFn;this.tree.root.cascade(function(c){if(!c.isLeaf()){d.updateSort(d.tree,c)}});this.updateSortIcon(a,e.dir)}},updateSortIcon:function(b,a){var d=this.sortClasses;var c=this.tree.innerHd.select("td").removeClass(d);c.item(b).addClass(d[a=="desc"?1:0])}}); -/* - * Ext JS Library 3.1.0 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license - */ -Ext.tree.ColumnResizer=Ext.extend(Ext.util.Observable,{minWidth:14,constructor:function(a){Ext.apply(this,a);Ext.tree.ColumnResizer.superclass.constructor.call(this)},init:function(a){this.tree=a;a.on("render",this.initEvents,this)},initEvents:function(a){a.mon(a.innerHd,"mousemove",this.handleHdMove,this);this.tracker=new Ext.dd.DragTracker({onBeforeStart:this.onBeforeStart.createDelegate(this),onStart:this.onStart.createDelegate(this),onDrag:this.onDrag.createDelegate(this),onEnd:this.onEnd.createDelegate(this),tolerance:3,autoStart:300});this.tracker.initEl(a.innerHd);a.on("beforedestroy",this.tracker.destroy,this.tracker)},handleHdMove:function(f,j){var g=5,i=f.getPageX(),d=f.getTarget(".x-treegrid-hd",3,true);if(d){var b=d.getRegion(),k=d.dom.style,c=d.dom.parentNode;if(i-b.left<=g&&d.dom!==c.firstChild){var a=d.dom.previousSibling;while(a&&Ext.fly(a).hasClass("x-treegrid-hd-hidden")){a=a.previousSibling}if(a){this.activeHd=Ext.get(a);k.cursor=Ext.isWebKit?"e-resize":"col-resize"}}else{if(b.right-i<=g){var h=d.dom;while(h&&Ext.fly(h).hasClass("x-treegrid-hd-hidden")){h=h.previousSibling}if(h){this.activeHd=Ext.get(h);k.cursor=Ext.isWebKit?"w-resize":"col-resize"}}else{delete this.activeHd;k.cursor=""}}}},onBeforeStart:function(a){this.dragHd=this.activeHd;return !!this.dragHd},onStart:function(b){this.tree.headersDisabled=true;this.proxy=this.tree.body.createChild({cls:"x-treegrid-resizer"});this.proxy.setHeight(this.tree.body.getHeight());var a=this.tracker.getXY()[0];this.hdX=this.dragHd.getX();this.hdIndex=this.tree.findHeaderIndex(this.dragHd);this.proxy.setX(this.hdX);this.proxy.setWidth(a-this.hdX);this.maxWidth=this.tree.outerCt.getWidth()-this.tree.innerBody.translatePoints(this.hdX).left},onDrag:function(b){var a=this.tracker.getXY()[0];this.proxy.setWidth((a-this.hdX).constrain(this.minWidth,this.maxWidth))},onEnd:function(c){var b=this.proxy.getWidth(),a=this.tree;this.proxy.remove();delete this.dragHd;a.columns[this.hdIndex].width=b;a.updateColumnWidths();setTimeout(function(){a.headersDisabled=false},100)}}); -/* - * Ext JS Library 3.1.0 - * Copyright(c) 2006-2009 Ext JS, LLC - * licensing@extjs.com - * http://www.extjs.com/license - */ -Ext.ux.tree.TreeGridNodeUI=Ext.extend(Ext.tree.TreeNodeUI,{isTreeGridNodeUI:true,renderElements:function(d,l,h,m){var o=d.getOwnerTree(),k=o.columns,j=k[0],e,b,g;this.indentMarkup=d.parentNode?d.parentNode.ui.getChildIndent():"";b=['','','','',this.indentMarkup,"",'','','",'',(j.tpl?j.tpl.apply(l):l[j.dataIndex]||j.text),"",""];for(e=1,g=k.length;e','
",(j.tpl?j.tpl.apply(l):l[j.dataIndex]),"
","")}b.push('','');for(e=0,g=k.length;e')}b.push("");if(m!==true&&d.nextSibling&&d.nextSibling.ui.getEl()){this.wrap=Ext.DomHelper.insertHtml("beforeBegin",d.nextSibling.ui.getEl(),b.join(""))}else{this.wrap=Ext.DomHelper.insertHtml("beforeEnd",h,b.join(""))}this.elNode=this.wrap.childNodes[0];this.ctNode=this.wrap.childNodes[1].firstChild.firstChild;var f=this.elNode.firstChild.childNodes;this.indentNode=f[0];this.ecNode=f[1];this.iconNode=f[2];this.anchor=f[3];this.textNode=f[3].firstChild},animExpand:function(a){this.ctNode.style.display="";Ext.ux.tree.TreeGridNodeUI.superclass.animExpand.call(this,a)}});Ext.ux.tree.TreeGridRootNodeUI=Ext.extend(Ext.tree.TreeNodeUI,{isTreeGridNodeUI:true,render:function(){if(!this.rendered){this.wrap=this.ctNode=this.node.ownerTree.innerCt.dom;this.node.expanded=true}if(Ext.isWebKit){var a=this.ctNode;a.style.tableLayout=null;(function(){a.style.tableLayout="fixed"}).defer(1)}},destroy:function(){if(this.elNode){Ext.dd.Registry.unregister(this.elNode.id)}delete this.node},collapse:Ext.emptyFn,expand:Ext.emptyFn}); +(function(){Ext.override(Ext.list.Column,{init:function(){if(!this.type){this.type="auto"}var a=Ext.data.SortTypes;if(typeof this.sortType=="string"){this.sortType=a[this.sortType]}if(!this.sortType){switch(this.type){case"string":this.sortType=a.asUCString;break;case"date":this.sortType=a.asDate;break;default:this.sortType=a.none}}}});Ext.tree.Column=Ext.extend(Ext.list.Column,{});Ext.tree.NumberColumn=Ext.extend(Ext.list.NumberColumn,{});Ext.tree.DateColumn=Ext.extend(Ext.list.DateColumn,{});Ext.tree.BooleanColumn=Ext.extend(Ext.list.BooleanColumn,{});Ext.reg("tgcolumn",Ext.tree.Column);Ext.reg("tgnumbercolumn",Ext.tree.NumberColumn);Ext.reg("tgdatecolumn",Ext.tree.DateColumn);Ext.reg("tgbooleancolumn",Ext.tree.BooleanColumn)})(); /* * Ext JS Library 3.1.0 * Copyright(c) 2006-2009 Ext JS, LLC @@ -67,11 +64,174 @@ Ext.ux.tree.TreeGridLoader=Ext.extend(Ext.tree.TreeLoader,{createNode:function(a * licensing@extjs.com * http://www.extjs.com/license */ -(function(){Ext.override(Ext.list.Column,{init:function(){if(!this.type){this.type="auto"}var a=Ext.data.SortTypes;if(typeof this.sortType=="string"){this.sortType=a[this.sortType]}if(!this.sortType){switch(this.type){case"string":this.sortType=a.asUCString;break;case"date":this.sortType=a.asDate;break;default:this.sortType=a.none}}}});Ext.tree.Column=Ext.extend(Ext.list.Column,{});Ext.tree.NumberColumn=Ext.extend(Ext.list.NumberColumn,{});Ext.tree.DateColumn=Ext.extend(Ext.list.DateColumn,{});Ext.tree.BooleanColumn=Ext.extend(Ext.list.BooleanColumn,{});Ext.reg("tgcolumn",Ext.tree.Column);Ext.reg("tgnumbercolumn",Ext.tree.NumberColumn);Ext.reg("tgdatecolumn",Ext.tree.DateColumn);Ext.reg("tgbooleancolumn",Ext.tree.BooleanColumn)})();Ext.tree.RenderColumn=Ext.extend(Ext.tree.Column,{constructor:function(a){a.tpl=a.tpl||new Ext.XTemplate("{"+a.dataIndex+":this.format}");a.tpl.format=a.renderer;a.tpl.col=this;Ext.tree.RenderColumn.superclass.constructor.call(this,a)}});Ext.reg("tgrendercolumn",Ext.tree.RenderColumn); +Ext.ux.tree.TreeGridNodeUI=Ext.extend(Ext.tree.TreeNodeUI,{isTreeGridNodeUI:true,renderElements:function(d,l,h,m){var o=d.getOwnerTree(),k=o.columns,j=k[0],e,b,g;this.indentMarkup=d.parentNode?d.parentNode.ui.getChildIndent():"";b=['','','','',this.indentMarkup,"",'','','",'',(j.tpl?j.tpl.apply(l):l[j.dataIndex]||j.text),"",""];for(e=1,g=k.length;e','
",(j.tpl?j.tpl.apply(l):l[j.dataIndex]),"
","")}b.push('','');for(e=0,g=k.length;e')}b.push("");if(m!==true&&d.nextSibling&&d.nextSibling.ui.getEl()){this.wrap=Ext.DomHelper.insertHtml("beforeBegin",d.nextSibling.ui.getEl(),b.join(""))}else{this.wrap=Ext.DomHelper.insertHtml("beforeEnd",h,b.join(""))}this.elNode=this.wrap.childNodes[0];this.ctNode=this.wrap.childNodes[1].firstChild.firstChild;var f=this.elNode.firstChild.childNodes;this.indentNode=f[0];this.ecNode=f[1];this.iconNode=f[2];this.anchor=f[3];this.textNode=f[3].firstChild},animExpand:function(a){this.ctNode.style.display="";Ext.ux.tree.TreeGridNodeUI.superclass.animExpand.call(this,a)}});Ext.ux.tree.TreeGridRootNodeUI=Ext.extend(Ext.tree.TreeNodeUI,{isTreeGridNodeUI:true,render:function(){if(!this.rendered){this.wrap=this.ctNode=this.node.ownerTree.innerCt.dom;this.node.expanded=true}if(Ext.isWebKit){var a=this.ctNode;a.style.tableLayout=null;(function(){a.style.tableLayout="fixed"}).defer(1)}},destroy:function(){if(this.elNode){Ext.dd.Registry.unregister(this.elNode.id)}delete this.node},collapse:Ext.emptyFn,expand:Ext.emptyFn}); +/* + * Ext.ux.tree.TreeGridNodeUIFix.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.override(Ext.ux.tree.TreeGridNodeUI,{updateColumns:function(){if(!this.rendered){return}var b=this.node.attributes,d=this.node.getOwnerTree(),e=d.columns,f=e[0];this.anchor.firstChild.innerHTML=(f.tpl?f.tpl.apply(b):b[f.dataIndex]||f.text);for(i=1,len=e.length;i','
','
','','','','","","
','
',this.enableHdMenu?'':"",'{header}',"
","
","
","",'
','
',"
")}if(!this.colgroupTpl){this.colgroupTpl=new Ext.XTemplate('')}},initColumns:function(){var e=this.columns,a=e.length,d=[],b,f;for(b=0;b10)){this.setScrollOffset(a)}else{var d=this;setTimeout(function(){d.setScrollOffset(e.offsetWidth-e.clientWidth>10?a:0)},10)}}},updateColumnWidths:function(){var k=this.columns,m=k.length,a=this.outerCt.query("colgroup"),l=a.length,h,e,d,b;for(d=0;d0&&this.columns[a]){this.setColumnVisible(a,!b.checked)}}return true},setColumnVisible:function(a,b){this.columns[a].hidden=!b;this.updateColumnWidths()},scrollToTop:function(){this.innerBody.dom.scrollTop=0;this.innerBody.dom.scrollLeft=0},syncScroll:function(){this.syncHeaderScroll();var a=this.innerBody.dom;this.fireEvent("bodyscroll",a.scrollLeft,a.scrollTop)},syncHeaderScroll:function(){var a=this.innerBody.dom;this.innerHd.dom.scrollLeft=a.scrollLeft;this.innerHd.dom.scrollLeft=a.scrollLeft},registerNode:function(a){Ext.ux.tree.TreeGrid.superclass.registerNode.call(this,a);if(!a.uiProvider&&!a.isRoot&&!a.ui.isTreeGridNodeUI){a.ui=new Ext.ux.tree.TreeGridNodeUI(a)}}});Ext.reg("treegrid",Ext.ux.tree.TreeGrid); \ No newline at end of file +Ext.ns("Ext.ux.tree");Ext.ux.tree.TreeGridSorter=Ext.extend(Ext.tree.TreeSorter,{sortClasses:["sort-asc","sort-desc"],sortAscText:"Sort Ascending",sortDescText:"Sort Descending",constructor:function(a,b){if(!Ext.isObject(b)){b={property:a.columns[0].dataIndex||"text",folderSort:true}}Ext.ux.tree.TreeGridSorter.superclass.constructor.apply(this,arguments);this.tree=a;a.on("headerclick",this.onHeaderClick,this);a.ddAppendOnly=true;me=this;this.defaultSortFn=function(k,j){var f=me.dir&&me.dir.toLowerCase()=="desc";var c=me.property||"text";var e=me.sortType;var g=me.folderSort;var h=me.caseSensitive===true;var d=me.leafAttr||"leaf";if(g){if(k.attributes[d]&&!j.attributes[d]){return 1}if(!k.attributes[d]&&j.attributes[d]){return -1}}var m=e?e(k.attributes[c]):(h?k.attributes[c]:k.attributes[c].toUpperCase());var l=e?e(j.attributes[c]):(h?j.attributes[c]:j.attributes[c].toUpperCase());if(ml){return f?-1:+1}else{return 0}}};a.on("afterrender",this.onAfterTreeRender,this,{single:true});a.on("headermenuclick",this.onHeaderMenuClick,this)},onAfterTreeRender:function(){var a=this.tree.hmenu;a.insert(0,{itemId:"asc",text:this.sortAscText,cls:"xg-hmenu-sort-asc"},{itemId:"desc",text:this.sortDescText,cls:"xg-hmenu-sort-desc"});this.updateSortIcon(0,"asc")},onHeaderMenuClick:function(d,b,a){if(b==="asc"||b==="desc"){this.onHeaderClick(d,null,a);return false}},onHeaderClick:function(e,b,a){if(e&&!this.tree.headersDisabled){var d=this;d.property=e.dataIndex;d.dir=e.dir=(e.dir==="desc"?"asc":"desc");d.sortType=e.sortType;d.caseSensitive===Ext.isBoolean(e.caseSensitive)?e.caseSensitive:this.caseSensitive;d.sortFn=e.sortFn||this.defaultSortFn;this.tree.root.cascade(function(c){if(!c.isLeaf()){d.updateSort(d.tree,c)}});this.updateSortIcon(a,e.dir)}},updateSortIcon:function(b,a){var d=this.sortClasses;var c=this.tree.innerHd.select("td").removeClass(d);c.item(b).addClass(d[a=="desc"?1:0])}}); +/* + * Ext JS Library 3.1.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +Ext.ns("Ext.ux.grid");Ext.ux.grid.BufferView=Ext.extend(Ext.grid.GridView,{rowHeight:19,borderHeight:2,scrollDelay:100,cacheSize:20,cleanDelay:500,initTemplates:function(){Ext.ux.grid.BufferView.superclass.initTemplates.call(this);var a=this.templates;a.rowHolder=new Ext.Template('
');a.rowHolder.disableFormats=true;a.rowHolder.compile();a.rowBody=new Ext.Template('',"{cells}",(this.enableRowBody?'':""),"
{body}
");a.rowBody.disableFormats=true;a.rowBody.compile()},getStyleRowHeight:function(){return Ext.isBorderBox?(this.rowHeight+this.borderHeight):this.rowHeight},getCalculatedRowHeight:function(){return this.rowHeight+this.borderHeight},getVisibleRowCount:function(){var b=this.getCalculatedRowHeight();var a=this.scroller.dom.clientHeight;return(a<1)?0:Math.ceil(a/b)},getVisibleRows:function(){var a=this.getVisibleRowCount();var b=this.scroller.dom.scrollTop;var c=(b==0?0:Math.floor(b/this.getCalculatedRowHeight())-1);return{first:Math.max(c,0),last:Math.min(c+a+2,this.ds.getCount()-1)}},doRender:function(g,k,u,a,s,A,l){var b=this.templates,f=b.cell,h=b.row,x=b.rowBody,n=s-1;var t=this.getStyleRowHeight();var z=this.getVisibleRows();var d="width:"+this.getTotalWidth()+";height:"+t+"px;";var D=[],w,E,v={},m={tstyle:d},q;for(var y=0,C=k.length;y=z.first&&o<=z.last;if(e){for(var B=0;B0},syncScroll:function(){Ext.ux.grid.BufferView.superclass.syncScroll.apply(this,arguments);this.update()},update:function(){if(this.scrollDelay){if(!this.renderTask){this.renderTask=new Ext.util.DelayedTask(this.doUpdate,this)}this.renderTask.delay(this.scrollDelay)}else{this.doUpdate()}},onRemove:function(d,a,b,c){Ext.ux.grid.BufferView.superclass.onRemove.apply(this,arguments);if(c!==true){this.update()}},doUpdate:function(){if(this.getVisibleRowCount()>0){var f=this.grid,b=f.colModel,h=f.store;var e=this.getColumnData();var a=this.getVisibleRows();for(var d=a.first;d<=a.last;d++){if(!this.isRowRendered(d)){var c=this.doRender(e,[h.getAt(d)],h,d,b.getColumnCount(),f.stripeRows,true);this.getRow(d).innerHTML=c}}this.clean()}},clean:function(){if(!this.cleanTask){this.cleanTask=new Ext.util.DelayedTask(this.doClean,this)}this.cleanTask.delay(this.cleanDelay)},doClean:function(){if(this.getVisibleRowCount()>0){var b=this.getVisibleRows();b.first-=this.cacheSize;b.last+=this.cacheSize;var c=0,d=this.getRows();if(b.first<=0){c=b.last+1}for(var a=this.ds.getCount();cb.last)&&d[c].innerHTML){d[c].innerHTML=""}}}},layout:function(){Ext.ux.grid.BufferView.superclass.layout.call(this);this.update()}}); +/* + * Ext JS Library 3.1.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +Ext.ns("Ext.ux.form");Ext.ux.form.FileUploadField=Ext.extend(Ext.form.TextField,{buttonText:"Browse...",buttonOnly:false,buttonOffset:3,readOnly:true,autoSize:Ext.emptyFn,initComponent:function(){Ext.ux.form.FileUploadField.superclass.initComponent.call(this);this.addEvents("fileselected")},onRender:function(c,a){Ext.ux.form.FileUploadField.superclass.onRender.call(this,c,a);this.wrap=this.el.wrap({cls:"x-form-field-wrap x-form-file-wrap"});this.el.addClass("x-form-file-text");this.el.dom.removeAttribute("name");this.createFileInput();var b=Ext.applyIf(this.buttonCfg||{},{text:this.buttonText});this.button=new Ext.Button(Ext.apply(b,{renderTo:this.wrap,cls:"x-form-file-btn"+(b.iconCls?" x-btn-icon":"")}));if(this.buttonOnly){this.el.hide();this.wrap.setWidth(this.button.getEl().getWidth())}this.bindListeners();this.resizeEl=this.positionEl=this.wrap},bindListeners:function(){this.fileInput.on({scope:this,mouseenter:function(){this.button.addClass(["x-btn-over","x-btn-focus"])},mouseleave:function(){this.button.removeClass(["x-btn-over","x-btn-focus","x-btn-click"])},mousedown:function(){this.button.addClass("x-btn-click")},mouseup:function(){this.button.removeClass(["x-btn-over","x-btn-focus","x-btn-click"])},change:function(){var a=this.fileInput.dom.value;this.setValue(a);this.fireEvent("fileselected",this,a)}})},createFileInput:function(){this.fileInput=this.wrap.createChild({id:this.getFileInputId(),name:this.name||this.getId(),cls:"x-form-file",tag:"input",type:"file",size:1})},reset:function(){this.fileInput.remove();this.createFileInput();this.bindListeners();Ext.ux.form.FileUploadField.superclass.reset.call(this)},getFileInputId:function(){return this.id+"-file"},onResize:function(a,b){Ext.ux.form.FileUploadField.superclass.onResize.call(this,a,b);this.wrap.setWidth(a);if(!this.buttonOnly){var a=this.wrap.getWidth()-this.button.getEl().getWidth()-this.buttonOffset;this.el.setWidth(a)}},onDestroy:function(){Ext.ux.form.FileUploadField.superclass.onDestroy.call(this);Ext.destroy(this.fileInput,this.button,this.wrap)},onDisable:function(){Ext.ux.form.FileUploadField.superclass.onDisable.call(this);this.doDisable(true)},onEnable:function(){Ext.ux.form.FileUploadField.superclass.onEnable.call(this);this.doDisable(false)},doDisable:function(a){this.fileInput.dom.disabled=a;this.button.setDisabled(a)},preFocus:Ext.emptyFn,alignErrorIcon:function(){this.errorIcon.alignTo(this.wrap,"tl-tr",[2,0])}});Ext.reg("fileuploadfield",Ext.ux.form.FileUploadField);Ext.form.FileUploadField=Ext.ux.form.FileUploadField; +/* + * Ext.ux.form.RadioGroup.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.override(Ext.form.RadioGroup,{afterRender:function(){this.items.each(function(a){this.relayEvents(a,["check"])},this);if(this.lazyValue){this.setValue(this.value);delete this.value;delete this.lazyValue}Ext.form.RadioGroup.superclass.afterRender.call(this)},getName:function(){return this.items.first().getName()},getValue:function(){return this.items.first().getGroupValue()},setValue:function(a){if(!this.items.each){this.value=a;this.lazyValue=true;return}this.items.each(function(c){if(c.rendered){var b=(c.el.getValue()==String(a));c.el.dom.checked=b;c.el.dom.defaultChecked=b;c.wrap[b?"addClass":"removeClass"](c.checkedCls)}})}}); +/* + * Ext JS Library 3.1.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +Ext.ns("Ext.ux.form");Ext.ux.form.SpinnerField=Ext.extend(Ext.form.NumberField,{actionMode:"wrap",deferHeight:true,autoSize:Ext.emptyFn,onBlur:Ext.emptyFn,adjustSize:Ext.BoxComponent.prototype.adjustSize,constructor:function(c){var b=Ext.copyTo({},c,"incrementValue,alternateIncrementValue,accelerate,defaultValue,triggerClass,splitterClass");var d=this.spinner=new Ext.ux.Spinner(b);var a=c.plugins?(Ext.isArray(c.plugins)?c.plugins.push(d):[c.plugins,d]):d;Ext.ux.form.SpinnerField.superclass.constructor.call(this,Ext.apply(c,{plugins:a}))},getResizeEl:function(){return this.wrap},getPositionEl:function(){return this.wrap},alignErrorIcon:function(){if(this.wrap){this.errorIcon.alignTo(this.wrap,"tl-tr",[2,0])}},validateBlur:function(){return true}});Ext.reg("spinnerfield",Ext.ux.form.SpinnerField);Ext.form.SpinnerField=Ext.ux.form.SpinnerField; +/* + * Ext.ux.form.SpinnerGroup.js + * + * Copyright (c) Damien Churchill 2009-2010 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.ns("Ext.ux.form");Ext.ux.form.SpinnerGroup=Ext.extend(Ext.form.CheckboxGroup,{defaultType:"spinnerfield",groupCls:"x-form-spinner-group",colCfg:{},onRender:function(h,f){if(!this.el){var o={cls:this.groupCls,layout:"column",border:false,renderTo:h};var a=Ext.apply({defaultType:this.defaultType,layout:"form",border:false,labelWidth:60,defaults:{hideLabel:true,anchor:"60%"}},this.colCfg);if(this.items[0].items){Ext.apply(o,{layoutConfig:{columns:this.items.length},defaults:this.defaults,items:this.items});for(var e=0,k=this.items.length;e0&&e%q==0){n++}if(this.items[e].fieldLabel){this.items[e].hideLabel=false}m[n].items.push(this.items[e])}}else{for(var e=0,k=this.items.length;e + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the OpenSSL + * library. + * You must obey the GNU General Public License in all respects for all of + * the code used other than OpenSSL. If you modify file(s) with this + * exception, you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete + * this exception statement from your version. If you delete this exception + * statement from all source files in the program, then also delete it here. + */ +Ext.namespace("Ext.ux.form");Ext.ux.form.ToggleField=Ext.extend(Ext.form.Field,{cls:"x-toggle-field",initComponent:function(){Ext.ux.form.ToggleField.superclass.initComponent.call(this);this.toggle=new Ext.form.Checkbox();this.toggle.on("check",this.onToggleCheck,this);this.input=new Ext.form.TextField({disabled:true})},onRender:function(b,a){if(!this.el){this.panel=new Ext.Panel({cls:this.groupCls,layout:"table",layoutConfig:{columns:2},border:false,renderTo:b});this.panel.ownerCt=this;this.el=this.panel.getEl();this.panel.add(this.toggle);this.panel.add(this.input);this.panel.doLayout();this.toggle.getEl().parent().setStyle("padding-right","10px")}Ext.ux.form.ToggleField.superclass.onRender.call(this,b,a)},onResize:function(a,b){this.panel.setSize(a,b);this.panel.doLayout();var c=a-this.toggle.getSize().width-25;this.input.setSize(c,b)},onToggleCheck:function(a,b){this.input.setDisabled(!b)}});Ext.reg("togglefield",Ext.ux.form.ToggleField);Ext.ux.JSLoader=function(options){Ext.ux.JSLoader.scripts[++Ext.ux.JSLoader.index]={url:options.url,success:true,jsLoadObj:null,options:options,onLoad:options.onLoad||Ext.emptyFn,onError:options.onError||Ext.ux.JSLoader.stdError,scope:options.scope||this};Ext.Ajax.request({url:options.url,scriptIndex:Ext.ux.JSLoader.index,success:function(response,options){var script=Ext.ux.JSLoader.scripts[options.scriptIndex];try{eval(response.responseText)}catch(e){script.success=false;script.onError(script.options,e)}if(script.success){script.onLoad.call(script.scope,script.options)}},failure:function(response,options){var script=Ext.ux.JSLoader.scripts[options.scriptIndex];script.success=false;script.onError(script.options,response.status)}})};Ext.ux.JSLoader.index=0;Ext.ux.JSLoader.scripts=[];Ext.ux.JSLoader.stdError=function(a,b){window.alert("Error loading script:\n\n"+a.url+"\n\nstatus: "+b)} +/* + * Ext JS Library 3.1.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +;Ext.ux.Spinner=Ext.extend(Ext.util.Observable,{incrementValue:1,alternateIncrementValue:5,triggerClass:"x-form-spinner-trigger",splitterClass:"x-form-spinner-splitter",alternateKey:Ext.EventObject.shiftKey,defaultValue:0,accelerate:false,constructor:function(a){Ext.ux.Spinner.superclass.constructor.call(this,a);Ext.apply(this,a);this.mimicing=false},init:function(a){this.field=a;a.afterMethod("onRender",this.doRender,this);a.afterMethod("onEnable",this.doEnable,this);a.afterMethod("onDisable",this.doDisable,this);a.afterMethod("afterRender",this.doAfterRender,this);a.afterMethod("onResize",this.doResize,this);a.afterMethod("onFocus",this.doFocus,this);a.beforeMethod("onDestroy",this.doDestroy,this)},doRender:function(b,a){var c=this.el=this.field.getEl();var d=this.field;if(!d.wrap){d.wrap=this.wrap=c.wrap({cls:"x-form-field-wrap"})}else{this.wrap=d.wrap.addClass("x-form-field-wrap")}this.trigger=this.wrap.createChild({tag:"img",src:Ext.BLANK_IMAGE_URL,cls:"x-form-trigger "+this.triggerClass});if(!d.width){this.wrap.setWidth(c.getWidth()+this.trigger.getWidth())}this.splitter=this.wrap.createChild({tag:"div",cls:this.splitterClass,style:"width:13px; height:2px;"});this.splitter.setRight((Ext.isIE)?1:2).setTop(10).show();this.proxy=this.trigger.createProxy("",this.splitter,true);this.proxy.addClass("x-form-spinner-proxy");this.proxy.setStyle("left","0px");this.proxy.setSize(14,1);this.proxy.hide();this.dd=new Ext.dd.DDProxy(this.splitter.dom.id,"SpinnerDrag",{dragElId:this.proxy.id});this.initTrigger();this.initSpinner()},doAfterRender:function(){var a;if(Ext.isIE&&this.el.getY()!=(a=this.trigger.getY())){this.el.position();this.el.setY(a)}},doEnable:function(){if(this.wrap){this.wrap.removeClass(this.field.disabledClass)}},doDisable:function(){if(this.wrap){this.wrap.addClass(this.field.disabledClass);this.el.removeClass(this.field.disabledClass)}},doResize:function(a,b){if(typeof a=="number"){this.el.setWidth(a-this.trigger.getWidth())}this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth())},doFocus:function(){if(!this.mimicing){this.wrap.addClass("x-trigger-wrap-focus");this.mimicing=true;Ext.get(Ext.isIE?document.body:document).on("mousedown",this.mimicBlur,this,{delay:10});this.el.on("keydown",this.checkTab,this)}},checkTab:function(a){if(a.getKey()==a.TAB){this.triggerBlur()}},mimicBlur:function(a){if(!this.wrap.contains(a.target)&&this.field.validateBlur(a)){this.triggerBlur()}},triggerBlur:function(){this.mimicing=false;Ext.get(Ext.isIE?document.body:document).un("mousedown",this.mimicBlur,this);this.el.un("keydown",this.checkTab,this);this.field.beforeBlur();this.wrap.removeClass("x-trigger-wrap-focus");this.field.onBlur.call(this.field)},initTrigger:function(){this.trigger.addClassOnOver("x-form-trigger-over");this.trigger.addClassOnClick("x-form-trigger-click")},initSpinner:function(){this.field.addEvents({spin:true,spinup:true,spindown:true});this.keyNav=new Ext.KeyNav(this.el,{up:function(a){a.preventDefault();this.onSpinUp()},down:function(a){a.preventDefault();this.onSpinDown()},pageUp:function(a){a.preventDefault();this.onSpinUpAlternate()},pageDown:function(a){a.preventDefault();this.onSpinDownAlternate()},scope:this});this.repeater=new Ext.util.ClickRepeater(this.trigger,{accelerate:this.accelerate});this.field.mon(this.repeater,"click",this.onTriggerClick,this,{preventDefault:true});this.field.mon(this.trigger,{mouseover:this.onMouseOver,mouseout:this.onMouseOut,mousemove:this.onMouseMove,mousedown:this.onMouseDown,mouseup:this.onMouseUp,scope:this,preventDefault:true});this.field.mon(this.wrap,"mousewheel",this.handleMouseWheel,this);this.dd.setXConstraint(0,0,10);this.dd.setYConstraint(1500,1500,10);this.dd.endDrag=this.endDrag.createDelegate(this);this.dd.startDrag=this.startDrag.createDelegate(this);this.dd.onDrag=this.onDrag.createDelegate(this)},onMouseOver:function(){if(this.disabled){return}var a=this.getMiddle();this.tmpHoverClass=(Ext.EventObject.getPageY()a)&&this.tmpHoverClass=="x-form-spinner-overup")||((Ext.EventObject.getPageY()0){this.onSpinUp();a.stopEvent()}else{if(b<0){this.onSpinDown();a.stopEvent()}}},startDrag:function(){this.proxy.show();this._previousY=Ext.fly(this.dd.getDragEl()).getTop()},endDrag:function(){this.proxy.hide()},onDrag:function(){if(this.disabled){return}var b=Ext.fly(this.dd.getDragEl()).getTop();var a="";if(this._previousY>b){a="Up"}if(this._previousYthis.field.maxValue){a=this.field.maxValue}return this.fixPrecision(a)},fixPrecision:function(b){var a=isNaN(b);if(!this.field.allowDecimals||this.field.decimalPrecision==-1||a||!b){return a?"":b}return parseFloat(parseFloat(b).toFixed(this.field.decimalPrecision))},doDestroy:function(){if(this.trigger){this.trigger.remove()}if(this.wrap){this.wrap.remove();delete this.field.wrap}if(this.splitter){this.splitter.remove()}if(this.dd){this.dd.unreg();this.dd=null}if(this.proxy){this.proxy.remove()}if(this.repeater){this.repeater.purgeListeners()}}});Ext.form.Spinner=Ext.ux.Spinner; +/* + * Ext JS Library 3.1.0 + * Copyright(c) 2006-2009 Ext JS, LLC + * licensing@extjs.com + * http://www.extjs.com/license + */ +Ext.ux.StatusBar=Ext.extend(Ext.Toolbar,{cls:"x-statusbar",busyIconCls:"x-status-busy",busyText:"Loading...",autoClear:5000,emptyText:" ",activeThreadId:0,initComponent:function(){if(this.statusAlign=="right"){this.cls+=" x-status-right"}Ext.ux.StatusBar.superclass.initComponent.call(this)},afterRender:function(){Ext.ux.StatusBar.superclass.afterRender.call(this);var a=this.statusAlign=="right";this.currIconCls=this.iconCls||this.defaultIconCls;this.statusEl=new Ext.Toolbar.TextItem({cls:"x-status-text "+(this.currIconCls||""),text:this.text||this.defaultText||""});if(a){this.add("->");this.add(this.statusEl)}else{this.insert(0,this.statusEl);this.insert(1,"->")}},setStatus:function(d){d=d||{};if(typeof d=="string"){d={text:d}}if(d.text!==undefined){this.setText(d.text)}if(d.iconCls!==undefined){this.setIcon(d.iconCls)}if(d.clear){var e=d.clear,b=this.autoClear,a={useDefaults:true,anim:true};if(typeof e=="object"){e=Ext.applyIf(e,a);if(e.wait){b=e.wait}}else{if(typeof e=="number"){b=e;e=a}else{if(typeof e=="boolean"){e=a}}}e.threadId=this.activeThreadId;this.clearStatus.defer(b,this,[e])}return this},clearStatus:function(c){c=c||{};if(c.threadId&&c.threadId!==this.activeThreadId){return this}var b=c.useDefaults?this.defaultText:this.emptyText,a=c.useDefaults?(this.defaultIconCls?this.defaultIconCls:""):"";if(c.anim){this.statusEl.el.fadeOut({remove:false,useDisplay:true,scope:this,callback:function(){this.setStatus({text:b,iconCls:a});this.statusEl.el.show()}})}else{this.statusEl.hide();this.setStatus({text:b,iconCls:a});this.statusEl.show()}return this},setText:function(a){this.activeThreadId++;this.text=a||"";if(this.rendered){this.statusEl.setText(this.text)}return this},getText:function(){return this.text},setIcon:function(a){this.activeThreadId++;a=a||"";if(this.rendered){if(this.currIconCls){this.statusEl.removeClass(this.currIconCls);this.currIconCls=null}if(a.length>0){this.statusEl.addClass(a);this.currIconCls=a}}else{this.currIconCls=a}return this},showBusy:function(a){if(typeof a=="string"){a={text:a}}a=Ext.applyIf(a||{},{text:this.busyText,iconCls:this.busyIconCls});return this.setStatus(a)}});Ext.reg("statusbar",Ext.ux.StatusBar); \ No newline at end of file