Mercurial > libervia-backend
comparison frontends/src/quick_frontend/quick_app.py @ 1938:011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 18 Apr 2016 18:31:13 +0200 |
parents | 2daf7b4c6756 |
children | e68483c5a999 |
comparison
equal
deleted
inserted
replaced
1937:14a33c2b1b2a | 1938:011eff37e21d |
---|---|
27 from sat_frontends.tools import jid | 27 from sat_frontends.tools import jid |
28 from sat_frontends.quick_frontend import quick_widgets | 28 from sat_frontends.quick_frontend import quick_widgets |
29 from sat_frontends.quick_frontend import quick_menus | 29 from sat_frontends.quick_frontend import quick_menus |
30 from sat_frontends.quick_frontend import quick_blog | 30 from sat_frontends.quick_frontend import quick_blog |
31 from sat_frontends.quick_frontend import quick_chat, quick_games | 31 from sat_frontends.quick_frontend import quick_chat, quick_games |
32 from sat_frontends.quick_frontend import quick_contact_list | |
32 from sat_frontends.quick_frontend.constants import Const as C | 33 from sat_frontends.quick_frontend.constants import Const as C |
33 | 34 |
34 import sys | 35 import sys |
35 from collections import OrderedDict | 36 from collections import OrderedDict |
36 | 37 |
93 log.error(u"Couldn't get cached values: {}".format(failure)) | 94 log.error(u"Couldn't get cached values: {}".format(failure)) |
94 self._plug_profile_gotCachedValues({}) | 95 self._plug_profile_gotCachedValues({}) |
95 | 96 |
96 def _plug_profile_gotCachedValues(self, cached_values): | 97 def _plug_profile_gotCachedValues(self, cached_values): |
97 # add the contact list and its listener | 98 # add the contact list and its listener |
98 contact_list = self.host.addContactList(self.profile) | 99 contact_list = self.host.contact_lists.addProfile(self.profile) |
99 self.host.contact_lists[self.profile] = contact_list | |
100 | 100 |
101 for entity, data in cached_values.iteritems(): | 101 for entity, data in cached_values.iteritems(): |
102 for key, value in data.iteritems(): | 102 for key, value in data.iteritems(): |
103 contact_list.setCache(jid.JID(entity), key, value) | 103 contact_list.setCache(jid.JID(entity), key, value) |
104 | 104 |
190 if profile not in self._profiles: | 190 if profile not in self._profiles: |
191 raise ValueError('The profile [{}] is not plugged'.format(profile)) | 191 raise ValueError('The profile [{}] is not plugged'.format(profile)) |
192 | 192 |
193 # remove the contact list and its listener | 193 # remove the contact list and its listener |
194 host = self._profiles[profile].host | 194 host = self._profiles[profile].host |
195 host.contact_lists[profile].onDelete() | 195 host.contact_lists[profile].unplug() |
196 del host.contact_lists[profile] | |
197 | 196 |
198 del self._profiles[profile] | 197 del self._profiles[profile] |
199 | 198 |
200 def chooseOneProfile(self): | 199 def chooseOneProfile(self): |
201 return self._profiles.keys()[0] | 200 return self._profiles.keys()[0] |
216 self.menus = quick_menus.QuickMenusManager(self) | 215 self.menus = quick_menus.QuickMenusManager(self) |
217 ProfileManager.host = self | 216 ProfileManager.host = self |
218 self.profiles = ProfilesManager() | 217 self.profiles = ProfilesManager() |
219 self.ready_profiles = set() # profiles which are connected and ready | 218 self.ready_profiles = set() # profiles which are connected and ready |
220 self.signals_cache = {} # used to keep signal received between start of plug_profile and when the profile is actualy ready | 219 self.signals_cache = {} # used to keep signal received between start of plug_profile and when the profile is actualy ready |
221 self.contact_lists = {} | 220 self.contact_lists = quick_contact_list.QuickContactListHandler(self) |
222 self.widgets = quick_widgets.QuickWidgetsManager(self) | 221 self.widgets = quick_widgets.QuickWidgetsManager(self) |
223 if check_options is not None: | 222 if check_options is not None: |
224 self.options = check_options() | 223 self.options = check_options() |
225 else: | 224 else: |
226 self.options = None | 225 self.options = None |
294 raise NotImplementedError | 293 raise NotImplementedError |
295 | 294 |
296 @property | 295 @property |
297 def alerts_count(self): | 296 def alerts_count(self): |
298 """Count the over whole alerts for all contact lists""" | 297 """Count the over whole alerts for all contact lists""" |
299 return sum([sum(clist._alerts.values()) for clist in self.contact_lists.values()]) | 298 # FIXME |
299 # return sum([sum(clist._alerts.values()) for clist in self.contact_lists.values()]) | |
300 | 300 |
301 def registerSignal(self, function_name, handler=None, iface="core", with_profile=True): | 301 def registerSignal(self, function_name, handler=None, iface="core", with_profile=True): |
302 """Register a handler for a signal | 302 """Register a handler for a signal |
303 | 303 |
304 @param function_name (str): name of the signal to handle | 304 @param function_name (str): name of the signal to handle |
446 self.profiles.unplug(profile) | 446 self.profiles.unplug(profile) |
447 | 447 |
448 def clear_profile(self): | 448 def clear_profile(self): |
449 self.profiles.clear() | 449 self.profiles.clear() |
450 | 450 |
451 def addContactList(self, profile): | |
452 """Method to subclass to add a contact list widget | |
453 | |
454 will be called on each profile session build | |
455 @return: a ContactList widget | |
456 """ | |
457 return NotImplementedError | |
458 | |
459 def newWidget(self, widget): | 451 def newWidget(self, widget): |
460 raise NotImplementedError | 452 raise NotImplementedError |
461 | 453 |
462 def connectedHandler(self, profile, jid_s): | 454 def connectedHandler(self, profile, jid_s): |
463 """Called when the connection is made. | 455 """Called when the connection is made. |
471 self.contact_lists[profile].fill() | 463 self.contact_lists[profile].fill() |
472 | 464 |
473 def disconnectedHandler(self, profile): | 465 def disconnectedHandler(self, profile): |
474 """called when the connection is closed""" | 466 """called when the connection is closed""" |
475 log.debug(_("Disconnected")) | 467 log.debug(_("Disconnected")) |
476 self.contact_lists[profile].clearContacts() | 468 self.contact_lists[profile].disconnect() |
477 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile) | 469 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile) |
478 | 470 |
479 def actionNewHandler(self, action_data, id_, security_limit, profile): | 471 def actionNewHandler(self, action_data, id_, security_limit, profile): |
480 self.actionManager(action_data, profile=profile) | 472 self.actionManager(action_data, profile=profile) |
481 | 473 |
482 def newContactHandler(self, jid_s, attributes, groups, profile): | 474 def newContactHandler(self, jid_s, attributes, groups, profile): |
483 entity = jid.JID(jid_s) | 475 entity = jid.JID(jid_s) |
484 _groups = list(groups) | 476 groups = list(groups) |
485 self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True) | 477 self.contact_lists[profile].setContact(entity, groups, attributes, in_roster=True) |
486 | 478 |
487 def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile): | 479 def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile): |
488 from_jid = jid.JID(from_jid_s) | 480 from_jid = jid.JID(from_jid_s) |
489 to_jid = jid.JID(to_jid_s) | 481 to_jid = jid.JID(to_jid_s) |
490 if not self.trigger.point("newMessageTrigger", from_jid, msg, type_, to_jid, extra, profile=profile): | 482 if not self.trigger.point("newMessageTrigger", from_jid, msg, type_, to_jid, extra, profile=profile): |
514 visible = False | 506 visible = False |
515 for widget in self.visible_widgets: | 507 for widget in self.visible_widgets: |
516 if isinstance(widget, quick_chat.QuickChat) and widget.manageMessage(from_jid, type_): | 508 if isinstance(widget, quick_chat.QuickChat) and widget.manageMessage(from_jid, type_): |
517 visible = True | 509 visible = True |
518 break | 510 break |
519 if visible: | 511 if visible: # FIXME: à virer gof: |
520 if self.isHidden(): # the window is hidden | 512 if self.isHidden(): # the window is hidden |
521 self.updateAlertsCounter(extra_inc=1) | 513 self.updateAlertsCounter(extra_inc=1) |
522 else: | 514 else: |
523 contact_list.addAlert(from_jid.bare if type_ == C.MESS_TYPE_GROUPCHAT else from_jid) | 515 contact_list.addAlert(from_jid.bare if type_ == C.MESS_TYPE_GROUPCHAT else from_jid) |
524 | 516 |
728 elif (namespace, name) == ('General', C.SHOW_EMPTY_GROUPS): | 720 elif (namespace, name) == ('General', C.SHOW_EMPTY_GROUPS): |
729 self.contact_lists[profile].showEmptyGroups(C.bool(value)) | 721 self.contact_lists[profile].showEmptyGroups(C.bool(value)) |
730 | 722 |
731 def contactDeletedHandler(self, jid_s, profile): | 723 def contactDeletedHandler(self, jid_s, profile): |
732 target = jid.JID(jid_s) | 724 target = jid.JID(jid_s) |
733 self.contact_lists[profile].removeContact(target, in_roster=True) | 725 self.contact_lists[profile].removeContact(target) |
734 | 726 |
735 def entityDataUpdatedHandler(self, entity_s, key, value, profile): | 727 def entityDataUpdatedHandler(self, entity_s, key, value, profile): |
736 entity = jid.JID(entity_s) | 728 entity = jid.JID(entity_s) |
737 if key == "nick": # this is the roster nick, not the MUC nick | 729 if key == "nick": # this is the roster nick, not the MUC nick |
738 if entity in self.contact_lists[profile]: | 730 if entity in self.contact_lists[profile]: |