Mercurial > libervia-web
comparison src/browser/libervia_main.py @ 574:b07f0fe2763a
browser_side: safer attributes handling in getOrCreateLiberviaWidget + use it to create MUC panels
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 18 Oct 2014 13:16:56 +0200 |
parents | 12823bcbd05b |
children | daa9be94e88f |
comparison
equal
deleted
inserted
replaced
573:12823bcbd05b | 574:b07f0fe2763a |
---|---|
663 if lib_wid.isJidAccepted(entity): | 663 if lib_wid.isJidAccepted(entity): |
664 self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'JID', [entity], 10) | 664 self.bridge.call('getMassiveLastMblogs', lib_wid.massiveInsert, 'JID', [entity], 10) |
665 | 665 |
666 def getLiberviaWidget(self, class_, entity, ignoreOtherTabs=True): | 666 def getLiberviaWidget(self, class_, entity, ignoreOtherTabs=True): |
667 """Get the corresponding panel if it exists. | 667 """Get the corresponding panel if it exists. |
668 @param class_: class of the panel (ChatPanel, MicroblogPanel...) | 668 @param class_ (class): class of the panel (ChatPanel, MicroblogPanel...) |
669 @param entity: polymorphic parameter, see class_.matchEntity. | 669 @param entity (dict): dictionnary to define the entity. |
670 @param ignoreOtherTabs: if True, the widgets that are not | 670 @param ignoreOtherTabs (bool): if True, the widgets that are not |
671 contained by the currently selected tab will be ignored | 671 contained by the currently selected tab will be ignored |
672 @return: the existing widget that has been found or None.""" | 672 @return: the existing widget that has been found or None.""" |
673 selected_tab = self.tab_panel.getCurrentPanel() | 673 selected_tab = self.tab_panel.getCurrentPanel() |
674 for lib_wid in self.libervia_widgets: | 674 for lib_wid in self.libervia_widgets: |
675 parent = lib_wid.getWidgetsPanel(expect=False) | 675 parent = lib_wid.getWidgetsPanel(expect=False) |
676 if parent is None or (ignoreOtherTabs and parent != selected_tab): | 676 if parent is None or (ignoreOtherTabs and parent != selected_tab): |
677 # do not return a widget that is not in the currently selected tab | 677 # do not return a widget that is not in the currently selected tab |
678 continue | 678 continue |
679 if isinstance(lib_wid, class_): | 679 if isinstance(lib_wid, class_): |
680 try: | 680 try: |
681 if lib_wid.matchEntity(entity): | 681 if lib_wid.matchEntity(*(entity.values())): # XXX: passing **entity bugs! |
682 log.debug("existing widget found: %s" % lib_wid.getDebugName()) | 682 log.debug("existing widget found: %s" % lib_wid.getDebugName()) |
683 return lib_wid | 683 return lib_wid |
684 except AttributeError as e: | 684 except AttributeError as e: |
685 e.stack_list() | 685 e.stack_list() |
686 return None | 686 return None |
687 return None | 687 return None |
688 | 688 |
689 def getOrCreateLiberviaWidget(self, class_, entity, select=True, new_tab=None): | 689 def getOrCreateLiberviaWidget(self, class_, entity, select=True, new_tab=None): |
690 """Get the matching LiberviaWidget if it exists, or create a new one. | 690 """Get the matching LiberviaWidget if it exists, or create a new one. |
691 @param class_: class of the panel (ChatPanel, MicroblogPanel...) | 691 @param class_ (class): class of the panel (ChatPanel, MicroblogPanel...) |
692 @param entity: polymorphic parameter, see class_.matchEntity. | 692 @param entity (dict): dictionnary to define the entity. |
693 @param select: if True, select the widget that has been found or created | 693 @param select (bool): if True, select the widget that has been found or created |
694 @param new_tab: if not None, a widget which is created is created in | 694 @param new_tab (str): if not None, a widget which is created is created in |
695 a new tab. In that case new_tab is a unicode to label that new tab. | 695 a new tab. In that case new_tab is a unicode to label that new tab. |
696 If new_tab is not None and a widget is found, no tab is created. | 696 If new_tab is not None and a widget is found, no tab is created. |
697 @return: the newly created wigdet if REUSE_EXISTING_LIBERVIA_WIDGETS | 697 @return: the newly created wigdet if REUSE_EXISTING_LIBERVIA_WIDGETS |
698 is set to False or if the widget has not been found, the existing | 698 is set to False or if the widget has not been found, the existing |
699 widget that has been found otherwise.""" | 699 widget that has been found otherwise.""" |
700 lib_wid = None | 700 lib_wid = None |
701 tab = None | 701 tab = None |
702 if REUSE_EXISTING_LIBERVIA_WIDGETS: | 702 if REUSE_EXISTING_LIBERVIA_WIDGETS: |
703 lib_wid = self.getLiberviaWidget(class_, entity, new_tab is None) | 703 lib_wid = self.getLiberviaWidget(class_, entity, new_tab is None) |
704 if lib_wid is None: # create a new widget | 704 if lib_wid is None: # create a new widget |
705 lib_wid = class_.createPanel(self, entity[0] if isinstance(entity, tuple) else entity) | 705 lib_wid = class_.createPanel(self, *(entity.values())) # XXX: passing **entity bugs! |
706 if new_tab is None: | 706 if new_tab is None: |
707 self.addWidget(lib_wid) | 707 self.addWidget(lib_wid) |
708 else: | 708 else: |
709 tab = self.addTab(new_tab, lib_wid, False) | 709 tab = self.addTab(new_tab, lib_wid, False) |
710 else: # reuse existing widget | 710 else: # reuse existing widget |
731 return # plugin returned False to interrupt the process | 731 return # plugin returned False to interrupt the process |
732 self.newMessageCb(from_jid, msg, msg_type, to_jid, extra) | 732 self.newMessageCb(from_jid, msg, msg_type, to_jid, extra) |
733 | 733 |
734 def newMessageCb(self, from_jid, msg, msg_type, to_jid, extra): | 734 def newMessageCb(self, from_jid, msg, msg_type, to_jid, extra): |
735 other = to_jid if from_jid.bare == self.whoami.bare else from_jid | 735 other = to_jid if from_jid.bare == self.whoami.bare else from_jid |
736 lib_wid = self.getLiberviaWidget(panels.ChatPanel, other, ignoreOtherTabs=False) | 736 lib_wid = self.getLiberviaWidget(panels.ChatPanel, {'item': other}, ignoreOtherTabs=False) |
737 self.displayNotification(from_jid, msg) | 737 self.displayNotification(from_jid, msg) |
738 if msg_type == 'headline' and from_jid.full() == self._defaultDomain: | 738 if msg_type == 'headline' and from_jid.full() == self._defaultDomain: |
739 try: | 739 try: |
740 assert extra['subject'] # subject is defined and not empty | 740 assert extra['subject'] # subject is defined and not empty |
741 title = extra['subject'] | 741 title = extra['subject'] |
765 self.status_panel.setPresence(show) # pylint: disable=E1103 | 765 self.status_panel.setPresence(show) # pylint: disable=E1103 |
766 if statuses: | 766 if statuses: |
767 self.status_panel.setStatus(statuses.values()[0]) # pylint: disable=E1103 | 767 self.status_panel.setStatus(statuses.values()[0]) # pylint: disable=E1103 |
768 else: | 768 else: |
769 if entity_jid.bare in self.room_list: | 769 if entity_jid.bare in self.room_list: |
770 wid = self.getLiberviaWidget(panels.ChatPanel, entity_jid.bare, ignoreOtherTabs=False) | 770 wid = self.getLiberviaWidget(panels.ChatPanel, {'item': entity_jid}, ignoreOtherTabs=False) |
771 else: | 771 else: |
772 wid = self.contact_panel | 772 wid = self.contact_panel |
773 if show == 'unavailable': # XXX: save some resources as for now we only need 'unavailable' | 773 if show == 'unavailable': # XXX: save some resources as for now we only need 'unavailable' |
774 for plugin in self.plugins.values(): | 774 for plugin in self.plugins.values(): |
775 if hasattr(plugin, 'presenceReceivedTrigger'): | 775 if hasattr(plugin, 'presenceReceivedTrigger'): |
784 # FIXME: pyjamas doesn't handle the properties well | 784 # FIXME: pyjamas doesn't handle the properties well |
785 node = _target.node | 785 node = _target.node |
786 | 786 |
787 if _target not in self.room_list: | 787 if _target not in self.room_list: |
788 self.room_list.append(_target) | 788 self.room_list.append(_target) |
789 chat_panel = panels.ChatPanel(self, _target, type_='group') | 789 |
790 # XXX: it's not really beautiful, but it works :) | |
791 if node.startswith('sat_tarot_'): | |
792 tab_name = "Tarot" | |
793 elif node.startswith('sat_radiocol_'): | |
794 tab_name = "Radio collective" | |
795 else: | |
796 tab_name = _target.node | |
797 | |
798 chat_panel = self.getOrCreateLiberviaWidget(panels.ChatPanel, {'item': _target, 'type_': 'group'}, new_tab=tab_name) | |
790 chat_panel.setUserNick(user_nick) | 799 chat_panel.setUserNick(user_nick) |
791 if node.startswith('sat_tarot_'): # XXX: it's not really beautiful, but it works :) | |
792 self.addTab("Tarot", chat_panel) | |
793 elif node.startswith('sat_radiocol_'): | |
794 self.addTab("Radio collective", chat_panel) | |
795 else: | |
796 self.addTab(_target.node, chat_panel) | |
797 chat_panel.setPresents(room_nicks) | 800 chat_panel.setPresents(room_nicks) |
798 chat_panel.historyPrint() | 801 chat_panel.historyPrint() |
799 chat_panel.refresh() | 802 chat_panel.refresh() |
800 | 803 |
801 def _roomLeftCb(self, room_jid, room_nicks, user_nick): | 804 def _roomLeftCb(self, room_jid, room_nicks, user_nick): |