gnome-panel r10984 - in trunk: . applets/clock



Author: vuntz
Date: Mon Apr  7 10:57:32 2008
New Revision: 10984
URL: http://svn.gnome.org/viewvc/gnome-panel?rev=10984&view=rev

Log:
2008-04-07  Vincent Untz  <vuntz gnome org>

	* configure.in: require gweather 2.22.1, do not check for libxml and
	the locations.xml file for the clock applet
	End of bug #519823.

2008-04-07  Vincent Untz  <vuntz gnome org>

	Use new gweather API, and make sure we always use data from the right
	country. Patch by Dan Winship <danw gnome org>. Fix bug #519823.

	* gweather-xml.c: gone, moved to libgweather
	* clock-location.c: updated
	* Makefile.am: updated
	* clock.c: #include <libgweather/gweather-xml.h> rather than
	"gweather-xml.h"
	(find_timezone): if the weather station has a country code
	associated with it, only return timezones that are also located in
	that country.
	(update_timezone): Use the tz-hint and iso-code from the location
	data to more reliably pick a timezone. #519823.
	(find_weather_code): Moved here from gweather-xml.c and updated to
	look for a matching country code as well.


Removed:
   trunk/applets/clock/gweather-xml.c
   trunk/applets/clock/gweather-xml.h
Modified:
   trunk/ChangeLog
   trunk/applets/clock/ChangeLog
   trunk/applets/clock/Makefile.am
   trunk/applets/clock/clock-location.c
   trunk/applets/clock/clock.c
   trunk/configure.in

Modified: trunk/applets/clock/Makefile.am
==============================================================================
--- trunk/applets/clock/Makefile.am	(original)
+++ trunk/applets/clock/Makefile.am	Mon Apr  7 10:57:32 2008
@@ -20,7 +20,6 @@
 	-DCLOCK_TIME_UTILITY="\"$(CLOCK_TIME_UTILITY)\""	\
 	-DEVOLUTION_TEXTDOMAIN=\"evolution-2.12\"		\
 	-DSYSTEM_ZONEINFODIR=\"/usr/share/zoneinfo\"		\
-	-DGWEATHER_XML_LOCATION=\"$(LIBGWEATHER_LOCATIONS)\"	\
 	-DGWEATHER_I_KNOW_THIS_IS_UNSTABLE
 
 if HAVE_LIBECAL
@@ -67,8 +66,6 @@
 	clock-zoneinfo.h	\
 	clock-zonetable.c	\
 	clock-zonetable.h	\
-	gweather-xml.c		\
-	gweather-xml.h		\
 	$(BUILT_SOURCES)	\
 	$(CALENDAR_SOURCES)	\
 	$(SETTIME_SOURCES)

Modified: trunk/applets/clock/clock-location.c
==============================================================================
--- trunk/applets/clock/clock-location.c	(original)
+++ trunk/applets/clock/clock-location.c	Mon Apr  7 10:57:32 2008
@@ -26,7 +26,6 @@
 #include "clock-location.h"
 #include "clock-marshallers.h"
 #include "set-timezone.h"
-#include "gweather-xml.h"
 
 G_DEFINE_TYPE (ClockLocation, clock_location, G_TYPE_OBJECT)
 
@@ -983,7 +982,7 @@
 
 	dms = rad2dms (priv->latitude, priv->longitude);
 	wl = weather_location_new (priv->name, priv->weather_code,
-				   NULL, NULL, dms);
+				   NULL, NULL, dms, NULL, NULL);
 
 	priv->weather_info =
 		weather_info_new (wl, &prefs, weather_info_updated, loc);

Modified: trunk/applets/clock/clock.c
==============================================================================
--- trunk/applets/clock/clock.c	(original)
+++ trunk/applets/clock/clock.c	Mon Apr  7 10:57:32 2008
@@ -50,6 +50,7 @@
 
 #include <glade/glade.h>
 #include <libgweather/gweather-prefs.h>
+#include <libgweather/gweather-xml.h>
 
 #include "clock.h"
 
@@ -59,7 +60,6 @@
 #include "clock-map.h"
 #include "clock-utils.h"
 #include "clock-zonetable.h"
-#include "gweather-xml.h"
 #include "obox.h"
 #include "set-timezone.h"
 
