Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-applets/gweather/ChangeLog,v
retrieving revision 1.261
diff -u -r1.261 ChangeLog
--- ChangeLog	9 Aug 2004 10:36:45 -0000	1.261
+++ ChangeLog	14 Aug 2004 04:04:33 -0000
@@ -1,3 +1,23 @@
+2004-08-13  Frank Solensky  <frank@solensky.org>
+
+	reviewed by: <delete if not using a buddy>
+
+	* gweather-xml.c: (gweather_xml_parse_name),
+	(gweather_xml_parse_location), (gweather_xml_parse_city),
+	(gweather_xml_parse_node): add support for "city" elements between
+	country/state and location.
+
+2004-08-10  Frank Solensky  <frank@solensky.org>
+
+	reviewed by: <delete if not using a buddy>
+
+	* Locations.xml.in: Add a large number of locations to synchronize with
+	19-July-2004 NOAA METAR station list, closing #106451, 139820, 142677,
+	149123.  Include latitude/longtude info in anticipation of post-freeze
+	submission for bug #68616.
+	* gweather-xml.c: (gweather_xml_parse_location):  Ignore unanticipated
+	subentities within location descriptors
+
 2004-08-09  Davyd Madeley  <davyd@madeley.id.au>
 
 	* gweather-pref.c: Change centigrade to celsius. Closes bug #149541.
Index: gweather-xml.c
===================================================================
RCS file: /cvs/gnome/gnome-applets/gweather/gweather-xml.c,v
retrieving revision 1.1
diff -u -r1.1 gweather-xml.c
--- gweather-xml.c	20 Jun 2004 20:56:14 -0000	1.1
+++ gweather-xml.c	14 Aug 2004 04:04:48 -0000
@@ -37,6 +37,14 @@
  *     <location>
  *       ....
  *     </location>
+ *     <city>
+ *      <name>Name of city with multiple locations</city>
+ *      <zone>Forecast code</zone>
+ *      <radar>Radar Map code</radar>
+ *      <location>
+ *        ...
+ *      </location>
+ *     </city>
  *   </state>
  *  </country>
  * </region>
@@ -71,13 +79,13 @@
 #define GWEATHER_XML_NODE_REGION     "region"
 #define GWEATHER_XML_NODE_COUNTRY    "country"
 #define GWEATHER_XML_NODE_STATE      "state"
+#define GWEATHER_XML_NODE_CITY       "city"
 #define GWEATHER_XML_NODE_LOC        "location"
 #define GWEATHER_XML_NODE_NAME       "name"
 #define GWEATHER_XML_NODE_CODE       "code"
 #define GWEATHER_XML_NODE_ZONE       "zone"
 #define GWEATHER_XML_NODE_RADAR      "radar"
 
-
 /* XML Attributes */
 #define GWEATHER_XML_ATTR_FORMAT    "format"
 
@@ -158,11 +166,15 @@
  *      *loc:           currently selected location
  *      reader:         xml text reader
  *      *iter:          iterator to named node
+ *      *untrans_city   untranslated city name or NULL
+ *      *trans_city     translated city name
  *      **untrans_name: returns untranslated name
  *      **trans_name:   returns translated name
  *      *pref:          the preference of the current translation, the smaller the better 
  */
