changeset 652:0262fee86375 frontends_multi_profiles

browser_side: MicroblogPanel.accepted_groups (set of unicode) is now built from QuickWidget.targets (set of tuple of unicode)
author souliane <souliane@mailoo.org>
date Fri, 27 Feb 2015 01:11:34 +0100 (2015-02-27)
parents 2df91d0308ac
children e1d067378ad3
files src/browser/sat_browser/blog.py src/browser/sat_browser/chat.py src/browser/sat_browser/libervia_widget.py
diffstat 3 files changed, 20 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/src/browser/sat_browser/blog.py	Fri Feb 27 01:08:36 2015 +0100
+++ b/src/browser/sat_browser/blog.py	Fri Feb 27 01:11:34 2015 +0100
@@ -357,17 +357,18 @@
 
 class MicroblogPanel(quick_widgets.QuickWidget, libervia_widget.LiberviaWidget):
     warning_msg_public = "This message will be <b>PUBLIC</b> and everybody will be able to see it, even people you don't know"
-    warning_msg_group = "This message will be published for all the people of the group <span class='warningTarget'>%s</span>"
+    warning_msg_group = "This message will be published for all the people of the following groups: <span class='warningTarget'>%s</span>"
     # FIXME: all the generic parts must be moved to quick_frontends
 
-    def __init__(self, host, accepted_groups, profiles=None):
+    def __init__(self, host, targets, profiles=None):
         """Panel used to show microblog
 
-        @param accepted_groups: groups displayed in this panel, if empty, show all microblogs from all contacts
+        @param targets (tuple(unicode)): contact groups displayed in this panel.
+            If empty, show all microblogs from all contacts.
         """
-        self.setAcceptedGroup(accepted_groups)
-        quick_widgets.QuickWidget.__init__(self, host, self.target, C.PROF_KEY_NONE)
-        libervia_widget.LiberviaWidget.__init__(self, host, ", ".join(accepted_groups), selectable=True)
+        # do not mix self.targets (set of tuple of unicode) and self.accepted_groups (set of unicode)
+        quick_widgets.QuickWidget.__init__(self, host, targets, C.PROF_KEY_NONE)
+        libervia_widget.LiberviaWidget.__init__(self, host, ", ".join(self.accepted_groups), selectable=True)
         self.entries = {}
         self.comments = {}
         self.selected_entry = None
@@ -380,11 +381,7 @@
         host.addListener('avatar', self.avatarListener, [C.PROF_KEY_NONE])
 
     def __str__(self):
-        return u"Blog Widget [target: {}, profile: {}]".format(self.target, self.profile)
-
-    @property
-    def target(self):
-        return tuple(self.accepted_groups)
+        return u"Blog Widget [target: {}, profile: {}]".format(', '.join(self.accepted_groups), self.profile)
 
     def onDelete(self):
         quick_widgets.QuickWidget.onDelete(self)
@@ -454,17 +451,8 @@
 
     @property
     def accepted_groups(self):
