[geary/mjog/notfication-avatars: 4/6] Plugin.DesktopNotifications: Display avatar in notifications if poss
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/notfication-avatars: 4/6] Plugin.DesktopNotifications: Display avatar in notifications if poss
- Date: Sat, 21 Mar 2020 22:01:14 +0000 (UTC)
commit b0e77dc717908face86c11708f2458d1fea7267d
Author: Michael Gratton <mike vee net>
Date: Thu Mar 12 10:19:15 2020 +1100
Plugin.DesktopNotifications: Display avatar in notifications if poss
.../desktop-notifications.vala | 35 +++++++++++++++++-----
1 file changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/src/client/plugin/desktop-notifications/desktop-notifications.vala
b/src/client/plugin/desktop-notifications/desktop-notifications.vala
index add646f7..25f2f689 100644
--- a/src/client/plugin/desktop-notifications/desktop-notifications.vala
+++ b/src/client/plugin/desktop-notifications/desktop-notifications.vala
@@ -85,6 +85,7 @@ public class Plugin.DesktopNotifications :
Email email
) throws GLib.Error {
string title = to_notitication_title(folder.account, total);
+ Gdk.Pixbuf? icon = null;
Geary.RFC822.MailboxAddress? originator = email.get_primary_originator();
if (originator != null) {
ContactStore contacts =
@@ -92,11 +93,26 @@ public class Plugin.DesktopNotifications :
global::Application.Contact? contact = yield contacts.load(
originator, this.cancellable
);
+
title = (
contact.is_trusted
? contact.display_name
: originator.to_short_display()
);
+
+ int window_scale = 1;
+ Gdk.Display? display = Gdk.Display.get_default();
+ if (display != null) {
+ Gdk.Monitor? monitor = display.get_primary_monitor();
+ if (monitor != null) {
+ window_scale = monitor.scale_factor;
+ }
+ }
+ icon = yield contact.load_avatar(
+ originator,
+ global::Application.Client.AVATAR_SIZE_PIXELS * window_scale,
+ this.cancellable
+ );
}
string body = email.subject;
@@ -116,7 +132,7 @@ public class Plugin.DesktopNotifications :
);
}
- issue_arrived_notification(title, body, folder, email.identifier);
+ issue_arrived_notification(title, body, icon, folder, email.identifier);
}
private void notify_general(Folder folder, int total, int added) {
@@ -142,11 +158,12 @@ public class Plugin.DesktopNotifications :
).printf(body, total);
}
- issue_arrived_notification(title, body, folder, null);
+ issue_arrived_notification(title, body, null, folder, null);
}
private void issue_arrived_notification(string summary,
string body,
+ Gdk.Pixbuf? icon,
Folder folder,
EmailIdentifier? id) {
// only one outstanding notification at a time
@@ -168,6 +185,7 @@ public class Plugin.DesktopNotifications :
ARRIVED_ID,
summary,
body,
+ icon,
Action.Application.prefix(action),
new GLib.Variant.tuple(target_param)
);
@@ -176,15 +194,18 @@ public class Plugin.DesktopNotifications :
private GLib.Notification issue_notification(string id,
string summary,
string body,
+ Gdk.Pixbuf? avatar,
string? action,
GLib.Variant? action_target) {
+ GLib.Icon icon = avatar;
+ if (avatar == null) {
+ icon = new GLib.ThemedIcon(
+ "%s-symbolic".printf(global::Application.Client.APP_ID)
+ );
+ }
GLib.Notification notification = new GLib.Notification(summary);
notification.set_body(body);
- notification.set_icon(
- new GLib.ThemedIcon(
- "%s-symbolic".printf(global::Application.Client.APP_ID)
- )
- );
+ notification.set_icon(icon);
// Do not show notification actions under Unity, it's
// notifications daemon doesn't support them.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]