[libgweather] location-entry: remove giant HACK



commit 7d719b8322b967efbf6d0cb7bd8ca471bf3879cd
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Apr 26 18:11:41 2015 -0700

    location-entry: remove giant HACK
    
    It's a continous source of crashes that I don't have time to
    address, and it's a fringe feature.
    
    Replace it with inline completion. The operation is similar, but
    it requires proper capitalization.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=748299

 libgweather/gweather-location-entry.c |   79 +--------------------------------
 1 files changed, 1 insertions(+), 78 deletions(-)
---
diff --git a/libgweather/gweather-location-entry.c b/libgweather/gweather-location-entry.c
index 5d6b8b1..a7b27ef 100644
--- a/libgweather/gweather-location-entry.c
+++ b/libgweather/gweather-location-entry.c
@@ -38,7 +38,6 @@
  */
 
 struct _GWeatherLocationEntryPrivate {
-    GtkTreeModel     *filter_model;
     GWeatherLocation *location;
     GWeatherLocation *top;
     gboolean          custom_text;
@@ -101,31 +100,6 @@ static void     entry_changed (GWeatherLocationEntry *entry);
 static void _no_matches (GtkEntryCompletion *completion, GWeatherLocationEntry *entry);
 
 static void
-hack_filter_model_data_func (GtkCellLayout   *layout,
-                            GtkCellRenderer *renderer,
-                            GtkTreeModel    *model,
-                            GtkTreeIter     *iter,
-                            gpointer         data)
-{
-    GWeatherLocationEntry *self;
-    GWeatherLocationEntryPrivate *priv;
-
-    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
 gweather_location_entry_init (GWeatherLocationEntry *entry)
 {
     GtkEntryCompletion *completion;
@@ -138,23 +112,7 @@ gweather_location_entry_init (GWeatherLocationEntry *entry)
     gtk_entry_completion_set_popup_set_width (completion, FALSE);
     gtk_entry_completion_set_text_column (completion, LOC_GWEATHER_LOCATION_ENTRY_COL_DISPLAY_NAME);
     gtk_entry_completion_set_match_func (completion, matcher, NULL, NULL);
-
-    /* Giant Hack!
-       We want to grab the filter model used internally by GtkEntryCompletion.
-       We know that it is "leaked" by a few functions and signals, such
-       as the CellDataFunc in GtkCellLayout. So we set that in a way that
-       when it gets called, it sets the filter model where we can access it.
-    */
-    {
-       GList *renderers;
-
-       renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (completion));
-       gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (completion),
-                                           renderers->data,
-                                           hack_filter_model_data_func, NULL, NULL);
-
-       g_list_free (renderers);
-    }
+    gtk_entry_completion_set_inline_completion (completion, TRUE);
 
     g_signal_connect (completion, "match-selected",
                      G_CALLBACK (match_selected), entry);
@@ -186,9 +144,6 @@ 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);
 }
 
@@ -211,47 +166,15 @@ dispose (GObject *object)
 }
 
 static void
-gweather_location_entry_activate (GtkEntry *entry)
-{
-    GWeatherLocationEntry *self;
-    GWeatherLocationEntryPrivate *priv;
-    GtkEntryCompletion *completion;
-
-    self = GWEATHER_LOCATION_ENTRY (entry);
-    priv = self->priv;
-
-    completion = gtk_entry_get_completion (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;
-
-       gtk_tree_model_get_iter_first (priv->filter_model, &iter);
-       gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (priv->filter_model),
-                                                         &real_iter, &iter);
-
-       set_location_internal (self, gtk_entry_completion_get_model (completion),
-                              &real_iter, NULL);
-    }
-
-    GTK_ENTRY_CLASS (gweather_location_entry_parent_class)->activate (entry);
-}
-
-static void
 gweather_location_entry_class_init (GWeatherLocationEntryClass *location_entry_class)
 {
     GObjectClass *object_class = G_OBJECT_CLASS (location_entry_class);
-    GtkEntryClass *entry_class = GTK_ENTRY_CLASS (location_entry_class);
 
     object_class->finalize = finalize;
     object_class->set_property = set_property;
     object_class->get_property = get_property;
     object_class->dispose = dispose;
 
-    entry_class->activate = gweather_location_entry_activate;
-
     /* properties */
     g_object_class_install_property (
        object_class, PROP_TOP,


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