[libgweather] Support multiple locations within a city
- From: Frank Solensky <fsolensky src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgweather] Support multiple locations within a city
- Date: Sun, 20 Dec 2009 02:52:33 +0000 (UTC)
commit 9d0ffc4893f74126bbee0687ed0f9e15e592136d
Author: Frank Solensky <frank src gnome org>
Date: Sat Dec 19 18:22:43 2009 -0500
Support multiple locations within a city
Allow the user to specify which location within a city that they would
prefer to use. Since the array is sorted by distance, selecting the
first displayed entry would give the same results that the user is
offered presently.
Closes bgo #604636
libgweather/gweather-xml.c | 31 ++++++++++++++++-----
libgweather/location-entry.c | 60 ++++++++++++++++++++++++++++++++++++-----
2 files changed, 76 insertions(+), 15 deletions(-)
---
diff --git a/libgweather/gweather-xml.c b/libgweather/gweather-xml.c
index b3a8118..8e89009 100644
--- a/libgweather/gweather-xml.c
+++ b/libgweather/gweather-xml.c
@@ -37,7 +37,7 @@ gweather_xml_parse_node (GWeatherLocation *gloc,
GtkTreeStore *store, GtkTreeIter *parent)
{
GtkTreeIter iter, *self = &iter;
- GWeatherLocation **children;
+ GWeatherLocation **children, *parent_loc;
GWeatherLocationLevel level;
WeatherLocation *wloc;
const char *name;
@@ -47,7 +47,7 @@ gweather_xml_parse_node (GWeatherLocation *gloc,
children = gweather_location_get_children (gloc);
level = gweather_location_get_level (gloc);
- if (!children[0]) {
+ if (!children[0] && level < GWEATHER_LOCATION_WEATHER_STATION) {
gweather_location_free_children (gloc, children);
return TRUE;
}
@@ -69,18 +69,35 @@ gweather_xml_parse_node (GWeatherLocation *gloc,
break;
case GWEATHER_LOCATION_CITY:
- /* Merge with child location */
+ /* If multiple children, treat this like a
+ * region/country/adm1. If a single child, merge with that
+ * location.
+ */
gtk_tree_store_append (store, &iter, parent);
gtk_tree_store_set (store, &iter,
GWEATHER_XML_COL_LOC, name,
-1);
- wloc = gweather_location_to_weather_location (children[0], name);
- gtk_tree_store_set (store, &iter,
- GWEATHER_XML_COL_POINTER, wloc,
- -1);
+ if (children[0] && !children[1]) {
+ wloc = gweather_location_to_weather_location (children[0], name);
+ gtk_tree_store_set (store, &iter,
+ GWEATHER_XML_COL_POINTER, wloc,
+ -1);
+ }
break;
case GWEATHER_LOCATION_WEATHER_STATION:
+ gtk_tree_store_append (store, &iter, parent);
+ gtk_tree_store_set (store, &iter,
+ GWEATHER_XML_COL_LOC, name,
+ -1);
+
+ parent_loc = gweather_location_get_parent (gloc);
+ if (parent_loc && gweather_location_get_level (parent_loc) == GWEATHER_LOCATION_CITY)
+ name = gweather_location_get_name (parent_loc);
+ wloc = gweather_location_to_weather_location (gloc, name);
+ gtk_tree_store_set (store, &iter,
+ GWEATHER_XML_COL_POINTER, wloc,
+ -1);
break;
}
diff --git a/libgweather/location-entry.c b/libgweather/location-entry.c
index 34cc5ca..dbe85d7 100644
--- a/libgweather/location-entry.c
+++ b/libgweather/location-entry.c
@@ -386,10 +386,58 @@ fill_location_entry_model (GtkTreeStore *store, GWeatherLocation *loc,
break;
case GWEATHER_LOCATION_CITY:
- if (!children[0])
- break;
+ 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),
+ gweather_location_get_name (children[i]),
+ parent_display_name);
+ compare_name = g_strdup_printf ("%s (%s), %s",
+ gweather_location_get_sort_name (loc),
+ gweather_location_get_sort_name (children[i]),
+ parent_compare_name);
+
+ gtk_tree_store_append (store, &iter, NULL);
+ gtk_tree_store_set (store, &iter,
+ GWEATHER_LOCATION_ENTRY_COL_LOCATION, children[i],
+ 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 (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);
+ }
+ break;
- /* Merge the city name with the location-specific information. */
+ case GWEATHER_LOCATION_WEATHER_STATION:
+ /* <location> with no parent <city>, or <city> with a single
+ * child <location>.
+ */
display_name = g_strdup_printf ("%s, %s",
gweather_location_get_name (loc),
parent_display_name);
@@ -399,7 +447,7 @@ fill_location_entry_model (GtkTreeStore *store, GWeatherLocation *loc,
gtk_tree_store_append (store, &iter, NULL);
gtk_tree_store_set (store, &iter,
- GWEATHER_LOCATION_ENTRY_COL_LOCATION, children[0],
+ GWEATHER_LOCATION_ENTRY_COL_LOCATION, loc,
GWEATHER_LOCATION_ENTRY_COL_DISPLAY_NAME, display_name,
GWEATHER_LOCATION_ENTRY_COL_COMPARE_NAME, compare_name,
-1);
@@ -407,10 +455,6 @@ fill_location_entry_model (GtkTreeStore *store, GWeatherLocation *loc,
g_free (display_name);
g_free (compare_name);
break;
-
- case GWEATHER_LOCATION_WEATHER_STATION:
- /* Shouldn't happen. Ignore */
- break;
}
gweather_location_free_children (loc, children);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]