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

galago-commits at freedesktop.org galago-commits at freedesktop.org
Mon Jan 23 01:10:59 PST 2006


Author: chipx86
Date: 2006-01-23 01:10:55 -0800 (Mon, 23 Jan 2006)
New Revision: 2477

Modified:
   trunk/libnotify/ChangeLog
   trunk/libnotify/libnotify/internal.h
   trunk/libnotify/libnotify/notification.c
   trunk/libnotify/libnotify/notify.c
   trunk/libnotify/tests/test-replace-widget.c
Log:
Make a best attempt at clearing away notifications that require actions or that exist until clicked when the calling application exits. This doesn't always work.


Modified: trunk/libnotify/ChangeLog
===================================================================
--- trunk/libnotify/ChangeLog	2006-01-23 08:39:58 UTC (rev 2476)
+++ trunk/libnotify/ChangeLog	2006-01-23 09:10:55 UTC (rev 2477)
@@ -1,3 +1,13 @@
+Mon Jan 23 01:10:23 PST 2006  Christian Hammond <chipx86 at chipx86.com>
+
+	* libnotify/internal.h:
+	* libnotify/notification.c:
+	* libnotify/notify.c:
+	* tests/test-replace-widget.c:
+	  - Make a best attempt at clearing away notifications that require
+	    actions or that exist until clicked when the calling application
+	    exits. This doesn't always work.
+
 Sun Jan 22 23:46:27 PST 2006  Christian Hammond <chipx86 at chipx86.com>
 
 	* docs/notification-spec.xml:

Modified: trunk/libnotify/libnotify/internal.h
===================================================================
--- trunk/libnotify/libnotify/internal.h	2006-01-23 08:39:58 UTC (rev 2476)
+++ trunk/libnotify/libnotify/internal.h	2006-01-23 09:10:55 UTC (rev 2477)
@@ -36,7 +36,13 @@
 #define NOTIFY_DBUS_CORE_INTERFACE "org.freedesktop.Notifications"
 #define NOTIFY_DBUS_CORE_OBJECT    "/org/freedesktop/Notifications"
 
-DBusGConnection *get_dbus_g_conn(void);
-DBusGProxy *get_g_proxy(void);
+DBusGConnection *_notify_get_dbus_g_conn(void);
+DBusGProxy *_notify_get_g_proxy(void);
 
+void _notify_cache_add_notification(NotifyNotification *n);
+void _notify_cache_remove_notification(NotifyNotification *n);
+gint _notify_notification_get_timeout(const NotifyNotification *n);
+gboolean _notify_notification_has_nondefault_actions(
+	const NotifyNotification *n);
+
 #endif /* _LIBNOTIFY_INTERNAL_H_ */

Modified: trunk/libnotify/libnotify/notification.c
===================================================================
--- trunk/libnotify/libnotify/notification.c	2006-01-23 08:39:58 UTC (rev 2476)
+++ trunk/libnotify/libnotify/notification.c	2006-01-23 09:10:55 UTC (rev 2477)
@@ -72,6 +72,7 @@
 	gint widget_old_x;
 	gint widget_old_y;
 
+	gboolean has_nondefault_actions;
 	gboolean updates_pending;
 	gboolean signals_registered;
 };
@@ -141,8 +142,10 @@
 {
 	NotifyNotification *obj = NOTIFY_NOTIFICATION(object);
 	NotifyNotificationPrivate *priv = obj->priv;
-	DBusGProxy *proxy = get_g_proxy();
+	DBusGProxy *proxy = _notify_get_g_proxy();
 
+	_notify_cache_remove_notification(obj);
+
 	g_free(priv->summary);
 	g_free(priv->body);
 	g_free(priv->icon_name);
@@ -282,6 +285,8 @@
 		obj->priv->attached_widget = attach;
 	}
 
+	_notify_cache_add_notification(obj);
+
 	return obj;
 }
 
@@ -380,7 +385,7 @@
 	g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
 
 	priv = notification->priv;
-	proxy = get_g_proxy();
+	proxy = _notify_get_g_proxy();
 
 	if (!priv->signals_registered)
 	{
@@ -437,6 +442,15 @@
 	notification->priv->timeout = timeout;
 }
 
+gint
+_notify_notification_get_timeout(const NotifyNotification *notification)
+{
+	g_return_val_if_fail(notification != NULL, -1);
+	g_return_val_if_fail(NOTIFY_IS_NOTIFICATION(notification), -1);
+
+	return notification->priv->timeout;
+}
+
 void
 notify_notification_set_category(NotifyNotification *notification,
 								 const char *category)
@@ -692,6 +706,7 @@
 	}
 
 	notification->priv->actions = NULL;
+	notification->priv->has_nondefault_actions = FALSE;
 }
 
 void
@@ -719,9 +734,24 @@
 	pair->cb = callback;
 	pair->user_data = user_data;
 	g_hash_table_insert(priv->action_map, g_strdup(action), pair);
