[gnome-control-center/setup] Initial implementation of the location page



commit bb194eef0697a118d0586735eae91a78789e49fe
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri May 13 07:41:16 2011 -0400

    Initial implementation of the location page
    
    Search and map work; geoip support still missing.

 configure.ac                  |    2 +-
 setup/Makefile.am             |    9 +-
 setup/cc-timezone-map.c       |  613 +++++++++++++++++++++++++++++++++++++++++
 setup/cc-timezone-map.h       |   79 ++++++
 setup/gnome-setup-assistant.c |  192 +++++++++++++-
 setup/set-timezone.c          |  479 ++++++++++++++++++++++++++++++++
 setup/set-timezone.h          |   57 ++++
 setup/setup.ui                |  500 ++++++++++++++++++++++------------
 setup/tz.c                    |  475 +++++++++++++++++++++++++++++++
 setup/tz.h                    |   89 ++++++
 10 files changed, 2317 insertions(+), 178 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 96bc5b5..fa57c1b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -91,7 +91,7 @@ PKG_CHECK_MODULES(LIBGNOME_CONTROL_CENTER, $COMMON_MODULES gconf-2.0)
 PKG_CHECK_MODULES(LIBLANGUAGE, $COMMON_MODULES gnome-desktop-3.0)
 PKG_CHECK_MODULES(LIBSHORTCUTS, $COMMON_MODULES x11)
 PKG_CHECK_MODULES(SHELL, $COMMON_MODULES libgnome-menu gio-unix-2.0)
