Changeset 7841 for branches/gajim_0.11/src/common
- Timestamp:
- 01/15/07 19:51:27 (23 months ago)
- Location:
- branches/gajim_0.11/src/common
- Files:
-
- 2 modified
-
commands.py (modified) (14 diffs)
-
config.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/gajim_0.11/src/common/commands.py
r7829 r7841 26 26 ''' This returns True if that command should be visible and invokable 27 27 for others. 28 samejid - True when command is invoked by an entity with the same bare jid.29 '''28 samejid - True when command is invoked by an entity with the same bare 29 jid.''' 30 30 return True 31 31 … … 35 35 self.sessionid = sessionid 36 36 37 def buildResponse(self, request, status='executing', defaultaction=None, actions=None): 37 def buildResponse(self, request, status = 'executing', defaultaction = None, 38 actions = None): 38 39 assert status in ('executing', 'completed', 'canceled') 39 40 … … 46 47 if defaultaction is not None or actions is not None: 47 48 if defaultaction is not None: 48 assert defaultaction in ('cancel', 'execute', 'prev', 'next', 'complete') 49 assert defaultaction in ('cancel', 'execute', 'prev', 'next', 50 'complete') 49 51 attrs = {'action': defaultaction} 50 52 else: … … 55 57 56 58 def badRequest(self, stanza): 57 self.connection.connection.send(xmpp.Error(stanza, xmpp.NS_STANZAS+' bad-request')) 59 self.connection.connection.send(xmpp.Error(stanza, xmpp.NS_STANZAS + \ 60 ' bad-request')) 58 61 59 62 def cancel(self, request): 60 response, cmd = self.buildResponse(request, status ='canceled')63 response, cmd = self.buildResponse(request, status = 'canceled') 61 64 self.connection.connection.send(response) 62 65 return False # finish the session … … 64 67 class ChangeStatusCommand(AdHocCommand): 65 68 commandnode = 'change-status' 66 commandname = 'Change status information'69 commandname = _('Change status information') 67 70 68 71 @staticmethod … … 73 76 def execute(self, request): 74 77 # first query... 75 response, cmd = self.buildResponse(request, defaultaction='execute', actions=['execute']) 78 response, cmd = self.buildResponse(request, defaultaction = 'execute', 79 actions = ['execute']) 76 80 77 cmd.addChild(node =dataforms.SimpleDataForm(78 title ='Change status',79 instructions ='Set the presence type and description',80 fields =[81 cmd.addChild(node = dataforms.SimpleDataForm( 82 title = _('Change status'), 83 instructions = _('Set the presence type and description'), 84 fields = [ 81 85 dataforms.Field('list-single', 82 var ='presence-type',83 label ='Type of presence:',84 options =[85 (u'free-for-chat', u'Free for chat'),86 (u'online', u'Online'),87 (u'away', u'Away'),88 (u'xa', u'Extended away'),89 (u'dnd', u'Do not disturb'),90 (u'offline', u'Offline - disconnect')],91 value ='online',92 required =True),86 var = 'presence-type', 87 label = 'Type of presence:', 88 options = [ 89 (u'free-for-chat', _('Free for chat')), 90 (u'online', _('Online')), 91 (u'away', _('Away')), 92 (u'xa', _('Extended away')), 93 (u'dnd', _('Do not disturb')), 94 (u'offline', _('Offline - disconnect'))], 95 value = 'online', 96 required = True), 93 97 dataforms.Field('text-multi', 94 var ='presence-desc',95 label ='Presence description:')]))98 var = 'presence-desc', 99 label = _('Presence description:'))])) 96 100 97 101 self.connection.connection.send(response) … … 105 109 # check if the data is correct 106 110 try: 107 form=dataforms.SimpleDataForm(extend=request.getTag('command').getTag('x')) 111 form = dataforms.SimpleDataForm(extend = request.getTag('command').\ 112 getTag('x')) 108 113 except: 109 114 self.badRequest(request) 110 115 return False 111 116 112 117 try: 113 118 presencetype = form['presence-type'].value … … 126 131 presencedesc = u'' 127 132 128 response, cmd = self.buildResponse(request, status ='completed')129 cmd.addChild('note', {}, 'The status has been changed.')133 response, cmd = self.buildResponse(request, status = 'completed') 134 cmd.addChild('note', {}, _('The status has been changed.')) 130 135 131 136 # if going offline, we need to push response so it won't go into 132 137 # queue and disappear 133 self.connection.connection.send(response, presencetype =='offline')138 self.connection.connection.send(response, presencetype == 'offline') 134 139 135 140 # send new status 136 gajim.interface.roster.send_status(self.connection.name, presencetype, presencedesc) 141 gajim.interface.roster.send_status(self.connection.name, presencetype, 142 presencedesc) 137 143 138 144 return False # finish the session 145 146 def find_current_groupchats(account): 147 import message_control 148 rooms = [] 149 for gc_control in gajim.interface.msg_win_mgr.get_controls( 150 message_control.TYPE_GC): 151 acct = gc_control.account 152 # check if account is the good one 153 if acct != account: 154 continue 155 room_jid = gc_control.room_jid 156 nick = gc_control.nick 157 if gajim.gc_connected[acct].has_key(room_jid) and \ 158 gajim.gc_connected[acct][room_jid]: 159 rooms.append((room_jid, nick,)) 160 return rooms 161 162 163 class LeaveGroupchatsCommand(AdHocCommand): 164 commandnode = 'leave-groupchats' 165 commandname = 'Leave Groupchats' 166 167 @staticmethod 168 def isVisibleFor(samejid): 169 ''' Change status is visible only if the entity has the same bare jid. ''' 170 return samejid 171 172 def execute(self, request): 173 # first query... 174 response, cmd = self.buildResponse(request, defaultaction = 'execute', 175 actions=['execute']) 176 options = [] 177 account = self.connection.name 178 for gc in find_current_groupchats(account): 179 options.append((u'%s' %(gc[0]), _('%(nickname)s on %(room_jid)s') % \ 180 {'nickname': gc[1], 'room_jid': gc[0]})) 181 if not len(options): 182 response, cmd = self.buildResponse(request, status = 'completed') 183 cmd.addChild('note', {}, _('You have not joined a groupchat.')) 184 185 self.connection.connection.send(response) 186 return False 187 188 cmd.addChild(node=dataforms.SimpleDataForm( 189 title = _('Leave Groupchats'), 190 instructions = _('Choose the groupchats you want to leave'), 191 fields=[ 192 dataforms.Field('list-multi', 193 var = 'groupchats', 194 label = _('Groupchats'), 195 options = options, 196 required = True)])) 197 198 self.connection.connection.send(response) 199 200 # for next invocation 201 self.execute = self.leavegroupchats 202 203 return True # keep the session 204 205 def leavegroupchats(self, request): 206 # check if the data is correct 207 try: 208 form = dataforms.SimpleDataForm(extend = request.getTag('command').\ 209 getTag('x')) 210 except: 211 self.badRequest(request) 212 return False 213 214 try: 215 gc = form['groupchats'].values 216 except: # KeyError if there's no presence-type field in form or 217 # AttributeError if that field is of wrong type 218 self.badRequest(request) 219 return False 220 account = self.connection.name 221 try: 222 for room_jid in gc: 223 gc_control = gajim.interface.msg_win_mgr.get_control(room_jid, 224 account) 225 gc_control.parent_win.remove_tab(gc_control, None, force = True) 226 except: # KeyError if there's no presence-type field in form or 227 self.badRequest(request) 228 return False 229 response, cmd = self.buildResponse(request, status = 'completed') 230 note = _('You leaved the following groupchats:') 231 for room_jid in gc: 232 note += '\n\t' + room_jid 233 cmd.addChild('note', {}, note) 234 235 self.connection.connection.send(response) 236 return False 237 139 238 140 239 class ConnectionCommands: … … 143 242 # a list of all commands exposed: node -> command class 144 243 self.__commands = {} 145 for cmdobj in (ChangeStatusCommand, ):244 for cmdobj in (ChangeStatusCommand, LeaveGroupchatsCommand): 146 245 self.__commands[cmdobj.commandnode] = cmdobj 147 246 … … 165 264 q.addChild('item', { 166 265 # TODO: find the jid 167 'jid': self.getOurBareJID() +u'/'+self.server_resource,266 'jid': self.getOurBareJID() + u'/' + self.server_resource, 168 267 'node': node, 169 268 'name': cmd.commandname}) … … 210 309 if node not in self.__commands.keys(): 211 310 self.connection.send( 212 xmpp.Error(iq_obj, xmpp.NS_STANZAS +' item-not-found'))311 xmpp.Error(iq_obj, xmpp.NS_STANZAS + ' item-not-found')) 213 312 raise xmpp.NodeProcessed 214 313 … … 221 320 222 321 # create new instance and run it 223 obj = newcmd(conn =self, jid=jid, sessionid=sessionid)322 obj = newcmd(conn = self, jid = jid, sessionid = sessionid) 224 323 rc = obj.execute(iq_obj) 225 324 if rc: … … 237 336 238 337 try: 239 if action == 'cancel': rc = obj.cancel(iq_obj) 240 elif action == 'prev': rc = obj.prev(iq_obj) 241 elif action == 'next': rc = obj.next(iq_obj) 338 if action == 'cancel': 339 rc = obj.cancel(iq_obj) 340 elif action == 'prev': 341 rc = obj.prev(iq_obj) 342 elif action == 'next': 343 rc = obj.next(iq_obj) 242 344 elif action == 'execute' or action is None: 243 rc = obj.execute(iq_obj) 244 elif action == 'complete': rc = obj.complete(iq_obj) 345 rc = obj.execute(iq_obj) 346 elif action == 'complete': 347 rc = obj.complete(iq_obj) 245 348 else: 246 349 # action is wrong. stop the session, send error … … 257 360 258 361 raise xmpp.NodeProcessed 259 -
branches/gajim_0.11/src/common/config.py
r7829 r7841 131 131 'latest_disco_addresses': [ opt_str, '' ], 132 132 'recently_groupchat': [ opt_str, '' ], 133 ' before_nickname': [ opt_str, ''],134 ' time_stamp': [ opt_str, '[%H:%M] '],135 'after_nickname': [ opt_str, ':' ],133 'time_stamp': [ opt_str, '[%X] ', _('This option let you customize timestamp that is printed in conversation. For exemple "[%H:%M] " will show "[hour:minute] ". See python doc on strftime for full documentation: http://docs.python.org/lib/module-time.html') ], 134 'before_nickname': [ opt_str, '', _('Characters that are printed before the nickname in conversations') ], 135 'after_nickname': [ opt_str, ':', _('Characters that are printed after the nickname in conversations') ], 136 136 'send_os_info': [ opt_bool, True ], 137 137 'set_status_msg_from_current_music_track': [ opt_bool, False ],
