Changeset 134
- Timestamp:
- 03/28/06 18:30:39 (3 years ago)
- Files:
-
- trunk/src/plugins/gajimstatus.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/plugins/gajimstatus.py
r133 r134 36 36 UPDATE_STATUS_STATES = ['chat', 'online'] 37 37 NOW_PLAYING_HEADER = '\nnp: ' 38 NOW_PLAYING_MIDDLE = ' - ' 38 39 NOW_PLAYING_FOOTER = '\n' 39 NOW_PLAYING_MIDDLE = ' by '40 40 NOW_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' 42 42 43 43 class GajimStatusPlugin(Plugin, AudioControlListener): … … 63 63 64 64 # TODO: Verify accounts exist 65 66 def shutdown(self): 67 self.change_status(audio_src = None) 65 68 66 69 def _update_status_map(self): … … 101 104 102 105 def _get_now_playing_str(self, audio_src, status_template, state_str = ''): 103 title = ''104 artist = ''105 106 if audio_src: 106 107 title = audio_src.meta_data.title.encode('utf-8') 107 108 artist = audio_src.meta_data.artist.encode('utf-8') 108 109 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 = '' 117 120 return status_template % {'now_playing': now_playing} 118 121 119 122 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) 121 126 122 127 def on_plugin_audio_pause(self, audio_src): 123 print "PAUSED"128 self.change_status(audio_src, _(' [paused]')) 124 129 def on_plugin_audio_stop(self, audio_src): 125 print "STOPPED"130 self.change_status(None, interval = 0) 126 131 127 def change_status(self, audio_src ):132 def change_status(self, audio_src, state = '', interval = 0): 128 133 if self.update_task: 129 134 self.update_task.cancel() 130 135 131 136 # 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]) 134 139 self.update_task.start() 135 140 136 def _change_status(self, audio_src ):141 def _change_status(self, audio_src, state = ''): 137 142 self._update_status_map() 138 143 for acct in self.status_map.keys(): … … 141 146 if status not in UPDATE_STATUS_STATES: 142 147 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"' % \ 145 150 (status, status_msg)) 146 151 … … 148 153 command = 'gajim-remote %s %s 2> /dev/null' % (command, acct) 149 154 stat, output = getstatusoutput(command) 150 self.log.debug('Executing: %s' % (command,))151 print output152 155 return (stat, output) 153 156
