GNotification

GNotification — User Notifications (pop up messages)

Synopsis

#include <gio/gio.h>

                    GNotification;
GNotification *     g_notification_new                  (const gchar *title);

void                g_notification_set_title            (GNotification *notification,
                                                         const gchar *title);
void                g_notification_set_body             (GNotification *notification,
                                                         const gchar *body);
void                g_notification_set_icon             (GNotification *notification,
                                                         GIcon *icon);
void                g_notification_set_urgent           (GNotification *notification,
                                                         gboolean urgent);

void                g_notification_set_default_action   (GNotification *notification,
                                                         const gchar *detailed_action);
void                g_notification_set_default_action_and_target
                                                        (GNotification *notification,
                                                         const gchar *action,
                                                         const gchar *target_format,
                                                         ...);
void                g_notification_set_default_action_and_target_value
                                                        (GNotification *notification,
                                                         const gchar *action,
                                                         GVariant *target);

void                g_notification_add_button           (GNotification *notification,
                                                         const gchar *label,
                                                         const gchar *detailed_action);
void                g_notification_add_button_with_target
                                                        (GNotification *notification,
                                                         const gchar *label,
                                                         const gchar *action,
                                                         const gchar *target_format,
                                                         ...);
void                g_notification_add_button_with_target_value
                                                        (GNotification *notification,
                                                         const gchar *label,
                                                         const gchar *action,
                                                         GVariant *target);

Description

GNotification is a mechanism for creating a notification to be shown to the user -- typically as a pop-up notification presented by the desktop environment shell.

The key difference between GNotification and other similar APIs is that, if supported by the desktop environment, notifications sent with GNotification will persist after the application has exited, and even across system reboots.

Since the user may click on a notification while the application is not running, applications using GNotification should be able to be started as a D-Bus service, using GApplication.

User interaction with a notification (either the default action, or buttons) must be associated with actions on the application (ie: "app." actions). It is not possible to route user interaction through the notification itself, because the object will not exist if the application is autostarted as a result of a notification being clicked.

A notification can be sent with g_application_send_notification().

Details

GNotification

typedef struct _GNotification GNotification;

This structure type is private and should only be accessed using the public APIs.

Since 2.40


g_notification_new ()

GNotification *     g_notification_new                  (const gchar *title);

Creates a new GNotification with title as its title.

After populating notification with more details, it can be sent to the desktop shell with g_application_send_notification(). Changing any properties after this call will not have any effect until resending notification.

title :

the title of the notification

Returns :

a new GNotification instance

Since 2.40


g_notification_set_title ()

void                g_notification_set_title            (GNotification *notification,
                                                         const gchar *title);

Sets the title of notification to title.

notification :

a GNotification

title :

the new title for notification

Since 2.40


g_notification_set_body ()

void                g_notification_set_body             (GNotification *notification,
                                                         const gchar *body);

Sets the body of notification to body.

notification :

a GNotification

body :

the new body for notification, or NULL. [allow-none]

Since 2.40


g_notification_set_icon ()

void                g_notification_set_icon             (GNotification *notification,
                                                         GIcon *icon);

Sets the icon of notification to icon.

notification :

a GNotification

icon :

the icon to be shown in notification, as a GIcon

Since 2.40


g_notification_set_urgent ()

void                g_notification_set_urgent           (GNotification *notification,
                                                         gboolean urgent);

Sets or unsets whether notification is marked as urgent.

notification :

a GNotification

urgent :

TRUE if notification is urgent

Since 2.40


g_notification_set_default_action ()

void                g_notification_set_default_action   (GNotification *notification,
                                                         const gchar *detailed_action);

Sets the default action of notification to detailed_action. This action is activated when the notification is clicked on.

The action in detailed_action must be an application-wide action (it must start with "app."). If detailed_action contains a target, the given action will be activated with that target as its parameter. See g_action_parse_detailed_name() for a description of the format for detailed_action.

When no default action is set, the application that the notification was sent on is activated.

notification :

a GNotification

detailed_action :

a detailed action name

Since 2.40


g_notification_set_default_action_and_target ()

void                g_notification_set_default_action_and_target
                                                        (GNotification *notification,
                                                         const gchar *action,
                                                         const gchar *target_format,
                                                         ...);

Sets the default action of notification to action. This action is activated when the notification is clicked on. It must be an application-wide action (it must start with "app.").

If target_format is given, it is used to collect remaining positional parameters into a GVariant instance, similar to g_variant_new(). action will be activated with that GVariant as its parameter.

When no default action is set, the application that the notification was sent on is activated.

notification :

a GNotification

action :

an action name

target_format :

a GVariant format string, or NULL. [allow-none]

... :

positional parameters, as determined by format_string

Since 2.40


g_notification_set_default_action_and_target_value ()

void                g_notification_set_default_action_and_target_value
                                                        (GNotification *notification,
                                                         const gchar *action,
                                                         GVariant *target);

Sets the default action of notification to action. This action is activated when the notification is clicked on. It must be an application-wide action (start with "app.").

If target_format is given, it is used to collect remaining positional parameters into a GVariant instance, similar to g_variant_new().

If target is non-NULL, action will be activated with target as its parameter.

When no default action is set, the application that the notification was sent on is activated.

notification :

a GNotification

action :

an action name

target :

a GVariant to use as action's parameter, or NULL. [allow-none]

Since 2.40


g_notification_add_button ()

void                g_notification_add_button           (GNotification *notification,
                                                         const gchar *label,
                                                         const gchar *detailed_action);

Adds a button to notification that activates the action in detailed_action when clicked. That action must be an application-wide action (starting with "app."). If detailed_action contains a target, the action will be activated with that target as its parameter.

See g_action_parse_detailed_name() for a description of the format for detailed_action.

notification :

a GNotification

label :

label of the button

detailed_action :

a detailed action name

Since 2.40


g_notification_add_button_with_target ()

void                g_notification_add_button_with_target
                                                        (GNotification *notification,
                                                         const gchar *label,
                                                         const gchar *action,
                                                         const gchar *target_format,
                                                         ...);

Adds a button to notification that activates action when clicked. action must be an application-wide action (it must start with "app.").

If target_format is given, it is used to collect remaining positional parameters into a GVariant instance, similar to g_variant_new(). action will be activated with that GVariant as its parameter.

notification :

a GNotification

label :

label of the button

action :

an action name

target_format :

a GVariant format string, or NULL. [allow-none]

... :

positional parameters, as determined by format_string

Since 2.40


g_notification_add_button_with_target_value ()

void                g_notification_add_button_with_target_value
                                                        (GNotification *notification,
                                                         const gchar *label,
                                                         const gchar *action,
                                                         GVariant *target);

Adds a button to notification that activates action when clicked. action must be an application-wide action (it must start with "app.").

If target is non-NULL, action will be activated with target as its parameter.

notification :

a GNotification

label :

label of the button

action :

an action name

target :

a GVariant to use as action's parameter, or NULL. [allow-none]

Since 2.40