comparison frontends/src/quick_frontend/quick_app.py @ 1417:176de79c8c39

core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus": - remove parameter "online" (can be guess from "presence" value) - process "statuses" dict in quick_frontend, so this method can get a simple unicode "status" - add C.PRESENCE_STATUSES_DEFAULT to define the key to use for fallback status
author souliane <souliane@mailoo.org>
date Mon, 20 Apr 2015 16:39:38 +0200
parents 3265a2639182
children 6adf1b0be609
comparison
equal deleted inserted replaced
1416:a419da93afef 1417:176de79c8c39
94 for entity, data in cached_values.iteritems(): 94 for entity, data in cached_values.iteritems():
95 for key, value in data.iteritems(): 95 for key, value in data.iteritems():
96 contact_list.setCache(jid.JID(entity), key, value) 96 contact_list.setCache(jid.JID(entity), key, value)
97 97
98 if not self.bridge.isConnected(self.profile): 98 if not self.bridge.isConnected(self.profile):
99 self.host.setStatusOnline(False, profile=self.profile) 99 self.host.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=self.profile)
100 else: 100 else:
101 self.host.setStatusOnline(True, profile=self.profile)
102 101
103 contact_list.fill() 102 contact_list.fill()
103 self.host.setPresenceStatus(profile=self.profile)
104 104
105 #The waiting subscription requests 105 #The waiting subscription requests
106 self.bridge.getWaitingSub(self.profile, callback=self._plug_profile_gotWaitingSub) 106 self.bridge.getWaitingSub(self.profile, callback=self._plug_profile_gotWaitingSub)
107 107
108 def _plug_profile_gotWaitingSub(self, waiting_sub): 108 def _plug_profile_gotWaitingSub(self, waiting_sub):
122 for subject_args in subjects_args: 122 for subject_args in subjects_args:
123 self.host.roomNewSubjectHandler(*subject_args, profile=self.profile) 123 self.host.roomNewSubjectHandler(*subject_args, profile=self.profile)
124 124
125 #Presence must be requested after rooms are filled 125 #Presence must be requested after rooms are filled
126 self.host.bridge.getPresenceStatuses(self.profile, callback=self._plug_profile_gotPresences) 126 self.host.bridge.getPresenceStatuses(self.profile, callback=self._plug_profile_gotPresences)
127
128 127
129 def _plug_profile_gotPresences(self, presences): 128 def _plug_profile_gotPresences(self, presences):
130 def gotEntityData(data, contact): 129 def gotEntityData(data, contact):
131 for key in ('avatar', 'nick'): 130 for key in ('avatar', 'nick'):
132 if key in data: 131 if key in data:
441 raise NotImplementedError 440 raise NotImplementedError
442 441
443 def connectedHandler(self, profile): 442 def connectedHandler(self, profile):
444 """called when the connection is made""" 443 """called when the connection is made"""
445 log.debug(_("Connected")) 444 log.debug(_("Connected"))
446 self.setStatusOnline(True, profile=profile) 445 self.setPresenceStatus(profile=profile)
447 446
448 def disconnectedHandler(self, profile): 447 def disconnectedHandler(self, profile):
449 """called when the connection is closed""" 448 """called when the connection is closed"""
450 log.debug(_("Disconnected")) 449 log.debug(_("Disconnected"))
451 self.contact_lists[profile].clearContacts() 450 self.contact_lists[profile].clearContacts()
452 self.setStatusOnline(False, profile=profile) 451 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile)
453 452
454 def newContactHandler(self, JabberId, attributes, groups, profile): 453 def newContactHandler(self, JabberId, attributes, groups, profile):
455 entity = jid.JID(JabberId) 454 entity = jid.JID(JabberId)
456 _groups = list(groups) 455 _groups = list(groups)
457 self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True) 456 self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True)
503 502
504 def newAlertHandler(self, msg, title, alert_type, profile): 503 def newAlertHandler(self, msg, title, alert_type, profile):
505 assert alert_type in ['INFO', 'ERROR'] 504 assert alert_type in ['INFO', 'ERROR']
506 self.showDialog(unicode(msg), unicode(title), alert_type.lower()) 505 self.showDialog(unicode(msg), unicode(title), alert_type.lower())
507 506
508 def setStatusOnline(self, online=True, show="", statuses={}, profile=C.PROF_KEY_NONE): 507 def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE):
509 raise NotImplementedError 508 raise NotImplementedError
510 509
511 def presenceUpdateHandler(self, entity_s, show, priority, statuses, profile): 510 def presenceUpdateHandler(self, entity_s, show, priority, statuses, profile):
512 511
513 log.debug(_(u"presence update for %(entity)s (show=%(show)s, priority=%(priority)s, statuses=%(statuses)s) [profile:%(profile)s]") 512 log.debug(_(u"presence update for %(entity)s (show=%(show)s, priority=%(priority)s, statuses=%(statuses)s) [profile:%(profile)s]")
514 % {'entity': entity_s, C.PRESENCE_SHOW: show, C.PRESENCE_PRIORITY: priority, C.PRESENCE_STATUSES: statuses, 'profile': profile}) 513 % {'entity': entity_s, C.PRESENCE_SHOW: show, C.PRESENCE_PRIORITY: priority, C.PRESENCE_STATUSES: statuses, 'profile': profile})
515 entity = jid.JID(entity_s) 514 entity = jid.JID(entity_s)
516 515
517 if entity == self.profiles[profile].whoami: 516 if entity == self.profiles[profile].whoami:
518 if show == "unavailable": 517 if show == C.PRESENCE_UNAVAILABLE:
519 self.setStatusOnline(False, profile=profile) 518 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile)
520 else: 519 else:
521 self.setStatusOnline(True, show, statuses, profile=profile) 520 # FIXME: try to retrieve user language status before fallback to default
521 status = statuses.get(C.PRESENCE_STATUSES_DEFAULT, None)
522 self.setPresenceStatus(show, status, profile=profile)
522 return 523 return
523 524
524 # #FIXME: must be moved in a plugin 525 # #FIXME: must be moved in a plugin
525 # if entity.bare in self.profiles[profile].data.get('watched',[]) and not entity.bare in self.profiles[profile]['onlineContact']: 526 # if entity.bare in self.profiles[profile].data.get('watched',[]) and not entity.bare in self.profiles[profile]['onlineContact']:
526 # self.showAlert(_("Watched jid [%s] is connected !") % entity.bare) 527 # self.showAlert(_("Watched jid [%s] is connected !") % entity.bare)