[gnome-control-center/gnome-3-10] color: Do not crash when toggling devices and reopening the panel



commit b242a00af1930df1e55aa7f3b3b2bb0bda1887bb
Author: Richard Hughes <richard hughsie com>
Date:   Tue Apr 22 11:08:32 2014 +0100

    color: Do not crash when toggling devices and reopening the panel
    
    Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=728584

 panels/color/cc-color-panel.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/panels/color/cc-color-panel.c b/panels/color/cc-color-panel.c
index 90b40c8..1a36ef7 100644
--- a/panels/color/cc-color-panel.c
+++ b/panels/color/cc-color-panel.c
@@ -46,6 +46,7 @@ struct _CcColorPanelPrivate
 {
   CdClient      *client;
   CdDevice      *current_device;
+  GPtrArray     *devices;
   GPtrArray     *sensors;
   GCancellable  *cancellable;
   GDBusProxy    *proxy;
@@ -1802,6 +1803,7 @@ gcm_prefs_add_device (CcColorPanel *prefs, CdDevice *device)
   gcm_prefs_add_device_profiles (prefs, device);
 
   /* watch for changes */
+  g_ptr_array_add (priv->devices, g_object_ref (device));
   g_signal_connect (device, "changed",
                     G_CALLBACK (gcm_prefs_device_changed_cb), prefs);
   gtk_list_box_invalidate_sort (priv->list_box);
@@ -1834,6 +1836,7 @@ gcm_prefs_remove_device (CcColorPanel *prefs, CdDevice *device)
   g_signal_handlers_disconnect_by_func (device,
                                         G_CALLBACK (gcm_prefs_device_changed_cb),
                                         prefs);
+  g_ptr_array_remove (priv->devices, device);
 }
 
 static void
@@ -2083,6 +2086,8 @@ static void
 cc_color_panel_dispose (GObject *object)
 {
   CcColorPanelPrivate *priv = CC_COLOR_PANEL (object)->priv;
+  CdDevice *device;
+  guint i;
 
   /* stop the EggListView from firing when it gets disposed */
   if (priv->list_box_selected_id != 0)
@@ -2092,6 +2097,20 @@ cc_color_panel_dispose (GObject *object)
       priv->list_box_selected_id = 0;
     }
 
+  /* stop the devices from emitting after the ListBox has been disposed */
+  if (priv->devices != NULL)
+    {
+      for (i = 0; i < priv->devices->len; i++)
+        {
+          device = g_ptr_array_index (priv->devices, i);
+          g_signal_handlers_disconnect_by_func (device,
+                                                G_CALLBACK (gcm_prefs_device_changed_cb),
+                                                CC_COLOR_PANEL (object));
+        }
+      g_ptr_array_unref (priv->devices);
+      priv->devices = NULL;
+    }
+
   if (priv->cancellable != NULL)
     g_cancellable_cancel (priv->cancellable);
   g_clear_object (&priv->settings);
@@ -2235,6 +2254,7 @@ cc_color_panel_init (CcColorPanel *prefs)
     }
 
   priv->cancellable = g_cancellable_new ();
+  priv->devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
 
   /* can do native display calibration using colord-session */
   priv->calibrate = cc_color_calibrate_new ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]