comparison src/core/sat_main.py @ 346:ca3a041fed30

core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
author Goffi <goffi@goffi.org>
date Sat, 28 May 2011 20:28:21 +0200
parents 9eebdc655b8b
children ea3e1b82dd79
comparison
equal deleted inserted replaced
345:e6047415868d 346:ca3a041fed30
32 from twisted.words.xish import domish 32 from twisted.words.xish import domish
33 33
34 from twisted.internet import reactor 34 from twisted.internet import reactor
35 35
36 from wokkel import compat 36 from wokkel import compat
37 from wokkel.xmppim import RosterItem
37 38
38 from sat.bridge.DBus import DBusBridge 39 from sat.bridge.DBus import DBusBridge
39 import logging 40 import logging
40 from logging import debug, info, error 41 from logging import debug, info, error
41 42
126 self.bridge.register("getParamsCategories", self.memory.getParamsCategories) 127 self.bridge.register("getParamsCategories", self.memory.getParamsCategories)
127 self.bridge.register("getHistory", self.memory.getHistory) 128 self.bridge.register("getHistory", self.memory.getHistory)
128 self.bridge.register("setPresence", self.setPresence) 129 self.bridge.register("setPresence", self.setPresence)
129 self.bridge.register("subscription", self.subscription) 130 self.bridge.register("subscription", self.subscription)
130 self.bridge.register("addContact", self.addContact) 131 self.bridge.register("addContact", self.addContact)
132 self.bridge.register("updateContact", self.updateContact)
131 self.bridge.register("delContact", self.delContact) 133 self.bridge.register("delContact", self.delContact)
132 self.bridge.register("isConnected", self.isConnected) 134 self.bridge.register("isConnected", self.isConnected)
133 self.bridge.register("launchAction", self.launchAction) 135 self.bridge.register("launchAction", self.launchAction)
134 self.bridge.register("confirmationAnswer", self.confirmationAnswer) 136 self.bridge.register("confirmationAnswer", self.confirmationAnswer)
135 self.bridge.register("getProgress", self.getProgress) 137 self.bridge.register("getProgress", self.getProgress)
233 if plugin[1].is_handler: 235 if plugin[1].is_handler:
234 plugin[1].getHandler(profile).setHandlerParent(current) 236 plugin[1].getHandler(profile).setHandlerParent(current)
235 237
236 current.startService() 238 current.startService()
237 239
238 def disconnect(self, profile_key='@DEFAULT@'): 240 def disconnect(self, profile_key):
239 """disconnect from jabber server""" 241 """disconnect from jabber server"""
240 if (not self.isConnected(profile_key)): 242 if (not self.isConnected(profile_key)):
241 info(_("not connected !")) 243 info(_("not connected !"))
242 return 244 return
243 profile = self.memory.getProfileName(profile_key) 245 profile = self.memory.getProfileName(profile_key)
320 server = self.memory.getParamA("Server", "Connection", profile_key=profile) 322 server = self.memory.getParamA("Server", "Connection", profile_key=profile)
321 self.registerNewAccount(user, password, None, server, id=action_id) 323 self.registerNewAccount(user, password, None, server, id=action_id)
322 else: 324 else:
323 self.actionResult(action_id, "SUPPRESS", {}) 325 self.actionResult(action_id, "SUPPRESS", {})
324 326
325 def submitForm(self, action, target, fields, profile_key='@DEFAULT@'): 327 def submitForm(self, action, target, fields, profile_key):
326 """submit a form 328 """submit a form
327 @param target: target jid where we are submitting 329 @param target: target jid where we are submitting
328 @param fields: list of tuples (name, value) 330 @param fields: list of tuples (name, value)
329 @return: tuple: (id, deferred) 331 @return: tuple: (id, deferred)
330 """ 332 """
349 deferred = iq.send(target) 351 deferred = iq.send(target)
350 return (iq['id'], deferred) 352 return (iq['id'], deferred)
351 353
352 ## Client management ## 354 ## Client management ##
353 355
354 def setParam(self, name, value, category, profile_key='@DEFAULT@'): 356 def setParam(self, name, value, category, profile_key):
355 """set wanted paramater and notice observers""" 357 """set wanted paramater and notice observers"""
356 info (_("setting param: %(name)s=%(value)s in category %(category)s") % {'name':name, 'value':value, 'category':category}) 358 info (_("setting param: %(name)s=%(value)s in category %(category)s") % {'name':name, 'value':value, 'category':category})
357 self.memory.setParam(name, value, category, profile_key) 359 self.memory.setParam(name, value, category, profile_key)
358 360
359 def isConnected(self, profile_key='@DEFAULT@'): 361 def isConnected(self, profile_key):
360 """Return connection status of profile 362 """Return connection status of profile
361 @param profile_key: key_word or profile name to determine profile name 363 @param profile_key: key_word or profile name to determine profile name
362 @return True if connected 364 @return True if connected
363 """ 365 """
364 profile = self.memory.getProfileName(profile_key) 366 profile = self.memory.getProfileName(profile_key)
367 return 369 return
368 if not self.profiles.has_key(profile): 370 if not self.profiles.has_key(profile):
369 return False 371 return False
370 return self.profiles[profile].isConnected() 372 return self.profiles[profile].isConnected()
371 373
372 def launchAction(self, type, data, profile_key='@DEFAULT@'): 374 def launchAction(self, type, data, profile_key):
373 """Launch a specific action asked by client 375 """Launch a specific action asked by client
374 @param type: action type (button) 376 @param type: action type (button)
375 @param data: needed data to launch the action 377 @param data: needed data to launch the action
376 378
377 @return: action id for result, or empty string in case or error 379 @return: action id for result, or empty string in case or error
427 del statuses[''] 429 del statuses['']
428 self.bridge.presenceUpdate(self.profiles[profile].jid.full(), show, 430 self.bridge.presenceUpdate(self.profiles[profile].jid.full(), show,
429 int(priority), statuses, profile) 431 int(priority), statuses, profile)
430 432
431 433
432 def subscription(self, subs_type, raw_jid, profile_key='@DEFAULT@'): 434 def subscription(self, subs_type, raw_jid, profile_key):
433 """Called to manage subscription 435 """Called to manage subscription
434 @param subs_type: subsciption type (cf RFC 3921) 436 @param subs_type: subsciption type (cf RFC 3921)
435 @param raw_jid: unicode entity's jid 437 @param raw_jid: unicode entity's jid
436 @param profile_key: profile""" 438 @param profile_key: profile"""
437 profile = self.memory.getProfileName(profile_key) 439 profile = self.memory.getProfileName(profile_key)
440 debug (_('subsciption request [%(subs_type)s] for %(jid)s') % {'subs_type':subs_type, 'jid':to_jid.full()}) 442 debug (_('subsciption request [%(subs_type)s] for %(jid)s') % {'subs_type':subs_type, 'jid':to_jid.full()})
441 if subs_type=="subscribe": 443 if subs_type=="subscribe":
442 self.profiles[profile].presence.subscribe(to_jid) 444 self.profiles[profile].presence.subscribe(to_jid)
443 elif subs_type=="subscribed": 445 elif subs_type=="subscribed":
444 self.profiles[profile].presence.subscribed(to_jid) 446 self.profiles[profile].presence.subscribed(to_jid)
445 contact = self.memory.getContact(to_jid)
446 if not contact or not bool(contact['to']): #we automatically subscribe to 'to' presence
447 debug(_('sending automatic "to" subscription request'))
448 self.subscription('subscribe', to_jid.userhost())
449 elif subs_type=="unsubscribe": 447 elif subs_type=="unsubscribe":
450 self.profiles[profile].presence.unsubscribe(to_jid) 448 self.profiles[profile].presence.unsubscribe(to_jid)
451 elif subs_type=="unsubscribed": 449 elif subs_type=="unsubscribed":
452 self.profiles[profile].presence.unsubscribed(to_jid) 450 self.profiles[profile].presence.unsubscribed(to_jid)
453 451
454 452 def addContact(self, to, profile_key):
455 def addContact(self, to, profile_key='@DEFAULT@'):
456 """Add a contact in roster list""" 453 """Add a contact in roster list"""
457 profile = self.memory.getProfileName(profile_key) 454 profile = self.memory.getProfileName(profile_key)
458 assert(profile) 455 assert(profile)
459 to_jid=jid.JID(to) 456 to_jid=jid.JID(to)
460 #self.profiles[profile].roster.addItem(to_jid) XXX: disabled (cf http://wokkel.ik.nu/ticket/56)) 457 #self.profiles[profile].roster.addItem(to_jid) XXX: disabled (cf http://wokkel.ik.nu/ticket/56))
461 self.profiles[profile].presence.subscribe(to_jid) 458 self.profiles[profile].presence.subscribe(to_jid)
462 459
463 def delContact(self, to, profile_key='@DEFAULT@'): 460 def updateContact(self, to, name, groups, profile_key):
461 """update a contact in roster list"""
462 profile = self.memory.getProfileName(profile_key)
463 assert(profile)
464 to_jid = jid.JID(to)
465 groups = set(groups)
466 roster_item = RosterItem(to_jid)
467 roster_item.name = name or None
468 roster_item.groups = set(groups)
469 self.profiles[profile].roster.updateItem(roster_item)
470
471 def delContact(self, to, profile_key):
464 """Remove contact from roster list""" 472 """Remove contact from roster list"""
465 profile = self.memory.getProfileName(profile_key) 473 profile = self.memory.getProfileName(profile_key)
466 assert(profile) 474 assert(profile)
467 to_jid=jid.JID(to) 475 to_jid=jid.JID(to)
468 self.profiles[profile].roster.removeItem(to_jid) 476 self.profiles[profile].roster.removeItem(to_jid)