comparison frontends/src/quick_frontend/quick_app.py @ 587:952322b1d490

Remove trailing whitespaces.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:34 +0100
parents 9902ec2d8d9b
children 84a6e83157c2
comparison
equal deleted inserted replaced
586:6a718ede8be1 587:952322b1d490
35 35
36 def __init__(self, single_profile=True): 36 def __init__(self, single_profile=True):
37 self.profiles = {} 37 self.profiles = {}
38 self.single_profile = single_profile 38 self.single_profile = single_profile
39 self.check_options() 39 self.check_options()
40 40
41 ## bridge ## 41 ## bridge ##
42 try: 42 try:
43 self.bridge=DBusBridgeFrontend() 43 self.bridge=DBusBridgeFrontend()
44 except BridgeExceptionNoService: 44 except BridgeExceptionNoService:
45 print(_(u"Can't connect to SàT backend, are you sure it's launched ?")) 45 print(_(u"Can't connect to SàT backend, are you sure it's launched ?"))
79 self.bridge.register("quizGamePlayerBuzzed", self.quizGamePlayerBuzzed, "plugin") 79 self.bridge.register("quizGamePlayerBuzzed", self.quizGamePlayerBuzzed, "plugin")
80 self.bridge.register("quizGamePlayerSays", self.quizGamePlayerSays, "plugin") 80 self.bridge.register("quizGamePlayerSays", self.quizGamePlayerSays, "plugin")
81 self.bridge.register("quizGameAnswerResult", self.quizGameAnswerResult, "plugin") 81 self.bridge.register("quizGameAnswerResult", self.quizGameAnswerResult, "plugin")
82 self.bridge.register("quizGameTimerExpired", self.quizGameTimerExpired, "plugin") 82 self.bridge.register("quizGameTimerExpired", self.quizGameTimerExpired, "plugin")
83 self.bridge.register("quizGameTimerRestarted", self.quizGameTimerRestarted, "plugin") 83 self.bridge.register("quizGameTimerRestarted", self.quizGameTimerRestarted, "plugin")
84 84
85 self.current_action_ids = set() 85 self.current_action_ids = set()
86 self.current_action_ids_cb = {} 86 self.current_action_ids_cb = {}
87 self.media_dir = self.bridge.getConfig('','media_dir') 87 self.media_dir = self.bridge.getConfig('','media_dir')
88 88
89 def check_profile(self, profile): 89 def check_profile(self, profile):
90 """Tell if the profile is currently followed by the application""" 90 """Tell if the profile is currently followed by the application"""
91 return profile in self.profiles.keys() 91 return profile in self.profiles.keys()
92 92
93 def postInit(self): 93 def postInit(self):
94 """Must be called after initialization is done, do all automatic task (auto plug profile)""" 94 """Must be called after initialization is done, do all automatic task (auto plug profile)"""
95 if self.options.profile: 95 if self.options.profile:
96 if not self.bridge.getProfileName(self.options.profile): 96 if not self.bridge.getProfileName(self.options.profile):
97 error(_("Trying to plug an unknown profile (%s)" % self.options.profile)) 97 error(_("Trying to plug an unknown profile (%s)" % self.options.profile))
98 else: 98 else:
99 self.plug_profile(self.options.profile) 99 self.plug_profile(self.options.profile)
100 100
101 def check_options(self): 101 def check_options(self):
114 self.options.profile = self.options.profile.decode('utf-8') 114 self.options.profile = self.options.profile.decode('utf-8')
115 return args 115 return args
116 116
117 def _getParamError(self, ignore): 117 def _getParamError(self, ignore):
118 error(_("Can't get profile parameter")) 118 error(_("Can't get profile parameter"))
119 119
120 def plug_profile(self, profile_key='@DEFAULT@'): 120 def plug_profile(self, profile_key='@DEFAULT@'):
121 """Tell application which profile must be used""" 121 """Tell application which profile must be used"""
122 if self.single_profile and self.profiles: 122 if self.single_profile and self.profiles:
123 error(_('There is already one profile plugged (we are in single profile mode) !')) 123 error(_('There is already one profile plugged (we are in single profile mode) !'))
124 return 124 return
130 warning(_("The profile is already plugged")) 130 warning(_("The profile is already plugged"))
131 return 131 return
132 self.profiles[profile]={} 132 self.profiles[profile]={}
133 if self.single_profile: 133 if self.single_profile:
134 self.profile = profile 134 self.profile = profile
135 135
136 ###now we get the essential params### 136 ###now we get the essential params###
137 self.bridge.asyncGetParamA("JabberID","Connection", profile_key=profile, 137 self.bridge.asyncGetParamA("JabberID","Connection", profile_key=profile,
138 callback=lambda _jid: self.plug_profile_2(_jid, profile), errback=self._getParamError) 138 callback=lambda _jid: self.plug_profile_2(_jid, profile), errback=self._getParamError)
139 139
140 def plug_profile_2(self, _jid, profile): 140 def plug_profile_2(self, _jid, profile):
141 self.profiles[profile]['whoami'] = JID(_jid) 141 self.profiles[profile]['whoami'] = JID(_jid)
142 self.bridge.asyncGetParamA("autoconnect","Connection", profile_key=profile, 142 self.bridge.asyncGetParamA("autoconnect","Connection", profile_key=profile,
143 callback=lambda value: self.plug_profile_3(value=="true", profile), errback=self._getParamError) 143 callback=lambda value: self.plug_profile_3(value=="true", profile), errback=self._getParamError)
144 144
150 if autoconnect and not self.bridge.isConnected(profile): 150 if autoconnect and not self.bridge.isConnected(profile):
151 #Does the user want autoconnection ? 151 #Does the user want autoconnection ?
152 self.bridge.asyncConnect(profile, callback=lambda: self.plug_profile_5(watched, autoconnect, profile), errback=lambda ignore: error(_('Error during autoconnection'))) 152 self.bridge.asyncConnect(profile, callback=lambda: self.plug_profile_5(watched, autoconnect, profile), errback=lambda ignore: error(_('Error during autoconnection')))
153 else: 153 else:
154 self.plug_profile_5(watched, autoconnect, profile) 154 self.plug_profile_5(watched, autoconnect, profile)
155 155
156 def plug_profile_5(self, watched, autoconnect, profile): 156 def plug_profile_5(self, watched, autoconnect, profile):
157 self.profiles[profile]['watched'] = watched.split() #TODO: put this in a plugin 157 self.profiles[profile]['watched'] = watched.split() #TODO: put this in a plugin
158 158
159 ## misc ## 159 ## misc ##
160 self.profiles[profile]['onlineContact'] = set() #FIXME: temporary 160 self.profiles[profile]['onlineContact'] = set() #FIXME: temporary
196 196
197 #Finaly, we get the waiting confirmation requests 197 #Finaly, we get the waiting confirmation requests
198 for confirm_id, confirm_type, data in self.bridge.getWaitingConf(profile): 198 for confirm_id, confirm_type, data in self.bridge.getWaitingConf(profile):
199 self.askConfirmation(confirm_id, confirm_type, data, profile) 199 self.askConfirmation(confirm_id, confirm_type, data, profile)
200 200
201 201
202 202
203 def unplug_profile(self, profile): 203 def unplug_profile(self, profile):
204 """Tell the application to not follow anymore the profile""" 204 """Tell the application to not follow anymore the profile"""
205 if not profile in self.profiles: 205 if not profile in self.profiles:
206 warning (_("This profile is not plugged")) 206 warning (_("This profile is not plugged"))
222 if not self.check_profile(profile): 222 if not self.check_profile(profile):
223 return 223 return
224 debug(_("Disconnected")) 224 debug(_("Disconnected"))
225 self.contact_list.clearContacts() 225 self.contact_list.clearContacts()
226 self.setStatusOnline(False) 226 self.setStatusOnline(False)
227 227
228 def connectionError(self, error_type, profile): 228 def connectionError(self, error_type, profile):
229 """called when something goest wrong with the connection""" 229 """called when something goest wrong with the connection"""
230 if not self.check_profile(profile): 230 if not self.check_profile(profile):
231 return 231 return
232 debug(_("Connection Error")) 232 debug(_("Connection Error"))
248 if a private MUC message is detected, from_jid or to_jid is prefixed and resource is escaped""" 248 if a private MUC message is detected, from_jid or to_jid is prefixed and resource is escaped"""
249 if not self.check_profile(profile): 249 if not self.check_profile(profile):
250 return 250 return
251 from_jid = JID(from_jid_s) 251 from_jid = JID(from_jid_s)
252 to_jid = JID(to_jid_s) 252 to_jid = JID(to_jid_s)
253 253
254 from_me = from_jid.short == self.profiles[profile]['whoami'].short 254 from_me = from_jid.short == self.profiles[profile]['whoami'].short
255 win = to_jid if from_me else from_jid 255 win = to_jid if from_me else from_jid
256 256
257 if _type != "groupchat" and self.contact_list.getSpecial(win) == "MUC": 257 if _type != "groupchat" and self.contact_list.getSpecial(win) == "MUC":
258 #we have a private message in a MUC room 258 #we have a private message in a MUC room
259 #XXX: normaly we use bare jid as key, here we need the full jid 259 #XXX: normaly we use bare jid as key, here we need the full jid
260 # so we cheat by replacing the "/" before the resource by 260 # so we cheat by replacing the "/" before the resource by
261 # a "@", so the jid is invalid, 261 # a "@", so the jid is invalid,
262 new_jid = escapePrivate(win) 262 new_jid = escapePrivate(win)
263 if from_me: 263 if from_me:
264 to_jid = new_jid 264 to_jid = new_jid
265 else: 265 else:
266 from_jid = new_jid 266 from_jid = new_jid
267 if new_jid not in self.contact_list: 267 if new_jid not in self.contact_list:
268 self.contact_list.add(new_jid) 268 self.contact_list.add(new_jid)
269 269
270 self.newMessage(from_jid, to_jid, msg, _type, extra, profile) 270 self.newMessage(from_jid, to_jid, msg, _type, extra, profile)
271 271
272 def newMessage(self, from_jid, to_jid, msg, _type, extra, profile): 272 def newMessage(self, from_jid, to_jid, msg, _type, extra, profile):
273 from_me = from_jid.short == self.profiles[profile]['whoami'].short 273 from_me = from_jid.short == self.profiles[profile]['whoami'].short
274 win = to_jid if from_me else from_jid 274 win = to_jid if from_me else from_jid
275 275
276 self.current_action_ids = set() 276 self.current_action_ids = set()
277 self.current_action_ids_cb = {} 277 self.current_action_ids_cb = {}
278 278
279 timestamp = extra.get('archive') 279 timestamp = extra.get('archive')
280 self.chat_wins[win.short].printMessage(from_jid, msg, profile, float(timestamp) if timestamp else '') 280 self.chat_wins[win.short].printMessage(from_jid, msg, profile, float(timestamp) if timestamp else '')
289 if not self.check_profile(profile): 289 if not self.check_profile(profile):
290 return 290 return
291 assert alert_type in ['INFO','ERROR'] 291 assert alert_type in ['INFO','ERROR']
292 self.showDialog(unicode(msg),unicode(title),alert_type.lower()) 292 self.showDialog(unicode(msg),unicode(title),alert_type.lower())
293 293
294 294
295 def setStatusOnline(self, online=True): 295 def setStatusOnline(self, online=True):
296 pass 296 pass
297 297
298 def presenceUpdate(self, jabber_id, show, priority, statuses, profile): 298 def presenceUpdate(self, jabber_id, show, priority, statuses, profile):
299 if not self.check_profile(profile): 299 if not self.check_profile(profile):
307 self.setStatusOnline(True) 307 self.setStatusOnline(True)
308 elif type=="unavailable": 308 elif type=="unavailable":
309 self.setStatusOnline(False) 309 self.setStatusOnline(False)
310 return 310 return
311 311
312 self.contact_list.updatePresence(from_jid, show, priority, statuses) 312 self.contact_list.updatePresence(from_jid, show, priority, statuses)
313 313
314 if show != 'unavailable': 314 if show != 'unavailable':
315 315
316 #FIXME: must be moved in a plugin 316 #FIXME: must be moved in a plugin
317 if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']: 317 if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']:
318 self.showAlert(_("Watched jid [%s] is connected !") % from_jid.short) 318 self.showAlert(_("Watched jid [%s] is connected !") % from_jid.short)
319 319
320 self.profiles[profile]['onlineContact'].add(from_jid) #FIXME onlineContact is useless with CM, must be removed 320 self.profiles[profile]['onlineContact'].add(from_jid) #FIXME onlineContact is useless with CM, must be removed
321 321
322 #TODO: vcard data (avatar) 322 #TODO: vcard data (avatar)
323 323
324 if show=="unavailable" and from_jid in self.profiles[profile]['onlineContact']: 324 if show=="unavailable" and from_jid in self.profiles[profile]['onlineContact']:
325 self.profiles[profile]['onlineContact'].remove(from_jid) 325 self.profiles[profile]['onlineContact'].remove(from_jid)
326 326
327 def roomJoined(self, room_jid, room_nicks, user_nick, profile): 327 def roomJoined(self, room_jid, room_nicks, user_nick, profile):
328 """Called when a MUC room is joined""" 328 """Called when a MUC room is joined"""
329 if not self.check_profile(profile): 329 if not self.check_profile(profile):
330 return 330 return
331 debug (_("Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s") % {'room_jid':room_jid, 'profile': profile, 'users':room_nicks}) 331 debug (_("Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s") % {'room_jid':room_jid, 'profile': profile, 'users':room_nicks})
372 if not self.check_profile(profile): 372 if not self.check_profile(profile):
373 return 373 return
374 if self.chat_wins.has_key(room_jid): 374 if self.chat_wins.has_key(room_jid):
375 self.chat_wins[room_jid].setSubject(subject) 375 self.chat_wins[room_jid].setSubject(subject)
376 debug (_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid':room_jid, "subject":subject}) 376 debug (_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid':room_jid, "subject":subject})
377 377
378 def tarotGameStarted(self, room_jid, referee, players, profile): 378 def tarotGameStarted(self, room_jid, referee, players, profile):
379 if not self.check_profile(profile): 379 if not self.check_profile(profile):
380 return 380 return
381 debug (_("Tarot Game Started \o/")) 381 debug (_("Tarot Game Started \o/"))
382 if self.chat_wins.has_key(room_jid): 382 if self.chat_wins.has_key(room_jid):
383 self.chat_wins[room_jid].startGame("Tarot", referee, players) 383 self.chat_wins[room_jid].startGame("Tarot", referee, players)
384 debug (_("new Tarot game started by [%(referee)s] in room [%(room_jid)s] with %(players)s") % {'referee':referee, 'room_jid':room_jid, 'players':[str(player) for player in players]}) 384 debug (_("new Tarot game started by [%(referee)s] in room [%(room_jid)s] with %(players)s") % {'referee':referee, 'room_jid':room_jid, 'players':[str(player) for player in players]})
385 385
386 def tarotGameNew(self, room_jid, hand, profile): 386 def tarotGameNew(self, room_jid, hand, profile):
387 if not self.check_profile(profile): 387 if not self.check_profile(profile):
388 return 388 return
389 debug (_("New Tarot Game")) 389 debug (_("New Tarot Game"))
390 if self.chat_wins.has_key(room_jid): 390 if self.chat_wins.has_key(room_jid):
409 if not self.check_profile(profile): 409 if not self.check_profile(profile):
410 return 410 return
411 debug (_("My turn to play")) 411 debug (_("My turn to play"))
412 if self.chat_wins.has_key(room_jid): 412 if self.chat_wins.has_key(room_jid):
413 self.chat_wins[room_jid].getGame("Tarot").myTurn() 413 self.chat_wins[room_jid].getGame("Tarot").myTurn()
414 414
415 def tarotScore(self, room_jid, xml_data, winners, loosers, profile): 415 def tarotScore(self, room_jid, xml_data, winners, loosers, profile):
416 """Called when the game is finished and the score are updated""" 416 """Called when the game is finished and the score are updated"""
417 if not self.check_profile(profile): 417 if not self.check_profile(profile):
418 return 418 return
419 debug (_("Tarot: score received")) 419 debug (_("Tarot: score received"))
420 if self.chat_wins.has_key(room_jid): 420 if self.chat_wins.has_key(room_jid):
424 if not self.check_profile(profile): 424 if not self.check_profile(profile):
425 return 425 return
426 debug (_("Card(s) played (%(player)s): %(cards)s") % {"player":player, "cards":cards}) 426 debug (_("Card(s) played (%(player)s): %(cards)s") % {"player":player, "cards":cards})
427 if self.chat_wins.has_key(room_jid): 427 if self.chat_wins.has_key(room_jid):
428 self.chat_wins[room_jid].getGame("Tarot").cardsPlayed(player, cards) 428 self.chat_wins[room_jid].getGame("Tarot").cardsPlayed(player, cards)
429 429
430 def tarotInvalidCards(self, room_jid, phase, played_cards, invalid_cards, profile): 430 def tarotInvalidCards(self, room_jid, phase, played_cards, invalid_cards, profile):
431 if not self.check_profile(profile): 431 if not self.check_profile(profile):
432 return 432 return
433 debug (_("Cards played are not valid: %s") % invalid_cards) 433 debug (_("Cards played are not valid: %s") % invalid_cards)
434 if self.chat_wins.has_key(room_jid): 434 if self.chat_wins.has_key(room_jid):
435 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) 435 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards)
436 436
437 def quizGameStarted(self, room_jid, referee, players, profile): 437 def quizGameStarted(self, room_jid, referee, players, profile):
438 if not self.check_profile(profile): 438 if not self.check_profile(profile):
439 return 439 return
440 debug (_("Quiz Game Started \o/")) 440 debug (_("Quiz Game Started \o/"))
441 if self.chat_wins.has_key(room_jid): 441 if self.chat_wins.has_key(room_jid):
442 self.chat_wins[room_jid].startGame("Quiz", referee, players) 442 self.chat_wins[room_jid].startGame("Quiz", referee, players)
443 debug (_("new Quiz game started by [%(referee)s] in room [%(room_jid)s] with %(players)s") % {'referee':referee, 'room_jid':room_jid, 'players':[str(player) for player in players]}) 443 debug (_("new Quiz game started by [%(referee)s] in room [%(room_jid)s] with %(players)s") % {'referee':referee, 'room_jid':room_jid, 'players':[str(player) for player in players]})
444 444
445 def quizGameNew(self, room_jid, data, profile): 445 def quizGameNew(self, room_jid, data, profile):
446 if not self.check_profile(profile): 446 if not self.check_profile(profile):
447 return 447 return
448 debug (_("New Quiz Game")) 448 debug (_("New Quiz Game"))
449 if self.chat_wins.has_key(room_jid): 449 if self.chat_wins.has_key(room_jid):
475 """Called when a player say something""" 475 """Called when a player say something"""
476 if not self.check_profile(profile): 476 if not self.check_profile(profile):
477 return 477 return
478 if self.chat_wins.has_key(room_jid): 478 if self.chat_wins.has_key(room_jid):
479 self.chat_wins[room_jid].getGame("Quiz").quizGameAnswerResult(player, good_answer, score) 479 self.chat_wins[room_jid].getGame("Quiz").quizGameAnswerResult(player, good_answer, score)
480 480
481 def quizGameTimerExpired(self, room_jid, profile): 481 def quizGameTimerExpired(self, room_jid, profile):
482 """Called when nobody answered the question in time""" 482 """Called when nobody answered the question in time"""
483 if not self.check_profile(profile): 483 if not self.check_profile(profile):
484 return 484 return
485 if self.chat_wins.has_key(room_jid): 485 if self.chat_wins.has_key(room_jid):
514 # this is a subscriptionn request, we have to ask for user confirmation 514 # this is a subscriptionn request, we have to ask for user confirmation
515 answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.short, _('Subscription confirmation'), 'yes/no', answer_cb = self._subscribe_cb, answer_data=(entity, profile)) 515 answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.short, _('Subscription confirmation'), 'yes/no', answer_cb = self._subscribe_cb, answer_data=(entity, profile))
516 516
517 def showDialog(self, message, title, type="info", answer_cb = None): 517 def showDialog(self, message, title, type="info", answer_cb = None):
518 raise NotImplementedError 518 raise NotImplementedError
519 519
520 def showAlert(self, message): 520 def showAlert(self, message):
521 pass #FIXME 521 pass #FIXME
522 522
523 def paramUpdate(self, name, value, namespace, profile): 523 def paramUpdate(self, name, value, namespace, profile):
524 if not self.check_profile(profile): 524 if not self.check_profile(profile):
525 return 525 return
526 debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace':namespace, 'name':name, 'value':value}) 526 debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace':namespace, 'name':name, 'value':value})
527 if (namespace,name) == ("Connection", "JabberID"): 527 if (namespace,name) == ("Connection", "JabberID"):
554 self.contact_list.setCache(jid, 'avatar', filename) 554 self.contact_list.setCache(jid, 'avatar', filename)
555 self.contact_list.replace(jid) 555 self.contact_list.replace(jid)
556 556
557 def askConfirmation(self, confirm_id, confirm_type, data, profile): 557 def askConfirmation(self, confirm_id, confirm_type, data, profile):
558 raise NotImplementedError 558 raise NotImplementedError
559 559
560 def actionResult(self, type, id, data): 560 def actionResult(self, type, id, data):
561 raise NotImplementedError 561 raise NotImplementedError
562 562
563 def onExit(self): 563 def onExit(self):
564 """Must be called when the frontend is terminating""" 564 """Must be called when the frontend is terminating"""