-PKG_CHECK_MODULES(SETUP, $COMMON_MODULES accountsservice)
+PKG_CHECK_MODULES(SETUP, $COMMON_MODULES accountsservice gweather-3.0)
 PKG_CHECK_MODULES(BACKGROUND_PANEL, $COMMON_MODULES libxml-2.0 gnome-desktop-3.0
                   gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION)
 PKG_CHECK_MODULES(DATETIME_PANEL, $COMMON_MODULES dbus-glib-1
diff --git a/setup/Makefile.am b/setup/Makefile.am
index 2ad8cca..97d5c5d 100644
--- a/setup/Makefile.am
+++ b/setup/Makefile.am
@@ -12,11 +12,16 @@ gnome_setup_assistant_SOURCES =	\
 	gnome-setup-assistant.c \
 	panel-cell-renderer-signal.c panel-cell-renderer-signal.h \
 	panel-cell-renderer-mode.c panel-cell-renderer-mode.h \
-	panel-cell-renderer-security.c panel-cell-renderer-security.h
+	panel-cell-renderer-security.c panel-cell-renderer-security.h \
+	cc-timezone-map.c cc-timezone-map.h \
+	set-timezone.c set-timezone.h \
+	tz.c tz.h
 
 AM_CPPFLAGS = \
 	-DGNOMELOCALEDIR="\"$(datadir)/locale\"" \
-	-DUIDIR="\"$(uidir)\""
+	-DGNOMECC_DATA_DIR="\"$(pkgdatadir)\"" \
+	-DUIDIR="\"$(uidir)\"" \
+	-DDATADIR="\"$(pkgdatadir)/ui/datetime\""
 
 gsettings_SCHEMAS = org.gnome.control-center.setup.gschema.xml
 
diff --git a/setup/cc-timezone-map.c b/setup/cc-timezone-map.c
new file mode 100644
index 0000000..ba7ba40
--- /dev/null
+++ b/setup/cc-timezone-map.c
@@ -0,0 +1,613 @@
+/*
+ * Copyright (C) 2010 Intel, Inc
+ *
+ * Portions from Ubiquity, Copyright (C) 2009 Canonical Ltd.
+ * Written by Evan Dandrea <evand ubuntu com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Thomas Wood <thomas wood intel com>
+ *
+ */
+
+#include "cc-timezone-map.h"
+#include <math.h>
+#include <string.h>
+#include "tz.h"
+
+G_DEFINE_TYPE (CcTimezoneMap, cc_timezone_map, GTK_TYPE_WIDGET)
+
+#define TIMEZONE_MAP_PRIVATE(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_TIMEZONE_MAP, CcTimezoneMapPrivate))
+
+
+typedef struct
+{
+  gdouble offset;
+  guchar red;
+  guchar green;
+  guchar blue;
+  guchar alpha;
+} CcTimezoneMapOffset;
+
+struct _CcTimezoneMapPrivate
+{
+  GdkPixbuf *orig_background;
+  GdkPixbuf *orig_color_map;
+
+  GdkPixbuf *background;
+  GdkPixbuf *color_map;
+
+  guchar *visible_map_pixels;
+  gint visible_map_rowstride;
+
+  gdouble selected_offset;
+
+  TzDB *tzdb;
+  TzLocation *location;
+};
+
+enum
+{
+  LOCATION_CHANGED,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
+
+static CcTimezoneMapOffset color_codes[] =
+{
+    {-11.0, 43, 0, 0, 255 },
+    {-10.0, 85, 0, 0, 255 },
+    {-9.5, 102, 255, 0, 255 },
+    {-9.0, 128, 0, 0, 255 },
+    {-8.0, 170, 0, 0, 255 },
+    {-7.0, 212, 0, 0, 255 },
+    {-6.0, 255, 0, 1, 255 }, // north
+    {-6.0, 255, 0, 0, 255 }, // south
+    {-5.0, 255, 42, 42, 255 },
+    {-4.5, 192, 255, 0, 255 },
+    {-4.0, 255, 85, 85, 255 },
+    {-3.5, 0, 255, 0, 255 },
+    {-3.0, 255, 128, 128, 255 },
+    {-2.0, 255, 170, 170, 255 },
+    {-1.0, 255, 213, 213, 255 },
+    {0.0, 43, 17, 0, 255 },
+    {1.0, 85, 34, 0, 255 },
+    {2.0, 128, 51, 0, 255 },
+    {3.0, 170, 68, 0, 255 },
+    {3.5, 0, 255, 102, 255 },
+    {4.0, 212, 85, 0, 255 },
+    {4.5, 0, 204, 255, 255 },
+    {5.0, 255, 102, 0, 255 },
+    {5.5, 0, 102, 255, 255 },
+    {5.75, 0, 238, 207, 247 },
+    {6.0, 255, 127, 42, 255 },
+    {6.5, 204, 0, 254, 254 },
+    {7.0, 255, 153, 85, 255 },
+    {8.0, 255, 179, 128, 255 },
+    {9.0, 255, 204, 170, 255 },
+    {9.5, 170, 0, 68, 250 },
+    {10.0, 255, 230, 213, 255 },
+    {10.5, 212, 124, 21, 250 },
+    {11.0, 212, 170, 0, 255 },
+    {11.5, 249, 25, 87, 253 },
+    {12.0, 255, 204, 0, 255 },
+    {12.75, 254, 74, 100, 248 },
+    {13.0, 255, 85, 153, 250 },
+    {-100, 0, 0, 0, 0 }
+};
+
+
+static void
+cc_timezone_map_get_property (GObject    *object,
+                              guint       property_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  switch (property_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
+}
+
+static void
+cc_timezone_map_set_property (GObject      *object,
+                              guint         property_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
+{
+  switch (property_id)
+    {
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+    }
+}
+
+static void
+cc_timezone_map_dispose (GObject *object)
+{
+  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (object)->priv;
+
+  if (priv->orig_background)
+    {
+      g_object_unref (priv->orig_background);
+      priv->orig_background = NULL;
+    }
+
+  if (priv->orig_color_map)
+    {
+      g_object_unref (priv->orig_color_map);
+      priv->orig_color_map = NULL;
+    }
+
+  if (priv->background)
+    {
+      g_object_unref (priv->background);
+      priv->background = NULL;
+    }
+
+  if (priv->color_map)
+    {
+      g_object_unref (priv->color_map);
+      priv->color_map = NULL;
+
+      priv->visible_map_pixels = NULL;
+      priv->visible_map_rowstride = 0;
+    }
+
+  G_OBJECT_CLASS (cc_timezone_map_parent_class)->dispose (object);
+}
+
+static void
+cc_timezone_map_finalize (GObject *object)
+{
+  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (object)->priv;
+
+  if (priv->tzdb)
+    {
+      tz_db_free (priv->tzdb);
+      priv->tzdb = NULL;
+    }
+
+
+  G_OBJECT_CLASS (cc_timezone_map_parent_class)->finalize (object);
+}
+
+/* GtkWidget functions */
+static void
+cc_timezone_map_get_preferred_width (GtkWidget *widget,
+                                     gint      *minimum,
+                                     gint      *natural)
+{
+  /* choose a minimum size small enough to prevent the window
+   * from growing horizontally
+   */
+  if (minimum != NULL)
+    *minimum = 300;
+  if (natural != NULL)
+    *natural = 300;
+}
+
+static void
+cc_timezone_map_get_preferred_height (GtkWidget *widget,
+                                      gint      *minimum,
+                                      gint      *natural)
+{
+  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
+  gint size;
+
+  /* The + 20 here is a slight tweak to make the map fill the
+   * panel better without causing horizontal growing
+   */
+  size = 300 * gdk_pixbuf_get_height (priv->orig_background) / gdk_pixbuf_get_width (priv->orig_background) + 20;
+  if (minimum != NULL)
+    *minimum = size;
+  if (natural != NULL)
+    *natural = size;
+}
+
+static void
+cc_timezone_map_size_allocate (GtkWidget     *widget,
+                               GtkAllocation *allocation)
+{
+  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
+
+  if (priv->background)
+    g_object_unref (priv->background);
+
+  priv->background = gdk_pixbuf_scale_simple (priv->orig_background,
+                                              allocation->width,
+                                              allocation->height,
+                                              GDK_INTERP_BILINEAR);
+
+  if (priv->color_map)
+    g_object_unref (priv->color_map);
+
+  priv->color_map = gdk_pixbuf_scale_simple (priv->orig_color_map,
+                                             allocation->width,
+                                             allocation->height,
+                                             GDK_INTERP_BILINEAR);
+
+  priv->visible_map_pixels = gdk_pixbuf_get_pixels (priv->color_map);
+  priv->visible_map_rowstride = gdk_pixbuf_get_rowstride (priv->color_map);
+
+  GTK_WIDGET_CLASS (cc_timezone_map_parent_class)->size_allocate (widget,
+                                                                  allocation);
+}
+
+static void
+cc_timezone_map_realize (GtkWidget *widget)
+{
+  GdkWindowAttr attr = { 0, };
+  GtkAllocation allocation;
+  GdkCursor *cursor;
+  GdkWindow *window;
+
+  gtk_widget_get_allocation (widget, &allocation);
+
+  gtk_widget_set_realized (widget, TRUE);
+
+  attr.window_type = GDK_WINDOW_CHILD;
+  attr.wclass = GDK_INPUT_OUTPUT;
+  attr.width = allocation.width;
+  attr.height = allocation.height;
+  attr.x = allocation.x;
+  attr.y = allocation.y;
+  attr.event_mask = gtk_widget_get_events (widget)
+                                 | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
+
+  window = gdk_window_new (gtk_widget_get_parent_window (widget), &attr,
+                           GDK_WA_X | GDK_WA_Y);
+
+  cursor = gdk_cursor_new (GDK_HAND2);
+  gdk_window_set_cursor (window, cursor);
+
+  gdk_window_set_user_data (window, widget);
+  gtk_widget_set_window (widget, window);
+}
+
+
+static gdouble
+convert_longtitude_to_x (gdouble longitude, gint map_width)
+{
+  const gdouble xdeg_offset = -6;
+  gdouble x;
+
+  x = (map_width * (180.0 + longitude) / 360.0)
+    + (map_width * xdeg_offset / 180.0);
+
+  return x;
+}
+
+static gdouble
+radians (gdouble degrees)
+{
+  return (degrees / 360.0) * G_PI * 2;
+}
+
+static gdouble
+convert_latitude_to_y (gdouble latitude, gdouble map_height)
+{
+  gdouble bottom_lat = -59;
+  gdouble top_lat = 81;
+  gdouble top_per, y, full_range, top_offset, map_range;
+
+  top_per = top_lat / 180.0;
+  y = 1.25 * log (tan (G_PI_4 + 0.4 * radians (latitude)));
+  full_range = 4.6068250867599998;
+  top_offset = full_range * top_per;
+  map_range = fabs (1.25 * log (tan (G_PI_4 + 0.4 * radians (bottom_lat))) - top_offset);
+  y = fabs (y - top_offset);
+  y = y / map_range;
+  y = y * map_height;
+  return y;
+}
+
+
+static gboolean
+cc_timezone_map_draw (GtkWidget *widget,
+                      cairo_t   *cr)
+{
+  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
+  GdkPixbuf *hilight, *orig_hilight, *pin;
+  GtkAllocation alloc;
+  gchar *file;
+  GError *err = NULL;
+  gdouble pointx, pointy;
+  char buf[16];
+
+  gtk_widget_get_allocation (widget, &alloc);
+
+  /* paint background */
+  gdk_cairo_set_source_pixbuf (cr, priv->background, 0, 0);
+  cairo_paint (cr);
+
+  /* paint hilight */
+  file = g_strdup_printf (DATADIR "/timezone_%s.png",
+                          g_ascii_formatd (buf, sizeof (buf),
+                                           "%g", priv->selected_offset));
+  orig_hilight = gdk_pixbuf_new_from_file (file, &err);
+  g_free (file);
+  file = NULL;
+
+  if (!orig_hilight)
+    {
+      g_warning ("Could not load hilight: %s",
+                 (err) ? err->message : "Unknown Error");
+      if (err)
+        g_clear_error (&err);
+    }
+  else
+    {
+
+      hilight = gdk_pixbuf_scale_simple (orig_hilight, alloc.width,
+                                         alloc.height, GDK_INTERP_BILINEAR);
+      gdk_cairo_set_source_pixbuf (cr, hilight, 0, 0);
+
+      cairo_paint (cr);
+      g_object_unref (hilight);
+      g_object_unref (orig_hilight);
+    }
+
+  /* load pin icon */
+  pin = gdk_pixbuf_new_from_file (DATADIR "/pin.png", &err);
+
+  if (err)
+    {
+      g_warning ("Could not load pin icon: %s", err->message);
+      g_clear_error (&err);
+    }
+
+  if (priv->location)
+    {
+      pointx = convert_longtitude_to_x (priv->location->longitude, alloc.width);
+      pointy = convert_latitude_to_y (priv->location->latitude, alloc.height);
+
+      if (pointy > alloc.height)
+        pointy = alloc.height;
+
+      if (pin)
+        {
+          gdk_cairo_set_source_pixbuf (cr, pin, pointx - 8, pointy - 14);
+          cairo_paint (cr);
+        }
+    }
+
+  if (pin)
+    {
+      g_object_unref (pin);
+    }
+
+  return TRUE;
+}
+
+
+static void
+cc_timezone_map_class_init (CcTimezoneMapClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (CcTimezoneMapPrivate));
+
+  object_class->get_property = cc_timezone_map_get_property;
+  object_class->set_property = cc_timezone_map_set_property;
+  object_class->dispose = cc_timezone_map_dispose;
+  object_class->finalize = cc_timezone_map_finalize;
+
+  widget_class->get_preferred_width = cc_timezone_map_get_preferred_width;
+  widget_class->get_preferred_height = cc_timezone_map_get_preferred_height;
+  widget_class->size_allocate = cc_timezone_map_size_allocate;
+  widget_class->realize = cc_timezone_map_realize;
+  widget_class->draw = cc_timezone_map_draw;
+
+  signals[LOCATION_CHANGED] = g_signal_new ("location-changed",
+                                            CC_TYPE_TIMEZONE_MAP,
+                                            G_SIGNAL_RUN_FIRST,
+                                            0,
+                                            NULL,
+                                            NULL,
+                                            g_cclosure_marshal_VOID__POINTER,
+                                            G_TYPE_NONE, 1,
+                                            G_TYPE_POINTER);
+}
+
+
+static gint
+sort_locations (TzLocation *a,
+                TzLocation *b)
+{
+  if (a->dist > b->dist)
+    return 1;
+
+  if (a->dist < b->dist)
+    return -1;
+
+  return 0;
+}
+
+static void
+set_location (CcTimezoneMap *map,
+              TzLocation    *location)
+{
+  CcTimezoneMapPrivate *priv = map->priv;
+  TzInfo *info;
+
+  priv->location = location;
+
+  info = tz_info_from_location (priv->location);
+
+  priv->selected_offset = tz_location_get_utc_offset (priv->location)
+    / (60.0*60.0) + ((info->daylight) ? -1.0 : 0.0);
+
+  g_signal_emit (map, signals[LOCATION_CHANGED], 0, priv->location);
+
+  tz_info_free (info);
+}
+
+static gboolean
+button_press_event (GtkWidget      *widget,
+                    GdkEventButton *event)
+{
+  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
+  gint x, y;
+  guchar r, g, b, a;
+  guchar *pixels;
+  gint rowstride;
+  gint i;
+
+  const GPtrArray *array;
+  gint width, height;
+  GList *distances = NULL;
+  GtkAllocation alloc;
+
+  x = event->x;
+  y = event->y;
+
+
+  rowstride = priv->visible_map_rowstride;
+  pixels = priv->visible_map_pixels;
+
+  r = pixels[(rowstride * y + x * 4)];
+  g = pixels[(rowstride * y + x * 4) + 1];
+  b = pixels[(rowstride * y + x * 4) + 2];
+  a = pixels[(rowstride * y + x * 4) + 3];
+
+
+  for (i = 0; color_codes[i].offset != -100; i++)
+    {
+       if (color_codes[i].red == r && color_codes[i].green == g
+           && color_codes[i].blue == b && color_codes[i].alpha == a)
+         {
+           priv->selected_offset = color_codes[i].offset;
+         }
+    }
+
+  gtk_widget_queue_draw (widget);
+
+  /* work out the co-ordinates */
+
+  array = tz_get_locations (priv->tzdb);
+
+  gtk_widget_get_allocation (widget, &alloc);
+  width = alloc.width;
+  height = alloc.height;
+
+  for (i = 0; i < array->len; i++)
+    {
+      gdouble pointx, pointy, dx, dy;
+      TzLocation *loc = array->pdata[i];
+
+      pointx = convert_longtitude_to_x (loc->longitude, width);
+      pointy = convert_latitude_to_y (loc->latitude, height);
+
+      dx = pointx - x;
+      dy = pointy - y;
+
+      loc->dist = dx * dx + dy * dy;
+      distances = g_list_prepend (distances, loc);
+
+    }
+  distances = g_list_sort (distances, (GCompareFunc) sort_locations);
+
+
+  set_location (CC_TIMEZONE_MAP (widget), (TzLocation*) distances->data);
+
+  g_list_free (distances);
+
+  return TRUE;
+}
+
+static void
+cc_timezone_map_init (CcTimezoneMap *self)
+{
+  CcTimezoneMapPrivate *priv;
+  GError *err = NULL;
+
+  priv = self->priv = TIMEZONE_MAP_PRIVATE (self);
+
+  priv->orig_background = gdk_pixbuf_new_from_file (DATADIR "/bg.png",
+                                                    &err);
+
+  if (!priv->orig_background)
+    {
+      g_warning ("Could not load background image: %s",
+                 (err) ? err->message : "Unknown error");
+      g_clear_error (&err);
+    }
+
+  priv->orig_color_map = gdk_pixbuf_new_from_file (DATADIR "/cc.png",
+                                                   &err);
+  if (!priv->orig_color_map)
+    {
+      g_warning ("Could not load background image: %s",
+                 (err) ? err->message : "Unknown error");
+      g_clear_error (&err);
+    }
+
+  priv->tzdb = tz_load_db ();
+
+  g_signal_connect (self, "button-press-event", G_CALLBACK (button_press_event),
+                    NULL);
+}
+
+CcTimezoneMap *
+cc_timezone_map_new (void)
+{
+  return g_object_new (CC_TYPE_TIMEZONE_MAP, NULL);
+}
+
+gboolean
+cc_timezone_map_set_timezone (CcTimezoneMap *map,
+                              const gchar   *timezone)
+{
+  GPtrArray *locations;
+  guint i;
+  char *real_tz;
+  gboolean ret;
+
+  real_tz = tz_info_get_clean_name (map->priv->tzdb, timezone);
+
+  locations = tz_get_locations (map->priv->tzdb);
+  ret = FALSE;
+
+  for (i = 0; i < locations->len; i++)
+    {
+      TzLocation *loc = locations->pdata[i];
+
+      if (!g_strcmp0 (loc->zone, real_tz ? real_tz : timezone))
+        {
+          set_location (map, loc);
+          ret = TRUE;
+          break;
+        }
+    }
+
+  if (ret)
+    gtk_widget_queue_draw (GTK_WIDGET (map));
+
+  g_free (real_tz);
+
+  return ret;
+}
+
+TzLocation *
+cc_timezone_map_get_location (CcTimezoneMap *map)
+{
+  return map->priv->location;
+}
diff --git a/setup/cc-timezone-map.h b/setup/cc-timezone-map.h
new file mode 100644
index 0000000..bb15def
--- /dev/null
+++ b/setup/cc-timezone-map.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2010 Intel, Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Author: Thomas Wood <thomas wood intel com>
+ *
+ */
+
+
+#ifndef _CC_TIMEZONE_MAP_H
+#define _CC_TIMEZONE_MAP_H
+
+#include <gtk/gtk.h>
+#include "tz.h"
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_TIMEZONE_MAP cc_timezone_map_get_type()
+
+#define CC_TIMEZONE_MAP(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+  CC_TYPE_TIMEZONE_MAP, CcTimezoneMap))
+
+#define CC_TIMEZONE_MAP_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), \
+  CC_TYPE_TIMEZONE_MAP, CcTimezoneMapClass))
+
+#define CC_IS_TIMEZONE_MAP(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+  CC_TYPE_TIMEZONE_MAP))
+
+#define CC_IS_TIMEZONE_MAP_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+  CC_TYPE_TIMEZONE_MAP))
+
+#define CC_TIMEZONE_MAP_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+  CC_TYPE_TIMEZONE_MAP, CcTimezoneMapClass))
+
+typedef struct _CcTimezoneMap CcTimezoneMap;
+typedef struct _CcTimezoneMapClass CcTimezoneMapClass;
+typedef struct _CcTimezoneMapPrivate CcTimezoneMapPrivate;
+
+struct _CcTimezoneMap
+{
+  GtkWidget parent;
+
+  CcTimezoneMapPrivate *priv;
+};
+
+struct _CcTimezoneMapClass
+{
+  GtkWidgetClass parent_class;
+};
+
+GType cc_timezone_map_get_type (void) G_GNUC_CONST;
+
+CcTimezoneMap *cc_timezone_map_new (void);
+
+gboolean cc_timezone_map_set_timezone (CcTimezoneMap *map,
+                                       const gchar   *timezone);
+TzLocation * cc_timezone_map_get_location (CcTimezoneMap *map);
+
+G_END_DECLS
+
+#endif /* _CC_TIMEZONE_MAP_H */
diff --git a/setup/gnome-setup-assistant.c b/setup/gnome-setup-assistant.c
index 48ddbf7..a599c69 100644
--- a/setup/gnome-setup-assistant.c
+++ b/setup/gnome-setup-assistant.c
@@ -16,6 +16,13 @@
 
 #include <act/act-user-manager.h>
 
+#include "cc-timezone-map.h"
+#include "set-timezone.h"
+
+#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
+#include <libgweather/location-entry.h>
+
+#define DEFAULT_TZ "Europe/London"
 
 typedef struct {
         GtkBuilder *builder;
@@ -42,6 +49,10 @@ typedef struct {
         ActUserAccountType account_type;
 
         gboolean user_data_unsaved;
+
+        /* location data */
+        CcTimezoneMap *map;
+        TzLocation *current_location;
 } SetupData;
 
 #define OBJ(type,name) ((type)gtk_builder_get_object(setup->builder,(name)))
@@ -371,7 +382,6 @@ refresh_wireless_list (SetupData *setup)
                 gtk_widget_hide (swin);
                 gtk_widget_hide (spinner);
                 gtk_widget_show (label);
-
                 goto out;
         }
         else if (aps == NULL || aps->len == 0) {
@@ -1135,6 +1145,185 @@ prepare_account_page (SetupData *setup)
         update_account_page_status (setup);
 }
 
+/* --- Location page --- */
+
+
+static void
+set_timezone_cb (SetupData *setup,
+                 GError    *error)
+{
+        /* TODO: display any error in a user friendly way */
+        if (error) {
+                g_warning ("Could not set system timezone: %s", error->message);
+        }
+}
+
+static void
+queue_set_timezone (SetupData *setup)
+{
+        /* for now just do it */
+        if (setup->current_location) {
+                set_system_timezone_async (setup->current_location->zone, (GFunc) set_timezone_cb, setup, NULL);
+        }
+}
+
+static void
+update_timezone (SetupData *setup)
+{
+        GtkWidget *widget;
+        GtkTreeIter iter;
+        GtkTreeModel *model;
+        GString *str;
+        gchar *location;
+        gchar *timezone;
+        gchar *c;
+
+        str = g_string_new ("");
+        for (c = setup->current_location->zone; *c; c++) {
+                switch (*c) {
+                case '_':
+                        g_string_append_c (str, ' ');
+                        break;
+                case '/':
+                        g_string_append (str, " / ");
+                        break;
+                default:
+                        g_string_append_c (str, *c);
+                }
+        }
+
+        c = strstr (str->str, " / ");
+        location = g_strdup (c + 3);
+        timezone = g_strdup (str->str);
+
+        gtk_label_set_label (OBJ(GtkLabel*,"current-location-label"), location);
+        gtk_label_set_label (OBJ(GtkLabel*,"current-timezone-label"), timezone);
+
+        g_free (location);
+        g_free (timezone);
+
+        g_string_free (str, TRUE);
+}
+
+static void
+location_changed_cb (CcTimezoneMap *map,
+                     TzLocation    *location,
+                     SetupData     *setup)
+{
+  g_debug ("location changed to %s/%s", location->country, location->zone);
+
+  setup->current_location = location;
+
+  update_timezone (setup);
+
+  queue_set_timezone (setup);
+}
+
+static void
+get_timezone_cb (SetupData   *setup,
+                 const gchar *timezone,
+                 GError      *error)
+{
+        if (error) {
+                g_warning ("Could not get current timezone: %s", error->message);
+        }
+        else {
+                if (!cc_timezone_map_set_timezone (setup->map, timezone)) {
+                        g_warning ("Timezone '%s' is unhandled, setting %s as default", timezone, DEFAULT_TZ);
+                        cc_timezone_map_set_timezone (setup->map, DEFAULT_TZ);
+                }
+                else {
+                        g_debug ("System timezone is '%s'", timezone);
+                }
+
+                setup->current_location = cc_timezone_map_get_location (setup->map);
+                update_timezone (setup);
+        }
+
+        g_signal_connect (setup->map, "location-changed",
+                          G_CALLBACK (location_changed_cb), setup);
+}
+
+static void
+location_changed (GObject *object, GParamSpec *param, SetupData *setup)
+{
+        GWeatherLocationEntry *entry = GWEATHER_LOCATION_ENTRY (object);
+        GWeatherLocation *gloc;
+        GWeatherTimezone *zone;
+        gchar *city;
+
+        gloc = gweather_location_entry_get_location (entry);
+        if (gloc == NULL)
+                return;
+
+        zone = gweather_location_get_timezone (gloc);
+        city = gweather_location_get_city_name (gloc);
+
+        if (zone != NULL) {
+                const gchar *name;
+                const gchar *id;
+                GtkLabel *label;
+
+                label = OBJ(GtkLabel*, "current-timezone-label");
+
+                name = gweather_timezone_get_name (zone);
+                id = gweather_timezone_get_tzid (zone);
+                if (name == NULL) {
+                        /* Why does this happen ? */
+                        name = id;
+                }
+                gtk_label_set_label (label, name);
+                cc_timezone_map_set_timezone (setup->map, id);
+        }
+
+        if (city != NULL) {
+                GtkLabel *label;
+
+                label = OBJ(GtkLabel*, "current-location-label");
+                gtk_label_set_label (label, city);
+        }
+
+        g_free (city);
+        gweather_location_unref (gloc);
+}
+
+static void
+prepare_location_page (SetupData *setup)
+{
+        GtkWidget *frame, *map, *entry;
+        GWeatherLocation *world;
+
+        frame = WID("location-map-frame");
+
+        setup->map = cc_timezone_map_new ();
+        map = (GtkWidget *)setup->map;
+        gtk_widget_set_hexpand (map, TRUE);
+        gtk_widget_set_vexpand (map, TRUE);
+        gtk_widget_set_halign (map, GTK_ALIGN_FILL);
+        gtk_widget_set_valign (map, GTK_ALIGN_FILL);
+        gtk_widget_show (map);
+
+        gtk_container_add (GTK_CONTAINER (frame), map);
+
+        get_system_timezone_async ((GetTimezoneFunc) get_timezone_cb, setup, NULL);
+
+        world = gweather_location_new_world (FALSE);
+        entry = gweather_location_entry_new (world);
+        gtk_entry_set_placeholder_text (GTK_ENTRY (entry), _("Search for a location"));
+        gtk_widget_set_halign (entry, GTK_ALIGN_END);
+        gtk_widget_show (entry);
+
+        frame = WID("location-page");
+        gtk_grid_attach (GTK_GRID (frame), entry, 1, 1, 1, 1);
+
+        g_signal_connect (G_OBJECT (entry), "notify::location",
+                          G_CALLBACK (location_changed), setup);
+#if 0
+        g_signal_connect (G_OBJECT (_entry), "changed",
+                          G_CALLBACK (location_name_changed), setup);
+#endif
+}
+
 /* --- Other setup --- */
 
 static void
@@ -1177,6 +1366,7 @@ prepare_assistant (SetupData *setup)
         prepare_welcome_page (setup);
         prepare_network_page (setup);
         prepare_account_page (setup);
+        prepare_location_page (setup);
 }
 
 int
