From 9e9cb423b969c68ecfe382cf1250dba3e7399655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 16 May 2022 11:42:44 +0200 Subject: Notification: Add NotifyClosedReason enum to define closed reasons We don't change the formal type of notify_notification_get_closed_reason but it's safe enough to compare the two returned values. --- docs/reference/libnotify-sections.txt | 1 + libnotify/notification.c | 16 ++++++++++------ libnotify/notification.h | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/docs/reference/libnotify-sections.txt b/docs/reference/libnotify-sections.txt index f78a33a..f7229c6 100644 --- a/docs/reference/libnotify-sections.txt +++ b/docs/reference/libnotify-sections.txt @@ -4,6 +4,7 @@ NOTIFY_EXPIRES_DEFAULT NOTIFY_EXPIRES_NEVER NotifyNotification NotifyNotification +NotifyClosedReason NotifyUrgency NotifyActionCallback NOTIFY_ACTION_CALLBACK diff --git a/libnotify/notification.c b/libnotify/notification.c index c781069..cb376e2 100644 --- a/libnotify/notification.c +++ b/libnotify/notification.c @@ -234,9 +234,9 @@ notify_notification_class_init (NotifyNotificationClass *klass) g_param_spec_int ("closed-reason", "Closed Reason", "The reason code for why the notification was closed", - -1, + NOTIFY_CLOSED_REASON_UNSET, G_MAXINT32, - -1, + NOTIFY_CLOSED_REASON_UNSET, G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK @@ -357,7 +357,7 @@ notify_notification_init (NotifyNotification *obj) { obj->priv = g_new0 (NotifyNotificationPrivate, 1); obj->priv->timeout = NOTIFY_EXPIRES_DEFAULT; - obj->priv->closed_reason = -1; + obj->priv->closed_reason = NOTIFY_CLOSED_REASON_UNSET; obj->priv->hints = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, @@ -1361,13 +1361,17 @@ notify_notification_close (NotifyNotification *notification, * Returns the closed reason code for the notification. This is valid only * after the "closed" signal is emitted. * - * Returns: The closed reason code. + * Since version 0.8.0 the returned value is of type #NotifyClosedReason. + * + * Returns: An integer representing the closed reason code + * (Since 0.8.0 it's also a #NotifyClosedReason). */ gint notify_notification_get_closed_reason (const NotifyNotification *notification) { - g_return_val_if_fail (notification != NULL, -1); - g_return_val_if_fail (NOTIFY_IS_NOTIFICATION (notification), -1); + g_return_val_if_fail (notification != NULL, NOTIFY_CLOSED_REASON_UNSET); + g_return_val_if_fail (NOTIFY_IS_NOTIFICATION (notification), + NOTIFY_CLOSED_REASON_UNSET); return notification->priv->closed_reason; } diff --git a/libnotify/notification.h b/libnotify/notification.h index f1639d8..f0c8e69 100644 --- a/libnotify/notification.h +++ b/libnotify/notification.h @@ -93,6 +93,29 @@ typedef enum } NotifyUrgency; + +/** + * NotifyClosedReason: + * @NOTIFY_CLOSED_REASON_UNSET: Notification not closed. + * @NOTIFY_CLOSED_REASON_EXPIRED: Timeout has expired. + * @NOTIFY_CLOSED_REASON_DISMISSED: It has been dismissed by the user. + * @NOTIFY_CLOSED_REASON_API_REQUEST: It has been closed by a call to + * notify_notification_close(). + * @NOTIFY_CLOSED_REASON_UNDEFIEND: Closed by undefined/reserved reasons. + * + * The reason for which the notification has been closed. + * + * Since: 0.8.0 + */ +typedef enum +{ + NOTIFY_CLOSED_REASON_UNSET = -1, + NOTIFY_CLOSED_REASON_EXPIRED = 1, + NOTIFY_CLOSED_REASON_DISMISSED = 2, + NOTIFY_CLOSED_REASON_API_REQUEST = 3, + NOTIFY_CLOSED_REASON_UNDEFIEND = 4, +} NotifyClosedReason; + /** * NotifyActionCallback: * @notification: a #NotifyActionCallback notification -- cgit v1.2.1