Implement per-action user data.

This commit is contained in:
Christian Hammond 2006-01-20 10:11:23 +00:00
parent 85342c8619
commit 8297e321bf
5 changed files with 51 additions and 13 deletions

View File

@ -1,3 +1,11 @@
Fri Jan 20 02:10:50 PST 2006 Christian Hammond <chipx86@chipx86.com>
* libnotify/notification.c:
* libnotify/notification.h:
* tests/test-default-action.c:
* tests/test-multi-actions.c:
- Implement per-action user data.
Fri Jan 20 01:59:26 PST 2006 Christian Hammond <chipx86@chipx86.com>
* docs/notification-spec.xml:

View File

@ -37,6 +37,14 @@ static void _action_signal_handler(DBusGProxy *proxy, guint32 id,
gchar *action,
NotifyNotification *notification);
typedef struct
{
NotifyActionCallback cb;
GFreeFunc free_func;
gpointer user_data;
} CallbackPair;
struct _NotifyNotificationPrivate
{
guint32 id;
@ -115,6 +123,15 @@ _g_value_free(GValue *value)
g_free(value);
}
static void
destroy_pair(CallbackPair *pair)
{
if (pair->user_data != NULL && pair->free_func != NULL)
pair->free_func(pair->user_data);
g_free(pair);
}
static void
notify_notification_init(NotifyNotification *obj)
{
@ -131,7 +148,8 @@ notify_notification_init(NotifyNotification *obj)
(GFreeFunc)_g_value_free);
obj->priv->action_map = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, NULL);
g_free,
(GFreeFunc)destroy_pair);
obj->priv->attached_widget = NULL;
@ -351,7 +369,7 @@ static void
_action_signal_handler(DBusGProxy *proxy, guint32 id, gchar *action,
NotifyNotification *notification)
{
NotifyActionCallback callback;
CallbackPair *pair;
g_return_if_fail(notification != NULL);
g_return_if_fail(NOTIFY_IS_NOTIFICATION(notification));
@ -359,13 +377,13 @@ _action_signal_handler(DBusGProxy *proxy, guint32 id, gchar *action,
if (id != notification->priv->id)
return;
callback = (NotifyActionCallback)g_hash_table_lookup(
pair = (CallbackPair *)g_hash_table_lookup(
notification->priv->action_map, action);
if (callback == NULL)
if (pair == NULL)
g_warning("Recieved unknown action %s", action);
else
callback(notification, action);
pair->cb(notification, action, pair->user_data);
}
static gchar **
@ -777,9 +795,11 @@ void
notify_notification_add_action(NotifyNotification *notification,
const char *action,
const char *label,
NotifyActionCallback callback)
NotifyActionCallback callback,
gpointer user_data, GFreeFunc free_func)
{
NotifyNotificationPrivate *priv;
CallbackPair *pair;
g_return_if_fail(notification != NULL);
g_return_if_fail(NOTIFY_IS_NOTIFICATION(notification));
@ -792,7 +812,10 @@ notify_notification_add_action(NotifyNotification *notification,
priv->actions = g_slist_append(priv->actions, g_strdup(action));
priv->actions = g_slist_append(priv->actions, g_strdup(label));
g_hash_table_insert(priv->action_map, g_strdup(action), callback);
pair = g_new0(CallbackPair, 1);
pair->cb = callback;
pair->user_data = user_data;
g_hash_table_insert(priv->action_map, g_strdup(action), pair);
}
gboolean

View File

@ -76,7 +76,9 @@ typedef enum
} NotifyUrgency;
typedef void (*NotifyActionCallback)(NotifyNotification *, gchar *);
typedef void (*NotifyActionCallback)(NotifyNotification *, gchar *, gpointer);
#define NOTIFY_ACTION_CALLBACK(func) ((NotifyActionCallback)(func))
GType notify_notification_get_type();
@ -132,7 +134,8 @@ void notify_notification_clear_hints(NotifyNotification *notification);
void notify_notification_add_action(NotifyNotification *notification,
const char *action, const char *label,
NotifyActionCallback callback);
NotifyActionCallback callback,
gpointer user_data, GFreeFunc free_func);
void notify_notification_clear_actions(NotifyNotification *notification);
gboolean notify_notification_close(NotifyNotification *notification,

View File

@ -61,7 +61,8 @@ main()
n = notify_notification_new ("Matt is online", "", NULL, NULL);
notify_notification_set_timeout (n, NOTIFY_EXPIRES_DEFAULT);
notify_notification_add_action (n, "default", "Do Default Action",
(NotifyActionCallback)callback);
(NotifyActionCallback)callback,
NULL, NULL);
notify_notification_set_category (n, "presence.online");
if (!notify_notification_show (n, NULL)) {

View File

@ -94,11 +94,14 @@ main(int argc, char **argv)
NULL, NULL);
notify_notification_set_timeout(n, NOTIFY_EXPIRES_DEFAULT);
notify_notification_add_action(n, "help", "Help",
(NotifyActionCallback)help_callback);
(NotifyActionCallback)help_callback,
NULL, NULL);
notify_notification_add_action(n, "ignore", "Ignore",
(NotifyActionCallback)ignore_callback);
(NotifyActionCallback)ignore_callback,
NULL, NULL);
notify_notification_add_action(n, "empty", "Empty Trash",
(NotifyActionCallback)empty_callback);
(NotifyActionCallback)empty_callback,
NULL, NULL);
notify_notification_set_category(n, "device");
if (!notify_notification_show(n, NULL))