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,
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))
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))
{
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__ */
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);
#include "gdbusutils.h"
#include "gicon.h"
#include "gaction.h"
+#include "gioenumtypes.h"
/**
* SECTION:gnotification
gchar *title;
gchar *body;
GIcon *icon;
- gboolean urgent;
+ GNotificationPriority priority;
GPtrArray *buttons;
gchar *default_action;
GVariant *default_action_target;
}
/*< 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;
}
/**
* @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
*/
{
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;
}
/**
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:
*
}
}
- 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)
{
#endif
#include <gio/giotypes.h>
+#include <gio/gioenums.h>
G_BEGIN_DECLS
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,
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");
gchar *title;
gchar *body;
GIcon *icon;
- gboolean urgent;
+ GNotificationPriority priority;
GPtrArray *buttons;
gchar *default_action;
GVariant *default_action_target;
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");
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];