← Back to team overview

ayatana-commits team mailing list archive

[Branch ~indicator-applet-developers/indicator-me/trunk] Rev 108: prevent the indicator from crashing after a service restart, by properly disconnecting signals at...

 

Merge authors:
  Cody Russell (bratsche)
Related merge proposals:
  https://code.launchpad.net/~bratsche/indicator-me/disconnect-some-signals/+merge/36249
  proposed by: Cody Russell (bratsche)
  review: Approve - David Barth (dbarth)
------------------------------------------------------------
revno: 108 [merge]
fixes bug(s): https://launchpad.net/bugs/643906
committer: David Barth <david.barth@xxxxxxxxxxxxx>
branch nick: indicator-me
timestamp: Wed 2010-09-22 10:55:37 +0200
message:
  prevent the indicator from crashing after a service restart, by properly disconnecting signals attached to the text entry. Thanks to Cody Russell
modified:
  src/indicator-me.c


--
lp:indicator-me
https://code.launchpad.net/~indicator-applet-developers/indicator-me/trunk

Your team ayatana-commits is subscribed to branch lp:indicator-me.
To unsubscribe from this branch go to https://code.launchpad.net/~indicator-applet-developers/indicator-me/trunk/+edit-subscription
=== modified file 'src/indicator-me.c'
--- src/indicator-me.c	2010-09-16 14:49:20 +0000
+++ src/indicator-me.c	2010-09-22 04:27:15 +0000
@@ -90,6 +90,8 @@
 static gboolean new_entry_item (DbusmenuMenuitem * newitem,
                                 DbusmenuMenuitem * parent,
                                 DbusmenuClient   * client);
+static void     entry_activate_cb (GtkEntry *entry, DbusmenuMenuitem *mi);
+static void     entry_prop_change_cb (DbusmenuMenuitem *mi, gchar *prop, GValue *value, GtkEntry *entry);
 
 G_DEFINE_TYPE (IndicatorMe, indicator_me, INDICATOR_OBJECT_TYPE);
 
@@ -205,6 +207,19 @@
 }
 
 static void
+item_destroyed_cb (GtkObject *item,
+                   gpointer   user_data)
+{
+  g_signal_handlers_disconnect_by_func (user_data,
+                                        G_CALLBACK (entry_activate_cb),
+                                        item);
+
+  g_signal_handlers_disconnect_by_func (user_data,
+                                        G_CALLBACK (entry_prop_change_cb),
+                                        item);
+}
+
+static void
 connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata)
 {
 	if (connected) {
@@ -238,6 +253,17 @@
     /* query the service for the username to display */
 		org_ayatana_indicator_me_service_pretty_user_name_async(status_proxy, username_cb, NULL);
 	} else {
+    DbusmenuMenuitem *mi = g_object_get_data (G_OBJECT (ido_entry),
+                                              "dbusmenuitem");
+
+    g_signal_handlers_disconnect_by_func (ido_entry,
+                                          G_CALLBACK (entry_activate_cb),
+                                          mi);
+
+    g_signal_handlers_disconnect_by_func (ido_entry,
+                                          G_CALLBACK (entry_prop_change_cb),
+                                          mi);
+
 		/* If we're disconnecting, go back to offline */
 		status_icon_cb(NULL, DEFAULT_ICON, NULL, NULL);
 
@@ -245,7 +271,7 @@
     status_proxy = NULL;
 
     if (ido_entry != NULL) {
-      g_object_unref (ido_entry);
+      gtk_widget_destroy (GTK_WIDGET (ido_entry));
       ido_entry = NULL;
     }
 	}
@@ -394,6 +420,10 @@
     entry_set_hint (entry, dbusmenu_menuitem_property_get (newitem, DBUSMENU_ENTRY_MENUITEM_PROP_HINT));
 	}
 
+  g_object_set_data (G_OBJECT (ido),
+                     "dbusmenitem",
+                     newitem);
+
 	gtk_entry_set_width_chars (entry, 23); /* set some nice aspect ratio for the menu */
   gtk_entry_set_max_length (entry, 140); /* enforce current gwibber limit */
 
@@ -424,10 +454,15 @@
 
   g_signal_connect (entry,
                     "grab-focus", G_CALLBACK (entry_focus_grab_cb),
-                    entry);
+                    NULL);
 
   g_signal_connect (entry,
                     "grab-broken-event", G_CALLBACK (entry_focus_ungrab_cb),
+                    NULL);
+
+  g_signal_connect (newitem,
+                    "destroy",
+                    G_CALLBACK (item_destroyed_cb),
                     entry);
 
 	return TRUE;