Changeset 529

Show
Ignore:
Timestamp:
01/11/07 18:59:03 (2 years ago)
Author:
nicfit
Message:

Profile based dbus services and a few more service methods

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/control.py

    r515 r529  
    4343                               gobject.SIGNAL_RUN_LAST, 
    4444                               gobject.TYPE_NONE, []) 
     45        self._is_active = False 
    4546 
    4647    def shutdown(self): 
    4748        pass 
    4849 
    49     def set_active(self, state = True, audio_ctrl = None): 
    50         pass 
    51     def set_focused(self, state = True): 
     50    def set_active(self, state=True, audio_ctrl=None): 
     51        self._is_active = state 
     52    def is_active(self): 
     53        return self._is_active 
     54 
     55    def set_focused(self, state=True): 
    5256        pass 
    5357 
  • trunk/src/dbus_service.py

    r527 r529  
    2121import dbus, dbus.service, dbus.glib 
    2222import mesk 
     23import config, playlist_control 
    2324 
    24 OBJ_PATH  = '/net/nicfit/mesk/MeskApp' 
    2525INTERFACE = 'net.nicfit.mesk.MeskAppInterface' 
    26 SERVICE   = 'net.nicfit.mesk.MeskApp' 
     26 
     27def get_service_name(profile): 
     28    return _append_profile('net.nicfit.mesk.MeskApp.', profile) 
     29def get_object_path(profile): 
     30    return _append_profile('/net/nicfit/mesk/MeskApp/', profile) 
     31 
     32def _append_profile(prefix, profile): 
     33    if not profile: 
     34        profile = 'default' 
     35    return prefix + profile 
    2736 
    2837class MeskDbusService(dbus.service.Object): 
     
    3039 
    3140    def __init__(self, bus_name, profile, main_win): 
    32         dbus.service.Object.__init__(self, bus_name, OBJ_PATH) 
    3341        self._main_win = main_win 
    3442        self._profile = profile 
     43        obj_path = get_object_path(self._profile) 
     44        dbus.service.Object.__init__(self, bus_name, obj_path) 
    3545 
    3646        self._audio_control = self._main_win._audio_control 
     
    132142 
    133143    @dbus.service.method(INTERFACE) 
    134     def get_current_playlist(self): 
    135         pass 
     144    def list_playlists(self): 
     145        return config.get_all_playlist_names() 
     146 
     147    @dbus.service.method(INTERFACE) 
     148    def get_active_playlist(self): 
     149        for ctrl in self._main_win._controls: 
     150            if ((type(ctrl) is playlist_control.PlaylistControl) and 
     151                    ctrl.is_active()): 
     152                return ctrl.name 
     153        return '' 
     154 
     155## FIXME 
     156#    @dbus.service.method(INTERFACE) 
     157#    def enqueue_uri(self, uri, pl): 
     158#        first_c = None 
     159#        for ctrl in self._main_win._controls: 
     160#            if type(ctrl) is playlist_control.PlaylistControl: 
     161#                if first_pl is None: 
     162#                    first_pl = ctrl 
     163#                print ctrl.name 
     164#        uri = mesk.uri.make_uri(uri) 
     165#        print "enqueue_uri:", uri, pl 
    136166 
    137167    def _on_audio_source_changed(self, ctrl, old, new): 
  • trunk/src/main.py

    r519 r529  
    7272                    remote_status |= self._remote_control(arg) 
    7373                except Exception, ex: 
    74                     mesk.log.error('Dbus error: %s' % str(ex)) 
     74                    sys.stderr.write('Dbus error: %s\n' % str(ex)) 
    7575                    return 2 
    7676 
     
    210210            import dbus 
    211211            import dbus_service  # This is a local module 
     212            obj_path = dbus_service.get_object_path(self.profile) 
     213            service = dbus_service.get_service_name(self.profile) 
    212214            session_bus = dbus.SessionBus() 
    213             self.remote_control = \ 
    214                 dbus.Interface(session_bus.get_object(dbus_service.SERVICE, 
    215                                                       dbus_service.OBJ_PATH), 
    216                                dbus_service.INTERFACE) 
     215            obj = session_bus.get_object(service, obj_path) 
     216            self.remote_control = dbus.Interface(obj, dbus_service.INTERFACE) 
    217217 
    218218        if cmd in ['--stop']: 
     
    241241                     '--get-current-length']: 
    242242            metadata = cmd[cmd.rfind('-') + 1:] 
    243             method = getattr(self.remote_control, 'get_current_%s' % metadata) 
     243            method = getattr(self.remote_control, 
     244                             'get_current_%s' % metadata) 
    244245            data = method() 
    245             sys.stdout.write(data.encode(locale.getpreferredencoding()) + '\n') 
     246            sys.stdout.write(data.encode(locale.getpreferredencoding()) + 
     247                             '\n') 
     248        elif cmd in ['--list-playlists']: 
     249            playlists = self.remote_control.list_playlists() 
     250            for pl in playlists: 
     251                sys.stdout.write('%s\n' % 
     252                                 pl.encode(locale.getpreferredencoding())) 
     253        elif cmd in ['--get-active-playlist']: 
     254            pl = self.remote_control.get_active_playlist() 
     255            if pl: 
     256                sys.stdout.write('%s\n' % 
     257                                 pl.encode(locale.getpreferredencoding())) 
     258## FIXME 
     259#        elif cmd in ['--enqueue-uri']: 
     260#            uri, pl = self.opts.enqueue_uri 
     261#            self.remote_control.enqueue_uri(uri, pl) 
    246262        else: 
    247263            assert(False) # This should not happen 
     
    313329                           help=_('Returns the length (in seconds) of the ' 
    314330                                  'current audio source.')) 
     331        rc_opts.add_option('--list-playlists', action='store_true', 
     332                           help=_('List all playlists.')) 
     333        rc_opts.add_option('--get-active-playlist', action='store_true', 
     334                           help=_('List the name of the active ' 
     335                                  'PlaylistControl.  This value may be empty.')) 
     336## FIXME 
     337#        rc_opts.add_option('--enqueue-uri', type='string', action='store', 
     338#                           nargs=2, metavar='URI PLAYLIST', 
     339#                           help=_('Enqueue a URI to PLAYLIST. The playlist ' 
     340#                                  'is opened if not already.')) 
    315341        self.add_option_group(rc_opts) 
    316342 
  • trunk/src/main_window.py

    r528 r529  
    135135            self.DBUS_SUPPORT = True 
    136136            session_bus = dbus.SessionBus() 
    137             name = dbus.service.BusName(dbus_service.SERVICE, bus=session_bus) 
     137            service_id = dbus_service.get_service_name(self.profile) 
     138            name = dbus.service.BusName(service_id, bus=session_bus) 
    138139            self.mesk_dbus = dbus_service.MeskDbusService(name, self.profile, 
    139140                                                          self) 
  • trunk/src/playlist_control.py

    r527 r529  
    7070        self._playlist = None 
    7171        self._playlist_save_id = None 
    72         self._is_active = self._initial_active = False 
     72        self._initial_active = False 
    7373        self._audio_control = None 
    7474        self._row_activated_awaiting_active = None 
     
    288288 
    289289    def set_active(self, active=True, audio_ctrl=None): 
     290        control.Control.set_active(self, active, audio_ctrl) 
    290291 
    291292        if not active: 
     
    295296        else: 
    296297            self._audio_control = audio_ctrl 
    297         self._is_active = active 
    298298 
    299299        # Connect events for audio_control on first activation