Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_app.py @ 906:1cbae66fa725
quick_app: better PEP-8 compliance
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 16 Mar 2014 21:25:49 +0100 |
parents | 1fe00f0c9a91 |
children | cd02f5ef30df |
comparison
equal
deleted
inserted
replaced
905:cad8e52bb2e6 | 906:1cbae66fa725 |
---|---|
26 from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate | 26 from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate |
27 from optparse import OptionParser | 27 from optparse import OptionParser |
28 | 28 |
29 from sat_frontends.quick_frontend.constants import Const | 29 from sat_frontends.quick_frontend.constants import Const |
30 | 30 |
31 | |
31 class QuickApp(object): | 32 class QuickApp(object): |
32 """This class contain the main methods needed for the frontend""" | 33 """This class contain the main methods needed for the frontend""" |
33 | 34 |
34 def __init__(self, single_profile=True): | 35 def __init__(self, single_profile=True): |
35 self.profiles = {} | 36 self.profiles = {} |
36 self.single_profile = single_profile | 37 self.single_profile = single_profile |
37 self.check_options() | 38 self.check_options() |
38 | 39 |
39 ## bridge ## | 40 ## bridge ## |
40 try: | 41 try: |
41 self.bridge=DBusBridgeFrontend() | 42 self.bridge = DBusBridgeFrontend() |
42 except BridgeExceptionNoService: | 43 except BridgeExceptionNoService: |
43 print(_(u"Can't connect to SàT backend, are you sure it's launched ?")) | 44 print(_(u"Can't connect to SàT backend, are you sure it's launched ?")) |
44 sys.exit(1) | 45 sys.exit(1) |
45 except BridgeInitError: | 46 except BridgeInitError: |
46 print(_(u"Can't init bridge")) | 47 print(_(u"Can't init bridge")) |
83 self.bridge.register("quizGameTimerRestarted", self.quizGameTimerRestarted, "plugin") | 84 self.bridge.register("quizGameTimerRestarted", self.quizGameTimerRestarted, "plugin") |
84 self.bridge.register("chatStateReceived", self.chatStateReceived, "plugin") | 85 self.bridge.register("chatStateReceived", self.chatStateReceived, "plugin") |
85 | 86 |
86 self.current_action_ids = set() | 87 self.current_action_ids = set() |
87 self.current_action_ids_cb = {} | 88 self.current_action_ids_cb = {} |
88 self.media_dir = self.bridge.getConfig('','media_dir') | 89 self.media_dir = self.bridge.getConfig('', 'media_dir') |
89 | 90 |
90 def check_profile(self, profile): | 91 def check_profile(self, profile): |
91 """Tell if the profile is currently followed by the application""" | 92 """Tell if the profile is currently followed by the application""" |
92 return profile in self.profiles.keys() | 93 return profile in self.profiles.keys() |
93 | 94 |
99 else: | 100 else: |
100 self.plug_profile(self.options.profile) | 101 self.plug_profile(self.options.profile) |
101 | 102 |
102 def check_options(self): | 103 def check_options(self): |
103 """Check command line options""" | 104 """Check command line options""" |
104 usage=_(""" | 105 usage = _(""" |
105 %prog [options] | 106 %prog [options] |
106 | 107 |
107 %prog --help for options list | 108 %prog --help for options list |
108 """) | 109 """) |
109 parser = OptionParser(usage=usage) | 110 parser = OptionParser(usage=usage) |
125 return | 126 return |
126 profile = self.bridge.getProfileName(profile_key) | 127 profile = self.bridge.getProfileName(profile_key) |
127 if not profile: | 128 if not profile: |
128 error(_("The profile asked doesn't exist")) | 129 error(_("The profile asked doesn't exist")) |
129 return | 130 return |
130 if self.profiles.has_key(profile): | 131 if profile in self.profiles: |
131 warning(_("The profile is already plugged")) | 132 warning(_("The profile is already plugged")) |
132 return | 133 return |
133 self.profiles[profile]={} | 134 self.profiles[profile] = {} |
134 if self.single_profile: | 135 if self.single_profile: |
135 self.profile = profile | 136 self.profile = profile |
136 | 137 |
137 ###now we get the essential params### | 138 ###now we get the essential params### |
138 self.bridge.asyncGetParamA("JabberID","Connection", profile_key=profile, | 139 self.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, |
139 callback=lambda _jid: self.plug_profile_2(_jid, profile), errback=self._getParamError) | 140 callback=lambda _jid: self.plug_profile_2(_jid, profile), errback=self._getParamError) |
140 | 141 |
141 def plug_profile_2(self, _jid, profile): | 142 def plug_profile_2(self, _jid, profile): |
142 self.profiles[profile]['whoami'] = JID(_jid) | 143 self.profiles[profile]['whoami'] = JID(_jid) |
143 self.bridge.asyncGetParamA("autoconnect","Connection", profile_key=profile, | 144 self.bridge.asyncGetParamA("autoconnect", "Connection", profile_key=profile, |
144 callback=lambda value: self.plug_profile_3(value=="true", profile), errback=self._getParamError) | 145 callback=lambda value: self.plug_profile_3(value == "true", profile), errback=self._getParamError) |
145 | 146 |
146 def plug_profile_3(self, autoconnect, profile): | 147 def plug_profile_3(self, autoconnect, profile): |
147 self.bridge.asyncGetParamA("Watched", "Misc", profile_key=profile, | 148 self.bridge.asyncGetParamA("Watched", "Misc", profile_key=profile, |
148 callback=lambda watched: self.plug_profile_4(watched, autoconnect, profile), errback=self._getParamError) | 149 callback=lambda watched: self.plug_profile_4(watched, autoconnect, profile), errback=self._getParamError) |
149 | 150 |
153 self.bridge.asyncConnect(profile, callback=lambda: self.plug_profile_5(watched, autoconnect, profile), errback=lambda ignore: error(_('Error during autoconnection'))) | 154 self.bridge.asyncConnect(profile, callback=lambda: self.plug_profile_5(watched, autoconnect, profile), errback=lambda ignore: error(_('Error during autoconnection'))) |
154 else: | 155 else: |
155 self.plug_profile_5(watched, autoconnect, profile) | 156 self.plug_profile_5(watched, autoconnect, profile) |
156 | 157 |
157 def plug_profile_5(self, watched, autoconnect, profile): | 158 def plug_profile_5(self, watched, autoconnect, profile): |
158 self.profiles[profile]['watched'] = watched.split() #TODO: put this in a plugin | 159 self.profiles[profile]['watched'] = watched.split() # TODO: put this in a plugin |
159 | 160 |
160 ## misc ## | 161 ## misc ## |
161 self.profiles[profile]['onlineContact'] = set() #FIXME: temporary | 162 self.profiles[profile]['onlineContact'] = set() # FIXME: temporary |
162 | 163 |
163 #TODO: manage multi-profiles here | 164 #TODO: manage multi-profiles here |
164 if not self.bridge.isConnected(profile): | 165 if not self.bridge.isConnected(profile): |
165 self.setStatusOnline(False) | 166 self.setStatusOnline(False) |
166 else: | 167 else: |
171 self.newContact(*contact, profile=profile) | 172 self.newContact(*contact, profile=profile) |
172 | 173 |
173 presences = self.bridge.getPresenceStatus(profile) | 174 presences = self.bridge.getPresenceStatus(profile) |
174 for contact in presences: | 175 for contact in presences: |
175 for res in presences[contact]: | 176 for res in presences[contact]: |
176 jabber_id = contact+('/'+res if res else '') | 177 jabber_id = contact + ('/' + res if res else '') |
177 show = presences[contact][res][0] | 178 show = presences[contact][res][0] |
178 priority = presences[contact][res][1] | 179 priority = presences[contact][res][1] |
179 statuses = presences[contact][res][2] | 180 statuses = presences[contact][res][2] |
180 self.presenceUpdate(jabber_id, show, priority, statuses, profile) | 181 self.presenceUpdate(jabber_id, show, priority, statuses, profile) |
181 data = self.bridge.getEntityData(contact, ['avatar','nick'], profile) | 182 data = self.bridge.getEntityData(contact, ['avatar', 'nick'], profile) |
182 for key in ('avatar', 'nick'): | 183 for key in ('avatar', 'nick'): |
183 if key in data: | 184 if key in data: |
184 self.entityDataUpdated(contact, key, data[key], profile) | 185 self.entityDataUpdated(contact, key, data[key], profile) |
185 | 186 |
186 #The waiting subscription requests | 187 #The waiting subscription requests |
197 | 198 |
198 #Finaly, we get the waiting confirmation requests | 199 #Finaly, we get the waiting confirmation requests |
199 for confirm_id, confirm_type, data in self.bridge.getWaitingConf(profile): | 200 for confirm_id, confirm_type, data in self.bridge.getWaitingConf(profile): |
200 self.askConfirmation(confirm_id, confirm_type, data, profile) | 201 self.askConfirmation(confirm_id, confirm_type, data, profile) |
201 | 202 |
202 | |
203 | |
204 def unplug_profile(self, profile): | 203 def unplug_profile(self, profile): |
205 """Tell the application to not follow anymore the profile""" | 204 """Tell the application to not follow anymore the profile""" |
206 if not profile in self.profiles: | 205 if not profile in self.profiles: |
207 warning (_("This profile is not plugged")) | 206 warning(_("This profile is not plugged")) |
208 return | 207 return |
209 self.profiles.remove(profile) | 208 self.profiles.remove(profile) |
210 | 209 |
211 def clear_profile(self): | 210 def clear_profile(self): |
212 self.profiles.clear() | 211 self.profiles.clear() |
238 error(_('FIXME: error_type %s not implemented') % error_type) | 237 error(_('FIXME: error_type %s not implemented') % error_type) |
239 | 238 |
240 def newContact(self, JabberId, attributes, groups, profile): | 239 def newContact(self, JabberId, attributes, groups, profile): |
241 if not self.check_profile(profile): | 240 if not self.check_profile(profile): |
242 return | 241 return |
243 entity=JID(JabberId) | 242 entity = JID(JabberId) |
244 _groups = list(groups) | 243 _groups = list(groups) |
245 self.contact_list.replace(entity, _groups, attributes) | 244 self.contact_list.replace(entity, _groups, attributes) |
246 | 245 |
247 def _newMessage(self, from_jid_s, msg, _type, to_jid_s, extra, profile): | 246 def _newMessage(self, from_jid_s, msg, _type, to_jid_s, extra, profile): |
248 """newMessage premanagement: a dirty hack to manage private messages | 247 """newMessage premanagement: a dirty hack to manage private messages |
291 self.bridge.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) | 290 self.bridge.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) |
292 | 291 |
293 def newAlert(self, msg, title, alert_type, profile): | 292 def newAlert(self, msg, title, alert_type, profile): |
294 if not self.check_profile(profile): | 293 if not self.check_profile(profile): |
295 return | 294 return |
296 assert alert_type in ['INFO','ERROR'] | 295 assert alert_type in ['INFO', 'ERROR'] |
297 self.showDialog(unicode(msg),unicode(title),alert_type.lower()) | 296 self.showDialog(unicode(msg), unicode(title), alert_type.lower()) |
298 | 297 |
299 def setStatusOnline(self, online=True, show="", statuses={}): | 298 def setStatusOnline(self, online=True, show="", statuses={}): |
300 raise NotImplementedError | 299 raise NotImplementedError |
301 | 300 |
302 def presenceUpdate(self, jabber_id, show, priority, statuses, profile): | 301 def presenceUpdate(self, jabber_id, show, priority, statuses, profile): |
331 | 330 |
332 def roomJoined(self, room_jid, room_nicks, user_nick, profile): | 331 def roomJoined(self, room_jid, room_nicks, user_nick, profile): |
333 """Called when a MUC room is joined""" | 332 """Called when a MUC room is joined""" |
334 if not self.check_profile(profile): | 333 if not self.check_profile(profile): |
335 return | 334 return |
336 debug (_("Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s") % {'room_jid':room_jid, 'profile': profile, 'users':room_nicks}) | 335 debug(_("Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s") % {'room_jid': room_jid, 'profile': profile, 'users': room_nicks}) |
337 self.chat_wins[room_jid].setUserNick(user_nick) | 336 self.chat_wins[room_jid].setUserNick(user_nick) |
338 self.chat_wins[room_jid].setType("group") | 337 self.chat_wins[room_jid].setType("group") |
339 self.chat_wins[room_jid].id = room_jid | 338 self.chat_wins[room_jid].id = room_jid |
340 self.chat_wins[room_jid].setPresents(list(set([user_nick]+room_nicks))) | 339 self.chat_wins[room_jid].setPresents(list(set([user_nick] + room_nicks))) |
341 self.contact_list.setSpecial(JID(room_jid), "MUC", show=True) | 340 self.contact_list.setSpecial(JID(room_jid), "MUC", show=True) |
342 | 341 |
343 def roomLeft(self, room_jid_s, profile): | 342 def roomLeft(self, room_jid_s, profile): |
344 """Called when a MUC room is left""" | 343 """Called when a MUC room is left""" |
345 if not self.check_profile(profile): | 344 if not self.check_profile(profile): |
346 return | 345 return |
347 debug (_("Room [%(room_jid)s] left by %(profile)s") % {'room_jid':room_jid_s, 'profile': profile}) | 346 debug(_("Room [%(room_jid)s] left by %(profile)s") % {'room_jid': room_jid_s, 'profile': profile}) |
348 del self.chat_wins[room_jid_s] | 347 del self.chat_wins[room_jid_s] |
349 self.contact_list.remove(JID(room_jid_s)) | 348 self.contact_list.remove(JID(room_jid_s)) |
350 | 349 |
351 def roomUserJoined(self, room_jid, user_nick, user_data, profile): | 350 def roomUserJoined(self, room_jid, user_nick, user_data, profile): |
352 """Called when an user joined a MUC room""" | 351 """Called when an user joined a MUC room""" |
353 if not self.check_profile(profile): | 352 if not self.check_profile(profile): |
354 return | 353 return |
355 if self.chat_wins.has_key(room_jid): | 354 if room_jid in self.chat_wins: |
356 self.chat_wins[room_jid].replaceUser(user_nick) | 355 self.chat_wins[room_jid].replaceUser(user_nick) |
357 debug (_("user [%(user_nick)s] joined room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid}) | 356 debug(_("user [%(user_nick)s] joined room [%(room_jid)s]") % {'user_nick': user_nick, 'room_jid': room_jid}) |
358 | 357 |
359 def roomUserLeft(self, room_jid, user_nick, user_data, profile): | 358 def roomUserLeft(self, room_jid, user_nick, user_data, profile): |
360 """Called when an user joined a MUC room""" | 359 """Called when an user joined a MUC room""" |
361 if not self.check_profile(profile): | 360 if not self.check_profile(profile): |
362 return | 361 return |
363 if self.chat_wins.has_key(room_jid): | 362 if room_jid in self.chat_wins: |
364 self.chat_wins[room_jid].removeUser(user_nick) | 363 self.chat_wins[room_jid].removeUser(user_nick) |
365 debug (_("user [%(user_nick)s] left room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid}) | 364 debug(_("user [%(user_nick)s] left room [%(room_jid)s]") % {'user_nick': user_nick, 'room_jid': room_jid}) |
366 | 365 |
367 def roomUserChangedNick(self, room_jid, old_nick, new_nick, profile): | 366 def roomUserChangedNick(self, room_jid, old_nick, new_nick, profile): |
368 """Called when an user joined a MUC room""" | 367 """Called when an user joined a MUC room""" |
369 if not self.check_profile(profile): | 368 if not self.check_profile(profile): |
370 return | 369 return |
371 if self.chat_wins.has_key(room_jid): | 370 if room_jid in self.chat_wins: |
372 self.chat_wins[room_jid].changeUserNick(old_nick, new_nick) | 371 self.chat_wins[room_jid].changeUserNick(old_nick, new_nick) |
373 debug (_("user [%(old_nick)s] is now known as [%(new_nick)s] in room [%(room_jid)s]") % {'old_nick':old_nick, 'new_nick':new_nick, 'room_jid':room_jid}) | 372 debug(_("user [%(old_nick)s] is now known as [%(new_nick)s] in room [%(room_jid)s]") % {'old_nick': old_nick, 'new_nick': new_nick, 'room_jid': room_jid}) |
374 | 373 |
375 def roomNewSubject(self, room_jid, subject, profile): | 374 def roomNewSubject(self, room_jid, subject, profile): |
376 """Called when subject of MUC room change""" | 375 """Called when subject of MUC room change""" |
377 if not self.check_profile(profile): | 376 if not self.check_profile(profile): |
378 return | 377 return |
379 if self.chat_wins.has_key(room_jid): | 378 if room_jid in self.chat_wins: |
380 self.chat_wins[room_jid].setSubject(subject) | 379 self.chat_wins[room_jid].setSubject(subject) |
381 debug (_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid':room_jid, "subject":subject}) | 380 debug(_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid': room_jid, "subject": subject}) |
382 | 381 |
383 def tarotGameStarted(self, room_jid, referee, players, profile): | 382 def tarotGameStarted(self, room_jid, referee, players, profile): |
384 if not self.check_profile(profile): | 383 if not self.check_profile(profile): |
385 return | 384 return |
386 debug (_("Tarot Game Started \o/")) | 385 debug(_("Tarot Game Started \o/")) |
387 if self.chat_wins.has_key(room_jid): | 386 if room_jid in self.chat_wins: |
388 self.chat_wins[room_jid].startGame("Tarot", referee, players) | 387 self.chat_wins[room_jid].startGame("Tarot", referee, players) |
389 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]}) | 388 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]}) |
390 | 389 |
391 def tarotGameNew(self, room_jid, hand, profile): | 390 def tarotGameNew(self, room_jid, hand, profile): |
392 if not self.check_profile(profile): | 391 if not self.check_profile(profile): |
393 return | 392 return |
394 debug (_("New Tarot Game")) | 393 debug(_("New Tarot Game")) |
395 if self.chat_wins.has_key(room_jid): | 394 if room_jid in self.chat_wins: |
396 self.chat_wins[room_jid].getGame("Tarot").newGame(hand) | 395 self.chat_wins[room_jid].getGame("Tarot").newGame(hand) |
397 | 396 |
398 def tarotChooseContrat(self, room_jid, xml_data, profile): | 397 def tarotChooseContrat(self, room_jid, xml_data, profile): |
399 """Called when the player has to select his contrat""" | 398 """Called when the player has to select his contrat""" |
400 if not self.check_profile(profile): | 399 if not self.check_profile(profile): |
401 return | 400 return |
402 debug (_("Tarot: need to select a contrat")) | 401 debug(_("Tarot: need to select a contrat")) |
403 if self.chat_wins.has_key(room_jid): | 402 if room_jid in self.chat_wins: |
404 self.chat_wins[room_jid].getGame("Tarot").chooseContrat(xml_data) | 403 self.chat_wins[room_jid].getGame("Tarot").chooseContrat(xml_data) |
405 | 404 |
406 def tarotShowCards(self, room_jid, game_stage, cards, data, profile): | 405 def tarotShowCards(self, room_jid, game_stage, cards, data, profile): |
407 if not self.check_profile(profile): | 406 if not self.check_profile(profile): |
408 return | 407 return |
409 debug (_("Show cards")) | 408 debug(_("Show cards")) |
410 if self.chat_wins.has_key(room_jid): | 409 if room_jid in self.chat_wins: |
411 self.chat_wins[room_jid].getGame("Tarot").showCards(game_stage, cards, data) | 410 self.chat_wins[room_jid].getGame("Tarot").showCards(game_stage, cards, data) |
412 | 411 |
413 def tarotMyTurn(self, room_jid, profile): | 412 def tarotMyTurn(self, room_jid, profile): |
414 if not self.check_profile(profile): | 413 if not self.check_profile(profile): |
415 return | 414 return |
416 debug (_("My turn to play")) | 415 debug(_("My turn to play")) |
417 if self.chat_wins.has_key(room_jid): | 416 if room_jid in self.chat_wins: |
418 self.chat_wins[room_jid].getGame("Tarot").myTurn() | 417 self.chat_wins[room_jid].getGame("Tarot").myTurn() |
419 | 418 |
420 def tarotScore(self, room_jid, xml_data, winners, loosers, profile): | 419 def tarotScore(self, room_jid, xml_data, winners, loosers, profile): |
421 """Called when the game is finished and the score are updated""" | 420 """Called when the game is finished and the score are updated""" |
422 if not self.check_profile(profile): | 421 if not self.check_profile(profile): |
423 return | 422 return |
424 debug (_("Tarot: score received")) | 423 debug(_("Tarot: score received")) |
425 if self.chat_wins.has_key(room_jid): | 424 if room_jid in self.chat_wins: |
426 self.chat_wins[room_jid].getGame("Tarot").showScores(xml_data, winners, loosers) | 425 self.chat_wins[room_jid].getGame("Tarot").showScores(xml_data, winners, loosers) |
427 | 426 |
428 def tarotCardsPlayed(self, room_jid, player, cards, profile): | 427 def tarotCardsPlayed(self, room_jid, player, cards, profile): |
429 if not self.check_profile(profile): | 428 if not self.check_profile(profile): |
430 return | 429 return |
431 debug (_("Card(s) played (%(player)s): %(cards)s") % {"player":player, "cards":cards}) | 430 debug(_("Card(s) played (%(player)s): %(cards)s") % {"player": player, "cards": cards}) |
432 if self.chat_wins.has_key(room_jid): | 431 if room_jid in self.chat_wins: |
433 self.chat_wins[room_jid].getGame("Tarot").cardsPlayed(player, cards) | 432 self.chat_wins[room_jid].getGame("Tarot").cardsPlayed(player, cards) |
434 | 433 |
435 def tarotInvalidCards(self, room_jid, phase, played_cards, invalid_cards, profile): | 434 def tarotInvalidCards(self, room_jid, phase, played_cards, invalid_cards, profile): |
436 if not self.check_profile(profile): | 435 if not self.check_profile(profile): |
437 return | 436 return |
438 debug (_("Cards played are not valid: %s") % invalid_cards) | 437 debug(_("Cards played are not valid: %s") % invalid_cards) |
439 if self.chat_wins.has_key(room_jid): | 438 if room_jid in self.chat_wins: |
440 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) | 439 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) |
441 | 440 |
442 def quizGameStarted(self, room_jid, referee, players, profile): | 441 def quizGameStarted(self, room_jid, referee, players, profile): |
443 if not self.check_profile(profile): | 442 if not self.check_profile(profile): |
444 return | 443 return |
445 debug (_("Quiz Game Started \o/")) | 444 debug(_("Quiz Game Started \o/")) |
446 if self.chat_wins.has_key(room_jid): | 445 if room_jid in self.chat_wins: |
447 self.chat_wins[room_jid].startGame("Quiz", referee, players) | 446 self.chat_wins[room_jid].startGame("Quiz", referee, players) |
448 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]}) | 447 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]}) |
449 | 448 |
450 def quizGameNew(self, room_jid, data, profile): | 449 def quizGameNew(self, room_jid, data, profile): |
451 if not self.check_profile(profile): | 450 if not self.check_profile(profile): |
452 return | 451 return |
453 debug (_("New Quiz Game")) | 452 debug(_("New Quiz Game")) |
454 if self.chat_wins.has_key(room_jid): | 453 if room_jid in self.chat_wins: |
455 self.chat_wins[room_jid].getGame("Quiz").quizGameNew(data) | 454 self.chat_wins[room_jid].getGame("Quiz").quizGameNew(data) |
456 | 455 |
457 def quizGameQuestion(self, room_jid, question_id, question, timer, profile): | 456 def quizGameQuestion(self, room_jid, question_id, question, timer, profile): |
458 """Called when a new question is asked""" | 457 """Called when a new question is asked""" |
459 if not self.check_profile(profile): | 458 if not self.check_profile(profile): |
460 return | 459 return |
461 debug (_(u"Quiz: new question: %s") % question) | 460 debug(_(u"Quiz: new question: %s") % question) |
462 if self.chat_wins.has_key(room_jid): | 461 if room_jid in self.chat_wins: |
463 self.chat_wins[room_jid].getGame("Quiz").quizGameQuestion(question_id, question, timer) | 462 self.chat_wins[room_jid].getGame("Quiz").quizGameQuestion(question_id, question, timer) |
464 | 463 |
465 def quizGamePlayerBuzzed(self, room_jid, player, pause, profile): | 464 def quizGamePlayerBuzzed(self, room_jid, player, pause, profile): |
466 """Called when a player pushed the buzzer""" | 465 """Called when a player pushed the buzzer""" |
467 if not self.check_profile(profile): | 466 if not self.check_profile(profile): |
468 return | 467 return |
469 if self.chat_wins.has_key(room_jid): | 468 if room_jid in self.chat_wins: |
470 self.chat_wins[room_jid].getGame("Quiz").quizGamePlayerBuzzed(player, pause) | 469 self.chat_wins[room_jid].getGame("Quiz").quizGamePlayerBuzzed(player, pause) |
471 | 470 |
472 def quizGamePlayerSays(self, room_jid, player, text, delay, profile): | 471 def quizGamePlayerSays(self, room_jid, player, text, delay, profile): |
473 """Called when a player say something""" | 472 """Called when a player say something""" |
474 if not self.check_profile(profile): | 473 if not self.check_profile(profile): |
475 return | 474 return |
476 if self.chat_wins.has_key(room_jid): | 475 if room_jid in self.chat_wins: |
477 self.chat_wins[room_jid].getGame("Quiz").quizGamePlayerSays(player, text, delay) | 476 self.chat_wins[room_jid].getGame("Quiz").quizGamePlayerSays(player, text, delay) |
478 | 477 |
479 def quizGameAnswerResult(self, room_jid, player, good_answer, score, profile): | 478 def quizGameAnswerResult(self, room_jid, player, good_answer, score, profile): |
480 """Called when a player say something""" | 479 """Called when a player say something""" |
481 if not self.check_profile(profile): | 480 if not self.check_profile(profile): |
482 return | 481 return |
483 if self.chat_wins.has_key(room_jid): | 482 if room_jid in self.chat_wins: |
484 self.chat_wins[room_jid].getGame("Quiz").quizGameAnswerResult(player, good_answer, score) | 483 self.chat_wins[room_jid].getGame("Quiz").quizGameAnswerResult(player, good_answer, score) |
485 | 484 |
486 def quizGameTimerExpired(self, room_jid, profile): | 485 def quizGameTimerExpired(self, room_jid, profile): |
487 """Called when nobody answered the question in time""" | 486 """Called when nobody answered the question in time""" |
488 if not self.check_profile(profile): | 487 if not self.check_profile(profile): |
489 return | 488 return |
490 if self.chat_wins.has_key(room_jid): | 489 if room_jid in self.chat_wins: |
491 self.chat_wins[room_jid].getGame("Quiz").quizGameTimerExpired() | 490 self.chat_wins[room_jid].getGame("Quiz").quizGameTimerExpired() |
492 | 491 |
493 def quizGameTimerRestarted(self, room_jid, time_left, profile): | 492 def quizGameTimerRestarted(self, room_jid, time_left, profile): |
494 """Called when the question is not answered, and we still have time""" | 493 """Called when the question is not answered, and we still have time""" |
495 if not self.check_profile(profile): | 494 if not self.check_profile(profile): |
496 return | 495 return |
497 if self.chat_wins.has_key(room_jid): | 496 if room_jid in self.chat_wins: |
498 self.chat_wins[room_jid].getGame("Quiz").quizGameTimerRestarted(time_left) | 497 self.chat_wins[room_jid].getGame("Quiz").quizGameTimerRestarted(time_left) |
499 | 498 |
500 def _subscribe_cb(self, answer, data): | 499 def _subscribe_cb(self, answer, data): |
501 entity, profile = data | 500 entity, profile = data |
502 if answer: | 501 if answer: |
503 self.bridge.subscription("subscribed", entity.bare, profile_key = profile) | 502 self.bridge.subscription("subscribed", entity.bare, profile_key=profile) |
504 else: | 503 else: |
505 self.bridge.subscription("unsubscribed", entity.bare, profile_key = profile) | 504 self.bridge.subscription("unsubscribed", entity.bare, profile_key=profile) |
506 | 505 |
507 def subscribe(self, type, raw_jid, profile): | 506 def subscribe(self, type, raw_jid, profile): |
508 """Called when a subsciption management signal is received""" | 507 """Called when a subsciption management signal is received""" |
509 if not self.check_profile(profile): | 508 if not self.check_profile(profile): |
510 return | 509 return |
511 entity = JID(raw_jid) | 510 entity = JID(raw_jid) |
512 if type=="subscribed": | 511 if type == "subscribed": |
513 # this is a subscription confirmation, we just have to inform user | 512 # this is a subscription confirmation, we just have to inform user |
514 self.showDialog(_("The contact %s has accepted your subscription") % entity.bare, _('Subscription confirmation')) | 513 self.showDialog(_("The contact %s has accepted your subscription") % entity.bare, _('Subscription confirmation')) |
515 elif type=="unsubscribed": | 514 elif type == "unsubscribed": |
516 # this is a subscription refusal, we just have to inform user | 515 # this is a subscription refusal, we just have to inform user |
517 self.showDialog(_("The contact %s has refused your subscription") % entity.bare, _('Subscription refusal'), 'error') | 516 self.showDialog(_("The contact %s has refused your subscription") % entity.bare, _('Subscription refusal'), 'error') |
518 elif type=="subscribe": | 517 elif type == "subscribe": |
519 # this is a subscriptionn request, we have to ask for user confirmation | 518 # this is a subscriptionn request, we have to ask for user confirmation |
520 answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.bare, _('Subscription confirmation'), 'yes/no', answer_cb = self._subscribe_cb, answer_data=(entity, profile)) | 519 answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.bare, _('Subscription confirmation'), 'yes/no', answer_cb=self._subscribe_cb, answer_data=(entity, profile)) |
521 | 520 |
522 def showDialog(self, message, title, type="info", answer_cb = None): | 521 def showDialog(self, message, title, type="info", answer_cb=None): |
523 raise NotImplementedError | 522 raise NotImplementedError |
524 | 523 |
525 def showAlert(self, message): | 524 def showAlert(self, message): |
526 pass #FIXME | 525 pass #FIXME |
527 | 526 |
528 def paramUpdate(self, name, value, namespace, profile): | 527 def paramUpdate(self, name, value, namespace, profile): |
529 if not self.check_profile(profile): | 528 if not self.check_profile(profile): |
530 return | 529 return |
531 debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace':namespace, 'name':name, 'value':value}) | 530 debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace': namespace, 'name': name, 'value': value}) |
532 if (namespace,name) == ("Connection", "JabberID"): | 531 if (namespace, name) == ("Connection", "JabberID"): |
533 debug (_("Changing JID to %s"), value) | 532 debug(_("Changing JID to %s"), value) |
534 self.profiles[profile]['whoami']=JID(value) | 533 self.profiles[profile]['whoami'] = JID(value) |
535 elif (namespace,name) == ("Misc", "Watched"): | 534 elif (namespace, name) == ("Misc", "Watched"): |
536 self.profiles[profile]['watched']=value.split() | 535 self.profiles[profile]['watched'] = value.split() |
537 | 536 |
538 def contactDeleted(self, jid, profile): | 537 def contactDeleted(self, jid, profile): |
539 if not self.check_profile(profile): | 538 if not self.check_profile(profile): |
540 return | 539 return |
541 target = JID(jid) | 540 target = JID(jid) |
568 def onExit(self): | 567 def onExit(self): |
569 """Must be called when the frontend is terminating""" | 568 """Must be called when the frontend is terminating""" |
570 #TODO: mange multi-profile here | 569 #TODO: mange multi-profile here |
571 try: | 570 try: |
572 if self.bridge.isConnected(self.profile): | 571 if self.bridge.isConnected(self.profile): |
573 if self.bridge.getParamA("autodisconnect","Connection", profile_key=self.profile) == "true": | 572 if self.bridge.getParamA("autodisconnect", "Connection", profile_key=self.profile) == "true": |
574 #The user wants autodisconnection | 573 #The user wants autodisconnection |
575 self.bridge.disconnect(self.profile) | 574 self.bridge.disconnect(self.profile) |
576 except: | 575 except: |
577 pass | 576 pass |
578 |