@@ -3190,19 +3190,28 @@
 }
 
 static gchar *
-find_timezone (ClockData *cd, const char *name, gfloat lat, gfloat lon)
+find_timezone (ClockData *cd, const char *name, const char *iso_code,
+               gfloat lat, gfloat lon)
 {
         ClockZoneTable *zonetab = cd->zones;
 	GList *zones, *l;
 	double dist, d;
 	gfloat zlat, zlon;
 	ClockZoneInfo *best;
+        const char *country;
 
 	dist = 1e6;
 	best = NULL;
 	zones = clock_zonetable_get_zones (zonetab);
 	for (l = zones; l; l = l->next) {
 		ClockZoneInfo *info = l->data;
+
+                if (iso_code) {
+                        country = clock_zoneinfo_get_country (info);
+                        if (!country || g_ascii_strcasecmp (iso_code, country) != 0)
+                                continue;
+                }
+
 		clock_zoneinfo_get_coords (info, &zlat, &zlon);
 
 		d = distance (lat, lon, zlat*M_PI/180.0, zlon*M_PI/180.0);
@@ -3213,13 +3222,16 @@
 		}
 	}
 
-	clock_zoneinfo_get_coords (best, &zlat, &zlon);
-
-	return g_strdup (clock_zoneinfo_get_name (best));
+        if (best)
+                return g_strdup (clock_zoneinfo_get_name (best));
+        else
+                return NULL;
 }
 
 static void
-update_timezone (ClockData *cd, const char *name, gboolean valid, gfloat lat, gfloat lon)
+update_timezone (ClockData *cd, const char *name,
+                 const char *country_code, const char *tz_hint,
+                 gboolean valid, gfloat lat, gfloat lon)
 {
         GtkWidget *zone_combo = glade_xml_get_widget (cd->glade_xml, "edit-location-timezone-combo");
 	gchar *timezone;
@@ -3239,7 +3251,14 @@
 	prefs.temperature_unit = cd->temperature_unit;
 	prefs.speed_unit = cd->speed_unit;
 
-	timezone = find_timezone (cd, name, lat, lon);
+        if (tz_hint)
+                timezone = g_strdup (tz_hint);
+        else {
+                timezone = find_timezone (cd, name, country_code, lat, lon);
+                if (!timezone)
+                        return;
+        }
+
 	loc = clock_location_new (name, timezone, lat*180.0/M_PI, lon*180.0/M_PI, NULL, &prefs);
 
 	g_signal_handler_block (zone_combo, cd->zone_combo_changed);
@@ -3279,10 +3298,8 @@
 
 	update_coords (cd, loc->latlon_valid, loc->latitude*180.0/M_PI, loc->longitude*180.0/M_PI);
 
-	/* FIXME: loc->zone can gives us the timezone. For Bristol, it's
-	 * :westcountry. No idea how to map this to a real timezone, though. */
-	update_timezone (cd, loc->name, loc->latlon_valid,
-			 loc->latitude, loc->longitude);
+	update_timezone (cd, loc->name, loc->country_code, loc->tz_hint,
+                         loc->latlon_valid, loc->latitude, loc->longitude);
 
 	find_hide (NULL, cd);
 }
@@ -3309,9 +3326,6 @@
 	if (gtk_tree_view_get_model (tree) != NULL)
 		return;
 
-	model = (GtkTreeModel*) gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
-	gtk_tree_view_set_model (tree, model);
-
 	cell = gtk_cell_renderer_text_new ();
 	column = gtk_tree_view_column_new_with_attributes ("not used", cell,
 							   "text", GWEATHER_XML_COL_LOC, NULL);
@@ -3321,7 +3335,9 @@
 	g_signal_connect (tree, "row-activated",
                           G_CALLBACK (location_row_activated), cd);
 
-	gweather_xml_load_locations (tree);
+	model = gweather_xml_load_locations ();
+	gtk_tree_view_set_model (tree, model);
+        g_object_unref (model);
 }
 
 static void
@@ -3564,6 +3580,70 @@
         return TRUE;
 }
 
