Skip to content
Closed
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
1 change: 1 addition & 0 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public class Notifications.Indicator : Wingpanel.Indicator {
}

private void on_notification_received (DBusMessage message, uint32 id) {
print ("notification received");
var notification = new Notification.from_message (message, id);
if (notification.is_transient || notification.app_name in EXCEPTIONS) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/Services/Interfaces.vala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

[DBus (name = "org.freedesktop.Notifications")]
[DBus (name = "io.elementary.Notifications")]
public interface Notifications.INotifications : Object {
public signal void action_invoked (uint32 id, string action);
public abstract void invoke_action (uint32 id, string action) throws DBusError, IOError;
}
44 changes: 30 additions & 14 deletions src/Services/Notification.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public class Notifications.Notification : Object {
UNDEFINED = 4
}

public const string ACTION_ID = "fdo-%u.%s";
public const string DESKTOP_ID_EXT = ".desktop";
public const string DEFAULT_ACTION = "default";

public bool is_transient = false;
public string app_name;
Expand Down Expand Up @@ -54,7 +56,6 @@ public class Notifications.Notification : Object {
COUNT
}

private const string DEFAULT_ACTION = "default";
private const string X_CANONICAL_PRIVATE_KEY = "x-canonical-private-synchronous";
private const string DESKTOP_ENTRY_KEY = "desktop-entry";
private const string FALLBACK_DESKTOP_ID = "gala-other" + DESKTOP_ID_EXT;
Expand Down Expand Up @@ -144,25 +145,40 @@ public class Notifications.Notification : Object {
is_transient = hints.lookup_value (X_CANONICAL_PRIVATE_KEY, null) != null || (transient_hint != null && transient_hint.get_boolean ());
}

public bool run_default_action () {
if (DEFAULT_ACTION in actions) {
app_info.launch_action (DEFAULT_ACTION, new GLib.AppLaunchContext ());
public bool action_invoked (string action) {
var notification_actions = NotificationMonitor.get_instance ().notification_actions;

var notifications_iface = NotificationMonitor.get_instance ().notifications_iface;
if (notifications_iface != null) {
notifications_iface.action_invoked (id, DEFAULT_ACTION);
if (action == DEFAULT_ACTION) {
if (DEFAULT_ACTION in actions) {
app_info.launch_action (DEFAULT_ACTION, new GLib.AppLaunchContext ());

if (notification_actions != null) {
notification_actions.activate_action ("fdo-" + id.to_string () + "." + DEFAULT_ACTION, null);
return true;
}

} else if (actions.length == 0) {
try {
app_info.launch (null, null);
return true;
} catch (Error e) {
critical ("Unable to launch app: %s", e.message);
}
}

return true;
return false;
} else {
try {
app_info.launch (null, null);
} catch (Error e) {
critical ("Unable to launch app: %s", e.message);
if (notification_actions != null) {
try {
notification_actions.activate_action ("fdo-" + id.to_string () + "." + action, null);
return true;
} catch (Error e) {
warning ("Failed to invoke action '%s': %s", action, e.message);
}
}
}

return false;
return false;
}
}

private string get_string (Variant tuple, int column) {
Expand Down
13 changes: 5 additions & 8 deletions src/Services/NotificationsMonitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/

public class Notifications.NotificationMonitor : Object {
private const string NOTIFY_IFACE = "org.freedesktop.Notifications";
private const string NOTIFY_PATH = "/org/freedesktop/Notifications";
private const string NOTIFY_IFACE = "io.elementary.notifications";
private const string NOTIFY_PATH = "/io/elementary/notifications";
private const string METHOD_CALL_MATCH_STRING = "type='method_call',interface='org.freedesktop.Notifications'";
private const string METHOD_RETURN_MATCH_STRING = "type='method_return'";
private const string ERROR_MATCH_STRING = "type='error'";
Expand All @@ -44,7 +44,7 @@ public class Notifications.NotificationMonitor : Object {
return instance;
}

public INotifications? notifications_iface = null;
public DBusActionGroup? notification_actions = null;

construct {
initialize.begin ();
Expand Down Expand Up @@ -87,11 +87,8 @@ public class Notifications.NotificationMonitor : Object {
critical ("Unable to monitor notifications bus: %s", e.message);
}

try {
notifications_iface = yield Bus.get_proxy (BusType.SESSION, NOTIFY_IFACE, NOTIFY_PATH, DBusProxyFlags.NONE, null);
} catch (Error e) {
warning ("Unable to connection to notifications bus: %s", e.message);
}
notification_actions = DBusActionGroup.get (connection, "io.elementary.notifications", "/org/freedesktop/Notifications");
print ("initialized");
}

private DBusMessage? message_filter (DBusConnection con, owned DBusMessage message, bool incoming) {
Expand Down
52 changes: 51 additions & 1 deletion src/Widgets/NotificationEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class Notifications.NotificationEntry : Gtk.ListBoxRow {
}

construct {
insert_action_group ("fdo-" + notification.id.to_string (), NotificationMonitor.get_instance ().notification_actions);

var app_image = new Gtk.Image ();

if (notification.app_icon.contains ("/")) {
Expand Down Expand Up @@ -138,12 +140,16 @@ public class Notifications.NotificationEntry : Gtk.ListBoxRow {
var delete_button = new Gtk.Button () {
halign = Gtk.Align.START,
valign = Gtk.Align.START,
image = delete_image
image = delete_image,
action_name = "close",
action_target = notification.id
};
delete_button.get_style_context ().add_class ("close");
delete_button.get_style_context ().add_provider (provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

var delete_revealer = new Gtk.Revealer () {
halign = Gtk.Align.START,
valign = Gtk.Align.START,
reveal_child = false,
transition_duration = Granite.TRANSITION_DURATION_CLOSE,
transition_type = Gtk.RevealerTransitionType.CROSSFADE
Expand Down Expand Up @@ -186,6 +192,39 @@ public class Notifications.NotificationEntry : Gtk.ListBoxRow {

grid.attach (body_label, 1, 1, 2);

if (notification.actions.length > 0) {
var action_area = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) {
margin_top = 12,
halign = Gtk.Align.END,
homogeneous = true
};

bool action_area_packed = false;

for (int i = 0; i < notification.actions.length; i += 2) {
if (notification.actions[i] == Notification.DEFAULT_ACTION) {
i += 2; //TODO: The i += 2 is copied from elementary/notifications. No idea why that's there though?
continue;
}

var button = new Gtk.Button.with_label (notification.actions[i + 1]) {
action_name = Notification.ACTION_ID.printf (notification.id, notification.actions[i])
};

button.clicked.connect (() => {
activate ();
clear ();
});

action_area.pack_end (button);

if (!action_area_packed) {
grid.attach (action_area, 0, 2, 3);
action_area_packed = true;
}
}
}

var delete_left = new DeleteAffordance (Gtk.Align.END) {
// Have to match with the grid
margin_top = 9,
Expand Down Expand Up @@ -231,6 +270,17 @@ public class Notifications.NotificationEntry : Gtk.ListBoxRow {

show_all ();

button_release_event.connect (() => {
// unowned var action_group = get_action_group ("fdo-" + notification.id.to_string ());
// action_gr
// if (notification.action_invoked (Notification.DEFAULT_ACTION)) {
activate ();
clear ();
// }

return Gdk.EVENT_STOP;
});

delete_button.clicked.connect (() => {
clear ();
});
Expand Down
5 changes: 0 additions & 5 deletions src/Widgets/NotificationsList.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class Notifications.NotificationsList : Gtk.ListBox {
placeholder_style_context.add_class (Granite.STYLE_CLASS_H2_LABEL);
placeholder_style_context.add_class (Gtk.STYLE_CLASS_DIM_LABEL);

activate_on_single_click = true;
selection_mode = Gtk.SelectionMode.NONE;
set_placeholder (placeholder);
show_all ();
Expand Down Expand Up @@ -129,10 +128,6 @@ public class Notifications.NotificationsList : Gtk.ListBox {

private void on_row_activated (Gtk.ListBoxRow row) {
if (row is NotificationEntry) {
unowned NotificationEntry notification_entry = (NotificationEntry) row;
notification_entry.notification.run_default_action ();
notification_entry.clear ();

close_popover ();
}
}
Expand Down