diff --git a/setup/set-timezone.c b/setup/set-timezone.c
new file mode 100644
index 0000000..74006bc
--- /dev/null
+++ b/setup/set-timezone.c
@@ -0,0 +1,479 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 David Zeuthen <david fubar dk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/wait.h>
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "set-timezone.h"
+
+
+static DBusGConnection *
+get_system_bus (GError **err)
+{
+        GError          *error;
+        static DBusGConnection *bus = NULL;
+
+	if (bus == NULL) {
+        	error = NULL;
+        	bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+        	if (bus == NULL) {
+			g_propagate_error (err, error);
+		}
+        }
+
+        return bus;
+}
+
+#define CACHE_VALIDITY_SEC 2
+
+typedef  void (*CanDoFunc) (gint value);
+
+static void
+notify_can_do (DBusGProxy     *proxy,
+	       DBusGProxyCall *call,
+	       void           *user_data)
+{
+	CanDoFunc callback = user_data;
+	GError *error = NULL;
+	gint value;
+
+	if (dbus_g_proxy_end_call (proxy, call,
+				   &error,
+				   G_TYPE_INT, &value,
+				   G_TYPE_INVALID)) {
+		callback (value);
+	}
+}
+
+static void
+refresh_can_do (const gchar *action, CanDoFunc callback)
+{
+        DBusGConnection *bus;
+        DBusGProxy      *proxy;
+
+        bus = get_system_bus (NULL);
+        if (bus == NULL)
+                return;
+
+	proxy = dbus_g_proxy_new_for_name (bus,
+					   "org.gnome.SettingsDaemon.DateTimeMechanism",
+					   "/",
+					   "org.gnome.SettingsDaemon.DateTimeMechanism");
+
+	dbus_g_proxy_begin_call_with_timeout (proxy,
+					      action,
+					      notify_can_do,
+					      callback, NULL,
+					      INT_MAX,
+					      G_TYPE_INVALID);
+}
+
+static gint   settimezone_cache = 0;
+static time_t settimezone_stamp = 0;
+
+static void
+update_can_settimezone (gint res)
+{
+	settimezone_cache = res;
+	time (&settimezone_stamp);
+}
+
+gint
+can_set_system_timezone (void)
+{
+	time_t          now;
+
+	time (&now);
+	if (ABS (now - settimezone_stamp) > CACHE_VALIDITY_SEC) {
+		refresh_can_do ("CanSetTimezone", update_can_settimezone);
+		settimezone_stamp = now;
+	}
+
+	return settimezone_cache;
+}
+
+static gint   settime_cache = 0;
+static time_t settime_stamp = 0;
+
+static void
+update_can_settime (gint res)
+{
+	settime_cache = res;
+	time (&settime_stamp);
+}
+
+gint
+can_set_system_time (void)
+{
+	time_t now;
+
+	time (&now);
+	if (ABS (now - settime_stamp) > CACHE_VALIDITY_SEC) {
+		refresh_can_do ("CanSetTime", update_can_settime);
+		settime_stamp = now;
+	}
+
+	return settime_cache;
+}
+
+static gint   usingntp_cache = 0;
+static time_t usingntp_stamp = 0;
+
+static void
+update_can_usingntp (gint res)
+{
+	usingntp_cache = res;
+	time (&usingntp_stamp);
+}
+
+gint
+can_set_using_ntp (void)
+{
+	time_t now;
+
+	time (&now);
+	if (ABS (now - usingntp_stamp) > CACHE_VALIDITY_SEC) {
+		refresh_can_do ("CanSetUsingNtp", update_can_usingntp);
+		settime_stamp = now;
+	}
+
+	return usingntp_cache;
+}
+
+typedef struct {
+	gint ref_count;
+        gchar *call;
+	gint64 time;
+	gchar *tz;
+	gboolean using_ntp;
+	GFunc callback;
+	gpointer data;
+	GDestroyNotify notify;
+} SetTimeCallbackData;
+
+static void
+free_data (gpointer d)
+{
+	SetTimeCallbackData *data = d;
+
+	data->ref_count--;
+	if (data->ref_count == 0) {
+		if (data->notify)
+			data->notify (data->data);
+		g_free (data->tz);
+		g_free (data);
+	}
+}
+
+static void
+set_time_notify (DBusGProxy     *proxy,
+		 DBusGProxyCall *call,
+		 void           *user_data)
+{
+	SetTimeCallbackData *data = user_data;
+	GError *error = NULL;
+
+	if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID)) {
+		if (data->callback)
+			data->callback (data->data, NULL);
+	}
+	else {
+		if (error->domain == DBUS_GERROR &&
+		    error->code == DBUS_GERROR_NO_REPLY) {
+			/* these errors happen because dbus doesn't
+			 * use monotonic clocks
+			 */	
+			g_warning ("ignoring no-reply error when setting time");
+			g_error_free (error);
+			if (data->callback)
+				data->callback (data->data, NULL);
+		}
+		else {
+			if (data->callback)
+				data->callback (data->data, error);
+			else
+				g_error_free (error);
+		}		
+	}
+}
+
+static void
+set_time_async (SetTimeCallbackData *data)
+{
+        DBusGConnection *bus;
+        DBusGProxy      *proxy;
+	GError          *err = NULL;
+
+        bus = get_system_bus (&err);
+        if (bus == NULL) {
+		if (err) {
+			if (data->callback)
+				data->callback (data->data, err);
+			g_clear_error (&err);
+		}
+		return;
+	}
+
+	proxy = dbus_g_proxy_new_for_name (bus,
+					   "org.gnome.SettingsDaemon.DateTimeMechanism",
+					   "/",
+					   "org.gnome.SettingsDaemon.DateTimeMechanism");
+
+	data->ref_count++;
+	if (strcmp (data->call, "SetTime") == 0)
+		dbus_g_proxy_begin_call_with_timeout (proxy,
+						      "SetTime",
+						      set_time_notify,
+						      data, free_data,
+						      INT_MAX,
+						      /* parameters: */
+						      G_TYPE_INT64, data->time,
+						      G_TYPE_INVALID,
+						      /* return values: */
+						      G_TYPE_INVALID);
+	else if (strcmp (data->call, "SetTimezone") == 0)
+		dbus_g_proxy_begin_call_with_timeout (proxy,
+						      "SetTimezone",
+						      set_time_notify,
+						      data, free_data,
+						      INT_MAX,
+						      /* parameters: */
+						      G_TYPE_STRING, data->tz,
+						      G_TYPE_INVALID,
+						      /* return values: */
+						      G_TYPE_INVALID);
+	else if (strcmp (data->call, "SetUsingNtp") == 0)
+		dbus_g_proxy_begin_call_with_timeout (proxy,
+						      "SetUsingNtp",
+						      set_time_notify,
+						      data, free_data,
+						      INT_MAX,
+						      /* parameters: */
+						      G_TYPE_BOOLEAN, data->using_ntp,
+						      G_TYPE_INVALID,
+						      /* return values: */
+						      G_TYPE_INVALID);
+}
+
+void
+set_system_time_async (gint64         time,
+		       GFunc          callback,
+		       gpointer       d,
+		       GDestroyNotify notify)
+{
+	SetTimeCallbackData *data;
+
+	if (time == -1)
+		return;
+
+	data = g_new0 (SetTimeCallbackData, 1);
+	data->ref_count = 1;
+	data->call = "SetTime";
+	data->time = time;
+	data->tz = NULL;
+	data->callback = callback;
+	data->data = d;
+	data->notify = notify;
+
+	set_time_async (data);
+	free_data (data);
+}
+
+void
+set_system_timezone_async (const gchar    *tz,
+			   GFunc           callback,
+			   gpointer        d,
+			   GDestroyNotify  notify)
+{
+	SetTimeCallbackData *data;
+
+	g_return_if_fail (tz != NULL);
+
+	data = g_new0 (SetTimeCallbackData, 1);
+	data->ref_count = 1;
+	data->call = "SetTimezone";
+	data->time = -1;
+	data->tz = g_strdup (tz);
+	data->callback = callback;
+	data->data = d;
+	data->notify = notify;
+
+	set_time_async (data);
+	free_data (data);
+}
+
+/* get timezone */
+
+typedef struct
+{
+  GetTimezoneFunc callback;
+  GDestroyNotify notify;
+
+  gpointer data;
+
+} GetTimezoneData;
+
+static void
+get_timezone_destroy_notify (GetTimezoneData *data)
+{
+	if (data->notify && data->data)
+		data->notify (data);
+
+	g_free (data);
+}
+
+static void
+get_timezone_notify (DBusGProxy     *proxy,
+		     DBusGProxyCall *call,
+		     void           *user_data)
+{
+	GError *error = NULL;
+	gboolean retval;
+	gchar *string = NULL;
+	GetTimezoneData *data = user_data;
+
+	retval = dbus_g_proxy_end_call (proxy, call, &error,
+					G_TYPE_STRING, &string,
+					G_TYPE_INVALID);
+
+	if (data->callback) {
+		if (!retval) {
+			data->callback (data->data, NULL, error);
+			g_error_free (error);
+		}
+		else {
+			data->callback (data->data, string, NULL);
+			g_free (string);
+		}
+	}
+}
+
+void
+get_system_timezone_async (GetTimezoneFunc callback,
+			   gpointer        user_data,
+			   GDestroyNotify  notify)
+{
+	DBusGConnection *bus;
+	DBusGProxy      *proxy;
+	GetTimezoneData *data;
+	GError          *error = NULL;
+
+	bus = get_system_bus (&error);
+	if (bus == NULL) {
+		if (error) {
+			if (callback)
+				callback (user_data, NULL, error);
+			g_clear_error (&error);
+		}
+		return;
+
+        }
+
+	data = g_new0 (GetTimezoneData, 1);
+	data->data = user_data;
+	data->notify = notify;
+	data->callback = callback;
+
+	proxy = dbus_g_proxy_new_for_name (bus,
+					   "org.gnome.SettingsDaemon.DateTimeMechanism",
+					   "/",
+					   "org.gnome.SettingsDaemon.DateTimeMechanism");
+
+	dbus_g_proxy_begin_call (proxy,
+				 "GetTimezone",
+				 get_timezone_notify,
+				 data,
+				 (GDestroyNotify) get_timezone_destroy_notify,
+				 /* parameters: */
+				 G_TYPE_INVALID,
+				 /* return values: */
+				 G_TYPE_STRING,
+				 G_TYPE_INVALID);
+
+}
+
+gboolean
+get_using_ntp (void)
+{
+	static gboolean is_using_cache = FALSE;
+	static time_t   last_refreshed = 0;
+	time_t          now;
+        DBusGConnection *bus;
+        DBusGProxy      *proxy;
+
+	time (&now);
+	if (ABS (now - last_refreshed) > CACHE_VALIDITY_SEC) {
+		gboolean cu, iu;
+		bus = get_system_bus (NULL);
+		if (bus == NULL)
+			return FALSE;
+
+		proxy = dbus_g_proxy_new_for_name (bus,
+						   "org.gnome.SettingsDaemon.DateTimeMechanism",
+						   "/",
+						   "org.gnome.SettingsDaemon.DateTimeMechanism");
+
+
+		if (dbus_g_proxy_call (proxy,
+				       "GetUsingNtp",
+				       NULL,
+				       G_TYPE_INVALID,
+				       G_TYPE_BOOLEAN, &cu,
+				       G_TYPE_BOOLEAN, &iu,
+				       G_TYPE_INVALID)) {
+			is_using_cache = iu;
+			last_refreshed = now;
+		}
+	}
+
+	return is_using_cache;
+}
+
+void
+set_using_ntp_async (gboolean        using_ntp,
+	             GFunc           callback,
+	             gpointer        d,
+	             GDestroyNotify  notify)
+{
+	SetTimeCallbackData *data;
+
+	data = g_new0 (SetTimeCallbackData, 1);
+	data->ref_count = 1;
+	data->call = "SetUsingNtp";
+	data->time = -1;
+	data->using_ntp = using_ntp;
+	data->callback = callback;
+	data->data = d;
+	data->notify = notify;
+
+	set_time_async (data);
+	free_data (data);
+}
diff --git a/setup/set-timezone.h b/setup/set-timezone.h
new file mode 100644
index 0000000..5e657e3
--- /dev/null
+++ b/setup/set-timezone.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 David Zeuthen <david fubar dk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __SET_SYSTEM_TIMEZONE_H__
+
+#include <config.h>
+
+#include <glib.h>
+#include <time.h>
+
+typedef void (*GetTimezoneFunc) (gpointer     data,
+                                 const gchar *timezone,
+                                 GError      *error);
+void     get_system_timezone_async   (GetTimezoneFunc callback,
+                                      gpointer        data,
+                                      GDestroyNotify  notify);
+
+gint     can_set_system_timezone (void);
+
+gint     can_set_system_time     (void);
+
+gint     can_set_using_ntp       (void);
+
+void     set_system_time_async   (gint64         time,
+                                  GFunc          callback,
+                                  gpointer       data,
+                                  GDestroyNotify notify);
+
+void     set_system_timezone_async   (const gchar    *tz,
+                                      GFunc           callback,
+                                      gpointer        data,
+                                      GDestroyNotify  notify);
+
+gboolean get_using_ntp               (void);
+
+void     set_using_ntp_async         (gboolean        using_ntp,
+                                      GFunc           callback,
+                                      gpointer        data,
+                                      GDestroyNotify  notify);
+#endif
diff --git a/setup/setup.ui b/setup/setup.ui
index 0fb95f8..0fc6f0e 100644
--- a/setup/setup.ui
+++ b/setup/setup.ui
@@ -23,11 +23,8 @@
     <property name="deletable">False</property>
     <property name="resizable">False</property>
     <child>