+typedef struct {
+  const gchar *name;
+  const gchar *country_code;
+  gdouble latitude;
+  gdouble longitude;
+  gdouble distance;
+  WeatherLocation *location;
+} SearchData;
+  
+static gboolean
+compare_location (GtkTreeModel *model,
+                  GtkTreePath  *path,
+                  GtkTreeIter  *iter,
+                  gpointer      user_data)
+{
+  SearchData *data = user_data;
+  WeatherLocation *loc;
+  gdouble d;
+   
+  gtk_tree_model_get (model, iter, GWEATHER_XML_COL_POINTER, &loc, -1);
+
+  if (!loc)
+    return FALSE;
+  if (loc->country_code && data->country_code &&
+      g_ascii_strcasecmp (loc->country_code, data->country_code) != 0)
+    return FALSE;
+
+  d = distance (data->latitude, data->longitude, loc->latitude, loc->longitude);
+
+  if (d < data->distance) {
+    data->distance = d;
+    data->location = loc;
+  }
+
+  return FALSE;
+}
+
+static gchar *
+find_weather_code (GtkTreeModel *model,
+		   const gchar  *name,
+		   const gchar  *iso_code,
+                   gdouble       lat, 
+                   gdouble       lon)
+{
+  SearchData data;
+  gchar *code;
+
+  data.name = name;
+  data.country_code = iso_code;
+  data.latitude = lat;
+  data.longitude = lon;
+  data.distance = 1e6;
+  data.location = NULL;
+
+  gtk_tree_model_foreach (GTK_TREE_MODEL (model), compare_location, &data);
+
+  if (data.location)
+    code = g_strdup (data.location->code);
+  else
+    code = g_strdup ("-");
+
+  return code;
+}
+
 static void
 zone_combo_changed (GtkComboBox *widget, ClockData *cd)
 {
@@ -3619,7 +3699,8 @@
 
 	fill_location_tree (cd);
 	model = gtk_tree_view_get_model (GTK_TREE_VIEW (cd->location_tree));
-	weather_code = find_weather_code (model, city, lat * M_PI/180.0, lon * M_PI/180.0);
+	weather_code = find_weather_code (model, city, clock_zoneinfo_get_country (info),
+                                          lat * M_PI/180.0, lon * M_PI/180.0);
 	g_object_set_data_full (G_OBJECT (edit_window), "weather-code", weather_code, g_free);
 }
 

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Mon Apr  7 10:57:32 2008
@@ -66,7 +66,7 @@
 LIBEDATASERVERUI_REQUIRED=1.2.0
 CAIRO_REQUIRED=1.0.0
 DBUS_GLIB_REQUIRED=0.60
-GWEATHER_REQUIRED=2.22.0
+GWEATHER_REQUIRED=2.22.1
 
 dnl pkg-config dependency checks
 
@@ -111,13 +111,10 @@
 AM_CONDITIONAL(HAVE_LIBECAL, test -n "$LIBECAL_REQUIREMENT")
 AC_SUBST(CLOCK_EDS_ICONDIR)
 
-PKG_CHECK_MODULES(CLOCK, pango >= $PANGO_REQUIRED gtk+-2.0 >= $GTK_REQUIRED glib-2.0 >= $GLIB_REQUIRED gio-2.0 >= $GLIB_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED $LIBECAL_REQUIREMENT libglade-2.0 >= $LIBGLADE_REQUIRED librsvg-2.0 dbus-glib-1 gweather >= $GWEATHER_REQUIRED libxml-2.0)
+PKG_CHECK_MODULES(CLOCK, pango >= $PANGO_REQUIRED gtk+-2.0 >= $GTK_REQUIRED glib-2.0 >= $GLIB_REQUIRED gio-2.0 >= $GLIB_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED $LIBECAL_REQUIREMENT libglade-2.0 >= $LIBGLADE_REQUIRED librsvg-2.0 dbus-glib-1 gweather >= $GWEATHER_REQUIRED)
 AC_SUBST(CLOCK_CFLAGS)
 AC_SUBST(CLOCK_LIBS)
 
-LIBGWEATHER_LOCATIONS=`pkg-config --variable=locations_file gweather`
-AC_SUBST(LIBGWEATHER_LOCATIONS)
-
 dnl Hmm, we already checked for these above.  Is there a way to avoid checking twice?
 PKG_CHECK_MODULES(CLOCK_MECHANISM, [ gthread-2.0 dbus-glib-1 ])
 AC_SUBST(CLOCK_MECHANISM_CFLAGS)



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