[gnome-control-center/wip/datetime-panel: 14/15] datetime: add a function to set the current location on CcTimezoneMap
- From: Thomas Wood <thos src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/datetime-panel: 14/15] datetime: add a function to set the current location on CcTimezoneMap
- Date: Mon, 28 Jun 2010 17:10:17 +0000 (UTC)
commit 5ed92c674ee3edd09569cc1f50aa50336cc93869
Author: Thomas Wood <thomas wood intel com>
Date: Mon Jun 28 17:59:27 2010 +0100
datetime: add a function to set the current location on CcTimezoneMap
Add cc_timezone_map_set_timezone function to set the current location on
the map.
panels/datetime/cc-timezone-map.c | 53 +++++++++++++++++++++++++++++-------
panels/datetime/cc-timezone-map.h | 2 +
2 files changed, 44 insertions(+), 11 deletions(-)
---
diff --git a/panels/datetime/cc-timezone-map.c b/panels/datetime/cc-timezone-map.c
index 75a28ce..4e17a6e 100644
--- a/panels/datetime/cc-timezone-map.c
+++ b/panels/datetime/cc-timezone-map.c
@@ -400,6 +400,25 @@ sort_locations (TzLocation *a,
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)
@@ -415,7 +434,6 @@ button_press_event (GtkWidget *widget,
gint width, height;
GList *distances = NULL;
GtkAllocation alloc;
- TzInfo *info;
x = event->x;
y = event->y;
@@ -467,17 +485,9 @@ button_press_event (GtkWidget *widget,
distances = g_list_sort (distances, (GCompareFunc) sort_locations);
- priv->location = (TzLocation*) distances->data;
- g_list_free (distances);
-
- 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 (widget, signals[LOCATION_CHANGED], 0, priv->location);
+ set_location (CC_TIMEZONE_MAP (widget), (TzLocation*) distances->data);
- tz_info_free (info);
+ g_list_free (distances);
return TRUE;
}
@@ -525,3 +535,24 @@ cc_timezone_map_new (void)
{
return g_object_new (CC_TYPE_TIMEZONE_MAP, NULL);
}
+
+void
+cc_timezone_map_set_timezone (CcTimezoneMap *map,
+ const gchar *timezone)
+{
+ GPtrArray *locations;
+ guint i;
+
+ locations = tz_get_locations (map->priv->tzdb);
+
+ for (i = 0; i < locations->len; i++)
+ {
+ TzLocation *loc = locations->pdata[i];
+
+ if (!g_strcmp0 (loc->zone, timezone))
+ {
+ set_location (map, loc);
+ break;
+ }
+ }
+}
diff --git a/panels/datetime/cc-timezone-map.h b/panels/datetime/cc-timezone-map.h
index 2a62855..631bf72 100644
--- a/panels/datetime/cc-timezone-map.h
+++ b/panels/datetime/cc-timezone-map.h
@@ -69,6 +69,8 @@ struct _CcTimezoneMapClass
GType cc_timezone_map_get_type (void) G_GNUC_CONST;
CcTimezoneMap *cc_timezone_map_new (void);
+void cc_timezone_map_set_timezone (CcTimezoneMap *map,
+ const gchar *timezone);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]