-      <object class="GtkBox" id="welcome-page">
+      <object class="GtkGrid" id="welcome-page">
         <property name="visible">True</property>
-        <property name="border_width">12</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">12</property>
         <child>
           <object class="GtkLabel" id="welcome-title">
             <property name="visible">True</property>
@@ -40,6 +37,10 @@
               <attribute name="scale" value="1.2"/>
             </attributes>
           </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+          </packing>
         </child>
         <child>
           <object class="GtkImage" id="welcome-image">
@@ -48,6 +49,10 @@
             <property name="valign">start</property>
             <property name="file">welcome-image.jpg</property>
           </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+          </packing>
         </child>
         <child>
           <object class="GtkLabel" id="welcome-subtitle">
@@ -55,13 +60,16 @@
             <property name="label" translatable="yes">Now let's set up some essentials for your account.</property>
             <property name="halign">start</property>
             <property name="xalign">0.0</property>
-            <property name="wrap">True</property>
-            <property name="margin-top">12</property>
+            <property name="margin-top">18</property>
             <property name="margin-bottom">18</property>
             <attributes>
               <attribute name="weight" value="bold"/>
             </attributes>
           </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">2</property>
+          </packing>
         </child>
       </object>
       <packing>
@@ -72,8 +80,6 @@
     <child>
       <object class="GtkGrid" id="network-page">
         <property name="visible">True</property>
