changeset 52:6455fb62ff83

Connection/disconnection signals - wix, sortilege: management of this new signals /!\ sortilege is bugged, the contact list window is not updated correctly
author Goffi <goffi@goffi.org>
date Thu, 07 Jan 2010 01:55:30 +1100
parents 8c67ea98ab91
children 6dfe5bb10008
files frontends/quick_frontend/quick_app.py frontends/quick_frontend/quick_contact_list.py frontends/quick_frontend/quick_contact_management.py frontends/sortilege/sortilege frontends/wix/main_window.py sat.tac sat_bridge/DBus.py
diffstat 7 files changed, 65 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/quick_frontend/quick_app.py	Thu Jan 07 00:17:27 2010 +1100
+++ b/frontends/quick_frontend/quick_app.py	Thu Jan 07 01:55:30 2010 +1100
@@ -32,6 +32,8 @@
         
         ## bridge ##
         self.bridge=DBusBridgeFrontend()
+        self.bridge.register("connected", self.connected)
+        self.bridge.register("disconnected", self.disconnected)
         self.bridge.register("newContact", self.newContact)
         self.bridge.register("newMessage", self.newMessage)
         self.bridge.register("presenceUpdate", self.presenceUpdate)
@@ -54,6 +56,9 @@
 
         if self.bridge.isConnected():
             self.setStatusOnline(True)
+        else:
+            self.setStatusOnline(False)
+            return
 
         ### now we fill the contact list ###
         for contact in self.bridge.getContacts():
@@ -73,6 +78,18 @@
             self.subscribe(waitingSub[sub], sub)
 
 
+    def connected(self):
+        """called when the connection is made"""
+        debug("Connected")
+        self.setStatusOnline(True)
+
+    def disconnected(self):
+        """called when the connection is closed"""
+        debug("Disconnected")
+        self.CM.clear()
+        self.contactList.clear_contacts()
+        self.setStatusOnline(False)
+    
     def newContact(self, JabberId, attributes, groups):
         entity=JID(JabberId)
         self.rosterList[entity.short]=(dict(attributes), list(groups))
--- a/frontends/quick_frontend/quick_contact_list.py	Thu Jan 07 00:17:27 2010 +1100
+++ b/frontends/quick_frontend/quick_contact_list.py	Thu Jan 07 01:55:30 2010 +1100
@@ -33,6 +33,10 @@
         debug("Contact List init")
         self.CM = CM
     
+    def clear_contacts(self, jid):
+        """Clear all the contact list"""
+        raise NotImplementedError
+    
     def replace(self, jid):
         """add a contact to the list if doesn't exist, else update it"""
         raise NotImplementedError
--- a/frontends/quick_frontend/quick_contact_management.py	Thu Jan 07 00:17:27 2010 +1100
+++ b/frontends/quick_frontend/quick_contact_management.py	Thu Jan 07 01:55:30 2010 +1100
@@ -31,6 +31,10 @@
     def __init__(self):
         self.__contactlist = {}
 
+    def clear(self):
+        """Clear all the contact list"""
+        self.__contactlist.clear()
+
     def add(self, entity):
         """Add contact to the list, update resources"""
         if not self.__contactlist.has_key(entity.short):
--- a/frontends/sortilege/sortilege	Thu Jan 07 00:17:27 2010 +1100
+++ b/frontends/sortilege/sortilege	Thu Jan 07 01:55:30 2010 +1100
@@ -45,6 +45,7 @@
 from quick_frontend.quick_app import QuickApp
 from quick_frontend.quick_contact_management import QuickContactManagement
 
+
 ### logging configuration FIXME: put this elsewhere ###
 logging.basicConfig(level=logging.CRITICAL,  #TODO: configure it top put messages in a log file
                     format='%(message)s')
@@ -78,7 +79,6 @@
         self.sizer.update()
         return chat 
         
-
 class ContactList(Window, QuickContactList):
     
     def __init__(self, host, CM):
@@ -101,6 +101,12 @@
     def registerEnterCB(self, CB):
         self.__enterCB=CB
 
+    def clear_contacts(self):
+        """clear all the contact list"""
+        del self.jid_list[:]
+        self.__index = 0
+        self.update()  #FIXME: window is not updated correctly (contacts are still here until C-L)
+
     def replace(self, jid):
         """add a contact to the list"""
         name = self.CM.getAttr(jid,'name')
@@ -256,7 +262,7 @@
     def onContactChoosed(self, jid_txt):
         """Called when a contact is selected in contact list."""
         jid=JID(jid_txt)
