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.
This commit is contained in:
parent
8174f22fe7
commit
5ed92c674e
2 changed files with 44 additions and 11 deletions
|
@ -400,6 +400,25 @@ sort_locations (TzLocation *a,
|
||||||
return 0;
|
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
|
static gboolean
|
||||||
button_press_event (GtkWidget *widget,
|
button_press_event (GtkWidget *widget,
|
||||||
GdkEventButton *event)
|
GdkEventButton *event)
|
||||||
|
@ -415,7 +434,6 @@ button_press_event (GtkWidget *widget,
|
||||||
gint width, height;
|
gint width, height;
|
||||||
GList *distances = NULL;
|
GList *distances = NULL;
|
||||||
GtkAllocation alloc;
|
GtkAllocation alloc;
|
||||||
TzInfo *info;
|
|
||||||
|
|
||||||
x = event->x;
|
x = event->x;
|
||||||
y = event->y;
|
y = event->y;
|
||||||
|
@ -467,18 +485,10 @@ button_press_event (GtkWidget *widget,
|
||||||
distances = g_list_sort (distances, (GCompareFunc) sort_locations);
|
distances = g_list_sort (distances, (GCompareFunc) sort_locations);
|
||||||
|
|
||||||
|
|
||||||
priv->location = (TzLocation*) distances->data;
|
set_location (CC_TIMEZONE_MAP (widget), (TzLocation*) distances->data);
|
||||||
|
|
||||||
g_list_free (distances);
|
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);
|
|
||||||
|
|
||||||
tz_info_free (info);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,3 +535,24 @@ cc_timezone_map_new (void)
|
||||||
{
|
{
|
||||||
return g_object_new (CC_TYPE_TIMEZONE_MAP, NULL);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -69,6 +69,8 @@ struct _CcTimezoneMapClass
|
||||||
GType cc_timezone_map_get_type (void) G_GNUC_CONST;
|
GType cc_timezone_map_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
CcTimezoneMap *cc_timezone_map_new (void);
|
CcTimezoneMap *cc_timezone_map_new (void);
|
||||||
|
void cc_timezone_map_set_timezone (CcTimezoneMap *map,
|
||||||
|
const gchar *timezone);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue