# HG changeset patch # User Goffi # Date 1581020181 -3600 # Node ID c04c3b167cb0f0e80c6a3fb0c9c4480418a2373a # Parent d15828ca9d86f083d96c1920a3fd1b5b40a320de chat: use header input to filter entities + open a new chat with unknown jid. diff -r d15828ca9d86 -r c04c3b167cb0 cagou/plugins/plugin_wid_chat.py --- a/cagou/plugins/plugin_wid_chat.py Thu Feb 06 21:16:21 2020 +0100 +++ b/cagou/plugins/plugin_wid_chat.py Thu Feb 06 21:16:21 2020 +0100 @@ -43,7 +43,9 @@ from cagou.core import xmlui from cagou.core.image import Image from cagou.core.common import SymbolButton, JidButton +from cagou.core.utils import FilterBehavior from cagou.core import menu +from cagou.core.common import ContactButton log = logging.getLogger(__name__) @@ -896,10 +898,11 @@ ) -class ChatSelector(cagou_widget.CagouWidget): +class ChatSelector(cagou_widget.CagouWidget, FilterBehavior): jid_selector = properties.ObjectProperty() profile = properties.StringProperty() plugin_info_class = Chat + use_header_input = True def on_pre_enter(self, screen): self.jid_selector.update() @@ -921,5 +924,28 @@ self, factory(plugin_info, contact_jid, profiles=[self.profile])) + def onHeaderInput(self): + text = self.header_input.text.strip() + try: + if text.count('@') != 1 or text.count(' '): + raise ValueError + jid_ = jid.JID(text) + except ValueError: + log.info("entered text is not a jid") + return + G.host.doAction("chat", jid_, [self.profile]) + + def onHeaderInputComplete(self, wid, text, **kwargs): + """we filter items when text is entered in input box""" + self.do_filter( + self.jid_selector.children[0].children, + text, + # we append nick to jid to filter on both + lambda c: c.jid + c.data.get('nick', ''), + width_cb=lambda c: c.base_width, + height_cb=lambda c: c.minimum_height, + continue_tests=[lambda c: not isinstance(c, ContactButton)]) + + PLUGIN_INFO["factory"] = Chat.factory quick_widgets.register(quick_chat.QuickChat, Chat)