Changeset 339
- Timestamp:
- 06/28/06 21:33:16 (3 years ago)
- Files:
-
- trunk/src/plugins/gajimstatus.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/plugins/gajimstatus.py
r334 r339 19 19 # $Id$ 20 20 ################################################################################ 21 import os, re,locale21 import os, locale 22 22 import threading 23 23 from commands import getstatusoutput … … 40 40 41 41 UPDATE_STATUS_STATES = ['chat', 'online', 'dnd'] 42 43 # Test whether the local encoding can support U+266B 42 44 NOW_PLAYING_HEADER = u'\nâ«:' 45 try: 46 s = NOW_PLAYING_HEADER.encode(locale.getpreferredencoding()) 47 except: 48 # Fallback on the original header 49 NOW_PLAYING_HEADER = u'\nnp:' 43 50 NOW_PLAYING_DELIM = ' - ' 44 51 NOW_PLAYING_FOOTER = '\n' … … 69 76 70 77 def _update_status_map(self): 71 now_playing_regex = re.compile('%(header)s.*%(middle)s.*%(footer)s' % \72 {'header': NOW_PLAYING_HEADER,73 'middle': NOW_PLAYING_DELIM,74 'footer': NOW_PLAYING_FOOTER,75 })76 78 77 79 for acct in self.status_map.keys(): … … 95 97 continue 96 98 97 # FIXME 98 # If current status message contains data we put there, it must 99 # be removed 100 (status_msg, subs) = now_playing_regex.subn('%(now_playing)s', 101 status_msg) 102 if subs == 0: 103 status_msg += '%(now_playing)s' 99 # Substitute a previous tune with the new. This tries to preserve 100 # any additional status the user has set. 101 if status_msg.startswith(NOW_PLAYING_HEADER): 102 # Status starts with a tune we put there, so just replace 103 status_msg = '%(now_playing)s' 104 else: 105 # User has custom status... 106 curr_idx = status_msg.find(NOW_PLAYING_HEADER) 107 if curr_idx == -1: 108 # Append 109 status_msg += '%(now_playing)s' 110 else: 111 # Replace 112 status_msg = status_msg[:curr_idx] + '%(now_playing)s' 104 113 self.log.debug('Updating status template for %s: %s' % (acct, 105 114 status_msg)) 106 # FIXME 107 #self.status_map[acct] = (status, status_msg) 108 self.status_map[acct] = (status, '%(now_playing)s') 115 self.status_map[acct] = (status, status_msg) 109 116 110 117 def _get_now_playing_str(self, audio_src, status_template, state_str = ''): … … 114 121 album = audio_src.meta_data.album 115 122 116 # Test whether the local encoding can support U+266B117 try:118 s = NOW_PLAYING_HEADER.encode(locale.getpreferredencoding())119 except:120 header = '\n'121 else:122 header = NOW_PLAYING_HEADER123 124 123 now_playing = NOW_PLAYING_FORMAT % \ 125 {'header': header,124 {'header': NOW_PLAYING_HEADER, 126 125 'title': title, 127 126 'middle': NOW_PLAYING_DELIM, … … 170 169 stat, output = getstatusoutput(command) 171 170 self.log.debug('%s returned:\n%s' % (command, output)) 172 return (stat, output)171 return (stat, unicode(output, locale.getpreferredencoding())) 173 172 174 173 def is_configurable(self):
