diff 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
line wrap: on
line diff
--- a/frontends/quick_frontend/quick_app.py	Mon Aug 16 21:59:52 2010 +0800
+++ b/frontends/quick_frontend/quick_app.py	Wed Aug 18 12:45:48 2010 +0800
@@ -48,6 +48,7 @@
         self.bridge.register("disconnected", self.disconnected)
         self.bridge.register("newContact", self.newContact)
         self.bridge.register("newMessage", self.newMessage)
+        self.bridge.register("newAlert", self.newAlert)
         self.bridge.register("presenceUpdate", self.presenceUpdate)
         self.bridge.register("roomJoined", self.roomJoined)
         self.bridge.register("roomUserJoined", self.roomUserJoined)
@@ -199,6 +200,13 @@
         self.current_action_ids_cb = {}
         self.chat_wins[win.short].printMessage(sender, msg, profile)
 
+    def newAlert(self, msg, title, type, profile):
+        if not self.check_profile(profile):
+            return
+        assert type in ['INFO','ERROR']
+        self.showDialog(unicode(msg),unicode(title),type.lower())
+
+    
     def setStatusOnline(self, online=True):
         pass
 
@@ -344,7 +352,14 @@
         debug (_("Cards played are not valid: %s") % invalid_cards)
         if self.chat_wins.has_key(room_jid):
             self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards)
-   
+  
+    def _subscribe_cb(self, answer, data):
+        entity, profile = data
+        if answer:
+            self.bridge.subscription("subscribed", entity.short, profile_key = profile)
+        else:
+            self.bridge.subscription("unsubscribed", entity.short, profile_key = profile)
+
     def subscribe(self, type, raw_jid, profile):
         """Called when a subsciption management signal is received"""
         if not self.check_profile(profile):
@@ -358,13 +373,9 @@
             self.showDialog(_("The contact %s has refused your subscription") % entity.short, _('Subscription refusal'), 'error')
         elif type=="subscribe":
             # this is a subscriptionn request, we have to ask for user confirmation
-            answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.short, _('Subscription confirmation'), 'yes/no')
-            if answer:
-                self.bridge.subscription("subscribed", entity.short, profile_key = profile)
-            else:
-                self.bridge.subscription("unsubscribed", entity.short, profile_key = profile)
+            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))
 
-    def showDialog(self, message, title, type="info"):
+    def showDialog(self, message, title, type="info", answer_cb = None):
         raise NotImplementedError
     
     def showAlert(self, message):