[libgweather] GWeatherXML: use meaningful column types in the tree model



commit 1e11b351c0c278059b0bc7ce4929056d542826aa
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Wed Dec 14 18:52:37 2011 +0100

    GWeatherXML: use meaningful column types in the tree model
    
    Now that WeatherLocation is no longer a public type, we should avoid
    using it in public places like the gweather-xml tree store.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=587017

 libgweather/gweather-xml.c |   53 +++++++++++++------------------------------
 libgweather/gweather-xml.h |    8 ++++--
 2 files changed, 21 insertions(+), 40 deletions(-)
---
diff --git a/libgweather/gweather-xml.c b/libgweather/gweather-xml.c
index 2f9e95f..3e72d5e 100644
--- a/libgweather/gweather-xml.c
+++ b/libgweather/gweather-xml.c
@@ -71,7 +71,7 @@ gweather_xml_parse_node (GWeatherLocation *gloc,
 	/* Create a row with a name but no WeatherLocation */
 	gtk_tree_store_append (store, &iter, parent);
 	gtk_tree_store_set (store, &iter,
-			    GWEATHER_XML_COL_LOC, name,
+			    GWEATHER_XML_COL_LOCATION_NAME, name,
 			    -1);
 	break;
 
@@ -82,20 +82,24 @@ gweather_xml_parse_node (GWeatherLocation *gloc,
 	 */
 	gtk_tree_store_append (store, &iter, parent);
 	gtk_tree_store_set (store, &iter,
-			    GWEATHER_XML_COL_LOC, name,
+			    GWEATHER_XML_COL_LOCATION_NAME, name,
 			    -1);
 	if (children[0] && !children[1]) {
 	    wloc = _weather_location_from_gweather_location (children[0], name);
 	    gtk_tree_store_set (store, &iter,
-				GWEATHER_XML_COL_POINTER, wloc,
+				GWEATHER_XML_COL_METAR_CODE, wloc->code,
+				GWEATHER_XML_COL_LATLON_VALID, wloc->latlon_valid,
+				GWEATHER_XML_COL_LATITUDE, wloc->latitude,
+				GWEATHER_XML_COL_LONGITUDE, wloc->longitude,
 				-1);
+	    _weather_location_free (wloc);
 	}
 	break;
 
     case GWEATHER_LOCATION_WEATHER_STATION:
 	gtk_tree_store_append (store, &iter, parent);
 	gtk_tree_store_set (store, &iter,
-			    GWEATHER_XML_COL_LOC, name,
+			    GWEATHER_XML_COL_LOCATION_NAME, name,
 			    -1);
 
 	parent_loc = gweather_location_get_parent (gloc);
@@ -103,8 +107,13 @@ gweather_xml_parse_node (GWeatherLocation *gloc,
 	    name = gweather_location_get_name (parent_loc);
 	wloc = _weather_location_from_gweather_location (gloc, name);
 	gtk_tree_store_set (store, &iter,
-			    GWEATHER_XML_COL_POINTER, wloc,
+			    GWEATHER_XML_COL_METAR_CODE, wloc->code,
+			    GWEATHER_XML_COL_LATLON_VALID, wloc->latlon_valid,
+			    GWEATHER_XML_COL_LATITUDE, wloc->latitude,
+			    GWEATHER_XML_COL_LONGITUDE, wloc->longitude,
 			    -1);
+	_weather_location_free (wloc);
+
 	break;
     }
 
@@ -129,10 +138,10 @@ gweather_xml_load_locations (void)
     if (!world)
 	return NULL;
 
-    store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
+    store = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
 
     if (!gweather_xml_parse_node (world, store, NULL)) {
-	gweather_xml_free_locations ((GtkTreeModel *)store);
+	g_object_unref (store);
 	store = NULL;
     }
 
@@ -140,33 +149,3 @@ gweather_xml_load_locations (void)
 
     return (GtkTreeModel *)store;
 }
-
-static gboolean
-free_locations (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
-{
-	WeatherLocation *loc = NULL;
-
-	gtk_tree_model_get (model, iter,
-			    GWEATHER_XML_COL_POINTER, &loc,
-			    -1);
-
-	if (loc) {
-		_weather_location_free (loc);
-		gtk_tree_store_set ((GtkTreeStore *)model, iter,
-			    GWEATHER_XML_COL_POINTER, NULL,
-			    -1);
-	}
-
-	return FALSE;
-}
-
-/* Frees model returned from @gweather_xml_load_locations. It contains allocated
-   WeatherLocation-s, thus this takes care of the freeing of that memory. */
-void
-gweather_xml_free_locations (GtkTreeModel *locations)
-{
-	if (locations && GTK_IS_TREE_STORE (locations)) {
-		gtk_tree_model_foreach (locations, free_locations, NULL);
-		g_object_unref (locations);
-	}
-}
diff --git a/libgweather/gweather-xml.h b/libgweather/gweather-xml.h
index b3573e6..b5679c4 100644
--- a/libgweather/gweather-xml.h
+++ b/libgweather/gweather-xml.h
@@ -26,12 +26,14 @@
 
 enum
 {
-    GWEATHER_XML_COL_LOC = 0,
-    GWEATHER_XML_COL_POINTER,
+    GWEATHER_XML_COL_LOCATION_NAME = 0,
+    GWEATHER_XML_COL_METAR_CODE,
+    GWEATHER_XML_COL_LATLON_VALID,
+    GWEATHER_XML_COL_LATITUDE,
+    GWEATHER_XML_COL_LONGITUDE,
     GWEATHER_XML_NUM_COLUMNS
 };
 
 GtkTreeModel *gweather_xml_load_locations (void);
-void          gweather_xml_free_locations (GtkTreeModel *locations);
 
 #endif /* __GWEATHER_XML_H__ */



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