# HG changeset patch # User Goffi # Date 1581534178 -3600 # Node ID 03554ad70846081333df490ff158c086b8c7b612 # Parent 84ff5c9170646072f9ffaa76b836b6f033b57bda common (jidSelector): replace implitict_update mechanism by real-time update: instead of having the possibility to (de)activate implicit update, real time update of items is now done. For now only the notifications and opened chat items are updated in real time. diff -r 84ff5c917064 -r 03554ad70846 cagou/core/common.py --- a/cagou/core/common.py Wed Feb 12 20:02:58 2020 +0100 +++ b/cagou/core/common.py Wed Feb 12 20:02:58 2020 +0100 @@ -211,9 +211,9 @@ # common_widgets.CategorySeparator) # - a callable, which must return an iterable of kwargs for ContactButton to_show = properties.ListProperty(['roster']) - # if True, update() is called automatically when widget is created - # if False, you'll have to call update() at least once manually - implicit_update = properties.ObjectProperty(True) + + # TODO: roster and bookmarks must be updated in real time, like for opened_chats + def __init__(self, **kwargs): self.register_event_type('on_select') @@ -224,23 +224,63 @@ super().__init__(**kwargs) def on_kv_post(self, wid): - if self.implicit_update: - self.update() + self.update() def on_select(self, wid): pass def on_parent(self, wid, parent): if parent is None: - log.debug("removing contactsFilled listener") + log.debug("removing listeners") G.host.removeListener("contactsFilled", self.onContactsFilled) + G.host.removeListener("notification", self.onNotification) + G.host.removeListener("notificationsClear", self.onNotificationsClear) + G.host.removeListener( + "widgetNew", self.onWidgetNew, ignore_missing=True) + G.host.removeListener( + "widgetDeleted", self.onWidgetDeleted, ignore_missing=True) else: + log.debug("adding listeners") G.host.addListener("contactsFilled", self.onContactsFilled) + G.host.addListener("notification", self.onNotification) + G.host.addListener("notificationsClear", self.onNotificationsClear) def onContactsFilled(self, profile): log.debug("onContactsFilled event received") self.update() + def onNotification(self, entity, notification_data, profile): + for item in self.items_map.get(entity.bare, []): + notifs = list(G.host.getNotifs(entity.bare, profile=profile)) + item.badge_text = str(len(notifs)) + + def onNotificationsClear(self, entity, type_, profile): + for item in self.items_map.get(entity.bare, []): + item.badge_text = '' + + def onWidgetNew(self, wid): + if not isinstance(wid, quick_chat.QuickChat): + return + item = self.getItemFromWid(wid) + if item is None: + return + idx = 0 + for child in self.opened_chats.children: + if isinstance(child, self.item_class) and child < item: + break + idx+=1 + self.opened_chats.add_widget(item, index=idx) + + def onWidgetDeleted(self, wid): + if not isinstance(wid, quick_chat.QuickChat): + return + + for child in self.opened_chats.children: + if not isinstance(child, self.item_class): + continue + if child.jid.bare == wid.target.bare: + self.opened_chats.remove_widget(child) + break def _createItem(self, **kwargs): item = self.item_class(**kwargs) @@ -302,6 +342,8 @@ return item def addOpenedChatsItems(self): + G.host.addListener("widgetNew", self.onWidgetNew) + G.host.addListener("widgetDeleted", self.onWidgetDeleted) self.opened_chats = category_layout = self.addCategoryLayout(_("Opened chats")) widgets = sorted(G.host.widgets.getWidgets( quick_chat.QuickChat, diff -r 84ff5c917064 -r 03554ad70846 cagou/plugins/plugin_wid_chat.kv --- a/cagou/plugins/plugin_wid_chat.kv Wed Feb 12 20:02:58 2020 +0100 +++ b/cagou/plugins/plugin_wid_chat.kv Wed Feb 12 20:02:58 2020 +0100 @@ -221,8 +221,6 @@ 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: ["opened_chats", "roster", "bookmarks"] diff -r 84ff5c917064 -r 03554ad70846 cagou/plugins/plugin_wid_chat.py --- a/cagou/plugins/plugin_wid_chat.py Wed Feb 12 20:02:58 2020 +0100 +++ b/cagou/plugins/plugin_wid_chat.py Wed Feb 12 20:02:58 2020 +0100 @@ -434,7 +434,6 @@ 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 @@ -916,9 +915,6 @@ plugin_info_class = Chat use_header_input = True - 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)