? Locations.xml
? gweather-pref.patch
? patch.tar
? toto.diff
Index: Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-applets/gweather/Makefile.am,v
retrieving revision 1.17
diff -u -d -b -u -r1.17 Makefile.am
--- Makefile.am	14 Aug 2002 11:14:54 -0000	1.17
+++ Makefile.am	30 Nov 2002 13:43:56 -0000
@@ -43,12 +43,12 @@
 	sed -e "s|\@LIBEXECDIR\@|$(libexecdir)|" $< > $@
 
 gweatherlocationsdir = $(datadir)/gweather
-gweatherlocations_DATA = Locations
+gweatherlocations_DATA = Locations.xml
 
 EXTRA_DIST = \
 	GNOME_GWeatherApplet_Factory.server.in.in \
 	gweather.schemas \
 	$(ui_DATA)	\
-	Locations
+	Locations.xml
 
 @INTLTOOL_SERVER_RULE@
Index: gweather-pref.c
===================================================================
RCS file: /cvs/gnome/gnome-applets/gweather/gweather-pref.c,v
retrieving revision 1.47
diff -u -d -b -u -r1.47 gweather-pref.c
--- gweather-pref.c	20 Nov 2002 02:42:03 -0000	1.47
+++ gweather-pref.c	30 Nov 2002 13:43:57 -0000
@@ -27,6 +27,10 @@
 #include <gconf/gconf-client.h>
 #include <egg-screen-help.h>
 
+#include <libxml/xmlmemory.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
 #include "gweather.h"
 #include "gweather-pref.h"
 #include "gweather-applet.h"
@@ -252,20 +256,24 @@
     GtkTreeStore *model;
     GtkTreeViewColumn *column;
     GtkCellRenderer *cell_renderer;
-
-    gchar *pp[1], *path;
-    gint nregions, iregions;
-    gchar **regions;
     gchar *file;
     
-    model = GTK_TREE_STORE (gtk_tree_view_get_model (tree));
+    xmlDocPtr doc;
+    xmlNodePtr root, region, state, location;
 
-    file = gnome_datadir_file("gweather/Locations");
+    model = GTK_TREE_STORE (gtk_tree_view_get_model (tree));
+    file = gnome_datadir_file("gweather/Locations.xml");
     g_return_if_fail (file);
-    path = g_strdup_printf("=%s=/", file);
-    gnome_config_push_prefix(path);
-    g_free(path);
+
+    doc = xmlParseFile (file);
     g_free (file);
+    g_return_if_fail( doc!= NULL);
+    
+    root = xmlDocGetRootElement (doc);
+    if ( root == NULL || xmlStrcmp (root->name, (const xmlChar *) "gweather" ) ) {
+      xmlFreeDoc(doc); 
+      g_return_if_fail(1 == 0);
+    }
     
     cell_renderer = gtk_cell_renderer_text_new ();
     column = gtk_tree_view_column_new_with_attributes ("not used", cell_renderer,
@@ -273,53 +281,41 @@
     gtk_tree_view_append_column (tree, column);
     gtk_tree_view_set_expander_column (GTK_TREE_VIEW (tree), column);
 
-    gnome_config_get_vector("Main/regions", &nregions, &regions);
-
-    for (iregions = nregions-1;  iregions >= 0;  iregions--) {
+    region = root->children;
+    while ( region != NULL ) {
         GtkTreeIter region_iter;
-        gint nstates, istates;
-        gchar **states;
-        gchar *region_name;
-        gchar *region_name_key = g_strconcat(regions[iregions], "/name", NULL);
-        gchar *states_key = g_strconcat(regions[iregions], "/states", NULL);
-
-        region_name = gnome_config_get_string(region_name_key);
-
-        gtk_tree_store_insert (model, &region_iter, NULL, 0);
-        gtk_tree_store_set (model, &region_iter, COL_LOC, region_name, -1);
         
-        gnome_config_get_vector(states_key, &nstates, &states);
+        /* watch out for those "text" nodes we have due to our "readable" formatting */
+        if ( g_strcasecmp (region->name, "region") == 0 ) {
+        	gtk_tree_store_append (model, &region_iter, NULL);
+	        gtk_tree_store_set (model, &region_iter, COL_LOC, xmlGetProp (region, "name"), -1);
 
-        for (istates = nstates - 1;  istates >= 0;  istates--) {
+		state = region->children;
+		while ( state != NULL ) {
             GtkTreeIter state_iter;
-            void *iter;
-            gchar *iter_key, *iter_val;
-            gchar *state_path = g_strconcat(regions[iregions], "_", states[istates], "/", NULL);
-            gchar *state_name_key = g_strconcat(state_path, "name", NULL);
-            gchar *state_name = gnome_config_get_string(state_name_key);
 
-	    gtk_tree_store_insert (model, &state_iter, &region_iter, 0);
-            gtk_tree_store_set (model, &state_iter, COL_LOC, state_name, -1);
+		    if ( g_strcasecmp (state->name, "state") == 0 ) {
+			gtk_tree_store_append (model, &state_iter, &region_iter);
+			gtk_tree_store_set (model, &state_iter, COL_LOC,  xmlGetProp (state, "name"), -1);
             
-            iter = gnome_config_init_iterator(state_path);
-            while ((iter = gnome_config_iterator_next(iter, &iter_key, &iter_val)) != NULL) {
-                if (strstr(iter_key, "loc") != NULL) {
+			location = state->children;
+			while ( location != NULL ) {
                     GtkTreeIter loc_iter;
-                    gchar **locdata;
-                    gint nlocdata;
                     WeatherLocation *weather_location;
+			    gchar *name;
 
-                    gnome_config_make_vector(iter_val, &nlocdata, &locdata);
-                    g_return_if_fail(nlocdata == 4);
+			    if ( g_strcasecmp (location->name, "location") == 0 ) {
+				name = xmlGetProp (location, "name");
+				weather_location = weather_location_new(name,
+									xmlGetProp (location, "code"),
+									xmlGetProp (location, "zone"),
+									xmlGetProp (location, "radar"));
                     
-		    weather_location = weather_location_new(locdata[0], 
-		    					    locdata[1], 
-		    					    locdata[2], 
-		    					    locdata[3]);
-                    gtk_tree_store_insert (model, &loc_iter, &state_iter, 0);
-                    gtk_tree_store_set (model, &loc_iter, COL_LOC, locdata[0], 
+				gtk_tree_store_prepend (model, &loc_iter, &state_iter);
+				gtk_tree_store_set (model, &loc_iter, COL_LOC, name, 
                     			COL_POINTER, weather_location, -1);                 
                     
+				g_free (name);
                     
                     if (gw_applet->gweather_pref.location && weather_location_equal(weather_location, gw_applet->gweather_pref.location)) {
                         GtkTreePath *path;
@@ -338,26 +334,18 @@
                         gtk_tree_path_free (path);
                     }
 		    
-                    g_strfreev(locdata);
-                }
 
-                g_free(iter_key);
-                g_free(iter_val);
             }
-
-            g_free(state_name);
-            g_free(state_path);
-            g_free(state_name_key);
+			    location = location->next;
         }
-
-        g_strfreev(states);
-        g_free(region_name);
-        g_free(region_name_key);
-        g_free(states_key);
     }
-    g_strfreev(regions);
+		    state = state->next;
+		}
+        }
+        region = region->next;
+    }
 
-    gnome_config_pop_prefix();
+    xmlFreeDoc(doc);
 }
 
 static void