-static void gweather_xml_parse_name (const GList *locale, GtkTreeStore *tree, GtkTreeIter* iter, xmlTextReaderPtr reader, xmlChar **untrans_name, xmlChar **trans_name, gint *pref)
+static void gweather_xml_parse_name (const GList *locale, GtkTreeStore *tree, GtkTreeIter* iter,
+				     xmlChar *untrans_city, xmlChar *trans_city, xmlTextReaderPtr reader,
+				     xmlChar **untrans_name, xmlChar **trans_name, gint *pref)
 {
     int ret, type;
     xmlChar *lang;
@@ -216,10 +228,15 @@
  *      *loc:           currently selected location
  *      reader:         xml text reader
  *      *iter:          Changed to iterator for this node
- *      *p_iter:        parent node's iterator 
- *      *s_iter:        sibling node's iterator (who this node appears after)
+ *      *r_iter:        parent node's iterator 
+ *      *c_iter:        sibling node's iterator (who this node appears after)
+ *      *untrans_city   untranslated city name (NULL if not applicable)
+ *      *trans_city     translated city name
+ *      *cityZone       default forecast zone for city
+ *      *cityRadar      default radar map code
  */
-static void gweather_xml_parse_location (const GList* locale, GtkTreeView *tree, WeatherLocation *loc, xmlTextReaderPtr reader, GtkTreeIter* iter, GtkTreeIter* r_iter, GtkTreeIter* c_iter)
+static void gweather_xml_parse_location (const GList* locale, GtkTreeView *tree, WeatherLocation *loc, xmlTextReaderPtr reader, GtkTreeIter* iter, GtkTreeIter* r_iter, GtkTreeIter* c_iter,
+					 xmlChar *untrans_city, xmlChar *trans_city, xmlChar *cityZone, xmlChar *cityRadar)
 {
     int ret, type;
     xmlChar *name, *untrans_name, *trans_name, *code, *zone, *radar;
@@ -237,8 +254,8 @@
     untrans_name = NULL; 
     trans_name = NULL;
     code = NULL;
-    zone = NULL;
-    radar = NULL;
+    zone = cityZone;
+    radar = cityRadar;
     pref = -1;
 
     /* create a node in the tree for this region */
@@ -256,14 +273,16 @@
             name = xmlTextReaderName (reader);
             
             if ( strcmp (name, GWEATHER_XML_NODE_NAME) == 0 ) {
-                gweather_xml_parse_name (locale, store, iter, reader, &untrans_name, &trans_name, &pref);
+                gweather_xml_parse_name (locale, store, iter, untrans_city, trans_city, reader, &untrans_name, &trans_name, &pref);
             } else if ( strcmp (name, GWEATHER_XML_NODE_CODE) == 0 ) {
                 code = gweather_xml_get_value (reader);
             } else if ( strcmp (name, GWEATHER_XML_NODE_ZONE) == 0 ) {
                 zone = gweather_xml_get_value (reader);
             } else if ( strcmp (name, GWEATHER_XML_NODE_RADAR) == 0 ) {
                 radar = gweather_xml_get_value (reader);
-            }
+	    } else {
+	        xmlFree (gweather_xml_get_value (reader) );
+	    }
             
             xmlFree (name);
         }
@@ -297,8 +316,76 @@
 }
 
 /*****************************************************************************
+ * Func:    gweather_xml_parse_city()
+ * Desc:    Parse a city node, creating a leaf for it in the tree
+ *          then parsing any sub-nodes for different locations
+ * Parm:
+ *      *locale         current_locale
+ *      *tree:          tree to view locations
+ *      *loc:           currently selected location
+ *      reader:         xml text reader
+ *      *iter:          Changed to iterator for this node
+ *      *p_iter:        iterator to parent node
+ *      *s_iter:        iterator to last sibling node
+ */
+
+static void gweather_xml_parse_city (const GList *locale, GtkTreeView *tree, WeatherLocation *loc, xmlTextReaderPtr reader, GtkTreeIter* iter, GtkTreeIter* p_iter, GtkTreeIter* s_iter)
+{
+    int type;
+    xmlChar *name, *untrans_name, *trans_name,*zone, *radar;
+    GtkTreeStore *model;
+    GtkTreeIter last_child;
+    gboolean first;
+    gint pref;
+
+    /* check for an empty element */
+    if ( xmlTextReaderIsEmptyElement (reader) ) {
+        return;
+    }
+       
+    /* initialise variables */
+    model = GTK_TREE_STORE (gtk_tree_view_get_model (tree));
+    first = TRUE;
+    pref = -1;
+    
+    /* create a node in the tree for this region */
+    gtk_tree_store_insert_after(model, iter, p_iter, s_iter);
+    
+    type = XML_READER_TYPE_ELEMENT;
+    while ( xmlTextReaderRead(reader) == 1 && (type != XML_READER_TYPE_END_ELEMENT) ) {
+
+        type = xmlTextReaderNodeType (reader);
+
+        /* skip non-element types */
+        if ( type == XML_READER_TYPE_ELEMENT ) {
+            name = xmlTextReaderName (reader);
+            if ( strcmp (name, GWEATHER_XML_NODE_NAME) == 0 ) {
+                gweather_xml_parse_name (locale, model, iter, NULL, NULL, reader, &untrans_name, &trans_name, &pref);
+            } else if ( strcmp (name, GWEATHER_XML_NODE_ZONE) == 0 ) {
+                zone = gweather_xml_get_value (reader);
+            } else if ( strcmp (name, GWEATHER_XML_NODE_RADAR) == 0 ) {
+                radar = gweather_xml_get_value (reader);
+            } else if ( strcmp (name, GWEATHER_XML_NODE_LOC) == 0 ) {
+                if (first) {
+                    gweather_xml_parse_location (locale, tree, loc, reader, &last_child, iter, NULL, untrans_name, trans_name, zone, radar);
+                    first = FALSE;
+                } else {
+                    gweather_xml_parse_location (locale, tree, loc, reader, &last_child, iter, &last_child, untrans_name, trans_name, zone, radar);
+                }
+            } else {
+	        xmlFree(gweather_xml_get_value (reader));
+	    }
+	      
+            
+            xmlFree (name);
+        }
+    }    
+
+}
+
+/*****************************************************************************
  * Func:    gweather_xml_parse_node()
- * Desc:    Parse a region/country/state node, creating a leaf for it in the tree
+ * Desc:    Parse a region/country/state/city node, creating a leaf for it in the tree
  *          then parsing any sub-nodes.
  *          This is called recursively as each node parses it's sub-nodes
  * Parm:
@@ -312,7 +399,7 @@
  */
 static void gweather_xml_parse_node (const GList *locale, GtkTreeView *tree, WeatherLocation *loc, xmlTextReaderPtr reader, GtkTreeIter* iter, GtkTreeIter* p_iter, GtkTreeIter* s_iter)
 {
-    int ret, type;
+    int type;
     xmlChar *name, *untrans_name, *trans_name;
     GtkTreeStore *model;
     GtkTreeIter last_child;
@@ -332,9 +419,8 @@
     /* create a node in the tree for this region */
     gtk_tree_store_insert_after(model, iter, p_iter, s_iter);
     
-    ret = xmlTextReaderRead(reader);
     type = XML_READER_TYPE_ELEMENT;
-    while ( (ret == 1) && (type != XML_READER_TYPE_END_ELEMENT) ) {
+    while ( xmlTextReaderRead(reader) == 1 && (type != XML_READER_TYPE_END_ELEMENT) ) {
 
         type = xmlTextReaderNodeType (reader);
 
@@ -342,29 +428,34 @@
         if ( type == XML_READER_TYPE_ELEMENT ) {
             name = xmlTextReaderName (reader);
             if ( strcmp (name, GWEATHER_XML_NODE_NAME) == 0 ) {
-                gweather_xml_parse_name (locale, model, iter, reader, &untrans_name, &trans_name, &pref);
+                gweather_xml_parse_name (locale, model, iter, NULL, NULL, reader, &untrans_name, &trans_name, &pref);
             } else if ( strcmp (name, GWEATHER_XML_NODE_COUNTRY) == 0 || 
-                        strcmp (name, GWEATHER_XML_NODE_STATE)   == 0 ) {
+                        strcmp (name, GWEATHER_XML_NODE_STATE)   == 0) {
                 if (first) {
                     gweather_xml_parse_node (locale, tree, loc, reader, &last_child, iter , NULL);
                     first = FALSE;
                 } else {
                     gweather_xml_parse_node (locale, tree, loc, reader, &last_child, iter, &last_child);
                 }
-                
+            } else if ( strcmp (name, GWEATHER_XML_NODE_CITY) == 0 ) {
+	        // pick up city name, zone, radar
+		if (first) {
+	            gweather_xml_parse_city (locale, tree, loc, reader, &last_child, iter, NULL);
+		    first = FALSE;
+		} else {
+		  gweather_xml_parse_city (locale, tree, loc, reader, &last_child, iter, &last_child);
+		}
             } else if ( strcmp (name, GWEATHER_XML_NODE_LOC) == 0 ) {
                 if (first) {
-                    gweather_xml_parse_location (locale, tree, loc, reader, &last_child, iter, NULL);
+                    gweather_xml_parse_location (locale, tree, loc, reader, &last_child, iter, NULL, NULL, NULL, NULL, NULL);
                     first = FALSE;
                 } else {
-                    gweather_xml_parse_location (locale, tree, loc, reader, &last_child, iter, &last_child);
+                    gweather_xml_parse_location (locale, tree, loc, reader, &last_child, iter, &last_child, NULL, NULL, NULL, NULL);
                 }
             }
             
             xmlFree (name);
         }
-        
-        ret = xmlTextReaderRead (reader);
     }    
 }
 