-        <property name="border-width">12</property>
-        <property name="orientation">vertical</property>
         <child>
           <object class="GtkLabel" id="network-title">
             <property name="visible">True</property>
@@ -89,7 +95,7 @@
           <packing>
             <property name="left_attach">0</property>
             <property name="top_attach">0</property>
-            <property name="width">2</property>
+            <property name="width">1</property>
             <property name="height">1</property>
           </packing>
         </child>
@@ -99,8 +105,7 @@
             <property name="label" translatable="yes">Select a wireless network</property>
             <property name="margin-bottom">12</property>
             <property name="halign">start</property>
-            <property name="xalign">0.0</property>
-            <property name="wrap">True</property>
+            <property name="valign">start</property>
             <attributes>
               <attribute name="weight" value="bold"/>
             </attributes>
@@ -108,7 +113,7 @@
           <packing>
             <property name="left_attach">0</property>
             <property name="top_attach">1</property>
-            <property name="width">2</property>
+            <property name="width">1</property>
             <property name="height">1</property>
           </packing>
         </child>
@@ -117,6 +122,9 @@
             <property name="visible">True</property>
             <property name="halign">fill</property>
             <property name="valign">fill</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="margin-top">0</property>
             <property name="margin-bottom">32</property>
             <property name="margin-right">64</property>
             <property name="hscrollbar-policy">never</property>
@@ -128,6 +136,8 @@
                 <property name="can-focus">True</property>
                 <property name="hexpand">True</property>
                 <property name="vexpand">True</property>
+                <property name="halign">fill</property>
+                <property name="valign">fill</property>
                 <property name="model">liststore-wireless</property>
                 <property name="headers-visible">False</property>
                 <property name="search-column">2</property>
