← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/indicator-appmenu/unity-crasher-fun into lp:indicator-appmenu

 

Ted Gould has proposed merging lp:~ted/indicator-appmenu/unity-crasher-fun into lp:indicator-appmenu.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)


Bad signal.  Bad bad signal.  Tracking the old root item so that we can disconnect from it properly.  Also checking to ensure there are entires in the array before looking inside it.  Fixes the same bug twice.
-- 
https://code.launchpad.net/~ted/indicator-appmenu/unity-crasher-fun/+merge/28788
Your team ayatana-commits is subscribed to branch lp:indicator-appmenu.
=== modified file 'src/window-menus.c'
--- src/window-menus.c	2010-06-21 20:22:22 +0000
+++ src/window-menus.c	2010-06-29 19:12:35 +0000
@@ -35,6 +35,7 @@
 struct _WindowMenusPrivate {
 	guint windowid;
 	DbusmenuGtkClient * client;
+	DbusmenuMenuitem * root;
 	DBusGProxy * props;
 	GArray * entries;
 };
@@ -113,6 +114,7 @@
 
 	priv->client = NULL;
 	priv->props = NULL;
+	priv->root = NULL;
 
 	priv->entries = g_array_new(FALSE, FALSE, sizeof(IndicatorObjectEntry *));
 
@@ -127,6 +129,11 @@
 
 	WindowMenusPrivate * priv = WINDOW_MENUS_GET_PRIVATE(object);
 
+	if (priv->root != NULL) {
+		g_object_unref(G_OBJECT(priv->root));
+		priv->root = NULL;
+	}
+
 	if (priv->client != NULL) {
 		g_object_unref(G_OBJECT(priv->client));
 		priv->client = NULL;
@@ -295,11 +302,21 @@
 		menu_entry_removed(NULL, NULL, user_data);
 	}
 
+	if (priv->root != NULL) {
+		g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), G_CALLBACK(menu_entry_added), user_data);
+		g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), G_CALLBACK(menu_entry_removed), user_data);
+		g_object_unref(priv->root);
+	}
+
+	priv->root = new_root;
+
 	/* See if we've got new entries */
 	if (new_root == NULL) {
 		return;
 	}
 
+	g_object_ref(priv->root);
+
 	/* Set up signals */
 	g_signal_connect(G_OBJECT(new_root), DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED,   G_CALLBACK(menu_entry_added),   user_data);
 	g_signal_connect(G_OBJECT(new_root), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(menu_entry_removed), user_data);
@@ -435,6 +452,10 @@
 {
 	g_return_if_fail(IS_WINDOW_MENUS(user_data));
 	WindowMenusPrivate * priv = WINDOW_MENUS_GET_PRIVATE(user_data);
+
+	if (priv->entries == NULL || priv->entries->len == 0) {
+		return;
+	}
 	
 	/* TODO: find the menuitem */
 	IndicatorObjectEntry * entry = g_array_index(priv->entries, IndicatorObjectEntry *, priv->entries->len - 1);


Follow ups