diff libervia.py @ 251:24335e82fef0

plugin XEP-249: added parameter Misc / Auto-join MUC on invitation: - also cleaned getOrCreateLiberviaWidget and _chatStateReceivedCb from unused arguments
author souliane <souliane@mailoo.org>
date Tue, 05 Nov 2013 21:12:14 +0100
parents 38e6211d36ca
children cc778206b7ae
line wrap: on
line diff
--- a/libervia.py	Wed Oct 23 18:33:16 2013 +0200
+++ b/libervia.py	Tue Nov 05 21:12:14 2013 +0100
@@ -119,7 +119,7 @@
                          "tarotGameContratChoosed", "tarotGamePlayCards", "launchRadioCollective",
                          "getWaitingSub", "subscription", "delContact", "updateContact", "getCard",
                          "getEntityData", "getParamsUI", "asyncGetParamA", "setParam", "launchAction",
-                         "disconnect", "chatStateComposing", "getNewAccountDomain"
+                         "disconnect", "chatStateComposing", "getNewAccountDomain", "confirmationAnswer"
                         ])
 
 
@@ -354,6 +354,10 @@
             self._roomUserJoinedCb(*args)
         elif name == 'roomUserLeft':
             self._roomUserLeftCb(*args)
+        elif name == 'askConfirmation':
+            self._askConfirmation(*args)
+        elif name == 'newAlert':
+            self._newAlert(*args)
         elif name == 'tarotGameStarted':
             self._tarotGameStartedCb(*args)
         elif name == 'tarotGameNew' or \
@@ -509,14 +513,11 @@
                     return None
         return None
 
-    def getOrCreateLiberviaWidget(self, class_, entity, add=True, refresh=True, add=True):
+    def getOrCreateLiberviaWidget(self, class_, entity, select=True):
         """Get the matching LiberviaWidget if it exists, or create a new one.
         @param class_: class of the panel (ChatPanel, MicroblogPanel...)
         @param entity: polymorphic parameter, see class_.matchEntity.
-        @param refresh: if True, refresh the display of a widget that is found
-                        (ignored if no widget is found and a new one is created)
-        @param add: if True, add a widget that is created to the selected tab
-                    (ignored if a widget is found and no new one is created)
+        @param select: if True, select the widget that has been found or created
         @return: the newly created wigdet if REUSE_EXISTING_LIBERVIA_WIDGETS
          is set to False or if the widget has not been found, the existing
          widget that has been found otherwise."""
@@ -525,14 +526,13 @@
             lib_wid = self.getLiberviaWidget(class_, entity)
         if lib_wid is None:
             lib_wid = class_.createPanel(self, entity)
-        elif refresh:
+        else:
             # remove the widget from its previous panel
             panel = lib_wid.getWidgetsPanel(verbose=False)
             if panel is not None:
                 panel.removeWidget(lib_wid)
-        if add or refresh:
-            self.addWidget(lib_wid)
-        if refresh:
+        self.addWidget(lib_wid)
+        if select:
             # must be done after the widget is added,
             # for example to scroll to the bottom
             self.setSelected(lib_wid)
@@ -657,11 +657,10 @@
                     if lib_wid.isJidAccepted(entity_jid_s) or (self.whoami and entity_jid_s == self.whoami.bare):
                         lib_wid.updateValue('avatar', entity_jid_s, avatar)
 
-    def _chatStateReceivedCb(self, from_jid_s, state, profile):
+    def _chatStateReceivedCb(self, from_jid_s, state):
         """Callback when a new chat state is received.
         @param from_jid_s: JID from the contact who sent his state
         @param state: new state
-        @profile: current profile
         """
         _from = JID(from_jid_s).bare if from_jid_s != "@ALL@" else from_jid_s
         for lib_wid in self.libervia_widgets:
@@ -679,6 +678,17 @@
                     # TODO: chat state notification for groupchat
                     pass
 
+    def _askConfirmation(self, confirmation_id, confirmation_type, data):
+        answer_data = {}
+
+        def confirm_cb(result):
+            self.bridge.call('confirmationAnswer', None, confirmation_id, result, answer_data)
+
+        if confirmation_type == "YES/NO":
+            dialog.ConfirmDialog(confirm_cb, text=data["message"], title=data["title"]).show()
+
+    def _newAlert(self, message, title, alert_type):
+        dialog.InfoDialog(title, message).show()
 
 if __name__ == '__main__':
     pyjd.setup("http://localhost:8080/libervia.html")