comparison cagou/plugins/plugin_wid_chat.py @ 395:c04c3b167cb0

chat: use header input to filter entities + open a new chat with unknown jid.
author Goffi <goffi@goffi.org>
date Thu, 06 Feb 2020 21:16:21 +0100
parents d15828ca9d86
children ae6f7fd1cb0e
comparison
equal deleted inserted replaced
394:d15828ca9d86 395:c04c3b167cb0
41 from cagou.core.constants import Const as C 41 from cagou.core.constants import Const as C
42 from cagou.core import cagou_widget 42 from cagou.core import cagou_widget
43 from cagou.core import xmlui 43 from cagou.core import xmlui
44 from cagou.core.image import Image 44 from cagou.core.image import Image
45 from cagou.core.common import SymbolButton, JidButton 45 from cagou.core.common import SymbolButton, JidButton
46 from cagou.core.utils import FilterBehavior
46 from cagou.core import menu 47 from cagou.core import menu
48 from cagou.core.common import ContactButton
47 49
48 log = logging.getLogger(__name__) 50 log = logging.getLogger(__name__)
49 51
50 PLUGIN_INFO = { 52 PLUGIN_INFO = {
51 "name": _("chat"), 53 "name": _("chat"),
894 callback=self._backHistoryGetCb, 896 callback=self._backHistoryGetCb,
895 errback=self._backHistoryGetEb, 897 errback=self._backHistoryGetEb,
896 ) 898 )
897 899
898 900
899 class ChatSelector(cagou_widget.CagouWidget): 901 class ChatSelector(cagou_widget.CagouWidget, FilterBehavior):
900 jid_selector = properties.ObjectProperty() 902 jid_selector = properties.ObjectProperty()
901 profile = properties.StringProperty() 903 profile = properties.StringProperty()
902 plugin_info_class = Chat 904 plugin_info_class = Chat
905 use_header_input = True
903 906
904 def on_pre_enter(self, screen): 907 def on_pre_enter(self, screen):
905 self.jid_selector.update() 908 self.jid_selector.update()
906 909
907 def on_select(self, contact_button): 910 def on_select(self, contact_button):
919 else: 922 else:
920 G.host.switchWidget( 923 G.host.switchWidget(
921 self, factory(plugin_info, contact_jid, profiles=[self.profile])) 924 self, factory(plugin_info, contact_jid, profiles=[self.profile]))
922 925
923 926
927 def onHeaderInput(self):
928 text = self.header_input.text.strip()
929 try:
930 if text.count('@') != 1 or text.count(' '):
931 raise ValueError
932 jid_ = jid.JID(text)
933 except ValueError:
934 log.info("entered text is not a jid")
935 return
936 G.host.doAction("chat", jid_, [self.profile])
937
938 def onHeaderInputComplete(self, wid, text, **kwargs):
939 """we filter items when text is entered in input box"""
940 self.do_filter(
941 self.jid_selector.children[0].children,
942 text,
943 # we append nick to jid to filter on both
944 lambda c: c.jid + c.data.get('nick', ''),
945 width_cb=lambda c: c.base_width,
946 height_cb=lambda c: c.minimum_height,
947 continue_tests=[lambda c: not isinstance(c, ContactButton)])
948
949
924 PLUGIN_INFO["factory"] = Chat.factory 950 PLUGIN_INFO["factory"] = Chat.factory
925 quick_widgets.register(quick_chat.QuickChat, Chat) 951 quick_widgets.register(quick_chat.QuickChat, Chat)