| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | /*
 | 
					
						
							|  |  |  |  |  * Copyright © 2013 Lars Uebernickel | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2022-05-18 09:12:45 +01:00
										 |  |  |  |  * SPDX-License-Identifier: LGPL-2.1-or-later | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							| 
									
										
										
										
											2017-05-27 18:21:30 +02:00
										 |  |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * You should have received a copy of the GNU Lesser General | 
					
						
							| 
									
										
										
										
											2014-01-23 12:58:29 +01:00
										 |  |  |  |  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Authors: Lars Uebernickel <lars@uebernic.de> | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #include "config.h"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #include "gnotification-private.h"
 | 
					
						
							|  |  |  |  | #include "gdbusutils.h"
 | 
					
						
							|  |  |  |  | #include "gicon.h"
 | 
					
						
							|  |  |  |  | #include "gaction.h"
 | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  | #include "gioenumtypes.h"
 | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2023-10-24 10:54:12 +01:00
										 |  |  |  |  * GNotification: | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-10-24 10:54:12 +01:00
										 |  |  |  |  * `GNotification` is a mechanism for creating a notification to be shown | 
					
						
							|  |  |  |  |  * to the user — typically as a pop-up notification presented by the | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  |  * desktop environment shell. | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-10-24 10:54:12 +01:00
										 |  |  |  |  * The key difference between `GNotification` and other similar APIs is | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  |  * that, if supported by the desktop environment, notifications sent | 
					
						
							| 
									
										
										
										
											2023-10-24 10:54:12 +01:00
										 |  |  |  |  * with `GNotification` will persist after the application has exited, | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  |  * and even across system reboots. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since the user may click on a notification while the application is | 
					
						
							| 
									
										
										
										
											2023-10-24 10:54:12 +01:00
										 |  |  |  |  * not running, applications using `GNotification` should be able to be | 
					
						
							|  |  |  |  |  * started as a D-Bus service, using [class@Gio.Application]. | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-10-24 10:54:12 +01:00
										 |  |  |  |  * In order for `GNotification` to work, the application must have installed | 
					
						
							| 
									
										
										
										
											2021-05-17 10:30:54 +00:00
										 |  |  |  |  * a `.desktop` file. For example: | 
					
						
							| 
									
										
										
										
											2023-10-24 10:54:12 +01:00
										 |  |  |  |  * ``` | 
					
						
							|  |  |  |  |  * [Desktop Entry] | 
					
						
							|  |  |  |  |  * Name=Test Application | 
					
						
							|  |  |  |  |  * Comment=Description of what Test Application does | 
					
						
							|  |  |  |  |  * Exec=gnome-test-application | 
					
						
							|  |  |  |  |  * Icon=org.gnome.TestApplication | 
					
						
							|  |  |  |  |  * Terminal=false | 
					
						
							|  |  |  |  |  * Type=Application | 
					
						
							|  |  |  |  |  * Categories=GNOME;GTK;TestApplication Category; | 
					
						
							|  |  |  |  |  * StartupNotify=true | 
					
						
							|  |  |  |  |  * DBusActivatable=true | 
					
						
							|  |  |  |  |  * X-GNOME-UsesNotifications=true | 
					
						
							|  |  |  |  |  * ``` | 
					
						
							| 
									
										
										
										
											2021-05-17 10:30:54 +00:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * The `X-GNOME-UsesNotifications` key indicates to GNOME Control Center | 
					
						
							|  |  |  |  |  * that this application uses notifications, so it can be listed in the | 
					
						
							|  |  |  |  |  * Control Center’s ‘Notifications’ panel. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * The `.desktop` file must be named as `org.gnome.TestApplication.desktop`, | 
					
						
							| 
									
										
										
										
											2023-10-24 10:54:12 +01:00
										 |  |  |  |  * where `org.gnome.TestApplication` is the ID passed to | 
					
						
							|  |  |  |  |  * [ctor@Gio.Application.new]. | 
					
						
							| 
									
										
										
										
											2021-05-17 10:30:54 +00:00
										 |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  |  * User interaction with a notification (either the default action, or | 
					
						
							|  |  |  |  |  * buttons) must be associated with actions on the application (ie: | 
					
						
							| 
									
										
										
										
											2023-10-24 10:54:12 +01:00
										 |  |  |  |  * `app.` actions).  It is not possible to route user interaction | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  |  * through the notification itself, because the object will not exist if | 
					
						
							|  |  |  |  |  * the application is autostarted as a result of a notification being | 
					
						
							|  |  |  |  |  * clicked. | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2023-10-24 10:54:12 +01:00
										 |  |  |  |  * A notification can be sent with [method@Gio.Application.send_notification]. | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  **/ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | typedef GObjectClass GNotificationClass; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | struct _GNotification | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GObject parent; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   gchar *title; | 
					
						
							|  |  |  |  |   gchar *body; | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  |   GIcon *icon; | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  |   GNotificationPriority priority; | 
					
						
							| 
									
										
										
										
											2021-07-28 16:45:26 +02:00
										 |  |  |  |   gchar *category; | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |   GPtrArray *buttons; | 
					
						
							|  |  |  |  |   gchar *default_action; | 
					
						
							| 
									
										
										
										
											2022-11-15 17:48:47 +00:00
										 |  |  |  |   GVariant *default_action_target;  /* (nullable) (owned), not floating */ | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | typedef struct | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   gchar *label; | 
					
						
							|  |  |  |  |   gchar *action_name; | 
					
						
							|  |  |  |  |   GVariant *target; | 
					
						
							|  |  |  |  | } Button; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-17 11:54:02 +01:00
										 |  |  |  | G_DEFINE_TYPE (GNotification, g_notification, G_TYPE_OBJECT) | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | button_free (gpointer data) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   Button *button = data; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_free (button->label); | 
					
						
							|  |  |  |  |   g_free (button->action_name); | 
					
						
							|  |  |  |  |   if (button->target) | 
					
						
							|  |  |  |  |     g_variant_unref (button->target); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_slice_free (Button, button); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | g_notification_dispose (GObject *object) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GNotification *notification = G_NOTIFICATION (object); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  |   g_clear_object (¬ification->icon); | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   G_OBJECT_CLASS (g_notification_parent_class)->dispose (object); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | g_notification_finalize (GObject *object) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GNotification *notification = G_NOTIFICATION (object); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_free (notification->title); | 
					
						
							|  |  |  |  |   g_free (notification->body); | 
					
						
							| 
									
										
										
										
											2021-07-28 16:45:26 +02:00
										 |  |  |  |   g_free (notification->category); | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |   g_free (notification->default_action); | 
					
						
							|  |  |  |  |   if (notification->default_action_target) | 
					
						
							|  |  |  |  |     g_variant_unref (notification->default_action_target); | 
					
						
							|  |  |  |  |   g_ptr_array_free (notification->buttons, TRUE); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   G_OBJECT_CLASS (g_notification_parent_class)->finalize (object); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | g_notification_class_init (GNotificationClass *klass) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GObjectClass *object_class = G_OBJECT_CLASS (klass); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   object_class->dispose = g_notification_dispose; | 
					
						
							|  |  |  |  |   object_class->finalize = g_notification_finalize; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | g_notification_init (GNotification *notification) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   notification->buttons = g_ptr_array_new_full (2, button_free); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_notification_new: | 
					
						
							|  |  |  |  |  * @title: the title of the notification | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * 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. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Returns: a new #GNotification instance | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | GNotification * | 
					
						
							|  |  |  |  | g_notification_new (const gchar *title) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GNotification *notification; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_return_val_if_fail (title != NULL, NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   notification = g_object_new (G_TYPE_NOTIFICATION, NULL); | 
					
						
							|  |  |  |  |   notification->title = g_strdup (title); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return notification; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  | /*< private >
 | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * g_notification_get_title: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Gets the title of @notification. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Returns: the title of @notification | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | const gchar * | 
					
						
							|  |  |  |  | g_notification_get_title (GNotification *notification) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_val_if_fail (G_IS_NOTIFICATION (notification), NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return notification->title; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_notification_set_title: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  |  * @title: the new title for @notification | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Sets the title of @notification to @title. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | g_notification_set_title (GNotification *notification, | 
					
						
							|  |  |  |  |                           const gchar   *title) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_if_fail (G_IS_NOTIFICATION (notification)); | 
					
						
							|  |  |  |  |   g_return_if_fail (title != NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_free (notification->title); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   notification->title = g_strdup (title); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  | /*< private >
 | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * g_notification_get_body: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Gets the current body of @notification. | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-10-28 18:29:02 -07:00
										 |  |  |  |  * Returns: (nullable): the body of @notification | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | const gchar * | 
					
						
							|  |  |  |  | g_notification_get_body (GNotification *notification) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_val_if_fail (G_IS_NOTIFICATION (notification), NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return notification->body; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_notification_set_body: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							| 
									
										
										
										
											2016-10-28 18:29:02 -07:00
										 |  |  |  |  * @body: (nullable): the new body for @notification, or %NULL | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Sets the body of @notification to @body. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | g_notification_set_body (GNotification *notification, | 
					
						
							|  |  |  |  |                          const gchar   *body) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_if_fail (G_IS_NOTIFICATION (notification)); | 
					
						
							|  |  |  |  |   g_return_if_fail (body != NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_free (notification->body); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   notification->body = g_strdup (body); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  | /*< private >
 | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  |  * g_notification_get_icon: | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  |  * Gets the icon currently set on @notification. | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  |  * Returns: (transfer none): the icon associated with @notification | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | GIcon * | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  | g_notification_get_icon (GNotification *notification) | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_val_if_fail (G_IS_NOTIFICATION (notification), NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  |   return notification->icon; | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  |  * g_notification_set_icon: | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * @notification: a #GNotification | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  |  * @icon: the icon to be shown in @notification, as a #GIcon | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  |  * Sets the icon of @notification to @icon. | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  | g_notification_set_icon (GNotification *notification, | 
					
						
							|  |  |  |  |                          GIcon         *icon) | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_if_fail (G_IS_NOTIFICATION (notification)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  |   if (notification->icon) | 
					
						
							|  |  |  |  |     g_object_unref (notification->icon); | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  |   notification->icon = g_object_ref (icon); | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-21 14:29:44 -04:00
										 |  |  |  | /*< private >
 | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  |  * g_notification_get_priority: | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  |  * Returns the priority of @notification | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  |  * Since: 2.42 | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  | GNotificationPriority | 
					
						
							|  |  |  |  | g_notification_get_priority (GNotification *notification) | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  |   g_return_val_if_fail (G_IS_NOTIFICATION (notification), G_NOTIFICATION_PRIORITY_NORMAL); | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  |   return notification->priority; | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_notification_set_urgent: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * @urgent: %TRUE if @notification is urgent | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  |  * Deprecated in favor of g_notification_set_priority(). | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							| 
									
										
										
										
											2018-01-22 11:24:47 +00:00
										 |  |  |  |  * Deprecated: 2.42: Since 2.42, this has been deprecated in favour of | 
					
						
							|  |  |  |  |  *    g_notification_set_priority(). | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | g_notification_set_urgent (GNotification *notification, | 
					
						
							|  |  |  |  |                            gboolean       urgent) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_if_fail (G_IS_NOTIFICATION (notification)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-23 11:52:34 +01:00
										 |  |  |  |   notification->priority = urgent ? | 
					
						
							|  |  |  |  |       G_NOTIFICATION_PRIORITY_URGENT : | 
					
						
							|  |  |  |  |       G_NOTIFICATION_PRIORITY_NORMAL; | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 16:45:26 +02:00
										 |  |  |  | /*< private >
 | 
					
						
							|  |  |  |  |  * g_notification_get_category: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2022-11-15 17:49:45 +00:00
										 |  |  |  |  * Gets the category of @notification. | 
					
						
							| 
									
										
										
										
											2021-07-28 16:45:26 +02:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * This will be %NULL if no category is set. | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2022-11-15 17:49:45 +00:00
										 |  |  |  |  * Returns: (nullable): the category of @notification | 
					
						
							| 
									
										
										
										
											2021-07-28 16:45:26 +02:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.70 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | const gchar * | 
					
						
							|  |  |  |  | g_notification_get_category (GNotification *notification) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_val_if_fail (G_IS_NOTIFICATION (notification), NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return notification->category; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_notification_set_category: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * @category: (nullable): the category for @notification, or %NULL for no category | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Sets the type of @notification to @category. Categories have a main | 
					
						
							|  |  |  |  |  * type like `email`, `im` or `device` and can have a detail separated | 
					
						
							|  |  |  |  |  * by a `.`, e.g. `im.received` or `email.arrived`. Setting the category | 
					
						
							|  |  |  |  |  * helps the notification server to select proper feedback to the user. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Standard categories are [listed in the specification](https://specifications.freedesktop.org/notification-spec/latest/ar01s06.html).
 | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.70 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | g_notification_set_category (GNotification *notification, | 
					
						
							|  |  |  |  |                              const gchar   *category) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_if_fail (G_IS_NOTIFICATION (notification)); | 
					
						
							|  |  |  |  |   g_return_if_fail (category == NULL || *category != '\0'); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_free (notification->category); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   notification->category = g_strdup (category); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_notification_set_priority: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * @priority: a #GNotificationPriority | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Sets the priority of @notification to @priority. See | 
					
						
							|  |  |  |  |  * #GNotificationPriority for possible values. | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | g_notification_set_priority (GNotification         *notification, | 
					
						
							|  |  |  |  |                              GNotificationPriority  priority) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_if_fail (G_IS_NOTIFICATION (notification)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   notification->priority = priority; | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_notification_add_button: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * @label: label of the button | 
					
						
							|  |  |  |  |  * @detailed_action: a detailed action name | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * 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. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | g_notification_add_button (GNotification *notification, | 
					
						
							|  |  |  |  |                            const gchar   *label, | 
					
						
							|  |  |  |  |                            const gchar   *detailed_action) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   gchar *action; | 
					
						
							|  |  |  |  |   GVariant *target; | 
					
						
							|  |  |  |  |   GError *error = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_return_if_fail (detailed_action != NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (!g_action_parse_detailed_name (detailed_action, &action, &target, &error)) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       g_warning ("%s: %s", G_STRFUNC, error->message); | 
					
						
							|  |  |  |  |       g_error_free (error); | 
					
						
							|  |  |  |  |       return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_notification_add_button_with_target_value (notification, label, action, target); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_free (action); | 
					
						
							|  |  |  |  |   if (target) | 
					
						
							|  |  |  |  |     g_variant_unref (target); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_notification_add_button_with_target: (skip) | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * @label: label of the button | 
					
						
							|  |  |  |  |  * @action: an action name | 
					
						
							| 
									
										
										
										
											2016-10-28 18:29:02 -07:00
										 |  |  |  |  * @target_format: (nullable): a #GVariant format string, or %NULL | 
					
						
							| 
									
										
										
										
											2014-03-26 23:10:00 +01:00
										 |  |  |  |  * @...: positional parameters, as determined by @target_format | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * 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 | 
					
						
							| 
									
										
										
										
											2014-03-26 23:10:00 +01:00
										 |  |  |  |  * positional parameters into a #GVariant instance, similar to | 
					
						
							|  |  |  |  |  * g_variant_new(). @action will be activated with that #GVariant as its | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * parameter. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | g_notification_add_button_with_target (GNotification *notification, | 
					
						
							|  |  |  |  |                                        const gchar   *label, | 
					
						
							|  |  |  |  |                                        const gchar   *action, | 
					
						
							|  |  |  |  |                                        const gchar   *target_format, | 
					
						
							|  |  |  |  |                                        ...) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   va_list args; | 
					
						
							|  |  |  |  |   GVariant *target = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (target_format) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       va_start (args, target_format); | 
					
						
							|  |  |  |  |       target = g_variant_new_va (target_format, NULL, &args); | 
					
						
							|  |  |  |  |       va_end (args); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_notification_add_button_with_target_value (notification, label, action, target); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_notification_add_button_with_target_value: (rename-to g_notification_add_button_with_target) | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * @label: label of the button | 
					
						
							|  |  |  |  |  * @action: an action name | 
					
						
							| 
									
										
										
										
											2016-10-28 18:29:02 -07:00
										 |  |  |  |  * @target: (nullable): a #GVariant to use as @action's parameter, or %NULL | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * 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. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | g_notification_add_button_with_target_value (GNotification *notification, | 
					
						
							|  |  |  |  |                                              const gchar   *label, | 
					
						
							|  |  |  |  |                                              const gchar   *action, | 
					
						
							|  |  |  |  |                                              GVariant      *target) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   Button *button; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_return_if_fail (G_IS_NOTIFICATION (notification)); | 
					
						
							|  |  |  |  |   g_return_if_fail (label != NULL); | 
					
						
							|  |  |  |  |   g_return_if_fail (action != NULL && g_action_name_is_valid (action)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (!g_str_has_prefix (action, "app.")) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       g_warning ("%s: action '%s' does not start with 'app.'." | 
					
						
							|  |  |  |  |                  "This is unlikely to work properly.", G_STRFUNC, action); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   button =  g_slice_new0 (Button); | 
					
						
							|  |  |  |  |   button->label = g_strdup (label); | 
					
						
							|  |  |  |  |   button->action_name = g_strdup (action); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (target) | 
					
						
							|  |  |  |  |     button->target = g_variant_ref_sink (target); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_ptr_array_add (notification->buttons, button); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /*< private >
 | 
					
						
							|  |  |  |  |  * g_notification_get_n_buttons: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Returns: the amount of buttons added to @notification. | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | guint | 
					
						
							|  |  |  |  | g_notification_get_n_buttons (GNotification *notification) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   return notification->buttons->len; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /*< private >
 | 
					
						
							|  |  |  |  |  * g_notification_get_button: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * @index: index of the button | 
					
						
							|  |  |  |  |  * @label: (): return location for the button's label | 
					
						
							|  |  |  |  |  * @action: (): return location for the button's associated action | 
					
						
							|  |  |  |  |  * @target: (): return location for the target @action should be | 
					
						
							|  |  |  |  |  * activated with | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Returns a description of a button that was added to @notification | 
					
						
							|  |  |  |  |  * with g_notification_add_button(). | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * @index must be smaller than the value returned by | 
					
						
							|  |  |  |  |  * g_notification_get_n_buttons(). | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | g_notification_get_button (GNotification  *notification, | 
					
						
							|  |  |  |  |                            gint            index, | 
					
						
							|  |  |  |  |                            gchar         **label, | 
					
						
							|  |  |  |  |                            gchar         **action, | 
					
						
							|  |  |  |  |                            GVariant      **target) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   Button *button; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   button = g_ptr_array_index (notification->buttons, index); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (label) | 
					
						
							|  |  |  |  |     *label = g_strdup (button->label); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (action) | 
					
						
							|  |  |  |  |     *action = g_strdup (button->action_name); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (target) | 
					
						
							|  |  |  |  |     *target = button->target ? g_variant_ref (button->target) : NULL; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /*< private >
 | 
					
						
							|  |  |  |  |  * g_notification_get_button_with_action: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * @action: an action name | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Returns the index of the button in @notification that is associated | 
					
						
							|  |  |  |  |  * with @action, or -1 if no such button exists. | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | gint | 
					
						
							|  |  |  |  | g_notification_get_button_with_action (GNotification *notification, | 
					
						
							|  |  |  |  |                                        const gchar   *action) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   guint i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   for (i = 0; i < notification->buttons->len; i++) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       Button *button; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       button = g_ptr_array_index (notification->buttons, i); | 
					
						
							|  |  |  |  |       if (g_str_equal (action, button->action_name)) | 
					
						
							|  |  |  |  |         return i; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return -1; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /*< private >
 | 
					
						
							|  |  |  |  |  * g_notification_get_default_action: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							| 
									
										
										
										
											2022-11-15 17:48:47 +00:00
										 |  |  |  |  * @action: (out) (optional) (nullable) (transfer full): return location for the | 
					
						
							|  |  |  |  |  *   default action, or %NULL if unset | 
					
						
							|  |  |  |  |  * @target: (out) (optional) (nullable) (transfer full): return location for the | 
					
						
							|  |  |  |  |  *   target of the default action, or %NULL if unset | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Gets the action and target for the default action of @notification. | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2022-11-15 17:48:47 +00:00
										 |  |  |  |  * If this function returns %TRUE, @action is guaranteed to be set to a non-%NULL | 
					
						
							|  |  |  |  |  * value (if a pointer is passed to @action). @target may still return a %NULL | 
					
						
							|  |  |  |  |  * value, as the default action may have no target. | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * Returns: %TRUE if @notification has a default action | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | gboolean | 
					
						
							|  |  |  |  | g_notification_get_default_action (GNotification  *notification, | 
					
						
							|  |  |  |  |                                    gchar         **action, | 
					
						
							|  |  |  |  |                                    GVariant      **target) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   if (notification->default_action == NULL) | 
					
						
							|  |  |  |  |     return FALSE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (action) | 
					
						
							|  |  |  |  |     *action = g_strdup (notification->default_action); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (target) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       if (notification->default_action_target) | 
					
						
							|  |  |  |  |         *target = g_variant_ref (notification->default_action_target); | 
					
						
							|  |  |  |  |       else | 
					
						
							|  |  |  |  |         *target = NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return TRUE; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_notification_set_default_action: | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * @detailed_action: a detailed action name | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * 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. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | g_notification_set_default_action (GNotification *notification, | 
					
						
							|  |  |  |  |                                    const gchar   *detailed_action) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   gchar *action; | 
					
						
							|  |  |  |  |   GVariant *target; | 
					
						
							|  |  |  |  |   GError *error = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (!g_action_parse_detailed_name (detailed_action, &action, &target, &error)) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       g_warning ("%s: %s", G_STRFUNC, error->message); | 
					
						
							|  |  |  |  |       g_error_free (error); | 
					
						
							|  |  |  |  |       return; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_notification_set_default_action_and_target_value (notification, action, target); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_free (action); | 
					
						
							|  |  |  |  |   if (target) | 
					
						
							|  |  |  |  |     g_variant_unref (target); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_notification_set_default_action_and_target: (skip) | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * @action: an action name | 
					
						
							| 
									
										
										
										
											2016-10-28 18:29:02 -07:00
										 |  |  |  |  * @target_format: (nullable): a #GVariant format string, or %NULL | 
					
						
							| 
									
										
										
										
											2014-03-26 23:10:00 +01:00
										 |  |  |  |  * @...: positional parameters, as determined by @target_format | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * 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 | 
					
						
							| 
									
										
										
										
											2014-03-26 23:10:00 +01:00
										 |  |  |  |  * positional parameters into a #GVariant instance, similar to | 
					
						
							|  |  |  |  |  * g_variant_new(). @action will be activated with that #GVariant as its | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * parameter. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * When no default action is set, the application that the notification | 
					
						
							|  |  |  |  |  * was sent on is activated. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | g_notification_set_default_action_and_target (GNotification *notification, | 
					
						
							|  |  |  |  |                                               const gchar   *action, | 
					
						
							|  |  |  |  |                                               const gchar   *target_format, | 
					
						
							|  |  |  |  |                                               ...) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   va_list args; | 
					
						
							|  |  |  |  |   GVariant *target = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (target_format) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       va_start (args, target_format); | 
					
						
							|  |  |  |  |       target = g_variant_new_va (target_format, NULL, &args); | 
					
						
							|  |  |  |  |       va_end (args); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_notification_set_default_action_and_target_value (notification, action, target); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_notification_set_default_action_and_target_value: (rename-to g_notification_set_default_action_and_target) | 
					
						
							|  |  |  |  |  * @notification: a #GNotification | 
					
						
							|  |  |  |  |  * @action: an action name | 
					
						
							| 
									
										
										
										
											2016-10-28 18:29:02 -07:00
										 |  |  |  |  * @target: (nullable): a #GVariant to use as @action's parameter, or %NULL | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * 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 is non-%NULL, @action will be activated with @target as | 
					
						
							| 
									
										
										
										
											2022-11-15 17:48:47 +00:00
										 |  |  |  |  * its parameter. If @target is floating, it will be consumed. | 
					
						
							| 
									
										
										
										
											2013-10-15 11:21:10 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * When no default action is set, the application that the notification | 
					
						
							|  |  |  |  |  * was sent on is activated. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * Since: 2.40 | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | void | 
					
						
							|  |  |  |  | g_notification_set_default_action_and_target_value (GNotification *notification, | 
					
						
							|  |  |  |  |                                                     const gchar   *action, | 
					
						
							|  |  |  |  |                                                     GVariant      *target) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_if_fail (G_IS_NOTIFICATION (notification)); | 
					
						
							|  |  |  |  |   g_return_if_fail (action != NULL && g_action_name_is_valid (action)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (!g_str_has_prefix (action, "app.")) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       g_warning ("%s: action '%s' does not start with 'app.'." | 
					
						
							|  |  |  |  |                  "This is unlikely to work properly.", G_STRFUNC, action); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_free (notification->default_action); | 
					
						
							|  |  |  |  |   g_clear_pointer (¬ification->default_action_target, g_variant_unref); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   notification->default_action = g_strdup (action); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (target) | 
					
						
							|  |  |  |  |     notification->default_action_target = g_variant_ref_sink (target); | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | static GVariant * | 
					
						
							|  |  |  |  | g_notification_serialize_button (Button *button) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GVariantBuilder builder; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-25 11:09:07 -07:00
										 |  |  |  |   g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("a{sv}")); | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_variant_builder_add (&builder, "{sv}", "label", g_variant_new_string (button->label)); | 
					
						
							|  |  |  |  |   g_variant_builder_add (&builder, "{sv}", "action", g_variant_new_string (button->action_name)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (button->target) | 
					
						
							|  |  |  |  |     g_variant_builder_add (&builder, "{sv}", "target", button->target); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return g_variant_builder_end (&builder); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  | static GVariant * | 
					
						
							|  |  |  |  | g_notification_get_priority_nick (GNotification *notification) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GEnumClass *enum_class; | 
					
						
							|  |  |  |  |   GEnumValue *value; | 
					
						
							|  |  |  |  |   GVariant *nick; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   enum_class = g_type_class_ref (G_TYPE_NOTIFICATION_PRIORITY); | 
					
						
							|  |  |  |  |   value = g_enum_get_value (enum_class, g_notification_get_priority (notification)); | 
					
						
							| 
									
										
										
										
											2015-07-17 16:46:26 -04:00
										 |  |  |  |   g_assert (value != NULL); | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  |   nick = g_variant_new_string (value->value_nick); | 
					
						
							|  |  |  |  |   g_type_class_unref (enum_class); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return nick; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  | /*< private >
 | 
					
						
							|  |  |  |  |  * g_notification_serialize: | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-08-23 21:45:16 +00:00
										 |  |  |  |  * Serializes @notification into a floating variant of type a{sv}. | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Returns: the serialized @notification as a floating variant. | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | GVariant * | 
					
						
							|  |  |  |  | g_notification_serialize (GNotification *notification) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GVariantBuilder builder; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-25 11:09:07 -07:00
										 |  |  |  |   g_variant_builder_init_static (&builder, G_VARIANT_TYPE ("a{sv}")); | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (notification->title) | 
					
						
							|  |  |  |  |     g_variant_builder_add (&builder, "{sv}", "title", g_variant_new_string (notification->title)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (notification->body) | 
					
						
							|  |  |  |  |     g_variant_builder_add (&builder, "{sv}", "body", g_variant_new_string (notification->body)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (notification->icon) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       GVariant *serialized_icon; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       if ((serialized_icon = g_icon_serialize (notification->icon))) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           g_variant_builder_add (&builder, "{sv}", "icon", serialized_icon); | 
					
						
							|  |  |  |  |           g_variant_unref (serialized_icon); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-15 15:42:31 +02:00
										 |  |  |  |   g_variant_builder_add (&builder, "{sv}", "priority", g_notification_get_priority_nick (notification)); | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (notification->default_action) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       g_variant_builder_add (&builder, "{sv}", "default-action", | 
					
						
							|  |  |  |  |                                                g_variant_new_string (notification->default_action)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       if (notification->default_action_target) | 
					
						
							|  |  |  |  |         g_variant_builder_add (&builder, "{sv}", "default-action-target", | 
					
						
							|  |  |  |  |                                                   notification->default_action_target); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (notification->buttons->len > 0) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       GVariantBuilder actions_builder; | 
					
						
							|  |  |  |  |       guint i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-25 11:09:07 -07:00
										 |  |  |  |       g_variant_builder_init_static (&actions_builder, G_VARIANT_TYPE ("aa{sv}")); | 
					
						
							| 
									
										
										
										
											2013-10-15 12:19:09 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |       for (i = 0; i < notification->buttons->len; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           Button *button = g_ptr_array_index (notification->buttons, i); | 
					
						
							|  |  |  |  |           g_variant_builder_add (&actions_builder, "@a{sv}", g_notification_serialize_button (button)); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       g_variant_builder_add (&builder, "{sv}", "buttons", g_variant_builder_end (&actions_builder)); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return g_variant_builder_end (&builder); | 
					
						
							|  |  |  |  | } |