diff --git a/ChangeLog b/ChangeLog index 7c625c2..b404feb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +Thu Jun 30 21:09:18 PDT 2005 Christian Hammond + + * tests/Makefile.am: + - Don't install the test programs during make install. + +Thu Jun 30 21:03:30 PDT 2005 Christian Hammond + + * libnotify/notify.c: + * libnotify/notify.h: + * tests/test-animation.c: + * tests/test-basic.c: + * tests/test-default-action.c: + * tests/test-error.c: + * tests/test-image.c: + * tests/test-markup.c: + * tests/test-multi-actions.c: + * tests/test-replace.c: + * tools/notify-send.c: + - Added support for hints in the API. + Mon Jun 20 06:13:02 PDT 2005 Christian Hammond * libnotify/notify.c: diff --git a/libnotify/notify.c b/libnotify/notify.c index 85e5cc2..7551db3 100644 --- a/libnotify/notify.c +++ b/libnotify/notify.c @@ -508,6 +508,38 @@ notify_get_server_caps(void) return caps; } + +/************************************************************************** + * Notify Hints API + **************************************************************************/ + +NotifyHints * +notify_hints_new(void) +{ + return g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); +} + +void +notify_hints_set_string(NotifyHints *hints, const char *key, + const char *value) +{ + 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)); +} + +void +notify_hints_set_int(NotifyHints *hints, const char *key, int value) +{ + 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)); +} + + /************************************************************************** * Icon API **************************************************************************/ @@ -616,7 +648,8 @@ notify_send_notification(NotifyHandle *replaces, const char *type, NotifyUrgency urgency, const char *summary, const char *body, const NotifyIcon *icon, gboolean expires, time_t timeout, - gpointer user_data, size_t action_count, ...) + GHashTable *hints, gpointer user_data, + size_t action_count, ...) { va_list actions; NotifyHandle *handle; @@ -626,20 +659,37 @@ notify_send_notification(NotifyHandle *replaces, const char *type, va_start(actions, action_count); handle = notify_send_notification_varg(replaces, type, urgency, summary, body, icon, expires, - timeout, user_data, + timeout, hints, user_data, action_count, actions); va_end(actions); return handle; } +static void +hint_foreach_func(const gchar *key, const gchar *value, DBusMessageIter *iter) +{ +#if NOTIFY_CHECK_DBUS_VERSION(0, 30) + DBusMessageIter entry_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); + dbus_message_iter_close_container(iter, &entry_iter); +#else + dbus_message_iter_append_dict_key(iter, key); + dbus_message_iter_append_string(iter, value); +#endif +} + NotifyHandle * 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, - gpointer user_data, size_t action_count, - va_list actions) + GHashTable *hints, gpointer user_data, + size_t action_count, va_list actions) { DBusMessage *message, *reply; DBusMessageIter iter, array_iter, dict_iter; @@ -769,11 +819,19 @@ notify_send_notification_varg(NotifyHandle *replaces, const char *type, DBUS_TYPE_STRING_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict_iter); - dbus_message_iter_close_container(&iter, &dict_iter); #else dbus_message_iter_append_dict(&iter, &dict_iter); #endif + if (hints != NULL) + { + g_hash_table_foreach(hints, (GHFunc)hint_foreach_func, &dict_iter); + } + +#if NOTIFY_CHECK_DBUS_VERSION(0, 30) + dbus_message_iter_close_container(&iter, &dict_iter); +#endif + /* Expires */ _notify_dbus_message_iter_append_boolean(&iter, expires); @@ -805,6 +863,9 @@ notify_send_notification_varg(NotifyHandle *replaces, const char *type, dbus_message_unref(reply); dbus_error_free(&error); + if (hints != NULL) + g_hash_table_destroy(hints); + handle = _notify_handle_new(id); handle->actions_table = table; handle->action_count = action_count; diff --git a/libnotify/notify.h b/libnotify/notify.h index 54584b5..d31f3c2 100644 --- a/libnotify/notify.h +++ b/libnotify/notify.h @@ -42,6 +42,7 @@ typedef enum typedef struct _NotifyHandle NotifyHandle; typedef struct _NotifyIcon NotifyIcon; +typedef GHashTable NotifyHints; typedef void (*NotifyCallback)(NotifyHandle *, guint32, gpointer); @@ -107,6 +108,40 @@ GList *notify_get_server_caps(void); /*@}*/ +/**************************************************************************/ +/** @name Hints API */ +/**************************************************************************/ +/*@{*/ + +/** + * Creates a hints table. + * + * @return A hints table. + */ +NotifyHints *notify_hints_new(void); + +/** + * Adds a string value to the hints table. + * + * @param hints The hints table. + * @param key The key. + * @param value The value. + */ +void notify_hints_set_string(NotifyHints *hints, const char *key, + const char *value); + +/** + * Adds an integer value to the hints table. + * + * @param hints The hints table. + * @param key The key. + * @param value The value. + */ +void notify_hints_set_int(NotifyHints *hints, const char *key, int value); + +/*@}*/ + + /**************************************************************************/ /** @name NotifyIcon API */ /**************************************************************************/ @@ -206,6 +241,7 @@ void notify_icon_destroy(NotifyIcon *icon); * or FALSE to keep it open until manually closed. * @param timeout The optional timeout to automatically close the * notification, or 0 for the daemon's default. + * @param hints A hashtable of hints. * @param user_data User-specified data to send to a callback. * @param action_count The number of actions. * @param ... The actions in uint32/string/callback sets. @@ -219,6 +255,7 @@ NotifyHandle *notify_send_notification(NotifyHandle *replaces, const char *body, const NotifyIcon *icon, gboolean expires, time_t timeout, + NotifyHints *hints, gpointer user_data, size_t action_count, ...); @@ -241,6 +278,7 @@ NotifyHandle *notify_send_notification(NotifyHandle *replaces, * or FALSE to keep it open until manually closed. * @param timeout The optional timeout to automatically close the * notification, or 0 for the daemon's default. + * @param hints A hashtable of hints. * @param user_data User-specified data to send to a callback. * @param action_count The number of actions. * @param actions The actions in string/callback pairs. @@ -255,6 +293,7 @@ NotifyHandle *notify_send_notification_varg(NotifyHandle *replaces, const NotifyIcon *icon, gboolean expires, time_t timeout, + NotifyHints *hints, gpointer user_data, size_t action_count, va_list actions); diff --git a/tests/Makefile.am b/tests/Makefile.am index cf0b73e..cdc38ab 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,13 @@ -bin_PROGRAMS = test-replace test-default-action test-multi-actions test-image test-basic test-error test-animation test-markup +noinst_PROGRAMS = \ + test-replace \ + test-default-action \ + test-multi-actions \ + test-image \ + test-basic \ + test-error \ + test-animation \ + test-markup \ + test-xy common_ldflags = \ $(top_builddir)/libnotify/libnotify.la \ @@ -26,4 +35,7 @@ test_animation_LDFLAGS = `pkg-config --libs gdk-pixbuf-2.0` test_markup_SOURCES = test-markup.c test_markup_LDADD = $(common_ldflags) +test_xy_SOURCES = test-xy.c +test_xy_LDADD = $(common_ldflags) + INCLUDES = $(PACKAGE_CFLAGS) `pkg-config --cflags gdk-pixbuf-2.0` diff --git a/tests/test-animation.c b/tests/test-animation.c index e6a0eb5..4f99480 100644 --- a/tests/test-animation.c +++ b/tests/test-animation.c @@ -93,6 +93,7 @@ int main() "Summary", "Content", icon, TRUE, time(NULL) + 5, + NULL, // no hints NULL, // no user data 0); // no actions diff --git a/tests/test-basic.c b/tests/test-basic.c index 24d17ca..6c712b3 100644 --- a/tests/test-basic.c +++ b/tests/test-basic.c @@ -32,6 +32,7 @@ int main() { "Summary", "Content", NULL, // no icon TRUE, time(NULL) + 5, + NULL, // no hints NULL, // no user data 0); // no actions diff --git a/tests/test-default-action.c b/tests/test-default-action.c index 8327417..3f0a2ca 100644 --- a/tests/test-default-action.c +++ b/tests/test-default-action.c @@ -60,6 +60,7 @@ main() "Matt is online", NULL, NULL, // no icon FALSE, 0, // does not expire + NULL, // no hints NULL, // no user data 1, 0, "default", callback); // 1 action diff --git a/tests/test-error.c b/tests/test-error.c index 227a772..385eec5 100644 --- a/tests/test-error.c +++ b/tests/test-error.c @@ -34,6 +34,7 @@ int main() { "Summary", "Content", icon, // no icon TRUE, time(NULL) + 5, + NULL, // no hints NULL, // no user data 0); diff --git a/tests/test-image.c b/tests/test-image.c index 726f744..7329319 100644 --- a/tests/test-image.c +++ b/tests/test-image.c @@ -56,6 +56,7 @@ static void send(char *i, size_t rawlen, char *s, char *b) s, b, icon, TRUE, time(NULL) + 5, + NULL, // no hints NULL, // no user data 0); diff --git a/tests/test-markup.c b/tests/test-markup.c index 9843884..6f3179f 100644 --- a/tests/test-markup.c +++ b/tests/test-markup.c @@ -32,9 +32,10 @@ int main() { NOTIFY_URGENCY_NORMAL, "Summary", "Some bold, underlined, italic, " - "linked text", + "linked text", NULL, // no icon TRUE, time(NULL) + 5, + NULL, // no hints NULL, // no user data 0); // no actions diff --git a/tests/test-multi-actions.c b/tests/test-multi-actions.c index 039a83d..2aa4cc8 100644 --- a/tests/test-multi-actions.c +++ b/tests/test-multi-actions.c @@ -71,6 +71,7 @@ int main() { "emptying the trash can.", NULL, // no icon FALSE, 0, // does not expire + NULL, // no hints NULL, // no user data 3, // 3 actions 0, "default", callback, diff --git a/tests/test-replace.c b/tests/test-replace.c index 47991dd..668caba 100644 --- a/tests/test-replace.c +++ b/tests/test-replace.c @@ -32,6 +32,7 @@ int main() { "Summary", "Content", NULL, // no icon FALSE, 0, // does not expire + NULL, // no hints NULL, // no user data 0); // no actions @@ -41,12 +42,11 @@ int main() { } - sleep(3); + sleep(20); notify_send_notification(n, NULL, NOTIFY_URGENCY_NORMAL, "Second Summary", "Second Content", - NULL, TRUE, 5, NULL, 0); + NULL, TRUE, 5, NULL, NULL, 0); return 0; } - diff --git a/tests/test-xy.c b/tests/test-xy.c new file mode 100644 index 0000000..2c6ee96 --- /dev/null +++ b/tests/test-xy.c @@ -0,0 +1,53 @@ +/* + * @file tests/test-xy.c Unit test: X, Y hints + * + * @Copyright (C) 2005 Christian Hammond + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include + +int main() { + GHashTable *hints; + + notify_init("XY"); + + hints = notify_hints_new(); + notify_hints_set_int(hints, "x", 150); + notify_hints_set_int(hints, "y", 10); + + NotifyHandle *n = notify_send_notification( + NULL, // replaces nothing + NULL, + NOTIFY_URGENCY_NORMAL, + "X, Y Test", + "This notification should point to 150, 10.", + NULL, // no icon + TRUE, time(NULL) + 5, + hints, + NULL, // no user data + 0); // no actions + + if (!n) { + fprintf(stderr, "failed to send notification\n"); + return 1; + } + + return 0; +} diff --git a/tools/notify-send.c b/tools/notify-send.c index 25ba848..63a61ff 100644 --- a/tools/notify-send.c +++ b/tools/notify-send.c @@ -126,7 +126,7 @@ main(int argc, const char **argv) exit(1); notify_send_notification(NULL, type, urgency, summary, body, icon, - TRUE, expire_timeout, NULL, 0); + TRUE, expire_timeout, NULL, NULL, 0); if (icon != NULL) notify_icon_destroy(icon);