diff --git a/ChangeLog b/ChangeLog index 1979970..9fc8a27 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Jul 28 01:52:03 PDT 2005 Christian Hammond + + * libnotify/notify.c: + * libnotify/notify.h: + - Don't send all hint values as strings. Send as integers, booleans, + or strings, depending on what the user set. + Wed Jul 27 23:08:43 PDT 2005 Christian Hammond * libnotify/notify.c: diff --git a/NEWS b/NEWS index e69de29..acd1b8a 100644 --- a/NEWS +++ b/NEWS @@ -0,0 +1,2 @@ +version 0.2.0: (28-July-2005): + * Initial public release. diff --git a/configure.ac b/configure.ac index d4c7b82..729349a 100644 --- a/configure.ac +++ b/configure.ac @@ -3,18 +3,18 @@ dnl Process this file with autoconf to create configure. dnl ################################################################ dnl # Initialize autoconf dnl ################################################################ -AC_INIT(libnotify, 0.0.1, chipx86@gnupdate.org) +AC_INIT(libnotify, 0.2.0, chipx86@chipx86.com) AC_PREREQ(2.50) AC_CONFIG_SRCDIR(config.h.in) -AC_COPYRIGHT([Copyright 2004 Christian Hammond]) +AC_COPYRIGHT([Copyright 2004-2005 Christian Hammond]) dnl ################################################################ dnl # Version information dnl ################################################################ LIBGALAGO_MAJOR_VERSION=0 -LIBGALAGO_MINOR_VERSION=0 -LIBGALAGO_MICRO_VERSION=1 +LIBGALAGO_MINOR_VERSION=2 +LIBGALAGO_MICRO_VERSION=0 LIBGALAGO_DEVEL_VERSION=0 LIBGALAGO_VERSION=$LIBGALAGO_MAJOR_VERSION.$LIBGALAGO_MINOR_VERSION.$LIBGALAGO_MICRO_VERSION diff --git a/docs/notification-spec.xml b/docs/notification-spec.xml index 484a212..e187c14 100644 --- a/docs/notification-spec.xml +++ b/docs/notification-spec.xml @@ -6,8 +6,8 @@
Desktop Notifications Specification - Version 0.5 - 2 October 2004 + Version 0.7 + 28 July 2005 Mike @@ -29,6 +29,14 @@ + + 0.7 + 28 July 2005 + cdh + + Added "x" and "y" hints. + + 0.6 1 April 2005 @@ -726,6 +734,22 @@ play its own sound. + + "x" + int + + Specifies the X location on the screen that the notification should + point to. The "y" hint must also be specified. + + + + "y" + int + + Specifies the Y location on the screen that the notification should + point to. The "x" hint must also be specified. + + diff --git a/libnotify/notify.c b/libnotify/notify.c index ff9e144..55998c1 100644 --- a/libnotify/notify.c +++ b/libnotify/notify.c @@ -67,6 +67,11 @@ struct _NotifyIcon guchar **raw_data; }; +struct _NotifyHints +{ + GHashTable *data; +}; + typedef struct { guint32 id; @@ -581,41 +586,101 @@ notify_get_server_caps(void) /************************************************************************** * Notify Hints API **************************************************************************/ +typedef enum +{ + HINT_TYPE_STRING, + HINT_TYPE_INT, + HINT_TYPE_BOOL + +} NotifyHintType; + +typedef struct +{ + NotifyHintType type; + + union + { + char *string; + int integer; + gboolean boolean; + } u; + +} NotifyHintData; + +static void +destroy_hint(NotifyHintData *hint_data) +{ + if (hint_data->type == HINT_TYPE_STRING) + g_free(hint_data->u.string); + + g_free(hint_data); +} NotifyHints * notify_hints_new(void) { - return g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + NotifyHints *hints = g_new0(NotifyHints, 1); + + hints->data = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, (GFreeFunc)destroy_hint); + + return hints; +} + +void +notify_hints_destroy(NotifyHints *hints) +{ + g_return_if_fail(hints != NULL); + + g_hash_table_destroy(hints->data); + g_free(hints); } void notify_hints_set_string(NotifyHints *hints, const char *key, const char *value) { + NotifyHintData *hint_data; + g_return_if_fail(hints != NULL); g_return_if_fail(key != NULL && *key != '\0'); g_return_if_fail(value != NULL && *value != '\0'); - g_hash_table_replace(hints, g_strdup(key), g_strdup(value)); + hint_data = g_new0(NotifyHintData, 1); + hint_data->type = HINT_TYPE_STRING; + hint_data->u.string = g_strdup(value); + + g_hash_table_replace(hints->data, g_strdup(key), hint_data); } void notify_hints_set_int(NotifyHints *hints, const char *key, int value) { + NotifyHintData *hint_data; + g_return_if_fail(hints != NULL); g_return_if_fail(key != NULL && *key != '\0'); - g_hash_table_replace(hints, g_strdup(key), g_strdup_printf("%d", value)); + hint_data = g_new0(NotifyHintData, 1); + hint_data->type = HINT_TYPE_INT; + hint_data->u.integer = value; + + g_hash_table_replace(hints->data, g_strdup(key), hint_data); } void notify_hints_set_bool(NotifyHints *hints, const char *key, gboolean value) { + NotifyHintData *hint_data; + g_return_if_fail(hints != NULL); g_return_if_fail(key != NULL && *key != '\0'); - g_hash_table_replace(hints, g_strdup(key), - g_strdup(value? "true" : "false")); + hint_data = g_new0(NotifyHintData, 1); + hint_data->type = HINT_TYPE_BOOL; + hint_data->u.boolean = value; + + g_hash_table_replace(hints->data, g_strdup(key), hint_data); } @@ -727,7 +792,7 @@ notify_send_notification(NotifyHandle *replaces, const char *type, NotifyUrgency urgency, const char *summary, const char *body, const NotifyIcon *icon, gboolean expires, time_t timeout, - GHashTable *hints, gpointer user_data, + NotifyHints *hints, gpointer user_data, size_t action_count, ...) { va_list actions; @@ -746,7 +811,8 @@ notify_send_notification(NotifyHandle *replaces, const char *type, } static void -hint_foreach_func(const gchar *key, const gchar *value, DBusMessageIter *iter) +hint_foreach_func(const gchar *key, NotifyHintData *hint, + DBusMessageIter *iter) { #if NOTIFY_CHECK_DBUS_VERSION(0, 30) DBusMessageIter entry_iter; @@ -754,11 +820,59 @@ hint_foreach_func(const gchar *key, const gchar *value, DBusMessageIter *iter) dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL, &entry_iter); dbus_message_iter_append_basic(&entry_iter, DBUS_TYPE_STRING, &key); - dbus_message_iter_append_basic(&entry_iter, DBUS_TYPE_STRING, &value); + + switch (hint->type) + { + case HINT_TYPE_STRING: + dbus_message_iter_append_basic(&entry_iter, DBUS_TYPE_STRING, + &hint->u.string); + break; + + case HINT_TYPE_INT: + dbus_message_iter_append_basic(&entry_iter, DBUS_TYPE_INT32, + &hint->u.integer); + break; + + case HINT_TYPE_BOOL: + dbus_message_iter_append_basic(&entry_iter, DBUS_TYPE_BOOLEAN, + &hint->u.boolean); + break; + + default: + { + /* Better than nothing... */ + char *empty = ""; + dbus_message_iter_append_basic(&entry_iter, DBUS_TYPE_STRING, + &empty); + break; + } + } + dbus_message_iter_close_container(iter, &entry_iter); #else dbus_message_iter_append_dict_key(iter, key); - dbus_message_iter_append_string(iter, value); + + switch (hint->type) + { + case HINT_TYPE_STRING: + dbus_message_iter_append_string(iter, hint->u.string); + break; + + case HINT_TYPE_INT: + dbus_message_iter_append_int32(iter, hint->u.integer); + break; + + case HINT_TYPE_BOOL: + dbus_message_iter_append_boolean(iter, hint->u.boolean); + break; + + default: + { + /* Better than nothing... */ + dbus_message_iter_append_string(iter, ""); + break; + } + } #endif } @@ -767,7 +881,7 @@ notify_send_notification_varg(NotifyHandle *replaces, const char *type, NotifyUrgency urgency, const char *summary, const char *body, const NotifyIcon *icon, gboolean expires, time_t timeout, - GHashTable *hints, gpointer user_data, + NotifyHints *hints, gpointer user_data, size_t action_count, va_list actions) { DBusMessage *message, *reply; @@ -904,7 +1018,8 @@ notify_send_notification_varg(NotifyHandle *replaces, const char *type, if (hints != NULL) { - g_hash_table_foreach(hints, (GHFunc)hint_foreach_func, &dict_iter); + g_hash_table_foreach(hints->data, + (GHFunc)hint_foreach_func, &dict_iter); } #if NOTIFY_CHECK_DBUS_VERSION(0, 30) @@ -943,7 +1058,7 @@ notify_send_notification_varg(NotifyHandle *replaces, const char *type, dbus_error_free(&error); if (hints != NULL) - g_hash_table_destroy(hints); + notify_hints_destroy(hints); handle = _notify_handle_new(id); handle->actions_table = table; diff --git a/libnotify/notify.h b/libnotify/notify.h index ba3460f..0ddfeba 100644 --- a/libnotify/notify.h +++ b/libnotify/notify.h @@ -41,7 +41,7 @@ typedef enum typedef struct _NotifyHandle NotifyHandle; typedef struct _NotifyIcon NotifyIcon; -typedef GHashTable NotifyHints; +typedef struct _NotifyHints NotifyHints; typedef void (*NotifyCallback)(NotifyHandle *, guint32, gpointer);