summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hammond <chipx86@chipx86.com>2006-01-20 10:11:23 +0000
committerChristian Hammond <chipx86@chipx86.com>2006-01-20 10:11:23 +0000
commit8297e321bfb5c5c8c0764e145e33f8b2e5fa71fd (patch)
tree3915d68b089d7a5d87be11ad4ca48631b2ccda09
parent85342c8619067019e0422495dbf0f149f5271e7a (diff)
downloadlibnotify-8297e321bfb5c5c8c0764e145e33f8b2e5fa71fd.tar.gz
Implement per-action user data.
-rw-r--r--ChangeLog8
-rw-r--r--libnotify/notification.c37
-rw-r--r--libnotify/notification.h7
-rw-r--r--tests/test-default-action.c3
-rw-r--r--tests/test-multi-actions.c9
5 files changed, 51 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 3ca4a8f..a1557aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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:
diff --git a/libnotify/notification.c b/libnotify/notification.c
index 6bac071..1deed34 100644
--- a/libnotify/notification.c
+++ b/libnotify/notification.c
@@ -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;
@@ -116,6 +124,15 @@ _g_value_free(GValue *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)
{
obj->priv = g_new0(NotifyNotificationPrivate, 1);
@@ -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
diff --git a/libnotify/notification.h b/libnotify/notification.h
index 0b7be02..87cc732 100644
--- a/libnotify/notification.h
+++ b/libnotify/notification.h
@@ -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,
diff --git a/tests/test-default-action.c b/tests/test-default-action.c
index eb8c4f4..6d4bb93 100644
--- a/tests/test-default-action.c
+++ b/tests/test-default-action.c
@@ -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)) {
diff --git a/tests/test-multi-actions.c b/tests/test-multi-actions.c
index 5f912f1..c611767 100644
--- a/tests/test-multi-actions.c
+++ b/tests/test-multi-actions.c
@@ -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))