changeset 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
files cagou/plugins/plugin_wid_chat.py
diffstat 1 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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)