SàT: multi-profile: DBus signals and frontend adaptation (first draft)
- Quick App: new single_profile parameter in __init__ (default: yes), used to tell if the application use only one profile at the time or not - Quick App: new __check_profile method, tell if the profile is used by the current frontend - Quick App: new methods plug_profile, unplug_profile and clear_profile, must be called by the frontend to tell which profiles to use - DBus Bridge: new methods getProfileName, getProfilesList and createProfile
This commit is contained in:
parent
54730cb077
commit
ca242c7aee
9 changed files with 169 additions and 104 deletions
|
|
@ -27,8 +27,10 @@ import pdb
|
||||||
class QuickApp():
|
class QuickApp():
|
||||||
"""This class contain the main methods needed for the frontend"""
|
"""This class contain the main methods needed for the frontend"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, single_profile=True):
|
||||||
self.rosterList = {}
|
self.rosterList = {}
|
||||||
|
self.profiles = {}
|
||||||
|
self.single_profile = single_profile
|
||||||
|
|
||||||
## bridge ##
|
## bridge ##
|
||||||
self.bridge=DBusBridgeFrontend()
|
self.bridge=DBusBridgeFrontend()
|
||||||
|
|
@ -45,70 +47,113 @@ class QuickApp():
|
||||||
self.bridge.register("actionResult", self.actionResult, "request")
|
self.bridge.register("actionResult", self.actionResult, "request")
|
||||||
self.bridge.register("actionResultExt", self.actionResult, "request")
|
self.bridge.register("actionResultExt", self.actionResult, "request")
|
||||||
|
|
||||||
###now we get the essential params###
|
|
||||||
self.whoami=JID(self.bridge.getParamA("JabberID","Connection"))
|
|
||||||
self.watched=self.bridge.getParamA("Watched", "Misc").split() #TODO: put this in a plugin
|
|
||||||
|
|
||||||
## misc ##
|
|
||||||
self.current_action_ids = set()
|
self.current_action_ids = set()
|
||||||
self.current_action_ids_cb = {}
|
self.current_action_ids_cb = {}
|
||||||
self.onlineContact = set() #FIXME: temporary
|
|
||||||
|
def __check_profile(self, profile):
|
||||||
|
"""Tell if the profile is currently followed by the application"""
|
||||||
|
return profile in self.profiles.keys()
|
||||||
|
|
||||||
if self.bridge.isConnected():
|
def plug_profile(self, profile_key='@DEFAULT@'):
|
||||||
|
"""Tell application which profile must be used"""
|
||||||
|
if self.single_profile and self.profiles:
|
||||||
|
error('There is already one profile plugged (we are in single profile mode) !')
|
||||||
|
return
|
||||||
|
profile = self.bridge.getProfileName(profile_key)
|
||||||
|
if not profile:
|
||||||
|
error("The profile asked doesn't exist")
|
||||||
|
if self.profiles.has_key(profile):
|
||||||
|
warning("The profile is already plugged")
|
||||||
|
return
|
||||||
|
self.profiles[profile]={}
|
||||||
|
if self.single_profile:
|
||||||
|
self.profile = profile
|
||||||
|
|
||||||
|
###now we get the essential params###
|
||||||
|
self.profiles[profile]['whoami']=JID(self.bridge.getParamA("JabberID","Connection", profile))
|
||||||
|
self.profiles[profile]['watched']=self.bridge.getParamA("Watched", "Misc", profile).split() #TODO: put this in a plugin
|
||||||
|
|
||||||
|
## misc ##
|
||||||
|
self.profiles[profile]['onlineContact'] = set() #FIXME: temporary
|
||||||
|
|
||||||
|
#TODO: managed multi-profiles here
|
||||||
|
if self.bridge.isConnected(profile):
|
||||||
self.setStatusOnline(True)
|
self.setStatusOnline(True)
|
||||||
else:
|
else:
|
||||||
self.setStatusOnline(False)
|
self.setStatusOnline(False)
|
||||||
return
|
return
|
||||||
|
|
||||||
### now we fill the contact list ###
|
### now we fill the contact list ###
|
||||||
for contact in self.bridge.getContacts():
|
for contact in self.bridge.getContacts(profile):
|
||||||
self.newContact(contact[0], contact[1], contact[2])
|
self.newContact(contact[0], contact[1], contact[2], profile)
|
||||||
|
|
||||||
presences = self.bridge.getPresenceStatus()
|
presences = self.bridge.getPresenceStatus(profile)
|
||||||
for contact in presences:
|
for contact in presences:
|
||||||
for res in presences[contact]:
|
for res in presences[contact]:
|
||||||
jabber_id = contact+('/'+res if res else '')
|
jabber_id = contact+('/'+res if res else '')
|
||||||
show = presences[contact][res][0]
|
show = presences[contact][res][0]
|
||||||
priority = presences[contact][res][1]
|
priority = presences[contact][res][1]
|
||||||
statuses = presences[contact][res][2]
|
statuses = presences[contact][res][2]
|
||||||
self.presenceUpdate(jabber_id, show, priority, statuses)
|
self.presenceUpdate(jabber_id, show, priority, statuses, profile)
|
||||||
|
|
||||||
waitingSub = self.bridge.getWaitingSub()
|
waitingSub = self.bridge.getWaitingSub(profile)
|
||||||
for sub in waitingSub:
|
for sub in waitingSub:
|
||||||
self.subscribe(waitingSub[sub], sub)
|
self.subscribe(waitingSub[sub], sub, profile)
|
||||||
|
|
||||||
|
def unplug_profile(self, profile):
|
||||||
|
"""Tell the application to not follow anymore the profile"""
|
||||||
|
if not profile in self.profiles:
|
||||||
|
warning ("This profile is not plugged")
|
||||||
|
return
|
||||||
|
self.profiles.remove(profile)
|
||||||
|
|
||||||
def connected(self):
|
def clear_profile(self):
|
||||||
|
self.profiles.clear()
|
||||||
|
|
||||||
|
def connected(self, profile):
|
||||||
"""called when the connection is made"""
|
"""called when the connection is made"""
|
||||||
|
if not self.__check_profile(profile):
|
||||||
|
return
|
||||||
debug("Connected")
|
debug("Connected")
|
||||||
self.setStatusOnline(True)
|
self.setStatusOnline(True)
|
||||||
|
|
||||||
def disconnected(self):
|
def disconnected(self, profile):
|
||||||
"""called when the connection is closed"""
|
"""called when the connection is closed"""
|
||||||
|
if not self.__check_profile(profile):
|
||||||
|
return
|
||||||
debug("Disconnected")
|
debug("Disconnected")
|
||||||
self.CM.clear()
|
self.CM.clear()
|
||||||
self.contactList.clear_contacts()
|
self.contactList.clear_contacts()
|
||||||
self.setStatusOnline(False)
|
self.setStatusOnline(False)
|
||||||
|
|
||||||
def newContact(self, JabberId, attributes, groups):
|
def newContact(self, JabberId, attributes, groups, profile):
|
||||||
|
if not self.__check_profile(profile):
|
||||||
|
return
|
||||||
entity=JID(JabberId)
|
entity=JID(JabberId)
|
||||||
self.rosterList[entity.short]=(dict(attributes), list(groups))
|
self.rosterList[entity.short]=(dict(attributes), list(groups))
|
||||||
|
|
||||||
def newMessage(self, from_jid, msg, type, to_jid):
|
def newMessage(self, from_jid, msg, type, to_jid, profile):
|
||||||
|
if not self.__check_profile(profile):
|
||||||
|
return
|
||||||
sender=JID(from_jid)
|
sender=JID(from_jid)
|
||||||
addr=JID(to_jid)
|
addr=JID(to_jid)
|
||||||
win = addr if sender.short == self.whoami.short else sender
|
win = addr if sender.short == self.profiles[profile]['whoami'].short else sender
|
||||||
self.chat_wins[win.short].printMessage(sender, msg)
|
self.current_action_ids = set()
|
||||||
|
self.current_action_ids_cb = {}
|
||||||
|
self.chat_wins[win.short].printMessage(sender, msg, profile)
|
||||||
|
|
||||||
def setStatusOnline(self, online=True):
|
def setStatusOnline(self, online=True):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def presenceUpdate(self, jabber_id, show, priority, statuses):
|
def presenceUpdate(self, jabber_id, show, priority, statuses, profile):
|
||||||
|
if not self.__check_profile(profile):
|
||||||
|
return
|
||||||
|
print "check ok"
|
||||||
debug ("presence update for %s (show=%s, statuses=%s)", jabber_id, show, statuses);
|
debug ("presence update for %s (show=%s, statuses=%s)", jabber_id, show, statuses);
|
||||||
from_jid=JID(jabber_id)
|
from_jid=JID(jabber_id)
|
||||||
debug ("from_jid.short=%s whoami.short=%s", from_jid.short, self.whoami.short)
|
debug ("from_jid.short=%s whoami.short=%s", from_jid.short, self.profiles[profile]['whoami'].short)
|
||||||
|
|
||||||
if from_jid.short==self.whoami.short:
|
if from_jid.short==self.profiles[profile]['whoami'].short:
|
||||||
if not type:
|
if not type:
|
||||||
self.setStatusOnline(True)
|
self.setStatusOnline(True)
|
||||||
elif type=="unavailable":
|
elif type=="unavailable":
|
||||||
|
|
@ -124,10 +169,10 @@ class QuickApp():
|
||||||
groups=self.rosterList[from_jid.short][1]
|
groups=self.rosterList[from_jid.short][1]
|
||||||
|
|
||||||
#FIXME: must be moved in a plugin
|
#FIXME: must be moved in a plugin
|
||||||
if from_jid.short in self.watched and not from_jid.short in self.onlineContact:
|
if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']:
|
||||||
self.showAlert("Watched jid [%s] is connected !" % from_jid.short)
|
self.showAlert("Watched jid [%s] is connected !" % from_jid.short)
|
||||||
|
|
||||||
self.onlineContact.add(from_jid) #FIXME onlineContact is useless with CM, must be removed
|
self.profiles[profile]['onlineContact'].add(from_jid) #FIXME onlineContact is useless with CM, must be removed
|
||||||
self.CM.add(from_jid)
|
self.CM.add(from_jid)
|
||||||
self.CM.update(from_jid, 'name', name)
|
self.CM.update(from_jid, 'name', name)
|
||||||
self.CM.update(from_jid, 'show', show)
|
self.CM.update(from_jid, 'show', show)
|
||||||
|
|
@ -140,14 +185,16 @@ class QuickApp():
|
||||||
self.CM.update(from_jid, 'avatar', self.bridge.getAvatarFile(cache['avatar']))
|
self.CM.update(from_jid, 'avatar', self.bridge.getAvatarFile(cache['avatar']))
|
||||||
self.contactList.replace(from_jid)
|
self.contactList.replace(from_jid)
|
||||||
|
|
||||||
if show=="unavailable" and from_jid in self.onlineContact:
|
if show=="unavailable" and from_jid in self.profiles[profile]['onlineContact']:
|
||||||
self.onlineContact.remove(from_jid)
|
self.profiles[profile]['onlineContact'].remove(from_jid)
|
||||||
self.CM.remove(from_jid)
|
self.CM.remove(from_jid)
|
||||||
if not self.CM.isConnected(from_jid):
|
if not self.CM.isConnected(from_jid):
|
||||||
self.contactList.disconnect(from_jid)
|
self.contactList.disconnect(from_jid)
|
||||||
|
|
||||||
def subscribe(self, type, raw_jid):
|
def subscribe(self, type, raw_jid, profile):
|
||||||
"""Called when a subsciption maangement signal is received"""
|
"""Called when a subsciption maangement signal is received"""
|
||||||
|
if not self.__check_profile(profile):
|
||||||
|
return
|
||||||
entity = JID(raw_jid)
|
entity = JID(raw_jid)
|
||||||
if type=="subscribed":
|
if type=="subscribed":
|
||||||
# this is a subscription confirmation, we just have to inform user
|
# this is a subscription confirmation, we just have to inform user
|
||||||
|
|
@ -169,29 +216,35 @@ class QuickApp():
|
||||||
def showAlert(self, message):
|
def showAlert(self, message):
|
||||||
pass #FIXME
|
pass #FIXME
|
||||||
|
|
||||||
def paramUpdate(self, name, value, namespace):
|
def paramUpdate(self, name, value, namespace, profile):
|
||||||
|
if not self.__check_profile(profile):
|
||||||
|
return
|
||||||
debug("param update: [%s] %s = %s", namespace, name, value)
|
debug("param update: [%s] %s = %s", namespace, name, value)
|
||||||
if (namespace,name) == ("Connection", "JabberID"):
|
if (namespace,name) == ("Connection", "JabberID"):
|
||||||
debug ("Changing ID to %s", value)
|
debug ("Changing ID to %s", value)
|
||||||
self.whoami=JID(value)
|
self.profiles[profile]['whoami']=JID(value)
|
||||||
elif (namespace,name) == ("Misc", "Watched"):
|
elif (namespace,name) == ("Misc", "Watched"):
|
||||||
self.watched=value.split()
|
self.profiles[profile]['watched']=value.split()
|
||||||
|
|
||||||
def contactDeleted(self, jid):
|
def contactDeleted(self, jid, profile):
|
||||||
|
if not self.__check_profile(profile):
|
||||||
|
return
|
||||||
target = JID(jid)
|
target = JID(jid)
|
||||||
self.CM.remove(target)
|
self.CM.remove(target)
|
||||||
self.contactList.remove(self.CM.get_full(target))
|
self.contactList.remove(self.CM.get_full(target))
|
||||||
try:
|
try:
|
||||||
self.onlineContact.remove(target.short)
|
self.profiles[profile]['onlineContact'].remove(target.short)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def updatedValue(self, name, data):
|
def updatedValue(self, name, data, profile):
|
||||||
if name == "profile_nick":
|
if not self.__check_profile(profile):
|
||||||
|
return
|
||||||
|
if name == "card_nick":
|
||||||
target = JID(data['jid'])
|
target = JID(data['jid'])
|
||||||
self.CM.update(target, 'nick', data['nick'])
|
self.CM.update(target, 'nick', data['nick'])
|
||||||
self.contactList.replace(target)
|
self.contactList.replace(target)
|
||||||
elif name == "profile_avatar":
|
elif name == "card_avatar":
|
||||||
target = JID(data['jid'])
|
target = JID(data['jid'])
|
||||||
filename = self.bridge.getAvatarFile(data['avatar'])
|
filename = self.bridge.getAvatarFile(data['avatar'])
|
||||||
self.CM.update(target, 'avatar', filename)
|
self.CM.update(target, 'avatar', filename)
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ class QuickContactManagement():
|
||||||
if self.__contactlist.has_key(entity.short):
|
if self.__contactlist.has_key(entity.short):
|
||||||
self.__contactlist[entity.short][key] = value
|
self.__contactlist[entity.short][key] = value
|
||||||
else:
|
else:
|
||||||
debug ('Trying to update an uknown contact: %s', entity.short)
|
debug ('Trying to update an unknown contact: %s', entity.short)
|
||||||
|
|
||||||
def get_full(self, entity):
|
def get_full(self, entity):
|
||||||
return entity.short+'/'+self.__contactlist[entity.short]['resources'][-1]
|
return entity.short+'/'+self.__contactlist[entity.short]['resources'][-1]
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,15 @@ class DBusBridgeFrontend(BridgeFrontend):
|
||||||
elif iface == "request":
|
elif iface == "request":
|
||||||
self.db_req_iface.connect_to_signal(functionName, handler)
|
self.db_req_iface.connect_to_signal(functionName, handler)
|
||||||
|
|
||||||
|
def getProfileName(self, profile_key='@DEFAULT@'):
|
||||||
|
return self.db_req_iface.getProfileName(profile_key)
|
||||||
|
|
||||||
|
def getProfilesList(self):
|
||||||
|
return self.db_req_iface.getProfilesList()
|
||||||
|
|
||||||
|
def createProfile(self, profile):
|
||||||
|
return self.db_req_iface.getProfileName(profile)
|
||||||
|
|
||||||
def connect(self, profile_key='@DEFAULT@'):
|
def connect(self, profile_key='@DEFAULT@'):
|
||||||
return self.db_comm_iface.connect(profile_key)
|
return self.db_comm_iface.connect(profile_key)
|
||||||
|
|
||||||
|
|
@ -80,7 +89,7 @@ class DBusBridgeFrontend(BridgeFrontend):
|
||||||
return self.db_comm_iface.getParamsForCategory(category, profile_key)
|
return self.db_comm_iface.getParamsForCategory(category, profile_key)
|
||||||
|
|
||||||
def getParamsCategories(self):
|
def getParamsCategories(self):
|
||||||
return self.db_comm_iface.getParamsCategories(profile_key)
|
return self.db_comm_iface.getParamsCategories()
|
||||||
|
|
||||||
def getHistory(self, from_jid, to_jid, size):
|
def getHistory(self, from_jid, to_jid, size):
|
||||||
return self.db_comm_iface.getHistory(from_jid, to_jid, size)
|
return self.db_comm_iface.getHistory(from_jid, to_jid, size)
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,10 @@ class Chat(wx.Frame, QuickChat):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def printMessage(self, from_jid, msg, timestamp=""): #FIXME: factorize with printDistantMessage
|
def printMessage(self, from_jid, msg, profile, timestamp=""):
|
||||||
"""Print the message with differents colors depending on where it comes from."""
|
"""Print the message with differents colors depending on where it comes from."""
|
||||||
jid=JID(from_jid)
|
jid=JID(from_jid)
|
||||||
mymess = (jid.short == self.host.whoami.short) #mymess = True if message comes from local user
|
mymess = (jid.short == self.host.profiles[profile]['whoami'].short) #mymess = True if message comes from local user
|
||||||
_font = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD)
|
_font = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD)
|
||||||
self.chatWindow.SetDefaultStyle(wx.TextAttr( "BLACK" if mymess else "BLUE", font=_font))
|
self.chatWindow.SetDefaultStyle(wx.TextAttr( "BLACK" if mymess else "BLUE", font=_font))
|
||||||
self.chatWindow.AppendText("[%s] " % jid)
|
self.chatWindow.AppendText("[%s] " % jid)
|
||||||
|
|
|
||||||
|
|
@ -223,6 +223,7 @@ class MainWindow(wx.Frame, QuickApp):
|
||||||
self.CM = QuickContactManagement() #FIXME: not the best place
|
self.CM = QuickContactManagement() #FIXME: not the best place
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Frame elements
|
#Frame elements
|
||||||
self.contactList = ContactList(self, self.CM)
|
self.contactList = ContactList(self, self.CM)
|
||||||
self.contactList.registerActivatedCB(self.onContactActivated)
|
self.contactList.registerActivatedCB(self.onContactActivated)
|
||||||
|
|
@ -253,6 +254,7 @@ class MainWindow(wx.Frame, QuickApp):
|
||||||
self.Bind(wx.EVT_CLOSE, self.onClose, self)
|
self.Bind(wx.EVT_CLOSE, self.onClose, self)
|
||||||
|
|
||||||
QuickApp.__init__(self)
|
QuickApp.__init__(self)
|
||||||
|
self.plug_profile()
|
||||||
|
|
||||||
self.Show()
|
self.Show()
|
||||||
|
|
||||||
|
|
@ -329,10 +331,6 @@ class MainWindow(wx.Frame, QuickApp):
|
||||||
self.tools.Disable()
|
self.tools.Disable()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def presenceUpdate(self, jabber_id, show, priority, statuses):
|
|
||||||
QuickApp.presenceUpdate(self, jabber_id, show, priority, statuses)
|
|
||||||
|
|
||||||
def askConfirmation(self, type, id, data):
|
def askConfirmation(self, type, id, data):
|
||||||
#TODO: refactor this in QuickApp
|
#TODO: refactor this in QuickApp
|
||||||
debug ("Confirmation asked")
|
debug ("Confirmation asked")
|
||||||
|
|
@ -533,7 +531,7 @@ class MainWindow(wx.Frame, QuickApp):
|
||||||
|
|
||||||
def onFindGateways(self, e):
|
def onFindGateways(self, e):
|
||||||
debug("Find Gateways request")
|
debug("Find Gateways request")
|
||||||
id = self.bridge.findGateways(self.whoami.domain)
|
id = self.bridge.findGateways(self.profiles[self.profile]['whoami'].domain)
|
||||||
self.current_action_ids.add(id)
|
self.current_action_ids.add(id)
|
||||||
self.current_action_ids_cb[id] = self.onGatewaysFound
|
self.current_action_ids_cb[id] = self.onGatewaysFound
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ class XEP_0054():
|
||||||
if not old_value or value != old_value:
|
if not old_value or value != old_value:
|
||||||
cache[name] = value
|
cache[name] = value
|
||||||
self.host.memory.setPrivate("vcard_cache", self.vcard_cache)
|
self.host.memory.setPrivate("vcard_cache", self.vcard_cache)
|
||||||
self.host.bridge.updatedValue('profile_'+name, {'jid':jid.userhost(), name:value})
|
self.host.bridge.updatedValue('card_'+name, {'jid':jid.userhost(), name:value})
|
||||||
|
|
||||||
def get_cache(self, jid, name):
|
def get_cache(self, jid, name):
|
||||||
"""return cached value for jid
|
"""return cached value for jid
|
||||||
|
|
|
||||||
26
sat.tac
26
sat.tac
|
|
@ -83,7 +83,7 @@ class SatXMPPClient(client.XMPPClient):
|
||||||
self.__connected=True
|
self.__connected=True
|
||||||
print "********** [%s] CONNECTED **********" % self.profile
|
print "********** [%s] CONNECTED **********" % self.profile
|
||||||
self.streamInitialized()
|
self.streamInitialized()
|
||||||
self.host_app.bridge.connected() #we send the signal to the clients
|
self.host_app.bridge.connected(self.profile) #we send the signal to the clients
|
||||||
|
|
||||||
def streamInitialized(self):
|
def streamInitialized(self):
|
||||||
"""Called after _authd"""
|
"""Called after _authd"""
|
||||||
|
|
@ -112,7 +112,7 @@ class SatXMPPClient(client.XMPPClient):
|
||||||
self.keep_alife.stop()
|
self.keep_alife.stop()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
debug("No keep_alife")
|
debug("No keep_alife")
|
||||||
self.host_app.bridge.disconnected() #we send the signal to the clients
|
self.host_app.bridge.disconnected(self.profile) #we send the signal to the clients
|
||||||
|
|
||||||
|
|
||||||
class SatMessageProtocol(xmppim.MessageProtocol):
|
class SatMessageProtocol(xmppim.MessageProtocol):
|
||||||
|
|
@ -125,7 +125,7 @@ class SatMessageProtocol(xmppim.MessageProtocol):
|
||||||
debug (u"got_message from: %s", message["from"])
|
debug (u"got_message from: %s", message["from"])
|
||||||
for e in message.elements():
|
for e in message.elements():
|
||||||
if e.name == "body":
|
if e.name == "body":
|
||||||
self.host.bridge.newMessage(message["from"], e.children[0])
|
self.host.bridge.newMessage(message["from"], e.children[0], self.parent.profile)
|
||||||
self.host.memory.addToHistory(self.parent.jid, jid.JID(message["from"]), self.parent.jid, "chat", e.children[0])
|
self.host.memory.addToHistory(self.parent.jid, jid.JID(message["from"]), self.parent.jid, "chat", e.children[0])
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
@ -165,7 +165,7 @@ class SatRosterProtocol(xmppim.RosterClientProtocol):
|
||||||
item_attr['name'] = item.name
|
item_attr['name'] = item.name
|
||||||
info ("new contact in roster list: %s", item.jid.full())
|
info ("new contact in roster list: %s", item.jid.full())
|
||||||
self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile)
|
self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile)
|
||||||
self.host.bridge.newContact(item.jid.full(), item_attr, item.groups)
|
self.host.bridge.newContact(item.jid.full(), item_attr, item.groups, self.parent.profile)
|
||||||
|
|
||||||
def onRosterRemove(self, entity):
|
def onRosterRemove(self, entity):
|
||||||
"""Called when a roster removal event is received"""
|
"""Called when a roster removal event is received"""
|
||||||
|
|
@ -191,7 +191,7 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
|
||||||
|
|
||||||
#now it's time to notify frontends
|
#now it's time to notify frontends
|
||||||
self.host.bridge.presenceUpdate(entity.full(), show or "",
|
self.host.bridge.presenceUpdate(entity.full(), show or "",
|
||||||
int(priority), statuses)
|
int(priority), statuses, self.parent.profile)
|
||||||
|
|
||||||
def unavailableReceived(self, entity, statuses=None):
|
def unavailableReceived(self, entity, statuses=None):
|
||||||
if statuses and statuses.has_key(None): #we only want string keys
|
if statuses and statuses.has_key(None): #we only want string keys
|
||||||
|
|
@ -200,7 +200,7 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
|
||||||
self.host.memory.addPresenceStatus(entity, "unavailable", 0, statuses, self.parent.profile)
|
self.host.memory.addPresenceStatus(entity, "unavailable", 0, statuses, self.parent.profile)
|
||||||
|
|
||||||
#now it's time to notify frontends
|
#now it's time to notify frontends
|
||||||
self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses)
|
self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses, self.parent.profile)
|
||||||
|
|
||||||
|
|
||||||
def available(self, entity=None, show=None, statuses=None, priority=0):
|
def available(self, entity=None, show=None, statuses=None, priority=0):
|
||||||
|
|
@ -212,22 +212,22 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
|
||||||
def subscribedReceived(self, entity):
|
def subscribedReceived(self, entity):
|
||||||
debug ("subscription approved for [%s]" % entity.userhost())
|
debug ("subscription approved for [%s]" % entity.userhost())
|
||||||
self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile)
|
self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile)
|
||||||
self.host.bridge.subscribe('subscribed', entity.userhost())
|
self.host.bridge.subscribe('subscribed', entity.userhost(), self.parent.profile)
|
||||||
|
|
||||||
def unsubscribedReceived(self, entity):
|
def unsubscribedReceived(self, entity):
|
||||||
debug ("unsubscription confirmed for [%s]" % entity.userhost())
|
debug ("unsubscription confirmed for [%s]" % entity.userhost())
|
||||||
self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile)
|
self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile)
|
||||||
self.host.bridge.subscribe('unsubscribed', entity.userhost())
|
self.host.bridge.subscribe('unsubscribed', entity.userhost(), self.parent.profile)
|
||||||
|
|
||||||
def subscribeReceived(self, entity):
|
def subscribeReceived(self, entity):
|
||||||
debug ("subscription request for [%s]" % entity.userhost())
|
debug ("subscription request for [%s]" % entity.userhost())
|
||||||
self.host.memory.addWaitingSub('subscribe', entity.userhost(), self.parent.profile)
|
self.host.memory.addWaitingSub('subscribe', entity.userhost(), self.parent.profile)
|
||||||
self.host.bridge.subscribe('subscribe', entity.userhost())
|
self.host.bridge.subscribe('subscribe', entity.userhost(), self.parent.profile)
|
||||||
|
|
||||||
def unsubscribeReceived(self, entity):
|
def unsubscribeReceived(self, entity):
|
||||||
debug ("unsubscription asked for [%s]" % entity.userhost())
|
debug ("unsubscription asked for [%s]" % entity.userhost())
|
||||||
self.host.memory.addWaitingSub('unsubscribe', entity.userhost(), self.parent.profile)
|
self.host.memory.addWaitingSub('unsubscribe', entity.userhost(), self.parent.profile)
|
||||||
self.host.bridge.subscribe('unsubscribe', entity.userhost())
|
self.host.bridge.subscribe('unsubscribe', entity.userhost(), self.parent.profile)
|
||||||
|
|
||||||
class SatDiscoProtocol(disco.DiscoClientProtocol):
|
class SatDiscoProtocol(disco.DiscoClientProtocol):
|
||||||
def __init__(self, host):
|
def __init__(self, host):
|
||||||
|
|
@ -326,6 +326,7 @@ class SAT(service.Service):
|
||||||
self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future
|
self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future
|
||||||
|
|
||||||
self.bridge=DBusBridge()
|
self.bridge=DBusBridge()
|
||||||
|
self.bridge.register("getProfileName", self.memory.getProfileName)
|
||||||
self.bridge.register("getProfilesList", self.memory.getProfilesList)
|
self.bridge.register("getProfilesList", self.memory.getProfilesList)
|
||||||
self.bridge.register("createProfile", self.memory.createProfile)
|
self.bridge.register("createProfile", self.memory.createProfile)
|
||||||
self.bridge.register("registerNewAccount", self.registerNewAccount)
|
self.bridge.register("registerNewAccount", self.registerNewAccount)
|
||||||
|
|
@ -407,7 +408,6 @@ class SAT(service.Service):
|
||||||
|
|
||||||
debug ("setting plugins parents")
|
debug ("setting plugins parents")
|
||||||
|
|
||||||
#FIXME: gof
|
|
||||||
for plugin in self.plugins.iteritems():
|
for plugin in self.plugins.iteritems():
|
||||||
if plugin[1].is_handler:
|
if plugin[1].is_handler:
|
||||||
plugin[1].getHandler().setHandlerParent(current)
|
plugin[1].getHandler().setHandlerParent(current)
|
||||||
|
|
@ -585,7 +585,7 @@ class SAT(service.Service):
|
||||||
message.addElement("body", "jabber:client", msg)
|
message.addElement("body", "jabber:client", msg)
|
||||||
self.profiles[profile].xmlstream.send(message)
|
self.profiles[profile].xmlstream.send(message)
|
||||||
self.memory.addToHistory(current_jid, current_jid, jid.JID(to), message["type"], unicode(msg))
|
self.memory.addToHistory(current_jid, current_jid, jid.JID(to), message["type"], unicode(msg))
|
||||||
self.bridge.newMessage(message['from'], unicode(msg), to=message['to']) #We send back the message, so all clients are aware of it
|
self.bridge.newMessage(message['from'], unicode(msg), to=message['to'], profile=profile) #We send back the message, so all clients are aware of it
|
||||||
|
|
||||||
|
|
||||||
def setPresence(self, to="", show="", priority = 0, statuses={}, profile_key='@DEFAULT@'):
|
def setPresence(self, to="", show="", priority = 0, statuses={}, profile_key='@DEFAULT@'):
|
||||||
|
|
@ -630,7 +630,7 @@ class SAT(service.Service):
|
||||||
to_jid=jid.JID(to)
|
to_jid=jid.JID(to)
|
||||||
self.profiles[profile].roster.removeItem(to_jid)
|
self.profiles[profile].roster.removeItem(to_jid)
|
||||||
self.profiles[profile].presence.unsubscribe(to_jid)
|
self.profiles[profile].presence.unsubscribe(to_jid)
|
||||||
self.profiles[profile].bridge.contactDeleted(to)
|
self.host.bridge.contactDeleted(to, profile)
|
||||||
|
|
||||||
|
|
||||||
## callbacks ##
|
## callbacks ##
|
||||||
|
|
|
||||||
|
|
@ -44,44 +44,44 @@ class DbusObject(dbus.service.Object):
|
||||||
### signals ###
|
### signals ###
|
||||||
|
|
||||||
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
||||||
signature='')
|
signature='s')
|
||||||
def connected(self):
|
def connected(self, profile):
|
||||||
debug("Connected signal")
|
debug("Connected signal")
|
||||||
|
|
||||||
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
||||||
signature='')
|
signature='s')
|
||||||
def disconnected(self):
|
def disconnected(self, profile):
|
||||||
debug("Disconnected signal")
|
debug("Disconnected signal")
|
||||||
|
|
||||||
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
||||||
signature='sa{ss}as')
|
signature='sa{ss}ass')
|
||||||
def newContact(self, contact, attributes, groups):
|
def newContact(self, contact, attributes, groups, profile):
|
||||||
debug("new contact signal (%s) sended", contact)
|
debug("new contact signal (%s) sended (profile: %s)", contact, profile)
|
||||||
|
|
||||||
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
||||||
signature='ssss')
|
signature='sssss')
|
||||||
def newMessage(self, from_jid, msg, type='chat', to=''):
|
def newMessage(self, from_jid, msg, type='chat', to='', profile='@NONE@'):
|
||||||
debug("new message signal (from:%s msg:%s type:%s to:%s) sended", from_jid, msg, type, to)
|
debug("new message signal (from:%s msg:%s type:%s to:%s) sended", from_jid, msg, type, to)
|
||||||
|
|
||||||
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
||||||
signature='ssia{ss}')
|
signature='ssia{ss}s')
|
||||||
def presenceUpdate(self, entity, show, priority, statuses):
|
def presenceUpdate(self, entity, show, priority, statuses, profile):
|
||||||
debug("presence update signal (from:%s show:%s priority:%d statuses:%s) sended" , entity, show, priority, statuses)
|
debug("presence update signal (from:%s show:%s priority:%d statuses:%s profile:%s) sended" , entity, show, priority, statuses, profile)
|
||||||
|
|
||||||
|
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
||||||
|
signature='sss')
|
||||||
|
def subscribe(self, type, entity, profile):
|
||||||
|
debug("subscribe (type: [%s] from:[%s] profile:[%s])" , type, entity, profile)
|
||||||
|
|
||||||
|
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
||||||
|
signature='ssss')
|
||||||
|
def paramUpdate(self, name, value, category, profile):
|
||||||
|
debug("param update signal: %s=%s in category %s (profile: %s)", name, value, category, profile)
|
||||||
|
|
||||||
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
||||||
signature='ss')
|
signature='ss')
|
||||||
def subscribe(self, type, entity):
|
def contactDeleted(self, entity, profile):
|
||||||
debug("subscribe (type: [%s] from:[%s])" , type, entity)
|
debug("contact deleted signal: %s (profile: %s)", entity, profile)
|
||||||
|
|
||||||
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
|
||||||
signature='sss')
|
|
||||||
def paramUpdate(self, name, value, category):
|
|
||||||
debug("param update signal: %s=%s in category %s", name, value, category)
|
|
||||||
|
|
||||||
@dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX,
|
|
||||||
signature='s')
|
|
||||||
def contactDeleted(self, entity):
|
|
||||||
debug("contact deleted signal: %s", entity)
|
|
||||||
|
|
||||||
@dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX,
|
@dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX,
|
||||||
signature='ssa{ss}')
|
signature='ssa{ss}')
|
||||||
|
|
@ -105,6 +105,11 @@ class DbusObject(dbus.service.Object):
|
||||||
|
|
||||||
### methods ###
|
### methods ###
|
||||||
|
|
||||||
|
@dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
|
||||||
|
in_signature='s', out_signature='s')
|
||||||
|
def getProfileName(self, profile_key):
|
||||||
|
return self.cb["getProfileName"](profile_key)
|
||||||
|
|
||||||
@dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
|
@dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
|
||||||
in_signature='', out_signature='as')
|
in_signature='', out_signature='as')
|
||||||
def getProfilesList(self):
|
def getProfilesList(self):
|
||||||
|
|
@ -112,8 +117,8 @@ class DbusObject(dbus.service.Object):
|
||||||
return self.cb["getProfilesList"]()
|
return self.cb["getProfilesList"]()
|
||||||
|
|
||||||
@dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
|
@dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
|
||||||
in_signature='sb', out_signature='')
|
in_signature='s', out_signature='')
|
||||||
def createProfile(self, name, default=False):
|
def createProfile(self, name):
|
||||||
info ('Profile creation asked')
|
info ('Profile creation asked')
|
||||||
return self.cb["createProfile"](name, default)
|
return self.cb["createProfile"](name, default)
|
||||||
|
|
||||||
|
|
@ -279,34 +284,34 @@ class DBusBridge(Bridge):
|
||||||
self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus)
|
self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus)
|
||||||
self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge')
|
self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge')
|
||||||
|
|
||||||
def connected(self):
|
def connected(self, profile):
|
||||||
self.dbus_bridge.connected()
|
self.dbus_bridge.connected(profile)
|
||||||
|
|
||||||
def disconnected(self):
|
def disconnected(self, profile):
|
||||||
self.dbus_bridge.disconnected()
|
self.dbus_bridge.disconnected(profile)
|
||||||
|
|
||||||
def newContact(self, contact, attributes, groups):
|
def newContact(self, contact, attributes, groups, profile):
|
||||||
self.dbus_bridge.newContact(contact, attributes, groups)
|
self.dbus_bridge.newContact(contact, attributes, groups, profile)
|
||||||
|
|
||||||
def newMessage(self,from_jid,msg,type='chat', to=''):
|
def newMessage(self,from_jid, msg, type, to, profile):
|
||||||
debug("sending message...")
|
debug("sending message...")
|
||||||
self.dbus_bridge.newMessage(from_jid, msg, type, to)
|
self.dbus_bridge.newMessage(from_jid, msg, type, to, profile)
|
||||||
|
|
||||||
def presenceUpdate(self, entity, show, priority, statuses):
|
def presenceUpdate(self, entity, show, priority, statuses, profile):
|
||||||
debug("updating presence for %s",entity)
|
debug("updating presence for %s",entity)
|
||||||
self.dbus_bridge.presenceUpdate(entity, show, priority, statuses)
|
self.dbus_bridge.presenceUpdate(entity, show, priority, statuses, profile)
|
||||||
|
|
||||||
def subscribe(self, type, entity):
|
def subscribe(self, type, entity, profile):
|
||||||
debug("subscribe request for %s",entity)
|
debug("subscribe request for %s",entity)
|
||||||
self.dbus_bridge.subscribe(type, entity)
|
self.dbus_bridge.subscribe(type, entity, profile)
|
||||||
|
|
||||||
def paramUpdate(self, name, value, category):
|
def paramUpdate(self, name, value, category, profile):
|
||||||
debug("updating param [%s] %s ", category, name)
|
debug("updating param [%s] %s ", category, name)
|
||||||
self.dbus_bridge.paramUpdate(name, value, category)
|
self.dbus_bridge.paramUpdate(name, value, category, profile)
|
||||||
|
|
||||||
def contactDeleted(self, entity):
|
def contactDeleted(self, entity, profile):
|
||||||
debug("sending contact deleted signal %s ", entity)
|
debug("sending contact deleted signal %s ", entity)
|
||||||
self.dbus_bridge.contactDeleted(entity)
|
self.dbus_bridge.contactDeleted(entity, profile)
|
||||||
|
|
||||||
def askConfirmation(self, type, id, data):
|
def askConfirmation(self, type, id, data):
|
||||||
self.dbus_bridge.askConfirmation(type, id, data)
|
self.dbus_bridge.askConfirmation(type, id, data)
|
||||||
|
|
@ -321,7 +326,7 @@ class DBusBridge(Bridge):
|
||||||
self.dbus_bridge.updatedValue(name, value)
|
self.dbus_bridge.updatedValue(name, value)
|
||||||
|
|
||||||
def register(self, name, callback):
|
def register(self, name, callback):
|
||||||
debug("registering DBus bridge method [%s]",name)
|
debug("registering DBus bridge method [%s]", name)
|
||||||
self.dbus_bridge.register(name, callback)
|
self.dbus_bridge.register(name, callback)
|
||||||
|
|
||||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method):
|
def addMethod(self, name, int_suffix, in_sign, out_sign, method):
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ class Param():
|
||||||
def getProfilesList(self):
|
def getProfilesList(self):
|
||||||
return self.params.keys()
|
return self.params.keys()
|
||||||
|
|
||||||
def createProfile(self, name, default=False):
|
def createProfile(self, name):
|
||||||
"""Create a new profile
|
"""Create a new profile
|
||||||
@param name: Name of the profile
|
@param name: Name of the profile
|
||||||
@param default: True if default value"""
|
@param default: True if default value"""
|
||||||
|
|
@ -135,12 +135,12 @@ class Param():
|
||||||
@return: requested profile name or None if it doesn't exist"""
|
@return: requested profile name or None if it doesn't exist"""
|
||||||
if profile_key=='@DEFAULT@':
|
if profile_key=='@DEFAULT@':
|
||||||
if not self.params:
|
if not self.params:
|
||||||
return None
|
return ""
|
||||||
info('No default profile, returning first one') #TODO: manage real default profile
|
info('No default profile, returning first one') #TODO: manage real default profile
|
||||||
return self.params.keys()[0] #FIXME: gof: temporary, must use real default value, and fallback to first one if it doesn't exists
|
return self.params.keys()[0] #FIXME: gof: temporary, must use real default value, and fallback to first one if it doesn't exists
|
||||||
if not self.params.has_key(profile_key):
|
if not self.params.has_key(profile_key):
|
||||||
error ('Trying to access an unknown profile')
|
error ('Trying to access an unknown profile')
|
||||||
return None
|
return ""
|
||||||
return profile_key
|
return profile_key
|
||||||
|
|
||||||
def __get_unique_node(self, parent, tag, name):
|
def __get_unique_node(self, parent, tag, name):
|
||||||
|
|
@ -354,7 +354,7 @@ class Param():
|
||||||
print "clique",node.toxml()
|
print "clique",node.toxml()
|
||||||
else:
|
else:
|
||||||
self.params[profile][(category, name)] = value
|
self.params[profile][(category, name)] = value
|
||||||
self.host.bridge.paramUpdate(name, value, category) #TODO: add profile in signal
|
self.host.bridge.paramUpdate(name, value, category, profile) #TODO: add profile in signal
|
||||||
|
|
||||||
class Memory:
|
class Memory:
|
||||||
"""This class manage all persistent informations"""
|
"""This class manage all persistent informations"""
|
||||||
|
|
@ -605,8 +605,8 @@ class Memory:
|
||||||
def getParams(self):
|
def getParams(self):
|
||||||
return self.params.getParams()
|
return self.params.getParams()
|
||||||
|
|
||||||
def getParamsForCategory(self, category):
|
def getParamsForCategory(self, category, profile_key='@DEFAULT@'):
|
||||||
return self.params.getParamsForCategory(category)
|
return self.params.getParamsForCategory(category, profile_key)
|
||||||
|
|
||||||
def getParamsCategories(self):
|
def getParamsCategories(self):
|
||||||
return self.params.getParamsCategories()
|
return self.params.getParamsCategories()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue