[Galago-commits] r2453 - in trunk/libnotify: . libnotify tests

galago-commits at freedesktop.org galago-commits at freedesktop.org
Fri Jan 20 02:11:25 PST 2006


Author: chipx86
Date: 2006-01-20 02:11:23 -0800 (Fri, 20 Jan 2006)
New Revision: 2453

Modified:
   trunk/libnotify/ChangeLog
   trunk/libnotify/libnotify/notification.c
   trunk/libnotify/libnotify/notification.h
   trunk/libnotify/tests/test-default-action.c
   trunk/libnotify/tests/test-multi-actions.c
Log:
Implement per-action user data.


Modified: trunk/libnotify/ChangeLog
===================================================================
--- trunk/libnotify/ChangeLog	2006-01-20 10:00:32 UTC (rev 2452)
+++ trunk/libnotify/ChangeLog	2006-01-20 10:11:23 UTC (rev 2453)
@@ -1,3 +1,11 @@
+Fri Jan 20 02:10:50 PST 2006  Christian Hammond <chipx86 at 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 at chipx86.com>
 
 	* docs/notification-spec.xml:

Modified: trunk/libnotify/libnotify/notification.c
===================================================================
--- trunk/libnotify/libnotify/notification.c	2006-01-20 10:00:32 UTC (rev 2452)
+++ trunk/libnotify/libnotify/notification.c	2006-01-20 10:11:23 UTC (rev 2453)
@@ -37,6 +37,14 @@
 								   gchar *action,
 								   NotifyNotification *notification);
 
+typedef struct
+{
+	NotifyActionCallback cb;
+	GFreeFunc free_func;
+	gpointer user_data;
+
+} CallbackPair;
+
 struct _NotifyNotificationPrivate
 {
 	guint32 id;
@@ -116,6 +124,15 @@
 }
 
 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 @@
 											 (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 @@
 _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 @@
 	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 @@
 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 @@
 	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

Modified: trunk/libnotify/libnotify/notification.h
===================================================================
--- trunk/libnotify/libnotify/notification.h	2006-01-20 10:00:32 UTC (rev 2452)
+++ trunk/libnotify/libnotify/notification.h	2006-01-20 10:11:23 UTC (rev 2453)
@@ -76,8 +76,10 @@
 
 } NotifyUrgency;
 
-typedef void (*NotifyActionCallback)(NotifyNotification *, gchar *);
+typedef void (*NotifyActionCallback)(NotifyNotification *, gchar *, gpointer);
 
+#define NOTIFY_ACTION_CALLBACK(func) ((NotifyActionCallback)(func))
+
 GType notify_notification_get_type();
 
 NotifyNotification *notify_notification_new(const gchar *summary,
@@ -132,7 +134,8 @@
 
 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,

Modified: trunk/libnotify/tests/test-default-action.c
===================================================================
--- trunk/libnotify/tests/test-default-action.c	2006-01-20 10:00:32 UTC (rev 2452)
+++ trunk/libnotify/tests/test-default-action.c	2006-01-20 10:11:23 UTC (rev 2453)
@@ -61,7 +61,8 @@
         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)) {

Modified: trunk/libnotify/tests/test-multi-actions.c
===================================================================
--- trunk/libnotify/tests/test-multi-actions.c	2006-01-20 10:00:32 UTC (rev 2452)
+++ trunk/libnotify/tests/test-multi-actions.c	2006-01-20 10:11:23 UTC (rev 2453)
@@ -94,11 +94,14 @@
 								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))



More information about the galago-commits mailing list