changeset 394:d15828ca9d86

chat: use the new "implicit_update" and "to_show" properties for ChatSelector.jid_selector: - "implicit_update" is used to avoid double update on init - "to_show" is used to show opened chats, roster and bookmarks - update jid_selector when pre_entering the chat selector
author Goffi <goffi@goffi.org>
date Thu, 06 Feb 2020 21:16:21 +0100
parents e2f806779b53
children c04c3b167cb0
files cagou/plugins/plugin_wid_chat.kv cagou/plugins/plugin_wid_chat.py
diffstat 2 files changed, 27 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/plugins/plugin_wid_chat.kv	Thu Feb 06 21:16:21 2020 +0100
+++ b/cagou/plugins/plugin_wid_chat.kv	Thu Feb 06 21:16:21 2020 +0100
@@ -20,13 +20,7 @@
 #:import SimpleXHTMLWidget cagou.core.simple_xhtml.SimpleXHTMLWidget
 #:import DelayedBoxLayout cagou.core.common_widgets.DelayedBoxLayout
 #:import ScrollEffect kivy.effects.scroll.ScrollEffect
-
-
-# Chat Selector
-
-<ChatSelector>:
-    JidSelector:
-        on_select: root.on_select(args[1])
+#:import CategorySeparator cagou.core.common_widgets.CategorySeparator
 
 
 # Chat
@@ -219,3 +213,24 @@
         Rectangle:
             pos: self.pos
             size: self.size
+
+
+# Chat Selector
+
+<ChatSelector>:
+    jid_selector: jid_selector
+    JidSelector:
+        id: jid_selector
+        # we call update() explicitly in on_pre_enter
+        implicit_update: False
+        on_select: root.on_select(args[1])
+        to_show:
+            [
+            CategorySeparator(text=_("Opened chats")),
+            "opened_chats",
+            CategorySeparator(text=_("Your contacts")),
+            "roster",
+            CategorySeparator(text=_("Your chat rooms")),
+            "bookmarks",
+            ]
+
--- 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
@@ -432,6 +432,7 @@
         sel_screen = Screen(name='chat_selector')
         chat_selector = ChatSelector(profile=self.profile)
         sel_screen.add_widget(chat_selector)
+        sel_screen.bind(on_pre_enter=chat_selector.on_pre_enter)
         screen_manager.add_widget(sel_screen)
         if self.show_chat_selector:
             transition = screen_manager.transition
@@ -896,9 +897,13 @@
 
 
 class ChatSelector(cagou_widget.CagouWidget):
+    jid_selector = properties.ObjectProperty()
     profile = properties.StringProperty()
     plugin_info_class = Chat
 
+    def on_pre_enter(self, screen):
+        self.jid_selector.update()
+
     def on_select(self, contact_button):
         contact_jid = jid.JID(contact_button.jid)
         plugin_info = G.host.getPluginInfo(main=Chat)