SàT: multi-profiles: somes fixes in core

This commit is contained in:
Goffi 2010-01-29 14:17:15 +11:00
commit 7b520ddc93
2 changed files with 31 additions and 21 deletions

47
sat.tac
View file

@ -413,13 +413,14 @@ class SAT(service.Service):
current.startService()
def disconnect(self):
def disconnect(self, profile_key='@DEFAULT@'):
"""disconnect from jabber server"""
if (not self.isConnected()):
if (not self.isConnected(profile_key)):
info("not connected !")
return
profile = self.memory.getProfileName(profile_key)
info("Disconnecting...")
self.xmppclient.stopService()
self.profiles[profile].stopService()
def startService(self):
info("Salut à toi ô mon frère !")
@ -511,10 +512,10 @@ class SAT(service.Service):
## Client management ##
def setParam(self, name, value, category):
def setParam(self, name, value, category, profile_key='@DEFAULT@'):
"""set wanted paramater and notice observers"""
info ("setting param: %s=%s in category %s", name, value, category)
self.memory.setParam(name, value, category)
self.memory.setParam(name, value, category, profile_key)
def isConnected(self, profile_key='@DEFAULT@'):
"""Return connection status of profile
@ -568,41 +569,49 @@ class SAT(service.Service):
self.bridge.newMessage(message['from'], unicode(msg), to=message['to']) #We send back the message, so all clients are aware of it
def setPresence(self, to="", show="", priority = 0, statuses={}):
def setPresence(self, to="", show="", priority = 0, statuses={}, profile_key='@DEFAULT@'):
"""Send our presence information"""
profile = self.memory.getProfileName(profile_key)
assert(profile)
to_jid = jid.JID(to) if to else None
self.presence.available(to_jid, show, statuses, priority)
self.profiles[profile].presence.available(to_jid, show, statuses, priority)
def subscription(self, type, raw_jid):
def subscription(self, type, raw_jid, profile_key='@DEFAULT@'):
"""Called to manage subscription"""
profile = self.memory.getProfileName(profile_key)
assert(profile)
to_jid = jid.JID(raw_jid)
debug ('subsciption request [%s] for %s', type, to_jid.full())
if type=="subscribe":
self.presence.subscribe(to_jid)
self.profiles[profile].presence.subscribe(to_jid)
elif type=="subscribed":
self.presence.subscribed(to_jid)
self.profiles[profile].subscribed(to_jid)
contact = self.memory.getContact(to_jid)
if not contact or not bool(contact['to']): #we automatically subscribe to 'to' presence
debug('sending automatic "to" subscription request')
self.subscription('subscribe', to_jid.userhost())
elif type=="unsubscribe":
self.presence.unsubscribe(to_jid)
self.profiles[profile].presence.unsubscribe(to_jid)
elif type=="unsubscribed":
self.presence.unsubscribed(to_jid)
self.profiles[profile].presence.unsubscribed(to_jid)
def addContact(self, to):
def addContact(self, to, profile_key='@DEFAULT@'):
"""Add a contact in roster list"""
profile = self.memory.getProfileName(profile_key)
assert(profile)
to_jid=jid.JID(to)
self.roster.addItem(to_jid)
self.presence.subscribe(to_jid)
self.profiles[profile].roster.addItem(to_jid)
self.profiles[profile].presence.subscribe(to_jid)
def delContact(self, to):
def delContact(self, to, profile_key='@DEFAULT@'):
"""Remove contact from roster list"""
profile = self.memory.getProfileName(profile_key)
assert(profile)
to_jid=jid.JID(to)
self.roster.removeItem(to_jid)
self.presence.unsubscribe(to_jid)
self.bridge.contactDeleted(to)
self.profiles[profile].roster.removeItem(to_jid)
self.profiles[profile].presence.unsubscribe(to_jid)
self.profiles[profile].bridge.contactDeleted(to)
## callbacks ##

View file

@ -175,6 +175,7 @@ class Param():
import_node(self.dom.documentElement, src_dom.documentElement)
def __default_ok(self, value, name, category):
#FIXME: gof: will not work with individual parameters
self.setParam(name, value, category) #FIXME: better to set param xml value ???
def __default_ko(self, failure, name, category):
@ -561,8 +562,8 @@ class Memory:
def getParamsCategories(self):
return self.params.getParamsCategories()
def setParam(self, name, value, category):
return self.params.setParam(name, value, category)
def setParam(self, name, value, category, profile_key='@DEFAULT@'):
return self.params.setParam(name, value, category, profile_key)
def importParams(self, xml):
return self.params.importParams(xml)