diff libervia.py @ 20:8f4b1a8914c3

- User status is now updated - by default, the uniBar target the status - clicking on user's status unselect the selected widget
author Goffi <goffi@goffi.org>
date Sat, 16 Apr 2011 18:06:02 +0200
parents e8e3704eb97f
children 77c2e48efa29
line wrap: on
line diff
--- a/libervia.py	Sat Apr 16 01:46:01 2011 +0200
+++ b/libervia.py	Sat Apr 16 18:06:02 2011 +0200
@@ -67,7 +67,7 @@
 class BridgeCall(LiberviaJsonProxy):
     def __init__(self):
         LiberviaJsonProxy.__init__(self, "/json_api",
-                        ["getContacts", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory"])
+                        ["getContacts", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", "getPresenceStatus"])
 
 class BridgeSignals(LiberviaJsonProxy):
     def __init__(self):
@@ -90,9 +90,12 @@
             if _txt:
                 if _txt.startswith('@'):
                     self.host.bridge.call('sendMblog', None, self.getText())
+                elif self.host.selected == None:
+                    print "changement de status pour", _txt
+                    self.host.bridge.call('setStatus', None, _txt)
                 elif isinstance(self.host.selected, ChatPanel):
                     _chat = self.host.selected
-                    self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', 'chat') 
+                    self.host.bridge.call('sendMessage', None, str(_chat.target), _txt, '', 'chat')
             self.setText('')
 
     def complete(self):
@@ -109,7 +112,7 @@
         self.selected = None
         self.uniBox = UniBox(self)
         self.uniBox.addKey("@@: ")
-        self.statusPanel = StatusPanel()
+        self.statusPanel = StatusPanel(self)
         self.contactPanel = ContactPanel(self)
         self.panel = MainPanel(self)
         self.middle_panel = self.panel.middle_panel
@@ -168,9 +171,14 @@
             self._personalEventCb(*args)
         elif name == 'newMessage':
             self._newMessageCb(*args)
+        elif name == 'presenceUpdate':
+            self._presenceUpdateCb(*args)
 
     def _getProfileJidCB(self, jid):
         self.whoami = JID(jid)
+        #we can now ask our status
+        self.bridge.call('getPresenceStatus', self._getPresenceStatusCB)
+
 
 
     ## Signals callbacks ##
@@ -202,6 +210,20 @@
             if isinstance(panel,ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare):
                 panel.printMessage(_from, msg)
 
+    def _presenceUpdateCb(self, entity, show, priority, statuses):
+        _entity = JID(entity)
+        #XXX: QnD way to only get our status
+        if self.whoami and self.whoami.bare == _entity.bare and statuses:
+            self.statusPanel.changeStatus(statuses.values()[0])
+            
+    def _getPresenceStatusCB(self, presence_data):
+        #XXX we are only interested in our own presence so far
+        if self.whoami and presence_data.has_key(self.whoami.bare):
+            myjid = self.whoami.bare
+            if presence_data[myjid]:
+                args = presence_data[myjid].values()[0]
+                self._presenceUpdateCb(myjid, *args)
+
 if __name__ == '__main__':
     pyjd.setup("http://localhost:8080/libervia.html")
     app = SatWebFrontend()