diff sat.tac @ 63:0db25931b60d

SàT: multi-profiles: somes fixes in core
author Goffi <goffi@goffi.org>
date Fri, 29 Jan 2010 14:17:15 +1100
parents 93cb45a7420f
children d46f849664aa
line wrap: on
line diff
--- a/sat.tac	Fri Jan 29 13:55:41 2010 +1100
+++ b/sat.tac	Fri Jan 29 14:17:15 2010 +1100
@@ -413,13 +413,14 @@
 
         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 @@
 
     ## 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 @@
         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 ##