mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-23 22:16:16 +01:00
GNotification: Allow to set a category
Some backends like the FDO one allow to set a category. This helps the notification daemon to select a proper feedback type.
This commit is contained in:
parent
37e5dfd3a2
commit
791218a5f5
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user