comparison src/browser/sat_browser/panels.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 e1a773a64fb6
comparison
equal deleted inserted replaced
573:12823bcbd05b 574:b07f0fe2763a
745 745
746 @property 746 @property
747 def accepted_groups(self): 747 def accepted_groups(self):
748 return self._accepted_groups 748 return self._accepted_groups
749 749
750 def matchEntity(self, entity): 750 def matchEntity(self, item):
751 """ 751 """
752 @param entity: single group as a string, list of groups 752 @param item: single group as a string, list of groups
753 (as an array) or None (for the meta group = "all groups") 753 (as an array) or None (for the meta group = "all groups")
754 @return: True if self matches the given entity 754 @return: True if self matches the given entity
755 """ 755 """
756 entity = entity if isinstance(entity, list) else ([] if entity is None else [entity]) 756 groups = item if isinstance(item, list) else ([] if item is None else [item])
757 entity.sort() # sort() do not return the sorted list: do it here, not on the "return" line 757 groups.sort() # sort() do not return the sorted list: do it here, not on the "return" line
758 return self.accepted_groups == entity 758 return self.accepted_groups == groups
759 759
760 def getWarningData(self, comment=None): 760 def getWarningData(self, comment=None):
761 """ 761 """
762 @param comment: True if the composed message is a comment. If None, consider we are 762 @param comment: True if the composed message is a comment. If None, consider we are
763 composing from the unibox and guess the message type from self.selected_entry 763 composing from the unibox and guess the message type from self.selected_entry
1149 @classmethod 1149 @classmethod
1150 def registerClass(cls): 1150 def registerClass(cls):
1151 base_widget.LiberviaWidget.addDropKey("CONTACT", cls.createPanel) 1151 base_widget.LiberviaWidget.addDropKey("CONTACT", cls.createPanel)
1152 1152
1153 @classmethod 1153 @classmethod
1154 def createPanel(cls, host, item): 1154 def createPanel(cls, host, item, type_='one2one'):
1155 assert(item)
1155 _contact = item if isinstance(item, jid.JID) else jid.JID(item) 1156 _contact = item if isinstance(item, jid.JID) else jid.JID(item)
1156 host.contact_panel.setContactMessageWaiting(_contact.bare, False) 1157 host.contact_panel.setContactMessageWaiting(_contact.bare, False)
1157 _new_panel = ChatPanel(host, _contact) # XXX: pyjamas doesn't seems to support creating with cls directly 1158 _new_panel = ChatPanel(host, _contact, type_) # XXX: pyjamas doesn't seems to support creating with cls directly
1158 _new_panel.historyPrint() 1159 _new_panel.historyPrint()
1159 host.setSelected(_new_panel) 1160 host.setSelected(_new_panel)
1160 _new_panel.refresh() 1161 _new_panel.refresh()
1161 return _new_panel 1162 return _new_panel
1162 1163
1180 if keycode == KEY_ENTER: 1181 if keycode == KEY_ENTER:
1181 self.host.showWarning(None, None) 1182 self.host.showWarning(None, None)
1182 else: 1183 else:
1183 self.host.showWarning(*self.getWarningData()) 1184 self.host.showWarning(*self.getWarningData())
1184 1185
1185 def matchEntity(self, entity): 1186 def matchEntity(self, item, type_=None):
1186 """ 1187 """
1187 @param entity: target jid as a string or jid.JID instance. 1188 @param entity: target jid as a string or jid.JID instance.
1188 Could also be a couple with a type in the second element. 1189 Could also be a couple with a type in the second element.
1189 @return: True if self matches the given entity 1190 @return: True if self matches the given entity
1190 """ 1191 """
1191 if isinstance(entity, tuple): 1192 if type_ is None:
1192 entity, type_ = entity if len(entity) > 1 else (entity[0], self.type)
1193 else:
1194 type_ = self.type 1193 type_ = self.type
1195 entity = entity if isinstance(entity, jid.JID) else jid.JID(entity) 1194 entity = item if isinstance(item, jid.JID) else jid.JID(item)
1196 try: 1195 try:
1197 return self.target.bare == entity.bare and self.type == type_ 1196 return self.target.bare == entity.bare and self.type == type_
1198 except AttributeError as e: 1197 except AttributeError as e:
1199 e.include_traceback() 1198 e.include_traceback()
1200 return False 1199 return False