Connection/disconnection signals

- wix, sortilege: management of this new signals
/!\ sortilege is bugged, the contact list window is not updated correctly
This commit is contained in:
Goffi 2010-01-07 01:55:30 +11:00
commit cf6075208a
7 changed files with 65 additions and 12 deletions

View file

@ -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))

View file

@ -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

View file

@ -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):

View file

@ -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:

View file

@ -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):

View file

@ -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

View file

@ -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)