From d98396fe85edab5e480a0f1e939e30f55139867b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 4 Sep 2026 09:25:10 -0700 Subject: [PATCH] NotificationEntry: handle building action buttons --- data/NotificationEntry.css | 4 ++++ src/Services/Notification.vala | 38 +++++++----------------------- src/Widgets/NotificationEntry.vala | 30 ++++++++++++++++++----- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/data/NotificationEntry.css b/data/NotificationEntry.css index 2e1135c8..f79ba9cc 100644 --- a/data/NotificationEntry.css +++ b/data/NotificationEntry.css @@ -56,3 +56,7 @@ notification .close image { color: #fff; -gtk-icon-shadow: 0 1px 1px alpha(#000, 0.6); } + +notification button.text-button { + min-width: 6rem; +} diff --git a/src/Services/Notification.vala b/src/Services/Notification.vala index baeff64a..7a0b387b 100644 --- a/src/Services/Notification.vala +++ b/src/Services/Notification.vala @@ -23,7 +23,7 @@ public class Notifications.Notification : Object { UNDEFINED = 4 } - public const string DEFAULT_ACTION = "default"; + public const string DEFAULT_ACTION_NAME = "default"; public const string DESKTOP_ID_EXT = ".desktop"; public string internal_id { get; construct set; } // Format: "timestamp.server_id" @@ -34,7 +34,6 @@ public class Notifications.Notification : Object { public string app_icon; public string sender; public string[] actions; - public List buttons; public string? default_action { get; private set; default = null; } public uint32 replaces_id; public uint32 server_id { get; construct set; default = 0; } // 0 means the notification is outdated i.e. not present in the server anymore @@ -75,7 +74,10 @@ public class Notifications.Notification : Object { sender = _sender; actions = _actions; - buttons = validate_actions (actions); + if (actions[0] == DEFAULT_ACTION_NAME) { + //FIXME: server_id not saved?? + default_action = server_id.to_string () + "." + DEFAULT_ACTION_NAME; + } timestamp = new GLib.DateTime.from_unix_local (_unix_time); @@ -97,7 +99,9 @@ public class Notifications.Notification : Object { sender = message.get_sender (); actions = body.get_child_value (Column.ACTIONS).dup_strv (); - buttons = validate_actions (actions); + if (actions[0] == DEFAULT_ACTION_NAME) { + default_action = _id.to_string () + "." + DEFAULT_ACTION_NAME; + } timestamp = new GLib.DateTime.now_local (); @@ -152,32 +156,6 @@ public class Notifications.Notification : Object { } } - private List validate_actions (string[] actions) { - var list = new List (); - - for (int i = 0; i < actions.length; i += 2) { - if (actions[i] == DEFAULT_ACTION) { - default_action = server_id.to_string () + "." + DEFAULT_ACTION; - continue; - } - - var label = actions[i + 1].strip (); - if (label == "") { - warning ("Action '%s' sent without label, skipping…", actions[i]); - continue; - } - - var button = new Gtk.Button.with_label (label) { - action_name = NotificationsList.ACTION_PREFIX + server_id.to_string () + "." + actions[i], - width_request = 86 - }; - - list.append (button); - } - - return list; - } - private string get_string (Variant tuple, int column) { var child = tuple.get_child_value (column); return child.dup_string (); diff --git a/src/Widgets/NotificationEntry.vala b/src/Widgets/NotificationEntry.vala index 2ec4d0b8..4362f3dd 100644 --- a/src/Widgets/NotificationEntry.vala +++ b/src/Widgets/NotificationEntry.vala @@ -8,8 +8,6 @@ public class Notifications.NotificationEntry : Gtk.ListBoxRow { public Notification notification { get; private set; } - private uint timeout_id; - private const int ICON_SIZE_PRIMARY = 48; private const int ICON_SIZE_SECONDARY = 24; @@ -17,6 +15,7 @@ public class Notifications.NotificationEntry : Gtk.ListBoxRow { private static Regex tag_regex; private static Settings settings; + private uint timeout_id; private Granite.Box action_area; private Gtk.Image primary_image; private Gtk.Image secondary_image; @@ -247,12 +246,31 @@ public class Notifications.NotificationEntry : Gtk.ListBoxRow { body_label.label = fix_markup (entry_body); - if (notification.buttons.length () > 0) { - action_area.visible = true; + for (int i = 0; i < notification.actions.length; i += 2) { + if (notification.actions[i] == Notification.DEFAULT_ACTION_NAME) { + continue; + } - foreach (var button in notification.buttons) { - action_area.append (button); + var label = notification.actions[i + 1].strip (); + if (label == "") { + warning ("Action '%s' sent without label, skipping…", notification.actions[i]); + continue; + } + + var button = new Gtk.Button.with_label (label) { + action_name = string.join ( + ".", + NotificationsList.ACTION_GROUP_PREFIX, + notification.server_id.to_string (), + notification.actions[i] + ) }; + + action_area.append (button); + } + + if (notification.actions.length >= 2) { + action_area.visible = true; } settings.bind_with_mapping (