From da14615c4cf2cb590586b8e34266870c05d9689f Mon Sep 17 00:00:00 2001
From: wurstsalat <mailtrash@posteo.de>
Date: Tue, 23 Mar 2021 23:01:46 +0100
Subject: [PATCH] NotificationManager: Improve display

---
 gajim/data/gui/account_page.ui    |  2 +-
 gajim/data/style/gajim.css        |  7 +++++++
 gajim/gtk/notification_manager.py | 32 ++++++++++++++++---------------
 3 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/gajim/data/gui/account_page.ui b/gajim/data/gui/account_page.ui
index 6742ebcc5e..81ef0d9546 100644
--- a/gajim/data/gui/account_page.ui
+++ b/gajim/data/gui/account_page.ui
@@ -120,7 +120,6 @@
       <object class="GtkBox" id="account_box">
         <property name="visible">True</property>
         <property name="can-focus">False</property>
-        <property name="halign">center</property>
         <property name="hexpand">True</property>
         <property name="orientation">vertical</property>
         <property name="spacing">18</property>
@@ -235,6 +234,7 @@
           <object class="GtkLabel">
             <property name="visible">True</property>
             <property name="can-focus">False</property>
+            <property name="margin-top">6</property>
             <property name="label" translatable="yes">Notifications</property>
             <style>
               <class name="bold16"/>
diff --git a/gajim/data/style/gajim.css b/gajim/data/style/gajim.css
index 1a71bc1b56..b7b8c4da0a 100644
--- a/gajim/data/style/gajim.css
+++ b/gajim/data/style/gajim.css
@@ -166,6 +166,13 @@ .account-page-box {
 .roster treeview {
 	padding: 0 3px;
 }
+/* Notification listbox */
+.notification-listbox {
+    background: transparent;
+}
+.notification-listbox row {
+    padding: 6px;
+}
 
 /*Middle Grid*/
 .middle-grid > scrolledwindow { background: transparent; }
diff --git a/gajim/gtk/notification_manager.py b/gajim/gtk/notification_manager.py
index 318ce28197..9e2173e727 100644
--- a/gajim/gtk/notification_manager.py
+++ b/gajim/gtk/notification_manager.py
@@ -18,6 +18,7 @@
 from gi.repository import Pango
 
 from gajim.common import app
+from gajim.common.const import AvatarSize
 from gajim.common.i18n import _
 
 from gajim.gui_menu_builder import get_subscription_menu
@@ -32,10 +33,12 @@ def __init__(self, account):
         self._account = account
         self._client = app.get_client(account)
 
-        self.set_size_request(400, 200)
+        self.set_vexpand(True)
 
         self._listbox = Gtk.ListBox()
         self._listbox.set_selection_mode(Gtk.SelectionMode.NONE)
+        self._listbox.set_halign(Gtk.Align.CENTER)
+        self._listbox.get_style_context().add_class('notification-listbox')
         self._set_placeholder()
 
         self.add(self._listbox)
@@ -165,7 +168,6 @@ def __init__(self, account, jid):
         self._account = account
         self._client = app.get_client(account)
         self.jid = jid
-        self.get_style_context().add_class('padding-6')
 
         self.grid = Gtk.Grid(column_spacing=12)
         self.add(self.grid)
@@ -179,15 +181,21 @@ def _generate_label():
         label.set_max_width_chars(30)
         return label
 
+    def _generate_avatar_image(self, jid):
+        contact = self._client.get_module('Contacts').get_contact(jid)
+        surface = contact.get_avatar(
+            AvatarSize.ROSTER, self.get_scale_factor(), add_show=False)
+        image = Gtk.Image.new_from_surface(surface)
+        image.set_valign(Gtk.Align.CENTER)
+        return image
+
 
 class SubscriptionRequestRow(NotificationRow):
     def __init__(self, account, jid, text, user_nick=None):
         NotificationRow.__init__(self, account, jid)
         self.type = 'subscribe'
 
-        image = Gtk.Image.new_from_icon_name(
-            'avatar-default-symbolic', Gtk.IconSize.DND)
-        image.set_valign(Gtk.Align.CENTER)
+        image = self._generate_avatar_image(jid)
         self.grid.attach(image, 1, 1, 1, 2)
 
         if user_nick is not None:
@@ -232,9 +240,7 @@ def __init__(self, account, jid):
         NotificationRow.__init__(self, account, jid)
         self.type = 'unsubscribed'
 
-        image = Gtk.Image.new_from_icon_name(
-            'avatar-default-symbolic', Gtk.IconSize.DND)
-        image.set_valign(Gtk.Align.CENTER)
+        image = self._generate_avatar_image(jid)
         self.grid.attach(image, 1, 1, 1, 2)
 
         contact = self._client.get_module('Contacts').get_contact(jid)
@@ -244,7 +250,7 @@ def __init__(self, account, jid):
         nick_label.set_markup(nick_markup)
         self.grid.attach(nick_label, 2, 1, 1, 1)
 
-        message_text = _('Stopped sharing their status')
+        message_text = _('Stopped sharing their status with you')
         text_label = self._generate_label()
         text_label.set_text(message_text)
         text_label.set_tooltip_text(message_text)
@@ -279,9 +285,7 @@ def __init__(self, account, event):
 
         self._event = event
 
-        image = Gtk.Image.new_from_icon_name(
-            'system-users-symbolic', Gtk.IconSize.DND)
-        image.set_valign(Gtk.Align.CENTER)
+        image = self._generate_avatar_image(event.from_)
         self.grid.attach(image, 1, 1, 1, 2)
 
         title_label = self._generate_label()
@@ -331,9 +335,7 @@ def __init__(self, account, event):
         NotificationRow.__init__(self, account, event.muc)
         self.type = 'invitation-declined'
 
-        image = Gtk.Image.new_from_icon_name(
-            'system-users-symbolic', Gtk.IconSize.DND)
-        image.set_valign(Gtk.Align.CENTER)
+        image = self._generate_avatar_image(event.from_)
         self.grid.attach(image, 1, 1, 1, 2)
 
         title_label = self._generate_label()
-- 
GitLab