Merge lp:~laney/timezonemap/more-data-whitespace into lp:timezonemap

Proposed by Iain Lane
Status: Merged
Merged at revision: 32
Proposed branch: lp:~laney/timezonemap/more-data-whitespace
Merge into: lp:timezonemap
Prerequisite: lp:~laney/timezonemap/more-data
Diff against target: 1354 lines (+550/-488)
4 files modified
src/cc-timezone-map.c (+49/-48)
src/test-timezone.c (+52/-49)
src/timezone-completion.c (+326/-270)
src/tz.c (+123/-121)
To merge this branch: bzr merge lp:~laney/timezonemap/more-data-whitespace
Reviewer Review Type Date Requested Status
Dimitri John Ledkov Pending
Review via email: mp+193907@code.launchpad.net

Commit message

Make whitespace & indentation consistent

Description of the change

There's a mix of tabs and spaces, and indentation styles. Try to unify these.

Also wrap lines to 80 columns.

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 2012-11-06 17:14:04 +0000
+++ src/cc-timezone-map.c 2013-11-05 11:33:58 +0000
@@ -974,40 +974,41 @@
974 width = alloc.width;974 width = alloc.width;
975 height = alloc.height;975 height = alloc.height;
976976
977 if (x == priv->previous_x && y == priv->previous_y) {977 if (x == priv->previous_x && y == priv->previous_y)
978 priv->distances = g_list_next (priv->distances);978 {
979 location = (CcTimezoneLocation*) priv->distances->data;979 priv->distances = g_list_next (priv->distances);
980 } else {980 location = (CcTimezoneLocation*) priv->distances->data;
981 g_list_free (priv->distances);981 } else {
982 priv->distances = NULL;982 g_list_free (priv->distances);
983 for (i = 0; i < array->len; i++)983 priv->distances = NULL;
984 {984 for (i = 0; i < array->len; i++)
985 gdouble pointx, pointy, dx, dy;985 {
986 CcTimezoneLocation *loc = array->pdata[i];986 gdouble pointx, pointy, dx, dy;
987987 CcTimezoneLocation *loc = array->pdata[i];
988 g_object_get_property(G_OBJECT (loc), "longitude", &glon);988
989 g_object_get_property(G_OBJECT (loc), "latitude", &glat);989 g_object_get_property(G_OBJECT (loc), "longitude", &glon);
990 pointx = convert_longtitude_to_x (g_value_get_double(&glon), width);990 g_object_get_property(G_OBJECT (loc), "latitude", &glat);
991 pointy = convert_latitude_to_y (g_value_get_double(&glat), height);991 pointx = convert_longtitude_to_x (g_value_get_double(&glon), width);
992992 pointy = convert_latitude_to_y (g_value_get_double(&glat), height);
993 dx = pointx - x;993
994 dy = pointy - y;994 dx = pointx - x;
995995 dy = pointy - y;
996 g_value_set_double(&gdist, (gdouble) dx * dx + dy * dy);996
997 g_object_set_property(G_OBJECT (loc), "dist", &gdist);997 g_value_set_double(&gdist, (gdouble) dx * dx + dy * dy);
998 priv->distances = g_list_prepend (priv->distances, loc);998 g_object_set_property(G_OBJECT (loc), "dist", &gdist);
999 }999 priv->distances = g_list_prepend (priv->distances, loc);
1000 priv->distances = g_list_sort (priv->distances, (GCompareFunc) sort_locations);1000 }
1001 location = (CcTimezoneLocation*) priv->distances->data;1001 priv->distances = g_list_sort (priv->distances, (GCompareFunc) sort_locations);
1002 priv->previous_x = x;1002 location = (CcTimezoneLocation*) priv->distances->data;
1003 priv->previous_y = y;1003 priv->previous_x = x;
1004 }1004 priv->previous_y = y;
10051005 }
1006 g_value_unset (&glon);1006
1007 g_value_unset (&glat);1007 g_value_unset (&glon);
1008 g_value_unset (&gdist);1008 g_value_unset (&glat);
10091009 g_value_unset (&gdist);
1010 return location;1010
1011 return location;
1011}1012}
10121013
1013static gboolean1014static gboolean
@@ -1199,20 +1200,20 @@
1199 if (zone < G_N_ELEMENTS(olsen_map_timezones))1200 if (zone < G_N_ELEMENTS(olsen_map_timezones))
1200 city = olsen_map_timezones[zone];1201 city = olsen_map_timezones[zone];
12011202
1202 if (city != NULL) {1203 if (city != NULL)
1203 return city;1204 {
1204 }1205 return city;
1205 else {1206 } else {
1206 GtkAllocation alloc;1207 GtkAllocation alloc;
1207 GValue val_zone = {0};1208 GValue val_zone = {0};
1208 g_value_init (&val_zone, G_TYPE_STRING);1209 g_value_init (&val_zone, G_TYPE_STRING);
1209 gtk_widget_get_allocation (GTK_WIDGET (map), &alloc);1210 gtk_widget_get_allocation (GTK_WIDGET (map), &alloc);
1210 x = convert_longtitude_to_x(lon, alloc.width);1211 x = convert_longtitude_to_x(lon, alloc.width);
1211 y = convert_latitude_to_y(lat, alloc.height);1212 y = convert_latitude_to_y(lat, alloc.height);
1212 CcTimezoneLocation * loc = get_loc_for_xy(GTK_WIDGET (map), x, y);1213 CcTimezoneLocation * loc = get_loc_for_xy(GTK_WIDGET (map), x, y);
1213 g_value_unset (&val_zone);1214 g_value_unset (&val_zone);
1214 return g_value_get_string(&val_zone);1215 return g_value_get_string(&val_zone);
1215 }1216 }
1216}1217}
12171218
1218void1219void
12191220
=== modified file 'src/test-timezone.c'
--- src/test-timezone.c 2011-08-01 16:37:54 +0000
+++ src/test-timezone.c 2013-11-05 11:33:58 +0000
@@ -5,58 +5,61 @@
55
6int main (int argc, char **argv)6int main (int argc, char **argv)
7{7{
8 TzDB *db;8 TzDB *db;
9 GPtrArray *locs;9 GPtrArray *locs;
10 guint i;10 guint i;
11 char *pixmap_dir;11 char *pixmap_dir;
12 int retval = 0;12 int retval = 0;
1313
14 setlocale (LC_ALL, "");14 setlocale (LC_ALL, "");
1515
16 if (argc == 2) {16 if (argc == 2)
17 pixmap_dir = g_strdup (argv[1]);17 {
18 } else if (argc == 1) {18 pixmap_dir = g_strdup (argv[1]);
19 pixmap_dir = g_strdup ("data/");19 } else if (argc == 1) {
20 } else {20 pixmap_dir = g_strdup ("data/");
21 g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]);21 } else {
22 return 1;22 g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]);
23 }23 return 1;
2424 }
25 g_type_init();25
26 GValue zone = {0};26 g_type_init();
27 g_value_init(&zone, G_TYPE_STRING);27 GValue zone = {0};
2828 g_value_init(&zone, G_TYPE_STRING);
29 db = tz_load_db ();29
30 locs = tz_get_locations (db);30 db = tz_load_db ();
31 for (i = 0; i < locs->len ; i++) {31 locs = tz_get_locations (db);
32 CcTimezoneLocation *loc = locs->pdata[i];32 for (i = 0; i < locs->len ; i++)
3333 {
34 TzInfo *info;34 CcTimezoneLocation *loc = locs->pdata[i];
35 char *filename, *path;35
36 gdouble selected_offset;36 TzInfo *info;
37 char buf[16];37 char *filename, *path;
38 g_object_get_property(G_OBJECT (loc), "zone", &zone);38 gdouble selected_offset;
3939 char buf[16];
40 info = tz_info_from_location (loc);40 g_object_get_property(G_OBJECT (loc), "zone", &zone);
41 selected_offset = tz_location_get_utc_offset (loc)41
42 / (60.0*60.0) + ((info->daylight) ? -1.0 : 0.0);42 info = tz_info_from_location (loc);
4343 selected_offset = tz_location_get_utc_offset (loc)
44 filename = g_strdup_printf ("timezone_%s.png",44 / (60.0*60.0) + ((info->daylight) ? -1.0 : 0.0);
45
46 filename = g_strdup_printf ("timezone_%s.png",
45 g_ascii_formatd (buf, sizeof (buf),47 g_ascii_formatd (buf, sizeof (buf),
46 "%g", selected_offset));48 "%g", selected_offset));
47 path = g_build_filename (pixmap_dir, filename, NULL);49 path = g_build_filename (pixmap_dir, filename, NULL);
4850
49 if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE) {51 if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE)
50 g_message ("File '%s' missing for zone '%s'", filename, g_value_get_string(&zone));52 {
51 retval = 1;53 g_message ("File '%s' missing for zone '%s'", filename, g_value_get_string(&zone));
52 }54 retval = 1;
5355 }
54 g_free (filename);56
55 g_free (path);57 g_free (filename);
56 tz_info_free (info);58 g_free (path);
57 }59 tz_info_free (info);
58 tz_db_free (db);60 }
59 g_free (pixmap_dir);61 tz_db_free (db);
6062 g_free (pixmap_dir);
61 return retval;63
64 return retval;
62}65}
6366
=== modified file 'src/timezone-completion.c'
--- src/timezone-completion.c 2012-11-06 17:14:04 +0000
+++ src/timezone-completion.c 2013-11-05 11:33:58 +0000
@@ -138,13 +138,14 @@
138 g_cancellable_reset (priv->cancel);138 g_cancellable_reset (priv->cancel);
139 }139 }
140140
141 if (error != NULL) {141 if (error != NULL)
142 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))142 {
143 save_and_use_model (completion, priv->initial_model);143 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
144 g_warning ("Could not parse geoname JSON data: %s", error->message);144 save_and_use_model (completion, priv->initial_model);
145 g_error_free (error);145 g_warning ("Could not parse geoname JSON data: %s", error->message);
146 return;146 g_error_free (error);
147 }147 return;
148 }
148149
149 GtkListStore * store = gtk_list_store_new (CC_TIMEZONE_COMPLETION_LAST,150 GtkListStore * store = gtk_list_store_new (CC_TIMEZONE_COMPLETION_LAST,
150 G_TYPE_STRING,151 G_TYPE_STRING,
@@ -156,73 +157,85 @@
156157
157 JsonReader * reader = json_reader_new (json_parser_get_root (JSON_PARSER (object)));158 JsonReader * reader = json_reader_new (json_parser_get_root (JSON_PARSER (object)));
158159
159 if (!json_reader_is_array (reader)) {160 if (!json_reader_is_array (reader))
160 g_warning ("Could not parse geoname JSON data");161 {
161 save_and_use_model (completion, priv->initial_model);162 g_warning ("Could not parse geoname JSON data");
162 g_object_unref (G_OBJECT (reader));163 save_and_use_model (completion, priv->initial_model);
163 return;164 g_object_unref (G_OBJECT (reader));
164 }165 return;
166 }
165167
166 gint i, count = json_reader_count_elements (reader);168 gint i, count = json_reader_count_elements (reader);
167 for (i = 0; i < count; ++i) {169 for (i = 0; i < count; ++i)
168 if (!json_reader_read_element (reader, i))170 {
169 continue;171 if (!json_reader_read_element (reader, i))
172 continue;
170173
171 if (json_reader_is_object (reader)) {174 if (json_reader_is_object (reader))
172 const gchar * name = NULL;175 {
173 const gchar * admin1 = NULL;176 const gchar * name = NULL;
174 const gchar * country = NULL;177 const gchar * admin1 = NULL;
175 const gchar * longitude = NULL;178 const gchar * country = NULL;
176 const gchar * latitude = NULL;179 const gchar * longitude = NULL;
177 gboolean skip = FALSE;180 const gchar * latitude = NULL;
178 if (json_reader_read_member (reader, "name")) {181 gboolean skip = FALSE;
179 name = json_reader_get_string_value (reader);182 if (json_reader_read_member (reader, "name"))
180 json_reader_end_member (reader);183 {
181 }184 name = json_reader_get_string_value (reader);
182 if (json_reader_read_member (reader, "admin1")) {185 json_reader_end_member (reader);
183 admin1 = json_reader_get_string_value (reader);186 }
184 json_reader_end_member (reader);187 if (json_reader_read_member (reader, "admin1"))
185 }188 {
186 if (json_reader_read_member (reader, "country")) {189 admin1 = json_reader_get_string_value (reader);
187 country = json_reader_get_string_value (reader);190 json_reader_end_member (reader);
188 json_reader_end_member (reader);191 }
189 }192 if (json_reader_read_member (reader, "country"))
190 if (json_reader_read_member (reader, "longitude")) {193 {
191 longitude = json_reader_get_string_value (reader);194 country = json_reader_get_string_value (reader);
192 json_reader_end_member (reader);195 json_reader_end_member (reader);
193 }196 }
194 if (json_reader_read_member (reader, "latitude")) {197 if (json_reader_read_member (reader, "longitude"))
195 latitude = json_reader_get_string_value (reader);198 {
196 json_reader_end_member (reader);199 longitude = json_reader_get_string_value (reader);
197 }200 json_reader_end_member (reader);
201 }
202 if (json_reader_read_member (reader, "latitude"))
203 {
204 latitude = json_reader_get_string_value (reader);
205 json_reader_end_member (reader);
206 }
198207
199 if (g_strcmp0(name, prev_name) == 0 &&208 if (g_strcmp0(name, prev_name) == 0 &&
200 g_strcmp0(admin1, prev_admin1) == 0 &&209 g_strcmp0(admin1, prev_admin1) == 0 &&
201 g_strcmp0(country, prev_country) == 0) {210 g_strcmp0(country, prev_country) == 0)
202 // Sometimes the data will have duplicate entries that only differ211 {
203 // in longitude and latitude. e.g. "rio de janeiro", "wellington"212 // Sometimes the data will have duplicate entries that only differ
204 skip = TRUE;213 // in longitude and latitude. e.g. "rio de janeiro", "wellington"
205 }214 skip = TRUE;
215 }
206216
207 if (!skip) {217 if (!skip)
208 GtkTreeIter iter;218 {
209 gtk_list_store_append (store, &iter);219 GtkTreeIter iter;
210 gtk_list_store_set (store, &iter,220 gtk_list_store_append (store, &iter);
211 CC_TIMEZONE_COMPLETION_ZONE, NULL,221 gtk_list_store_set (store, &iter,
212 CC_TIMEZONE_COMPLETION_NAME, name,222 CC_TIMEZONE_COMPLETION_ZONE, NULL,
213 CC_TIMEZONE_COMPLETION_ADMIN1, admin1,223 CC_TIMEZONE_COMPLETION_NAME, name,
214 CC_TIMEZONE_COMPLETION_COUNTRY, country,224 CC_TIMEZONE_COMPLETION_ADMIN1, admin1,
215 CC_TIMEZONE_COMPLETION_LONGITUDE, longitude,225 CC_TIMEZONE_COMPLETION_COUNTRY, country,
216 CC_TIMEZONE_COMPLETION_LATITUDE, latitude,226 CC_TIMEZONE_COMPLETION_LONGITUDE, longitude,
217 -1);227 CC_TIMEZONE_COMPLETION_LATITUDE, latitude,
218 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),228 -1);
219 CC_TIMEZONE_COMPLETION_NAME, sort_zone,229 gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store),
220 g_utf8_casefold(priv->request_text, -1),230 CC_TIMEZONE_COMPLETION_NAME,
221 g_free);231 sort_zone,
222 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),232 g_utf8_casefold(priv->request_text,
223 CC_TIMEZONE_COMPLETION_NAME,233 -1),
224 GTK_SORT_ASCENDING);234 g_free);
225 }235 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store),
236 CC_TIMEZONE_COMPLETION_NAME,
237 GTK_SORT_ASCENDING);
238 }
226239
227 prev_name = name;240 prev_name = name;
228 prev_admin1 = admin1;241 prev_admin1 = admin1;
@@ -232,19 +245,21 @@
232 json_reader_end_element (reader);245 json_reader_end_element (reader);
233 }246 }
234247
235 if (strlen (priv->request_text) < 4) {248 if (strlen (priv->request_text) < 4)
236 gchar * lower_text = g_ascii_strdown (priv->request_text, -1);249 {
237 if (g_strcmp0 (lower_text, "ut") == 0 ||250 gchar * lower_text = g_ascii_strdown (priv->request_text, -1);
238 g_strcmp0 (lower_text, "utc") == 0) {251 if (g_strcmp0 (lower_text, "ut") == 0 ||
239 GtkTreeIter iter;252 g_strcmp0 (lower_text, "utc") == 0)
240 gtk_list_store_append (store, &iter);253 {
241 gtk_list_store_set (store, &iter,254 GtkTreeIter iter;
242 CC_TIMEZONE_COMPLETION_ZONE, "UTC",255 gtk_list_store_append (store, &iter);
243 CC_TIMEZONE_COMPLETION_NAME, "UTC",256 gtk_list_store_set (store, &iter,
244 -1);257 CC_TIMEZONE_COMPLETION_ZONE, "UTC",
258 CC_TIMEZONE_COMPLETION_NAME, "UTC",
259 -1);
260 }
261 g_free (lower_text);
245 }262 }
246 g_free (lower_text);
247 }
248263
249 save_and_use_model (completion, GTK_TREE_MODEL (store));264 save_and_use_model (completion, GTK_TREE_MODEL (store));
250 g_object_unref (G_OBJECT (reader));265 g_object_unref (G_OBJECT (reader));
@@ -260,17 +275,20 @@
260275
261 stream = g_file_read_finish (G_FILE (object), res, &error);276 stream = g_file_read_finish (G_FILE (object), res, &error);
262277
263 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && priv->cancel) {278 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && priv->cancel)
264 g_cancellable_reset (priv->cancel);279 {
265 }280 g_cancellable_reset (priv->cancel);
281 }
266282
267 if (error != NULL) {283 if (error != NULL)
268 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))284 {
269 save_and_use_model (completion, priv->initial_model);285 if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
270 g_warning ("Could not connect to geoname lookup server: %s", error->message);286 save_and_use_model (completion, priv->initial_model);
271 g_error_free (error);287 g_warning ("Could not connect to geoname lookup server: %s",
272 return;288 error->message);
273 }289 g_error_free (error);
290 return;
291 }
274292
275 JsonParser * parser = json_parser_new ();293 JsonParser * parser = json_parser_new ();
276 json_parser_load_from_stream_async (parser, G_INPUT_STREAM (stream), priv->cancel,294 json_parser_load_from_stream_async (parser, G_INPUT_STREAM (stream), priv->cancel,
@@ -286,11 +304,12 @@
286 const gchar *env = NULL;304 const gchar *env = NULL;
287 gint i;305 gint i;
288306
289 for (i = 0; env_names[i]; i++) {307 for (i = 0; env_names[i]; i++)
290 env = g_getenv (env_names[i]);308 {
291 if (env != NULL && env[0] != 0)309 env = g_getenv (env_names[i]);
292 break;310 if (env != NULL && env[0] != 0)
293 }311 break;
312 }
294313
295 if (env == NULL)314 if (env == NULL)
296 return NULL;315 return NULL;
@@ -301,10 +320,11 @@
301 if (split == NULL)320 if (split == NULL)
302 return NULL;321 return NULL;
303322
304 if (split[0] == NULL) {323 if (split[0] == NULL)
305 g_strfreev (split);324 {
306 return NULL;325 g_strfreev (split);
307 }326 return NULL;
327 }
308328
309 gchar *locale = g_strdup (split[0]);329 gchar *locale = g_strdup (split[0]);
310 g_strfreev (split);330 g_strfreev (split);
@@ -316,15 +336,16 @@
316{336{
317 static gchar *version = NULL;337 static gchar *version = NULL;
318338
319 if (version == NULL) {339 if (version == NULL)
320 gchar *stdout = NULL;340 {
321 g_spawn_command_line_sync ("lsb_release -rs", &stdout, NULL, NULL, NULL);341 gchar *stdout = NULL;
342 g_spawn_command_line_sync ("lsb_release -rs", &stdout, NULL, NULL, NULL);
322343
323 if (stdout != NULL)344 if (stdout != NULL)
324 version = g_strstrip (stdout);345 version = g_strstrip (stdout);
325 else346 else
326 version = g_strdup("");347 version = g_strdup("");
327 }348 }
328349
329 return version;350 return version;
330}351}
@@ -336,15 +357,17 @@
336357
337 priv->queued_request = 0;358 priv->queued_request = 0;
338359
339 if (priv->entry == NULL) {360 if (priv->entry == NULL)
340 return FALSE;361 {
341 }362 return FALSE;
363 }
342364
343 /* Cancel any ongoing request */365 /* Cancel any ongoing request */
344 if (priv->cancel) {366 if (priv->cancel)
345 g_cancellable_cancel (priv->cancel);367 {
346 g_cancellable_reset (priv->cancel);368 g_cancellable_cancel (priv->cancel);
347 }369 g_cancellable_reset (priv->cancel);
370 }
348 g_free (priv->request_text);371 g_free (priv->request_text);
349372
350 const gchar * text = gtk_entry_get_text (priv->entry);373 const gchar * text = gtk_entry_get_text (priv->entry);
@@ -371,21 +394,26 @@
371{394{
372 CcTimezoneCompletionPrivate * priv = completion->priv;395 CcTimezoneCompletionPrivate * priv = completion->priv;
373396
374 if (priv->queued_request) {397 if (priv->queued_request)
375 g_source_remove (priv->queued_request);398 {
376 priv->queued_request = 0;399 g_source_remove (priv->queued_request);
377 }400 priv->queued_request = 0;
401 }
378402
379 /* See if we've already got this one */403 /* See if we've already got this one */
380 const gchar * text = gtk_entry_get_text (priv->entry);404 const gchar * text = gtk_entry_get_text (priv->entry);
381 gpointer data;405 gpointer data;
382 if (g_hash_table_lookup_extended (priv->request_table, text, NULL, &data)) {406 if (g_hash_table_lookup_extended (priv->request_table, text, NULL, &data))
383 gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion), GTK_TREE_MODEL (data));407 {
384 }408 gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion),
385 else {409 GTK_TREE_MODEL (data));
386 priv->queued_request = g_timeout_add (300, (GSourceFunc)request_zones, completion);410 }
387 gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion), NULL);411 else
388 }412 {
413 priv->queued_request = g_timeout_add (300, (GSourceFunc)request_zones,
414 completion);
415 gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion), NULL);
416 }
389 gtk_entry_completion_complete (GTK_ENTRY_COMPLETION (completion));417 gtk_entry_completion_complete (GTK_ENTRY_COMPLETION (completion));
390}418}
391419
@@ -395,18 +423,21 @@
395 if (g_type_is_a (G_OBJECT_TYPE (parent), type))423 if (g_type_is_a (G_OBJECT_TYPE (parent), type))
396 return parent;424 return parent;
397425
398 if (GTK_IS_CONTAINER (parent)) {426 if (GTK_IS_CONTAINER (parent))
399 GList * children = gtk_container_get_children (GTK_CONTAINER (parent));427 {
400 GList * iter;428 GList * children = gtk_container_get_children (GTK_CONTAINER (parent));
401 for (iter = children; iter; iter = iter->next) {429 GList * iter;
402 GtkWidget * found = get_descendent (GTK_WIDGET (iter->data), type);430 for (iter = children; iter; iter = iter->next)
403 if (found) {431 {
404 g_list_free (children);432 GtkWidget * found = get_descendent (GTK_WIDGET (iter->data), type);
405 return found;433 if (found)
406 }434 {
435 g_list_free (children);
436 return found;
437 }
438 }
439 g_list_free (children);
407 }440 }
408 g_list_free (children);
409 }
410441
411 return NULL;442 return NULL;
412}443}
@@ -429,20 +460,26 @@
429 GtkWindowGroup * group = gtk_window_get_group (GTK_WINDOW (toplevel)); 460 GtkWindowGroup * group = gtk_window_get_group (GTK_WINDOW (toplevel));
430 GList * windows = gtk_window_group_list_windows (group);461 GList * windows = gtk_window_group_list_windows (group);
431 GList * iter;462 GList * iter;
432 for (iter = windows; iter; iter = iter->next) {463 for (iter = windows; iter; iter = iter->next)
433 if (iter->data == toplevel)464 {
434 continue; // Skip our own window, we don't have it465 if (iter->data == toplevel)
435 GtkWidget * view = get_descendent (GTK_WIDGET (iter->data), GTK_TYPE_TREE_VIEW);466 continue; // Skip our own window, we don't have it
436 if (view != NULL) {467 GtkWidget * view = get_descendent (GTK_WIDGET (iter->data),
437 GtkTreeModel * tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));468 GTK_TYPE_TREE_VIEW);
438 if (GTK_IS_TREE_MODEL_FILTER (tree_model))469 if (view != NULL)
439 tree_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (tree_model));470 {
440 if (tree_model == model) {471 GtkTreeModel * tree_model =
441 g_list_free (windows);472 gtk_tree_view_get_model (GTK_TREE_VIEW (view));
442 return GTK_TREE_VIEW (view);473 if (GTK_IS_TREE_MODEL_FILTER (tree_model))
443 }474 tree_model = gtk_tree_model_filter_get_model (
475 GTK_TREE_MODEL_FILTER (tree_model));
476 if (tree_model == model)
477 {
478 g_list_free (windows);
479 return GTK_TREE_VIEW (view);
480 }
481 }
444 }482 }
445 }
446 g_list_free (windows);483 g_list_free (windows);
447484
448 return NULL;485 return NULL;
@@ -453,26 +490,30 @@
453{490{
454 if (event->keyval == GDK_KEY_ISO_Enter ||491 if (event->keyval == GDK_KEY_ISO_Enter ||
455 event->keyval == GDK_KEY_KP_Enter ||492 event->keyval == GDK_KEY_KP_Enter ||
456 event->keyval == GDK_KEY_Return) {493 event->keyval == GDK_KEY_Return)
457 /* Make sure that user has a selection to choose, otherwise ignore */494 {
458 GtkTreeModel * model = gtk_entry_completion_get_model (GTK_ENTRY_COMPLETION (completion));495 /* Make sure that user has a selection to choose, otherwise ignore */
459 GtkTreeView * view = find_popup_treeview (GTK_WIDGET (entry), model);496 GtkTreeModel * model = gtk_entry_completion_get_model (
460 if (view == NULL) {497 GTK_ENTRY_COMPLETION (completion));
461 // Just beep if popup hasn't appeared yet.498 GtkTreeView * view = find_popup_treeview (GTK_WIDGET (entry), model);
462 gtk_widget_error_bell (GTK_WIDGET (entry));499 if (view == NULL)
463 return TRUE;500 {
464 }501 // Just beep if popup hasn't appeared yet.
502 gtk_widget_error_bell (GTK_WIDGET (entry));
503 return TRUE;
504 }
465505
466 GtkTreeSelection * sel = gtk_tree_view_get_selection (view);506 GtkTreeSelection * sel = gtk_tree_view_get_selection (view);
467 GtkTreeModel * sel_model = NULL;507 GtkTreeModel * sel_model = NULL;
468 if (!gtk_tree_selection_get_selected (sel, &sel_model, NULL)) {508 if (!gtk_tree_selection_get_selected (sel, &sel_model, NULL))
469 // No selection, we should help them out and select first item in list509 {
470 GtkTreeIter iter;510 // No selection, we should help them out and select first item in list
471 if (gtk_tree_model_get_iter_first (sel_model, &iter))511 GtkTreeIter iter;
472 gtk_tree_selection_select_iter (sel, &iter);512 if (gtk_tree_model_get_iter_first (sel_model, &iter))
473 // And fall through to normal handler code513 gtk_tree_selection_select_iter (sel, &iter);
514 // And fall through to normal handler code
515 }
474 }516 }
475 }
476517
477 return FALSE;518 return FALSE;
478}519}
@@ -482,32 +523,37 @@
482{523{
483 CcTimezoneCompletionPrivate * priv = completion->priv;524 CcTimezoneCompletionPrivate * priv = completion->priv;
484525
485 if (priv->queued_request) {526 if (priv->queued_request)
486 g_source_remove (priv->queued_request);527 {
487 priv->queued_request = 0;528 g_source_remove (priv->queued_request);
488 }529 priv->queued_request = 0;
489 if (priv->entry) {530 }
490 g_signal_handler_disconnect (priv->entry, priv->changed_id);531 if (priv->entry)
491 priv->changed_id = 0;532 {
492 g_signal_handler_disconnect (priv->entry, priv->keypress_id);533 g_signal_handler_disconnect (priv->entry, priv->changed_id);
493 priv->keypress_id = 0;534 priv->changed_id = 0;
494 g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *)&priv->entry);535 g_signal_handler_disconnect (priv->entry, priv->keypress_id);
495 gtk_entry_set_completion (priv->entry, NULL);536 priv->keypress_id = 0;
496 }537 g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *)&priv->entry);
538 gtk_entry_set_completion (priv->entry, NULL);
539 }
497540
498 priv->entry = entry;541 priv->entry = entry;
499542
500 if (entry) {543 if (entry)
501 guint id = g_signal_connect (entry, "changed", G_CALLBACK (entry_changed), completion);544 {
502 priv->changed_id = id;545 guint id = g_signal_connect (entry, "changed",
503546 G_CALLBACK (entry_changed), completion);
504 id = g_signal_connect (entry, "key-press-event", G_CALLBACK (entry_keypress), completion);547 priv->changed_id = id;
505 priv->keypress_id = id;548
506549 id = g_signal_connect (entry, "key-press-event",
507 g_object_add_weak_pointer (G_OBJECT (entry), (gpointer *)&priv->entry);550 G_CALLBACK (entry_keypress), completion);
508551 priv->keypress_id = id;
509 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (completion));552
510 }553 g_object_add_weak_pointer (G_OBJECT (entry), (gpointer *)&priv->entry);
554
555 gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (completion));
556 }
511}557}
512558
513static GtkListStore *559static GtkListStore *
@@ -525,37 +571,38 @@
525 G_TYPE_STRING);571 G_TYPE_STRING);
526572
527 gint i;573 gint i;
528 for (i = 0; i < locations->len; ++i) {574 for (i = 0; i < locations->len; ++i)
529 CcTimezoneLocation * loc = g_ptr_array_index (locations, i);575 {
530 GtkTreeIter iter;576 CcTimezoneLocation * loc = g_ptr_array_index (locations, i);
531 gtk_list_store_append (store, &iter);577 GtkTreeIter iter;
532578 gtk_list_store_append (store, &iter);
533 gchar * zone;579
534 gchar * country;580 gchar * zone;
535 gchar * en_name; // FIXME: need something better for non-English locales 581 gchar * country;
536 gdouble longitude;582 gchar * en_name; // FIXME: need something better for non-English locales
537 gdouble latitude;583 gdouble longitude;
538 g_object_get (loc, "zone", &zone, "country", &country, "en_name", &en_name,584 gdouble latitude;
539 "longitude", &longitude, "latitude", &latitude,585 g_object_get (loc, "zone", &zone, "country", &country, "en_name", &en_name,
540 NULL);586 "longitude", &longitude, "latitude", &latitude,
541587 NULL);
542 gchar * longitude_s = g_strdup_printf ("%f", longitude);588
543 gchar * latitude_s= g_strdup_printf ("%f", latitude);589 gchar * longitude_s = g_strdup_printf ("%f", longitude);
544590 gchar * latitude_s= g_strdup_printf ("%f", latitude);
545 gtk_list_store_set (store, &iter,591
546 CC_TIMEZONE_COMPLETION_ZONE, NULL,592 gtk_list_store_set (store, &iter,
547 CC_TIMEZONE_COMPLETION_NAME, en_name,593 CC_TIMEZONE_COMPLETION_ZONE, NULL,
548 CC_TIMEZONE_COMPLETION_COUNTRY, country,594 CC_TIMEZONE_COMPLETION_NAME, en_name,
549 CC_TIMEZONE_COMPLETION_LONGITUDE, longitude_s,595 CC_TIMEZONE_COMPLETION_COUNTRY, country,
550 CC_TIMEZONE_COMPLETION_LATITUDE, latitude_s,596 CC_TIMEZONE_COMPLETION_LONGITUDE, longitude_s,
551 -1);597 CC_TIMEZONE_COMPLETION_LATITUDE, latitude_s,
552598 -1);
553 g_free (latitude_s);599
554 g_free (longitude_s);600 g_free (latitude_s);
555 g_free (en_name);601 g_free (longitude_s);
556 g_free (country);602 g_free (en_name);
557 g_free (zone);603 g_free (country);
558 }604 g_free (zone);
605 }
559606
560 GtkTreeIter iter;607 GtkTreeIter iter;
561 gtk_list_store_append (store, &iter);608 gtk_list_store_append (store, &iter);
@@ -581,13 +628,14 @@
581 -1);628 -1);
582629
583 gchar * user_name;630 gchar * user_name;
584 if (country == NULL || country[0] == 0) {631 if (country == NULL || country[0] == 0)
585 user_name = g_strdup (name);632 {
586 } else if (admin1 == NULL || admin1[0] == 0) {633 user_name = g_strdup (name);
587 user_name = g_strdup_printf ("%s <small>(%s)</small>", name, country);634 } else if (admin1 == NULL || admin1[0] == 0) {
588 } else {635 user_name = g_strdup_printf ("%s <small>(%s)</small>", name, country);
589 user_name = g_strdup_printf ("%s <small>(%s, %s)</small>", name, admin1, country);636 } else {
590 }637 user_name = g_strdup_printf ("%s <small>(%s, %s)</small>", name, admin1, country);
638 }
591639
592 g_object_set (G_OBJECT (cell), "markup", user_name, NULL);640 g_object_set (G_OBJECT (cell), "markup", user_name, NULL);
593}641}
@@ -641,49 +689,57 @@
641 CcTimezoneCompletion * completion = CC_TIMEZONE_COMPLETION (object);689 CcTimezoneCompletion * completion = CC_TIMEZONE_COMPLETION (object);
642 CcTimezoneCompletionPrivate * priv = completion->priv;690 CcTimezoneCompletionPrivate * priv = completion->priv;
643691
644 if (priv->changed_id) {692 if (priv->changed_id)
645 if (priv->entry)693 {
646 g_signal_handler_disconnect (priv->entry, priv->changed_id);694 if (priv->entry)
647 priv->changed_id = 0;695 g_signal_handler_disconnect (priv->entry, priv->changed_id);
648 }696 priv->changed_id = 0;
649697 }
650 if (priv->keypress_id) {698
651 if (priv->entry)699 if (priv->keypress_id)
652 g_signal_handler_disconnect (priv->entry, priv->keypress_id);700 {
653 priv->keypress_id = 0;701 if (priv->entry)
654 }702 g_signal_handler_disconnect (priv->entry, priv->keypress_id);
655703 priv->keypress_id = 0;
656 if (priv->entry != NULL) {704 }
657 gtk_entry_set_completion (priv->entry, NULL);705
658 g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *)&priv->entry);706 if (priv->entry != NULL)
659 priv->entry = NULL;707 {
660 }708 gtk_entry_set_completion (priv->entry, NULL);
661709 g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *)&priv->entry);
662 if (priv->initial_model != NULL) {710 priv->entry = NULL;
663 g_object_unref (G_OBJECT (priv->initial_model));711 }
664 priv->initial_model = NULL;712
665 }713 if (priv->initial_model != NULL)
666714 {
667 if (priv->queued_request) {715 g_object_unref (G_OBJECT (priv->initial_model));
668 g_source_remove (priv->queued_request);716 priv->initial_model = NULL;
669 priv->queued_request = 0;717 }
670 }718
671719 if (priv->queued_request)
672 if (priv->cancel != NULL) {720 {
673 g_cancellable_cancel (priv->cancel);721 g_source_remove (priv->queued_request);
674 g_object_unref (priv->cancel);722 priv->queued_request = 0;
675 priv->cancel = NULL;723 }
676 }724
677725 if (priv->cancel != NULL)
678 if (priv->request_text != NULL) {726 {
679 g_free (priv->request_text);727 g_cancellable_cancel (priv->cancel);
680 priv->request_text = NULL;728 g_object_unref (priv->cancel);
681 }729 priv->cancel = NULL;
682730 }
683 if (priv->request_table != NULL) {731
684 g_hash_table_destroy (priv->request_table);732 if (priv->request_text != NULL)
685 priv->request_table = NULL;733 {
686 }734 g_free (priv->request_text);
735 priv->request_text = NULL;
736 }
737
738 if (priv->request_table != NULL)
739 {
740 g_hash_table_destroy (priv->request_table);
741 priv->request_table = NULL;
742 }
687743
688 return;744 return;
689}745}
690746
=== modified file 'src/tz.c'
--- src/tz.c 2013-11-05 11:33:58 +0000
+++ src/tz.c 2013-11-05 11:33:58 +0000
@@ -50,16 +50,16 @@
5050
51struct _CcTimezoneLocationPrivate51struct _CcTimezoneLocationPrivate
52{52{
53 gchar *country;53 gchar *country;
54 gchar *full_country;54 gchar *full_country;
55 gchar *en_name;55 gchar *en_name;
56 gchar *state;56 gchar *state;
57 gdouble latitude;57 gdouble latitude;
58 gdouble longitude;58 gdouble longitude;
59 gchar *zone;59 gchar *zone;
60 gchar *comment;60 gchar *comment;
6161
62 gdouble dist; /* distance to clicked point for comparison */62 gdouble dist; /* distance to clicked point for comparison */
63};63};
6464
65enum {65enum {
@@ -82,8 +82,7 @@
82 GParamSpec *pspec)82 GParamSpec *pspec)
83{83{
84 CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv;84 CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv;
85 switch (property_id)85 switch (property_id) {
86 {
87 case PROP_COUNTRY:86 case PROP_COUNTRY:
88 g_value_set_string (value, priv->country);87 g_value_set_string (value, priv->country);
89 break;88 break;
@@ -123,8 +122,7 @@
123 GParamSpec *pspec)122 GParamSpec *pspec)
124{123{
125 CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv;124 CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv;
126 switch (property_id)125 switch (property_id) {
127 {
128 case PROP_COUNTRY:126 case PROP_COUNTRY:
129 priv->country = g_value_get_string(value);127 priv->country = g_value_get_string(value);
130 break;128 break;
@@ -162,31 +160,31 @@
162{160{
163 CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv;161 CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv;
164162
165 if (priv->country)163 if (priv->country)
166 {164 {
167 g_free (priv->country);165 g_free (priv->country);
168 priv->country = NULL;166 priv->country = NULL;
169 }167 }
170168
171 if (priv->full_country)169 if (priv->full_country)
172 {170 {
173 g_free (priv->full_country);171 g_free (priv->full_country);
174 priv->full_country = NULL;172 priv->full_country = NULL;
175 }173 }
176174
177 if (priv->state)175 if (priv->state)
178 {176 {
179 g_free (priv->state);177 g_free (priv->state);
180 priv->state = NULL;178 priv->state = NULL;
181 }179 }
182180
183 if (priv->zone)181 if (priv->zone)
184 {182 {
185 g_free (priv->zone);183 g_free (priv->zone);
186 priv->zone = NULL;184 priv->zone = NULL;
187 }185 }
188186
189 if (priv->comment)187 if (priv->comment)
190 {188 {
191 g_free (priv->comment);189 g_free (priv->comment);
192 priv->comment = NULL;190 priv->comment = NULL;
@@ -304,19 +302,20 @@
304 FILE *fh = fopen (filename, "r");302 FILE *fh = fopen (filename, "r");
305 char buf[4096];303 char buf[4096];
306304
307 if (!fh) {305 if (!fh)
306 {
308 g_warning ("Could not open *%s*\n", filename);307 g_warning ("Could not open *%s*\n", filename);
309 fclose (fh);308 fclose (fh);
310 return;309 return;
311 }310 }
312311
313 while (fgets (buf, sizeof(buf), fh))312 while (fgets (buf, sizeof(buf), fh))
314 {313 {
315 if (*buf == '#') continue;314 if (*buf == '#') continue;
316315
317 g_strchomp (buf);316 g_strchomp (buf);
318 func (g_strsplit (buf,"\t", ncolumns), user_data);317 func (g_strsplit (buf,"\t", ncolumns), user_data);
319 }318 }
320319
321 fclose (fh);320 fclose (fh);
322}321}
@@ -438,22 +437,25 @@
438 char buf[4096];437 char buf[4096];
439438
440 tz_data_file = tz_data_file_get ("TZ_DATA_FILE", TZ_DATA_FILE);439 tz_data_file = tz_data_file_get ("TZ_DATA_FILE", TZ_DATA_FILE);
441 if (!tz_data_file) {440 if (!tz_data_file)
441 {
442 g_warning ("Could not get the TimeZone data file name");442 g_warning ("Could not get the TimeZone data file name");
443 return NULL;443 return NULL;
444 }444 }
445445
446 admin1_file = tz_data_file_get ("ADMIN1_FILE", ADMIN1_FILE);446 admin1_file = tz_data_file_get ("ADMIN1_FILE", ADMIN1_FILE);
447 if (!admin1_file) {447 if (!admin1_file)
448 {
448 g_warning ("Could not get the admin1 data file name");449 g_warning ("Could not get the admin1 data file name");
449 return NULL;450 return NULL;
450 }451 }
451452
452 country_file = tz_data_file_get ("COUNTRY_FILE", COUNTRY_FILE);453 country_file = tz_data_file_get ("COUNTRY_FILE", COUNTRY_FILE);
453 if (!country_file) {454 if (!country_file)
455 {
454 g_warning ("Could not get the country data file name");456 g_warning ("Could not get the country data file name");
455 return NULL;457 return NULL;
456 }458 }
457459
458 GHashTable *stateHash = g_hash_table_new_full (g_str_hash,460 GHashTable *stateHash = g_hash_table_new_full (g_str_hash,
459 g_str_equal, g_free, g_free);461 g_str_equal, g_free, g_free);
@@ -491,9 +493,9 @@
491void493void
492tz_db_free (TzDB *db)494tz_db_free (TzDB *db)
493{495{
494 g_ptr_array_foreach (db->locations, (GFunc) g_object_unref, NULL);496 g_ptr_array_foreach (db->locations, (GFunc) g_object_unref, NULL);
495 g_ptr_array_free (db->locations, TRUE);497 g_ptr_array_free (db->locations, TRUE);
496 g_free (db);498 g_free (db);
497}499}
498500
499static gint501static gint
@@ -548,103 +550,103 @@
548GPtrArray *550GPtrArray *
549tz_get_locations (TzDB *db)551tz_get_locations (TzDB *db)
550{552{
551 return db->locations;553 return db->locations;
552}554}
553555
554glong556 glong
555tz_location_get_utc_offset (CcTimezoneLocation *loc)557tz_location_get_utc_offset (CcTimezoneLocation *loc)
556{558{
557 TzInfo *tz_info;559 TzInfo *tz_info;
558 glong offset;560 glong offset;
559561
560 tz_info = tz_info_from_location (loc);562 tz_info = tz_info_from_location (loc);
561 offset = tz_info->utc_offset;563 offset = tz_info->utc_offset;
562 tz_info_free (tz_info);564 tz_info_free (tz_info);
563 return offset;565 return offset;
564}566}
565567
566gint568gint
567tz_location_set_locally (CcTimezoneLocation *loc)569tz_location_set_locally (CcTimezoneLocation *loc)
568{570{
569 time_t curtime;571 time_t curtime;
570 struct tm *curzone;572 struct tm *curzone;
571 gboolean is_dst = FALSE;573 gboolean is_dst = FALSE;
572 gint correction = 0;574 gint correction = 0;
573575
574 g_return_val_if_fail (loc != NULL, 0);576 g_return_val_if_fail (loc != NULL, 0);
575 g_return_val_if_fail (loc->priv->zone != NULL, 0);577 g_return_val_if_fail (loc->priv->zone != NULL, 0);
576 578
577 curtime = time (NULL);579 curtime = time (NULL);
578 curzone = localtime (&curtime);580 curzone = localtime (&curtime);
579 is_dst = curzone->tm_isdst;581 is_dst = curzone->tm_isdst;
580582
581 setenv ("TZ", loc->priv->zone, 1);583 setenv ("TZ", loc->priv->zone, 1);
582#if 0584#if 0
583 curtime = time (NULL);585 curtime = time (NULL);
584 curzone = localtime (&curtime);586 curzone = localtime (&curtime);
585587
586 if (!is_dst && curzone->tm_isdst) {588 if (!is_dst && curzone->tm_isdst) {
587 correction = (60 * 60);589 correction = (60 * 60);
588 }590 }
589 else if (is_dst && !curzone->tm_isdst) {591 else if (is_dst && !curzone->tm_isdst) {
590 correction = 0;592 correction = 0;
591 }593 }
592#endif594#endif
593595
594 return correction;596 return correction;
595}597}
596598
597TzInfo *599 TzInfo *
598tz_info_from_location (CcTimezoneLocation *loc)600tz_info_from_location (CcTimezoneLocation *loc)
599{601{
600 TzInfo *tzinfo;602 TzInfo *tzinfo;
601 time_t curtime;603 time_t curtime;
602 struct tm *curzone;604 struct tm *curzone;
603 605
604 g_return_val_if_fail (loc != NULL, NULL);606 g_return_val_if_fail (loc != NULL, NULL);
605 g_return_val_if_fail (loc->priv->zone != NULL, NULL);607 g_return_val_if_fail (loc->priv->zone != NULL, NULL);
606 608
607 setenv ("TZ", loc->priv->zone, 1);609 setenv ("TZ", loc->priv->zone, 1);
608 610
609#if 0611#if 0
610 tzset ();612 tzset ();
611#endif613#endif
612 tzinfo = g_new0 (TzInfo, 1);614 tzinfo = g_new0 (TzInfo, 1);
613615
614 curtime = time (NULL);616 curtime = time (NULL);
615 curzone = localtime (&curtime);617 curzone = localtime (&curtime);
616618
617#ifndef __sun619#ifndef __sun
618 /* Currently this solution doesnt seem to work - I get that */620 /* Currently this solution doesnt seem to work - I get that */
619 /* America/Phoenix uses daylight savings, which is wrong */621 /* America/Phoenix uses daylight savings, which is wrong */
620 tzinfo->tzname_normal = g_strdup (curzone->tm_zone);622 tzinfo->tzname_normal = g_strdup (curzone->tm_zone);
621 if (curzone->tm_isdst) 623 if (curzone->tm_isdst)
622 tzinfo->tzname_daylight =624 tzinfo->tzname_daylight =
623 g_strdup (&curzone->tm_zone[curzone->tm_isdst]);625 g_strdup (&curzone->tm_zone[curzone->tm_isdst]);
624 else626 else
625 tzinfo->tzname_daylight = NULL;627 tzinfo->tzname_daylight = NULL;
626628
627 tzinfo->utc_offset = curzone->tm_gmtoff;629 tzinfo->utc_offset = curzone->tm_gmtoff;
628#else630#else
629 tzinfo->tzname_normal = NULL;631 tzinfo->tzname_normal = NULL;
630 tzinfo->tzname_daylight = NULL;632 tzinfo->tzname_daylight = NULL;
631 tzinfo->utc_offset = 0;633 tzinfo->utc_offset = 0;
632#endif634#endif
633635
634 tzinfo->daylight = curzone->tm_isdst;636 tzinfo->daylight = curzone->tm_isdst;
635 637
636 return tzinfo;638 return tzinfo;
637}639}
638640
639641
640void642 void
641tz_info_free (TzInfo *tzinfo)643tz_info_free (TzInfo *tzinfo)
642{644{
643 g_return_if_fail (tzinfo != NULL);645 g_return_if_fail (tzinfo != NULL);
644 646
645 if (tzinfo->tzname_normal) g_free (tzinfo->tzname_normal);647 if (tzinfo->tzname_normal) g_free (tzinfo->tzname_normal);
646 if (tzinfo->tzname_daylight) g_free (tzinfo->tzname_daylight);648 if (tzinfo->tzname_daylight) g_free (tzinfo->tzname_daylight);
647 g_free (tzinfo);649 g_free (tzinfo);
648}650}
649651
650/* ----------------- *652/* ----------------- *
@@ -665,38 +667,38 @@
665static float667static float
666convert_pos (gchar *pos, int digits)668convert_pos (gchar *pos, int digits)
667{669{
668 gchar whole[10];670 gchar whole[10];
669 gchar *fraction;671 gchar *fraction;
670 gint i;672 gint i;
671 float t1, t2;673 float t1, t2;
672 674
673 if (!pos || strlen(pos) < 4 || digits > 9) return 0.0;675 if (!pos || strlen(pos) < 4 || digits > 9) return 0.0;
674 676
675 for (i = 0; i < digits + 1; i++) whole[i] = pos[i];677 for (i = 0; i < digits + 1; i++) whole[i] = pos[i];
676 whole[i] = '\0';678 whole[i] = '\0';
677 fraction = pos + digits + 1;679 fraction = pos + digits + 1;
678680
679 t1 = g_strtod (whole, NULL);681 t1 = g_strtod (whole, NULL);
680 t2 = g_strtod (fraction, NULL);682 t2 = g_strtod (fraction, NULL);
681683
682 if (t1 >= 0.0) return t1 + t2/pow (10.0, strlen(fraction));684 if (t1 >= 0.0) return t1 + t2/pow (10.0, strlen(fraction));
683 else return t1 - t2/pow (10.0, strlen(fraction));685 else return t1 - t2/pow (10.0, strlen(fraction));
684}686}
685#endif687#endif
686688
687static int689 static int
688compare_country_names (const void *a, const void *b)690compare_country_names (const void *a, const void *b)
689{691{
690 const CcTimezoneLocation *tza = * (CcTimezoneLocation **) a;692 const CcTimezoneLocation *tza = * (CcTimezoneLocation **) a;
691 const CcTimezoneLocation *tzb = * (CcTimezoneLocation **) b;693 const CcTimezoneLocation *tzb = * (CcTimezoneLocation **) b;
692 694
693 return strcmp (tza->priv->zone, tzb->priv->zone);695 return strcmp (tza->priv->zone, tzb->priv->zone);
694}696}
695697
696698
697static void699 static void
698sort_locations_by_country (GPtrArray *locations)700sort_locations_by_country (GPtrArray *locations)
699{701{
700 qsort (locations->pdata, locations->len, sizeof (gpointer),702 qsort (locations->pdata, locations->len, sizeof (gpointer),
701 compare_country_names);703 compare_country_names);
702}704}

Subscribers

People subscribed via source and target branches

to all changes: