Changeset 134

Show
Ignore:
Timestamp:
03/28/06 18:30:39 (3 years ago)
Author:
nicfit
Message:

stop, pause, shutdown

Files:

Legend:

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

    r133 r134  
    3636UPDATE_STATUS_STATES = ['chat', 'online'] 
    3737NOW_PLAYING_HEADER = '\nnp: ' 
     38NOW_PLAYING_MIDDLE = ' - ' 
    3839NOW_PLAYING_FOOTER = '\n' 
    39 NOW_PLAYING_MIDDLE = ' by ' 
    4040NOW_PLAYING_FORMAT = \ 
    41   '%(header)s%(title)s%(middle)s%(artist)s%(state)s%(footer)s' 
     41  '%(header)s%(artist)s%(middle)s%(title)s%(state)s%(footer)s' 
    4242 
    4343class GajimStatusPlugin(Plugin, AudioControlListener):  
     
    6363 
    6464        # TODO: Verify accounts exist 
     65 
     66    def shutdown(self): 
     67        self.change_status(audio_src = None) 
    6568 
    6669    def _update_status_map(self): 
     
    101104 
    102105    def _get_now_playing_str(self, audio_src, status_template, state_str = ''): 
    103         title = '' 
    104         artist = '' 
    105106        if audio_src: 
    106107           title = audio_src.meta_data.title.encode('utf-8') 
    107108           artist = audio_src.meta_data.artist.encode('utf-8') 
    108109 
    109         now_playing = NOW_PLAYING_FORMAT % \ 
    110                       {'header': NOW_PLAYING_HEADER, 
    111                        'title': title, 
    112                        'middle': NOW_PLAYING_MIDDLE, 
    113                        'artist': artist, 
    114                        'state': state_str, 
    115                        'footer': NOW_PLAYING_FOOTER, 
    116                       } 
     110           now_playing = NOW_PLAYING_FORMAT % \ 
     111                         {'header': NOW_PLAYING_HEADER, 
     112                          'title': title, 
     113                          'middle': NOW_PLAYING_MIDDLE, 
     114                          'artist': artist, 
     115                          'state': state_str, 
     116                          'footer': NOW_PLAYING_FOOTER, 
     117                         } 
     118        else: 
     119            now_playing = '' 
    117120        return status_template % {'now_playing': now_playing} 
    118121 
    119122    def on_plugin_source_started(self, audio_src): 
    120         self.change_status(audio_src) 
     123        # Delay 5 seconds in case the source changes again the previous can 
     124        # be cancelled 
     125        self.change_status(audio_src, interval = 5.0) 
    121126 
    122127    def on_plugin_audio_pause(self, audio_src): 
    123         print "PAUSED" 
     128        self.change_status(audio_src, _(' [paused]')) 
    124129    def on_plugin_audio_stop(self, audio_src): 
    125         print "STOPPED" 
     130        self.change_status(None, interval = 0) 
    126131 
    127     def change_status(self, audio_src): 
     132    def change_status(self, audio_src, state = '', interval = 0): 
    128133        if self.update_task: 
    129134            self.update_task.cancel() 
    130135 
    131136        # Give it a few seconds, in case the song changes again 
    132         self.update_task = threading.Timer(5, self._change_status, 
    133                                            args = [audio_src]) 
     137        self.update_task = threading.Timer(interval, self._change_status, 
     138                                           args = [audio_src, state]) 
    134139        self.update_task.start() 
    135140 
    136     def _change_status(self, audio_src): 
     141    def _change_status(self, audio_src, state = ''): 
    137142        self._update_status_map() 
    138143        for acct in self.status_map.keys(): 
     
    141146            if status not in UPDATE_STATUS_STATES: 
    142147                continue 
    143             status_msg = self._get_now_playing_str(audio_src, status_msg
    144             self.gajim_remote(acct, 'change_status %s \'%s\'' % \ 
     148            status_msg = self._get_now_playing_str(audio_src, status_msg, state
     149            self.gajim_remote(acct, 'change_status %s "%s"' % \ 
    145150                                    (status, status_msg)) 
    146151 
     
    148153        command = 'gajim-remote %s %s 2> /dev/null' % (command, acct) 
    149154        stat, output = getstatusoutput(command) 
    150         self.log.debug('Executing: %s' % (command,)) 
    151         print output 
    152155        return (stat, output) 
    153156