diff options
author | Christian Hammond <chipx86@chipx86.com> | 2005-07-28 08:54:18 +0000 |
---|---|---|
committer | Christian Hammond <chipx86@chipx86.com> | 2005-07-28 08:54:18 +0000 |
commit | 07e112a7ee445e3da68b77fbcd5cdb32a391b2ef (patch) | |
tree | 9a16ee68732565b01a3811c8ee031dcb55dd1f18 | |
parent | b2b4e09eb67d2daff1b79585cd0c213561b70a4b (diff) | |
download | libnotify-07e112a7ee445e3da68b77fbcd5cdb32a391b2ef.tar.gz |
Don't send all hint values as strings. Send as integers, booleans, or strings, depending on what the user set.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | configure.ac | 8 | ||||
-rw-r--r-- | docs/notification-spec.xml | 28 | ||||
-rw-r--r-- | libnotify/notify.c | 139 | ||||
-rw-r--r-- | libnotify/notify.h | 2 |
6 files changed, 167 insertions, 19 deletions
@@ -1,3 +1,10 @@ +Thu Jul 28 01:52:03 PDT 2005 Christian Hammond <chipx86@chipx86.com> + + * 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 <chipx86@chipx86.com> * libnotify/notify.c: @@ -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 @@ <article id="index"> <articleinfo> <title>Desktop Notifications Specification</title> - <releaseinfo>Version 0.5</releaseinfo> - <date>2 October 2004</date> + <releaseinfo>Version 0.7</releaseinfo> + <date>28 July 2005</date> <authorgroup> <author> <firstname>Mike</firstname> @@ -30,6 +30,14 @@ </authorgroup> <revhistory> <revision> + <revnumber>0.7</revnumber> + <date>28 July 2005</date> + <authorinitials>cdh</authorinitials> + <revremark> + Added "x" and "y" hints. + </revremark> + </revision> + <revision> <revnumber>0.6</revnumber> <date>1 April 2005</date> <authorinitials>cdh</authorinitials> @@ -726,6 +734,22 @@ play its own sound. </entry> </row> + <row> + <entry><literal>"x"</literal></entry> + <entry>int</entry> + <entry> + Specifies the X location on the screen that the notification should + point to. The <literal>"y"</literal> hint must also be specified. + </entry> + </row> + <row> + <entry><literal>"y"</literal></entry> + <entry>int</entry> + <entry> + Specifies the Y location on the screen that the notification should + point to. The <literal>"x"</literal> hint must also be specified. + </entry> + </row> </tbody> </tgroup> </table> 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); |