comparison frontends/quick_frontend/quick_app.py @ 182:556c2bd7c344

Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
author Goffi <goffi@goffi.org>
date Wed, 18 Aug 2010 12:45:48 +0800
parents 8a2053de6f8c
children 9ee4a1d0d7fb
comparison
equal deleted inserted replaced
181:a566f654929e 182:556c2bd7c344
46 sys.exit(1) 46 sys.exit(1)
47 self.bridge.register("connected", self.connected) 47 self.bridge.register("connected", self.connected)
48 self.bridge.register("disconnected", self.disconnected) 48 self.bridge.register("disconnected", self.disconnected)
49 self.bridge.register("newContact", self.newContact) 49 self.bridge.register("newContact", self.newContact)
50 self.bridge.register("newMessage", self.newMessage) 50 self.bridge.register("newMessage", self.newMessage)
51 self.bridge.register("newAlert", self.newAlert)
51 self.bridge.register("presenceUpdate", self.presenceUpdate) 52 self.bridge.register("presenceUpdate", self.presenceUpdate)
52 self.bridge.register("roomJoined", self.roomJoined) 53 self.bridge.register("roomJoined", self.roomJoined)
53 self.bridge.register("roomUserJoined", self.roomUserJoined) 54 self.bridge.register("roomUserJoined", self.roomUserJoined)
54 self.bridge.register("roomUserLeft", self.roomUserLeft) 55 self.bridge.register("roomUserLeft", self.roomUserLeft)
55 self.bridge.register("roomNewSubject", self.roomNewSubject) 56 self.bridge.register("roomNewSubject", self.roomNewSubject)
197 win = addr if sender.short == self.profiles[profile]['whoami'].short else sender 198 win = addr if sender.short == self.profiles[profile]['whoami'].short else sender
198 self.current_action_ids = set() 199 self.current_action_ids = set()
199 self.current_action_ids_cb = {} 200 self.current_action_ids_cb = {}
200 self.chat_wins[win.short].printMessage(sender, msg, profile) 201 self.chat_wins[win.short].printMessage(sender, msg, profile)
201 202
203 def newAlert(self, msg, title, type, profile):
204 if not self.check_profile(profile):
205 return
206 assert type in ['INFO','ERROR']
207 self.showDialog(unicode(msg),unicode(title),type.lower())
208
209
202 def setStatusOnline(self, online=True): 210 def setStatusOnline(self, online=True):
203 pass 211 pass
204 212
205 def presenceUpdate(self, jabber_id, show, priority, statuses, profile): 213 def presenceUpdate(self, jabber_id, show, priority, statuses, profile):
206 if not self.check_profile(profile): 214 if not self.check_profile(profile):
342 if not self.check_profile(profile): 350 if not self.check_profile(profile):
343 return 351 return
344 debug (_("Cards played are not valid: %s") % invalid_cards) 352 debug (_("Cards played are not valid: %s") % invalid_cards)
345 if self.chat_wins.has_key(room_jid): 353 if self.chat_wins.has_key(room_jid):
346 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) 354 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards)
347 355
356 def _subscribe_cb(self, answer, data):
357 entity, profile = data
358 if answer:
359 self.bridge.subscription("subscribed", entity.short, profile_key = profile)
360 else:
361 self.bridge.subscription("unsubscribed", entity.short, profile_key = profile)
362
348 def subscribe(self, type, raw_jid, profile): 363 def subscribe(self, type, raw_jid, profile):
349 """Called when a subsciption management signal is received""" 364 """Called when a subsciption management signal is received"""
350 if not self.check_profile(profile): 365 if not self.check_profile(profile):
351 return 366 return
352 entity = JID(raw_jid) 367 entity = JID(raw_jid)
356 elif type=="unsubscribed": 371 elif type=="unsubscribed":
357 # this is a subscription refusal, we just have to inform user 372 # this is a subscription refusal, we just have to inform user
358 self.showDialog(_("The contact %s has refused your subscription") % entity.short, _('Subscription refusal'), 'error') 373 self.showDialog(_("The contact %s has refused your subscription") % entity.short, _('Subscription refusal'), 'error')
359 elif type=="subscribe": 374 elif type=="subscribe":
360 # this is a subscriptionn request, we have to ask for user confirmation 375 # this is a subscriptionn request, we have to ask for user confirmation
361 answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.short, _('Subscription confirmation'), 'yes/no') 376 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))
362 if answer: 377
363 self.bridge.subscription("subscribed", entity.short, profile_key = profile) 378 def showDialog(self, message, title, type="info", answer_cb = None):
364 else:
365 self.bridge.subscription("unsubscribed", entity.short, profile_key = profile)
366
367 def showDialog(self, message, title, type="info"):
368 raise NotImplementedError 379 raise NotImplementedError
369 380
370 def showAlert(self, message): 381 def showAlert(self, message):
371 pass #FIXME 382 pass #FIXME
372 383