Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_app.py @ 1103:a096b8579a3c
frontends: signals are managed in a more generic way
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 11 Aug 2014 19:10:24 +0200 |
parents | 11e2bb20e896 |
children | 6053fb8a6466 |
comparison
equal
deleted
inserted
replaced
1102:4c48e2549592 | 1103:a096b8579a3c |
---|---|
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 ?")) |
46 sys.exit(1) | 46 sys.exit(1) |
47 except BridgeInitError: | 47 except BridgeInitError: |
48 print(_(u"Can't init bridge")) | 48 print(_(u"Can't init bridge")) |
49 sys.exit(1) | 49 sys.exit(1) |
50 self.bridge.register("connected", self.connected) | 50 self.registerSignal("connected") |
51 self.bridge.register("disconnected", self.disconnected) | 51 self.registerSignal("disconnected") |
52 self.bridge.register("newContact", self.newContact) | 52 self.registerSignal("newContact") |
53 self.bridge.register("newMessage", self._newMessage) | 53 self.registerSignal("newMessage", self._newMessage) |
54 self.bridge.register("newAlert", self.newAlert) | 54 self.registerSignal("newAlert") |
55 self.bridge.register("presenceUpdate", self.presenceUpdate) | 55 self.registerSignal("presenceUpdate") |
56 self.bridge.register("subscribe", self.subscribe) | 56 self.registerSignal("subscribe") |
57 self.bridge.register("paramUpdate", self.paramUpdate) | 57 self.registerSignal("paramUpdate") |
58 self.bridge.register("contactDeleted", self.contactDeleted) | 58 self.registerSignal("contactDeleted") |
59 self.bridge.register("entityDataUpdated", self.entityDataUpdated) | 59 self.registerSignal("entityDataUpdated") |
60 self.bridge.register("askConfirmation", self.askConfirmation) | 60 self.registerSignal("askConfirmation") |
61 self.bridge.register("actionResult", self.actionResult) | 61 self.registerSignal("actionResult") |
62 self.bridge.register("actionResultExt", self.actionResult) | 62 self.registerSignal("actionResultExt", self.actionResultHandler) |
63 self.bridge.register("roomJoined", self.roomJoined, "plugin") | 63 self.registerSignal("roomJoined", iface="plugin") |
64 self.bridge.register("roomLeft", self.roomLeft, "plugin") | 64 self.registerSignal("roomLeft", iface="plugin") |
65 self.bridge.register("roomUserJoined", self.roomUserJoined, "plugin") | 65 self.registerSignal("roomUserJoined", iface="plugin") |
66 self.bridge.register("roomUserLeft", self.roomUserLeft, "plugin") | 66 self.registerSignal("roomUserLeft", iface="plugin") |
67 self.bridge.register("roomUserChangedNick", self.roomUserChangedNick, "plugin") | 67 self.registerSignal("roomUserChangedNick", iface="plugin") |
68 self.bridge.register("roomNewSubject", self.roomNewSubject, "plugin") | 68 self.registerSignal("roomNewSubject", iface="plugin") |
69 self.bridge.register("tarotGameStarted", self.tarotGameStarted, "plugin") | 69 self.registerSignal("tarotGameStarted", iface="plugin") |
70 self.bridge.register("tarotGameNew", self.tarotGameNew, "plugin") | 70 self.registerSignal("tarotGameNew", iface="plugin") |
71 self.bridge.register("tarotGameChooseContrat", self.tarotChooseContrat, "plugin") | 71 self.registerSignal("tarotGameChooseContrat", iface="plugin") |
72 self.bridge.register("tarotGameShowCards", self.tarotShowCards, "plugin") | 72 self.registerSignal("tarotGameShowCards", iface="plugin") |
73 self.bridge.register("tarotGameYourTurn", self.tarotMyTurn, "plugin") | 73 self.registerSignal("tarotGameYourTurn", iface="plugin") |
74 self.bridge.register("tarotGameScore", self.tarotScore, "plugin") | 74 self.registerSignal("tarotGameScore", iface="plugin") |
75 self.bridge.register("tarotGameCardsPlayed", self.tarotCardsPlayed, "plugin") | 75 self.registerSignal("tarotGameCardsPlayed", iface="plugin") |
76 self.bridge.register("tarotGameInvalidCards", self.tarotInvalidCards, "plugin") | 76 self.registerSignal("tarotGameInvalidCards", iface="plugin") |
77 self.bridge.register("quizGameStarted", self.quizGameStarted, "plugin") | 77 self.registerSignal("quizGameStarted", iface="plugin") |
78 self.bridge.register("quizGameNew", self.quizGameNew, "plugin") | 78 self.registerSignal("quizGameNew", iface="plugin") |
79 self.bridge.register("quizGameQuestion", self.quizGameQuestion, "plugin") | 79 self.registerSignal("quizGameQuestion", iface="plugin") |
80 self.bridge.register("quizGamePlayerBuzzed", self.quizGamePlayerBuzzed, "plugin") | 80 self.registerSignal("quizGamePlayerBuzzed", iface="plugin") |
81 self.bridge.register("quizGamePlayerSays", self.quizGamePlayerSays, "plugin") | 81 self.registerSignal("quizGamePlayerSays", iface="plugin") |
82 self.bridge.register("quizGameAnswerResult", self.quizGameAnswerResult, "plugin") | 82 self.registerSignal("quizGameAnswerResult", iface="plugin") |
83 self.bridge.register("quizGameTimerExpired", self.quizGameTimerExpired, "plugin") | 83 self.registerSignal("quizGameTimerExpired", iface="plugin") |
84 self.bridge.register("quizGameTimerRestarted", self.quizGameTimerRestarted, "plugin") | 84 self.registerSignal("quizGameTimerRestarted", iface="plugin") |
85 self.bridge.register("chatStateReceived", self.chatStateReceived, "plugin") | 85 self.registerSignal("chatStateReceived", iface="plugin") |
86 | 86 |
87 self.current_action_ids = set() | 87 self.current_action_ids = set() |
88 self.current_action_ids_cb = {} | 88 self.current_action_ids_cb = {} |
89 self.media_dir = self.bridge.getConfig('', 'media_dir') | 89 self.media_dir = self.bridge.getConfig('', 'media_dir') |
90 | |
91 def registerSignal(self, functionName, handler=None, iface="core"): | |
92 """Register a handler for a signal | |
93 | |
94 @param functionName: name of the signal to handle | |
95 @param handler: method to call when the signal arrive, None for calling an automaticaly named handler (functionName + 'Handler') | |
96 @param iface: interface of the bridge to use | |
97 | |
98 """ | |
99 if handler is None: | |
100 handler = getattr(self, "%s%s" % (functionName, 'Handler')) | |
101 def signalReceived(*args, **kwargs): | |
102 profile = kwargs.get('profile', None) | |
103 if profile is not None and not self.check_profile(profile): | |
104 return # we ignore signal for profiles we don't manage | |
105 handler(*args, **kwargs) | |
106 self.bridge.register(functionName, signalReceived, iface) | |
90 | 107 |
91 def check_profile(self, profile): | 108 def check_profile(self, profile): |
92 """Tell if the profile is currently followed by the application""" | 109 """Tell if the profile is currently followed by the application""" |
93 return profile in self.profiles.keys() | 110 return profile in self.profiles.keys() |
94 | 111 |
187 else: | 204 else: |
188 self.setStatusOnline(True) | 205 self.setStatusOnline(True) |
189 | 206 |
190 ### now we fill the contact list ### | 207 ### now we fill the contact list ### |
191 for contact in self.bridge.getContacts(profile): | 208 for contact in self.bridge.getContacts(profile): |
192 self.newContact(*contact, profile=profile) | 209 self.newContactHandler(*contact, profile=profile) |
193 | 210 |
194 presences = self.bridge.getPresenceStatuses(profile) | 211 presences = self.bridge.getPresenceStatuses(profile) |
195 for contact in presences: | 212 for contact in presences: |
196 for res in presences[contact]: | 213 for res in presences[contact]: |
197 jabber_id = contact + ('/' + res if res else '') | 214 jabber_id = contact + ('/' + res if res else '') |
198 show = presences[contact][res][0] | 215 show = presences[contact][res][0] |
199 priority = presences[contact][res][1] | 216 priority = presences[contact][res][1] |
200 statuses = presences[contact][res][2] | 217 statuses = presences[contact][res][2] |
201 self.presenceUpdate(jabber_id, show, priority, statuses, profile) | 218 self.presenceUpdateHandler(jabber_id, show, priority, statuses, profile) |
202 data = self.bridge.getEntityData(contact, ['avatar', 'nick'], profile) | 219 data = self.bridge.getEntityData(contact, ['avatar', 'nick'], profile) |
203 for key in ('avatar', 'nick'): | 220 for key in ('avatar', 'nick'): |
204 if key in data: | 221 if key in data: |
205 self.entityDataUpdated(contact, key, data[key], profile) | 222 self.entityDataUpdatedHandler(contact, key, data[key], profile) |
206 | 223 |
207 #The waiting subscription requests | 224 #The waiting subscription requests |
208 waitingSub = self.bridge.getWaitingSub(profile) | 225 waitingSub = self.bridge.getWaitingSub(profile) |
209 for sub in waitingSub: | 226 for sub in waitingSub: |
210 self.subscribe(waitingSub[sub], sub, profile) | 227 self.subscribeHandler(waitingSub[sub], sub, profile) |
211 | 228 |
212 #Now we open the MUC window where we already are: | 229 #Now we open the MUC window where we already are: |
213 for room_args in self.bridge.getRoomsJoined(profile): | 230 for room_args in self.bridge.getRoomsJoined(profile): |
214 self.roomJoined(*room_args, profile=profile) | 231 self.roomJoinedHandler(*room_args, profile=profile) |
215 | 232 |
216 for subject_args in self.bridge.getRoomsSubjects(profile): | 233 for subject_args in self.bridge.getRoomsSubjects(profile): |
217 self.roomNewSubject(*subject_args, profile=profile) | 234 self.roomNewSubjectHandler(*subject_args, profile=profile) |
218 | 235 |
219 #Finaly, we get the waiting confirmation requests | 236 #Finaly, we get the waiting confirmation requests |
220 for confirm_id, confirm_type, data in self.bridge.getWaitingConf(profile): | 237 for confirm_id, confirm_type, data in self.bridge.getWaitingConf(profile): |
221 self.askConfirmation(confirm_id, confirm_type, data, profile) | 238 self.askConfirmationHandler(confirm_id, confirm_type, data, profile) |
222 | 239 |
223 def unplug_profile(self, profile): | 240 def unplug_profile(self, profile): |
224 """Tell the application to not follow anymore the profile""" | 241 """Tell the application to not follow anymore the profile""" |
225 if not profile in self.profiles: | 242 if not profile in self.profiles: |
226 log.warning(_("This profile is not plugged")) | 243 log.warning(_("This profile is not plugged")) |
228 self.profiles.remove(profile) | 245 self.profiles.remove(profile) |
229 | 246 |
230 def clear_profile(self): | 247 def clear_profile(self): |
231 self.profiles.clear() | 248 self.profiles.clear() |
232 | 249 |
233 def connected(self, profile): | 250 def connectedHandler(self, profile): |
234 """called when the connection is made""" | 251 """called when the connection is made""" |
235 if not self.check_profile(profile): | |
236 return | |
237 log.debug(_("Connected")) | 252 log.debug(_("Connected")) |
238 self.setStatusOnline(True) | 253 self.setStatusOnline(True) |
239 | 254 |
240 def disconnected(self, profile): | 255 def disconnectedHandler(self, profile): |
241 """called when the connection is closed""" | 256 """called when the connection is closed""" |
242 if not self.check_profile(profile): | |
243 return | |
244 log.debug(_("Disconnected")) | 257 log.debug(_("Disconnected")) |
245 self.contact_list.clearContacts() | 258 self.contact_list.clearContacts() |
246 self.setStatusOnline(False) | 259 self.setStatusOnline(False) |
247 | 260 |
248 def newContact(self, JabberId, attributes, groups, profile): | 261 def newContactHandler(self, JabberId, attributes, groups, profile): |
249 if not self.check_profile(profile): | |
250 return | |
251 entity = JID(JabberId) | 262 entity = JID(JabberId) |
252 _groups = list(groups) | 263 _groups = list(groups) |
253 self.contact_list.replace(entity, _groups, attributes) | 264 self.contact_list.replace(entity, _groups, attributes) |
254 | 265 |
255 def _newMessage(self, from_jid_s, msg, _type, to_jid_s, extra, profile): | 266 def _newMessage(self, from_jid_s, msg, _type, to_jid_s, extra, profile): |
256 """newMessage premanagement: a dirty hack to manage private messages | 267 """newMessage premanagement: a dirty hack to manage private messages |
257 if a private MUC message is detected, from_jid or to_jid is prefixed and resource is escaped""" | 268 if a private MUC message is detected, from_jid or to_jid is prefixed and resource is escaped""" |
258 if not self.check_profile(profile): | |
259 return | |
260 from_jid = JID(from_jid_s) | 269 from_jid = JID(from_jid_s) |
261 to_jid = JID(to_jid_s) | 270 to_jid = JID(to_jid_s) |
262 | 271 |
263 from_me = from_jid.bare == self.profiles[profile]['whoami'].bare | 272 from_me = from_jid.bare == self.profiles[profile]['whoami'].bare |
264 win = to_jid if from_me else from_jid | 273 win = to_jid if from_me else from_jid |
274 else: | 283 else: |
275 from_jid = new_jid | 284 from_jid = new_jid |
276 if new_jid not in self.contact_list: | 285 if new_jid not in self.contact_list: |
277 self.contact_list.add(new_jid, [C.GROUP_NOT_IN_ROSTER]) | 286 self.contact_list.add(new_jid, [C.GROUP_NOT_IN_ROSTER]) |
278 | 287 |
279 self.newMessage(from_jid, to_jid, msg, _type, extra, profile) | 288 self.newMessageHandler(from_jid, to_jid, msg, _type, extra, profile) |
280 | 289 |
281 def newMessage(self, from_jid, to_jid, msg, _type, extra, profile): | 290 def newMessageHandler(self, from_jid, to_jid, msg, _type, extra, profile): |
282 from_me = from_jid.bare == self.profiles[profile]['whoami'].bare | 291 from_me = from_jid.bare == self.profiles[profile]['whoami'].bare |
283 win = to_jid if from_me else from_jid | 292 win = to_jid if from_me else from_jid |
284 | 293 |
285 self.current_action_ids = set() | 294 self.current_action_ids = set() |
286 self.current_action_ids_cb = {} | 295 self.current_action_ids_cb = {} |
296 callback = lambda: None | 305 callback = lambda: None |
297 if errback is None: | 306 if errback is None: |
298 errback = lambda failure: self.showDialog(failure.fullname, failure.message, "error") | 307 errback = lambda failure: self.showDialog(failure.fullname, failure.message, "error") |
299 self.bridge.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) | 308 self.bridge.sendMessage(to_jid, message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) |
300 | 309 |
301 def newAlert(self, msg, title, alert_type, profile): | 310 def newAlertHandler(self, msg, title, alert_type, profile): |
302 if not self.check_profile(profile): | |
303 return | |
304 assert alert_type in ['INFO', 'ERROR'] | 311 assert alert_type in ['INFO', 'ERROR'] |
305 self.showDialog(unicode(msg), unicode(title), alert_type.lower()) | 312 self.showDialog(unicode(msg), unicode(title), alert_type.lower()) |
306 | 313 |
307 def setStatusOnline(self, online=True, show="", statuses={}): | 314 def setStatusOnline(self, online=True, show="", statuses={}): |
308 raise NotImplementedError | 315 raise NotImplementedError |
309 | 316 |
310 def presenceUpdate(self, jabber_id, show, priority, statuses, profile): | 317 def presenceUpdateHandler(self, jabber_id, show, priority, statuses, profile): |
311 if not self.check_profile(profile): | |
312 return | |
313 | 318 |
314 log.debug(_("presence update for %(jid)s (show=%(show)s, priority=%(priority)s, statuses=%(statuses)s) [profile:%(profile)s]") | 319 log.debug(_("presence update for %(jid)s (show=%(show)s, priority=%(priority)s, statuses=%(statuses)s) [profile:%(profile)s]") |
315 % {'jid': jabber_id, 'show': show, 'priority': priority, 'statuses': statuses, 'profile': profile}) | 320 % {'jid': jabber_id, 'show': show, 'priority': priority, 'statuses': statuses, 'profile': profile}) |
316 from_jid = JID(jabber_id) | 321 from_jid = JID(jabber_id) |
317 | 322 |
354 if not jids or priority >= max_priority: | 359 if not jids or priority >= max_priority: |
355 # case 1: not jids means all resources are disconnected, send the 'unavailable' presence | 360 # case 1: not jids means all resources are disconnected, send the 'unavailable' presence |
356 # case 2: update (or confirm) with the values of the resource which takes precedence | 361 # case 2: update (or confirm) with the values of the resource which takes precedence |
357 self.contact_list.updatePresence(from_jid, show, priority, statuses) | 362 self.contact_list.updatePresence(from_jid, show, priority, statuses) |
358 | 363 |
359 def roomJoined(self, room_jid, room_nicks, user_nick, profile): | 364 def roomJoinedHandler(self, room_jid, room_nicks, user_nick, profile): |
360 """Called when a MUC room is joined""" | 365 """Called when a MUC room is joined""" |
361 if not self.check_profile(profile): | |
362 return | |
363 log.debug(_("Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s") % {'room_jid': room_jid, 'profile': profile, 'users': room_nicks}) | 366 log.debug(_("Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s") % {'room_jid': room_jid, 'profile': profile, 'users': room_nicks}) |
364 self.chat_wins[room_jid].setUserNick(user_nick) | 367 self.chat_wins[room_jid].setUserNick(user_nick) |
365 self.chat_wins[room_jid].setType("group") | 368 self.chat_wins[room_jid].setType("group") |
366 self.chat_wins[room_jid].id = room_jid | 369 self.chat_wins[room_jid].id = room_jid |
367 self.chat_wins[room_jid].setPresents(list(set([user_nick] + room_nicks))) | 370 self.chat_wins[room_jid].setPresents(list(set([user_nick] + room_nicks))) |
368 self.contact_list.setSpecial(JID(room_jid), "MUC", show=True) | 371 self.contact_list.setSpecial(JID(room_jid), "MUC", show=True) |
369 | 372 |
370 def roomLeft(self, room_jid_s, profile): | 373 def roomLeftHandler(self, room_jid_s, profile): |
371 """Called when a MUC room is left""" | 374 """Called when a MUC room is left""" |
372 if not self.check_profile(profile): | |
373 return | |
374 log.debug(_("Room [%(room_jid)s] left by %(profile)s") % {'room_jid': room_jid_s, 'profile': profile}) | 375 log.debug(_("Room [%(room_jid)s] left by %(profile)s") % {'room_jid': room_jid_s, 'profile': profile}) |
375 del self.chat_wins[room_jid_s] | 376 del self.chat_wins[room_jid_s] |
376 self.contact_list.remove(JID(room_jid_s)) | 377 self.contact_list.remove(JID(room_jid_s)) |
377 | 378 |
378 def roomUserJoined(self, room_jid, user_nick, user_data, profile): | 379 def roomUserJoinedHandler(self, room_jid, user_nick, user_data, profile): |
379 """Called when an user joined a MUC room""" | 380 """Called when an user joined a MUC room""" |
380 if not self.check_profile(profile): | |
381 return | |
382 if room_jid in self.chat_wins: | 381 if room_jid in self.chat_wins: |
383 self.chat_wins[room_jid].replaceUser(user_nick) | 382 self.chat_wins[room_jid].replaceUser(user_nick) |
384 log.debug(_("user [%(user_nick)s] joined room [%(room_jid)s]") % {'user_nick': user_nick, 'room_jid': room_jid}) | 383 log.debug(_("user [%(user_nick)s] joined room [%(room_jid)s]") % {'user_nick': user_nick, 'room_jid': room_jid}) |
385 | 384 |
386 def roomUserLeft(self, room_jid, user_nick, user_data, profile): | 385 def roomUserLeftHandler(self, room_jid, user_nick, user_data, profile): |
387 """Called when an user joined a MUC room""" | 386 """Called when an user joined a MUC room""" |
388 if not self.check_profile(profile): | |
389 return | |
390 if room_jid in self.chat_wins: | 387 if room_jid in self.chat_wins: |
391 self.chat_wins[room_jid].removeUser(user_nick) | 388 self.chat_wins[room_jid].removeUser(user_nick) |
392 log.debug(_("user [%(user_nick)s] left room [%(room_jid)s]") % {'user_nick': user_nick, 'room_jid': room_jid}) | 389 log.debug(_("user [%(user_nick)s] left room [%(room_jid)s]") % {'user_nick': user_nick, 'room_jid': room_jid}) |
393 | 390 |
394 def roomUserChangedNick(self, room_jid, old_nick, new_nick, profile): | 391 def roomUserChangedNickHandler(self, room_jid, old_nick, new_nick, profile): |
395 """Called when an user joined a MUC room""" | 392 """Called when an user joined a MUC room""" |
396 if not self.check_profile(profile): | |
397 return | |
398 if room_jid in self.chat_wins: | 393 if room_jid in self.chat_wins: |
399 self.chat_wins[room_jid].changeUserNick(old_nick, new_nick) | 394 self.chat_wins[room_jid].changeUserNick(old_nick, new_nick) |
400 log.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}) | 395 log.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}) |
401 | 396 |
402 def roomNewSubject(self, room_jid, subject, profile): | 397 def roomNewSubjectHandler(self, room_jid, subject, profile): |
403 """Called when subject of MUC room change""" | 398 """Called when subject of MUC room change""" |
404 if not self.check_profile(profile): | |
405 return | |
406 if room_jid in self.chat_wins: | 399 if room_jid in self.chat_wins: |
407 self.chat_wins[room_jid].setSubject(subject) | 400 self.chat_wins[room_jid].setSubject(subject) |
408 log.debug(_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid': room_jid, "subject": subject}) | 401 log.debug(_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid': room_jid, "subject": subject}) |
409 | 402 |
410 def tarotGameStarted(self, room_jid, referee, players, profile): | 403 def tarotGameStartedHandler(self, room_jid, referee, players, profile): |
411 if not self.check_profile(profile): | |
412 return | |
413 log.debug(_("Tarot Game Started \o/")) | 404 log.debug(_("Tarot Game Started \o/")) |
414 if room_jid in self.chat_wins: | 405 if room_jid in self.chat_wins: |
415 self.chat_wins[room_jid].startGame("Tarot", referee, players) | 406 self.chat_wins[room_jid].startGame("Tarot", referee, players) |
416 log.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]}) | 407 log.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]}) |
417 | 408 |
418 def tarotGameNew(self, room_jid, hand, profile): | 409 def tarotGameNewHandler(self, room_jid, hand, profile): |
419 if not self.check_profile(profile): | |
420 return | |
421 log.debug(_("New Tarot Game")) | 410 log.debug(_("New Tarot Game")) |
422 if room_jid in self.chat_wins: | 411 if room_jid in self.chat_wins: |
423 self.chat_wins[room_jid].getGame("Tarot").newGame(hand) | 412 self.chat_wins[room_jid].getGame("Tarot").newGame(hand) |
424 | 413 |
425 def tarotChooseContrat(self, room_jid, xml_data, profile): | 414 def tarotGameChooseContratHandler(self, room_jid, xml_data, profile): |
426 """Called when the player has to select his contrat""" | 415 """Called when the player has to select his contrat""" |
427 if not self.check_profile(profile): | |
428 return | |
429 log.debug(_("Tarot: need to select a contrat")) | 416 log.debug(_("Tarot: need to select a contrat")) |
430 if room_jid in self.chat_wins: | 417 if room_jid in self.chat_wins: |
431 self.chat_wins[room_jid].getGame("Tarot").chooseContrat(xml_data) | 418 self.chat_wins[room_jid].getGame("Tarot").chooseContrat(xml_data) |
432 | 419 |
433 def tarotShowCards(self, room_jid, game_stage, cards, data, profile): | 420 def tarotGameShowCardsHandler(self, room_jid, game_stage, cards, data, profile): |
434 if not self.check_profile(profile): | |
435 return | |
436 log.debug(_("Show cards")) | 421 log.debug(_("Show cards")) |
437 if room_jid in self.chat_wins: | 422 if room_jid in self.chat_wins: |
438 self.chat_wins[room_jid].getGame("Tarot").showCards(game_stage, cards, data) | 423 self.chat_wins[room_jid].getGame("Tarot").showCards(game_stage, cards, data) |
439 | 424 |
440 def tarotMyTurn(self, room_jid, profile): | 425 def tarotGameYourTurnHandler(self, room_jid, profile): |
441 if not self.check_profile(profile): | |
442 return | |
443 log.debug(_("My turn to play")) | 426 log.debug(_("My turn to play")) |
444 if room_jid in self.chat_wins: | 427 if room_jid in self.chat_wins: |
445 self.chat_wins[room_jid].getGame("Tarot").myTurn() | 428 self.chat_wins[room_jid].getGame("Tarot").myTurn() |
446 | 429 |
447 def tarotScore(self, room_jid, xml_data, winners, loosers, profile): | 430 def tarotGameScoreHandler(self, room_jid, xml_data, winners, loosers, profile): |
448 """Called when the game is finished and the score are updated""" | 431 """Called when the game is finished and the score are updated""" |
449 if not self.check_profile(profile): | |
450 return | |
451 log.debug(_("Tarot: score received")) | 432 log.debug(_("Tarot: score received")) |
452 if room_jid in self.chat_wins: | 433 if room_jid in self.chat_wins: |
453 self.chat_wins[room_jid].getGame("Tarot").showScores(xml_data, winners, loosers) | 434 self.chat_wins[room_jid].getGame("Tarot").showScores(xml_data, winners, loosers) |
454 | 435 |
455 def tarotCardsPlayed(self, room_jid, player, cards, profile): | 436 def tarotGameCardsPlayedHandler(self, room_jid, player, cards, profile): |
456 if not self.check_profile(profile): | |
457 return | |
458 log.debug(_("Card(s) played (%(player)s): %(cards)s") % {"player": player, "cards": cards}) | 437 log.debug(_("Card(s) played (%(player)s): %(cards)s") % {"player": player, "cards": cards}) |
459 if room_jid in self.chat_wins: | 438 if room_jid in self.chat_wins: |
460 self.chat_wins[room_jid].getGame("Tarot").cardsPlayed(player, cards) | 439 self.chat_wins[room_jid].getGame("Tarot").cardsPlayed(player, cards) |
461 | 440 |
462 def tarotInvalidCards(self, room_jid, phase, played_cards, invalid_cards, profile): | 441 def tarotGameInvalidCardsHandler(self, room_jid, phase, played_cards, invalid_cards, profile): |
463 if not self.check_profile(profile): | |
464 return | |
465 log.debug(_("Cards played are not valid: %s") % invalid_cards) | 442 log.debug(_("Cards played are not valid: %s") % invalid_cards) |
466 if room_jid in self.chat_wins: | 443 if room_jid in self.chat_wins: |
467 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) | 444 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) |
468 | 445 |
469 def quizGameStarted(self, room_jid, referee, players, profile): | 446 def quizGameStartedHandler(self, room_jid, referee, players, profile): |
470 if not self.check_profile(profile): | |
471 return | |
472 log.debug(_("Quiz Game Started \o/")) | 447 log.debug(_("Quiz Game Started \o/")) |
473 if room_jid in self.chat_wins: | 448 if room_jid in self.chat_wins: |
474 self.chat_wins[room_jid].startGame("Quiz", referee, players) | 449 self.chat_wins[room_jid].startGame("Quiz", referee, players) |
475 log.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]}) | 450 log.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]}) |
476 | 451 |
477 def quizGameNew(self, room_jid, data, profile): | 452 def quizGameNewHandler(self, room_jid, data, profile): |
478 if not self.check_profile(profile): | |
479 return | |
480 log.debug(_("New Quiz Game")) | 453 log.debug(_("New Quiz Game")) |
481 if room_jid in self.chat_wins: | 454 if room_jid in self.chat_wins: |
482 self.chat_wins[room_jid].getGame("Quiz").quizGameNew(data) | 455 self.chat_wins[room_jid].getGame("Quiz").quizGameNewHandler(data) |
483 | 456 |
484 def quizGameQuestion(self, room_jid, question_id, question, timer, profile): | 457 def quizGameQuestionHandler(self, room_jid, question_id, question, timer, profile): |
485 """Called when a new question is asked""" | 458 """Called when a new question is asked""" |
486 if not self.check_profile(profile): | |
487 return | |
488 log.debug(_(u"Quiz: new question: %s") % question) | 459 log.debug(_(u"Quiz: new question: %s") % question) |
489 if room_jid in self.chat_wins: | 460 if room_jid in self.chat_wins: |
490 self.chat_wins[room_jid].getGame("Quiz").quizGameQuestion(question_id, question, timer) | 461 self.chat_wins[room_jid].getGame("Quiz").quizGameQuestionHandler(question_id, question, timer) |
491 | 462 |
492 def quizGamePlayerBuzzed(self, room_jid, player, pause, profile): | 463 def quizGamePlayerBuzzedHandler(self, room_jid, player, pause, profile): |
493 """Called when a player pushed the buzzer""" | 464 """Called when a player pushed the buzzer""" |
494 if not self.check_profile(profile): | 465 if room_jid in self.chat_wins: |
495 return | 466 self.chat_wins[room_jid].getGame("Quiz").quizGamePlayerBuzzedHandler(player, pause) |
496 if room_jid in self.chat_wins: | 467 |
497 self.chat_wins[room_jid].getGame("Quiz").quizGamePlayerBuzzed(player, pause) | 468 def quizGamePlayerSaysHandler(self, room_jid, player, text, delay, profile): |
498 | |
499 def quizGamePlayerSays(self, room_jid, player, text, delay, profile): | |
500 """Called when a player say something""" | 469 """Called when a player say something""" |
501 if not self.check_profile(profile): | 470 if room_jid in self.chat_wins: |
502 return | 471 self.chat_wins[room_jid].getGame("Quiz").quizGamePlayerSaysHandler(player, text, delay) |
503 if room_jid in self.chat_wins: | 472 |
504 self.chat_wins[room_jid].getGame("Quiz").quizGamePlayerSays(player, text, delay) | 473 def quizGameAnswerResultHandler(self, room_jid, player, good_answer, score, profile): |
505 | |
506 def quizGameAnswerResult(self, room_jid, player, good_answer, score, profile): | |
507 """Called when a player say something""" | 474 """Called when a player say something""" |
508 if not self.check_profile(profile): | 475 if room_jid in self.chat_wins: |
509 return | 476 self.chat_wins[room_jid].getGame("Quiz").quizGameAnswerResultHandler(player, good_answer, score) |
510 if room_jid in self.chat_wins: | 477 |
511 self.chat_wins[room_jid].getGame("Quiz").quizGameAnswerResult(player, good_answer, score) | 478 def quizGameTimerExpiredHandler(self, room_jid, profile): |
512 | |
513 def quizGameTimerExpired(self, room_jid, profile): | |
514 """Called when nobody answered the question in time""" | 479 """Called when nobody answered the question in time""" |
515 if not self.check_profile(profile): | 480 if room_jid in self.chat_wins: |
516 return | 481 self.chat_wins[room_jid].getGame("Quiz").quizGameTimerExpiredHandler() |
517 if room_jid in self.chat_wins: | 482 |
518 self.chat_wins[room_jid].getGame("Quiz").quizGameTimerExpired() | 483 def quizGameTimerRestartedHandler(self, room_jid, time_left, profile): |
519 | |
520 def quizGameTimerRestarted(self, room_jid, time_left, profile): | |
521 """Called when the question is not answered, and we still have time""" | 484 """Called when the question is not answered, and we still have time""" |
522 if not self.check_profile(profile): | 485 if room_jid in self.chat_wins: |
523 return | 486 self.chat_wins[room_jid].getGame("Quiz").quizGameTimerRestartedHandler(time_left) |
524 if room_jid in self.chat_wins: | 487 |
525 self.chat_wins[room_jid].getGame("Quiz").quizGameTimerRestarted(time_left) | 488 def chatStateReceivedHandler(self, from_jid_s, state, profile): |
526 | |
527 def chatStateReceived(self, from_jid_s, state, profile): | |
528 """Callback when a new chat state is received. | 489 """Callback when a new chat state is received. |
529 @param from_jid_s: JID of the contact who sent his state, or '@ALL@' | 490 @param from_jid_s: JID of the contact who sent his state, or '@ALL@' |
530 @param state: new state (string) | 491 @param state: new state (string) |
531 @profile: current profile | 492 @profile: current profile |
532 """ | 493 """ |
533 if not self.check_profile(profile): | |
534 return | |
535 | 494 |
536 if from_jid_s == '@ALL@': | 495 if from_jid_s == '@ALL@': |
537 target = '@ALL@' | 496 target = '@ALL@' |
538 nick = C.ALL_OCCUPANTS | 497 nick = C.ALL_OCCUPANTS |
539 else: | 498 else: |
554 if answer: | 513 if answer: |
555 self.bridge.subscription("subscribed", entity.bare, profile_key=profile) | 514 self.bridge.subscription("subscribed", entity.bare, profile_key=profile) |
556 else: | 515 else: |
557 self.bridge.subscription("unsubscribed", entity.bare, profile_key=profile) | 516 self.bridge.subscription("unsubscribed", entity.bare, profile_key=profile) |
558 | 517 |
559 def subscribe(self, type, raw_jid, profile): | 518 def subscribeHandler(self, type, raw_jid, profile): |
560 """Called when a subsciption management signal is received""" | 519 """Called when a subsciption management signal is received""" |
561 if not self.check_profile(profile): | |
562 return | |
563 entity = JID(raw_jid) | 520 entity = JID(raw_jid) |
564 if type == "subscribed": | 521 if type == "subscribed": |
565 # this is a subscription confirmation, we just have to inform user | 522 # this is a subscription confirmation, we just have to inform user |
566 self.showDialog(_("The contact %s has accepted your subscription") % entity.bare, _('Subscription confirmation')) | 523 self.showDialog(_("The contact %s has accepted your subscription") % entity.bare, _('Subscription confirmation')) |
567 elif type == "unsubscribed": | 524 elif type == "unsubscribed": |
575 raise NotImplementedError | 532 raise NotImplementedError |
576 | 533 |
577 def showAlert(self, message): | 534 def showAlert(self, message): |
578 pass #FIXME | 535 pass #FIXME |
579 | 536 |
580 def paramUpdate(self, name, value, namespace, profile): | 537 def paramUpdateHandler(self, name, value, namespace, profile): |
581 if not self.check_profile(profile): | |
582 return | |
583 log.debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace': namespace, 'name': name, 'value': value}) | 538 log.debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace': namespace, 'name': name, 'value': value}) |
584 if (namespace, name) == ("Connection", "JabberID"): | 539 if (namespace, name) == ("Connection", "JabberID"): |
585 log.debug(_("Changing JID to %s") % value) | 540 log.debug(_("Changing JID to %s") % value) |
586 self.profiles[profile]['whoami'] = JID(value) | 541 self.profiles[profile]['whoami'] = JID(value) |
587 elif (namespace, name) == ("Misc", "Watched"): | 542 elif (namespace, name) == ("Misc", "Watched"): |
588 self.profiles[profile]['watched'] = value.split() | 543 self.profiles[profile]['watched'] = value.split() |
589 | 544 |
590 def contactDeleted(self, jid, profile): | 545 def contactDeletedHandler(self, jid, profile): |
591 if not self.check_profile(profile): | |
592 return | |
593 target = JID(jid) | 546 target = JID(jid) |
594 self.contact_list.remove(target) | 547 self.contact_list.remove(target) |
595 try: | 548 try: |
596 self.profiles[profile]['onlineContact'].remove(target.bare) | 549 self.profiles[profile]['onlineContact'].remove(target.bare) |
597 except KeyError: | 550 except KeyError: |
598 pass | 551 pass |
599 | 552 |
600 def entityDataUpdated(self, jid_str, key, value, profile): | 553 def entityDataUpdatedHandler(self, jid_str, key, value, profile): |
601 if not self.check_profile(profile): | |
602 return | |
603 jid = JID(jid_str) | 554 jid = JID(jid_str) |
604 if key == "nick": | 555 if key == "nick": |
605 if jid in self.contact_list: | 556 if jid in self.contact_list: |
606 self.contact_list.setCache(jid, 'nick', value) | 557 self.contact_list.setCache(jid, 'nick', value) |
607 self.contact_list.replace(jid) | 558 self.contact_list.replace(jid) |
609 if jid in self.contact_list: | 560 if jid in self.contact_list: |
610 filename = self.bridge.getAvatarFile(value) | 561 filename = self.bridge.getAvatarFile(value) |
611 self.contact_list.setCache(jid, 'avatar', filename) | 562 self.contact_list.setCache(jid, 'avatar', filename) |
612 self.contact_list.replace(jid) | 563 self.contact_list.replace(jid) |
613 | 564 |
614 def askConfirmation(self, confirm_id, confirm_type, data, profile): | 565 def askConfirmationHandler(self, confirm_id, confirm_type, data, profile): |
615 raise NotImplementedError | 566 raise NotImplementedError |
616 | 567 |
617 def actionResult(self, type, id, data): | 568 def actionResultHandler(self, type, id, data): |
618 raise NotImplementedError | 569 raise NotImplementedError |
619 | 570 |
620 def launchAction(self, callback_id, data=None, profile_key="@NONE@"): | 571 def launchAction(self, callback_id, data=None, profile_key="@NONE@"): |
621 """ Launch a dynamic action | 572 """ Launch a dynamic action |
622 @param callback_id: id of the action to launch | 573 @param callback_id: id of the action to launch |