[libgweather] GWeatherLocationEntry: Build model after object is constructed



commit 8060e45a13ef398bdf426fae9f957aefbfbf0dbb
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Nov 30 18:02:37 2017 +0100

    GWeatherLocationEntry: Build model after object is constructed
    
    So that additional construct time properties can be used.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=791066

 libgweather/gweather-location-entry.c |   57 ++++++++++++++++++--------------
 1 files changed, 32 insertions(+), 25 deletions(-)
---
diff --git a/libgweather/gweather-location-entry.c b/libgweather/gweather-location-entry.c
index 52ad1c7..8655ff8 100644
--- a/libgweather/gweather-location-entry.c
+++ b/libgweather/gweather-location-entry.c
@@ -56,8 +56,6 @@ enum {
     LAST_PROP
 };
 
-static void gweather_location_entry_build_model (GWeatherLocationEntry *entry,
-                                                GWeatherLocation *top);
 static void set_property (GObject *object, guint prop_id,
                          const GValue *value, GParamSpec *pspec);
 static void get_property (GObject *object, guint prop_id,
@@ -73,6 +71,11 @@ create_new_detached_location (GWeatherLocation *nearest_station,
                               gboolean          latlon_valid,
                               gdouble           latitude,
                               gdouble           longitude);
+static void
+fill_location_entry_model (GtkTreeStore *store, GWeatherLocation *loc,
+                          const char *parent_display_name,
+                          const char *parent_compare_local_name,
+                          const char *parent_compare_english_name);
 
 enum LOC
 {
@@ -166,10 +169,34 @@ dispose (GObject *object)
 }
 
 static void
+constructed (GObject *object)
+{
+    GWeatherLocationEntry *entry;
+    GtkTreeStore *store = NULL;
+    GtkEntryCompletion *completion;
+
+    entry = GWEATHER_LOCATION_ENTRY (object);
+
+    if (!entry->priv->top)
+       entry->priv->top = gweather_location_ref (gweather_location_get_world ());
+
+    store = gtk_tree_store_new (4, G_TYPE_STRING, GWEATHER_TYPE_LOCATION, G_TYPE_STRING, G_TYPE_STRING);
+    fill_location_entry_model (store, entry->priv->top, NULL, NULL, NULL);
+
+    entry->priv->model = GTK_TREE_MODEL (store);
+    completion = gtk_entry_get_completion (GTK_ENTRY (entry));
+    gtk_entry_completion_set_match_func (completion, matcher, NULL, NULL);
+    gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (store));
+
+    G_OBJECT_CLASS (gweather_location_entry_parent_class)->constructed (object);
+}
+
+static void
 gweather_location_entry_class_init (GWeatherLocationEntryClass *location_entry_class)
 {
     GObjectClass *object_class = G_OBJECT_CLASS (location_entry_class);
 
+    object_class->constructed = constructed;
     object_class->finalize = finalize;
     object_class->set_property = set_property;
     object_class->get_property = get_property;
@@ -198,10 +225,11 @@ static void
 set_property (GObject *object, guint prop_id,
              const GValue *value, GParamSpec *pspec)
 {
+    GWeatherLocationEntry *entry = GWEATHER_LOCATION_ENTRY (object);
+
     switch (prop_id) {
     case PROP_TOP:
-       gweather_location_entry_build_model (GWEATHER_LOCATION_ENTRY (object),
-                                            g_value_get_boxed (value));
+        entry->priv->top = g_value_dup_boxed (value);
        break;
     case PROP_LOCATION:
        gweather_location_entry_set_location (GWEATHER_LOCATION_ENTRY (object),
@@ -530,27 +558,6 @@ fill_location_entry_model (GtkTreeStore *store, GWeatherLocation *loc,
     }
 }
 
-static void
-gweather_location_entry_build_model (GWeatherLocationEntry *entry,
-                                    GWeatherLocation *top)
-{
-    GtkTreeStore *store = NULL;
-    GtkEntryCompletion *completion;
-
-    if (top)
-       entry->priv->top = gweather_location_ref (top);
-    else
-       entry->priv->top = gweather_location_ref (gweather_location_get_world ());
-
-    store = gtk_tree_store_new (4, G_TYPE_STRING, GWEATHER_TYPE_LOCATION, G_TYPE_STRING, G_TYPE_STRING);
-    fill_location_entry_model (store, entry->priv->top, NULL, NULL, NULL);
-
-    entry->priv->model = GTK_TREE_MODEL (store);
-    completion = gtk_entry_get_completion (GTK_ENTRY (entry));
-    gtk_entry_completion_set_match_func (completion, matcher, NULL, NULL);
-    gtk_entry_completion_set_model (completion, GTK_TREE_MODEL (store));
-}
-
 static char *
 find_word (const char *full_name, const char *word, int word_len,
           gboolean whole_word, gboolean is_first_word)


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