Philipp Hörist pushed to branch master at gajim / gajim
Commits: e05cb4b8 by wurstsalat at 2022-05-10T09:47:18+02:00 feat: Windows: Use avatar for incoming message notification - - - - - 2 changed files: - gajim/data/gui/popup_notification_window.ui - gajim/gtk/notification.py Changes: ===================================== gajim/data/gui/popup_notification_window.ui ===================================== @@ -32,6 +32,10 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="icon_size">6</property> + <property name="margin-start">6</property> + <property name="margin-end">6</property> + <property name="margin-top">12</property> + <property name="valign">start</property> </object> <packing> <property name="expand">False</property> ===================================== gajim/gtk/notification.py ===================================== @@ -176,8 +176,15 @@ def __init__(self, event: events.Notification, timeout: int) -> None: self.add(self._ui.eventbox) self._add_background_color(event) - icon_name = self._get_icon_name(event) - self._ui.image.set_from_icon_name(icon_name, Gtk.IconSize.DIALOG) + + if event.type == 'incoming-message': + assert event.jid is not None + pixbuf = _get_avatar_for_notification( + event.account, event.jid) + self._ui.image.set_from_pixbuf(pixbuf) + else: + icon_name = self._get_icon_name(event) + self._ui.image.set_from_icon_name(icon_name, Gtk.IconSize.DIALOG) self._ui.event_type_label.set_text(event.title) self._ui.event_description_label.set_text(event.text) @@ -191,11 +198,12 @@ def __init__(self, event: events.Notification, timeout: int) -> None: self.connect('destroy', self._on_destroy) self.show_all() - def _get_icon_name(self, event: events.Notification) -> str: + @staticmethod + def _get_icon_name(event: events.Notification) -> str: if event.icon_name is not None: return event.icon_name icon_name = event.sub_type or event.type - return NOTIFICATION_ICONS.get(icon_name, 'mail-unread') + return NOTIFICATION_ICONS.get(icon_name, 'gajim-chat_msg_recv') def _add_background_color(self, event: events.Notification) -> None: event_type = event.sub_type or event.type @@ -368,22 +376,10 @@ def _make_notification_id(self, return None - @staticmethod - def _get_avatar_for_notification(account: str, - jid: Union[JID, str]) -> GdkPixbuf.Pixbuf: - scale = get_monitor_scale_factor() - size = AvatarSize.NOTIFICATION - client = app.get_client(account) - contact = client.get_module('Contacts').get_contact(jid) - avatar_surface = contact.get_avatar(size, scale) - pixbuf = Gdk.pixbuf_get_from_surface(avatar_surface, 0, 0, size, size) - assert pixbuf is not None - return pixbuf - def _make_icon(self, event: events.Notification) -> Gio.Icon: if (event.type == 'incoming-message' and app.desktop_env == 'gnome'): assert event.jid is not None - return self._get_avatar_for_notification(event.account, event.jid) + return _get_avatar_for_notification(event.account, event.jid) if event.icon_name is not None: return Gio.ThemedIcon.new(event.icon_name) @@ -405,6 +401,18 @@ def _make_id(details: list[Any]) -> str: return ','.join(map(str, details)) +def _get_avatar_for_notification(account: str, + jid: Union[JID, str]) -> GdkPixbuf.Pixbuf: + scale = get_monitor_scale_factor() + size = AvatarSize.NOTIFICATION + client = app.get_client(account) + contact = client.get_module('Contacts').get_contact(jid) + avatar_surface = contact.get_avatar(size, scale) + pixbuf = Gdk.pixbuf_get_from_surface(avatar_surface, 0, 0, size, size) + assert pixbuf is not None + return pixbuf + + def get_notification_backend() -> NotificationBackend: if sys.platform == 'win32': return Windows() View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/e05cb4b81975c2b09e6d73eb063e23e9e84d0737 -- View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/e05cb4b81975c2b09e6d73eb063e23e9e84d0737 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