diff libervia.py @ 55:d5266c41ca24

Roster list update, contact deletion + some refactoring
author Goffi <goffi@goffi.org>
date Sun, 29 May 2011 02:13:53 +0200
parents f25c4077f6b9
children e552a67b933d
line wrap: on
line diff
--- a/libervia.py	Sat May 28 20:18:14 2011 +0200
+++ b/libervia.py	Sun May 29 02:13:53 2011 +0200
@@ -68,7 +68,7 @@
         LiberviaJsonProxy.__init__(self, "/json_api",
                         ["getContacts", "addContact", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus",
                          "joinMUC", "getRoomJoined", "launchTarotGame", "getTarotCardsPaths", "tarotGameReady", "tarotGameContratChoosed",
-                         "tarotGamePlayCards", "getWaitingSub", "subscription"])
+                         "tarotGamePlayCards", "getWaitingSub", "subscription", "delContact"])
 
 class BridgeSignals(LiberviaJsonProxy):
     def __init__(self):
@@ -160,7 +160,7 @@
     def _getContactsCB(self, contacts_data):
         for contact in contacts_data:
             jid, attributes, groups = contact
-            self.contact_panel.addContact(jid, attributes, groups)
+            self._newContactCb(jid, attributes, groups)
 
     def _getSignalsCB(self, signal_data):
         bridge_signals = BridgeSignals()
@@ -191,6 +191,10 @@
             self._tarotGameGenericCb(name, args[0], args[1:])
         elif name == 'subscribe':
             self._subscribeCb(*args)
+        elif name == 'contactDeleted':
+            self._contactDeletedCb(*args)
+        elif name == 'newContact':
+            self._newContactCb(*args)
 
     def _getProfileJidCB(self, jid):
         self.whoami = JID(jid)
@@ -283,10 +287,10 @@
 
     def _subscribeCb(self, sub_type, entity):
         if sub_type == 'subscribed':
-            dialog.SimpleDialog('Subscription confirmation', 'The contact <b>%s</b> has added you to his/her contact list' % html_sanitize(entity)).show()
+            dialog.InfoDialog('Subscription confirmation', 'The contact <b>%s</b> has added you to his/her contact list' % html_sanitize(entity)).show()
 
         elif sub_type == 'unsubscribed':
-            dialog.SimpleDialog('Subscription refusal', 'The contact <b>%s</b> has refused to add you in his/her contact list' % html_sanitize(entity)).show()
+            dialog.InfoDialog('Subscription refusal', 'The contact <b>%s</b> has refused to add you in his/her contact list' % html_sanitize(entity)).show()
 
         elif sub_type == 'subscribe':
             #The user want to subscribe to our presence
@@ -302,7 +306,11 @@
             _dialog.setHTML('<b>Add contact request</b>')
             _dialog.show()
 
-            
+    def _contactDeletedCb(self, entity):
+        self.contact_panel.removeContact(entity)
+
+    def _newContactCb(self, contact, attributes, groups):
+        self.contact_panel.updateContact(contact, attributes, groups)
 
 if __name__ == '__main__':
     pyjd.setup("http://localhost:8080/libervia.html")