11/*
2- * Copyright 2020-2023 elementary, Inc. (https://elementary.io)
3- *
4- * This program is free software; you can redistribute it and/or
5- * modify it under the terms of the GNU General Public
6- * License as published by the Free Software Foundation; either
7- * version 3 of the License, or (at your option) any later version.
8- *
9- * This program is distributed in the hope that it will be useful,
10- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12- * General Public License for more details.
13- *
14- * You should have received a copy of the GNU General Public
15- * License along with this program; if not, write to the
16- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17- * Boston, MA 02110-1301 USA
18- *
19- */
20-
21- public class Notifications.Notification : GLib .Object {
2+ * Copyright 2020-2025 elementary, Inc. (https://elementary.io)
3+ * SPDX-License-Identifier: GPL-3.0-or-later
4+ */
5+
6+ public class Notifications.Notification : Object {
227 private const string OTHER_APP_ID = " gala-other" ;
238
24- public GLib . DesktopAppInfo ? app_info { get ; private set ; default = null ; }
25- public GLib . NotificationPriority priority { get ; private set ; default = GLib . NotificationPriority . NORMAL ; }
26- public HashTable<string, Variant > hints { get ; construct; }
27- public string app_icon { get ; construct; }
28- public string app_id { get ; private set ; default = OTHER_APP_ID ; }
299 public string app_name { get ; construct; }
30- public string body { get ; construct set ; }
10+ public string app_icon { get ; construct; }
3111 public string summary { get ; construct set ; }
12+ public string body { get ; construct set ; }
13+ public DesktopAppInfo ? app_info { get ; construct; }
14+ public HashTable<string, Variant > hints { get ; construct; }
15+
16+ public GLib . NotificationPriority priority { get ; set ; default = NORMAL ; }
17+
18+ public string app_id { get ; private set ; default = OTHER_APP_ID ; }
3219
3320 public GLib . Icon ? primary_icon { get ; set ; default = null ; }
3421 public GLib . Icon ? badge_icon { get ; set ; default = null ; }
@@ -47,12 +34,13 @@ public class Notifications.Notification : GLib.Object {
4734 string action_name;
4835 }
4936
50- public Notification (string app_name, string app_icon, string summary, string body, HashTable<string, Variant > hints) {
37+ public Notification (string app_name, string app_icon, string summary, string body, DesktopAppInfo ? app_info, HashTable<string, Variant > hints) {
5138 Object (
5239 app_name: app_name,
5340 app_icon: app_icon,
5441 summary: summary,
5542 body: body,
43+ app_info: app_info,
5644 hints: hints
5745 );
5846 }
@@ -67,39 +55,13 @@ public class Notifications.Notification : GLib.Object {
6755 }
6856
6957 construct {
70- unowned Variant ? variant = null ;
71-
72- // GLib.Notification.set_priority ()
73- // convert between freedesktop urgency levels and GLib.NotificationPriority levels
74- // See: https://specifications.freedesktop.org/notification-spec/notification-spec-latest.html#urgency-levels
75- if (" urgency" in hints && hints[" urgency" ]. is_of_type (VariantType . BYTE )) {
76- switch (hints[" urgency" ]. get_byte ()) {
77- case 0 :
78- priority = LOW ;
79- break ;
80- case 1 :
81- priority = NORMAL ;
82- break ;
83- case 2 :
84- priority = URGENT ;
85- break ;
86- default:
87- warning (" unknown urgency value: %i , ignoring" , hints[" urgency" ]. get_byte ());
88- break ;
89- }
90- }
91-
92- if (" desktop-entry" in hints && hints[" desktop-entry" ]. is_of_type (VariantType . STRING )) {
93- app_info = new DesktopAppInfo (" %s.desktop " . printf (hints[" desktop-entry" ]. get_string ()));
94-
95- if (app_info != null && app_info. get_boolean (" X-GNOME-UsesNotifications" )) {
96- var app_info_id = app_info. get_id ();
97- if (app_info_id != null ) {
98- if (app_info_id. has_suffix (" .desktop" )) {
99- app_id = app_info_id. substring (0 , app_info_id. length - " .desktop" . length);
100- } else {
101- app_id = app_info_id;
102- }
58+ if (app_info != null && app_info. get_boolean (" X-GNOME-UsesNotifications" )) {
59+ var app_info_id = app_info. get_id ();
60+ if (app_info_id != null ) {
61+ if (app_info_id. has_suffix (" .desktop" )) {
62+ app_id = app_info_id. substring (0 , app_info_id. length - " .desktop" . length);
63+ } else {
64+ app_id = app_info_id;
10365 }
10466 }
10567 }
@@ -117,6 +79,8 @@ public class Notifications.Notification : GLib.Object {
11779 primary_icon = new ThemedIcon (app_icon);
11880 }
11981
82+ unowned Variant ? variant = null ;
83+
12084 // GLib.Notification.set_icon ()
12185 if ((variant = hints. lookup (" image-path" )) != null || (variant = hints. lookup (" image_path" )) != null ) {
12286 var image_path = variant. get_string ();
0 commit comments