Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions data/NotificationEntry.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
38 changes: 8 additions & 30 deletions src/Services/Notification.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -34,7 +34,6 @@ public class Notifications.Notification : Object {
public string app_icon;
public string sender;
public string[] actions;
public List<Gtk.Button> 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
Expand Down Expand Up @@ -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);

Expand All @@ -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 ();

Expand Down Expand Up @@ -152,32 +156,6 @@ public class Notifications.Notification : Object {
}
}

private List<Gtk.Button> validate_actions (string[] actions) {
var list = new List<Gtk.Button> ();

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 ();
Expand Down
30 changes: 24 additions & 6 deletions src/Widgets/NotificationEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ 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;

private static Regex entity_regex;
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;
Expand Down Expand Up @@ -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 (
Expand Down
Loading