[libgweather] Fix the filter model hack



commit 9e732053b2e6b21f72b0963c3354433db68df2d8
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Dec 11 17:12:01 2014 -0500

    Fix the filter model hack
    
    The current code leads to crashes when there are no matches.
    Using weak references to update the filter_model pointer when
    that model goes away avoids theses.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=739899

 libgweather/location-entry.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/libgweather/location-entry.c b/libgweather/location-entry.c
index 32c1210..b374122 100644
--- a/libgweather/location-entry.c
+++ b/libgweather/location-entry.c
@@ -114,7 +114,16 @@ hack_filter_model_data_func (GtkCellLayout   *layout,
     self = GWEATHER_LOCATION_ENTRY (gtk_entry_completion_get_entry (GTK_ENTRY_COMPLETION (layout)));
     priv = self->priv;
 
+    if (priv->filter_model == model)
+      return;
+
+    if (priv->filter_model)
+      g_object_remove_weak_pointer (G_OBJECT (priv->filter_model), (gpointer *)&priv->filter_model);
+
     priv->filter_model = model;
+
+    if (priv->filter_model)
+      g_object_add_weak_pointer (G_OBJECT (priv->filter_model), (gpointer *)&priv->filter_model);
 }
 
 static void
@@ -178,6 +187,9 @@ finalize (GObject *object)
     if (priv->model)
         g_object_unref (priv->model);
 
+    if (priv->filter_model)
+      g_object_remove_weak_pointer (G_OBJECT (priv->filter_model), (gpointer *)&priv->filter_model);
+
     G_OBJECT_CLASS (gweather_location_entry_parent_class)->finalize (object);
 }
 
@@ -213,6 +225,7 @@ gweather_location_entry_activate (GtkEntry *entry)
     gtk_entry_completion_complete (completion);
 
     if (priv->custom_text &&
+        priv->filter_model &&
        gtk_tree_model_iter_n_children (priv->filter_model, NULL) == 1) {
        GtkTreeIter iter, real_iter;
 


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