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:
parent
81a5a510b7
commit
7848ca6968
20
ChangeLog
20
ChangeLog
|
@ -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>
|
Mon Jun 20 06:13:02 PDT 2005 Christian Hammond <chipx86@gnupdate.org>
|
||||||
|
|
||||||
* libnotify/notify.c:
|
* libnotify/notify.c:
|
||||||
|
|
|
@ -508,6 +508,38 @@ notify_get_server_caps(void)
|
||||||
return caps;
|
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
|
* Icon API
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
@ -616,7 +648,8 @@ notify_send_notification(NotifyHandle *replaces, const char *type,
|
||||||
NotifyUrgency urgency, const char *summary,
|
NotifyUrgency urgency, const char *summary,
|
||||||
const char *body, const NotifyIcon *icon,
|
const char *body, const NotifyIcon *icon,
|
||||||
gboolean expires, time_t timeout,
|
gboolean expires, time_t timeout,
|
||||||
gpointer user_data, size_t action_count, ...)
|
GHashTable *hints, gpointer user_data,
|
||||||
|
size_t action_count, ...)
|
||||||
{
|
{
|
||||||
va_list actions;
|
va_list actions;
|
||||||
NotifyHandle *handle;
|
NotifyHandle *handle;
|
||||||
|
@ -626,20 +659,37 @@ notify_send_notification(NotifyHandle *replaces, const char *type,
|
||||||
va_start(actions, action_count);
|
va_start(actions, action_count);
|
||||||
handle = notify_send_notification_varg(replaces, type, urgency, summary,
|
handle = notify_send_notification_varg(replaces, type, urgency, summary,
|
||||||
body, icon, expires,
|
body, icon, expires,
|
||||||
timeout, user_data,
|
timeout, hints, user_data,
|
||||||
action_count, actions);
|
action_count, actions);
|
||||||
va_end(actions);
|
va_end(actions);
|
||||||
|
|
||||||
return handle;
|
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 *
|
NotifyHandle *
|
||||||
notify_send_notification_varg(NotifyHandle *replaces, const char *type,
|
notify_send_notification_varg(NotifyHandle *replaces, const char *type,
|
||||||
NotifyUrgency urgency, const char *summary,
|
NotifyUrgency urgency, const char *summary,
|
||||||
const char *body, const NotifyIcon *icon,
|
const char *body, const NotifyIcon *icon,
|
||||||
gboolean expires, time_t timeout,
|
gboolean expires, time_t timeout,
|
||||||
gpointer user_data, size_t action_count,
|
GHashTable *hints, gpointer user_data,
|
||||||
va_list actions)
|
size_t action_count, va_list actions)
|
||||||
{
|
{
|
||||||
DBusMessage *message, *reply;
|
DBusMessage *message, *reply;
|
||||||
DBusMessageIter iter, array_iter, dict_iter;
|
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_TYPE_STRING_AS_STRING
|
||||||
DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
|
DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
|
||||||
&dict_iter);
|
&dict_iter);
|
||||||
dbus_message_iter_close_container(&iter, &dict_iter);
|
|
||||||
#else
|
#else
|
||||||
dbus_message_iter_append_dict(&iter, &dict_iter);
|
dbus_message_iter_append_dict(&iter, &dict_iter);
|
||||||
#endif
|
#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 */
|
/* Expires */
|
||||||
_notify_dbus_message_iter_append_boolean(&iter, 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_message_unref(reply);
|
||||||
dbus_error_free(&error);
|
dbus_error_free(&error);
|
||||||
|
|
||||||
|
if (hints != NULL)
|
||||||
|
g_hash_table_destroy(hints);
|
||||||
|
|
||||||
handle = _notify_handle_new(id);
|
handle = _notify_handle_new(id);
|
||||||
handle->actions_table = table;
|
handle->actions_table = table;
|
||||||
handle->action_count = action_count;
|
handle->action_count = action_count;
|
||||||
|
|
|
@ -42,6 +42,7 @@ typedef enum
|
||||||
|
|
||||||
typedef struct _NotifyHandle NotifyHandle;
|
typedef struct _NotifyHandle NotifyHandle;
|
||||||
typedef struct _NotifyIcon NotifyIcon;
|
typedef struct _NotifyIcon NotifyIcon;
|
||||||
|
typedef GHashTable NotifyHints;
|
||||||
|
|
||||||
typedef void (*NotifyCallback)(NotifyHandle *, guint32, gpointer);
|
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 */
|
/** @name NotifyIcon API */
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
@ -206,6 +241,7 @@ void notify_icon_destroy(NotifyIcon *icon);
|
||||||
* or FALSE to keep it open until manually closed.
|
* or FALSE to keep it open until manually closed.
|
||||||
* @param timeout The optional timeout to automatically close the
|
* @param timeout The optional timeout to automatically close the
|
||||||
* notification, or 0 for the daemon's default.
|
* 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 user_data User-specified data to send to a callback.
|
||||||
* @param action_count The number of actions.
|
* @param action_count The number of actions.
|
||||||
* @param ... The actions in uint32/string/callback sets.
|
* @param ... The actions in uint32/string/callback sets.
|
||||||
|
@ -219,6 +255,7 @@ NotifyHandle *notify_send_notification(NotifyHandle *replaces,
|
||||||
const char *body,
|
const char *body,
|
||||||
const NotifyIcon *icon,
|
const NotifyIcon *icon,
|
||||||
gboolean expires, time_t timeout,
|
gboolean expires, time_t timeout,
|
||||||
|
NotifyHints *hints,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
size_t action_count, ...);
|
size_t action_count, ...);
|
||||||
|
|
||||||
|
@ -241,6 +278,7 @@ NotifyHandle *notify_send_notification(NotifyHandle *replaces,
|
||||||
* or FALSE to keep it open until manually closed.
|
* or FALSE to keep it open until manually closed.
|
||||||
* @param timeout The optional timeout to automatically close the
|
* @param timeout The optional timeout to automatically close the
|
||||||
* notification, or 0 for the daemon's default.
|
* 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 user_data User-specified data to send to a callback.
|
||||||
* @param action_count The number of actions.
|
* @param action_count The number of actions.
|
||||||
* @param actions The actions in string/callback pairs.
|
* @param actions The actions in string/callback pairs.
|
||||||
|
@ -255,6 +293,7 @@ NotifyHandle *notify_send_notification_varg(NotifyHandle *replaces,
|
||||||
const NotifyIcon *icon,
|
const NotifyIcon *icon,
|
||||||
gboolean expires,
|
gboolean expires,
|
||||||
time_t timeout,
|
time_t timeout,
|
||||||
|
NotifyHints *hints,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
size_t action_count,
|
size_t action_count,
|
||||||
va_list actions);
|
va_list actions);
|
||||||
|
|
|
@ -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 = \
|
common_ldflags = \
|
||||||
$(top_builddir)/libnotify/libnotify.la \
|
$(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_SOURCES = test-markup.c
|
||||||
test_markup_LDADD = $(common_ldflags)
|
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`
|
INCLUDES = $(PACKAGE_CFLAGS) `pkg-config --cflags gdk-pixbuf-2.0`
|
||||||
|
|
|
@ -93,6 +93,7 @@ int main()
|
||||||
"Summary", "Content",
|
"Summary", "Content",
|
||||||
icon,
|
icon,
|
||||||
TRUE, time(NULL) + 5,
|
TRUE, time(NULL) + 5,
|
||||||
|
NULL, // no hints
|
||||||
NULL, // no user data
|
NULL, // no user data
|
||||||
0); // no actions
|
0); // no actions
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ int main() {
|
||||||
"Summary", "Content",
|
"Summary", "Content",
|
||||||
NULL, // no icon
|
NULL, // no icon
|
||||||
TRUE, time(NULL) + 5,
|
TRUE, time(NULL) + 5,
|
||||||
|
NULL, // no hints
|
||||||
NULL, // no user data
|
NULL, // no user data
|
||||||
0); // no actions
|
0); // no actions
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,7 @@ main()
|
||||||
"Matt is online", NULL,
|
"Matt is online", NULL,
|
||||||
NULL, // no icon
|
NULL, // no icon
|
||||||
FALSE, 0, // does not expire
|
FALSE, 0, // does not expire
|
||||||
|
NULL, // no hints
|
||||||
NULL, // no user data
|
NULL, // no user data
|
||||||
1,
|
1,
|
||||||
0, "default", callback); // 1 action
|
0, "default", callback); // 1 action
|
||||||
|
|
|
@ -34,6 +34,7 @@ int main() {
|
||||||
"Summary", "Content",
|
"Summary", "Content",
|
||||||
icon, // no icon
|
icon, // no icon
|
||||||
TRUE, time(NULL) + 5,
|
TRUE, time(NULL) + 5,
|
||||||
|
NULL, // no hints
|
||||||
NULL, // no user data
|
NULL, // no user data
|
||||||
0);
|
0);
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ static void send(char *i, size_t rawlen, char *s, char *b)
|
||||||
s, b,
|
s, b,
|
||||||
icon,
|
icon,
|
||||||
TRUE, time(NULL) + 5,
|
TRUE, time(NULL) + 5,
|
||||||
|
NULL, // no hints
|
||||||
NULL, // no user data
|
NULL, // no user data
|
||||||
0);
|
0);
|
||||||
|
|
||||||
|
|
|
@ -32,9 +32,10 @@ int main() {
|
||||||
NOTIFY_URGENCY_NORMAL,
|
NOTIFY_URGENCY_NORMAL,
|
||||||
"Summary",
|
"Summary",
|
||||||
"Some <b>bold</b>, <u>underlined</u>, <i>italic</i>, "
|
"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
|
NULL, // no icon
|
||||||
TRUE, time(NULL) + 5,
|
TRUE, time(NULL) + 5,
|
||||||
|
NULL, // no hints
|
||||||
NULL, // no user data
|
NULL, // no user data
|
||||||
0); // no actions
|
0); // no actions
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@ int main() {
|
||||||
"emptying the trash can.",
|
"emptying the trash can.",
|
||||||
NULL, // no icon
|
NULL, // no icon
|
||||||
FALSE, 0, // does not expire
|
FALSE, 0, // does not expire
|
||||||
|
NULL, // no hints
|
||||||
NULL, // no user data
|
NULL, // no user data
|
||||||
3, // 3 actions
|
3, // 3 actions
|
||||||
0, "default", callback,
|
0, "default", callback,
|
||||||
|
|
|
@ -32,6 +32,7 @@ int main() {
|
||||||
"Summary", "Content",
|
"Summary", "Content",
|
||||||
NULL, // no icon
|
NULL, // no icon
|
||||||
FALSE, 0, // does not expire
|
FALSE, 0, // does not expire
|
||||||
|
NULL, // no hints
|
||||||
NULL, // no user data
|
NULL, // no user data
|
||||||
0); // no actions
|
0); // no actions
|
||||||
|
|
||||||
|
@ -41,12 +42,11 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sleep(3);
|
sleep(20);
|
||||||
|
|
||||||
notify_send_notification(n, NULL, NOTIFY_URGENCY_NORMAL,
|
notify_send_notification(n, NULL, NOTIFY_URGENCY_NORMAL,
|
||||||
"Second Summary", "Second Content",
|
"Second Summary", "Second Content",
|
||||||
NULL, TRUE, 5, NULL, 0);
|
NULL, TRUE, 5, NULL, NULL, 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -126,7 +126,7 @@ main(int argc, const char **argv)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
notify_send_notification(NULL, type, urgency, summary, body, icon,
|
notify_send_notification(NULL, type, urgency, summary, body, icon,
|
||||||
TRUE, expire_timeout, NULL, 0);
|
TRUE, expire_timeout, NULL, NULL, 0);
|
||||||
|
|
||||||
if (icon != NULL)
|
if (icon != NULL)
|
||||||
notify_icon_destroy(icon);
|
notify_icon_destroy(icon);
|
||||||
|
|
Loading…
Reference in New Issue