@@ -146,15 +156,45 @@
           <packing>
             <property name="left_attach">0</property>
             <property name="top_attach">2</property>
-            <property name="width">2</property>
+            <property name="width">1</property>
             <property name="height">1</property>
           </packing>
         </child>
         <child>
-          <object class="GtkSpinner" id="no-network-spinner">
+          <object class="GtkGrid" id="no-network-grid">
             <property name="visible">True</property>
-            <property name="active">True</property>
-            <property name="margin-left">6</property>
+            <property name="halign">start</property>
+            <property name="valign">start</property>
+            <child>
+              <object class="GtkSpinner" id="no-network-spinner">
+                <property name="visible">True</property>
+                <property name="active">True</property>
+                <property name="halign">start</property>
+                <property name="valign">center</property>
+                <property name="margin-left">6</property>
+                <property name="margin-right">6</property>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="no-network-label">
+                <property name="visible">True</property>
+                <property name="label">No text</property>
+                <property name="halign">start</property>
+                <property name="valign">center</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="left_attach">0</property>
@@ -163,35 +203,200 @@
             <property name="height">1</property>
           </packing>
         </child>
+      </object>
+      <packing>
+        <property name="title" translatable="yes">Network</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkGrid" id="account-page">
+        <property name="visible">True</property>
+        <property name="row-spacing">6</property>
+        <property name="column-spacing">12</property>
         <child>
-          <object class="GtkLabel" id="no-network-label">
+          <object class="GtkLabel" id="account-title">
             <property name="visible">True</property>
-            <property name="label">No text</property>
-            <property name="wrap">True</property>
-            <property name="margin-left">6</property>
+            <property name="label" translatable="yes">Create an Account</property>
+            <property name="halign">start</property>
+            <property name="valign">start</property>
+            <property name="margin-bottom">12</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+              <attribute name="scale" value="1.2"/>
+            </attributes>
           </object>
           <packing>
-            <property name="left_attach">1</property>
-            <property name="top_attach">3</property>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">2</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="account-fullname-label">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">_Fullname</property>
+            <property name="use_underline">True</property>
+            <property name="mnemonic_widget">account-fullname-entry</property>
+            <property name="halign">end</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkEntry" id="account-fullname-entry">
+            <property name="visible">True</property>
+            <property name="halign">start</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkLabel" id="account-username-label">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">_Username</property>
+            <property name="use_underline">True</property>
+            <property name="mnemonic_widget">account-username-entry</property>
+            <property name="halign">end</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">2</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkEntry" id="account-username-entry">
+            <property name="visible">True</property>
+            <property name="halign">start</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">2</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkCheckButton" id="account-password-check">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">_Require a password to use this account</property>
+            <property name="use_underline">True</property>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">3</property>
+            <property name="width">2</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkLabel" id="account-password-label">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">_Password</property>
+            <property name="use_underline">True</property>
+            <property name="mnemonic_widget">account-password-entry</property>
+            <property name="halign">end</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">4</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkEntry" id="account-password-entry">
+            <property name="visible">True</property>
+            <property name="halign">start</property>
+            <property name="visibility">False</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">4</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkLabel" id="account-confirm-label">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">_Confirm Password</property>
+            <property name="use_underline">True</property>
+            <property name="mnemonic_widget">account-confirm-entry</property>
+            <property name="halign">end</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">5</property>
             <property name="width">1</property>
             <property name="height">1</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkEntry" id="account-confirm-entry">
+            <property name="visible">True</property>
+            <property name="halign">start</property>
+            <property name="visibility">False</property>
+          </object>
+          <packing>
+            <property name="left-attach">1</property>
+            <property name="top-attach">5</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+
+        <child>
+          <object class="GtkCheckButton" id="account-admin-check">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">_Act as administrator of this computer</property>
+            <property name="use_underline">True</property>
+          </object>
+          <packing>
+            <property name="left-attach">0</property>
+            <property name="top-attach">6</property>
+            <property name="width">2</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
       </object>
       <packing>
-        <property name="title" translatable="yes">Network</property>
+        <property name="title" translatable="yes">Account</property>
       </packing>
     </child>
     <child>
-      <object class="GtkBox" id="account-page">
+      <object class="GtkGrid" id="location-page">
         <property name="visible">True</property>
-        <property name="border_width">12</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">12</property>
         <child>
-          <object class="GtkLabel" id="account-title">
+          <object class="GtkLabel" id="location-title">
             <property name="visible">True</property>
-            <property name="label" translatable="yes">Create an Account</property>
+            <property name="label" translatable="yes">Select your Location</property>
             <property name="halign">start</property>
             <property name="valign">start</property>
             <property name="margin-bottom">18</property>
@@ -200,181 +405,107 @@
               <attribute name="scale" value="1.2"/>
             </attributes>
           </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">2</property>
+            <property name="height">1</property>
+          </packing>
         </child>
         <child>
-          <object class="GtkGrid" id="account-grid">
+          <object class="GtkCheckButton" id="location-auto-check">
             <property name="visible">True</property>
-            <property name="row-spacing">6</property>
-            <property name="column-spacing">12</property>
-            <child>
-              <object class="GtkLabel" id="account-fullname-label">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Fullname</property>
-                <property name="halign">end</property>
-                <style>
-                  <class name="dim-label"/>
-                </style>
-              </object>
-              <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkEntry" id="account-fullname-entry">
-                <property name="visible">True</property>
-                <property name="halign">start</property>
-              </object>
-              <packing>
-                <property name="left-attach">1</property>
-                <property name="top-attach">0</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-
-            <child>
-              <object class="GtkLabel" id="account-username-label">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Username</property>
-                <property name="halign">end</property>
-                <style>
-                  <class name="dim-label"/>
-                </style>
-              </object>
-              <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">1</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkEntry" id="account-username-entry">
-                <property name="visible">True</property>
-                <property name="halign">start</property>
-              </object>
-              <packing>
-                <property name="left-attach">1</property>
-                <property name="top-attach">1</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-
-            <child>
-              <object class="GtkCheckButton" id="account-password-check">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Require a password to use this account</property>
-              </object>
-              <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">2</property>
-                <property name="width">2</property>
-                <property name="height">1</property>
-              </packing>
-
-            </child>
-
+            <property name="label" translatable="yes">_Determine your location automatically</property>
+            <property name="use_underline">True</property>
+            <property name="halign">start</property>
+            <property name="margin-right">24</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkAspectFrame" id="location-map-frame">
+            <property name="visible">True</property>
+            <property name="halign">fill</property>
+            <property name="valign">fill</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="margin-top">12</property>
+            <property name="margin-bottom">12</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">2</property>
+            <property name="width">2</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkGrid" id="location-info-grid">
+            <property name="visible">True</property>
+            <property name="halign">start</property>
+            <property name="valign">start</property>
+            <property name="row-spacing">12</property>
+            <property name="column-spacing">6</property>
             <child>
-              <object class="GtkLabel" id="account-password-label">
+              <object class="GtkLabel" id="location-label">
                 <property name="visible">True</property>
-                <property name="label" translatable="yes">Password</property>
+                <property name="label" translatable="yes">Location</property>
                 <property name="halign">end</property>
                 <style>
                   <class name="dim-label"/>
                 </style>
               </object>
               <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">3</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
               </packing>
             </child>
             <child>
-              <object class="GtkEntry" id="account-password-entry">
+              <object class="GtkLabel" id="current-location-label">
                 <property name="visible">True</property>
+                <property name="label">Boston, MA</property>
                 <property name="halign">start</property>
-                <property name="visibility">False</property>
               </object>
               <packing>
-                <property name="left-attach">1</property>
-                <property name="top-attach">3</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
+                <property name="left_attach">1</property>
+                <property name="top_attach">0</property>
               </packing>
             </child>
-
             <child>
-              <object class="GtkLabel" id="account-confirm-password-label">
+              <object class="GtkLabel" id="timezone-label">
                 <property name="visible">True</property>
-                <property name="label" translatable="yes">Confirm Password</property>
+                <property name="label" translatable="yes">Timezone</property>
                 <property name="halign">end</property>
                 <style>
                   <class name="dim-label"/>
                 </style>
               </object>
               <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">4</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
+                <property name="left_attach">0</property>
+                <property name="top_attach">1</property>
               </packing>
             </child>
             <child>
-              <object class="GtkEntry" id="account-confirm-entry">
+              <object class="GtkLabel" id="current-timezone-label">
                 <property name="visible">True</property>
+                <property name="label">America / New York</property>
                 <property name="halign">start</property>
-                <property name="visibility">False</property>
               </object>
               <packing>
-                <property name="left-attach">1</property>
-                <property name="top-attach">4</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
+                <property name="left_attach">1</property>
+                <property name="top_attach">1</property>
               </packing>
             </child>
-
-            <child>
-              <object class="GtkCheckButton" id="account-admin-check">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Act as administrator of this computer</property>
-              </object>
-              <packing>
-                <property name="left-attach">0</property>
-                <property name="top-attach">5</property>
-                <property name="width">2</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-          </object>
-        </child>
-      </object>
-      <packing>
-        <property name="title" translatable="yes">Account</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkBox" id="location-page">
-        <property name="visible">True</property>
-        <property name="border_width">12</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">12</property>
-        <child>
-          <object class="GtkLabel" id="location-title">
-            <property name="visible">True</property>
-            <property name="label" translatable="yes">Select your Location</property>
-            <property name="halign">start</property>
-            <property name="valign">start</property>
-            <property name="margin-bottom">18</property>
-            <attributes>
-              <attribute name="weight" value="bold"/>
-              <attribute name="scale" value="1.2"/>
-            </attributes>
           </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">3</property>
