From cf6075208a9aaff74a72ab2983de876145edfe05 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 7 Jan 2010 01:55:30 +1100 Subject: [PATCH] Connection/disconnection signals - wix, sortilege: management of this new signals /!\ sortilege is bugged, the contact list window is not updated correctly --- frontends/quick_frontend/quick_app.py | 17 +++++++++++ .../quick_frontend/quick_contact_list.py | 4 +++ .../quick_contact_management.py | 4 +++ frontends/sortilege/sortilege | 10 +++++-- frontends/wix/main_window.py | 7 +++-- sat.tac | 7 +++-- sat_bridge/DBus.py | 28 +++++++++++++++---- 7 files changed, 65 insertions(+), 12 deletions(-) diff --git a/frontends/quick_frontend/quick_app.py b/frontends/quick_frontend/quick_app.py index 909457da..f8be40e0 100644 --- a/frontends/quick_frontend/quick_app.py +++ b/frontends/quick_frontend/quick_app.py @@ -32,6 +32,8 @@ class QuickApp(): ## 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 @@ class QuickApp(): 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 @@ class QuickApp(): 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)) diff --git a/frontends/quick_frontend/quick_contact_list.py b/frontends/quick_frontend/quick_contact_list.py index eb333ab5..ab717818 100644 --- a/frontends/quick_frontend/quick_contact_list.py +++ b/frontends/quick_frontend/quick_contact_list.py @@ -33,6 +33,10 @@ class QuickContactList(): 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 diff --git a/frontends/quick_frontend/quick_contact_management.py b/frontends/quick_frontend/quick_contact_management.py index 266c9870..388f16f3 100644 --- a/frontends/quick_frontend/quick_contact_management.py +++ b/frontends/quick_frontend/quick_contact_management.py @@ -31,6 +31,10 @@ class QuickContactManagement(): 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): diff --git a/frontends/sortilege/sortilege b/frontends/sortilege/sortilege index 99eb50f3..9f89ab42 100755 --- a/frontends/sortilege/sortilege +++ b/frontends/sortilege/sortilege @@ -45,6 +45,7 @@ from quick_frontend.quick_contact_list import QuickContactList 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 @@ class ChatList(QuickChatList): self.sizer.update() return chat - class ContactList(Window, QuickContactList): def __init__(self, host, CM): @@ -101,6 +101,12 @@ class ContactList(Window, QuickContactList): 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 @@ class SortilegeApp(QuickApp): 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: diff --git a/frontends/wix/main_window.py b/frontends/wix/main_window.py index f1265f12..7d76dd7b 100644 --- a/frontends/wix/main_window.py +++ b/frontends/wix/main_window.py @@ -126,6 +126,10 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList): 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 @@ class MainWindow(wx.Frame, QuickApp): self.contactList.registerActivatedCB(self.onContactActivated) self.chat_wins=ChatList(self) self.CreateStatusBar() - self.SetStatusText(msgOFFLINE) self.createMenus() #ToolBar @@ -197,7 +200,7 @@ class MainWindow(wx.Frame, QuickApp): self.Bind(wx.EVT_CLOSE, self.onClose, self) QuickApp.__init__(self) - + self.Show() def createMenus(self): diff --git a/sat.tac b/sat.tac index 2f89887f..4aa06b1a 100644 --- a/sat.tac +++ b/sat.tac @@ -70,10 +70,11 @@ def sat_next_id(): 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 @@ class SatXMPPClient(client.XMPPClient): 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 @@ class SatXMPPClient(client.XMPPClient): 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 @@ class SAT(service.Service): 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 diff --git a/sat_bridge/DBus.py b/sat_bridge/DBus.py index bf0b301a..5c5de134 100755 --- a/sat_bridge/DBus.py +++ b/sat_bridge/DBus.py @@ -43,6 +43,16 @@ class DbusObject(dbus.service.Object): ### 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): @@ -113,6 +123,12 @@ class DbusObject(dbus.service.Object): info ("Disconnection asked") 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): @@ -190,12 +206,6 @@ class DbusObject(dbus.service.Object): 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 @@ class DBusBridge(Bridge): 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)