Adds an action to a notification.
When the action is invoked, the specified callback function will be called, along with the value passed to user_data
.
Example: Notification with a button:
public static int main (string[] args) {
string summary = "Short summary";
string body = "A long description";
// = Gtk.Stock.DIALOG_INFO
string icon = "dialog-information";
Notify.init ("My test app");
GLib.MainLoop loop = new GLib.MainLoop ();
try {
Notify.Notification notification = new Notify.Notification (summary, body, icon);
notification.add_action ("action-name", "Quit", (notification, action) => {
print ("Bye!\n");
try {
notification.close ();
} catch (Error e) {
debug ("Error: %s", e.message);
}
loop.quit ();
});
notification.show ();
loop.run ();
} catch (Error e) {
error ("Error: %s", e.message);
}
return 0;
}
valac --pkg libnotify with-button.vala
this |
The notification. |
action |
The action ID. |
label |
The human-readable action label. |
callback |
The action's callback function. |
free_func |
An optional function to free |
user_data |
Optional custom data to pass to |