From 392d030acfb438b8adcf1d0fbe54dcbd8369294f Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 14 Jul 2004 01:09:40 +0000 Subject: [PATCH] * libnotify/notify.c: Use pointers instead of GINT_TO_POINTER * tools/test-replace.c: Test replacing notifications --- ChangeLog | 8 ++++++-- libnotify/notify.c | 17 +++++++++-------- libnotify/notify.h | 7 ++++--- tools/Makefile.am | 5 ++++- tools/notify-send.c | 2 +- tools/test-replace.c | 28 ++++++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 tools/test-replace.c diff --git a/ChangeLog b/ChangeLog index 97ac332..2820eb6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,11 @@ -Tue Jul 13 23:58:54 2004 Mike Hearn +Wed Jul 14 02:11:48 GMT 2004 Mike Hearn + * libnotify/notify.c: Use pointers instead of GINT_TO_POINTER + * tools/test-replace.c: Test replacing notifications + +Tue Jul 13 23:58:54 GMT 2004 Mike Hearn * SPECIFICATION: CloseNotification sends NotificationClosed signal. -Mon Jul 5 00:12:03 2004 Mike Hearn +Mon Jul 5 00:12:03 GMT 2004 Mike Hearn * tools/notify-send.c (main): Treat expiry times < current time as timeouts from current instant diff --git a/libnotify/notify.c b/libnotify/notify.c index 0890367..bff9d65 100644 --- a/libnotify/notify.c +++ b/libnotify/notify.c @@ -106,9 +106,9 @@ _notify_handle_new(guint32 id) handle->id = id; - handle->replaces = -1; + handle->replaces = 0; - g_hash_table_insert(_handles, GINT_TO_POINTER(id), handle); + g_hash_table_insert(_handles, &handle->id, handle); return handle; } @@ -215,7 +215,7 @@ _filter_func(DBusConnection *dbus_conn, DBusMessage *message, void *user_data) reason = dbus_message_iter_get_uint32(&iter); - g_hash_table_remove(_handles, GINT_TO_POINTER(id)); + g_hash_table_remove(_handles, &id); } else if (dbus_message_is_signal(message, NOTIFY_DBUS_CORE_INTERFACE, "ActionInvoked")) @@ -230,7 +230,7 @@ _filter_func(DBusConnection *dbus_conn, DBusMessage *message, void *user_data) action_id = dbus_message_iter_get_uint32(&iter); - handle = g_hash_table_lookup(_handles, GINT_TO_POINTER(id)); + handle = g_hash_table_lookup(_handles, &id); if (handle->actions_table == NULL) { @@ -243,7 +243,7 @@ _filter_func(DBusConnection *dbus_conn, DBusMessage *message, void *user_data) NotifyAction *action; action = g_hash_table_lookup(handle->actions_table, - GINT_TO_POINTER(action_id)); + &action_id); if (action == NULL) { @@ -578,7 +578,7 @@ notify_icon_destroy(NotifyIcon *icon) * Notifications API **************************************************************************/ NotifyHandle * -notify_send_notification(guint32 replaces, NotifyUrgency urgency, const char *summary, +notify_send_notification(NotifyHandle *replaces, NotifyUrgency urgency, const char *summary, const char *detailed, const NotifyIcon *icon, gboolean expires, time_t expire_time, gpointer user_data, size_t action_count, ...) @@ -598,7 +598,7 @@ notify_send_notification(guint32 replaces, NotifyUrgency urgency, const char *su } NotifyHandle * -notify_send_notification_varg(guint32 replaces, NotifyUrgency urgency, const char *summary, +notify_send_notification_varg(NotifyHandle *replaces, NotifyUrgency urgency, const char *summary, const char *detailed, const NotifyIcon *icon, gboolean expires, time_t expire_time, gpointer user_data, size_t action_count, @@ -619,7 +619,8 @@ notify_send_notification_varg(guint32 replaces, NotifyUrgency urgency, const cha #if 0 _notify_dbus_message_iter_append_app_info(&iter); #endif - dbus_message_iter_append_uint32(&iter, replaces); + + dbus_message_iter_append_uint32(&iter, replaces ? replaces->id : 0); dbus_message_iter_append_byte(&iter, urgency); dbus_message_iter_append_string(&iter, summary); _notify_dbus_message_iter_append_string_or_nil(&iter, detailed); diff --git a/libnotify/notify.h b/libnotify/notify.h index 5c563dd..db53201 100644 --- a/libnotify/notify.h +++ b/libnotify/notify.h @@ -77,6 +77,7 @@ gboolean notify_is_initted(void); */ void notify_close(NotifyHandle *handle); + /** * Returns the server information. * @@ -165,7 +166,7 @@ void notify_icon_destroy(NotifyIcon *icon); * * @return A unique ID for the notification. */ -NotifyHandle *notify_send_notification(guint32 replaces, +NotifyHandle *notify_send_notification(NotifyHandle *replaces, NotifyUrgency urgency, const char *summary, const char *detailed, @@ -183,7 +184,7 @@ NotifyHandle *notify_send_notification(guint32 replaces, * void callback(NotifyHandle *handle, guint32 action, void *user_data); * @endcode * - * @param replaces The ID of the notification to atomically replace + * @param replaces The handle of the notification to atomically replace * @param urgency The urgency level. * @param summary The summary of the notification. * @param detailed The optional detailed information. @@ -198,7 +199,7 @@ NotifyHandle *notify_send_notification(guint32 replaces, * * @return A unique ID for the notification. */ -NotifyHandle *notify_send_notification_varg(guint32 replaces, +NotifyHandle *notify_send_notification_varg(NotifyHandle *replaces, NotifyUrgency urgency, const char *summary, const char *detailed, diff --git a/tools/Makefile.am b/tools/Makefile.am index 7cba1c9..a52ee30 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,4 +1,4 @@ -bin_PROGRAMS = notify-send +bin_PROGRAMS = notify-send test-replace common_ldflags = \ $(top_builddir)/libnotify/libnotify.la \ @@ -8,4 +8,7 @@ common_ldflags = \ notify_send_SOURCES = notify-send.c notify_send_LDADD = $(common_ldflags) +test_replace_SOURCES = test-replace.c +test_replace_LDADD = $(common_ldflags) + INCLUDES = $(PACKAGE_CFLAGS) diff --git a/tools/notify-send.c b/tools/notify-send.c index f1f11ce..d12d89f 100644 --- a/tools/notify-send.c +++ b/tools/notify-send.c @@ -130,7 +130,7 @@ main(int argc, const char **argv) /* if the given time is < current time, treat it as a timeout in seconds (ie 5 seconds) */ if (expire_time && expire_time < time(NULL)) expire_time += time(NULL); - notify_send_notification(0, urgency, summary, description, icon, + notify_send_notification(NULL, urgency, summary, description, icon, TRUE, expire_time, NULL, 0); if (icon != NULL) diff --git a/tools/test-replace.c b/tools/test-replace.c new file mode 100644 index 0000000..feb624e --- /dev/null +++ b/tools/test-replace.c @@ -0,0 +1,28 @@ +#include +#include +#include + +int main() { + notify_init("Replace Test"); + + NotifyHandle *n = notify_send_notification(NULL, // replaces nothing + NOTIFY_URGENCY_NORMAL, + "Summary", "Content", + NULL, // no icon + FALSE, 0, // does not expire + NULL, // no user data + 0); // no actions + + if (!n) { + fprintf(stderr, "failed to send notification\n"); + return 1; + } + + + sleep(3); + + notify_send_notification(n, NOTIFY_URGENCY_NORMAL, "Second Summary", "Second Content", + NULL, TRUE, time(NULL) + 5, NULL, 0); + + return 0; +}