+
+	if (notification->priv->has_nondefault_actions &&
+		g_ascii_strcasecmp(action, "default"))
+	{
+		notification->priv->has_nondefault_actions = TRUE;
+	}
 }
 
 gboolean
+_notify_notification_has_nondefault_actions(const NotifyNotification *n)
+{
+	g_return_val_if_fail(n != NULL, FALSE);
+	g_return_val_if_fail(NOTIFY_IS_NOTIFICATION(n), FALSE);
+
+	return n->priv->has_nondefault_actions;
+}
+
+gboolean
 notify_notification_close(NotifyNotification *notification,
 						  GError **error)
 {
@@ -734,7 +764,7 @@
 
 	priv = notification->priv;
 
-	dbus_g_proxy_call(get_g_proxy(), "CloseNotification", &tmp_error,
+	dbus_g_proxy_call(_notify_get_g_proxy(), "CloseNotification", &tmp_error,
 					  G_TYPE_UINT, priv->id, G_TYPE_INVALID,
 					  G_TYPE_INVALID);
 

Modified: trunk/libnotify/libnotify/notify.c
===================================================================
--- trunk/libnotify/libnotify/notify.c	2006-01-23 08:39:58 UTC (rev 2476)
+++ trunk/libnotify/libnotify/notify.c	2006-01-23 09:10:55 UTC (rev 2477)
@@ -31,6 +31,7 @@
 static gchar *_app_name = NULL;
 static DBusGProxy *_proxy = NULL;
 static DBusGConnection *_dbus_gconn = NULL;
+static GList *_active_notifications = NULL;
 
 #ifdef __GNUC__
 #  define format_func __attribute__((format(printf, 1, 2)))
@@ -80,9 +81,7 @@
 							G_TYPE_UINT, G_TYPE_STRING,
 							G_TYPE_INVALID);
 
-#ifdef HAVE_ATEXIT
-	atexit(notify_uninit);
-#endif /* HAVE_ATEXIT */
+	g_atexit(notify_uninit);
 
 	_initted = TRUE;
 
@@ -98,16 +97,24 @@
 void
 notify_uninit(void)
 {
+	GList *l;
+
 	if (_app_name != NULL)
 	{
 		g_free(_app_name);
 		_app_name = NULL;
 	}
 
-	/*
-	 * TODO: Keep track of all notifications and destroy them here?
-	 *       Definitely all notifications that don't expire.
-	 */
+	for (l = _active_notifications; l != NULL; l = l->next)
+	{
+		NotifyNotification *n = NOTIFY_NOTIFICATION(l->data);
+
+		if (_notify_notification_get_timeout(n) == 0 ||
+			_notify_notification_has_nondefault_actions(n))
+		{
+			notify_notification_close(n, NULL);
+		}
+	}
 }
 
 gboolean
@@ -117,13 +124,13 @@
 }
 
 DBusGConnection *
-get_dbus_g_conn(void)
+_notify_get_dbus_g_conn(void)
 {
 	return _dbus_gconn;
 }
 
 DBusGProxy *
-get_g_proxy(void)
+_notify_get_g_proxy(void)
 {
 	return _proxy;
 }
@@ -134,7 +141,7 @@
 	GError *error = NULL;
 	char **caps = NULL, **cap;
 	GList *result = NULL;
-	DBusGProxy *proxy = get_g_proxy();
+	DBusGProxy *proxy = _notify_get_g_proxy();
 
 	g_return_val_if_fail(proxy != NULL, NULL);
 
@@ -162,7 +169,7 @@
 					   char **ret_version, char **ret_spec_version)
 {
 	GError *error = NULL;
-	DBusGProxy *proxy = get_g_proxy();
+	DBusGProxy *proxy = _notify_get_g_proxy();
 	char *name, *vendor, *version, *spec_version;
 
 	g_return_val_if_fail(proxy != NULL, FALSE);
@@ -193,3 +200,15 @@
 
 	return TRUE;
 }
+
+void
+_notify_cache_add_notification(NotifyNotification *n)
+{
+	_active_notifications = g_list_prepend(_active_notifications, n);
+}
+
+void
+_notify_cache_remove_notification(NotifyNotification *n)
+{
+	_active_notifications = g_list_remove(_active_notifications, n);
+}

Modified: trunk/libnotify/tests/test-replace-widget.c
===================================================================
--- trunk/libnotify/tests/test-replace-widget.c	2006-01-23 08:39:58 UTC (rev 2476)
+++ trunk/libnotify/tests/test-replace-widget.c	2006-01-23 09:10:55 UTC (rev 2477)
@@ -41,6 +41,9 @@
 	notify_init("Replace Test");
 
 	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	g_signal_connect(G_OBJECT(window), "delete_event",
+					 G_CALLBACK(gtk_main_quit), NULL);
+
 	button = gtk_button_new_with_label("click here to change notification");
 	gtk_container_add(GTK_CONTAINER(window), button);
 



More information about the galago-commits mailing list