Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits: 23b50cc6 by lovetox at 2021-02-05T22:00:17+01:00 Unread count improv
- - - - - b5fcbd49 by lovetox at 2021-02-05T22:04:05+01:00 Add unread count to workspace
- - - - -
4 changed files:
- gajim/gtk/chat_list.py - gajim/gtk/chat_list_stack.py - gajim/gtk/main.py - gajim/gtk/workspace_side_bar.py
Changes:
===================================== gajim/gtk/chat_list.py ===================================== @@ -37,10 +37,19 @@ def __init__(self, workspace_id):
self.show_all()
+ def get_unread_count(self): + return sum([chats.unread_count for chats in self._chats.values()]) + + def emit_unread_changed(self): + count = self.get_unread_count() + self.get_parent().emit('unread-count-changed', + self._workspace_id, + count) + def is_visible(self): return self.get_parent().get_property('child-widget') == self
- def _on_destroy(self): + def _on_destroy(self, *args): GLib.source_remove(self._timer_id)
def _update_timer(self): @@ -220,6 +229,16 @@ def __init__(self, workspace_id, account, jid, type_):
self.show_all()
+ @property + def unread_count(self): + return self._unread_count + + @unread_count.setter + def unread_count(self, value): + self._unread_count = value + self._update_unread() + self.get_parent().emit_unread_changed() + @property def is_active(self): return (self.is_selected() and @@ -241,23 +260,19 @@ def update_time(self): get_uf_relative_time(self._timestamp))
def _update_unread(self): - print('Update unread', self.account, self.jid, self._unread_count) if self._unread_count < 1000: self._ui.unread_label.set_text(str(self._unread_count)) else: self._ui.unread_label.set_text('999+') - self._ui.unread_label.set_text(str(self._unread_count)) self._ui.unread_label.set_visible(bool(self._unread_count))
def add_unread(self): if self.is_active: return - self._unread_count += 1 - self._update_unread() + self.unread_count += 1
def reset_unread(self): - self._unread_count = 0 - self._update_unread() + self.unread_count = 0
def set_last_message_text(self, nickname, text): self._ui.message_label.set_text(text)
===================================== gajim/gtk/chat_list_stack.py ===================================== @@ -1,5 +1,6 @@
from gi.repository import Gtk +from gi.repository import GObject
from gajim.common import app
@@ -14,6 +15,13 @@
class ChatListStack(Gtk.Stack): + + __gsignals__ = { + 'unread-count-changed': (GObject.SignalFlags.RUN_LAST, + None, + (str, int)), + } + def __init__(self, main_window, ui, chat_stack): Gtk.Stack.__init__(self) self.set_hexpand(True)
===================================== gajim/gtk/main.py ===================================== @@ -49,7 +49,7 @@ def __init__(self): self._ui.chat_list_scrolled.add(self._chat_list_stack)
self._account_side_bar = AccountSideBar() - self._workspace_side_bar = WorkspaceSideBar() + self._workspace_side_bar = WorkspaceSideBar(self._chat_list_stack)
surface = load_icon('org.gajim.Gajim', self, 40) self._ui.app_image.set_from_surface(surface) @@ -107,7 +107,6 @@ def __init__(self): ('muc-configuration-finished', ged.GUI1, self._on_event), ('muc-configuration-failed', ged.GUI1, self._on_event), ('update-room-avatar', ged.GUI1, self._on_event), - ('message-sent', ged.OUT_POSTCORE, self._on_event), ('message-error', ged.GUI1, self._on_event), ])
===================================== gajim/gtk/workspace_side_bar.py ===================================== @@ -10,7 +10,7 @@
class WorkspaceSideBar(Gtk.ListBox): - def __init__(self): + def __init__(self, chat_list_stack): Gtk.ListBox.__init__(self) self.set_vexpand(True) self.set_valign(Gtk.Align.START) @@ -20,8 +20,14 @@ def __init__(self): self.connect('button-press-event', self._on_button_press) self.connect('row-activated', self._on_row_activated)
+ chat_list_stack.connect('unread-count-changed', + self._on_unread_count_changed) self._workspaces = {}
+ def _on_unread_count_changed(self, _chat_list_stack, workspace_id, count): + workspace = self._workspaces[workspace_id] + workspace.set_unread_count(count) + @staticmethod def _sort_func(child1, child2): if child1.sort_index < child2.sort_index: @@ -92,7 +98,6 @@ def __init__(self, workspace_id): CommonWorkspace.__init__(self, workspace_id)
self.sort_index = 0 - self._unread_count = 0
self._unread_label = Gtk.Label() self._unread_label.get_style_context().add_class( @@ -111,31 +116,15 @@ def __init__(self, workspace_id): self.add(overlay) self.show_all()
- @property - def is_active(self): - return (self.is_selected() and - self.get_toplevel().get_property('is-active')) - def update_avatar(self): self._image.update()
- def _update_unread(self): - print('Update unread', self.workspace_id, self._unread_count) - if self._unread_count < 1000: - self._unread_label.set_text(str(self._unread_count)) + def set_unread_count(self, count): + if count < 1000: + self._unread_label.set_text(str(count)) else: self._unread_label.set_text('999+') - self._unread_label.set_visible(bool(self._unread_count)) - - def add_unread(self): - if self.is_active: - return - self._unread_count += 1 - self._update_unread() - - def reset_unread(self): - self._unread_count = 0 - self._update_unread() + self._unread_label.set_visible(bool(count))
class AddWorkspace(CommonWorkspace):
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/5731c0ec3ce72b820e4deaa99d977323...