Merge lp:~ev/timezonemap/timezonelocation into lp:timezonemap
- timezonelocation
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Terry | Pending | ||
Review via email: mp+70122@code.launchpad.net |
Commit message
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
1 | === modified file 'src/cc-timezone-map.c' | |||
2 | --- src/cc-timezone-map.c 2011-07-29 09:01:38 +0000 | |||
3 | +++ src/cc-timezone-map.c 2011-08-02 08:06:15 +0000 | |||
4 | @@ -63,7 +63,7 @@ | |||
5 | 63 | gchar *watermark; | 63 | gchar *watermark; |
6 | 64 | 64 | ||
7 | 65 | TzDB *tzdb; | 65 | TzDB *tzdb; |
9 | 66 | TzLocation *location; | 66 | CcTimezoneLocation *location; |
10 | 67 | GHashTable *alias_db; | 67 | GHashTable *alias_db; |
11 | 68 | }; | 68 | }; |
12 | 69 | 69 | ||
13 | @@ -813,8 +813,16 @@ | |||
14 | 813 | g_clear_error (&err); | 813 | g_clear_error (&err); |
15 | 814 | } | 814 | } |
16 | 815 | 815 | ||
19 | 816 | pointx = convert_longtitude_to_x (priv->location->longitude, alloc.width); | 816 | GValue lat = {0}; |
20 | 817 | pointy = convert_latitude_to_y (priv->location->latitude, alloc.height); | 817 | GValue lon = {0}; |
21 | 818 | g_value_init (&lat, G_TYPE_DOUBLE); | ||
22 | 819 | g_value_init (&lon, G_TYPE_DOUBLE); | ||
23 | 820 | g_object_get_property(G_OBJECT (priv->location), "latitude", &lat); | ||
24 | 821 | g_object_get_property(G_OBJECT (priv->location), "longitude", &lon); | ||
25 | 822 | pointx = convert_longtitude_to_x (g_value_get_double(&lon), alloc.width); | ||
26 | 823 | pointy = convert_latitude_to_y (g_value_get_double(&lat), alloc.height); | ||
27 | 824 | g_value_unset (&lon); | ||
28 | 825 | g_value_unset (&lat); | ||
29 | 818 | 826 | ||
30 | 819 | if (pointy > alloc.height) | 827 | if (pointy > alloc.height) |
31 | 820 | pointy = alloc.height; | 828 | pointy = alloc.height; |
32 | @@ -854,20 +862,31 @@ | |||
33 | 854 | 0, | 862 | 0, |
34 | 855 | NULL, | 863 | NULL, |
35 | 856 | NULL, | 864 | NULL, |
37 | 857 | g_cclosure_marshal_VOID__POINTER, | 865 | g_cclosure_marshal_VOID__OBJECT, |
38 | 858 | G_TYPE_NONE, 1, | 866 | G_TYPE_NONE, 1, |
40 | 859 | G_TYPE_POINTER); | 867 | CC_TYPE_TIMEZONE_LOCATION); |
41 | 860 | } | 868 | } |
42 | 861 | 869 | ||
43 | 862 | 870 | ||
44 | 863 | static gint | 871 | static gint |
47 | 864 | sort_locations (TzLocation *a, | 872 | sort_locations (CcTimezoneLocation *a, |
48 | 865 | TzLocation *b) | 873 | CcTimezoneLocation *b) |
49 | 866 | { | 874 | { |
51 | 867 | if (a->dist > b->dist) | 875 | GValue val_a = {0}; |
52 | 876 | GValue val_b = {0}; | ||
53 | 877 | gdouble dist_a, dist_b; | ||
54 | 878 | g_value_init (&val_a, G_TYPE_DOUBLE); | ||
55 | 879 | g_value_init (&val_b, G_TYPE_DOUBLE); | ||
56 | 880 | g_object_get_property(G_OBJECT (a), "dist", &val_a); | ||
57 | 881 | g_object_get_property(G_OBJECT (b), "dist", &val_b); | ||
58 | 882 | dist_a = g_value_get_double(&val_a); | ||
59 | 883 | dist_b = g_value_get_double(&val_b); | ||
60 | 884 | g_value_unset (&val_a); | ||
61 | 885 | g_value_unset (&val_b); | ||
62 | 886 | if (dist_a > dist_b) | ||
63 | 868 | return 1; | 887 | return 1; |
64 | 869 | 888 | ||
66 | 870 | if (a->dist < b->dist) | 889 | if (dist_a < dist_b) |
67 | 871 | return -1; | 890 | return -1; |
68 | 872 | 891 | ||
69 | 873 | return 0; | 892 | return 0; |
70 | @@ -875,7 +894,7 @@ | |||
71 | 875 | 894 | ||
72 | 876 | static void | 895 | static void |
73 | 877 | set_location (CcTimezoneMap *map, | 896 | set_location (CcTimezoneMap *map, |
75 | 878 | TzLocation *location) | 897 | CcTimezoneLocation *location) |
76 | 879 | { | 898 | { |
77 | 880 | CcTimezoneMapPrivate *priv = map->priv; | 899 | CcTimezoneMapPrivate *priv = map->priv; |
78 | 881 | TzInfo *info; | 900 | TzInfo *info; |
79 | @@ -892,7 +911,7 @@ | |||
80 | 892 | tz_info_free (info); | 911 | tz_info_free (info); |
81 | 893 | } | 912 | } |
82 | 894 | 913 | ||
84 | 895 | static TzLocation * | 914 | static CcTimezoneLocation * |
85 | 896 | get_loc_for_xy (GtkWidget * widget, gint x, gint y) | 915 | get_loc_for_xy (GtkWidget * widget, gint x, gint y) |
86 | 897 | { | 916 | { |
87 | 898 | CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv; | 917 | CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv; |
88 | @@ -906,6 +925,13 @@ | |||
89 | 906 | GList *distances = NULL; | 925 | GList *distances = NULL; |
90 | 907 | GtkAllocation alloc; | 926 | GtkAllocation alloc; |
91 | 908 | 927 | ||
92 | 928 | GValue glon = {0}; | ||
93 | 929 | GValue glat = {0}; | ||
94 | 930 | GValue gdist = {0}; | ||
95 | 931 | g_value_init (&glon, G_TYPE_DOUBLE); | ||
96 | 932 | g_value_init (&glat, G_TYPE_DOUBLE); | ||
97 | 933 | g_value_init (&gdist, G_TYPE_DOUBLE); | ||
98 | 934 | |||
99 | 909 | rowstride = priv->visible_map_rowstride; | 935 | rowstride = priv->visible_map_rowstride; |
100 | 910 | pixels = priv->visible_map_pixels; | 936 | pixels = priv->visible_map_pixels; |
101 | 911 | 937 | ||
102 | @@ -937,22 +963,27 @@ | |||
103 | 937 | for (i = 0; i < array->len; i++) | 963 | for (i = 0; i < array->len; i++) |
104 | 938 | { | 964 | { |
105 | 939 | gdouble pointx, pointy, dx, dy; | 965 | gdouble pointx, pointy, dx, dy; |
107 | 940 | TzLocation *loc = array->pdata[i]; | 966 | CcTimezoneLocation *loc = array->pdata[i]; |
108 | 941 | 967 | ||
111 | 942 | pointx = convert_longtitude_to_x (loc->longitude, width); | 968 | g_object_get_property(G_OBJECT (loc), "longitude", &glon); |
112 | 943 | pointy = convert_latitude_to_y (loc->latitude, height); | 969 | g_object_get_property(G_OBJECT (loc), "latitude", &glat); |
113 | 970 | pointx = convert_longtitude_to_x (g_value_get_double(&glon), width); | ||
114 | 971 | pointy = convert_latitude_to_y (g_value_get_double(&glat), height); | ||
115 | 944 | 972 | ||
116 | 945 | dx = pointx - x; | 973 | dx = pointx - x; |
117 | 946 | dy = pointy - y; | 974 | dy = pointy - y; |
118 | 947 | 975 | ||
120 | 948 | loc->dist = dx * dx + dy * dy; | 976 | g_value_set_double(&gdist, (gdouble) dx * dx + dy * dy); |
121 | 977 | g_object_set_property(G_OBJECT (loc), "dist", &gdist); | ||
122 | 949 | distances = g_list_prepend (distances, loc); | 978 | distances = g_list_prepend (distances, loc); |
123 | 950 | |||
124 | 951 | } | 979 | } |
125 | 952 | distances = g_list_sort (distances, (GCompareFunc) sort_locations); | 980 | distances = g_list_sort (distances, (GCompareFunc) sort_locations); |
126 | 953 | 981 | ||
128 | 954 | TzLocation * loc = (TzLocation*) distances->data; | 982 | CcTimezoneLocation * loc = (CcTimezoneLocation*) distances->data; |
129 | 955 | 983 | ||
130 | 984 | g_value_unset (&glon); | ||
131 | 985 | g_value_unset (&glat); | ||
132 | 986 | g_value_unset (&gdist); | ||
133 | 956 | g_list_free (distances); | 987 | g_list_free (distances); |
134 | 957 | 988 | ||
135 | 958 | return loc; | 989 | return loc; |
136 | @@ -962,7 +993,7 @@ | |||
137 | 962 | button_press_event (GtkWidget *widget, | 993 | button_press_event (GtkWidget *widget, |
138 | 963 | GdkEventButton *event) | 994 | GdkEventButton *event) |
139 | 964 | { | 995 | { |
141 | 965 | TzLocation * loc = get_loc_for_xy (widget, event->x, event->y); | 996 | CcTimezoneLocation * loc = get_loc_for_xy (widget, event->x, event->y); |
142 | 966 | set_location (CC_TIMEZONE_MAP (widget), loc); | 997 | set_location (CC_TIMEZONE_MAP (widget), loc); |
143 | 967 | return TRUE; | 998 | return TRUE; |
144 | 968 | } | 999 | } |
145 | @@ -1087,6 +1118,8 @@ | |||
146 | 1087 | GPtrArray *locations; | 1118 | GPtrArray *locations; |
147 | 1088 | guint i; | 1119 | guint i; |
148 | 1089 | char *real_tz; | 1120 | char *real_tz; |
149 | 1121 | GValue zone = {0}; | ||
150 | 1122 | g_value_init (&zone, G_TYPE_STRING); | ||
151 | 1090 | 1123 | ||
152 | 1091 | real_tz = g_hash_table_lookup (map->priv->alias_db, timezone); | 1124 | real_tz = g_hash_table_lookup (map->priv->alias_db, timezone); |
153 | 1092 | 1125 | ||
154 | @@ -1094,9 +1127,10 @@ | |||
155 | 1094 | 1127 | ||
156 | 1095 | for (i = 0; i < locations->len; i++) | 1128 | for (i = 0; i < locations->len; i++) |
157 | 1096 | { | 1129 | { |
159 | 1097 | TzLocation *loc = locations->pdata[i]; | 1130 | CcTimezoneLocation *loc = locations->pdata[i]; |
160 | 1131 | g_object_get_property(G_OBJECT (loc), "zone", &zone); | ||
161 | 1098 | 1132 | ||
163 | 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)) |
164 | 1100 | { | 1134 | { |
165 | 1101 | set_location (map, loc); | 1135 | set_location (map, loc); |
166 | 1102 | break; | 1136 | break; |
167 | @@ -1104,6 +1138,7 @@ | |||
168 | 1104 | } | 1138 | } |
169 | 1105 | 1139 | ||
170 | 1106 | gtk_widget_queue_draw (GTK_WIDGET (map)); | 1140 | gtk_widget_queue_draw (GTK_WIDGET (map)); |
171 | 1141 | g_value_unset (&zone); | ||
172 | 1107 | } | 1142 | } |
173 | 1108 | 1143 | ||
174 | 1109 | void | 1144 | void |
175 | @@ -1132,11 +1167,14 @@ | |||
176 | 1132 | } | 1167 | } |
177 | 1133 | else { | 1168 | else { |
178 | 1134 | GtkAllocation alloc; | 1169 | GtkAllocation alloc; |
179 | 1170 | GValue val_zone = {0}; | ||
180 | 1171 | g_value_init (&val_zone, G_TYPE_STRING); | ||
181 | 1135 | gtk_widget_get_allocation (GTK_WIDGET (map), &alloc); | 1172 | gtk_widget_get_allocation (GTK_WIDGET (map), &alloc); |
182 | 1136 | x = convert_longtitude_to_x(lon, alloc.width); | 1173 | x = convert_longtitude_to_x(lon, alloc.width); |
183 | 1137 | y = convert_latitude_to_y(lat, alloc.height); | 1174 | y = convert_latitude_to_y(lat, alloc.height); |
186 | 1138 | TzLocation * loc = get_loc_for_xy(GTK_WIDGET (map), x, y); | 1175 | CcTimezoneLocation * loc = get_loc_for_xy(GTK_WIDGET (map), x, y); |
187 | 1139 | return loc->zone; | 1176 | g_value_unset (&val_zone); |
188 | 1177 | return g_value_get_string(&val_zone); | ||
189 | 1140 | } | 1178 | } |
190 | 1141 | } | 1179 | } |
191 | 1142 | 1180 | ||
192 | @@ -1150,7 +1188,7 @@ | |||
193 | 1150 | gtk_widget_queue_draw (GTK_WIDGET (map)); | 1188 | gtk_widget_queue_draw (GTK_WIDGET (map)); |
194 | 1151 | } | 1189 | } |
195 | 1152 | 1190 | ||
197 | 1153 | TzLocation * | 1191 | CcTimezoneLocation * |
198 | 1154 | cc_timezone_map_get_location (CcTimezoneMap *map) | 1192 | cc_timezone_map_get_location (CcTimezoneMap *map) |
199 | 1155 | { | 1193 | { |
200 | 1156 | return map->priv->location; | 1194 | return map->priv->location; |
201 | 1157 | 1195 | ||
202 | === modified file 'src/cc-timezone-map.h' | |||
203 | --- src/cc-timezone-map.h 2011-07-28 15:18:24 +0000 | |||
204 | +++ src/cc-timezone-map.h 2011-08-02 08:06:15 +0000 | |||
205 | @@ -78,7 +78,7 @@ | |||
206 | 78 | gdouble lon, gdouble lat); | 78 | gdouble lon, gdouble lat); |
207 | 79 | const gchar * cc_timezone_map_get_timezone_at_coords (CcTimezoneMap *map, | 79 | const gchar * cc_timezone_map_get_timezone_at_coords (CcTimezoneMap *map, |
208 | 80 | gdouble lon, gdouble lat); | 80 | gdouble lon, gdouble lat); |
210 | 81 | TzLocation * cc_timezone_map_get_location (CcTimezoneMap *map); | 81 | CcTimezoneLocation * cc_timezone_map_get_location (CcTimezoneMap *map); |
211 | 82 | 82 | ||
212 | 83 | G_END_DECLS | 83 | G_END_DECLS |
213 | 84 | 84 | ||
214 | 85 | 85 | ||
215 | === modified file 'src/test-timezone.c' | |||
216 | --- src/test-timezone.c 2011-07-28 15:28:24 +0000 | |||
217 | +++ src/test-timezone.c 2011-08-02 08:06:15 +0000 | |||
218 | @@ -22,14 +22,20 @@ | |||
219 | 22 | return 1; | 22 | return 1; |
220 | 23 | } | 23 | } |
221 | 24 | 24 | ||
222 | 25 | g_type_init(); | ||
223 | 26 | GValue zone = {0}; | ||
224 | 27 | g_value_init(&zone, G_TYPE_STRING); | ||
225 | 28 | |||
226 | 25 | db = tz_load_db (); | 29 | db = tz_load_db (); |
227 | 26 | locs = tz_get_locations (db); | 30 | locs = tz_get_locations (db); |
228 | 27 | for (i = 0; i < locs->len ; i++) { | 31 | for (i = 0; i < locs->len ; i++) { |
230 | 28 | TzLocation *loc = locs->pdata[i]; | 32 | CcTimezoneLocation *loc = locs->pdata[i]; |
231 | 33 | |||
232 | 29 | TzInfo *info; | 34 | TzInfo *info; |
233 | 30 | char *filename, *path; | 35 | char *filename, *path; |
234 | 31 | gdouble selected_offset; | 36 | gdouble selected_offset; |
236 | 32 | char buf[16]; | 37 | char buf[16]; |
237 | 38 | g_object_get_property(G_OBJECT (loc), "zone", &zone); | ||
238 | 33 | 39 | ||
239 | 34 | info = tz_info_from_location (loc); | 40 | info = tz_info_from_location (loc); |
240 | 35 | selected_offset = tz_location_get_utc_offset (loc) | 41 | selected_offset = tz_location_get_utc_offset (loc) |
241 | @@ -41,7 +47,7 @@ | |||
242 | 41 | path = g_build_filename (pixmap_dir, filename, NULL); | 47 | path = g_build_filename (pixmap_dir, filename, NULL); |
243 | 42 | 48 | ||
244 | 43 | if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE) { | 49 | if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE) { |
246 | 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)); |
247 | 45 | retval = 1; | 51 | retval = 1; |
248 | 46 | } | 52 | } |
249 | 47 | 53 | ||
250 | 48 | 54 | ||
251 | === modified file 'src/tz.c' | |||
252 | --- src/tz.c 2011-07-28 15:18:24 +0000 | |||
253 | +++ src/tz.c 2011-08-02 08:06:15 +0000 | |||
254 | @@ -30,6 +30,7 @@ | |||
255 | 30 | #include <time.h> | 30 | #include <time.h> |
256 | 31 | #include <math.h> | 31 | #include <math.h> |
257 | 32 | #include <string.h> | 32 | #include <string.h> |
258 | 33 | #include <float.h> | ||
259 | 33 | #include "tz.h" | 34 | #include "tz.h" |
260 | 34 | 35 | ||
261 | 35 | 36 | ||
262 | @@ -40,6 +41,202 @@ | |||
263 | 40 | static void sort_locations_by_country (GPtrArray *locations); | 41 | static void sort_locations_by_country (GPtrArray *locations); |
264 | 41 | static gchar * tz_data_file_get (void); | 42 | static gchar * tz_data_file_get (void); |
265 | 42 | 43 | ||
266 | 44 | G_DEFINE_TYPE (CcTimezoneLocation, cc_timezone_location, G_TYPE_OBJECT) | ||
267 | 45 | |||
268 | 46 | #define TIMEZONE_LOCATION_PRIVATE(o) \ | ||
269 | 47 | (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_TIMEZONE_LOCATION, CcTimezoneLocationPrivate)) | ||
270 | 48 | |||
271 | 49 | struct _CcTimezoneLocationPrivate | ||
272 | 50 | { | ||
273 | 51 | gchar *country; | ||
274 | 52 | gdouble latitude; | ||
275 | 53 | gdouble longitude; | ||
276 | 54 | gchar *zone; | ||
277 | 55 | gchar *comment; | ||
278 | 56 | |||
279 | 57 | gdouble dist; /* distance to clicked point for comparison */ | ||
280 | 58 | }; | ||
281 | 59 | |||
282 | 60 | enum { | ||
283 | 61 | PROP_0, | ||
284 | 62 | PROP_COUNTRY, | ||
285 | 63 | PROP_LATITUDE, | ||
286 | 64 | PROP_LONGITUDE, | ||
287 | 65 | PROP_ZONE, | ||
288 | 66 | PROP_COMMENT, | ||
289 | 67 | PROP_DIST | ||
290 | 68 | }; | ||
291 | 69 | |||
292 | 70 | static void | ||
293 | 71 | cc_timezone_location_get_property (GObject *object, | ||
294 | 72 | guint property_id, | ||
295 | 73 | GValue *value, | ||
296 | 74 | GParamSpec *pspec) | ||
297 | 75 | { | ||
298 | 76 | CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv; | ||
299 | 77 | switch (property_id) | ||
300 | 78 | { | ||
301 | 79 | case PROP_COUNTRY: | ||
302 | 80 | g_value_set_string (value, priv->country); | ||
303 | 81 | break; | ||
304 | 82 | case PROP_LATITUDE: | ||
305 | 83 | g_value_set_double (value, priv->latitude); | ||
306 | 84 | break; | ||
307 | 85 | case PROP_LONGITUDE: | ||
308 | 86 | g_value_set_double (value, priv->longitude); | ||
309 | 87 | break; | ||
310 | 88 | case PROP_ZONE: | ||
311 | 89 | g_value_set_string (value, priv->zone); | ||
312 | 90 | break; | ||
313 | 91 | case PROP_COMMENT: | ||
314 | 92 | g_value_set_string (value, priv->comment); | ||
315 | 93 | break; | ||
316 | 94 | case PROP_DIST: | ||
317 | 95 | g_value_set_double (value, priv->dist); | ||
318 | 96 | break; | ||
319 | 97 | default: | ||
320 | 98 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | ||
321 | 99 | } | ||
322 | 100 | } | ||
323 | 101 | |||
324 | 102 | static void | ||
325 | 103 | cc_timezone_location_set_property (GObject *object, | ||
326 | 104 | guint property_id, | ||
327 | 105 | const GValue *value, | ||
328 | 106 | GParamSpec *pspec) | ||
329 | 107 | { | ||
330 | 108 | CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv; | ||
331 | 109 | switch (property_id) | ||
332 | 110 | { | ||
333 | 111 | case PROP_COUNTRY: | ||
334 | 112 | priv->country = g_value_get_string(value); | ||
335 | 113 | break; | ||
336 | 114 | case PROP_LATITUDE: | ||
337 | 115 | priv->latitude = g_value_get_double(value); | ||
338 | 116 | break; | ||
339 | 117 | case PROP_LONGITUDE: | ||
340 | 118 | priv->longitude = g_value_get_double(value); | ||
341 | 119 | break; | ||
342 | 120 | case PROP_ZONE: | ||
343 | 121 | priv->zone = g_value_get_string(value); | ||
344 | 122 | break; | ||
345 | 123 | case PROP_COMMENT: | ||
346 | 124 | priv->comment = g_value_get_string(value); | ||
347 | 125 | break; | ||
348 | 126 | case PROP_DIST: | ||
349 | 127 | priv->dist = g_value_get_double(value); | ||
350 | 128 | break; | ||
351 | 129 | default: | ||
352 | 130 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); | ||
353 | 131 | } | ||
354 | 132 | } | ||
355 | 133 | |||
356 | 134 | static void | ||
357 | 135 | cc_timezone_location_dispose (GObject *object) | ||
358 | 136 | { | ||
359 | 137 | CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv; | ||
360 | 138 | |||
361 | 139 | if (priv->country) | ||
362 | 140 | { | ||
363 | 141 | g_object_unref (priv->country); | ||
364 | 142 | priv->country = NULL; | ||
365 | 143 | } | ||
366 | 144 | |||
367 | 145 | if (priv->zone) | ||
368 | 146 | { | ||
369 | 147 | g_object_unref (priv->zone); | ||
370 | 148 | priv->zone = NULL; | ||
371 | 149 | } | ||
372 | 150 | |||
373 | 151 | if (priv->comment) | ||
374 | 152 | { | ||
375 | 153 | g_object_unref (priv->comment); | ||
376 | 154 | priv->comment = NULL; | ||
377 | 155 | } | ||
378 | 156 | |||
379 | 157 | G_OBJECT_CLASS (cc_timezone_location_parent_class)->dispose (object); | ||
380 | 158 | } | ||
381 | 159 | |||
382 | 160 | static void | ||
383 | 161 | cc_timezone_location_finalize (GObject *object) | ||
384 | 162 | { | ||
385 | 163 | CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv; | ||
386 | 164 | G_OBJECT_CLASS (cc_timezone_location_parent_class)->finalize (object); | ||
387 | 165 | } | ||
388 | 166 | |||
389 | 167 | static void | ||
390 | 168 | cc_timezone_location_class_init (CcTimezoneLocationClass *klass) | ||
391 | 169 | { | ||
392 | 170 | GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||
393 | 171 | g_type_class_add_private (klass, sizeof (CcTimezoneLocationPrivate)); | ||
394 | 172 | |||
395 | 173 | object_class->get_property = cc_timezone_location_get_property; | ||
396 | 174 | object_class->set_property = cc_timezone_location_set_property; | ||
397 | 175 | object_class->dispose = cc_timezone_location_dispose; | ||
398 | 176 | object_class->finalize = cc_timezone_location_finalize; | ||
399 | 177 | |||
400 | 178 | g_object_class_install_property(object_class, | ||
401 | 179 | PROP_COUNTRY, | ||
402 | 180 | g_param_spec_string ("country", | ||
403 | 181 | "Country", | ||
404 | 182 | "The country for the location", | ||
405 | 183 | "", | ||
406 | 184 | G_PARAM_READWRITE)); | ||
407 | 185 | g_object_class_install_property(object_class, | ||
408 | 186 | PROP_LATITUDE, | ||
409 | 187 | g_param_spec_double ("latitude", | ||
410 | 188 | "Latitude", | ||
411 | 189 | "The latitude for the location", | ||
412 | 190 | -90.0, | ||
413 | 191 | 90.0, | ||
414 | 192 | 0.0, | ||
415 | 193 | G_PARAM_READWRITE)); | ||
416 | 194 | g_object_class_install_property(object_class, | ||
417 | 195 | PROP_LONGITUDE, | ||
418 | 196 | g_param_spec_double ("longitude", | ||
419 | 197 | "Longitude", | ||
420 | 198 | "The longitude for the location", | ||
421 | 199 | -180.0, | ||
422 | 200 | 180.0, | ||
423 | 201 | 0.0, | ||
424 | 202 | G_PARAM_READWRITE)); | ||
425 | 203 | g_object_class_install_property(object_class, | ||
426 | 204 | PROP_ZONE, | ||
427 | 205 | g_param_spec_string ("zone", | ||
428 | 206 | "Zone", | ||
429 | 207 | "The time zone for the location", | ||
430 | 208 | "", | ||
431 | 209 | G_PARAM_READWRITE)); | ||
432 | 210 | g_object_class_install_property(object_class, | ||
433 | 211 | PROP_COMMENT, | ||
434 | 212 | g_param_spec_string ("Comment", | ||
435 | 213 | "Comment", | ||
436 | 214 | "A comment for the location", | ||
437 | 215 | "", | ||
438 | 216 | G_PARAM_READWRITE)); | ||
439 | 217 | g_object_class_install_property(object_class, | ||
440 | 218 | PROP_DIST, | ||
441 | 219 | g_param_spec_double ("dist", | ||
442 | 220 | "Distance", | ||
443 | 221 | "The distance for the location", | ||
444 | 222 | 0.0, | ||
445 | 223 | DBL_MAX, | ||
446 | 224 | 0.0, | ||
447 | 225 | G_PARAM_READWRITE)); | ||
448 | 226 | } | ||
449 | 227 | |||
450 | 228 | static void | ||
451 | 229 | cc_timezone_location_init (CcTimezoneLocation *self) { | ||
452 | 230 | CcTimezoneLocationPrivate *priv; | ||
453 | 231 | priv = self->priv = TIMEZONE_LOCATION_PRIVATE (self); | ||
454 | 232 | } | ||
455 | 233 | |||
456 | 234 | CcTimezoneLocation * | ||
457 | 235 | cc_timezone_location_new (void) | ||
458 | 236 | { | ||
459 | 237 | return g_object_new (CC_TYPE_TIMEZONE_LOCATION, NULL); | ||
460 | 238 | } | ||
461 | 239 | |||
462 | 43 | 240 | ||
463 | 44 | /* ---------------- * | 241 | /* ---------------- * |
464 | 45 | * Public interface * | 242 | * Public interface * |
465 | @@ -71,7 +268,7 @@ | |||
466 | 71 | { | 268 | { |
467 | 72 | gchar **tmpstrarr; | 269 | gchar **tmpstrarr; |
468 | 73 | gchar *latstr, *lngstr, *p; | 270 | gchar *latstr, *lngstr, *p; |
470 | 74 | TzLocation *loc; | 271 | CcTimezoneLocation *loc; |
471 | 75 | 272 | ||
472 | 76 | if (*buf == '#') continue; | 273 | if (*buf == '#') continue; |
473 | 77 | 274 | ||
474 | @@ -84,21 +281,21 @@ | |||
475 | 84 | lngstr = g_strdup (p); | 281 | lngstr = g_strdup (p); |
476 | 85 | *p = '\0'; | 282 | *p = '\0'; |
477 | 86 | 283 | ||
483 | 87 | loc = g_new0 (TzLocation, 1); | 284 | loc = cc_timezone_location_new (); |
484 | 88 | loc->country = g_strdup (tmpstrarr[0]); | 285 | loc->priv->country = g_strdup (tmpstrarr[0]); |
485 | 89 | loc->zone = g_strdup (tmpstrarr[2]); | 286 | loc->priv->zone = g_strdup (tmpstrarr[2]); |
486 | 90 | loc->latitude = convert_pos (latstr, 2); | 287 | loc->priv->latitude = convert_pos (latstr, 2); |
487 | 91 | loc->longitude = convert_pos (lngstr, 3); | 288 | loc->priv->longitude = convert_pos (lngstr, 3); |
488 | 92 | 289 | ||
489 | 93 | #ifdef __sun | 290 | #ifdef __sun |
490 | 94 | if (tmpstrarr[3] && *tmpstrarr[3] == '-' && tmpstrarr[4]) | 291 | if (tmpstrarr[3] && *tmpstrarr[3] == '-' && tmpstrarr[4]) |
491 | 95 | loc->comment = g_strdup (tmpstrarr[4]); | 292 | loc->comment = g_strdup (tmpstrarr[4]); |
492 | 96 | 293 | ||
493 | 97 | if (tmpstrarr[3] && *tmpstrarr[3] != '-' && !islower(loc->zone)) { | 294 | if (tmpstrarr[3] && *tmpstrarr[3] != '-' && !islower(loc->zone)) { |
495 | 98 | TzLocation *locgrp; | 295 | CcTimezoneLocation *locgrp; |
496 | 99 | 296 | ||
497 | 100 | /* duplicate entry */ | 297 | /* duplicate entry */ |
499 | 101 | locgrp = g_new0 (TzLocation, 1); | 298 | locgrp = cc_timezone_location_new (); |
500 | 102 | locgrp->country = g_strdup (tmpstrarr[0]); | 299 | locgrp->country = g_strdup (tmpstrarr[0]); |
501 | 103 | locgrp->zone = g_strdup (tmpstrarr[3]); | 300 | locgrp->zone = g_strdup (tmpstrarr[3]); |
502 | 104 | locgrp->latitude = convert_pos (latstr, 2); | 301 | locgrp->latitude = convert_pos (latstr, 2); |
503 | @@ -108,7 +305,7 @@ | |||
504 | 108 | g_ptr_array_add (tz_db->locations, (gpointer) locgrp); | 305 | g_ptr_array_add (tz_db->locations, (gpointer) locgrp); |
505 | 109 | } | 306 | } |
506 | 110 | #else | 307 | #else |
508 | 111 | loc->comment = (tmpstrarr[3]) ? g_strdup(tmpstrarr[3]) : NULL; | 308 | loc->priv->comment = (tmpstrarr[3]) ? g_strdup(tmpstrarr[3]) : NULL; |
509 | 112 | #endif | 309 | #endif |
510 | 113 | 310 | ||
511 | 114 | g_ptr_array_add (tz_db->locations, (gpointer) loc); | 311 | g_ptr_array_add (tz_db->locations, (gpointer) loc); |
512 | @@ -128,32 +325,22 @@ | |||
513 | 128 | return tz_db; | 325 | return tz_db; |
514 | 129 | } | 326 | } |
515 | 130 | 327 | ||
516 | 131 | static void | ||
517 | 132 | tz_location_free (TzLocation *loc) | ||
518 | 133 | { | ||
519 | 134 | g_free (loc->country); | ||
520 | 135 | g_free (loc->zone); | ||
521 | 136 | g_free (loc->comment); | ||
522 | 137 | |||
523 | 138 | g_free (loc); | ||
524 | 139 | } | ||
525 | 140 | |||
526 | 141 | void | 328 | void |
527 | 142 | tz_db_free (TzDB *db) | 329 | tz_db_free (TzDB *db) |
528 | 143 | { | 330 | { |
530 | 144 | g_ptr_array_foreach (db->locations, (GFunc) tz_location_free, NULL); | 331 | g_ptr_array_foreach (db->locations, (GFunc) g_object_unref, NULL); |
531 | 145 | g_ptr_array_free (db->locations, TRUE); | 332 | g_ptr_array_free (db->locations, TRUE); |
532 | 146 | g_free (db); | 333 | g_free (db); |
533 | 147 | } | 334 | } |
534 | 148 | 335 | ||
535 | 149 | static gint | 336 | static gint |
538 | 150 | sort_locations (TzLocation *a, | 337 | sort_locations (CcTimezoneLocation *a, |
539 | 151 | TzLocation *b) | 338 | CcTimezoneLocation *b) |
540 | 152 | { | 339 | { |
542 | 153 | if (a->dist > b->dist) | 340 | if (a->priv->dist > b->priv->dist) |
543 | 154 | return 1; | 341 | return 1; |
544 | 155 | 342 | ||
546 | 156 | if (a->dist < b->dist) | 343 | if (a->priv->dist < b->priv->dist) |
547 | 157 | return -1; | 344 | return -1; |
548 | 158 | 345 | ||
549 | 159 | return 0; | 346 | return 0; |
550 | @@ -201,37 +388,8 @@ | |||
551 | 201 | return db->locations; | 388 | return db->locations; |
552 | 202 | } | 389 | } |
553 | 203 | 390 | ||
554 | 204 | |||
555 | 205 | gchar * | ||
556 | 206 | tz_location_get_country (TzLocation *loc) | ||
557 | 207 | { | ||
558 | 208 | return loc->country; | ||
559 | 209 | } | ||
560 | 210 | |||
561 | 211 | |||
562 | 212 | gchar * | ||
563 | 213 | tz_location_get_zone (TzLocation *loc) | ||
564 | 214 | { | ||
565 | 215 | return loc->zone; | ||
566 | 216 | } | ||
567 | 217 | |||
568 | 218 | |||
569 | 219 | gchar * | ||
570 | 220 | tz_location_get_comment (TzLocation *loc) | ||
571 | 221 | { | ||
572 | 222 | return loc->comment; | ||
573 | 223 | } | ||
574 | 224 | |||
575 | 225 | |||
576 | 226 | void | ||
577 | 227 | tz_location_get_position (TzLocation *loc, double *longitude, double *latitude) | ||
578 | 228 | { | ||
579 | 229 | *longitude = loc->longitude; | ||
580 | 230 | *latitude = loc->latitude; | ||
581 | 231 | } | ||
582 | 232 | |||
583 | 233 | glong | 391 | glong |
585 | 234 | tz_location_get_utc_offset (TzLocation *loc) | 392 | tz_location_get_utc_offset (CcTimezoneLocation *loc) |
586 | 235 | { | 393 | { |
587 | 236 | TzInfo *tz_info; | 394 | TzInfo *tz_info; |
588 | 237 | glong offset; | 395 | glong offset; |
589 | @@ -243,7 +401,7 @@ | |||
590 | 243 | } | 401 | } |
591 | 244 | 402 | ||
592 | 245 | gint | 403 | gint |
594 | 246 | tz_location_set_locally (TzLocation *loc) | 404 | tz_location_set_locally (CcTimezoneLocation *loc) |
595 | 247 | { | 405 | { |
596 | 248 | time_t curtime; | 406 | time_t curtime; |
597 | 249 | struct tm *curzone; | 407 | struct tm *curzone; |
598 | @@ -251,13 +409,13 @@ | |||
599 | 251 | gint correction = 0; | 409 | gint correction = 0; |
600 | 252 | 410 | ||
601 | 253 | g_return_val_if_fail (loc != NULL, 0); | 411 | g_return_val_if_fail (loc != NULL, 0); |
603 | 254 | g_return_val_if_fail (loc->zone != NULL, 0); | 412 | g_return_val_if_fail (loc->priv->zone != NULL, 0); |
604 | 255 | 413 | ||
605 | 256 | curtime = time (NULL); | 414 | curtime = time (NULL); |
606 | 257 | curzone = localtime (&curtime); | 415 | curzone = localtime (&curtime); |
607 | 258 | is_dst = curzone->tm_isdst; | 416 | is_dst = curzone->tm_isdst; |
608 | 259 | 417 | ||
610 | 260 | setenv ("TZ", loc->zone, 1); | 418 | setenv ("TZ", loc->priv->zone, 1); |
611 | 261 | #if 0 | 419 | #if 0 |
612 | 262 | curtime = time (NULL); | 420 | curtime = time (NULL); |
613 | 263 | curzone = localtime (&curtime); | 421 | curzone = localtime (&curtime); |
614 | @@ -274,16 +432,16 @@ | |||
615 | 274 | } | 432 | } |
616 | 275 | 433 | ||
617 | 276 | TzInfo * | 434 | TzInfo * |
619 | 277 | tz_info_from_location (TzLocation *loc) | 435 | tz_info_from_location (CcTimezoneLocation *loc) |
620 | 278 | { | 436 | { |
621 | 279 | TzInfo *tzinfo; | 437 | TzInfo *tzinfo; |
622 | 280 | time_t curtime; | 438 | time_t curtime; |
623 | 281 | struct tm *curzone; | 439 | struct tm *curzone; |
624 | 282 | 440 | ||
625 | 283 | g_return_val_if_fail (loc != NULL, NULL); | 441 | g_return_val_if_fail (loc != NULL, NULL); |
627 | 284 | g_return_val_if_fail (loc->zone != NULL, NULL); | 442 | g_return_val_if_fail (loc->priv->zone != NULL, NULL); |
628 | 285 | 443 | ||
630 | 286 | setenv ("TZ", loc->zone, 1); | 444 | setenv ("TZ", loc->priv->zone, 1); |
631 | 287 | 445 | ||
632 | 288 | #if 0 | 446 | #if 0 |
633 | 289 | tzset (); | 447 | tzset (); |
634 | @@ -361,33 +519,13 @@ | |||
635 | 361 | else return t1 - t2/pow (10.0, strlen(fraction)); | 519 | else return t1 - t2/pow (10.0, strlen(fraction)); |
636 | 362 | } | 520 | } |
637 | 363 | 521 | ||
638 | 364 | |||
639 | 365 | #if 0 | ||
640 | 366 | |||
641 | 367 | /* Currently not working */ | ||
642 | 368 | static void | ||
643 | 369 | free_tzdata (TzLocation *tz) | ||
644 | 370 | { | ||
645 | 371 | |||
646 | 372 | if (tz->country) | ||
647 | 373 | g_free(tz->country); | ||
648 | 374 | if (tz->zone) | ||
649 | 375 | g_free(tz->zone); | ||
650 | 376 | if (tz->comment) | ||
651 | 377 | g_free(tz->comment); | ||
652 | 378 | |||
653 | 379 | g_free(tz); | ||
654 | 380 | } | ||
655 | 381 | #endif | ||
656 | 382 | |||
657 | 383 | |||
658 | 384 | static int | 522 | static int |
659 | 385 | compare_country_names (const void *a, const void *b) | 523 | compare_country_names (const void *a, const void *b) |
660 | 386 | { | 524 | { |
663 | 387 | const TzLocation *tza = * (TzLocation **) a; | 525 | const CcTimezoneLocation *tza = * (CcTimezoneLocation **) a; |
664 | 388 | const TzLocation *tzb = * (TzLocation **) b; | 526 | const CcTimezoneLocation *tzb = * (CcTimezoneLocation **) b; |
665 | 389 | 527 | ||
667 | 390 | return strcmp (tza->zone, tzb->zone); | 528 | return strcmp (tza->priv->zone, tzb->priv->zone); |
668 | 391 | } | 529 | } |
669 | 392 | 530 | ||
670 | 393 | 531 | ||
671 | 394 | 532 | ||
672 | === modified file 'src/tz.h' | |||
673 | --- src/tz.h 2011-07-28 15:18:24 +0000 | |||
674 | +++ src/tz.h 2011-08-02 08:06:15 +0000 | |||
675 | @@ -27,6 +27,7 @@ | |||
676 | 27 | #define _E_TZ_H | 27 | #define _E_TZ_H |
677 | 28 | 28 | ||
678 | 29 | #include <glib.h> | 29 | #include <glib.h> |
679 | 30 | #include <glib-object.h> | ||
680 | 30 | 31 | ||
681 | 31 | #ifndef __sun | 32 | #ifndef __sun |
682 | 32 | # define TZ_DATA_FILE "/usr/share/zoneinfo/zone.tab" | 33 | # define TZ_DATA_FILE "/usr/share/zoneinfo/zone.tab" |
683 | @@ -34,9 +35,50 @@ | |||
684 | 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" |
685 | 35 | #endif | 36 | #endif |
686 | 36 | 37 | ||
687 | 38 | G_BEGIN_DECLS | ||
688 | 39 | |||
689 | 40 | #define CC_TYPE_TIMEZONE_LOCATION cc_timezone_location_get_type() | ||
690 | 41 | |||
691 | 42 | #define CC_TIMEZONE_LOCATION(obj) \ | ||
692 | 43 | (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ | ||
693 | 44 | CC_TYPE_TIMEZONE_LOCATION, CcTimezoneLocation)) | ||
694 | 45 | |||
695 | 46 | #define CC_TIMEZONE_LOCATION_CLASS(klass) \ | ||
696 | 47 | (G_TYPE_CHECK_CLASS_CAST ((klass), \ | ||
697 | 48 | CC_TYPE_TIMEZONE_LOCATION, CcTimezoneLocationClass)) | ||
698 | 49 | |||
699 | 50 | #define CC_IS_TIMEZONE_LOCATION(obj) \ | ||
700 | 51 | (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ | ||
701 | 52 | CC_TYPE_TIMEZONE_LOCATION)) | ||
702 | 53 | |||
703 | 54 | #define CC_IS_TIMEZONE_LOCATION_CLASS(klass) \ | ||
704 | 55 | (G_TYPE_CHECK_CLASS_TYPE ((klass), \ | ||
705 | 56 | CC_TYPE_TIMEZONE_LOCATION)) | ||
706 | 57 | |||
707 | 58 | #define CC_TIMEZONE_LOCATION_GET_CLASS(obj) \ | ||
708 | 59 | (G_TYPE_INSTANCE_GET_CLASS ((obj), \ | ||
709 | 60 | CC_TYPE_TIMEZONE_LOCATION, CcTimezoneLocationClass)) | ||
710 | 61 | |||
711 | 37 | typedef struct _TzDB TzDB; | 62 | typedef struct _TzDB TzDB; |
712 | 38 | typedef struct _TzLocation TzLocation; | ||
713 | 39 | typedef struct _TzInfo TzInfo; | 63 | typedef struct _TzInfo TzInfo; |
714 | 64 | typedef struct _CcTimezoneLocation CcTimezoneLocation; | ||
715 | 65 | typedef struct _CcTimezoneLocationClass CcTimezoneLocationClass; | ||
716 | 66 | typedef struct _CcTimezoneLocationPrivate CcTimezoneLocationPrivate; | ||
717 | 67 | |||
718 | 68 | struct _CcTimezoneLocation | ||
719 | 69 | { | ||
720 | 70 | GObject parent; | ||
721 | 71 | CcTimezoneLocationPrivate *priv; | ||
722 | 72 | }; | ||
723 | 73 | |||
724 | 74 | struct _CcTimezoneLocationClass | ||
725 | 75 | { | ||
726 | 76 | GObjectClass parent_class; | ||
727 | 77 | }; | ||
728 | 78 | |||
729 | 79 | GType cc_timezone_location_get_type (void) G_GNUC_CONST; | ||
730 | 80 | |||
731 | 81 | CcTimezoneLocation *cc_timezone_location_new (void); | ||
732 | 40 | 82 | ||
733 | 41 | 83 | ||
734 | 42 | struct _TzDB | 84 | struct _TzDB |
735 | @@ -44,16 +86,6 @@ | |||
736 | 44 | GPtrArray *locations; | 86 | GPtrArray *locations; |
737 | 45 | }; | 87 | }; |
738 | 46 | 88 | ||
739 | 47 | struct _TzLocation | ||
740 | 48 | { | ||
741 | 49 | gchar *country; | ||
742 | 50 | gdouble latitude; | ||
743 | 51 | gdouble longitude; | ||
744 | 52 | gchar *zone; | ||
745 | 53 | gchar *comment; | ||
746 | 54 | |||
747 | 55 | gdouble dist; /* distance to clicked point for comparison */ | ||
748 | 56 | }; | ||
749 | 57 | 89 | ||
750 | 58 | /* see the glibc info page information on time zone information */ | 90 | /* see the glibc info page information on time zone information */ |
751 | 59 | /* tzname_normal is the default name for the timezone */ | 91 | /* tzname_normal is the default name for the timezone */ |
752 | @@ -73,14 +105,11 @@ | |||
753 | 73 | TzDB *tz_load_db (void); | 105 | TzDB *tz_load_db (void); |
754 | 74 | void tz_db_free (TzDB *db); | 106 | void tz_db_free (TzDB *db); |
755 | 75 | GPtrArray *tz_get_locations (TzDB *db); | 107 | GPtrArray *tz_get_locations (TzDB *db); |
764 | 76 | void tz_location_get_position (TzLocation *loc, | 108 | glong tz_location_get_utc_offset (CcTimezoneLocation *loc); |
765 | 77 | double *longitude, double *latitude); | 109 | gint tz_location_set_locally (CcTimezoneLocation *loc); |
766 | 78 | char *tz_location_get_country (TzLocation *loc); | 110 | TzInfo *tz_info_from_location (CcTimezoneLocation *loc); |
759 | 79 | gchar *tz_location_get_zone (TzLocation *loc); | ||
760 | 80 | gchar *tz_location_get_comment (TzLocation *loc); | ||
761 | 81 | glong tz_location_get_utc_offset (TzLocation *loc); | ||
762 | 82 | gint tz_location_set_locally (TzLocation *loc); | ||
763 | 83 | TzInfo *tz_info_from_location (TzLocation *loc); | ||
767 | 84 | void tz_info_free (TzInfo *tz_info); | 111 | void tz_info_free (TzInfo *tz_info); |
768 | 85 | 112 | ||
769 | 113 | G_END_DECLS | ||
770 | 114 | |||
771 | 86 | #endif | 115 | #endif |