Merge lp:~ev/timezonemap/timezonelocation into lp:timezonemap

Proposed by Evan
Status: Merged
Merged at revision: 15
Proposed branch: lp:~ev/timezonemap/timezonelocation
Merge into: lp:timezonemap
Diff against target: 771 lines (+340/-129)
5 files modified
src/cc-timezone-map.c (+61/-23)
src/cc-timezone-map.h (+1/-1)
src/test-timezone.c (+9/-3)
src/tz.c (+221/-83)
src/tz.h (+48/-19)
To merge this branch: bzr merge lp:~ev/timezonemap/timezonelocation
Reviewer Review Type Date Requested Status
Michael Terry Pending
Review via email: mp+70122@code.launchpad.net

Description of the change

This branch exposes the timezone locations as GObjects. Do you think it's better to do this across the board, as I've done here, or to push the location private struct to the header, so that cc-timezone-map.c can use it?

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/cc-timezone-map.c'
--- src/cc-timezone-map.c 2011-07-29 09:01:38 +0000
+++ src/cc-timezone-map.c 2011-08-02 08:06:15 +0000
@@ -63,7 +63,7 @@
63 gchar *watermark;63 gchar *watermark;
6464
65 TzDB *tzdb;65 TzDB *tzdb;
66 TzLocation *location;66 CcTimezoneLocation *location;
67 GHashTable *alias_db;67 GHashTable *alias_db;
68};68};
6969
@@ -813,8 +813,16 @@
813 g_clear_error (&err);813 g_clear_error (&err);
814 }814 }
815815
816 pointx = convert_longtitude_to_x (priv->location->longitude, alloc.width);816 GValue lat = {0};
817 pointy = convert_latitude_to_y (priv->location->latitude, alloc.height);817 GValue lon = {0};
818 g_value_init (&lat, G_TYPE_DOUBLE);
819 g_value_init (&lon, G_TYPE_DOUBLE);
820 g_object_get_property(G_OBJECT (priv->location), "latitude", &lat);
821 g_object_get_property(G_OBJECT (priv->location), "longitude", &lon);
822 pointx = convert_longtitude_to_x (g_value_get_double(&lon), alloc.width);
823 pointy = convert_latitude_to_y (g_value_get_double(&lat), alloc.height);
824 g_value_unset (&lon);
825 g_value_unset (&lat);
818826
819 if (pointy > alloc.height)827 if (pointy > alloc.height)
820 pointy = alloc.height;828 pointy = alloc.height;
@@ -854,20 +862,31 @@
854 0,862 0,
855 NULL,863 NULL,
856 NULL,864 NULL,
857 g_cclosure_marshal_VOID__POINTER,865 g_cclosure_marshal_VOID__OBJECT,
858 G_TYPE_NONE, 1,866 G_TYPE_NONE, 1,
859 G_TYPE_POINTER);867 CC_TYPE_TIMEZONE_LOCATION);
860}868}
861869
862870
863static gint871static gint
864sort_locations (TzLocation *a,872sort_locations (CcTimezoneLocation *a,
865 TzLocation *b)873 CcTimezoneLocation *b)
866{874{
867 if (a->dist > b->dist)875 GValue val_a = {0};
876 GValue val_b = {0};
877 gdouble dist_a, dist_b;
878 g_value_init (&val_a, G_TYPE_DOUBLE);
879 g_value_init (&val_b, G_TYPE_DOUBLE);
880 g_object_get_property(G_OBJECT (a), "dist", &val_a);
881 g_object_get_property(G_OBJECT (b), "dist", &val_b);
882 dist_a = g_value_get_double(&val_a);
883 dist_b = g_value_get_double(&val_b);
884 g_value_unset (&val_a);
885 g_value_unset (&val_b);
886 if (dist_a > dist_b)
868 return 1;887 return 1;
869888
870 if (a->dist < b->dist)889 if (dist_a < dist_b)
871 return -1;890 return -1;
872891
873 return 0;892 return 0;
@@ -875,7 +894,7 @@
875894
876static void895static void
877set_location (CcTimezoneMap *map,896set_location (CcTimezoneMap *map,
878 TzLocation *location)897 CcTimezoneLocation *location)
879{898{
880 CcTimezoneMapPrivate *priv = map->priv;899 CcTimezoneMapPrivate *priv = map->priv;
881 TzInfo *info;900 TzInfo *info;
@@ -892,7 +911,7 @@
892 tz_info_free (info);911 tz_info_free (info);
893}912}
894913
895static TzLocation *914static CcTimezoneLocation *
896get_loc_for_xy (GtkWidget * widget, gint x, gint y)915get_loc_for_xy (GtkWidget * widget, gint x, gint y)
897{916{
898 CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;917 CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
@@ -906,6 +925,13 @@
906 GList *distances = NULL;925 GList *distances = NULL;
907 GtkAllocation alloc;926 GtkAllocation alloc;
908927
928 GValue glon = {0};
929 GValue glat = {0};
930 GValue gdist = {0};
931 g_value_init (&glon, G_TYPE_DOUBLE);
932 g_value_init (&glat, G_TYPE_DOUBLE);
933 g_value_init (&gdist, G_TYPE_DOUBLE);
934
909 rowstride = priv->visible_map_rowstride;935 rowstride = priv->visible_map_rowstride;
910 pixels = priv->visible_map_pixels;936 pixels = priv->visible_map_pixels;
911937
@@ -937,22 +963,27 @@
937 for (i = 0; i < array->len; i++)963 for (i = 0; i < array->len; i++)
938 {964 {
939 gdouble pointx, pointy, dx, dy;965 gdouble pointx, pointy, dx, dy;
940 TzLocation *loc = array->pdata[i];966 CcTimezoneLocation *loc = array->pdata[i];
941967
942 pointx = convert_longtitude_to_x (loc->longitude, width);968 g_object_get_property(G_OBJECT (loc), "longitude", &glon);
943 pointy = convert_latitude_to_y (loc->latitude, height);969 g_object_get_property(G_OBJECT (loc), "latitude", &glat);
970 pointx = convert_longtitude_to_x (g_value_get_double(&glon), width);
971 pointy = convert_latitude_to_y (g_value_get_double(&glat), height);
944972
945 dx = pointx - x;973 dx = pointx - x;
946 dy = pointy - y;974 dy = pointy - y;
947975
948 loc->dist = dx * dx + dy * dy;976 g_value_set_double(&gdist, (gdouble) dx * dx + dy * dy);
977 g_object_set_property(G_OBJECT (loc), "dist", &gdist);
949 distances = g_list_prepend (distances, loc);978 distances = g_list_prepend (distances, loc);
950
951 }979 }
952 distances = g_list_sort (distances, (GCompareFunc) sort_locations);980 distances = g_list_sort (distances, (GCompareFunc) sort_locations);
953981
954 TzLocation * loc = (TzLocation*) distances->data;982 CcTimezoneLocation * loc = (CcTimezoneLocation*) distances->data;
955983
984 g_value_unset (&glon);
985 g_value_unset (&glat);
986 g_value_unset (&gdist);
956 g_list_free (distances);987 g_list_free (distances);
957988
958 return loc;989 return loc;
@@ -962,7 +993,7 @@
962button_press_event (GtkWidget *widget,993button_press_event (GtkWidget *widget,
963 GdkEventButton *event)994 GdkEventButton *event)
964{995{
965 TzLocation * loc = get_loc_for_xy (widget, event->x, event->y);996 CcTimezoneLocation * loc = get_loc_for_xy (widget, event->x, event->y);
966 set_location (CC_TIMEZONE_MAP (widget), loc);997 set_location (CC_TIMEZONE_MAP (widget), loc);
967 return TRUE;998 return TRUE;
968}999}
@@ -1087,6 +1118,8 @@
1087 GPtrArray *locations;1118 GPtrArray *locations;
1088 guint i;1119 guint i;
1089 char *real_tz;1120 char *real_tz;
1121 GValue zone = {0};
1122 g_value_init (&zone, G_TYPE_STRING);
10901123
1091 real_tz = g_hash_table_lookup (map->priv->alias_db, timezone);1124 real_tz = g_hash_table_lookup (map->priv->alias_db, timezone);
10921125
@@ -1094,9 +1127,10 @@
10941127
1095 for (i = 0; i < locations->len; i++)1128 for (i = 0; i < locations->len; i++)
1096 {1129 {
1097 TzLocation *loc = locations->pdata[i];1130 CcTimezoneLocation *loc = locations->pdata[i];
1131 g_object_get_property(G_OBJECT (loc), "zone", &zone);
10981132
1099 if (!g_strcmp0 (loc->zone, real_tz ? real_tz : timezone))1133 if (!g_strcmp0 (g_value_get_string(&zone), real_tz ? real_tz : timezone))
1100 {1134 {
1101 set_location (map, loc);1135 set_location (map, loc);
1102 break;1136 break;
@@ -1104,6 +1138,7 @@
1104 }1138 }
11051139
1106 gtk_widget_queue_draw (GTK_WIDGET (map));1140 gtk_widget_queue_draw (GTK_WIDGET (map));
1141 g_value_unset (&zone);
1107}1142}
11081143
1109void1144void
@@ -1132,11 +1167,14 @@
1132 }1167 }
1133 else {1168 else {
1134 GtkAllocation alloc;1169 GtkAllocation alloc;
1170 GValue val_zone = {0};
1171 g_value_init (&val_zone, G_TYPE_STRING);
1135 gtk_widget_get_allocation (GTK_WIDGET (map), &alloc);1172 gtk_widget_get_allocation (GTK_WIDGET (map), &alloc);
1136 x = convert_longtitude_to_x(lon, alloc.width);1173 x = convert_longtitude_to_x(lon, alloc.width);
1137 y = convert_latitude_to_y(lat, alloc.height);1174 y = convert_latitude_to_y(lat, alloc.height);
1138 TzLocation * loc = get_loc_for_xy(GTK_WIDGET (map), x, y);1175 CcTimezoneLocation * loc = get_loc_for_xy(GTK_WIDGET (map), x, y);
1139 return loc->zone;1176 g_value_unset (&val_zone);
1177 return g_value_get_string(&val_zone);
1140 }1178 }
1141}1179}
11421180
@@ -1150,7 +1188,7 @@
1150 gtk_widget_queue_draw (GTK_WIDGET (map));1188 gtk_widget_queue_draw (GTK_WIDGET (map));
1151}1189}
11521190
1153TzLocation *1191CcTimezoneLocation *
1154cc_timezone_map_get_location (CcTimezoneMap *map)1192cc_timezone_map_get_location (CcTimezoneMap *map)
1155{1193{
1156 return map->priv->location;1194 return map->priv->location;
11571195
=== modified file 'src/cc-timezone-map.h'
--- src/cc-timezone-map.h 2011-07-28 15:18:24 +0000
+++ src/cc-timezone-map.h 2011-08-02 08:06:15 +0000
@@ -78,7 +78,7 @@
78 gdouble lon, gdouble lat);78 gdouble lon, gdouble lat);
79const gchar * cc_timezone_map_get_timezone_at_coords (CcTimezoneMap *map,79const gchar * cc_timezone_map_get_timezone_at_coords (CcTimezoneMap *map,
80 gdouble lon, gdouble lat);80 gdouble lon, gdouble lat);
81TzLocation * cc_timezone_map_get_location (CcTimezoneMap *map);81CcTimezoneLocation * cc_timezone_map_get_location (CcTimezoneMap *map);
8282
83G_END_DECLS83G_END_DECLS
8484
8585
=== modified file 'src/test-timezone.c'
--- src/test-timezone.c 2011-07-28 15:28:24 +0000
+++ src/test-timezone.c 2011-08-02 08:06:15 +0000
@@ -22,14 +22,20 @@
22 return 1;22 return 1;
23 }23 }
2424
25 g_type_init();
26 GValue zone = {0};
27 g_value_init(&zone, G_TYPE_STRING);
28
25 db = tz_load_db ();29 db = tz_load_db ();
26 locs = tz_get_locations (db);30 locs = tz_get_locations (db);
27 for (i = 0; i < locs->len ; i++) {31 for (i = 0; i < locs->len ; i++) {
28 TzLocation *loc = locs->pdata[i];32 CcTimezoneLocation *loc = locs->pdata[i];
33
29 TzInfo *info;34 TzInfo *info;
30 char *filename, *path;35 char *filename, *path;
31 gdouble selected_offset;36 gdouble selected_offset;
32 char buf[16];37 char buf[16];
38 g_object_get_property(G_OBJECT (loc), "zone", &zone);
3339
34 info = tz_info_from_location (loc);40 info = tz_info_from_location (loc);
35 selected_offset = tz_location_get_utc_offset (loc)41 selected_offset = tz_location_get_utc_offset (loc)
@@ -41,7 +47,7 @@
41 path = g_build_filename (pixmap_dir, filename, NULL);47 path = g_build_filename (pixmap_dir, filename, NULL);
4248
43 if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE) {49 if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE) {
44 g_message ("File '%s' missing for zone '%s'", filename, loc->zone);50 g_message ("File '%s' missing for zone '%s'", filename, g_value_get_string(&zone));
45 retval = 1;51 retval = 1;
46 }52 }
4753
4854
=== modified file 'src/tz.c'
--- src/tz.c 2011-07-28 15:18:24 +0000
+++ src/tz.c 2011-08-02 08:06:15 +0000
@@ -30,6 +30,7 @@
30#include <time.h>30#include <time.h>
31#include <math.h>31#include <math.h>
32#include <string.h>32#include <string.h>
33#include <float.h>
33#include "tz.h"34#include "tz.h"
3435
3536
@@ -40,6 +41,202 @@
40static void sort_locations_by_country (GPtrArray *locations);41static void sort_locations_by_country (GPtrArray *locations);
41static gchar * tz_data_file_get (void);42static gchar * tz_data_file_get (void);
4243
44G_DEFINE_TYPE (CcTimezoneLocation, cc_timezone_location, G_TYPE_OBJECT)
45
46#define TIMEZONE_LOCATION_PRIVATE(o) \
47 (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_TIMEZONE_LOCATION, CcTimezoneLocationPrivate))
48
49struct _CcTimezoneLocationPrivate
50{
51 gchar *country;
52 gdouble latitude;
53 gdouble longitude;
54 gchar *zone;
55 gchar *comment;
56
57 gdouble dist; /* distance to clicked point for comparison */
58};
59
60enum {
61 PROP_0,
62 PROP_COUNTRY,
63 PROP_LATITUDE,
64 PROP_LONGITUDE,
65 PROP_ZONE,
66 PROP_COMMENT,
67 PROP_DIST
68};
69
70static void
71cc_timezone_location_get_property (GObject *object,
72 guint property_id,
73 GValue *value,
74 GParamSpec *pspec)
75{
76 CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv;
77 switch (property_id)
78 {
79 case PROP_COUNTRY:
80 g_value_set_string (value, priv->country);
81 break;
82 case PROP_LATITUDE:
83 g_value_set_double (value, priv->latitude);
84 break;
85 case PROP_LONGITUDE:
86 g_value_set_double (value, priv->longitude);
87 break;
88 case PROP_ZONE:
89 g_value_set_string (value, priv->zone);
90 break;
91 case PROP_COMMENT:
92 g_value_set_string (value, priv->comment);
93 break;
94 case PROP_DIST:
95 g_value_set_double (value, priv->dist);
96 break;
97 default:
98 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
99 }
100}
101
102static void
103cc_timezone_location_set_property (GObject *object,
104 guint property_id,
105 const GValue *value,
106 GParamSpec *pspec)
107{
108 CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv;
109 switch (property_id)
110 {
111 case PROP_COUNTRY:
112 priv->country = g_value_get_string(value);
113 break;
114 case PROP_LATITUDE:
115 priv->latitude = g_value_get_double(value);
116 break;
117 case PROP_LONGITUDE:
118 priv->longitude = g_value_get_double(value);
119 break;
120 case PROP_ZONE:
121 priv->zone = g_value_get_string(value);
122 break;
123 case PROP_COMMENT:
124 priv->comment = g_value_get_string(value);
125 break;
126 case PROP_DIST:
127 priv->dist = g_value_get_double(value);
128 break;
129 default:
130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
131 }
132}
133
134static void
135cc_timezone_location_dispose (GObject *object)
136{
137 CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv;
138
139 if (priv->country)
140 {
141 g_object_unref (priv->country);
142 priv->country = NULL;
143 }
144
145 if (priv->zone)
146 {
147 g_object_unref (priv->zone);
148 priv->zone = NULL;
149 }
150
151 if (priv->comment)
152 {
153 g_object_unref (priv->comment);
154 priv->comment = NULL;
155 }
156
157 G_OBJECT_CLASS (cc_timezone_location_parent_class)->dispose (object);
158}
159
160static void
161cc_timezone_location_finalize (GObject *object)
162{
163 CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv;
164 G_OBJECT_CLASS (cc_timezone_location_parent_class)->finalize (object);
165}
166
167static void
168cc_timezone_location_class_init (CcTimezoneLocationClass *klass)
169{
170 GObjectClass *object_class = G_OBJECT_CLASS (klass);
171 g_type_class_add_private (klass, sizeof (CcTimezoneLocationPrivate));
172
173 object_class->get_property = cc_timezone_location_get_property;
174 object_class->set_property = cc_timezone_location_set_property;
175 object_class->dispose = cc_timezone_location_dispose;
176 object_class->finalize = cc_timezone_location_finalize;
177
178 g_object_class_install_property(object_class,
179 PROP_COUNTRY,
180 g_param_spec_string ("country",
181 "Country",
182 "The country for the location",
183 "",
184 G_PARAM_READWRITE));
185 g_object_class_install_property(object_class,
186 PROP_LATITUDE,
187 g_param_spec_double ("latitude",
188 "Latitude",
189 "The latitude for the location",
190 -90.0,
191 90.0,
192 0.0,
193 G_PARAM_READWRITE));
194 g_object_class_install_property(object_class,
195 PROP_LONGITUDE,
196 g_param_spec_double ("longitude",
197 "Longitude",
198 "The longitude for the location",
199 -180.0,
200 180.0,
201 0.0,
202 G_PARAM_READWRITE));
203 g_object_class_install_property(object_class,
204 PROP_ZONE,
205 g_param_spec_string ("zone",
206 "Zone",
207 "The time zone for the location",
208 "",
209 G_PARAM_READWRITE));
210 g_object_class_install_property(object_class,
211 PROP_COMMENT,
212 g_param_spec_string ("Comment",
213 "Comment",
214 "A comment for the location",
215 "",
216 G_PARAM_READWRITE));
217 g_object_class_install_property(object_class,
218 PROP_DIST,
219 g_param_spec_double ("dist",
220 "Distance",
221 "The distance for the location",
222 0.0,
223 DBL_MAX,
224 0.0,
225 G_PARAM_READWRITE));
226}
227
228static void
229cc_timezone_location_init (CcTimezoneLocation *self) {
230 CcTimezoneLocationPrivate *priv;
231 priv = self->priv = TIMEZONE_LOCATION_PRIVATE (self);
232}
233
234CcTimezoneLocation *
235cc_timezone_location_new (void)
236{
237 return g_object_new (CC_TYPE_TIMEZONE_LOCATION, NULL);
238}
239
43240
44/* ---------------- *241/* ---------------- *
45 * Public interface *242 * Public interface *
@@ -71,7 +268,7 @@
71 {268 {
72 gchar **tmpstrarr;269 gchar **tmpstrarr;
73 gchar *latstr, *lngstr, *p;270 gchar *latstr, *lngstr, *p;
74 TzLocation *loc;271 CcTimezoneLocation *loc;
75272
76 if (*buf == '#') continue;273 if (*buf == '#') continue;
77274
@@ -84,21 +281,21 @@
84 lngstr = g_strdup (p);281 lngstr = g_strdup (p);
85 *p = '\0';282 *p = '\0';
86 283
87 loc = g_new0 (TzLocation, 1);284 loc = cc_timezone_location_new ();
88 loc->country = g_strdup (tmpstrarr[0]);285 loc->priv->country = g_strdup (tmpstrarr[0]);
89 loc->zone = g_strdup (tmpstrarr[2]);286 loc->priv->zone = g_strdup (tmpstrarr[2]);
90 loc->latitude = convert_pos (latstr, 2);287 loc->priv->latitude = convert_pos (latstr, 2);
91 loc->longitude = convert_pos (lngstr, 3);288 loc->priv->longitude = convert_pos (lngstr, 3);
92 289
93#ifdef __sun290#ifdef __sun
94 if (tmpstrarr[3] && *tmpstrarr[3] == '-' && tmpstrarr[4])291 if (tmpstrarr[3] && *tmpstrarr[3] == '-' && tmpstrarr[4])
95 loc->comment = g_strdup (tmpstrarr[4]);292 loc->comment = g_strdup (tmpstrarr[4]);
96293
97 if (tmpstrarr[3] && *tmpstrarr[3] != '-' && !islower(loc->zone)) {294 if (tmpstrarr[3] && *tmpstrarr[3] != '-' && !islower(loc->zone)) {
98 TzLocation *locgrp;295 CcTimezoneLocation *locgrp;
99296
100 /* duplicate entry */297 /* duplicate entry */
101 locgrp = g_new0 (TzLocation, 1);298 locgrp = cc_timezone_location_new ();
102 locgrp->country = g_strdup (tmpstrarr[0]);299 locgrp->country = g_strdup (tmpstrarr[0]);
103 locgrp->zone = g_strdup (tmpstrarr[3]);300 locgrp->zone = g_strdup (tmpstrarr[3]);
104 locgrp->latitude = convert_pos (latstr, 2);301 locgrp->latitude = convert_pos (latstr, 2);
@@ -108,7 +305,7 @@
108 g_ptr_array_add (tz_db->locations, (gpointer) locgrp);305 g_ptr_array_add (tz_db->locations, (gpointer) locgrp);
109 }306 }
110#else307#else
111 loc->comment = (tmpstrarr[3]) ? g_strdup(tmpstrarr[3]) : NULL;308 loc->priv->comment = (tmpstrarr[3]) ? g_strdup(tmpstrarr[3]) : NULL;
112#endif309#endif
113310
114 g_ptr_array_add (tz_db->locations, (gpointer) loc);311 g_ptr_array_add (tz_db->locations, (gpointer) loc);
@@ -128,32 +325,22 @@
128 return tz_db;325 return tz_db;
129} 326}
130327
131static void
132tz_location_free (TzLocation *loc)
133{
134 g_free (loc->country);
135 g_free (loc->zone);
136 g_free (loc->comment);
137
138 g_free (loc);
139}
140
141void328void
142tz_db_free (TzDB *db)329tz_db_free (TzDB *db)
143{330{
144 g_ptr_array_foreach (db->locations, (GFunc) tz_location_free, NULL);331 g_ptr_array_foreach (db->locations, (GFunc) g_object_unref, NULL);
145 g_ptr_array_free (db->locations, TRUE);332 g_ptr_array_free (db->locations, TRUE);
146 g_free (db);333 g_free (db);
147}334}
148335
149static gint336static gint
150sort_locations (TzLocation *a,337sort_locations (CcTimezoneLocation *a,
151 TzLocation *b)338 CcTimezoneLocation *b)
152{339{
153 if (a->dist > b->dist)340 if (a->priv->dist > b->priv->dist)
154 return 1;341 return 1;
155342
156 if (a->dist < b->dist)343 if (a->priv->dist < b->priv->dist)
157 return -1;344 return -1;
158345
159 return 0;346 return 0;
@@ -201,37 +388,8 @@
201 return db->locations;388 return db->locations;
202}389}
203390
204
205gchar *
206tz_location_get_country (TzLocation *loc)
207{
208 return loc->country;
209}
210
211
212gchar *
213tz_location_get_zone (TzLocation *loc)
214{
215 return loc->zone;
216}
217
218
219gchar *
220tz_location_get_comment (TzLocation *loc)
221{
222 return loc->comment;
223}
224
225
226void
227tz_location_get_position (TzLocation *loc, double *longitude, double *latitude)
228{
229 *longitude = loc->longitude;
230 *latitude = loc->latitude;
231}
232
233glong391glong
234tz_location_get_utc_offset (TzLocation *loc)392tz_location_get_utc_offset (CcTimezoneLocation *loc)
235{393{
236 TzInfo *tz_info;394 TzInfo *tz_info;
237 glong offset;395 glong offset;
@@ -243,7 +401,7 @@
243}401}
244402
245gint403gint
246tz_location_set_locally (TzLocation *loc)404tz_location_set_locally (CcTimezoneLocation *loc)
247{405{
248 time_t curtime;406 time_t curtime;
249 struct tm *curzone;407 struct tm *curzone;
@@ -251,13 +409,13 @@
251 gint correction = 0;409 gint correction = 0;
252410
253 g_return_val_if_fail (loc != NULL, 0);411 g_return_val_if_fail (loc != NULL, 0);
254 g_return_val_if_fail (loc->zone != NULL, 0);412 g_return_val_if_fail (loc->priv->zone != NULL, 0);
255 413
256 curtime = time (NULL);414 curtime = time (NULL);
257 curzone = localtime (&curtime);415 curzone = localtime (&curtime);
258 is_dst = curzone->tm_isdst;416 is_dst = curzone->tm_isdst;
259417
260 setenv ("TZ", loc->zone, 1);418 setenv ("TZ", loc->priv->zone, 1);
261#if 0419#if 0
262 curtime = time (NULL);420 curtime = time (NULL);
263 curzone = localtime (&curtime);421 curzone = localtime (&curtime);
@@ -274,16 +432,16 @@
274}432}
275433
276TzInfo *434TzInfo *
277tz_info_from_location (TzLocation *loc)435tz_info_from_location (CcTimezoneLocation *loc)
278{436{
279 TzInfo *tzinfo;437 TzInfo *tzinfo;
280 time_t curtime;438 time_t curtime;
281 struct tm *curzone;439 struct tm *curzone;
282 440
283 g_return_val_if_fail (loc != NULL, NULL);441 g_return_val_if_fail (loc != NULL, NULL);
284 g_return_val_if_fail (loc->zone != NULL, NULL);442 g_return_val_if_fail (loc->priv->zone != NULL, NULL);
285 443
286 setenv ("TZ", loc->zone, 1);444 setenv ("TZ", loc->priv->zone, 1);
287 445
288#if 0446#if 0
289 tzset ();447 tzset ();
@@ -361,33 +519,13 @@
361 else return t1 - t2/pow (10.0, strlen(fraction));519 else return t1 - t2/pow (10.0, strlen(fraction));
362}520}
363521
364
365#if 0
366
367/* Currently not working */
368static void
369free_tzdata (TzLocation *tz)
370{
371
372 if (tz->country)
373 g_free(tz->country);
374 if (tz->zone)
375 g_free(tz->zone);
376 if (tz->comment)
377 g_free(tz->comment);
378
379 g_free(tz);
380}
381#endif
382
383
384static int522static int
385compare_country_names (const void *a, const void *b)523compare_country_names (const void *a, const void *b)
386{524{
387 const TzLocation *tza = * (TzLocation **) a;525 const CcTimezoneLocation *tza = * (CcTimezoneLocation **) a;
388 const TzLocation *tzb = * (TzLocation **) b;526 const CcTimezoneLocation *tzb = * (CcTimezoneLocation **) b;
389 527
390 return strcmp (tza->zone, tzb->zone);528 return strcmp (tza->priv->zone, tzb->priv->zone);
391}529}
392530
393531
394532
=== modified file 'src/tz.h'
--- src/tz.h 2011-07-28 15:18:24 +0000
+++ src/tz.h 2011-08-02 08:06:15 +0000
@@ -27,6 +27,7 @@
27#define _E_TZ_H27#define _E_TZ_H
2828
29#include <glib.h>29#include <glib.h>
30#include <glib-object.h>
3031
31#ifndef __sun32#ifndef __sun
32# define TZ_DATA_FILE "/usr/share/zoneinfo/zone.tab"33# define TZ_DATA_FILE "/usr/share/zoneinfo/zone.tab"
@@ -34,9 +35,50 @@
34# define TZ_DATA_FILE "/usr/share/lib/zoneinfo/tab/zone_sun.tab"35# define TZ_DATA_FILE "/usr/share/lib/zoneinfo/tab/zone_sun.tab"
35#endif36#endif
3637
38G_BEGIN_DECLS
39
40#define CC_TYPE_TIMEZONE_LOCATION cc_timezone_location_get_type()
41
42#define CC_TIMEZONE_LOCATION(obj) \
43 (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
44 CC_TYPE_TIMEZONE_LOCATION, CcTimezoneLocation))
45
46#define CC_TIMEZONE_LOCATION_CLASS(klass) \
47 (G_TYPE_CHECK_CLASS_CAST ((klass), \
48 CC_TYPE_TIMEZONE_LOCATION, CcTimezoneLocationClass))
49
50#define CC_IS_TIMEZONE_LOCATION(obj) \
51 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
52 CC_TYPE_TIMEZONE_LOCATION))
53
54#define CC_IS_TIMEZONE_LOCATION_CLASS(klass) \
55 (G_TYPE_CHECK_CLASS_TYPE ((klass), \
56 CC_TYPE_TIMEZONE_LOCATION))
57
58#define CC_TIMEZONE_LOCATION_GET_CLASS(obj) \
59 (G_TYPE_INSTANCE_GET_CLASS ((obj), \
60 CC_TYPE_TIMEZONE_LOCATION, CcTimezoneLocationClass))
61
37typedef struct _TzDB TzDB;62typedef struct _TzDB TzDB;
38typedef struct _TzLocation TzLocation;
39typedef struct _TzInfo TzInfo;63typedef struct _TzInfo TzInfo;
64typedef struct _CcTimezoneLocation CcTimezoneLocation;
65typedef struct _CcTimezoneLocationClass CcTimezoneLocationClass;
66typedef struct _CcTimezoneLocationPrivate CcTimezoneLocationPrivate;
67
68struct _CcTimezoneLocation
69{
70 GObject parent;
71 CcTimezoneLocationPrivate *priv;
72};
73
74struct _CcTimezoneLocationClass
75{
76 GObjectClass parent_class;
77};
78
79GType cc_timezone_location_get_type (void) G_GNUC_CONST;
80
81CcTimezoneLocation *cc_timezone_location_new (void);
4082
4183
42struct _TzDB84struct _TzDB
@@ -44,16 +86,6 @@
44 GPtrArray *locations;86 GPtrArray *locations;
45};87};
4688
47struct _TzLocation
48{
49 gchar *country;
50 gdouble latitude;
51 gdouble longitude;
52 gchar *zone;
53 gchar *comment;
54
55 gdouble dist; /* distance to clicked point for comparison */
56};
5789
58/* see the glibc info page information on time zone information */90/* see the glibc info page information on time zone information */
59/* tzname_normal is the default name for the timezone */91/* tzname_normal is the default name for the timezone */
@@ -73,14 +105,11 @@
73TzDB *tz_load_db (void);105TzDB *tz_load_db (void);
74void tz_db_free (TzDB *db);106void tz_db_free (TzDB *db);
75GPtrArray *tz_get_locations (TzDB *db);107GPtrArray *tz_get_locations (TzDB *db);
76void tz_location_get_position (TzLocation *loc,108glong tz_location_get_utc_offset (CcTimezoneLocation *loc);
77 double *longitude, double *latitude);109gint tz_location_set_locally (CcTimezoneLocation *loc);
78char *tz_location_get_country (TzLocation *loc);110TzInfo *tz_info_from_location (CcTimezoneLocation *loc);
79gchar *tz_location_get_zone (TzLocation *loc);
80gchar *tz_location_get_comment (TzLocation *loc);
81glong tz_location_get_utc_offset (TzLocation *loc);
82gint tz_location_set_locally (TzLocation *loc);
83TzInfo *tz_info_from_location (TzLocation *loc);
84void tz_info_free (TzInfo *tz_info);111void tz_info_free (TzInfo *tz_info);
85112
113G_END_DECLS
114
86#endif115#endif

Subscribers

People subscribed via source and target branches

to all changes: