libgweather r302 - in trunk: . libgweather



Author: danw
Date: Mon Aug  4 17:48:44 2008
New Revision: 302
URL: http://svn.gnome.org/viewvc/libgweather?rev=302&view=rev

Log:
	* libgweather/gweather-location.c
	(gweather_location_get_city_name): Make this work for cities too,
	not just <location>s.

	* libgweather/location-entry.c (fill_location_entry_model): fix
	the city-with-a-single-location case.


Modified:
   trunk/ChangeLog
   trunk/libgweather/gweather-location.c
   trunk/libgweather/location-entry.c

Modified: trunk/libgweather/gweather-location.c
==============================================================================
--- trunk/libgweather/gweather-location.c	(original)
+++ trunk/libgweather/gweather-location.c	Mon Aug  4 17:48:44 2008
@@ -505,12 +505,14 @@
 char *
 gweather_location_get_city_name (GWeatherLocation *loc)
 {
-    if (loc->level != GWEATHER_LOCATION_WEATHER_STATION ||
-	!loc->parent ||
-	loc->parent->level != GWEATHER_LOCATION_CITY)
+    if (loc->level == GWEATHER_LOCATION_CITY)
+	return g_strdup (loc->name);
+    else if (loc->level == GWEATHER_LOCATION_WEATHER_STATION &&
+	     loc->parent &&
+	     loc->parent->level == GWEATHER_LOCATION_CITY)
+	return g_strdup (loc->parent->name);
+    else
 	return NULL;
-
-    return g_strdup (loc->parent->name);
 }
 
 WeatherLocation *

Modified: trunk/libgweather/location-entry.c
==============================================================================
--- trunk/libgweather/location-entry.c	(original)
+++ trunk/libgweather/location-entry.c	Mon Aug  4 17:48:44 2008
@@ -294,10 +294,10 @@
 	break;
 
     case GWEATHER_LOCATION_CITY:
-	/* If there are multiple (<location>) children, add a line for
-	 * each of them.
-	 */
-	if (children[1]) {
+	if (children[0] && children[1]) {
+	    /* If there are multiple (<location>) children, add a line
+	     * for each of them.
+	     */
 	    for (i = 0; children[i]; i++) {
 		display_name = g_strdup_printf ("%s (%s), %s",
 						gweather_location_get_name (loc),
@@ -318,9 +318,29 @@
 		g_free (display_name);
 		g_free (compare_name);
 	    }
-	    break;
+	} else if (children[0]) {
+	    /* Else there's only one location. This is a mix of the
+	     * city-with-multiple-location case above and the
+	     * location-with-no-city case below.
+	     */
+	    display_name = g_strdup_printf ("%s, %s",
+					    gweather_location_get_name (loc),
+					    parent_display_name);
+	    compare_name = g_strdup_printf ("%s, %s",
+					    gweather_location_get_sort_name (loc),
+					    parent_compare_name);
+
+	    gtk_tree_store_append (store, &iter, NULL);
+	    gtk_tree_store_set (store, &iter,
+				GWEATHER_LOCATION_ENTRY_COL_LOCATION, children[0],
+				GWEATHER_LOCATION_ENTRY_COL_DISPLAY_NAME, display_name,
+				GWEATHER_LOCATION_ENTRY_COL_COMPARE_NAME, compare_name,
+				-1);
+
+	    g_free (display_name);
+	    g_free (compare_name);
 	}
-	/* else, if there's only a single location, fall through */
+	break;
 
     case GWEATHER_LOCATION_WEATHER_STATION:
 	/* <location> with no parent <city>, or <city> with a single



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