Don't send all hint values as strings. Send as integers, booleans, or strings, depending on what the user set.
This commit is contained in:
parent
b2b4e09eb6
commit
07e112a7ee
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
@ -29,6 +29,14 @@
|
|||
</author>
|
||||
</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>
|
||||
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue