[gnome-initial-setup] Sync the timezone map widget with the control-center
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup] Sync the timezone map widget with the control-center
- Date: Fri, 12 Feb 2016 00:48:00 +0000 (UTC)
commit 141f75200d309611e00bf20870b107037f07be34
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Feb 11 19:44:37 2016 -0500
Sync the timezone map widget with the control-center
The main motivation for this change is that we want to
show an indication of the selected timezone, and the
control-center version of the map has a built-in bubble
for this purpose.
At the same time, allow selecting the timezone with
the mouse.
https://bugzilla.gnome.org/show_bug.cgi?id=761854
gnome-initial-setup/pages/timezone/Makefile.am | 1 +
.../pages/timezone/cc-timezone-map.c | 542 +++++++++++++++++---
.../pages/timezone/cc-timezone-map.h | 11 +-
gnome-initial-setup/pages/timezone/data/cc.png | Bin 0 -> 52271 bytes
.../pages/timezone/data/timezone_8.5.png | Bin 0 -> 2069 bytes
.../pages/timezone/data/timezone_8.5_dim.png | Bin 0 -> 1177 bytes
.../pages/timezone/datetime.gresource.xml | 4 +
.../pages/timezone/gis-timezone-page.c | 150 ++++++-
gnome-initial-setup/pages/timezone/tz.c | 483 +++++++++++++++++
gnome-initial-setup/pages/timezone/tz.h | 88 ++++
10 files changed, 1198 insertions(+), 81 deletions(-)
---
diff --git a/gnome-initial-setup/pages/timezone/Makefile.am b/gnome-initial-setup/pages/timezone/Makefile.am
index ff6f410..c05de2e 100644
--- a/gnome-initial-setup/pages/timezone/Makefile.am
+++ b/gnome-initial-setup/pages/timezone/Makefile.am
@@ -40,6 +40,7 @@ BUILT_SOURCES += timezone-resources.c timezone-resources.h
libgistimezone_la_SOURCES = \
cc-timezone-map.c cc-timezone-map.h \
+ tz.c tz.h \
gis-bubble-widget.c gis-bubble-widget.h \
gis-timezone-page.c gis-timezone-page.h \
$(BUILT_SOURCES)
diff --git a/gnome-initial-setup/pages/timezone/cc-timezone-map.c
b/gnome-initial-setup/pages/timezone/cc-timezone-map.c
index f94a31e..85567b2 100644
--- a/gnome-initial-setup/pages/timezone/cc-timezone-map.c
+++ b/gnome-initial-setup/pages/timezone/cc-timezone-map.c
@@ -24,6 +24,7 @@
#include "cc-timezone-map.h"
#include <math.h>
#include <string.h>
+#include "tz.h"
G_DEFINE_TYPE (CcTimezoneMap, cc_timezone_map, GTK_TYPE_WIDGET)
@@ -35,16 +36,89 @@ G_DEFINE_TYPE (CcTimezoneMap, cc_timezone_map, GTK_TYPE_WIDGET)
#define DATETIME_RESOURCE_PATH "/org/gnome/control-center/datetime"
+typedef struct
+{
+ gdouble offset;
+ guchar red;
+ guchar green;
+ guchar blue;
+ guchar alpha;
+} CcTimezoneMapOffset;
+
struct _CcTimezoneMapPrivate
{
GdkPixbuf *orig_background;
GdkPixbuf *orig_background_dim;
+ GdkPixbuf *orig_color_map;
GdkPixbuf *background;
+ GdkPixbuf *color_map;
+ GdkPixbuf *pin;
+
+ guchar *visible_map_pixels;
+ gint visible_map_rowstride;
+
+ gdouble selected_offset;
+
+ TzDB *tzdb;
+ TzLocation *location;
+
+ gchar *bubble_text;
+};
+
+enum
+{
+ LOCATION_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
- GWeatherLocation *location;
+
+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_dispose (GObject *object)
{
@@ -52,11 +126,37 @@ cc_timezone_map_dispose (GObject *object)
g_clear_object (&priv->orig_background);
g_clear_object (&priv->orig_background_dim);
+ g_clear_object (&priv->orig_color_map);
g_clear_object (&priv->background);
+ g_clear_object (&priv->pin);
+ g_clear_pointer (&priv->bubble_text, g_free);
+
+ if (priv->color_map)
+ {
+ g_clear_object (&priv->color_map);
+
+ 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,
@@ -110,10 +210,49 @@ cc_timezone_map_size_allocate (GtkWidget *widget,
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;
+ 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);
+
+ gdk_window_set_user_data (window, widget);
+ gtk_widget_set_window (widget, window);
+}
+
+
static gdouble
convert_longitude_to_x (gdouble longitude, gint map_width)
{
@@ -151,104 +290,184 @@ convert_latitude_to_y (gdouble latitude, gdouble map_height)
}
static void
-draw_hilight (CcTimezoneMap *map,
- cairo_t *cr)
+draw_text_bubble (cairo_t *cr,
+ GtkWidget *widget,
+ gdouble pointx,
+ gdouble pointy)
{
- GtkWidget *widget = GTK_WIDGET (map);
- CcTimezoneMapPrivate *priv = map->priv;
- const char *fmt;
- GWeatherTimezone *zone;
- double selected_offset;
- GdkPixbuf *hilight, *orig_hilight;
- GtkAllocation alloc;
- char *file;
- GError *err = NULL;
+ static const double corner_radius = 9.0;
+ static const double margin_top = 12.0;
+ static const double margin_bottom = 12.0;
+ static const double margin_left = 24.0;
+ static const double margin_right = 24.0;
- if (!priv->location)
+ CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
+ GtkAllocation alloc;
+ PangoLayout *layout;
+ PangoRectangle text_rect;
+ double x;
+ double y;
+ double width;
+ double height;
+
+ if (!priv->bubble_text)
return;
gtk_widget_get_allocation (widget, &alloc);
+ layout = gtk_widget_create_pango_layout (widget, NULL);
- /* paint hilight */
- if (gtk_widget_is_sensitive (widget))
- fmt = DATETIME_RESOURCE_PATH "/timezone_%g.png";
+ /* Layout the text */
+ pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
+ pango_layout_set_spacing (layout, 3);
+ pango_layout_set_markup (layout, priv->bubble_text, -1);
+
+ pango_layout_get_pixel_extents (layout, NULL, &text_rect);
+
+ /* Calculate the bubble size based on the text layout size */
+ width = text_rect.width + margin_left + margin_right;
+ height = text_rect.height + margin_top + margin_bottom;
+
+ if (pointx < alloc.width / 2)
+ x = pointx + 25;
else
- fmt = DATETIME_RESOURCE_PATH "/timezone_%g_dim.png";
+ x = pointx - width - 25;
- zone = gweather_location_get_timezone (priv->location);
+ y = pointy - height / 2;
- /* XXX: Do we need to do anything for DST? I don't think so... */
- selected_offset = gweather_timezone_get_offset (zone) / 60.0;
+ /* Make sure it fits in the visible area */
+ x = CLAMP (x, 0, alloc.width - width);
+ y = CLAMP (y, 0, alloc.height - height);
- file = g_strdup_printf (fmt, selected_offset);
- orig_hilight = gdk_pixbuf_new_from_resource (file, &err);
- g_free (file);
- file = NULL;
+ cairo_save (cr);
+ cairo_translate (cr, x, y);
- hilight = gdk_pixbuf_scale_simple (orig_hilight, alloc.width, alloc.height, GDK_INTERP_BILINEAR);
- gdk_cairo_set_source_pixbuf (cr, hilight, 0, 0);
+ /* Draw the bubble */
+ cairo_new_sub_path (cr);
+ cairo_arc (cr, width - corner_radius, corner_radius, corner_radius, radians (-90), radians (0));
+ cairo_arc (cr, width - corner_radius, height - corner_radius, corner_radius, radians (0), radians (90));
+ cairo_arc (cr, corner_radius, height - corner_radius, corner_radius, radians (90), radians (180));
+ cairo_arc (cr, corner_radius, corner_radius, corner_radius, radians (180), radians (270));
+ cairo_close_path (cr);
- cairo_paint (cr);
- g_object_unref (hilight);
- g_object_unref (orig_hilight);
+ cairo_set_source_rgba (cr, 0.2, 0.2, 0.2, 0.7);
+ cairo_fill (cr);
+
+ /* And finally draw the text */
+ cairo_set_source_rgb (cr, 1, 1, 1);
+ cairo_move_to (cr, margin_left, margin_top);
+ pango_cairo_show_layout (cr, layout);
- g_clear_error (&err);
+ g_object_unref (layout);
+ cairo_restore (cr);
}
-static void
-draw_pin (CcTimezoneMap *map,
- cairo_t *cr)
+static gboolean
+cc_timezone_map_draw (GtkWidget *widget,
+ cairo_t *cr)
{
- GtkWidget *widget = GTK_WIDGET (map);
- CcTimezoneMapPrivate *priv = map->priv;
- GdkPixbuf *pin;
+ CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
+ GdkPixbuf *hilight, *orig_hilight;
GtkAllocation alloc;
+ gchar *file;
GError *err = NULL;
- double longitude, latitude;
- double pointx, pointy;
+ gdouble pointx, pointy;
+ char buf[16];
+ const char *fmt;
gtk_widget_get_allocation (widget, &alloc);
- if (!priv->location)
- return;
+ /* paint background */
+ gdk_cairo_set_source_pixbuf (cr, priv->background, 0, 0);
+ cairo_paint (cr);
- if (!gweather_location_has_coords (priv->location))
- return;
+ /* paint hilight */
+ if (gtk_widget_is_sensitive (widget))
+ fmt = DATETIME_RESOURCE_PATH "/timezone_%s.png";
+ else
+ fmt = DATETIME_RESOURCE_PATH "/timezone_%s_dim.png";
- /* load pin icon */
- pin = gdk_pixbuf_new_from_resource (DATETIME_RESOURCE_PATH "/pin.png", &err);
+ file = g_strdup_printf (fmt,
+ g_ascii_formatd (buf, sizeof (buf),
+ "%g", priv->selected_offset));
+ orig_hilight = gdk_pixbuf_new_from_resource (file, &err);
+ g_free (file);
+ file = NULL;
- gweather_location_get_coords (priv->location, &latitude, &longitude);
+ if (!orig_hilight)
+ {
+ g_warning ("Could not load hilight: %s",
+ (err) ? err->message : "Unknown Error");
+ if (err)
+ g_clear_error (&err);
+ }
+ else
+ {
- pointx = convert_longitude_to_x (longitude, alloc.width);
- pointy = convert_latitude_to_y (latitude, alloc.height);
+ hilight = gdk_pixbuf_scale_simple (orig_hilight, alloc.width,
+ alloc.height, GDK_INTERP_BILINEAR);
+ gdk_cairo_set_source_pixbuf (cr, hilight, 0, 0);
- pointx = CLAMP (floor (pointx), 0, alloc.width);
- pointy = CLAMP (floor (pointy), 0, alloc.height);
+ cairo_paint (cr);
+ g_object_unref (hilight);
+ g_object_unref (orig_hilight);
+ }
- gdk_cairo_set_source_pixbuf (cr, pin, pointx - PIN_HOT_POINT_X, pointy - PIN_HOT_POINT_Y);
- cairo_paint (cr);
+ if (priv->location)
+ {
+ pointx = convert_longitude_to_x (priv->location->longitude, alloc.width);
+ pointy = convert_latitude_to_y (priv->location->latitude, alloc.height);
- g_object_unref (pin);
+ pointx = CLAMP (floor (pointx), 0, alloc.width);
+ pointy = CLAMP (floor (pointy), 0, alloc.height);
+
+ draw_text_bubble (cr, widget, pointx, pointy);
+
+ if (priv->pin)
+ {
+ gdk_cairo_set_source_pixbuf (cr, priv->pin,
+ pointx - PIN_HOT_POINT_X,
+ pointy - PIN_HOT_POINT_Y);
+ cairo_paint (cr);
+ }
+ }
+
+ return TRUE;
}
-static gboolean
-cc_timezone_map_draw (GtkWidget *widget,
- cairo_t *cr)
+static void
+update_cursor (GtkWidget *widget)
{
- CcTimezoneMap *map = CC_TIMEZONE_MAP (widget);
- CcTimezoneMapPrivate *priv = map->priv;
+ GdkWindow *window;
+ GdkCursor *cursor = NULL;
- /* paint background */
- gdk_cairo_set_source_pixbuf (cr, priv->background, 0, 0);
- cairo_paint (cr);
+ if (!gtk_widget_get_realized (widget))
+ return;
- draw_hilight (map, cr);
- draw_pin (map, cr);
+ if (gtk_widget_is_sensitive (widget))
+ {
+ GdkDisplay *display;
+ display = gtk_widget_get_display (widget);
+ cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
+ }
- return TRUE;
+ window = gtk_widget_get_window (widget);
+ gdk_window_set_cursor (window, cursor);
+
+ if (cursor)
+ g_object_unref (cursor);
+}
+
+static void
+cc_timezone_map_state_flags_changed (GtkWidget *widget,
+ GtkStateFlags prev_state)
+{
+ update_cursor (widget);
+
+ if (GTK_WIDGET_CLASS (cc_timezone_map_parent_class)->state_flags_changed)
+ GTK_WIDGET_CLASS (cc_timezone_map_parent_class)->state_flags_changed (widget, prev_state);
}
+
static void
cc_timezone_map_class_init (CcTimezoneMapClass *klass)
{
@@ -258,11 +477,130 @@ cc_timezone_map_class_init (CcTimezoneMapClass *klass)
g_type_class_add_private (klass, sizeof (CcTimezoneMapPrivate));
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;
+ widget_class->state_flags_changed = cc_timezone_map_state_flags_changed;
+
+ 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_longitude_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
@@ -293,7 +631,28 @@ cc_timezone_map_init (CcTimezoneMap *self)
g_clear_error (&err);
}
- gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
+ priv->orig_color_map = gdk_pixbuf_new_from_resource (DATETIME_RESOURCE_PATH "/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->pin = gdk_pixbuf_new_from_resource (DATETIME_RESOURCE_PATH "/pin.png",
+ &err);
+ if (!priv->pin)
+ {
+ g_warning ("Could not load pin icon: %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 *
@@ -302,19 +661,54 @@ cc_timezone_map_new (void)
return g_object_new (CC_TYPE_TIMEZONE_MAP, NULL);
}
-void
-cc_timezone_map_set_location (CcTimezoneMap *map,
- GWeatherLocation *location)
+gboolean
+cc_timezone_map_set_timezone (CcTimezoneMap *map,
+ const gchar *timezone)
{
- CcTimezoneMapPrivate *priv = map->priv;
+ GPtrArray *locations;
+ guint i;
+ char *real_tz;
+ gboolean ret;
- if (priv->location)
- gweather_location_unref (priv->location);
+ real_tz = tz_info_get_clean_name (map->priv->tzdb, timezone);
- if (location)
- priv->location = gweather_location_ref (location);
- else
- priv->location = NULL;
+ 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;
+}
+
+void
+cc_timezone_map_set_bubble_text (CcTimezoneMap *map,
+ const gchar *text)
+{
+ CcTimezoneMapPrivate *priv = TIMEZONE_MAP_PRIVATE (map);
+
+ g_free (priv->bubble_text);
+ priv->bubble_text = g_strdup (text);
gtk_widget_queue_draw (GTK_WIDGET (map));
}
+
+TzLocation *
+cc_timezone_map_get_location (CcTimezoneMap *map)
+{
+ return map->priv->location;
+}
diff --git a/gnome-initial-setup/pages/timezone/cc-timezone-map.h
b/gnome-initial-setup/pages/timezone/cc-timezone-map.h
index 17453b2..facf133 100644
--- a/gnome-initial-setup/pages/timezone/cc-timezone-map.h
+++ b/gnome-initial-setup/pages/timezone/cc-timezone-map.h
@@ -23,9 +23,7 @@
#define _CC_TIMEZONE_MAP_H
#include <gtk/gtk.h>
-
-#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
-#include <libgweather/gweather.h>
+#include "tz.h"
G_BEGIN_DECLS
@@ -71,8 +69,11 @@ GType cc_timezone_map_get_type (void) G_GNUC_CONST;
CcTimezoneMap *cc_timezone_map_new (void);
-void cc_timezone_map_set_location (CcTimezoneMap *map,
- GWeatherLocation *location);
+gboolean cc_timezone_map_set_timezone (CcTimezoneMap *map,
+ const gchar *timezone);
+void cc_timezone_map_set_bubble_text (CcTimezoneMap *map,
+ const gchar *text);
+TzLocation * cc_timezone_map_get_location (CcTimezoneMap *map);
G_END_DECLS
diff --git a/gnome-initial-setup/pages/timezone/data/cc.png b/gnome-initial-setup/pages/timezone/data/cc.png
new file mode 100644
index 0000000..9984d23
Binary files /dev/null and b/gnome-initial-setup/pages/timezone/data/cc.png differ
diff --git a/gnome-initial-setup/pages/timezone/data/timezone_8.5.png
b/gnome-initial-setup/pages/timezone/data/timezone_8.5.png
new file mode 100644
index 0000000..e7df3d7
Binary files /dev/null and b/gnome-initial-setup/pages/timezone/data/timezone_8.5.png differ
diff --git a/gnome-initial-setup/pages/timezone/data/timezone_8.5_dim.png
b/gnome-initial-setup/pages/timezone/data/timezone_8.5_dim.png
new file mode 100644
index 0000000..7f1fbf4
Binary files /dev/null and b/gnome-initial-setup/pages/timezone/data/timezone_8.5_dim.png differ
diff --git a/gnome-initial-setup/pages/timezone/datetime.gresource.xml
b/gnome-initial-setup/pages/timezone/datetime.gresource.xml
index fa316ed..7081349 100644
--- a/gnome-initial-setup/pages/timezone/datetime.gresource.xml
+++ b/gnome-initial-setup/pages/timezone/datetime.gresource.xml
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/control-center/datetime">
+ <file>backward</file>
<file alias="bg.png">data/bg.png</file>
<file alias="bg_dim.png">data/bg_dim.png</file>
+ <file alias="cc.png">data/cc.png</file>
<file alias="pin.png">data/pin.png</file>
<file alias="timezone_0.png">data/timezone_0.png</file>
<file alias="timezone_0_dim.png">data/timezone_0_dim.png</file>
@@ -74,6 +76,8 @@
<file alias="timezone_-8_dim.png">data/timezone_-8_dim.png</file>
<file alias="timezone_8.png">data/timezone_8.png</file>
<file alias="timezone_8_dim.png">data/timezone_8_dim.png</file>
+ <file alias="timezone_8.5.png">data/timezone_8.5.png</file>
+ <file alias="timezone_8.5_dim.png">data/timezone_8.5_dim.png</file>
<file alias="timezone_8.75.png">data/timezone_8.75.png</file>
<file alias="timezone_8.75_dim.png">data/timezone_8.75_dim.png</file>
<file alias="timezone_-9.png">data/timezone_-9.png</file>
diff --git a/gnome-initial-setup/pages/timezone/gis-timezone-page.c
b/gnome-initial-setup/pages/timezone/gis-timezone-page.c
index 1e4a603..7c32dc2 100644
--- a/gnome-initial-setup/pages/timezone/gis-timezone-page.c
+++ b/gnome-initial-setup/pages/timezone/gis-timezone-page.c
@@ -31,9 +31,12 @@
#include <stdlib.h>
#include <string.h>
+#include <langinfo.h>
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnome-desktop/gnome-languages.h>
+#include <libgnome-desktop/gnome-wall-clock.h>
+#include <gdesktop-enums.h>
#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
#include <libgweather/gweather.h>
@@ -52,6 +55,9 @@
/* Defines from geoclue private header src/public-api/gclue-enums.h */
#define GCLUE_ACCURACY_LEVEL_CITY 4
+#define CLOCK_SCHEMA "org.gnome.desktop.interface"
+#define CLOCK_FORMAT_KEY "clock-format"
+
struct _GisTimezonePagePrivate
{
GtkWidget *map;
@@ -67,6 +73,10 @@ struct _GisTimezonePagePrivate
GWeatherLocation *auto_location;
GWeatherLocation *current_location;
Timedate1 *dtm;
+
+ GnomeWallClock *clock;
+ GDesktopClockFormat clock_format;
+ gboolean ampm_available;
};
typedef struct _GisTimezonePagePrivate GisTimezonePagePrivate;
@@ -115,8 +125,6 @@ set_location (GisTimezonePage *page,
g_clear_pointer (&priv->current_location, gweather_location_unref);
- cc_timezone_map_set_location (CC_TIMEZONE_MAP (priv->map), location);
-
gtk_widget_set_visible (priv->search_overlay, (location == NULL));
gis_page_set_complete (GIS_PAGE (page), (location != NULL));
@@ -130,6 +138,8 @@ set_location (GisTimezonePage *page,
zone = gweather_location_get_timezone (location);
tzid = gweather_timezone_get_tzid (zone);
+ cc_timezone_map_set_timezone (CC_TIMEZONE_MAP (priv->map), tzid);
+
queue_set_timezone (page, tzid);
}
}
@@ -376,6 +386,124 @@ entry_location_changed (GObject *object, GParamSpec *param, GisTimezonePage *pag
set_location (page, location);
}
+#define GETTEXT_PACKAGE_TIMEZONES "gnome-control-center-2.0-timezones"
+
+static char *
+translated_city_name (TzLocation *loc)
+{
+ char *country;
+ char *name;
+ char *zone_translated;
+ char **split_translated;
+ gint length;
+
+ /* Load the translation for it */
+ zone_translated = g_strdup (dgettext (GETTEXT_PACKAGE_TIMEZONES, loc->zone));
+ g_strdelimit (zone_translated, "_", ' ');
+ split_translated = g_regex_split_simple ("[\\x{2044}\\x{2215}\\x{29f8}\\x{ff0f}/]",
+ zone_translated,
+ 0, 0);
+ g_free (zone_translated);
+
+ length = g_strv_length (split_translated);
+
+ country = gnome_get_country_from_code (loc->country, NULL);
+ /* Translators: "city, country" */
+ name = g_strdup_printf (C_("timezone loc", "%s, %s"),
+ split_translated[length-1],
+ country);
+ g_free (country);
+ g_strfreev (split_translated);
+
+ return name;
+}
+
+static void
+update_timezone (GisTimezonePage *page, TzLocation *location)
+{
+ GisTimezonePagePrivate *priv = gis_timezone_page_get_instance_private (page);
+ char *tz_desc;
+ char *bubble_text;
+ char *city_country;
+ char *utc_label;
+ char *time_label;
+ GTimeZone *zone;
+ GDateTime *date;
+ gboolean use_ampm;
+
+ if (priv->clock_format == G_DESKTOP_CLOCK_FORMAT_12H && priv->ampm_available)
+ use_ampm = TRUE;
+ else
+ use_ampm = FALSE;
+
+ zone = g_time_zone_new (location->zone);
+ date = g_date_time_new_now (zone);
+ g_time_zone_unref (zone);
+
+ /* Update the text bubble in the timezone map */
+ city_country = translated_city_name (location);
+
+ /* Translators: UTC here means the Coordinated Universal Time.
+ * %:::z will be replaced by the offset from UTC e.g. UTC+02
+ */
+ utc_label = g_date_time_format (date, _("UTC%:::z"));
+
+ if (use_ampm)
+ /* Translators: This is the time format used in 12-hour mode. */
+ time_label = g_date_time_format (date, _("%l:%M %p"));
+ else
+ /* Translators: This is the time format used in 24-hour mode. */
+ time_label = g_date_time_format (date, _("%R"));
+
+ /* Translators: "timezone (utc shift)" */
+ tz_desc = g_strdup_printf (C_("timezone map", "%s (%s)"),
+ g_date_time_get_timezone_abbreviation (date),
+ utc_label);
+ bubble_text = g_strdup_printf ("<b>%s</b>\n"
+ "<small>%s</small>\n"
+ "<b>%s</b>",
+ tz_desc,
+ city_country,
+ time_label);
+ cc_timezone_map_set_bubble_text (CC_TIMEZONE_MAP (priv->map), bubble_text);
+
+ g_free (tz_desc);
+ g_free (city_country);
+ g_free (utc_label);
+ g_free (time_label);
+ g_free (bubble_text);
+
+ g_date_time_unref (date);
+}
+
+static void
+map_location_changed (CcTimezoneMap *map,
+ TzLocation *location,
+ GisTimezonePage *page)
+{
+ update_timezone (page, location);
+ queue_set_timezone (page, location->zone);
+}
+
+static void
+on_clock_changed (GnomeWallClock *clock,
+ GParamSpec *pspec,
+ GisTimezonePage *page)
+{
+ GisTimezonePagePrivate *priv = gis_timezone_page_get_instance_private (page);
+ TzLocation *location;
+
+ if (!gtk_widget_get_mapped (priv->map))
+ return;
+
+ if (gtk_widget_is_visible (priv->search_overlay))
+ return;
+
+ location = cc_timezone_map_get_location (CC_TIMEZONE_MAP (priv->map));
+ if (location)
+ update_timezone (page, location);
+}
+
static void
entry_mapped (GtkWidget *widget,
gpointer user_data)
@@ -429,6 +557,8 @@ gis_timezone_page_constructed (GObject *object)
GisTimezonePage *page = GIS_TIMEZONE_PAGE (object);
GisTimezonePagePrivate *priv = gis_timezone_page_get_instance_private (page);
GError *error;
+ const char *ampm;
+ GSettings *settings;
G_OBJECT_CLASS (gis_timezone_page_parent_class)->constructed (object);
@@ -444,6 +574,19 @@ gis_timezone_page_constructed (GObject *object)
exit (1);
}
+ priv->clock = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL);
+ g_signal_connect (priv->clock, "notify::clock", G_CALLBACK (on_clock_changed), page);
+
+ ampm = nl_langinfo (AM_STR);
+ if (ampm == NULL || ampm[0] == '\0')
+ priv->ampm_available = FALSE;
+ else
+ priv->ampm_available = TRUE;
+
+ settings = g_settings_new (CLOCK_SCHEMA);
+ priv->clock_format = g_settings_get_enum (settings, CLOCK_FORMAT_KEY);
+ g_object_unref (settings);
+
priv->geoclue_cancellable = g_cancellable_new ();
set_auto_location (page, NULL);
@@ -458,6 +601,8 @@ gis_timezone_page_constructed (GObject *object)
G_CALLBACK (visible_child_changed), page);
g_signal_connect (priv->search_button, "toggled",
G_CALLBACK (search_button_toggled), page);
+ g_signal_connect (priv->map, "location-changed",
+ G_CALLBACK (map_location_changed), page);
gtk_widget_show (GTK_WIDGET (page));
}
@@ -471,6 +616,7 @@ gis_timezone_page_dispose (GObject *object)
stop_geolocation (page);
g_clear_object (&priv->dtm);
+ g_clear_object (&priv->clock);
G_OBJECT_CLASS (gis_timezone_page_parent_class)->dispose (object);
}
diff --git a/gnome-initial-setup/pages/timezone/tz.c b/gnome-initial-setup/pages/timezone/tz.c
new file mode 100644
index 0000000..0eac576
--- /dev/null
+++ b/gnome-initial-setup/pages/timezone/tz.c
@@ -0,0 +1,483 @@
+/* -*- 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <math.h>
+#include <string.h>
+#include "tz.h"
+#include "cc-datetime-resources.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;
+ gchar *tz_env_value;
+
+ g_return_val_if_fail (loc != NULL, NULL);
+ g_return_val_if_fail (loc->zone != NULL, NULL);
+
+ tz_env_value = g_strdup (getenv ("TZ"));
+ 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;
+
+ if (tz_env_value)
+ setenv ("TZ", tz_env_value, 1);
+ else
+ unsetenv ("TZ");
+
+ g_free (tz_env_value);
+
+ 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)
+{
+ char **lines;
+ GBytes *bytes;
+ const char *contents;
+ guint i;
+
+ tz_db->backward = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+ bytes = g_resources_lookup_data ("/org/gnome/control-center/datetime/backward",
+ G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
+ contents = (const char *) g_bytes_get_data (bytes, NULL);
+
+ lines = g_strsplit (contents, "\n", -1);
+ g_bytes_unref (bytes);
+
+ 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/gnome-initial-setup/pages/timezone/tz.h b/gnome-initial-setup/pages/timezone/tz.h
new file mode 100644
index 0000000..93905b3
--- /dev/null
+++ b/gnome-initial-setup/pages/timezone/tz.h
@@ -0,0 +1,88 @@
+/* -*- 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#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]