1 /* 2 Script: Deluge.Toolbar.js 3 Contains the Deluge toolbar. 4 5 Copyright: 6 (C) Damien Churchill 2009 <damoxc@gmail.com> 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 3, or (at your option) 10 any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program. If not, write to: 19 The Free Software Foundation, Inc., 20 51 Franklin Street, Fifth Floor 21 Boston, MA 02110-1301, USA. 22 23 In addition, as a special exception, the copyright holders give 24 permission to link the code of portions of this program with the OpenSSL 25 library. 26 You must obey the GNU General Public License in all respects for all of 27 the code used other than OpenSSL. If you modify file(s) with this 28 exception, you may extend this exception to your version of the file(s), 29 but you are not obligated to do so. If you do not wish to do so, delete 30 this exception statement from your version. If you delete this exception 31 statement from all source files in the program, then also delete it here. 32 33 */ 34 35 (function() { 36 Ext.deluge.Toolbar = Ext.extend(Ext.Toolbar, { 37 constructor: function(config) { 38 config = Ext.apply({ 39 items: [ 40 { 41 id: 'create', 42 cls: 'x-btn-text-icon', 43 disabled: true, 44 text: _('Create'), 45 icon: '/icons/create.png', 46 handler: this.onTorrentAction 47 },{ 48 id: 'add', 49 cls: 'x-btn-text-icon', 50 disabled: true, 51 text: _('Add'), 52 icon: '/icons/add.png', 53 handler: this.onTorrentAdd 54 },{ 55 id: 'remove', 56 cls: 'x-btn-text-icon', 57 disabled: true, 58 text: _('Remove'), 59 icon: '/icons/remove.png', 60 handler: this.onTorrentAction 61 },'|',{ 62 id: 'pause', 63 cls: 'x-btn-text-icon', 64 disabled: true, 65 text: _('Pause'), 66 icon: '/icons/pause.png', 67 handler: this.onTorrentAction 68 },{ 69 id: 'resume', 70 cls: 'x-btn-text-icon', 71 disabled: true, 72 text: _('Resume'), 73 icon: '/icons/start.png', 74 handler: this.onTorrentAction 75 },'|',{ 76 id: 'up', 77 cls: 'x-btn-text-icon', 78 disabled: true, 79 text: _('Up'), 80 icon: '/icons/up.png', 81 handler: this.onTorrentAction 82 },{ 83 id: 'down', 84 cls: 'x-btn-text-icon', 85 disabled: true, 86 text: _('Down'), 87 icon: '/icons/down.png', 88 handler: this.onTorrentAction 89 },'|',{ 90 id: 'preferences', 91 cls: 'x-btn-text-icon', 92 text: _('Preferences'), 93 icon: '/icons/preferences.png', 94 handler: this.onPreferencesClick, 95 scope: this 96 },{ 97 id: 'connectionman', 98 cls: 'x-btn-text-icon', 99 text: _('Connection Manager'), 100 iconCls: 'x-deluge-connections', 101 handler: this.onConnectionManagerClick, 102 scope: this 103 },'->',{ 104 id: 'help', 105 cls: 'x-btn-text-icon', 106 disabled: true, 107 icon: '/icons/help.png', 108 text: _('Help'), 109 handler: this.onHelpClick, 110 scope: this 111 },{ 112 id: 'logout', 113 cls: 'x-btn-text-icon', 114 icon: '/icons/logout.png', 115 disabled: true, 116 text: _('Logout'), 117 handler: this.onLogout, 118 scope: this 119 } 120 ] 121 }, config); 122 Ext.deluge.Toolbar.superclass.constructor.call(this, config); 123 }, 124 125 connectedButtons: [ 126 'add', 'remove', 'pause', 'resume', 'up', 'down' 127 ], 128 129 initComponent: function() { 130 Ext.deluge.Toolbar.superclass.initComponent.call(this); 131 Deluge.Events.on('connect', this.onConnect, this); 132 Deluge.Events.on('login', this.onLogin, this); 133 }, 134 135 onConnect: function() { 136 Ext.each(this.connectedButtons, function(buttonId) { 137 this.items.get(buttonId).enable(); 138 }, this); 139 }, 140 141 onDisconnect: function() { 142 Ext.each(this.connectedButtons, function(buttonId) { 143 this.items.get(buttonId).disable(); 144 }, this); 145 }, 146 147 onLogin: function() { 148 this.items.get('logout').enable(); 149 }, 150 151 onLogout: function() { 152 this.items.get('logout').disable(); 153 Deluge.Events.fire('logout'); 154 Deluge.Login.show(); 155 }, 156 157 onConnectionManagerClick: function() { 158 Deluge.ConnectionManager.show(); 159 }, 160 161 onPreferencesClick: function() { 162 Deluge.Preferences.show(); 163 }, 164 165 onTorrentAction: function(item) { 166 var selection = Deluge.Torrents.getSelections(); 167 var ids = []; 168 Ext.each(selection, function(record) { 169 ids.push(record.id); 170 }); 171 172 switch (item.id) { 173 case 'remove': 174 Deluge.Events.fire('torrentRemoved', ids); 175 Deluge.Client.core.remove_torrent(ids, null, { 176 success: function() { 177 Deluge.UI.update(); 178 } 179 }); 180 break; 181 case 'pause': 182 case 'resume': 183 Deluge.Client.core[item.id + '_torrent'](ids, { 184 success: function() { 185 Deluge.UI.update(); 186 } 187 }); 188 break; 189 case 'up': 190 case 'down': 191 Deluge.Client.core['queue_' + item.id](ids, { 192 success: function() { 193 Deluge.UI.update(); 194 } 195 }); 196 break; 197 } 198 }, 199 200 onTorrentAdd: function() { 201 Deluge.Add.show(); 202 } 203 }); 204 205 Deluge.Toolbar = new Ext.deluge.Toolbar(); 206 })();