diff options
Diffstat (limited to 'deluge/ui/web/js/deluge-all/add')
-rw-r--r-- | deluge/ui/web/js/deluge-all/add/.order | 1 | ||||
-rw-r--r-- | deluge/ui/web/js/deluge-all/add/AddWindow.js | 332 | ||||
-rw-r--r-- | deluge/ui/web/js/deluge-all/add/FilesTab.js | 100 | ||||
-rw-r--r-- | deluge/ui/web/js/deluge-all/add/Infohash.js | 10 | ||||
-rw-r--r-- | deluge/ui/web/js/deluge-all/add/OptionsPanel.js | 145 | ||||
-rw-r--r-- | deluge/ui/web/js/deluge-all/add/OptionsTab.js | 217 | ||||
-rw-r--r-- | deluge/ui/web/js/deluge-all/add/UrlWindow.js | 112 | ||||
-rw-r--r-- | deluge/ui/web/js/deluge-all/add/Window.js | 29 |
8 files changed, 946 insertions, 0 deletions
diff --git a/deluge/ui/web/js/deluge-all/add/.order b/deluge/ui/web/js/deluge-all/add/.order new file mode 100644 index 0000000..dbd1ab9 --- /dev/null +++ b/deluge/ui/web/js/deluge-all/add/.order @@ -0,0 +1 @@ ++ Window.js diff --git a/deluge/ui/web/js/deluge-all/add/AddWindow.js b/deluge/ui/web/js/deluge-all/add/AddWindow.js new file mode 100644 index 0000000..f5f2fdf --- /dev/null +++ b/deluge/ui/web/js/deluge-all/add/AddWindow.js @@ -0,0 +1,332 @@ +/** + * Deluge.add.AddWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> + * + * This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with + * the additional special exception to link portions of this program with the OpenSSL library. + * See LICENSE for more details. + */ + +Ext.namespace('Deluge.add'); + +// This override allows file upload buttons to contain icons +Ext.override(Ext.ux.form.FileUploadField, { + onRender: function (ct, position) { + Ext.ux.form.FileUploadField.superclass.onRender.call( + this, + ct, + position + ); + + 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 btnCfg = Ext.applyIf(this.buttonCfg || {}, { + text: this.buttonText, + }); + this.button = new Ext.Button( + Ext.apply(btnCfg, { + renderTo: this.wrap, + cls: + 'x-form-file-btn' + + (btnCfg.iconCls ? ' x-btn-text-icon' : ''), + }) + ); + + if (this.buttonOnly) { + this.el.hide(); + this.wrap.setWidth(this.button.getEl().getWidth()); + } + + this.bindListeners(); + this.resizeEl = this.positionEl = this.wrap; + }, +}); + +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); + + 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, + dataIndex: 'text', + tpl: new Ext.XTemplate( + '<div class="x-deluge-add-torrent-name">{text:htmlEncode}</div>' + ), + }, + ], + stripeRows: true, + singleSelect: true, + listeners: { + selectionchange: { + fn: this.onSelect, + scope: this, + }, + }, + hideHeaders: true, + autoExpandColumn: 'torrent', + height: '100%', + autoScroll: true, + }); + + this.add({ + region: 'center', + items: [this.list], + border: false, + bbar: new Ext.Toolbar({ + items: [ + { + id: 'fileUploadForm', + xtype: 'form', + layout: 'fit', + baseCls: 'x-plain', + fileUpload: true, + items: [ + { + buttonOnly: true, + xtype: 'fileuploadfield', + id: 'torrentFile', + name: 'file', + multiple: true, + buttonCfg: { + iconCls: 'x-deluge-add-file', + text: _('File'), + }, + listeners: { + scope: this, + fileselected: this.onFileSelected, + }, + }, + ], + }, + { + text: _('Url'), + iconCls: 'icon-add-url', + handler: this.onUrl, + scope: this, + }, + { + text: _('Infohash'), + iconCls: 'icon-magnet-add', + hidden: true, + disabled: true, + }, + '->', + { + text: _('Remove'), + iconCls: 'icon-remove', + handler: this.onRemove, + scope: this, + }, + ], + }), + }); + + this.fileUploadForm = Ext.getCmp('fileUploadForm').getForm(); + 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(); + // Reset upload form so handler fires when a canceled file is reselected + this.fileUploadForm.reset(); + }, + + 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]; + if (!torrent) return; + 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')); + } 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); + this.url.on('addfailed', this.onTorrentAddFailed, this); + } + + this.optionsPanel.form.getDefaults(); + }, + + onFileSelected: function () { + if (this.fileUploadForm.isValid()) { + var torrentIds = []; + var files = this.fileUploadForm.findField('torrentFile').value; + var randomId = this.createTorrentId(); + Array.prototype.forEach.call( + files, + function (file, i) { + // Append index for batch of unique torrentIds. + var torrentId = randomId + i.toString(); + torrentIds.push(torrentId); + this.onTorrentBeforeAdd(torrentId, file.name); + }.bind(this) + ); + this.fileUploadForm.submit({ + url: deluge.config.base + 'upload', + waitMsg: _('Uploading your torrent...'), + success: this.onUploadSuccess, + failure: this.onUploadFailure, + scope: this, + torrentIds: torrentIds, + }); + } + }, + + onUploadSuccess: function (fp, upload) { + if (!upload.result.success) { + this.clear(); + return; + } + + upload.result.files.forEach( + function (filename, i) { + deluge.client.web.get_torrent_info(filename, { + success: this.onGotInfo, + scope: this, + filename: filename, + torrentId: upload.options.torrentIds[i], + }); + }.bind(this) + ); + this.fileUploadForm.reset(); + }, + + onUploadFailure: function (form, action) { + this.hide(); + Ext.MessageBox.show({ + title: _('Error'), + msg: _('Failed to upload torrent'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error', + }); + this.fireEvent('addfailed', this.torrentId); + }, + + onGotInfo: function (info, obj, response, request) { + info.filename = request.options.filename; + torrentId = request.options.torrentId; + this.onTorrentAdd(torrentId, info); + }, + + 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); + this.list.select(r); + } + }, + + onTorrentAddFailed: function (torrentId) { + var store = this.list.getStore(); + var torrentRecord = store.getById(torrentId); + if (torrentRecord) { + store.remove(torrentRecord); + } + }, + + onUrl: function (button, event) { + this.url.show(); + }, +}); diff --git a/deluge/ui/web/js/deluge-all/add/FilesTab.js b/deluge/ui/web/js/deluge-all/add/FilesTab.js new file mode 100644 index 0000000..d712c02 --- /dev/null +++ b/deluge/ui/web/js/deluge-all/add/FilesTab.js @@ -0,0 +1,100 @@ +/** + * Deluge.add.FilesTab.js + * + * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> + * + * This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with + * the additional special exception to link portions of this program with the OpenSSL library. + * See LICENSE for more details. + */ +Ext.ns('Deluge.add'); + +/** + * @class Deluge.add.FilesTab + * @extends Ext.ux.tree.TreeGrid + */ +Deluge.add.FilesTab = Ext.extend(Ext.ux.tree.TreeGrid, { + layout: 'fit', + title: _('Files'), + + autoScroll: false, + animate: false, + border: false, + disabled: true, + rootVisible: false, + + columns: [ + { + header: _('Filename'), + width: 295, + dataIndex: 'filename', + tpl: new Ext.XTemplate('{filename:htmlEncode}'), + }, + { + 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 ( + '<div rel="chkbox" class="x-grid3-check-col' + + (v ? '-on' : '') + + '"> </div>' + ); + }, + }), + }, + ], + + 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); + } + }, +}); diff --git a/deluge/ui/web/js/deluge-all/add/Infohash.js b/deluge/ui/web/js/deluge-all/add/Infohash.js new file mode 100644 index 0000000..0105e02 --- /dev/null +++ b/deluge/ui/web/js/deluge-all/add/Infohash.js @@ -0,0 +1,10 @@ +/** + * Deluge.add.Infohash.js + * + * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> + * + * This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with + * the additional special exception to link portions of this program with the OpenSSL library. + * See LICENSE for more details. + */ +Ext.namespace('Ext.deluge.add'); diff --git a/deluge/ui/web/js/deluge-all/add/OptionsPanel.js b/deluge/ui/web/js/deluge-all/add/OptionsPanel.js new file mode 100644 index 0000000..365b001 --- /dev/null +++ b/deluge/ui/web/js/deluge-all/add/OptionsPanel.js @@ -0,0 +1,145 @@ +/** + * Deluge.add.OptionsPanel.js + * + * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> + * + * This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with + * the additional special exception to link portions of this program with the OpenSSL library. + * See LICENSE for more details. + */ +Ext.ns('Deluge.add'); + +Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, { + torrents: {}, + + // layout options + region: 'south', + border: false, + activeTab: 0, + height: 265, + + 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.form.setDisabled(false); + + if (this.torrents[torrentId]['files_tree']) { + 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(); + this.files.setDisabled(false); + this.files.show(); + } else { + // Files tab is empty so show options tab + this.form.show(); + this.files.setDisabled(true); + } + }, + + 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) { + 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 + ); + }, +}); diff --git a/deluge/ui/web/js/deluge-all/add/OptionsTab.js b/deluge/ui/web/js/deluge-all/add/OptionsTab.js new file mode 100644 index 0000000..73a8a5c --- /dev/null +++ b/deluge/ui/web/js/deluge-all/add/OptionsTab.js @@ -0,0 +1,217 @@ +/** + * Deluge.add.OptionsPanel.js + * + * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> + * + * This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with + * the additional special exception to link portions of this program with the OpenSSL library. + * See LICENSE for more details. + */ +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 Folder'), + border: false, + autoHeight: true, + defaultType: 'textfield', + labelWidth: 1, + fieldLabel: '', + style: 'padding: 5px 0; margin-bottom: 0;', + }); + this.optionsManager.bind( + 'download_location', + fieldset.add({ + fieldLabel: '', + name: 'download_location', + anchor: '95%', + labelSeparator: '', + }) + ); + var fieldset = this.add({ + xtype: 'fieldset', + title: _('Move Completed Folder'), + border: false, + autoHeight: true, + defaultType: 'togglefield', + labelWidth: 1, + fieldLabel: '', + style: 'padding: 5px 0; margin-bottom: 0;', + }); + var field = fieldset.add({ + fieldLabel: '', + name: 'move_completed_path', + anchor: '98%', + }); + this.optionsManager.bind('move_completed', field.toggle); + this.optionsManager.bind('move_completed_path', field.input); + + var panel = this.add({ + border: false, + layout: 'column', + defaultType: 'fieldset', + }); + + fieldset = panel.add({ + title: _('Bandwidth'), + border: false, + autoHeight: true, + bodyStyle: 'padding: 2px 5px', + labelWidth: 105, + width: 200, + defaultType: 'spinnerfield', + style: 'padding-right: 10px;', + }); + this.optionsManager.bind( + 'max_download_speed', + fieldset.add({ + fieldLabel: _('Max Down Speed'), + name: 'max_download_speed', + width: 60, + }) + ); + this.optionsManager.bind( + 'max_upload_speed', + fieldset.add({ + fieldLabel: _('Max Up Speed'), + name: 'max_upload_speed', + width: 60, + }) + ); + this.optionsManager.bind( + 'max_connections', + fieldset.add({ + fieldLabel: _('Max Connections'), + name: 'max_connections', + width: 60, + }) + ); + this.optionsManager.bind( + 'max_upload_slots', + fieldset.add({ + fieldLabel: _('Max Upload Slots'), + 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.optionsManager.bind( + 'sequential_download', + fieldset.add({ + name: 'sequential_download', + boxLabel: _('Sequential Download'), + fieldLabel: '', + labelSeparator: '', + }) + ); + this.optionsManager.bind( + 'seed_mode', + fieldset.add({ + name: 'seed_mode', + boxLabel: _('Skip File Hash Check'), + fieldLabel: '', + labelSeparator: '', + }) + ); + this.optionsManager.bind( + 'super_seeding', + fieldset.add({ + name: 'super_seeding', + boxLabel: _('Super Seed'), + fieldLabel: '', + labelSeparator: '', + }) + ); + this.optionsManager.bind( + 'pre_allocate_storage', + fieldset.add({ + name: 'pre_allocate_storage', + boxLabel: _('Preallocate Disk Space'), + fieldLabel: '', + labelSeparator: '', + }) + ); + }, + + getDefaults: function () { + var keys = [ + 'add_paused', + 'pre_allocate_storage', + 'download_location', + 'max_connections_per_torrent', + 'max_download_speed_per_torrent', + 'move_completed', + 'move_completed_path', + 'max_upload_slots_per_torrent', + 'max_upload_speed_per_torrent', + 'prioritize_first_last_pieces', + 'sequential_download', + ]; + + deluge.client.core.get_config_values(keys, { + success: function (config) { + var options = { + file_priorities: [], + add_paused: config.add_paused, + sequential_download: config.sequential_download, + pre_allocate_storage: config.pre_allocate_storage, + download_location: config.download_location, + move_completed: config.move_completed, + move_completed_path: config.move_completed_path, + 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, + seed_mode: false, + super_seeding: false, + }; + this.optionsManager.options = options; + this.optionsManager.resetAll(); + }, + scope: this, + }); + }, +}); diff --git a/deluge/ui/web/js/deluge-all/add/UrlWindow.js b/deluge/ui/web/js/deluge-all/add/UrlWindow.js new file mode 100644 index 0000000..caf2250 --- /dev/null +++ b/deluge/ui/web/js/deluge-all/add/UrlWindow.js @@ -0,0 +1,112 @@ +/** + * Deluge.add.UrlWindow.js + * + * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> + * + * This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with + * the additional special exception to link portions of this program with the OpenSSL library. + * See LICENSE for more details. + */ + +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', + width: '97%', + }); + this.urlField.on('specialkey', this.onAdd, this); + + this.cookieField = form.add({ + fieldLabel: _('Cookies'), + id: 'cookies', + name: 'cookies', + width: '97%', + }); + 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(); + + if (url.indexOf('magnet:?') == 0 && url.indexOf('xt=urn:btih') > -1) { + deluge.client.web.get_magnet_info(url, { + success: this.onGotInfo, + scope: this, + filename: url, + torrentId: torrentId, + }); + } else { + deluge.client.web.download_torrent_from_url(url, cookies, { + success: this.onDownload, + failure: this.onDownloadFailed, + scope: this, + torrentId: torrentId, + }); + } + + this.hide(); + this.urlField.setValue(''); + this.fireEvent('beforeadd', torrentId, url); + }, + + onDownload: function (filename, obj, resp, req) { + deluge.client.web.get_torrent_info(filename, { + success: this.onGotInfo, + failure: this.onDownloadFailed, + scope: this, + filename: filename, + torrentId: req.options.torrentId, + }); + }, + + onDownloadFailed: function (obj, resp, req) { + Ext.MessageBox.show({ + title: _('Error'), + msg: _('Failed to download torrent'), + buttons: Ext.MessageBox.OK, + modal: false, + icon: Ext.MessageBox.ERROR, + iconCls: 'x-deluge-icon-error', + }); + this.fireEvent('addfailed', req.options.torrentId); + }, + + onGotInfo: function (info, obj, response, request) { + info['filename'] = request.options.filename; + this.fireEvent('add', request.options.torrentId, info); + }, +}); diff --git a/deluge/ui/web/js/deluge-all/add/Window.js b/deluge/ui/web/js/deluge-all/add/Window.js new file mode 100644 index 0000000..20851e7 --- /dev/null +++ b/deluge/ui/web/js/deluge-all/add/Window.js @@ -0,0 +1,29 @@ +/** + * Deluge.add.Window.js + * + * Copyright (c) Damien Churchill 2009-2010 <damoxc@gmail.com> + * + * This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with + * the additional special exception to link portions of this program with the OpenSSL library. + * See LICENSE for more details. + */ +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', 'addfailed'); + }, + + /** + * Create an id for the torrent before we have any info about it. + */ + createTorrentId: function () { + return new Date().getTime().toString(); + }, +}); |