diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2021-08-03 13:44:16 +0000 |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2021-08-03 13:44:16 +0000 |
commit | 30b9aacff1bcef6dbbec956f64bdfabe98925b44 (patch) | |
tree | 7f138e3deec5f9da882586b280f3477feb330488 | |
parent | 37e5dfd3a2ced10c395b38702ae15e0e128e457b (diff) | |
parent | 8704c521fd5fe37c053717d6eb18c329ea4f566c (diff) | |
download | glib-30b9aacff1bcef6dbbec956f64bdfabe98925b44.tar.gz |
Merge branch 'notify-hint' into 'main'
GNotification: Allow to set a category
Closes #2446
See merge request GNOME/glib!2207
-rw-r--r-- | docs/reference/gio/gio-sections-common.txt | 1 | ||||
-rw-r--r-- | gio/gfdonotificationbackend.c | 6 | ||||
-rw-r--r-- | gio/gnotification-private.h | 2 | ||||
-rw-r--r-- | gio/gnotification.c | 48 | ||||
-rw-r--r-- | gio/gnotification.h | 4 | ||||
-rw-r--r-- | gio/tests/gnotification.c | 4 |
6 files changed, 65 insertions, 0 deletions
diff --git a/docs/reference/gio/gio-sections-common.txt b/docs/reference/gio/gio-sections-common.txt index a7addedc2..1b1ddc531 100644 --- a/docs/reference/gio/gio-sections-common.txt +++ b/docs/reference/gio/gio-sections-common.txt @@ -4677,6 +4677,7 @@ g_notification_set_icon GNotificationPriority g_notification_set_priority g_notification_set_urgent +g_notification_set_category <SUBSECTION> g_notification_set_default_action g_notification_set_default_action_and_target diff --git a/gio/gfdonotificationbackend.c b/gio/gfdonotificationbackend.c index 4a0a557d6..312ad1e0d 100644 --- a/gio/gfdonotificationbackend.c +++ b/gio/gfdonotificationbackend.c @@ -303,6 +303,12 @@ call_notify (GDBusConnection *con, g_variant_new_string (g_application_get_application_id (app))); urgency = urgency_from_priority (g_notification_get_priority (notification)); g_variant_builder_add (&hints_builder, "{sv}", "urgency", g_variant_new_byte (urgency)); + if (g_notification_get_category (notification)) + { + g_variant_builder_add (&hints_builder, "{sv}", "category", + g_variant_new_string (g_notification_get_category (notification))); + } + icon = g_notification_get_icon (notification); if (icon != NULL) { diff --git a/gio/gnotification-private.h b/gio/gnotification-private.h index e3e4a7818..ee38457fb 100644 --- a/gio/gnotification-private.h +++ b/gio/gnotification-private.h @@ -28,6 +28,8 @@ const gchar * g_notification_get_title (GNotifi const gchar * g_notification_get_body (GNotification *notification); +const gchar * g_notification_get_category (GNotification *notification); + GIcon * g_notification_get_icon (GNotification *notification); GNotificationPriority g_notification_get_priority (GNotification *notification); diff --git a/gio/gnotification.c b/gio/gnotification.c index aa7df7f7b..f77cd4e9e 100644 --- a/gio/gnotification.c +++ b/gio/gnotification.c @@ -97,6 +97,7 @@ struct _GNotification gchar *body; GIcon *icon; GNotificationPriority priority; + gchar *category; GPtrArray *buttons; gchar *default_action; GVariant *default_action_target; @@ -141,6 +142,7 @@ g_notification_finalize (GObject *object) g_free (notification->title); g_free (notification->body); + g_free (notification->category); g_free (notification->default_action); if (notification->default_action_target) g_variant_unref (notification->default_action_target); @@ -347,6 +349,52 @@ g_notification_set_urgent (GNotification *notification, G_NOTIFICATION_PRIORITY_NORMAL; } +/*< private > + * g_notification_get_category: + * @notification: a #GNotification + * + * Gets the cateogry of @notification. + * + * This will be %NULL if no category is set. + * + * Returns: (nullable): the cateogry of @notification + * + * 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); +} + /** * g_notification_set_priority: * @notification: a #GNotification diff --git a/gio/gnotification.h b/gio/gnotification.h index 55e683012..0b1035478 100644 --- a/gio/gnotification.h +++ b/gio/gnotification.h @@ -59,6 +59,10 @@ GLIB_AVAILABLE_IN_2_42 void g_notification_set_priority (GNotification *notification, GNotificationPriority priority); +GLIB_AVAILABLE_IN_2_70 +void g_notification_set_category (GNotification *notification, + const gchar *category); + GLIB_AVAILABLE_IN_2_40 void g_notification_add_button (GNotification *notification, const gchar *label, diff --git a/gio/tests/gnotification.c b/gio/tests/gnotification.c index 80d476d5a..853983c18 100644 --- a/gio/tests/gnotification.c +++ b/gio/tests/gnotification.c @@ -180,6 +180,7 @@ struct _GNotification gchar *body; GIcon *icon; GNotificationPriority priority; + gchar *category; GPtrArray *buttons; gchar *default_action; GVariant *default_action_target; @@ -205,10 +206,12 @@ test_properties (void) g_notification_set_title (n, "title"); g_notification_set_body (n, "body"); + g_notification_set_category (n, "cate.gory"); icon = g_themed_icon_new ("i-c-o-n"); g_notification_set_icon (n, icon); g_object_unref (icon); g_notification_set_priority (n, G_NOTIFICATION_PRIORITY_HIGH); + g_notification_set_category (n, "cate.gory"); g_notification_add_button (n, "label1", "app.action1::target1"); g_notification_set_default_action (n, "app.action2::target2"); @@ -222,6 +225,7 @@ test_properties (void) g_assert_cmpstr (names[1], ==, "i-c-o-n-symbolic"); g_assert_null (names[2]); g_assert (rn->priority == G_NOTIFICATION_PRIORITY_HIGH); + g_assert_cmpstr (rn->category, ==, "cate.gory"); g_assert_cmpint (rn->buttons->len, ==, 1); b = (Button*)rn->buttons->pdata[0]; |