Daniel Brötzmann pushed to branch mainwindow at gajim / gajim


Commits:
5731c0ec by wurstsalat at 2021-02-05T21:25:02+01:00
WorkspaceSidebar: Add unread counter

- - - - -


3 changed files:

- gajim/data/style/gajim.css
- gajim/gtk/chat_list.py
- gajim/gtk/workspace_side_bar.py


Changes:

=====================================
gajim/data/style/gajim.css
=====================================
@@ -61,11 +61,11 @@
 /* Workspace sidebar */
 .workspace-sidebar {
        background: transparent;
-    margin-left: 12px;
-    margin-right: 12px;
+       margin-left: 12px;
+       margin-right: 6px;
 }
 .workspace-sidebar-item {
-    padding-top: 6px;
+       padding-top: 0px;
        padding-bottom: 6px;
 }
 .workspace-sidebar-item:selected,
@@ -80,6 +80,8 @@
 }
 .workspace-sidebar-item image {
        border-radius: 9px;
+       margin-top: 6px;
+       margin-right: 6px;
 }
 
 /* Account sidebar */


=====================================
gajim/gtk/chat_list.py
=====================================
@@ -242,6 +242,10 @@ def update_time(self):
 
     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))
 


=====================================
gajim/gtk/workspace_side_bar.py
=====================================
@@ -92,15 +92,51 @@ 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(
+            'unread-counter')
+        self._unread_label.set_no_show_all(True)
+        self._unread_label.set_halign(Gtk.Align.END)
+        self._unread_label.set_valign(Gtk.Align.START)
 
         self._image = WorkspaceAvatar(workspace_id)
         self._image.set_halign(Gtk.Align.CENTER)
-        self.add(self._image)
+
+        overlay = Gtk.Overlay()
+        overlay.add(self._image)
+        overlay.add_overlay(self._unread_label)
+
+        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))
+        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()
+
 
 class AddWorkspace(CommonWorkspace):
     def __init__(self, workspace_id):



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/5731c0ec3ce72b820e4deaa99d977323d99b26b7

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/5731c0ec3ce72b820e4deaa99d977323d99b26b7
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
Commits@gajim.org
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to