mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
GNotification: add priority
https://bugzilla.gnome.org/show_bug.cgi?id=731623
This commit is contained in:
parent
baef9d1811
commit
01098e34c1
@ -181,6 +181,27 @@ notify_signal (GDBusConnection *connection,
|
||||
freedesktop_notification_free (n);
|
||||
}
|
||||
|
||||
/* Converts a GNotificationPriority to an urgency level as defined by
|
||||
* the freedesktop spec (0: low, 1: normal, 2: critical).
|
||||
*/
|
||||
static guchar
|
||||
urgency_from_priority (GNotificationPriority priority)
|
||||
{
|
||||
switch (priority)
|
||||
{
|
||||
case G_NOTIFICATION_PRIORITY_LOW:
|
||||
return 0;
|
||||
|
||||
default:
|
||||
case G_NOTIFICATION_PRIORITY_NORMAL:
|
||||
return 1;
|
||||
|
||||
case G_NOTIFICATION_PRIORITY_HIGH:
|
||||
case G_NOTIFICATION_PRIORITY_URGENT:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
call_notify (GDBusConnection *con,
|
||||
GApplication *app,
|
||||
@ -196,6 +217,7 @@ call_notify (GDBusConnection *con,
|
||||
GIcon *icon;
|
||||
GVariant *parameters;
|
||||
const gchar *body;
|
||||
guchar urgency;
|
||||
|
||||
g_variant_builder_init (&action_builder, G_VARIANT_TYPE_STRING_ARRAY);
|
||||
if (g_notification_get_default_action (notification, NULL, NULL))
|
||||
@ -237,8 +259,8 @@ call_notify (GDBusConnection *con,
|
||||
g_variant_builder_init (&hints_builder, G_VARIANT_TYPE ("a{sv}"));
|
||||
g_variant_builder_add (&hints_builder, "{sv}", "desktop-entry",
|
||||
g_variant_new_string (g_application_get_application_id (app)));
|
||||
if (g_notification_get_urgent (notification))
|
||||
g_variant_builder_add (&hints_builder, "{sv}", "urgency", g_variant_new_byte (2));
|
||||
urgency = urgency_from_priority (g_notification_get_priority (notification));
|
||||
g_variant_builder_add (&hints_builder, "{sv}", "urgency", g_variant_new_byte (urgency));
|
||||
icon = g_notification_get_icon (notification);
|
||||
if (icon != NULL && G_IS_FILE_ICON (icon))
|
||||
{
|
||||
|
@ -1783,6 +1783,32 @@ typedef enum {
|
||||
G_SUBPROCESS_FLAGS_INHERIT_FDS = (1u << 7)
|
||||
} GSubprocessFlags;
|
||||
|
||||
/**
|
||||
* GNotificationPriority:
|
||||
* @G_NOTIFICATION_PRIORITY_LOW: for notifications that do not require
|
||||
* immediate attention - typically used for contextual background
|
||||
* information, such as contact birthdays or local weather
|
||||
* @G_NOTIFICATION_PRIORITY_NORMAL: the default priority, to be used for the
|
||||
* majority of notifications (for example email messages, software updates,
|
||||
* completed download/sync operations)
|
||||
* @G_NOTIFICATION_PRIORITY_HIGH: for events that require more attention,
|
||||
* usually because responses are time-sensitive (for example chat and SMS
|
||||
* messages or alarms)
|
||||
* @G_NOTIFICATION_PRIORITY_URGENT: for urgent notifications, or notifications
|
||||
* that require a response in a short space of time (for example phone calls
|
||||
* or emergency warnings)
|
||||
*
|
||||
* Priority levels for #GNotifications.
|
||||
*
|
||||
* Since: 2.42
|
||||
*/
|
||||
typedef enum {
|
||||
G_NOTIFICATION_PRIORITY_NORMAL,
|
||||
G_NOTIFICATION_PRIORITY_LOW,
|
||||
G_NOTIFICATION_PRIORITY_HIGH,
|
||||
G_NOTIFICATION_PRIORITY_URGENT
|
||||
} GNotificationPriority;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GIO_ENUMS_H__ */
|
||||
|
@ -30,7 +30,7 @@ const gchar * g_notification_get_body (GNotifi
|
||||
|
||||
GIcon * g_notification_get_icon (GNotification *notification);
|
||||
|
||||
gboolean g_notification_get_urgent (GNotification *notification);
|
||||
GNotificationPriority g_notification_get_priority (GNotification *notification);
|
||||
|
||||
guint g_notification_get_n_buttons (GNotification *notification);
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "gdbusutils.h"
|
||||
#include "gicon.h"
|
||||
#include "gaction.h"
|
||||
#include "gioenumtypes.h"
|
||||
|
||||
/**
|
||||
* SECTION:gnotification
|
||||
@ -72,7 +73,7 @@ struct _GNotification
|
||||
gchar *title;
|
||||
gchar *body;
|
||||
GIcon *icon;
|
||||
gboolean urgent;
|
||||
GNotificationPriority priority;
|
||||
GPtrArray *buttons;
|
||||
gchar *default_action;
|
||||
GVariant *default_action_target;
|
||||
@ -286,19 +287,19 @@ g_notification_set_icon (GNotification *notification,
|
||||
}
|
||||
|
||||
/*< private >
|
||||
* g_notification_get_urgent:
|
||||
* g_notification_get_priority:
|
||||
* @notification: a #GNotification
|
||||
*
|
||||
* Returns %TRUE if @notification is marked as urgent.
|
||||
* Returns the priority of @notification
|
||||
*
|
||||
* Since: 2.40
|
||||
* Since: 2.42
|
||||
*/
|
||||
gboolean
|
||||
g_notification_get_urgent (GNotification *notification)
|
||||
GNotificationPriority
|
||||
g_notification_get_priority (GNotification *notification)
|
||||
{
|
||||
g_return_val_if_fail (G_IS_NOTIFICATION (notification), FALSE);
|
||||
g_return_val_if_fail (G_IS_NOTIFICATION (notification), G_NOTIFICATION_PRIORITY_NORMAL);
|
||||
|
||||
return notification->urgent;
|
||||
return notification->priority;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -306,7 +307,7 @@ g_notification_get_urgent (GNotification *notification)
|
||||
* @notification: a #GNotification
|
||||
* @urgent: %TRUE if @notification is urgent
|
||||
*
|
||||
* Sets or unsets whether @notification is marked as urgent.
|
||||
* Deprecated in favor of g_notification_set_priority().
|
||||
*
|
||||
* Since: 2.40
|
||||
*/
|
||||
@ -316,7 +317,24 @@ g_notification_set_urgent (GNotification *notification,
|
||||
{
|
||||
g_return_if_fail (G_IS_NOTIFICATION (notification));
|
||||
|
||||
notification->urgent = urgent;
|
||||
g_notification_set_priority (notification, G_NOTIFICATION_PRIORITY_URGENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -687,6 +705,21 @@ g_notification_serialize_button (Button *button)
|
||||
return g_variant_builder_end (&builder);
|
||||
}
|
||||
|
||||
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));
|
||||
nick = g_variant_new_string (value->value_nick);
|
||||
g_type_class_unref (enum_class);
|
||||
|
||||
return nick;
|
||||
}
|
||||
|
||||
/*< private >
|
||||
* g_notification_serialize:
|
||||
*
|
||||
@ -718,7 +751,7 @@ g_notification_serialize (GNotification *notification)
|
||||
}
|
||||
}
|
||||
|
||||
g_variant_builder_add (&builder, "{sv}", "urgent", g_variant_new_boolean (notification->urgent));
|
||||
g_variant_builder_add (&builder, "{sv}", "priority", g_notification_get_priority_nick (notification));
|
||||
|
||||
if (notification->default_action)
|
||||
{
|
||||
|
@ -25,6 +25,7 @@
|
||||
#endif
|
||||
|
||||
#include <gio/giotypes.h>
|
||||
#include <gio/gioenums.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -50,10 +51,14 @@ GLIB_AVAILABLE_IN_2_40
|
||||
void g_notification_set_icon (GNotification *notification,
|
||||
GIcon *icon);
|
||||
|
||||
GLIB_AVAILABLE_IN_2_40
|
||||
GLIB_DEPRECATED_IN_2_42_FOR(g_notification_set_priority)
|
||||
void g_notification_set_urgent (GNotification *notification,
|
||||
gboolean urgent);
|
||||
|
||||
GLIB_AVAILABLE_IN_2_42
|
||||
void g_notification_set_priority (GNotification *notification,
|
||||
GNotificationPriority priority);
|
||||
|
||||
GLIB_AVAILABLE_IN_2_40
|
||||
void g_notification_add_button (GNotification *notification,
|
||||
const gchar *label,
|
||||
|
@ -41,7 +41,7 @@ activate_app (GApplication *application,
|
||||
g_object_unref (icon);
|
||||
|
||||
g_notification_set_body (notification, "body");
|
||||
g_notification_set_urgent (notification, TRUE);
|
||||
g_notification_set_priority (notification, G_NOTIFICATION_PRIORITY_URGENT);
|
||||
g_notification_set_default_action_and_target (notification, "app.action", "i", 42);
|
||||
g_notification_add_button_with_target (notification, "label", "app.action2", "s", "bla");
|
||||
|
||||
@ -179,7 +179,7 @@ struct _GNotification
|
||||
gchar *title;
|
||||
gchar *body;
|
||||
GIcon *icon;
|
||||
gboolean urgent;
|
||||
GNotificationPriority priority;
|
||||
GPtrArray *buttons;
|
||||
gchar *default_action;
|
||||
GVariant *default_action_target;
|
||||
@ -208,7 +208,7 @@ test_properties (void)
|
||||
icon = g_themed_icon_new ("i-c-o-n");
|
||||
g_notification_set_icon (n, icon);
|
||||
g_object_unref (icon);
|
||||
g_notification_set_urgent (n, TRUE);
|
||||
g_notification_set_priority (n, G_NOTIFICATION_PRIORITY_HIGH);
|
||||
g_notification_add_button (n, "label1", "app.action1::target1");
|
||||
g_notification_set_default_action (n, "app.action2::target2");
|
||||
|
||||
@ -220,7 +220,7 @@ test_properties (void)
|
||||
names = g_themed_icon_get_names (G_THEMED_ICON (rn->icon));
|
||||
g_assert_cmpstr (names[0], ==, "i-c-o-n");
|
||||
g_assert (names[1] == NULL);
|
||||
g_assert (rn->urgent);
|
||||
g_assert (rn->priority == G_NOTIFICATION_PRIORITY_HIGH);
|
||||
|
||||
g_assert_cmpint (rn->buttons->len, ==, 1);
|
||||
b = (Button*)rn->buttons->pdata[0];
|
||||
|
Loading…
Reference in New Issue
Block a user