-        return self._accepted_groups
-
-    def matchEntity(self, item):
-        """
-        @param item: single group as a string, list of groups
-        (as an array) or None (for the meta group = "all groups")
-        @return: True if self matches the given entity
-        """
-        groups = item if isinstance(item, list) else ([] if item is None else [item])
-        groups.sort()  # sort() do not return the sorted list: do it here, not on the "return" line
-        return self.accepted_groups == groups
+        """Return a set of the accepted groups"""
+        return set().union(*self.targets)
 
     def getWarningData(self, comment=None):
         """
@@ -478,13 +466,12 @@
             comment = self.selected_entry is not None
         if comment:
             return ("PUBLIC", "This is a <span class='warningTarget'>comment</span> and keep the initial post visibility, so it is potentialy public")
-        elif not self._accepted_groups:
+        elif not self.accepted_groups:
             # we have a meta MicroblogPanel, we publish publicly
             return ("PUBLIC", self.warning_msg_public)
         else:
-            # we only accept one group at the moment
             # FIXME: manage several groups
-            return ("GROUP", self.warning_msg_group % self._accepted_groups[0])
+            return ("GROUP", self.warning_msg_group % ' '.join(self.accepted_groups))
 
     def onTextEntered(self, text):
         if self.selected_entry:
@@ -493,17 +480,15 @@
             if not comments_url:
                 raise Exception("ERROR: the comments URL is empty")
             target = ("COMMENT", comments_url)
-        elif not self._accepted_groups:
+        elif not self.accepted_groups:
             # we are entering a public microblog
             target = ("PUBLIC", None)
         else:
-            # we are entering a microblog restricted to a group
-            # FIXME: manage several groups
-            target = ("GROUP", self._accepted_groups[0])
+            target = ("GROUP", self.accepted_groups)
         self.host.send([target], text)
 
     def accept_all(self):
-        return not self._accepted_groups  # we accept every microblog only if we are not filtering by groups
+        return not self.accepted_groups  # we accept every microblog only if we are not filtering by groups
 
     def getEntries(self):
         """Ask all the entries for the currenly accepted groups,
@@ -702,21 +687,13 @@
         if type_ == 'avatar':
             updateVPanel(self.vpanel)
 
-    def setAcceptedGroup(self, group):
+    def addAcceptedGroups(self, groups):
         """Add one or more group(s) which can be displayed in this panel.
 
-        Prevent from duplicate values and keep the list sorted.
-        @param group: string of the group, or list of string
+        @param groups (tuple(unicode)): tuple of groups to add
         """
-        if isinstance(group, basestring):
-            groups = [group]
-        else:
-            groups = list(group)
-        try:
-            self._accepted_groups.extend(groups)
-        except (AttributeError, TypeError): # XXX: should be AttributeError, but pyjamas bugs here
-            self._accepted_groups = groups
-        self._accepted_groups.sort()
+        # FIXME: update the widget's hash in QuickApp._widgets[MicroblogPanel]
+        self.targets.update(groups)
 
     def isJidAccepted(self, jid_):
         """Tell if a jid is actepted and must be shown in this panel
@@ -727,7 +704,7 @@
         assert isinstance(jid_, jid.JID) # FIXME temporary
         if self.accept_all():
             return True
-        for group in self._accepted_groups:
+        for group in self.accepted_groups:
             if self.host.contact_lists[self.profile].isEntityInGroup(jid_, group):
                 return True
         return False
--- a/src/browser/sat_browser/chat.py	Fri Feb 27 01:08:36 2015 +0100
+++ b/src/browser/sat_browser/chat.py	Fri Feb 27 01:11:34 2015 +0100
@@ -165,20 +165,6 @@
         else:
             self.host.showWarning(*self.getWarningData())
 
-    def matchEntity(self, item, type_=None):
-        """
-        @param entity: target jid as a string or jid.JID instance.
-        @return: True if self matches the given entity
-        """
-        if type_ is None:
-            type_ = self.type
-        entity = item if isinstance(item, jid.JID) else jid.JID(item)
-        try:
-            return self.target.bare == entity.bare and self.type == type_
-        except AttributeError as e:
-            e.include_traceback()
-            return False
-
     def addMenus(self, menu_bar):
         """Add cached menus to the header.
 
--- a/src/browser/sat_browser/libervia_widget.py	Fri Feb 27 01:08:36 2015 +0100
+++ b/src/browser/sat_browser/libervia_widget.py	Fri Feb 27 01:11:34 2015 +0100
@@ -563,13 +563,6 @@
         # the event will not propagate to children
         VerticalPanel.doAttachChildren(self)
 
-    def matchEntity(self, item):
-        """Check if this widget corresponds to the given entity.
-
-        This method should be overwritten by child classes.
-        @return: True if the widget matches the entity"""
-        raise NotImplementedError
-
     def addMenus(self, menu_bar):
         """Add menus to the header.