+          </packing>
         </child>
       </object>
       <packing>
@@ -382,11 +513,8 @@
       </packing>
     </child>
     <child>
-      <object class="GtkBox" id="online-page">
+      <object class="GtkGrid" id="online-page">
         <property name="visible">True</property>
-        <property name="border_width">12</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">12</property>
         <child>
           <object class="GtkLabel" id="online-title">
             <property name="visible">True</property>
@@ -399,18 +527,32 @@
               <attribute name="scale" value="1.2"/>
             </attributes>
           </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
         </child>
         <child>
           <object class="GtkLabel" id="online-subtitle">
             <property name="visible">True</property>
             <property name="label" translatable="yes">Associate your new account with your existing online accounts</property>
             <property name="halign">start</property>
+            <property name="valign">start</property>
+            <property name="margin-bottom">18</property>
             <property name="xalign">0.0</property>
             <property name="wrap">True</property>
             <attributes>
               <attribute name="weight" value="bold"/>
             </attributes>
           </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
         </child>
       </object>
       <packing>
@@ -418,11 +560,8 @@
       </packing>
     </child>
     <child>
-      <object class="GtkBox" id="page6">
+      <object class="GtkGrid" id="page6">
         <property name="visible">True</property>
-        <property name="border_width">12</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">12</property>
         <child>
           <object class="GtkLabel" id="summary-title">
             <property name="visible">True</property>
@@ -435,6 +574,12 @@
               <attribute name="scale" value="1.2"/>
             </attributes>
           </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
         </child>
         <child>
           <object class="GtkLabel" id="summary-details">
@@ -443,10 +588,17 @@
             <property name="label" translatable="yes">Your new account is ready to use. You may change any of these options at any time in the System Settings.</property>
             <property name="wrap">True</property>
             <property name="halign">start</property>
+            <property name="valign">start</property>
             <attributes>
               <attribute name="weight" value="bold"/>
             </attributes>
           </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
         </child>
       </object>
       <packing>
diff --git a/setup/tz.c b/setup/tz.c
new file mode 100644
index 0000000..776418b
--- /dev/null
+++ b/setup/tz.c
@@ -0,0 +1,475 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* Generic timezone utilities.
+ *
+ * Copyright (C) 2000-2001 Ximian, Inc.
+ *
+ * Authors: Hans Petter Jansson <hpj ximian com>
+ * 
+ * Largely based on Michael Fulbright's work on Anaconda.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <math.h>
+#include <string.h>
+#include "tz.h"
+
+
+/* Forward declarations for private functions */
+
+static float convert_pos (gchar *pos, int digits);
+static int compare_country_names (const void *a, const void *b);
+static void sort_locations_by_country (GPtrArray *locations);
+static gchar * tz_data_file_get (void);
+static void load_backward_tz (TzDB *tz_db);
+
+/* ---------------- *
+ * Public interface *
+ * ---------------- */
+TzDB *
+tz_load_db (void)
+{
+	gchar *tz_data_file;
+	TzDB *tz_db;
+	FILE *tzfile;
+	char buf[4096];
+
+	tz_data_file = tz_data_file_get ();
+	if (!tz_data_file) {
+		g_warning ("Could not get the TimeZone data file name");
+		return NULL;
+	}
+	tzfile = fopen (tz_data_file, "r");
+	if (!tzfile) {
+		g_warning ("Could not open *%s*\n", tz_data_file);
+		g_free (tz_data_file);
+		return NULL;
+	}
+
+	tz_db = g_new0 (TzDB, 1);
+	tz_db->locations = g_ptr_array_new ();
+
+	while (fgets (buf, sizeof(buf), tzfile))
+	{
+		gchar **tmpstrarr;
+		gchar *latstr, *lngstr, *p;
+		TzLocation *loc;
+
+		if (*buf == '#') continue;
+
+		g_strchomp(buf);
+		tmpstrarr = g_strsplit(buf,"\t", 6);
+		
+		latstr = g_strdup (tmpstrarr[1]);
+		p = latstr + 1;
+		while (*p != '-' && *p != '+') p++;
+		lngstr = g_strdup (p);
+		*p = '\0';
+		
+		loc = g_new0 (TzLocation, 1);
+		loc->country = g_strdup (tmpstrarr[0]);
+		loc->zone = g_strdup (tmpstrarr[2]);
+		loc->latitude  = convert_pos (latstr, 2);
+		loc->longitude = convert_pos (lngstr, 3);
+		
+#ifdef __sun
+		if (tmpstrarr[3] && *tmpstrarr[3] == '-' && tmpstrarr[4])
+			loc->comment = g_strdup (tmpstrarr[4]);
+
+		if (tmpstrarr[3] && *tmpstrarr[3] != '-' && !islower(loc->zone)) {
+			TzLocation *locgrp;
+
+			/* duplicate entry */
+			locgrp = g_new0 (TzLocation, 1);
+			locgrp->country = g_strdup (tmpstrarr[0]);
+			locgrp->zone = g_strdup (tmpstrarr[3]);
+			locgrp->latitude  = convert_pos (latstr, 2);
+			locgrp->longitude = convert_pos (lngstr, 3);
+			locgrp->comment = (tmpstrarr[4]) ? g_strdup (tmpstrarr[4]) : NULL;
+
+			g_ptr_array_add (tz_db->locations, (gpointer) locgrp);
+		}
+#else
+		loc->comment = (tmpstrarr[3]) ? g_strdup(tmpstrarr[3]) : NULL;
+#endif
+
+		g_ptr_array_add (tz_db->locations, (gpointer) loc);
+
+		g_free (latstr);
+		g_free (lngstr);
+		g_strfreev (tmpstrarr);
+	}
+	
+	fclose (tzfile);
+	
+	/* now sort by country */
+	sort_locations_by_country (tz_db->locations);
+	
+	g_free (tz_data_file);
+
+	/* Load up the hashtable of backward links */
+	load_backward_tz (tz_db);
+
+	return tz_db;
+}
+
+static void
+tz_location_free (TzLocation *loc)
+{
+	g_free (loc->country);
+	g_free (loc->zone);
+	g_free (loc->comment);
+
+	g_free (loc);
+}
+
+void
+tz_db_free (TzDB *db)
+{
+	g_ptr_array_foreach (db->locations, (GFunc) tz_location_free, NULL);
+	g_ptr_array_free (db->locations, TRUE);
+	g_hash_table_destroy (db->backward);
+	g_free (db);
+}
+
+GPtrArray *
+tz_get_locations (TzDB *db)
+{
+	return db->locations;
+}
+
+
+gchar *
+tz_location_get_country (TzLocation *loc)
+{
+	return loc->country;
+}
+
+
+gchar *
+tz_location_get_zone (TzLocation *loc)
+{
+	return loc->zone;
+}
+
+
+gchar *
+tz_location_get_comment (TzLocation *loc)
+{
+	return loc->comment;
+}
+
+
+void
+tz_location_get_position (TzLocation *loc, double *longitude, double *latitude)
+{
+	*longitude = loc->longitude;
+	*latitude = loc->latitude;
+}
+
+glong
+tz_location_get_utc_offset (TzLocation *loc)
+{
+	TzInfo *tz_info;
+	glong offset;
+
+	tz_info = tz_info_from_location (loc);
+	offset = tz_info->utc_offset;
+	tz_info_free (tz_info);
+	return offset;
+}
+
+TzInfo *
+tz_info_from_location (TzLocation *loc)
+{
+	TzInfo *tzinfo;
+	time_t curtime;
+	struct tm *curzone;
+	
+	g_return_val_if_fail (loc != NULL, NULL);
+	g_return_val_if_fail (loc->zone != NULL, NULL);
+	
+	setenv ("TZ", loc->zone, 1);
+	
+#if 0
+	tzset ();
+#endif
+	tzinfo = g_new0 (TzInfo, 1);
+
+	curtime = time (NULL);
+	curzone = localtime (&curtime);
+
+#ifndef __sun
+	/* Currently this solution doesnt seem to work - I get that */
+	/* America/Phoenix uses daylight savings, which is wrong    */
+	tzinfo->tzname_normal = g_strdup (curzone->tm_zone);
+	if (curzone->tm_isdst) 
+		tzinfo->tzname_daylight =
+			g_strdup (&curzone->tm_zone[curzone->tm_isdst]);
+	else
+		tzinfo->tzname_daylight = NULL;
+
+	tzinfo->utc_offset = curzone->tm_gmtoff;
+#else
+	tzinfo->tzname_normal = NULL;
+	tzinfo->tzname_daylight = NULL;
+	tzinfo->utc_offset = 0;
+#endif
+
+	tzinfo->daylight = curzone->tm_isdst;
+
+	setenv ("TZ", "", 1);
+	
+	return tzinfo;
+}
+
+
+void
+tz_info_free (TzInfo *tzinfo)
+{
+	g_return_if_fail (tzinfo != NULL);
+	
+	if (tzinfo->tzname_normal) g_free (tzinfo->tzname_normal);
+	if (tzinfo->tzname_daylight) g_free (tzinfo->tzname_daylight);
+	g_free (tzinfo);
+}
+
+struct {
+	const char *orig;
+	const char *dest;
+} aliases[] = {
+	{ "Asia/Istanbul",  "Europe/Istanbul" },	/* Istanbul is in both Europe and Asia */
+	{ "Europe/Nicosia", "Asia/Nicosia" },		/* Ditto */
+	{ "EET",            "Europe/Istanbul" },	/* Same tz as the 2 above */
+	{ "HST",            "Pacific/Honolulu" },
+	{ "WET",            "Europe/Brussels" },	/* Other name for the mainland Europe tz */
+	{ "CET",            "Europe/Brussels" },	/* ditto */
+	{ "MET",            "Europe/Brussels" },
+	{ "Etc/Zulu",       "Etc/GMT" },
+	{ "Etc/UTC",        "Etc/GMT" },
+	{ "GMT",            "Etc/GMT" },
+	{ "Greenwich",      "Etc/GMT" },
+	{ "Etc/UCT",        "Etc/GMT" },
+	{ "Etc/GMT0",       "Etc/GMT" },
+	{ "Etc/GMT+0",      "Etc/GMT" },
+	{ "Etc/GMT-0",      "Etc/GMT" },
+	{ "Etc/Universal",  "Etc/GMT" },
+	{ "PST8PDT",        "America/Los_Angeles" },	/* Other name for the Atlantic tz */
+	{ "EST",            "America/New_York" },	/* Other name for the Eastern tz */
+	{ "EST5EDT",        "America/New_York" },	/* ditto */
+	{ "CST6CDT",        "America/Chicago" },	/* Other name for the Central tz */
+	{ "MST",            "America/Denver" },		/* Other name for the mountain tz */
+	{ "MST7MDT",        "America/Denver" },		/* ditto */
+};
+
+static gboolean
+compare_timezones (const char *a,
+		   const char *b)
+{
+	if (g_str_equal (a, b))
+		return TRUE;
+	if (strchr (b, '/') == NULL) {
+		char *prefixed;
+
+		prefixed = g_strdup_printf ("/%s", b);
+		if (g_str_has_suffix (a, prefixed)) {
+			g_free (prefixed);
+			return TRUE;
+		}
+		g_free (prefixed);
+	}
+
+	return FALSE;
+}
+
+char *
+tz_info_get_clean_name (TzDB *tz_db,
+			const char *tz)
+{
+	char *ret;
+	const char *timezone;
+	guint i;
+	gboolean replaced;
+
+	/* Remove useless prefixes */
+	if (g_str_has_prefix (tz, "right/"))
+		tz = tz + strlen ("right/");
+	else if (g_str_has_prefix (tz, "posix/"))
+		tz = tz + strlen ("posix/");
+
+	/* Here start the crazies */
+	replaced = FALSE;
+
+	for (i = 0; i < G_N_ELEMENTS (aliases); i++) {
+		if (compare_timezones (tz, aliases[i].orig)) {
+			replaced = TRUE;
+			timezone = aliases[i].dest;
+			break;
+		}
+	}
+
+	/* Try again! */
+	if (!replaced) {
+		/* Ignore crazy solar times from the '80s */
+		if (g_str_has_prefix (tz, "Asia/Riyadh") ||
+		    g_str_has_prefix (tz, "Mideast/Riyadh")) {
+			timezone = "Asia/Riyadh";
+			replaced = TRUE;
+		}
+	}
+
+	if (!replaced)
+		timezone = tz;
+
+	ret = g_hash_table_lookup (tz_db->backward, timezone);
+	if (ret == NULL)
+		return g_strdup (timezone);
+	return g_strdup (ret);
+}
+
+/* ----------------- *
+ * Private functions *
+ * ----------------- */
+
+static gchar *
+tz_data_file_get (void)
+{
+	gchar *file;
+
+	file = g_strdup (TZ_DATA_FILE);
+
+	return file;
+}
+
+static float
+convert_pos (gchar *pos, int digits)
+{
+	gchar whole[10];
+	gchar *fraction;
+	gint i;
+	float t1, t2;
+	
+	if (!pos || strlen(pos) < 4 || digits > 9) return 0.0;
+	
+	for (i = 0; i < digits + 1; i++) whole[i] = pos[i];
+	whole[i] = '\0';
+	fraction = pos + digits + 1;
+
+	t1 = g_strtod (whole, NULL);
+	t2 = g_strtod (fraction, NULL);
+
+	if (t1 >= 0.0) return t1 + t2/pow (10.0, strlen(fraction));
+	else return t1 - t2/pow (10.0, strlen(fraction));
+}
+
+
+#if 0
+
+/* Currently not working */
+static void
+free_tzdata (TzLocation *tz)
+{
+	
+	if (tz->country)
+	  g_free(tz->country);
+	if (tz->zone)
+	  g_free(tz->zone);
+	if (tz->comment)
+	  g_free(tz->comment);
+	
+	g_free(tz);
+}
+#endif
+
+
+static int
+compare_country_names (const void *a, const void *b)
+{
+	const TzLocation *tza = * (TzLocation **) a;
+	const TzLocation *tzb = * (TzLocation **) b;
+	
+	return strcmp (tza->zone, tzb->zone);
+}
+
+
+static void
+sort_locations_by_country (GPtrArray *locations)
+{
+	qsort (locations->pdata, locations->len, sizeof (gpointer),
+	       compare_country_names);
+}
+
+static void
+load_backward_tz (TzDB *tz_db)
+{
+  GError *error = NULL;
+  char **lines, *contents;
+  guint i;
+
+  tz_db->backward = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+  if (g_file_get_contents (GNOMECC_DATA_DIR "/datetime/backward", &contents, NULL, &error) == FALSE)
+    {
+      g_warning ("Failed to load 'backward' file: %s", error->message);
+      return;
+    }
+  lines = g_strsplit (contents, "\n", -1);
+  g_free (contents);
+  for (i = 0; lines[i] != NULL; i++)
+    {
+      char **items;
+      guint j;
+      char *real, *alias;
+
+      if (g_ascii_strncasecmp (lines[i], "Link\t", 5) != 0)
+        continue;
+
+      items = g_strsplit (lines[i], "\t", -1);
+      real = NULL;
+      alias = NULL;
+      /* Skip the "Link<tab>" part */
+      for (j = 1; items[j] != NULL; j++)
+        {
+          if (items[j][0] == '\0')
+            continue;
+          if (real == NULL)
+            {
+              real = items[j];
+              continue;
+            }
+          alias = items[j];
+          break;
+        }
+
+      if (real == NULL || alias == NULL)
+        g_warning ("Could not parse line: %s", lines[i]);
+
+      /* We don't need more than one name for it */
+      if (g_str_equal (real, "Etc/UTC") ||
+          g_str_equal (real, "Etc/UCT"))
+        real = "Etc/GMT";
+
+      g_hash_table_insert (tz_db->backward, g_strdup (alias), g_strdup (real));
+      g_strfreev (items);
+    }
+  g_strfreev (lines);
+}
+
diff --git a/setup/tz.h b/setup/tz.h
new file mode 100644
index 0000000..71c1c23
--- /dev/null
+++ b/setup/tz.h
@@ -0,0 +1,89 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* Generic timezone utilities.
+ *
+ * Copyright (C) 2000-2001 Ximian, Inc.
+ *
+ * Authors: Hans Petter Jansson <hpj ximian com>
+ * 
+ * Largely based on Michael Fulbright's work on Anaconda.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+
+#ifndef _E_TZ_H
+#define _E_TZ_H
+
+#include <glib.h>
+
+#ifndef __sun
+#  define TZ_DATA_FILE "/usr/share/zoneinfo/zone.tab"
+#else
+#  define TZ_DATA_FILE "/usr/share/lib/zoneinfo/tab/zone_sun.tab"
+#endif
+
+typedef struct _TzDB TzDB;
+typedef struct _TzLocation TzLocation;
+typedef struct _TzInfo TzInfo;
+
+
+struct _TzDB
+{
+	GPtrArray  *locations;
+	GHashTable *backward;
+};
+
+struct _TzLocation
+{
+	gchar *country;
+	gdouble latitude;
+	gdouble longitude;
+	gchar *zone;
+	gchar *comment;
+
+	gdouble dist; /* distance to clicked point for comparison */
+};
+
+/* see the glibc info page information on time zone information */
+/*  tzname_normal    is the default name for the timezone */
+/*  tzname_daylight  is the name of the zone when in daylight savings */
+/*  utc_offset       is offset in seconds from utc */
+/*  daylight         if non-zero then location obeys daylight savings */
+
+struct _TzInfo
+{
+	gchar *tzname_normal;
+	gchar *tzname_daylight;
+	glong utc_offset;
+	gint daylight;
+};
+
+
+TzDB      *tz_load_db                 (void);
+void       tz_db_free                 (TzDB *db);
+char *     tz_info_get_clean_name     (TzDB *tz_db,
+				       const char *tz);
+GPtrArray *tz_get_locations           (TzDB *db);
+void       tz_location_get_position   (TzLocation *loc,
+				       double *longitude, double *latitude);
+char      *tz_location_get_country    (TzLocation *loc);
+gchar     *tz_location_get_zone       (TzLocation *loc);
+gchar     *tz_location_get_comment    (TzLocation *loc);
+glong      tz_location_get_utc_offset (TzLocation *loc);
+gint       tz_location_set_locally    (TzLocation *loc);
+TzInfo    *tz_info_from_location      (TzLocation *loc);
+void       tz_info_free               (TzInfo *tz_info);
+
+#endif



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