Mercurial > libervia-backend
changeset 1337:f29beedb33b0 frontends_multi_profiles
merged souliane changes
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 23 Feb 2015 18:08:22 +0100 |
parents | 2ecc07a8f91b (diff) 0f92b6a150ff (current diff) |
children | 139263ee85c5 |
files | frontends/src/constants.py frontends/src/primitivus/primitivus frontends/src/quick_frontend/quick_app.py frontends/src/quick_frontend/quick_contact_list.py src/plugins/plugin_xep_0085.py |
diffstat | 3 files changed, 56 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus Sun Feb 22 21:30:20 2015 +0100 +++ b/frontends/src/primitivus/primitivus Mon Feb 23 18:08:22 2015 +0100 @@ -529,8 +529,8 @@ def removeWindow(self): """Remove window showed on the right column""" - #TODO: to a better Window management than this crappy hack - assert(len(self.center_part.widget_list)<=2) + #TODO: better Window management than this hack + assert len(self.center_part.widget_list) <= 2 wid_idx = len(self.center_part.widget_list)-1 self.center_part.widget_list[wid_idx] = urwid.Filler(urwid.Text('')) self.center_part.focus_position = 0 @@ -555,21 +555,6 @@ self.selectWidget(chat_widget) self.menu_roller.addMenu(_('Chat menu'), chat_widget.getMenu(), C.MENU_ID_WIDGET) - def newMessageHandler(self, from_jid, to_jid, msg, type_, extra, profile): - QuickApp.newMessageHandler(self, from_jid, to_jid, msg, type_, extra, profile) - - if not from_jid in self.contact_lists[profile] and from_jid.bare != self.profiles[profile].whoami.bare: - #XXX: needed to show entities which haven't sent any - # presence information and which are not in roster - self.contact_lists[profile].setContact(from_jid) - visible = False - for widget in self.visible_widgets: - if isinstance(widget, Chat) and widget.manageMessage(from_jid, type_): - visible = True - break - if not visible: - self.contact_lists[profile].setAlert(from_jid.bare if type_ == C.MESS_TYPE_GROUPCHAT else from_jid) - def _dialogOkCb(self, widget, data): self.removePopUp() answer_cb = data[0]
--- a/frontends/src/quick_frontend/quick_app.py Sun Feb 22 21:30:20 2015 +0100 +++ b/frontends/src/quick_frontend/quick_app.py Mon Feb 23 18:08:22 2015 +0100 @@ -230,7 +230,7 @@ self.registerSignal("connected") self.registerSignal("disconnected") self.registerSignal("newContact") - self.registerSignal("newMessage", self._newMessage) + self.registerSignal("newMessage") self.registerSignal("newAlert") self.registerSignal("presenceUpdate") self.registerSignal("subscribe") @@ -433,24 +433,37 @@ _groups = list(groups) self.contact_lists[profile].setContact(entity, _groups, attributes, in_roster=True) - def _newMessage(self, from_jid_s, msg, type_, to_jid_s, extra, profile): + def newMessageHandler(self, from_jid_s, msg, type_, to_jid_s, extra, profile): from_jid = jid.JID(from_jid_s) to_jid = jid.JID(to_jid_s) - self.newMessageHandler(from_jid, to_jid, msg, type_, extra, profile) - - def newMessageHandler(self, from_jid, to_jid, msg, type_, extra, profile): from_me = from_jid.bare == self.profiles[profile].whoami.bare target = to_jid if from_me else from_jid chat_type = C.CHAT_GROUP if type_ == C.MESS_TYPE_GROUPCHAT else C.CHAT_ONE2ONE + contact_list = self.contact_lists[profile] - chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, target, type_=chat_type, profile=profile) + chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, target, type_=chat_type, on_new_widget=None, profile=profile) self.current_action_ids = set() # FIXME: to be removed self.current_action_ids_cb = {} # FIXME: to be removed + if not from_jid in contact_list and from_jid.bare != self.profiles[profile].whoami.bare: + #XXX: needed to show entities which haven't sent any + # presence information and which are not in roster + contact_list.setContact(from_jid) + + # we display the message in the widget chat_widget.newMessage(from_jid, target, msg, type_, extra, profile) + # ContactList alert + visible = False + for widget in self.visible_widgets: + if isinstance(widget, quick_chat.QuickChat) and widget.manageMessage(from_jid, type_): + visible = True + break + if not visible: + contact_list.setAlert(from_jid.bare if type_ == C.MESS_TYPE_GROUPCHAT else from_jid) + def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, callback=None, errback=None, profile_key=C.PROF_KEY_NONE): if callback is None: callback = lambda dummy=None: None # FIXME: optional argument is here because pyjamas doesn't support callback without arg with json proxy
--- a/frontends/src/quick_frontend/quick_contact_list.py Sun Feb 22 21:30:20 2015 +0100 +++ b/frontends/src/quick_frontend/quick_contact_list.py Mon Feb 23 18:08:22 2015 +0100 @@ -22,6 +22,7 @@ log = getLogger(__name__) from sat_frontends.quick_frontend.quick_widgets import QuickWidget from sat_frontends.quick_frontend.constants import Const as C +from sat_frontends.tools import jid try: @@ -68,8 +69,8 @@ self.show_resources = False self.show_status = False # TODO: this may lead to two successive UI refresh and needs an optimization - self.host.bridge.asyncGetParamA(C.SHOW_EMPTY_GROUPS, "General", profile_key=profile, callback=self.showEmptyGroups) - self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=profile, callback=self.showOfflineContacts) + self.host.bridge.asyncGetParamA(C.SHOW_EMPTY_GROUPS, "General", profile_key=profile, callback=self._showEmptyGroups) + self.host.bridge.asyncGetParamA(C.SHOW_OFFLINE_CONTACTS, "General", profile_key=profile, callback=self._showOfflineContacts) # FIXME: workaround for a pyjamas issue: calling hash on a class method always return a different value if that method is defined directly within the class (with the "def" keyword) self.presenceListener = self.updatePresence @@ -147,6 +148,7 @@ - if no resource is given (bare jid), the main resource is used, according to priority - if resource is given, it is used @param name(unicode): name the data to get, or None to get everything + @return: full cache if no name is given, or value of "name", or None """ try: cache = self._cache[entity.bare] @@ -181,6 +183,19 @@ """ self.setContact(entity, None, {name: value}) + def getFullJid(self, entity): + """Get full jid from a bare jid + + @param entity(jid.JID): must be a bare jid + @return (jid.JID): bare jid + main resource + @raise ValueError: the entity is not bare + """ + if entity.resource: + raise ValueError("getFullJid must be used with a bare jid") + main_resource = self.getCache(entity, C.CONTACT_MAIN_RESOURCE) + return jid.JID(u"{}/{}".format(entity, main_resource)) + + def setGroupData(self, group, name, value): """Register a data for a group @@ -293,9 +308,9 @@ def entityToShow(self, entity, check_resource=False): """Tell if the contact should be showed or hidden. - @param contact (jid.JID): jid of the contact + @param entity (jid.JID): jid of the contact @param check_resource (bool): True if resource must be significant - @return: True if that contact should be showed in the list + @return (bool): True if that contact should be showed in the list """ show = self.getCache(entity, C.PRESENCE_SHOW) @@ -366,7 +381,10 @@ cache[C.CONTACT_RESOURCES].clear() cache[C.CONTACT_MAIN_RESOURCE]= None else: - del cache[C.CONTACT_RESOURCES][entity.resource] + try: + del cache[C.CONTACT_RESOURCES][entity.resource] + except KeyError: + log.error("Presence unavailable received for an unknown resource [{}]".format(entity)) if not cache[C.CONTACT_RESOURCES]: cache[C.CONTACT_MAIN_RESOURCE] = None else: @@ -402,15 +420,25 @@ self._alerts.add(entity) self.update() + def _showOfflineContacts(self, show_str): + self.showOfflineContacts(C.bool(show_str)) + def showOfflineContacts(self, show): - show = C.bool(show) + """Tell if offline contacts should shown + + @param show(bool): True if offline contacts should be shown + """ + assert isinstance(show, bool) if self.show_disconnected == show: return self.show_disconnected = show self.update() + def _showEmptyGroups(self, show_str): + self.showEmptyGroups(C.bool(show_str)) + def showEmptyGroups(self, show): - show = C.bool(show) + assert isinstance(show, bool) if self.show_empty_groups == show: return self.show_empty_groups = show