--- ipod/main.old 2006-08-05 12:14:07.245399000 +0200 +++ ipod/main.py 2006-08-05 12:33:46.595399000 +0200 @@ -23,6 +23,7 @@ from qltk import ErrorMessage import gpod +import dbus class iPodMain(SongsMenuPlugin): PLUGIN_VERSION = '0.4' @@ -34,18 +35,58 @@ win = None complete = True + def detect_ipod(self): + bus = dbus.SystemBus() + try: + hal_manager_obj = bus.get_object('org.freedesktop.Hal', + '/org/freedesktop/Hal/Manager') + hal_manager = dbus.Interface(hal_manager_obj, + 'org.freedesktop.Hal.Manager') + dev_udi_list = hal_manager.FindDeviceStringMatch ('portable_audio_player.type', 'ipod') + for udi in dev_udi_list: + vol_udi_list = hal_manager.FindDeviceStringMatch ('info.parent', udi) + + for vol_udi in vol_udi_list: + vol_obj = bus.get_object ('org.freedesktop.Hal', vol_udi) + vol = dbus.Interface (vol_obj, 'org.freedesktop.Hal.Device') + + if not vol.GetProperty('volume.is_mounted'): + continue; + + return (vol.GetProperty('block.device').encode('ascii'), + vol.GetProperty('volume.mount_point').encode('ascii')) + except None: + print 'HAL is down.' + + return ('-', '-') + + def get_ipod_path(self): + path = '-' + try: + path = config.get('plugins', 'ipod_path') + except: pass + + if '-' == path: + (dev, path) = self.detect_ipod() + + return path + + def get_ipod_dev(self): + path = '-' + try: + path = config.get('plugins', 'ipod_device') + except: pass + + if '-' == path: + (dev, path) = self.detect_ipod() + + return dev + def plugin_songs(self, songs): if self.win: self.win.window.focus() return - try: config.get('plugins', 'ipod_path') - except: - ErrorMessage( - widgets.main, 'Error', 'You have to set the mountpoint first!' - ).run() - return - self.complete = True self.win = self.create_window() self.load_db() @@ -118,9 +159,9 @@ label = gtk.Label() label.set_alignment(1, 0) label.set_justify(gtk.JUSTIFY_RIGHT) - try: path = config.get('plugins', 'ipod_path') + try: path = self.get_ipod_path() except: path = '-' - try: device = config.get('plugins', 'ipod_device') + try: device = self.get_ipod_dev() except: device = '-' label.set_markup('Mount point: %s\nDevice: %s' % (path, device)) @@ -223,7 +264,7 @@ buttons[0].set_sensitive(three) def update_model(self): - path = config.get('plugins', 'ipod_path') + path = self.get_ipod_path() if os.path.isdir(path): try: file = open(os.path.join(path, 'iPod_Control/Device/SysInfo')) @@ -242,7 +283,7 @@ self.refresh() def update_space(self): - path = config.get('plugins', 'ipod_path') + path = self.get_ipod_path() if os.path.isdir(path): if self.db: songs = len(gpod.sw_get_tracks(self.db)) else: songs = '?' @@ -264,7 +305,7 @@ self.refresh() def load_db(self): - path = config.get('plugins', 'ipod_path') + path = self.get_ipod_path() self.db = gpod.itdb_parse(path, None) if self.db: return True @@ -291,7 +332,7 @@ def create_db(self): db = gpod.itdb_new(); - gpod.itdb_set_mountpoint(db, config.get('plugins', 'ipod_path')) + gpod.itdb_set_mountpoint(db, self.get_ipod_path()) master = gpod.itdb_playlist_new('iPod', False) gpod.itdb_playlist_set_mpl(master) @@ -301,7 +342,7 @@ def eject(self): try: - device = config.get('plugins', 'ipod_device') + device = self.get_ipod_dev() except: ErrorMessage( widgets.main, 'Error', 'You have to set the device first!'