A few things I did on the way home:

- Added support for hints in the API.
- Don't install the test programs during make install.
This commit is contained in:
Christian Hammond 2005-07-01 06:42:29 +00:00
parent 81a5a510b7
commit 7848ca6968
14 changed files with 203 additions and 11 deletions

View File

@ -1,3 +1,23 @@
Thu Jun 30 21:09:18 PDT 2005 Christian Hammond <chipx86@chipx86.com>
* tests/Makefile.am:
- Don't install the test programs during make install.
Thu Jun 30 21:03:30 PDT 2005 Christian Hammond <chipx86@chipx86.com>
* 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 <chipx86@gnupdate.org>
* libnotify/notify.c:

View File

@ -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;

View File

@ -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);

View File

@ -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`

View File

@ -93,6 +93,7 @@ int main()
"Summary", "Content",
icon,
TRUE, time(NULL) + 5,
NULL, // no hints
NULL, // no user data
0); // no actions

View File

@ -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

View File

@ -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

View File

@ -34,6 +34,7 @@ int main() {
"Summary", "Content",
icon, // no icon
TRUE, time(NULL) + 5,
NULL, // no hints
NULL, // no user data
0);

View File

@ -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);

View File

@ -32,9 +32,10 @@ int main() {
NOTIFY_URGENCY_NORMAL,
"Summary",
"Some <b>bold</b>, <u>underlined</u>, <i>italic</i>, "
"<a href='google.com'>linked</a> text",
"<a href='http://www.google.com'>linked</a> text",
NULL, // no icon
TRUE, time(NULL) + 5,
NULL, // no hints
NULL, // no user data
0); // no actions

View File

@ -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,

View File

@ -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;
}

53
tests/test-xy.c Normal file
View File

@ -0,0 +1,53 @@
/*
* @file tests/test-xy.c Unit test: X, Y hints
*
* @Copyright (C) 2005 Christian Hammond <chipx86@chipx86.com>
*
* 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 <libnotify/notify.h>
#include <stdio.h>
#include <unistd.h>
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;
}

View File

@ -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);