comparison sat.tac @ 66:8147b4f40809

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
author Goffi <goffi@goffi.org>
date Wed, 03 Feb 2010 23:35:57 +1100
parents d35c5edab53f
children 0e50dd3a234a
comparison
equal deleted inserted replaced
65:d35c5edab53f 66:8147b4f40809
81 print "SatXMPPClient" 81 print "SatXMPPClient"
82 client.XMPPClient._authd(self, xmlstream) 82 client.XMPPClient._authd(self, xmlstream)
83 self.__connected=True 83 self.__connected=True
84 print "********** [%s] CONNECTED **********" % self.profile 84 print "********** [%s] CONNECTED **********" % self.profile
85 self.streamInitialized() 85 self.streamInitialized()
86 self.host_app.bridge.connected() #we send the signal to the clients 86 self.host_app.bridge.connected(self.profile) #we send the signal to the clients
87 87
88 def streamInitialized(self): 88 def streamInitialized(self):
89 """Called after _authd""" 89 """Called after _authd"""
90 debug ("XML stream is initialized") 90 debug ("XML stream is initialized")
91 self.keep_alife = task.LoopingCall(self.xmlstream.send, " ") #Needed to avoid disconnection (specially with openfire) 91 self.keep_alife = task.LoopingCall(self.xmlstream.send, " ") #Needed to avoid disconnection (specially with openfire)
110 print "********** [%s] DISCONNECTED **********" % self.profile 110 print "********** [%s] DISCONNECTED **********" % self.profile
111 try: 111 try:
112 self.keep_alife.stop() 112 self.keep_alife.stop()
113 except AttributeError: 113 except AttributeError:
114 debug("No keep_alife") 114 debug("No keep_alife")
115 self.host_app.bridge.disconnected() #we send the signal to the clients 115 self.host_app.bridge.disconnected(self.profile) #we send the signal to the clients
116 116
117 117
118 class SatMessageProtocol(xmppim.MessageProtocol): 118 class SatMessageProtocol(xmppim.MessageProtocol):
119 119
120 def __init__(self, host): 120 def __init__(self, host):
123 123
124 def onMessage(self, message): 124 def onMessage(self, message):
125 debug (u"got_message from: %s", message["from"]) 125 debug (u"got_message from: %s", message["from"])
126 for e in message.elements(): 126 for e in message.elements():
127 if e.name == "body": 127 if e.name == "body":
128 self.host.bridge.newMessage(message["from"], e.children[0]) 128 self.host.bridge.newMessage(message["from"], e.children[0], self.parent.profile)
129 self.host.memory.addToHistory(self.parent.jid, jid.JID(message["from"]), self.parent.jid, "chat", e.children[0]) 129 self.host.memory.addToHistory(self.parent.jid, jid.JID(message["from"]), self.parent.jid, "chat", e.children[0])
130 break 130 break
131 131
132 class SatRosterProtocol(xmppim.RosterClientProtocol): 132 class SatRosterProtocol(xmppim.RosterClientProtocol):
133 133
163 } 163 }
164 if item.name: 164 if item.name:
165 item_attr['name'] = item.name 165 item_attr['name'] = item.name
166 info ("new contact in roster list: %s", item.jid.full()) 166 info ("new contact in roster list: %s", item.jid.full())
167 self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile) 167 self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile)
168 self.host.bridge.newContact(item.jid.full(), item_attr, item.groups) 168 self.host.bridge.newContact(item.jid.full(), item_attr, item.groups, self.parent.profile)
169 169
170 def onRosterRemove(self, entity): 170 def onRosterRemove(self, entity):
171 """Called when a roster removal event is received""" 171 """Called when a roster removal event is received"""
172 #TODO: send a signal to frontends 172 #TODO: send a signal to frontends
173 print "removing %s from roster list" % entity.full() 173 print "removing %s from roster list" % entity.full()
189 self.host.memory.addPresenceStatus(entity, show or "", 189 self.host.memory.addPresenceStatus(entity, show or "",
190 int(priority), statuses, self.parent.profile) 190 int(priority), statuses, self.parent.profile)
191 191
192 #now it's time to notify frontends 192 #now it's time to notify frontends
193 self.host.bridge.presenceUpdate(entity.full(), show or "", 193 self.host.bridge.presenceUpdate(entity.full(), show or "",
194 int(priority), statuses) 194 int(priority), statuses, self.parent.profile)
195 195
196 def unavailableReceived(self, entity, statuses=None): 196 def unavailableReceived(self, entity, statuses=None):
197 if statuses and statuses.has_key(None): #we only want string keys 197 if statuses and statuses.has_key(None): #we only want string keys
198 statuses["default"] = statuses[None] 198 statuses["default"] = statuses[None]
199 del statuses[None] 199 del statuses[None]
200 self.host.memory.addPresenceStatus(entity, "unavailable", 0, statuses, self.parent.profile) 200 self.host.memory.addPresenceStatus(entity, "unavailable", 0, statuses, self.parent.profile)
201 201
202 #now it's time to notify frontends 202 #now it's time to notify frontends
203 self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses) 203 self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses, self.parent.profile)
204 204
205 205
206 def available(self, entity=None, show=None, statuses=None, priority=0): 206 def available(self, entity=None, show=None, statuses=None, priority=0):
207 if statuses and statuses.has_key('default'): 207 if statuses and statuses.has_key('default'):
208 statuses[None] = statuses['default'] 208 statuses[None] = statuses['default']
210 xmppim.PresenceClientProtocol.available(self, entity, show, statuses, priority) 210 xmppim.PresenceClientProtocol.available(self, entity, show, statuses, priority)
211 211
212 def subscribedReceived(self, entity): 212 def subscribedReceived(self, entity):
213 debug ("subscription approved for [%s]" % entity.userhost()) 213 debug ("subscription approved for [%s]" % entity.userhost())
214 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile) 214 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile)
215 self.host.bridge.subscribe('subscribed', entity.userhost()) 215 self.host.bridge.subscribe('subscribed', entity.userhost(), self.parent.profile)
216 216
217 def unsubscribedReceived(self, entity): 217 def unsubscribedReceived(self, entity):
218 debug ("unsubscription confirmed for [%s]" % entity.userhost()) 218 debug ("unsubscription confirmed for [%s]" % entity.userhost())
219 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile) 219 self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile)
220 self.host.bridge.subscribe('unsubscribed', entity.userhost()) 220 self.host.bridge.subscribe('unsubscribed', entity.userhost(), self.parent.profile)
221 221
222 def subscribeReceived(self, entity): 222 def subscribeReceived(self, entity):
223 debug ("subscription request for [%s]" % entity.userhost()) 223 debug ("subscription request for [%s]" % entity.userhost())
224 self.host.memory.addWaitingSub('subscribe', entity.userhost(), self.parent.profile) 224 self.host.memory.addWaitingSub('subscribe', entity.userhost(), self.parent.profile)
225 self.host.bridge.subscribe('subscribe', entity.userhost()) 225 self.host.bridge.subscribe('subscribe', entity.userhost(), self.parent.profile)
226 226
227 def unsubscribeReceived(self, entity): 227 def unsubscribeReceived(self, entity):
228 debug ("unsubscription asked for [%s]" % entity.userhost()) 228 debug ("unsubscription asked for [%s]" % entity.userhost())
229 self.host.memory.addWaitingSub('unsubscribe', entity.userhost(), self.parent.profile) 229 self.host.memory.addWaitingSub('unsubscribe', entity.userhost(), self.parent.profile)
230 self.host.bridge.subscribe('unsubscribe', entity.userhost()) 230 self.host.bridge.subscribe('unsubscribe', entity.userhost(), self.parent.profile)
231 231
232 class SatDiscoProtocol(disco.DiscoClientProtocol): 232 class SatDiscoProtocol(disco.DiscoClientProtocol):
233 def __init__(self, host): 233 def __init__(self, host):
234 disco.DiscoClientProtocol.__init__(self) 234 disco.DiscoClientProtocol.__init__(self)
235 235
324 324
325 self.memory=Memory(self) 325 self.memory=Memory(self)
326 self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future 326 self.server_features=[] #XXX: temp dic, need to be transfered into self.memory in the future
327 327
328 self.bridge=DBusBridge() 328 self.bridge=DBusBridge()
329 self.bridge.register("getProfileName", self.memory.getProfileName)
329 self.bridge.register("getProfilesList", self.memory.getProfilesList) 330 self.bridge.register("getProfilesList", self.memory.getProfilesList)
330 self.bridge.register("createProfile", self.memory.createProfile) 331 self.bridge.register("createProfile", self.memory.createProfile)
331 self.bridge.register("registerNewAccount", self.registerNewAccount) 332 self.bridge.register("registerNewAccount", self.registerNewAccount)
332 self.bridge.register("connect", self.connect) 333 self.bridge.register("connect", self.connect)
333 self.bridge.register("disconnect", self.disconnect) 334 self.bridge.register("disconnect", self.disconnect)
405 self.get_const('client_version')) 406 self.get_const('client_version'))
406 current.versionHandler.setHandlerParent(current) 407 current.versionHandler.setHandlerParent(current)
407 408
408 debug ("setting plugins parents") 409 debug ("setting plugins parents")
409 410
410 #FIXME: gof
411 for plugin in self.plugins.iteritems(): 411 for plugin in self.plugins.iteritems():
412 if plugin[1].is_handler: 412 if plugin[1].is_handler:
413 plugin[1].getHandler().setHandlerParent(current) 413 plugin[1].getHandler().setHandlerParent(current)
414 414
415 current.startService() 415 current.startService()
583 message["from"] = current_jid.full() 583 message["from"] = current_jid.full()
584 message["type"] = type 584 message["type"] = type
585 message.addElement("body", "jabber:client", msg) 585 message.addElement("body", "jabber:client", msg)
586 self.profiles[profile].xmlstream.send(message) 586 self.profiles[profile].xmlstream.send(message)
587 self.memory.addToHistory(current_jid, current_jid, jid.JID(to), message["type"], unicode(msg)) 587 self.memory.addToHistory(current_jid, current_jid, jid.JID(to), message["type"], unicode(msg))
588 self.bridge.newMessage(message['from'], unicode(msg), to=message['to']) #We send back the message, so all clients are aware of it 588 self.bridge.newMessage(message['from'], unicode(msg), to=message['to'], profile=profile) #We send back the message, so all clients are aware of it
589 589
590 590
591 def setPresence(self, to="", show="", priority = 0, statuses={}, profile_key='@DEFAULT@'): 591 def setPresence(self, to="", show="", priority = 0, statuses={}, profile_key='@DEFAULT@'):
592 """Send our presence information""" 592 """Send our presence information"""
593 profile = self.memory.getProfileName(profile_key) 593 profile = self.memory.getProfileName(profile_key)
628 profile = self.memory.getProfileName(profile_key) 628 profile = self.memory.getProfileName(profile_key)
629 assert(profile) 629 assert(profile)
630 to_jid=jid.JID(to) 630 to_jid=jid.JID(to)
631 self.profiles[profile].roster.removeItem(to_jid) 631 self.profiles[profile].roster.removeItem(to_jid)
632 self.profiles[profile].presence.unsubscribe(to_jid) 632 self.profiles[profile].presence.unsubscribe(to_jid)
633 self.profiles[profile].bridge.contactDeleted(to) 633 self.host.bridge.contactDeleted(to, profile)
634 634
635 635
636 ## callbacks ## 636 ## callbacks ##
637 637
638 def serverDisco(self, disco): 638 def serverDisco(self, disco):