1# Copyright (C) 2008-2010 Adam Olsen 2# 3# This program is free software; you can redistribute it and/or modify 4# it under the terms of the GNU General Public License as published by 5# the Free Software Foundation; either version 2, or (at your option) 6# any later version. 7# 8# This program is distributed in the hope that it will be useful, 9# but WITHOUT ANY WARRANTY; without even the implied warranty of 10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11# GNU General Public License for more details. 12# 13# You should have received a copy of the GNU General Public License 14# along with this program; if not, write to the Free Software 15# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16# 17# 18# The developers of the Exaile media player hereby grant permission 19# for non-GPL compatible GStreamer and Exaile plugins to be used and 20# distributed together with GStreamer and Exaile. This permission is 21# above and beyond the permissions granted by the GPL license by which 22# Exaile is covered. If you modify this code, you may extend this 23# exception to your version of the code, but you are not obligated to 24# do so. If you do not wish to do so, delete this exception statement 25# from your version. 26 27import logging 28 29from gi.repository import Gtk 30 31from xl import event 32from xlgui.guiutil import GtkTemplate 33 34logger = logging.getLogger(__name__) 35 36 37@GtkTemplate('ui', 'device_manager.ui') 38class ManagerDialog(Gtk.Window): 39 """ 40 the device manager dialog 41 """ 42 43 __gtype_name__ = 'DeviceManager' 44 45 tree_devices, model = GtkTemplate.Child.widgets(2) 46 47 def __init__(self, parent, main): 48 Gtk.Window.__init__(self) 49 self.init_template() 50 51 self.main = main 52 self.device_manager = self.main.exaile.devices 53 self.set_transient_for(parent) 54 55 # GtkListStore self.model: first column (PyObject) should really be of 56 # type devices.Device, but that doesn't work with GtkBuilder. 57 58 self.populate_tree() 59 event.add_ui_callback(self.populate_tree, 'device_added') 60 event.add_ui_callback(self.populate_tree, 'device_removed') 61 62 def populate_tree(self, *args): 63 self.model.clear() 64 for d in self.device_manager.get_devices(): 65 self.model.append([d, None, d.get_name(), d.__class__.__name__]) 66 67 def _get_selected_devices(self): 68 sel = self.tree_devices.get_selection() 69 (model, paths) = sel.get_selected_rows() 70 devices = [] 71 for path in paths: 72 iter = self.model.get_iter(path) 73 device = self.model.get_value(iter, 0) 74 devices.append(device) 75 76 return devices 77 78 @GtkTemplate.Callback 79 def on_btn_connect_clicked(self, *args): 80 devices = self._get_selected_devices() 81 82 for d in devices: 83 d.connect() 84 85 @GtkTemplate.Callback 86 def on_btn_disconnect_clicked(self, *args): 87 devices = self._get_selected_devices() 88 89 for d in devices: 90 d.disconnect() 91 92 @GtkTemplate.Callback 93 def on_btn_close_clicked(self, *args): 94 self.hide() 95 self.destroy() 96 97 def run(self): 98 self.show_all() 99