-        debug ("contact choose: %s", jid)
+        debug ("contact choosed: %s", jid)
         self.showChat(jid.short)
         self.statusBar.remove_item(jid.short)
         if len(self.statusBar)==0:
--- a/frontends/wix/main_window.py	Thu Jan 07 00:17:27 2010 +1100
+++ b/frontends/wix/main_window.py	Thu Jan 07 01:55:30 2010 +1100
@@ -126,6 +126,10 @@
 
         return html
 
+    def clear_contacts(self):
+        """Clear all the contact list"""
+        self.Clear()
+
     def add(self, jid):
         """add a contact to the list"""
         debug ("adding %s",jid)
@@ -171,7 +175,6 @@
         self.contactList.registerActivatedCB(self.onContactActivated)
         self.chat_wins=ChatList(self)
         self.CreateStatusBar()
-        self.SetStatusText(msgOFFLINE)
         self.createMenus()
 
         #ToolBar
@@ -197,7 +200,7 @@
         self.Bind(wx.EVT_CLOSE, self.onClose, self)
 
         QuickApp.__init__(self)
-
+        
         self.Show()
 
     def createMenus(self):
--- a/sat.tac	Thu Jan 07 00:17:27 2010 +1100
+++ b/sat.tac	Thu Jan 07 01:55:30 2010 +1100
@@ -70,10 +70,11 @@
 
 class SatXMPPClient(client.XMPPClient):
     
-    def __init__(self, user_jid, password, host=None, port=5222):
+    def __init__(self, bridge, user_jid, password, host=None, port=5222):
         client.XMPPClient.__init__(self, user_jid, password, host, port)
         self.factory.clientConnectionLost = self.connectionLost
         self.__connected=False
+        self.bridge = bridge
 
     def _authd(self, xmlstream):
         print "SatXMPPClient"
@@ -81,6 +82,7 @@
         self.__connected=True
         print "********** CONNECTED **********"
         self.streamInitialized()
+        self.bridge.connected() #we send the signal to the clients
 
     def streamInitialized(self):
         """Called after _authd"""
@@ -97,6 +99,7 @@
             self.keep_alife.stop()
         except AttributeError:
             debug("No keep_alife")
+        self.bridge.disconnected() #we send the signal to the clients
 
 
 class SatMessageProtocol(xmppim.MessageProtocol):
@@ -356,7 +359,7 @@
             return
         print "connecting..."
         self.me = jid.JID(self.memory.getParamA("JabberID", "Connection"))
-        self.xmppclient = SatXMPPClient(self.me, self.memory.getParamA("Password", "Connection"),
+        self.xmppclient = SatXMPPClient(self.bridge, self.me, self.memory.getParamA("Password", "Connection"),
             self.memory.getParamA("Server", "Connection"), 5222)
         self.xmppclient.streamInitialized = self.streamInitialized
 
--- a/sat_bridge/DBus.py	Thu Jan 07 00:17:27 2010 +1100
+++ b/sat_bridge/DBus.py	Thu Jan 07 01:55:30 2010 +1100
@@ -44,6 +44,16 @@
     ### signals ###    
 
     @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
+                         signature='')
+    def connected(self):
+        debug("Connected signal")
+    
+    @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
+                         signature='')
+    def disconnected(self):
+        debug("Disconnected signal")
+    
+    @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
                          signature='sa{ss}as')
     def newContact(self, contact, attributes, groups):
         debug("new contact signal (%s) sended", contact)
@@ -114,6 +124,12 @@
         return self.cb["disconnect"]()
     
     @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
+                         in_signature='', out_signature='b')
+    def isConnected(self):
+        info ("Connection status asked")
+        return self.cb["isConnected"]()
+
+    @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
                          in_signature='', out_signature='a(sa{ss}as)')
     def getContacts(self):
         debug("getContacts...")
@@ -190,12 +206,6 @@
         debug("Unsubscription asked for %s", entity)
         return self.cb["delContact"](entity)
 
-    @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX,
-                         in_signature='', out_signature='b')
-    def isConnected(self):
-        debug("Connection status requested")
-        return self.cb["isConnected"]()
-
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
                          in_signature='sa{ss}', out_signature='s')
     def launchAction(self, type, data):
@@ -257,6 +267,12 @@
         self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus)
         self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge')
 
+    def connected(self):
+        self.dbus_bridge.connected()
+    
+    def disconnected(self):
+        self.dbus_bridge.disconnected()
+    
     def newContact(self, contact, attributes, groups):
         self.dbus_bridge.newContact(contact, attributes, groups)