Merge lp:~laney/timezonemap/more-data-whitespace into lp:timezonemap
- more-data-whitespace
- Merge into trunk
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 |
Related bugs: |
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
1 | === modified file 'src/cc-timezone-map.c' | |||
2 | --- src/cc-timezone-map.c 2012-11-06 17:14:04 +0000 | |||
3 | +++ src/cc-timezone-map.c 2013-11-05 11:33:58 +0000 | |||
4 | @@ -974,40 +974,41 @@ | |||
5 | 974 | width = alloc.width; | 974 | width = alloc.width; |
6 | 975 | height = alloc.height; | 975 | height = alloc.height; |
7 | 976 | 976 | ||
42 | 977 | if (x == priv->previous_x && y == priv->previous_y) { | 977 | if (x == priv->previous_x && y == priv->previous_y) |
43 | 978 | priv->distances = g_list_next (priv->distances); | 978 | { |
44 | 979 | location = (CcTimezoneLocation*) priv->distances->data; | 979 | priv->distances = g_list_next (priv->distances); |
45 | 980 | } else { | 980 | location = (CcTimezoneLocation*) priv->distances->data; |
46 | 981 | g_list_free (priv->distances); | 981 | } else { |
47 | 982 | priv->distances = NULL; | 982 | g_list_free (priv->distances); |
48 | 983 | for (i = 0; i < array->len; i++) | 983 | priv->distances = NULL; |
49 | 984 | { | 984 | for (i = 0; i < array->len; i++) |
50 | 985 | gdouble pointx, pointy, dx, dy; | 985 | { |
51 | 986 | CcTimezoneLocation *loc = array->pdata[i]; | 986 | gdouble pointx, pointy, dx, dy; |
52 | 987 | 987 | CcTimezoneLocation *loc = array->pdata[i]; | |
53 | 988 | g_object_get_property(G_OBJECT (loc), "longitude", &glon); | 988 | |
54 | 989 | g_object_get_property(G_OBJECT (loc), "latitude", &glat); | 989 | g_object_get_property(G_OBJECT (loc), "longitude", &glon); |
55 | 990 | pointx = convert_longtitude_to_x (g_value_get_double(&glon), width); | 990 | g_object_get_property(G_OBJECT (loc), "latitude", &glat); |
56 | 991 | pointy = convert_latitude_to_y (g_value_get_double(&glat), height); | 991 | pointx = convert_longtitude_to_x (g_value_get_double(&glon), width); |
57 | 992 | 992 | pointy = convert_latitude_to_y (g_value_get_double(&glat), height); | |
58 | 993 | dx = pointx - x; | 993 | |
59 | 994 | dy = pointy - y; | 994 | dx = pointx - x; |
60 | 995 | 995 | dy = pointy - y; | |
61 | 996 | g_value_set_double(&gdist, (gdouble) dx * dx + dy * dy); | 996 | |
62 | 997 | g_object_set_property(G_OBJECT (loc), "dist", &gdist); | 997 | g_value_set_double(&gdist, (gdouble) dx * dx + dy * dy); |
63 | 998 | priv->distances = g_list_prepend (priv->distances, loc); | 998 | g_object_set_property(G_OBJECT (loc), "dist", &gdist); |
64 | 999 | } | 999 | priv->distances = g_list_prepend (priv->distances, loc); |
65 | 1000 | priv->distances = g_list_sort (priv->distances, (GCompareFunc) sort_locations); | 1000 | } |
66 | 1001 | location = (CcTimezoneLocation*) priv->distances->data; | 1001 | priv->distances = g_list_sort (priv->distances, (GCompareFunc) sort_locations); |
67 | 1002 | priv->previous_x = x; | 1002 | location = (CcTimezoneLocation*) priv->distances->data; |
68 | 1003 | priv->previous_y = y; | 1003 | priv->previous_x = x; |
69 | 1004 | } | 1004 | priv->previous_y = y; |
70 | 1005 | 1005 | } | |
71 | 1006 | g_value_unset (&glon); | 1006 | |
72 | 1007 | g_value_unset (&glat); | 1007 | g_value_unset (&glon); |
73 | 1008 | g_value_unset (&gdist); | 1008 | g_value_unset (&glat); |
74 | 1009 | 1009 | g_value_unset (&gdist); | |
75 | 1010 | return location; | 1010 | |
76 | 1011 | return location; | ||
77 | 1011 | } | 1012 | } |
78 | 1012 | 1013 | ||
79 | 1013 | static gboolean | 1014 | static gboolean |
80 | @@ -1199,20 +1200,20 @@ | |||
81 | 1199 | if (zone < G_N_ELEMENTS(olsen_map_timezones)) | 1200 | if (zone < G_N_ELEMENTS(olsen_map_timezones)) |
82 | 1200 | city = olsen_map_timezones[zone]; | 1201 | city = olsen_map_timezones[zone]; |
83 | 1201 | 1202 | ||
98 | 1202 | if (city != NULL) { | 1203 | if (city != NULL) |
99 | 1203 | return city; | 1204 | { |
100 | 1204 | } | 1205 | return city; |
101 | 1205 | else { | 1206 | } else { |
102 | 1206 | GtkAllocation alloc; | 1207 | GtkAllocation alloc; |
103 | 1207 | GValue val_zone = {0}; | 1208 | GValue val_zone = {0}; |
104 | 1208 | g_value_init (&val_zone, G_TYPE_STRING); | 1209 | g_value_init (&val_zone, G_TYPE_STRING); |
105 | 1209 | gtk_widget_get_allocation (GTK_WIDGET (map), &alloc); | 1210 | gtk_widget_get_allocation (GTK_WIDGET (map), &alloc); |
106 | 1210 | x = convert_longtitude_to_x(lon, alloc.width); | 1211 | x = convert_longtitude_to_x(lon, alloc.width); |
107 | 1211 | y = convert_latitude_to_y(lat, alloc.height); | 1212 | y = convert_latitude_to_y(lat, alloc.height); |
108 | 1212 | CcTimezoneLocation * loc = get_loc_for_xy(GTK_WIDGET (map), x, y); | 1213 | CcTimezoneLocation * loc = get_loc_for_xy(GTK_WIDGET (map), x, y); |
109 | 1213 | g_value_unset (&val_zone); | 1214 | g_value_unset (&val_zone); |
110 | 1214 | return g_value_get_string(&val_zone); | 1215 | return g_value_get_string(&val_zone); |
111 | 1215 | } | 1216 | } |
112 | 1216 | } | 1217 | } |
113 | 1217 | 1218 | ||
114 | 1218 | void | 1219 | void |
115 | 1219 | 1220 | ||
116 | === modified file 'src/test-timezone.c' | |||
117 | --- src/test-timezone.c 2011-08-01 16:37:54 +0000 | |||
118 | +++ src/test-timezone.c 2013-11-05 11:33:58 +0000 | |||
119 | @@ -5,58 +5,61 @@ | |||
120 | 5 | 5 | ||
121 | 6 | int main (int argc, char **argv) | 6 | int main (int argc, char **argv) |
122 | 7 | { | 7 | { |
128 | 8 | TzDB *db; | 8 | TzDB *db; |
129 | 9 | GPtrArray *locs; | 9 | GPtrArray *locs; |
130 | 10 | guint i; | 10 | guint i; |
131 | 11 | char *pixmap_dir; | 11 | char *pixmap_dir; |
132 | 12 | int retval = 0; | 12 | int retval = 0; |
133 | 13 | 13 | ||
134 | 14 | setlocale (LC_ALL, ""); | 14 | setlocale (LC_ALL, ""); |
135 | 15 | 15 | ||
165 | 16 | if (argc == 2) { | 16 | if (argc == 2) |
166 | 17 | pixmap_dir = g_strdup (argv[1]); | 17 | { |
167 | 18 | } else if (argc == 1) { | 18 | pixmap_dir = g_strdup (argv[1]); |
168 | 19 | pixmap_dir = g_strdup ("data/"); | 19 | } else if (argc == 1) { |
169 | 20 | } else { | 20 | pixmap_dir = g_strdup ("data/"); |
170 | 21 | g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]); | 21 | } else { |
171 | 22 | return 1; | 22 | g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]); |
172 | 23 | } | 23 | return 1; |
173 | 24 | 24 | } | |
174 | 25 | g_type_init(); | 25 | |
175 | 26 | GValue zone = {0}; | 26 | g_type_init(); |
176 | 27 | g_value_init(&zone, G_TYPE_STRING); | 27 | GValue zone = {0}; |
177 | 28 | 28 | g_value_init(&zone, G_TYPE_STRING); | |
178 | 29 | db = tz_load_db (); | 29 | |
179 | 30 | locs = tz_get_locations (db); | 30 | db = tz_load_db (); |
180 | 31 | for (i = 0; i < locs->len ; i++) { | 31 | locs = tz_get_locations (db); |
181 | 32 | CcTimezoneLocation *loc = locs->pdata[i]; | 32 | for (i = 0; i < locs->len ; i++) |
182 | 33 | 33 | { | |
183 | 34 | TzInfo *info; | 34 | CcTimezoneLocation *loc = locs->pdata[i]; |
184 | 35 | char *filename, *path; | 35 | |
185 | 36 | gdouble selected_offset; | 36 | TzInfo *info; |
186 | 37 | char buf[16]; | 37 | char *filename, *path; |
187 | 38 | g_object_get_property(G_OBJECT (loc), "zone", &zone); | 38 | gdouble selected_offset; |
188 | 39 | 39 | char buf[16]; | |
189 | 40 | info = tz_info_from_location (loc); | 40 | g_object_get_property(G_OBJECT (loc), "zone", &zone); |
190 | 41 | selected_offset = tz_location_get_utc_offset (loc) | 41 | |
191 | 42 | / (60.0*60.0) + ((info->daylight) ? -1.0 : 0.0); | 42 | info = tz_info_from_location (loc); |
192 | 43 | 43 | selected_offset = tz_location_get_utc_offset (loc) | |
193 | 44 | filename = g_strdup_printf ("timezone_%s.png", | 44 | / (60.0*60.0) + ((info->daylight) ? -1.0 : 0.0); |
194 | 45 | |||
195 | 46 | filename = g_strdup_printf ("timezone_%s.png", | ||
196 | 45 | g_ascii_formatd (buf, sizeof (buf), | 47 | g_ascii_formatd (buf, sizeof (buf), |
197 | 46 | "%g", selected_offset)); | 48 | "%g", selected_offset)); |
213 | 47 | path = g_build_filename (pixmap_dir, filename, NULL); | 49 | path = g_build_filename (pixmap_dir, filename, NULL); |
214 | 48 | 50 | ||
215 | 49 | if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE) { | 51 | if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE) |
216 | 50 | g_message ("File '%s' missing for zone '%s'", filename, g_value_get_string(&zone)); | 52 | { |
217 | 51 | retval = 1; | 53 | g_message ("File '%s' missing for zone '%s'", filename, g_value_get_string(&zone)); |
218 | 52 | } | 54 | retval = 1; |
219 | 53 | 55 | } | |
220 | 54 | g_free (filename); | 56 | |
221 | 55 | g_free (path); | 57 | g_free (filename); |
222 | 56 | tz_info_free (info); | 58 | g_free (path); |
223 | 57 | } | 59 | tz_info_free (info); |
224 | 58 | tz_db_free (db); | 60 | } |
225 | 59 | g_free (pixmap_dir); | 61 | tz_db_free (db); |
226 | 60 | 62 | g_free (pixmap_dir); | |
227 | 61 | return retval; | 63 | |
228 | 64 | return retval; | ||
229 | 62 | } | 65 | } |
230 | 63 | 66 | ||
231 | === modified file 'src/timezone-completion.c' | |||
232 | --- src/timezone-completion.c 2012-11-06 17:14:04 +0000 | |||
233 | +++ src/timezone-completion.c 2013-11-05 11:33:58 +0000 | |||
234 | @@ -138,13 +138,14 @@ | |||
235 | 138 | g_cancellable_reset (priv->cancel); | 138 | g_cancellable_reset (priv->cancel); |
236 | 139 | } | 139 | } |
237 | 140 | 140 | ||
245 | 141 | if (error != NULL) { | 141 | if (error != NULL) |
246 | 142 | if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) | 142 | { |
247 | 143 | save_and_use_model (completion, priv->initial_model); | 143 | if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) |
248 | 144 | g_warning ("Could not parse geoname JSON data: %s", error->message); | 144 | save_and_use_model (completion, priv->initial_model); |
249 | 145 | g_error_free (error); | 145 | g_warning ("Could not parse geoname JSON data: %s", error->message); |
250 | 146 | return; | 146 | g_error_free (error); |
251 | 147 | } | 147 | return; |
252 | 148 | } | ||
253 | 148 | 149 | ||
254 | 149 | GtkListStore * store = gtk_list_store_new (CC_TIMEZONE_COMPLETION_LAST, | 150 | GtkListStore * store = gtk_list_store_new (CC_TIMEZONE_COMPLETION_LAST, |
255 | 150 | G_TYPE_STRING, | 151 | G_TYPE_STRING, |
256 | @@ -156,73 +157,85 @@ | |||
257 | 156 | 157 | ||
258 | 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))); |
259 | 158 | 159 | ||
266 | 159 | if (!json_reader_is_array (reader)) { | 160 | if (!json_reader_is_array (reader)) |
267 | 160 | g_warning ("Could not parse geoname JSON data"); | 161 | { |
268 | 161 | save_and_use_model (completion, priv->initial_model); | 162 | g_warning ("Could not parse geoname JSON data"); |
269 | 162 | g_object_unref (G_OBJECT (reader)); | 163 | save_and_use_model (completion, priv->initial_model); |
270 | 163 | return; | 164 | g_object_unref (G_OBJECT (reader)); |
271 | 164 | } | 165 | return; |
272 | 166 | } | ||
273 | 165 | 167 | ||
274 | 166 | gint i, count = json_reader_count_elements (reader); | 168 | gint i, count = json_reader_count_elements (reader); |
278 | 167 | for (i = 0; i < count; ++i) { | 169 | for (i = 0; i < count; ++i) |
279 | 168 | if (!json_reader_read_element (reader, i)) | 170 | { |
280 | 169 | continue; | 171 | if (!json_reader_read_element (reader, i)) |
281 | 172 | continue; | ||
282 | 170 | 173 | ||
310 | 171 | if (json_reader_is_object (reader)) { | 174 | if (json_reader_is_object (reader)) |
311 | 172 | const gchar * name = NULL; | 175 | { |
312 | 173 | const gchar * admin1 = NULL; | 176 | const gchar * name = NULL; |
313 | 174 | const gchar * country = NULL; | 177 | const gchar * admin1 = NULL; |
314 | 175 | const gchar * longitude = NULL; | 178 | const gchar * country = NULL; |
315 | 176 | const gchar * latitude = NULL; | 179 | const gchar * longitude = NULL; |
316 | 177 | gboolean skip = FALSE; | 180 | const gchar * latitude = NULL; |
317 | 178 | if (json_reader_read_member (reader, "name")) { | 181 | gboolean skip = FALSE; |
318 | 179 | name = json_reader_get_string_value (reader); | 182 | if (json_reader_read_member (reader, "name")) |
319 | 180 | json_reader_end_member (reader); | 183 | { |
320 | 181 | } | 184 | name = json_reader_get_string_value (reader); |
321 | 182 | if (json_reader_read_member (reader, "admin1")) { | 185 | json_reader_end_member (reader); |
322 | 183 | admin1 = json_reader_get_string_value (reader); | 186 | } |
323 | 184 | json_reader_end_member (reader); | 187 | if (json_reader_read_member (reader, "admin1")) |
324 | 185 | } | 188 | { |
325 | 186 | if (json_reader_read_member (reader, "country")) { | 189 | admin1 = json_reader_get_string_value (reader); |
326 | 187 | country = json_reader_get_string_value (reader); | 190 | json_reader_end_member (reader); |
327 | 188 | json_reader_end_member (reader); | 191 | } |
328 | 189 | } | 192 | if (json_reader_read_member (reader, "country")) |
329 | 190 | if (json_reader_read_member (reader, "longitude")) { | 193 | { |
330 | 191 | longitude = json_reader_get_string_value (reader); | 194 | country = json_reader_get_string_value (reader); |
331 | 192 | json_reader_end_member (reader); | 195 | json_reader_end_member (reader); |
332 | 193 | } | 196 | } |
333 | 194 | if (json_reader_read_member (reader, "latitude")) { | 197 | if (json_reader_read_member (reader, "longitude")) |
334 | 195 | latitude = json_reader_get_string_value (reader); | 198 | { |
335 | 196 | json_reader_end_member (reader); | 199 | longitude = json_reader_get_string_value (reader); |
336 | 197 | } | 200 | json_reader_end_member (reader); |
337 | 201 | } | ||
338 | 202 | if (json_reader_read_member (reader, "latitude")) | ||
339 | 203 | { | ||
340 | 204 | latitude = json_reader_get_string_value (reader); | ||
341 | 205 | json_reader_end_member (reader); | ||
342 | 206 | } | ||
343 | 198 | 207 | ||
344 | 199 | if (g_strcmp0(name, prev_name) == 0 && | 208 | if (g_strcmp0(name, prev_name) == 0 && |
345 | 200 | g_strcmp0(admin1, prev_admin1) == 0 && | 209 | g_strcmp0(admin1, prev_admin1) == 0 && |
351 | 201 | g_strcmp0(country, prev_country) == 0) { | 210 | g_strcmp0(country, prev_country) == 0) |
352 | 202 | // Sometimes the data will have duplicate entries that only differ | 211 | { |
353 | 203 | // in longitude and latitude. e.g. "rio de janeiro", "wellington" | 212 | // Sometimes the data will have duplicate entries that only differ |
354 | 204 | skip = TRUE; | 213 | // in longitude and latitude. e.g. "rio de janeiro", "wellington" |
355 | 205 | } | 214 | skip = TRUE; |
356 | 215 | } | ||
357 | 206 | 216 | ||
377 | 207 | if (!skip) { | 217 | if (!skip) |
378 | 208 | GtkTreeIter iter; | 218 | { |
379 | 209 | gtk_list_store_append (store, &iter); | 219 | GtkTreeIter iter; |
380 | 210 | gtk_list_store_set (store, &iter, | 220 | gtk_list_store_append (store, &iter); |
381 | 211 | CC_TIMEZONE_COMPLETION_ZONE, NULL, | 221 | gtk_list_store_set (store, &iter, |
382 | 212 | CC_TIMEZONE_COMPLETION_NAME, name, | 222 | CC_TIMEZONE_COMPLETION_ZONE, NULL, |
383 | 213 | CC_TIMEZONE_COMPLETION_ADMIN1, admin1, | 223 | CC_TIMEZONE_COMPLETION_NAME, name, |
384 | 214 | CC_TIMEZONE_COMPLETION_COUNTRY, country, | 224 | CC_TIMEZONE_COMPLETION_ADMIN1, admin1, |
385 | 215 | CC_TIMEZONE_COMPLETION_LONGITUDE, longitude, | 225 | CC_TIMEZONE_COMPLETION_COUNTRY, country, |
386 | 216 | CC_TIMEZONE_COMPLETION_LATITUDE, latitude, | 226 | CC_TIMEZONE_COMPLETION_LONGITUDE, longitude, |
387 | 217 | -1); | 227 | CC_TIMEZONE_COMPLETION_LATITUDE, latitude, |
388 | 218 | gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store), | 228 | -1); |
389 | 219 | CC_TIMEZONE_COMPLETION_NAME, sort_zone, | 229 | gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store), |
390 | 220 | g_utf8_casefold(priv->request_text, -1), | 230 | CC_TIMEZONE_COMPLETION_NAME, |
391 | 221 | g_free); | 231 | sort_zone, |
392 | 222 | gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), | 232 | g_utf8_casefold(priv->request_text, |
393 | 223 | CC_TIMEZONE_COMPLETION_NAME, | 233 | -1), |
394 | 224 | GTK_SORT_ASCENDING); | 234 | g_free); |
395 | 225 | } | 235 | gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), |
396 | 236 | CC_TIMEZONE_COMPLETION_NAME, | ||
397 | 237 | GTK_SORT_ASCENDING); | ||
398 | 238 | } | ||
399 | 226 | 239 | ||
400 | 227 | prev_name = name; | 240 | prev_name = name; |
401 | 228 | prev_admin1 = admin1; | 241 | prev_admin1 = admin1; |
402 | @@ -232,19 +245,21 @@ | |||
403 | 232 | json_reader_end_element (reader); | 245 | json_reader_end_element (reader); |
404 | 233 | } | 246 | } |
405 | 234 | 247 | ||
416 | 235 | if (strlen (priv->request_text) < 4) { | 248 | if (strlen (priv->request_text) < 4) |
417 | 236 | gchar * lower_text = g_ascii_strdown (priv->request_text, -1); | 249 | { |
418 | 237 | if (g_strcmp0 (lower_text, "ut") == 0 || | 250 | gchar * lower_text = g_ascii_strdown (priv->request_text, -1); |
419 | 238 | g_strcmp0 (lower_text, "utc") == 0) { | 251 | if (g_strcmp0 (lower_text, "ut") == 0 || |
420 | 239 | GtkTreeIter iter; | 252 | g_strcmp0 (lower_text, "utc") == 0) |
421 | 240 | gtk_list_store_append (store, &iter); | 253 | { |
422 | 241 | gtk_list_store_set (store, &iter, | 254 | GtkTreeIter iter; |
423 | 242 | CC_TIMEZONE_COMPLETION_ZONE, "UTC", | 255 | gtk_list_store_append (store, &iter); |
424 | 243 | CC_TIMEZONE_COMPLETION_NAME, "UTC", | 256 | gtk_list_store_set (store, &iter, |
425 | 244 | -1); | 257 | CC_TIMEZONE_COMPLETION_ZONE, "UTC", |
426 | 258 | CC_TIMEZONE_COMPLETION_NAME, "UTC", | ||
427 | 259 | -1); | ||
428 | 260 | } | ||
429 | 261 | g_free (lower_text); | ||
430 | 245 | } | 262 | } |
431 | 246 | g_free (lower_text); | ||
432 | 247 | } | ||
433 | 248 | 263 | ||
434 | 249 | save_and_use_model (completion, GTK_TREE_MODEL (store)); | 264 | save_and_use_model (completion, GTK_TREE_MODEL (store)); |
435 | 250 | g_object_unref (G_OBJECT (reader)); | 265 | g_object_unref (G_OBJECT (reader)); |
436 | @@ -260,17 +275,20 @@ | |||
437 | 260 | 275 | ||
438 | 261 | stream = g_file_read_finish (G_FILE (object), res, &error); | 276 | stream = g_file_read_finish (G_FILE (object), res, &error); |
439 | 262 | 277 | ||
443 | 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) |
444 | 264 | g_cancellable_reset (priv->cancel); | 279 | { |
445 | 265 | } | 280 | g_cancellable_reset (priv->cancel); |
446 | 281 | } | ||
447 | 266 | 282 | ||
455 | 267 | if (error != NULL) { | 283 | if (error != NULL) |
456 | 268 | if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) | 284 | { |
457 | 269 | save_and_use_model (completion, priv->initial_model); | 285 | if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) |
458 | 270 | g_warning ("Could not connect to geoname lookup server: %s", error->message); | 286 | save_and_use_model (completion, priv->initial_model); |
459 | 271 | g_error_free (error); | 287 | g_warning ("Could not connect to geoname lookup server: %s", |
460 | 272 | return; | 288 | error->message); |
461 | 273 | } | 289 | g_error_free (error); |
462 | 290 | return; | ||
463 | 291 | } | ||
464 | 274 | 292 | ||
465 | 275 | JsonParser * parser = json_parser_new (); | 293 | JsonParser * parser = json_parser_new (); |
466 | 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, |
467 | @@ -286,11 +304,12 @@ | |||
468 | 286 | const gchar *env = NULL; | 304 | const gchar *env = NULL; |
469 | 287 | gint i; | 305 | gint i; |
470 | 288 | 306 | ||
476 | 289 | for (i = 0; env_names[i]; i++) { | 307 | for (i = 0; env_names[i]; i++) |
477 | 290 | env = g_getenv (env_names[i]); | 308 | { |
478 | 291 | if (env != NULL && env[0] != 0) | 309 | env = g_getenv (env_names[i]); |
479 | 292 | break; | 310 | if (env != NULL && env[0] != 0) |
480 | 293 | } | 311 | break; |
481 | 312 | } | ||
482 | 294 | 313 | ||
483 | 295 | if (env == NULL) | 314 | if (env == NULL) |
484 | 296 | return NULL; | 315 | return NULL; |
485 | @@ -301,10 +320,11 @@ | |||
486 | 301 | if (split == NULL) | 320 | if (split == NULL) |
487 | 302 | return NULL; | 321 | return NULL; |
488 | 303 | 322 | ||
493 | 304 | if (split[0] == NULL) { | 323 | if (split[0] == NULL) |
494 | 305 | g_strfreev (split); | 324 | { |
495 | 306 | return NULL; | 325 | g_strfreev (split); |
496 | 307 | } | 326 | return NULL; |
497 | 327 | } | ||
498 | 308 | 328 | ||
499 | 309 | gchar *locale = g_strdup (split[0]); | 329 | gchar *locale = g_strdup (split[0]); |
500 | 310 | g_strfreev (split); | 330 | g_strfreev (split); |
501 | @@ -316,15 +336,16 @@ | |||
502 | 316 | { | 336 | { |
503 | 317 | static gchar *version = NULL; | 337 | static gchar *version = NULL; |
504 | 318 | 338 | ||
508 | 319 | if (version == NULL) { | 339 | if (version == NULL) |
509 | 320 | gchar *stdout = NULL; | 340 | { |
510 | 321 | g_spawn_command_line_sync ("lsb_release -rs", &stdout, NULL, NULL, NULL); | 341 | gchar *stdout = NULL; |
511 | 342 | g_spawn_command_line_sync ("lsb_release -rs", &stdout, NULL, NULL, NULL); | ||
512 | 322 | 343 | ||
518 | 323 | if (stdout != NULL) | 344 | if (stdout != NULL) |
519 | 324 | version = g_strstrip (stdout); | 345 | version = g_strstrip (stdout); |
520 | 325 | else | 346 | else |
521 | 326 | version = g_strdup(""); | 347 | version = g_strdup(""); |
522 | 327 | } | 348 | } |
523 | 328 | 349 | ||
524 | 329 | return version; | 350 | return version; |
525 | 330 | } | 351 | } |
526 | @@ -336,15 +357,17 @@ | |||
527 | 336 | 357 | ||
528 | 337 | priv->queued_request = 0; | 358 | priv->queued_request = 0; |
529 | 338 | 359 | ||
533 | 339 | if (priv->entry == NULL) { | 360 | if (priv->entry == NULL) |
534 | 340 | return FALSE; | 361 | { |
535 | 341 | } | 362 | return FALSE; |
536 | 363 | } | ||
537 | 342 | 364 | ||
538 | 343 | /* Cancel any ongoing request */ | 365 | /* Cancel any ongoing request */ |
543 | 344 | if (priv->cancel) { | 366 | if (priv->cancel) |
544 | 345 | g_cancellable_cancel (priv->cancel); | 367 | { |
545 | 346 | g_cancellable_reset (priv->cancel); | 368 | g_cancellable_cancel (priv->cancel); |
546 | 347 | } | 369 | g_cancellable_reset (priv->cancel); |
547 | 370 | } | ||
548 | 348 | g_free (priv->request_text); | 371 | g_free (priv->request_text); |
549 | 349 | 372 | ||
550 | 350 | const gchar * text = gtk_entry_get_text (priv->entry); | 373 | const gchar * text = gtk_entry_get_text (priv->entry); |
551 | @@ -371,21 +394,26 @@ | |||
552 | 371 | { | 394 | { |
553 | 372 | CcTimezoneCompletionPrivate * priv = completion->priv; | 395 | CcTimezoneCompletionPrivate * priv = completion->priv; |
554 | 373 | 396 | ||
559 | 374 | if (priv->queued_request) { | 397 | if (priv->queued_request) |
560 | 375 | g_source_remove (priv->queued_request); | 398 | { |
561 | 376 | priv->queued_request = 0; | 399 | g_source_remove (priv->queued_request); |
562 | 377 | } | 400 | priv->queued_request = 0; |
563 | 401 | } | ||
564 | 378 | 402 | ||
565 | 379 | /* See if we've already got this one */ | 403 | /* See if we've already got this one */ |
566 | 380 | const gchar * text = gtk_entry_get_text (priv->entry); | 404 | const gchar * text = gtk_entry_get_text (priv->entry); |
567 | 381 | gpointer data; | 405 | gpointer data; |
575 | 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)) |
576 | 383 | gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion), GTK_TREE_MODEL (data)); | 407 | { |
577 | 384 | } | 408 | gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion), |
578 | 385 | else { | 409 | GTK_TREE_MODEL (data)); |
579 | 386 | priv->queued_request = g_timeout_add (300, (GSourceFunc)request_zones, completion); | 410 | } |
580 | 387 | gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion), NULL); | 411 | else |
581 | 388 | } | 412 | { |
582 | 413 | priv->queued_request = g_timeout_add (300, (GSourceFunc)request_zones, | ||
583 | 414 | completion); | ||
584 | 415 | gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion), NULL); | ||
585 | 416 | } | ||
586 | 389 | gtk_entry_completion_complete (GTK_ENTRY_COMPLETION (completion)); | 417 | gtk_entry_completion_complete (GTK_ENTRY_COMPLETION (completion)); |
587 | 390 | } | 418 | } |
588 | 391 | 419 | ||
589 | @@ -395,18 +423,21 @@ | |||
590 | 395 | if (g_type_is_a (G_OBJECT_TYPE (parent), type)) | 423 | if (g_type_is_a (G_OBJECT_TYPE (parent), type)) |
591 | 396 | return parent; | 424 | return parent; |
592 | 397 | 425 | ||
602 | 398 | if (GTK_IS_CONTAINER (parent)) { | 426 | if (GTK_IS_CONTAINER (parent)) |
603 | 399 | GList * children = gtk_container_get_children (GTK_CONTAINER (parent)); | 427 | { |
604 | 400 | GList * iter; | 428 | GList * children = gtk_container_get_children (GTK_CONTAINER (parent)); |
605 | 401 | for (iter = children; iter; iter = iter->next) { | 429 | GList * iter; |
606 | 402 | GtkWidget * found = get_descendent (GTK_WIDGET (iter->data), type); | 430 | for (iter = children; iter; iter = iter->next) |
607 | 403 | if (found) { | 431 | { |
608 | 404 | g_list_free (children); | 432 | GtkWidget * found = get_descendent (GTK_WIDGET (iter->data), type); |
609 | 405 | return found; | 433 | if (found) |
610 | 406 | } | 434 | { |
611 | 435 | g_list_free (children); | ||
612 | 436 | return found; | ||
613 | 437 | } | ||
614 | 438 | } | ||
615 | 439 | g_list_free (children); | ||
616 | 407 | } | 440 | } |
617 | 408 | g_list_free (children); | ||
618 | 409 | } | ||
619 | 410 | 441 | ||
620 | 411 | return NULL; | 442 | return NULL; |
621 | 412 | } | 443 | } |
622 | @@ -429,20 +460,26 @@ | |||
623 | 429 | GtkWindowGroup * group = gtk_window_get_group (GTK_WINDOW (toplevel)); | 460 | GtkWindowGroup * group = gtk_window_get_group (GTK_WINDOW (toplevel)); |
624 | 430 | GList * windows = gtk_window_group_list_windows (group); | 461 | GList * windows = gtk_window_group_list_windows (group); |
625 | 431 | GList * iter; | 462 | GList * iter; |
638 | 432 | for (iter = windows; iter; iter = iter->next) { | 463 | for (iter = windows; iter; iter = iter->next) |
639 | 433 | if (iter->data == toplevel) | 464 | { |
640 | 434 | continue; // Skip our own window, we don't have it | 465 | if (iter->data == toplevel) |
641 | 435 | GtkWidget * view = get_descendent (GTK_WIDGET (iter->data), GTK_TYPE_TREE_VIEW); | 466 | continue; // Skip our own window, we don't have it |
642 | 436 | if (view != NULL) { | 467 | GtkWidget * view = get_descendent (GTK_WIDGET (iter->data), |
643 | 437 | GtkTreeModel * tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (view)); | 468 | GTK_TYPE_TREE_VIEW); |
644 | 438 | if (GTK_IS_TREE_MODEL_FILTER (tree_model)) | 469 | if (view != NULL) |
645 | 439 | tree_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (tree_model)); | 470 | { |
646 | 440 | if (tree_model == model) { | 471 | GtkTreeModel * tree_model = |
647 | 441 | g_list_free (windows); | 472 | gtk_tree_view_get_model (GTK_TREE_VIEW (view)); |
648 | 442 | return GTK_TREE_VIEW (view); | 473 | if (GTK_IS_TREE_MODEL_FILTER (tree_model)) |
649 | 443 | } | 474 | tree_model = gtk_tree_model_filter_get_model ( |
650 | 475 | GTK_TREE_MODEL_FILTER (tree_model)); | ||
651 | 476 | if (tree_model == model) | ||
652 | 477 | { | ||
653 | 478 | g_list_free (windows); | ||
654 | 479 | return GTK_TREE_VIEW (view); | ||
655 | 480 | } | ||
656 | 481 | } | ||
657 | 444 | } | 482 | } |
658 | 445 | } | ||
659 | 446 | g_list_free (windows); | 483 | g_list_free (windows); |
660 | 447 | 484 | ||
661 | 448 | return NULL; | 485 | return NULL; |
662 | @@ -453,26 +490,30 @@ | |||
663 | 453 | { | 490 | { |
664 | 454 | if (event->keyval == GDK_KEY_ISO_Enter || | 491 | if (event->keyval == GDK_KEY_ISO_Enter || |
665 | 455 | event->keyval == GDK_KEY_KP_Enter || | 492 | event->keyval == GDK_KEY_KP_Enter || |
675 | 456 | event->keyval == GDK_KEY_Return) { | 493 | event->keyval == GDK_KEY_Return) |
676 | 457 | /* Make sure that user has a selection to choose, otherwise ignore */ | 494 | { |
677 | 458 | GtkTreeModel * model = gtk_entry_completion_get_model (GTK_ENTRY_COMPLETION (completion)); | 495 | /* Make sure that user has a selection to choose, otherwise ignore */ |
678 | 459 | GtkTreeView * view = find_popup_treeview (GTK_WIDGET (entry), model); | 496 | GtkTreeModel * model = gtk_entry_completion_get_model ( |
679 | 460 | if (view == NULL) { | 497 | GTK_ENTRY_COMPLETION (completion)); |
680 | 461 | // Just beep if popup hasn't appeared yet. | 498 | GtkTreeView * view = find_popup_treeview (GTK_WIDGET (entry), model); |
681 | 462 | gtk_widget_error_bell (GTK_WIDGET (entry)); | 499 | if (view == NULL) |
682 | 463 | return TRUE; | 500 | { |
683 | 464 | } | 501 | // Just beep if popup hasn't appeared yet. |
684 | 502 | gtk_widget_error_bell (GTK_WIDGET (entry)); | ||
685 | 503 | return TRUE; | ||
686 | 504 | } | ||
687 | 465 | 505 | ||
696 | 466 | GtkTreeSelection * sel = gtk_tree_view_get_selection (view); | 506 | GtkTreeSelection * sel = gtk_tree_view_get_selection (view); |
697 | 467 | GtkTreeModel * sel_model = NULL; | 507 | GtkTreeModel * sel_model = NULL; |
698 | 468 | if (!gtk_tree_selection_get_selected (sel, &sel_model, NULL)) { | 508 | if (!gtk_tree_selection_get_selected (sel, &sel_model, NULL)) |
699 | 469 | // No selection, we should help them out and select first item in list | 509 | { |
700 | 470 | GtkTreeIter iter; | 510 | // No selection, we should help them out and select first item in list |
701 | 471 | if (gtk_tree_model_get_iter_first (sel_model, &iter)) | 511 | GtkTreeIter iter; |
702 | 472 | gtk_tree_selection_select_iter (sel, &iter); | 512 | if (gtk_tree_model_get_iter_first (sel_model, &iter)) |
703 | 473 | // And fall through to normal handler code | 513 | gtk_tree_selection_select_iter (sel, &iter); |
704 | 514 | // And fall through to normal handler code | ||
705 | 515 | } | ||
706 | 474 | } | 516 | } |
707 | 475 | } | ||
708 | 476 | 517 | ||
709 | 477 | return FALSE; | 518 | return FALSE; |
710 | 478 | } | 519 | } |
711 | @@ -482,32 +523,37 @@ | |||
712 | 482 | { | 523 | { |
713 | 483 | CcTimezoneCompletionPrivate * priv = completion->priv; | 524 | CcTimezoneCompletionPrivate * priv = completion->priv; |
714 | 484 | 525 | ||
727 | 485 | if (priv->queued_request) { | 526 | if (priv->queued_request) |
728 | 486 | g_source_remove (priv->queued_request); | 527 | { |
729 | 487 | priv->queued_request = 0; | 528 | g_source_remove (priv->queued_request); |
730 | 488 | } | 529 | priv->queued_request = 0; |
731 | 489 | if (priv->entry) { | 530 | } |
732 | 490 | g_signal_handler_disconnect (priv->entry, priv->changed_id); | 531 | if (priv->entry) |
733 | 491 | priv->changed_id = 0; | 532 | { |
734 | 492 | g_signal_handler_disconnect (priv->entry, priv->keypress_id); | 533 | g_signal_handler_disconnect (priv->entry, priv->changed_id); |
735 | 493 | priv->keypress_id = 0; | 534 | priv->changed_id = 0; |
736 | 494 | g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *)&priv->entry); | 535 | g_signal_handler_disconnect (priv->entry, priv->keypress_id); |
737 | 495 | gtk_entry_set_completion (priv->entry, NULL); | 536 | priv->keypress_id = 0; |
738 | 496 | } | 537 | g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *)&priv->entry); |
739 | 538 | gtk_entry_set_completion (priv->entry, NULL); | ||
740 | 539 | } | ||
741 | 497 | 540 | ||
742 | 498 | priv->entry = entry; | 541 | priv->entry = entry; |
743 | 499 | 542 | ||
755 | 500 | if (entry) { | 543 | if (entry) |
756 | 501 | guint id = g_signal_connect (entry, "changed", G_CALLBACK (entry_changed), completion); | 544 | { |
757 | 502 | priv->changed_id = id; | 545 | guint id = g_signal_connect (entry, "changed", |
758 | 503 | 546 | G_CALLBACK (entry_changed), completion); | |
759 | 504 | id = g_signal_connect (entry, "key-press-event", G_CALLBACK (entry_keypress), completion); | 547 | priv->changed_id = id; |
760 | 505 | priv->keypress_id = id; | 548 | |
761 | 506 | 549 | id = g_signal_connect (entry, "key-press-event", | |
762 | 507 | g_object_add_weak_pointer (G_OBJECT (entry), (gpointer *)&priv->entry); | 550 | G_CALLBACK (entry_keypress), completion); |
763 | 508 | 551 | priv->keypress_id = id; | |
764 | 509 | gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (completion)); | 552 | |
765 | 510 | } | 553 | g_object_add_weak_pointer (G_OBJECT (entry), (gpointer *)&priv->entry); |
766 | 554 | |||
767 | 555 | gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (completion)); | ||
768 | 556 | } | ||
769 | 511 | } | 557 | } |
770 | 512 | 558 | ||
771 | 513 | static GtkListStore * | 559 | static GtkListStore * |
772 | @@ -525,37 +571,38 @@ | |||
773 | 525 | G_TYPE_STRING); | 571 | G_TYPE_STRING); |
774 | 526 | 572 | ||
775 | 527 | gint i; | 573 | gint i; |
807 | 528 | for (i = 0; i < locations->len; ++i) { | 574 | for (i = 0; i < locations->len; ++i) |
808 | 529 | CcTimezoneLocation * loc = g_ptr_array_index (locations, i); | 575 | { |
809 | 530 | GtkTreeIter iter; | 576 | CcTimezoneLocation * loc = g_ptr_array_index (locations, i); |
810 | 531 | gtk_list_store_append (store, &iter); | 577 | GtkTreeIter iter; |
811 | 532 | 578 | gtk_list_store_append (store, &iter); | |
812 | 533 | gchar * zone; | 579 | |
813 | 534 | gchar * country; | 580 | gchar * zone; |
814 | 535 | gchar * en_name; // FIXME: need something better for non-English locales | 581 | gchar * country; |
815 | 536 | gdouble longitude; | 582 | gchar * en_name; // FIXME: need something better for non-English locales |
816 | 537 | gdouble latitude; | 583 | gdouble longitude; |
817 | 538 | g_object_get (loc, "zone", &zone, "country", &country, "en_name", &en_name, | 584 | gdouble latitude; |
818 | 539 | "longitude", &longitude, "latitude", &latitude, | 585 | g_object_get (loc, "zone", &zone, "country", &country, "en_name", &en_name, |
819 | 540 | NULL); | 586 | "longitude", &longitude, "latitude", &latitude, |
820 | 541 | 587 | NULL); | |
821 | 542 | gchar * longitude_s = g_strdup_printf ("%f", longitude); | 588 | |
822 | 543 | gchar * latitude_s= g_strdup_printf ("%f", latitude); | 589 | gchar * longitude_s = g_strdup_printf ("%f", longitude); |
823 | 544 | 590 | gchar * latitude_s= g_strdup_printf ("%f", latitude); | |
824 | 545 | gtk_list_store_set (store, &iter, | 591 | |
825 | 546 | CC_TIMEZONE_COMPLETION_ZONE, NULL, | 592 | gtk_list_store_set (store, &iter, |
826 | 547 | CC_TIMEZONE_COMPLETION_NAME, en_name, | 593 | CC_TIMEZONE_COMPLETION_ZONE, NULL, |
827 | 548 | CC_TIMEZONE_COMPLETION_COUNTRY, country, | 594 | CC_TIMEZONE_COMPLETION_NAME, en_name, |
828 | 549 | CC_TIMEZONE_COMPLETION_LONGITUDE, longitude_s, | 595 | CC_TIMEZONE_COMPLETION_COUNTRY, country, |
829 | 550 | CC_TIMEZONE_COMPLETION_LATITUDE, latitude_s, | 596 | CC_TIMEZONE_COMPLETION_LONGITUDE, longitude_s, |
830 | 551 | -1); | 597 | CC_TIMEZONE_COMPLETION_LATITUDE, latitude_s, |
831 | 552 | 598 | -1); | |
832 | 553 | g_free (latitude_s); | 599 | |
833 | 554 | g_free (longitude_s); | 600 | g_free (latitude_s); |
834 | 555 | g_free (en_name); | 601 | g_free (longitude_s); |
835 | 556 | g_free (country); | 602 | g_free (en_name); |
836 | 557 | g_free (zone); | 603 | g_free (country); |
837 | 558 | } | 604 | g_free (zone); |
838 | 605 | } | ||
839 | 559 | 606 | ||
840 | 560 | GtkTreeIter iter; | 607 | GtkTreeIter iter; |
841 | 561 | gtk_list_store_append (store, &iter); | 608 | gtk_list_store_append (store, &iter); |
842 | @@ -581,13 +628,14 @@ | |||
843 | 581 | -1); | 628 | -1); |
844 | 582 | 629 | ||
845 | 583 | gchar * user_name; | 630 | gchar * user_name; |
853 | 584 | if (country == NULL || country[0] == 0) { | 631 | if (country == NULL || country[0] == 0) |
854 | 585 | user_name = g_strdup (name); | 632 | { |
855 | 586 | } else if (admin1 == NULL || admin1[0] == 0) { | 633 | user_name = g_strdup (name); |
856 | 587 | user_name = g_strdup_printf ("%s <small>(%s)</small>", name, country); | 634 | } else if (admin1 == NULL || admin1[0] == 0) { |
857 | 588 | } else { | 635 | user_name = g_strdup_printf ("%s <small>(%s)</small>", name, country); |
858 | 589 | user_name = g_strdup_printf ("%s <small>(%s, %s)</small>", name, admin1, country); | 636 | } else { |
859 | 590 | } | 637 | user_name = g_strdup_printf ("%s <small>(%s, %s)</small>", name, admin1, country); |
860 | 638 | } | ||
861 | 591 | 639 | ||
862 | 592 | g_object_set (G_OBJECT (cell), "markup", user_name, NULL); | 640 | g_object_set (G_OBJECT (cell), "markup", user_name, NULL); |
863 | 593 | } | 641 | } |
864 | @@ -641,49 +689,57 @@ | |||
865 | 641 | CcTimezoneCompletion * completion = CC_TIMEZONE_COMPLETION (object); | 689 | CcTimezoneCompletion * completion = CC_TIMEZONE_COMPLETION (object); |
866 | 642 | CcTimezoneCompletionPrivate * priv = completion->priv; | 690 | CcTimezoneCompletionPrivate * priv = completion->priv; |
867 | 643 | 691 | ||
911 | 644 | if (priv->changed_id) { | 692 | if (priv->changed_id) |
912 | 645 | if (priv->entry) | 693 | { |
913 | 646 | g_signal_handler_disconnect (priv->entry, priv->changed_id); | 694 | if (priv->entry) |
914 | 647 | priv->changed_id = 0; | 695 | g_signal_handler_disconnect (priv->entry, priv->changed_id); |
915 | 648 | } | 696 | priv->changed_id = 0; |
916 | 649 | 697 | } | |
917 | 650 | if (priv->keypress_id) { | 698 | |
918 | 651 | if (priv->entry) | 699 | if (priv->keypress_id) |
919 | 652 | g_signal_handler_disconnect (priv->entry, priv->keypress_id); | 700 | { |
920 | 653 | priv->keypress_id = 0; | 701 | if (priv->entry) |
921 | 654 | } | 702 | g_signal_handler_disconnect (priv->entry, priv->keypress_id); |
922 | 655 | 703 | priv->keypress_id = 0; | |
923 | 656 | if (priv->entry != NULL) { | 704 | } |
924 | 657 | gtk_entry_set_completion (priv->entry, NULL); | 705 | |
925 | 658 | g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *)&priv->entry); | 706 | if (priv->entry != NULL) |
926 | 659 | priv->entry = NULL; | 707 | { |
927 | 660 | } | 708 | gtk_entry_set_completion (priv->entry, NULL); |
928 | 661 | 709 | g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *)&priv->entry); | |
929 | 662 | if (priv->initial_model != NULL) { | 710 | priv->entry = NULL; |
930 | 663 | g_object_unref (G_OBJECT (priv->initial_model)); | 711 | } |
931 | 664 | priv->initial_model = NULL; | 712 | |
932 | 665 | } | 713 | if (priv->initial_model != NULL) |
933 | 666 | 714 | { | |
934 | 667 | if (priv->queued_request) { | 715 | g_object_unref (G_OBJECT (priv->initial_model)); |
935 | 668 | g_source_remove (priv->queued_request); | 716 | priv->initial_model = NULL; |
936 | 669 | priv->queued_request = 0; | 717 | } |
937 | 670 | } | 718 | |
938 | 671 | 719 | if (priv->queued_request) | |
939 | 672 | if (priv->cancel != NULL) { | 720 | { |
940 | 673 | g_cancellable_cancel (priv->cancel); | 721 | g_source_remove (priv->queued_request); |
941 | 674 | g_object_unref (priv->cancel); | 722 | priv->queued_request = 0; |
942 | 675 | priv->cancel = NULL; | 723 | } |
943 | 676 | } | 724 | |
944 | 677 | 725 | if (priv->cancel != NULL) | |
945 | 678 | if (priv->request_text != NULL) { | 726 | { |
946 | 679 | g_free (priv->request_text); | 727 | g_cancellable_cancel (priv->cancel); |
947 | 680 | priv->request_text = NULL; | 728 | g_object_unref (priv->cancel); |
948 | 681 | } | 729 | priv->cancel = NULL; |
949 | 682 | 730 | } | |
950 | 683 | if (priv->request_table != NULL) { | 731 | |
951 | 684 | g_hash_table_destroy (priv->request_table); | 732 | if (priv->request_text != NULL) |
952 | 685 | priv->request_table = NULL; | 733 | { |
953 | 686 | } | 734 | g_free (priv->request_text); |
954 | 735 | priv->request_text = NULL; | ||
955 | 736 | } | ||
956 | 737 | |||
957 | 738 | if (priv->request_table != NULL) | ||
958 | 739 | { | ||
959 | 740 | g_hash_table_destroy (priv->request_table); | ||
960 | 741 | priv->request_table = NULL; | ||
961 | 742 | } | ||
962 | 687 | 743 | ||
963 | 688 | return; | 744 | return; |
964 | 689 | } | 745 | } |
965 | 690 | 746 | ||
966 | === modified file 'src/tz.c' | |||
967 | --- src/tz.c 2013-11-05 11:33:58 +0000 | |||
968 | +++ src/tz.c 2013-11-05 11:33:58 +0000 | |||
969 | @@ -50,16 +50,16 @@ | |||
970 | 50 | 50 | ||
971 | 51 | struct _CcTimezoneLocationPrivate | 51 | struct _CcTimezoneLocationPrivate |
972 | 52 | { | 52 | { |
981 | 53 | gchar *country; | 53 | gchar *country; |
982 | 54 | gchar *full_country; | 54 | gchar *full_country; |
983 | 55 | gchar *en_name; | 55 | gchar *en_name; |
984 | 56 | gchar *state; | 56 | gchar *state; |
985 | 57 | gdouble latitude; | 57 | gdouble latitude; |
986 | 58 | gdouble longitude; | 58 | gdouble longitude; |
987 | 59 | gchar *zone; | 59 | gchar *zone; |
988 | 60 | gchar *comment; | 60 | gchar *comment; |
989 | 61 | 61 | ||
991 | 62 | gdouble dist; /* distance to clicked point for comparison */ | 62 | gdouble dist; /* distance to clicked point for comparison */ |
992 | 63 | }; | 63 | }; |
993 | 64 | 64 | ||
994 | 65 | enum { | 65 | enum { |
995 | @@ -82,8 +82,7 @@ | |||
996 | 82 | GParamSpec *pspec) | 82 | GParamSpec *pspec) |
997 | 83 | { | 83 | { |
998 | 84 | CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv; | 84 | CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv; |
1001 | 85 | switch (property_id) | 85 | switch (property_id) { |
1000 | 86 | { | ||
1002 | 87 | case PROP_COUNTRY: | 86 | case PROP_COUNTRY: |
1003 | 88 | g_value_set_string (value, priv->country); | 87 | g_value_set_string (value, priv->country); |
1004 | 89 | break; | 88 | break; |
1005 | @@ -123,8 +122,7 @@ | |||
1006 | 123 | GParamSpec *pspec) | 122 | GParamSpec *pspec) |
1007 | 124 | { | 123 | { |
1008 | 125 | CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv; | 124 | CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv; |
1011 | 126 | switch (property_id) | 125 | switch (property_id) { |
1010 | 127 | { | ||
1012 | 128 | case PROP_COUNTRY: | 126 | case PROP_COUNTRY: |
1013 | 129 | priv->country = g_value_get_string(value); | 127 | priv->country = g_value_get_string(value); |
1014 | 130 | break; | 128 | break; |
1015 | @@ -162,31 +160,31 @@ | |||
1016 | 162 | { | 160 | { |
1017 | 163 | CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv; | 161 | CcTimezoneLocationPrivate *priv = CC_TIMEZONE_LOCATION (object)->priv; |
1018 | 164 | 162 | ||
1020 | 165 | if (priv->country) | 163 | if (priv->country) |
1021 | 166 | { | 164 | { |
1022 | 167 | g_free (priv->country); | 165 | g_free (priv->country); |
1023 | 168 | priv->country = NULL; | 166 | priv->country = NULL; |
1024 | 169 | } | 167 | } |
1025 | 170 | 168 | ||
1027 | 171 | if (priv->full_country) | 169 | if (priv->full_country) |
1028 | 172 | { | 170 | { |
1029 | 173 | g_free (priv->full_country); | 171 | g_free (priv->full_country); |
1030 | 174 | priv->full_country = NULL; | 172 | priv->full_country = NULL; |
1031 | 175 | } | 173 | } |
1032 | 176 | 174 | ||
1034 | 177 | if (priv->state) | 175 | if (priv->state) |
1035 | 178 | { | 176 | { |
1036 | 179 | g_free (priv->state); | 177 | g_free (priv->state); |
1037 | 180 | priv->state = NULL; | 178 | priv->state = NULL; |
1038 | 181 | } | 179 | } |
1039 | 182 | 180 | ||
1041 | 183 | if (priv->zone) | 181 | if (priv->zone) |
1042 | 184 | { | 182 | { |
1043 | 185 | g_free (priv->zone); | 183 | g_free (priv->zone); |
1044 | 186 | priv->zone = NULL; | 184 | priv->zone = NULL; |
1045 | 187 | } | 185 | } |
1046 | 188 | 186 | ||
1048 | 189 | if (priv->comment) | 187 | if (priv->comment) |
1049 | 190 | { | 188 | { |
1050 | 191 | g_free (priv->comment); | 189 | g_free (priv->comment); |
1051 | 192 | priv->comment = NULL; | 190 | priv->comment = NULL; |
1052 | @@ -304,19 +302,20 @@ | |||
1053 | 304 | FILE *fh = fopen (filename, "r"); | 302 | FILE *fh = fopen (filename, "r"); |
1054 | 305 | char buf[4096]; | 303 | char buf[4096]; |
1055 | 306 | 304 | ||
1057 | 307 | if (!fh) { | 305 | if (!fh) |
1058 | 306 | { | ||
1059 | 308 | g_warning ("Could not open *%s*\n", filename); | 307 | g_warning ("Could not open *%s*\n", filename); |
1060 | 309 | fclose (fh); | 308 | fclose (fh); |
1061 | 310 | return; | 309 | return; |
1063 | 311 | } | 310 | } |
1064 | 312 | 311 | ||
1067 | 313 | while (fgets (buf, sizeof(buf), fh)) | 312 | while (fgets (buf, sizeof(buf), fh)) |
1068 | 314 | { | 313 | { |
1069 | 315 | if (*buf == '#') continue; | 314 | if (*buf == '#') continue; |
1070 | 316 | 315 | ||
1071 | 317 | g_strchomp (buf); | 316 | g_strchomp (buf); |
1072 | 318 | func (g_strsplit (buf,"\t", ncolumns), user_data); | 317 | func (g_strsplit (buf,"\t", ncolumns), user_data); |
1074 | 319 | } | 318 | } |
1075 | 320 | 319 | ||
1076 | 321 | fclose (fh); | 320 | fclose (fh); |
1077 | 322 | } | 321 | } |
1078 | @@ -438,22 +437,25 @@ | |||
1079 | 438 | char buf[4096]; | 437 | char buf[4096]; |
1080 | 439 | 438 | ||
1081 | 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); |
1083 | 441 | if (!tz_data_file) { | 440 | if (!tz_data_file) |
1084 | 441 | { | ||
1085 | 442 | g_warning ("Could not get the TimeZone data file name"); | 442 | g_warning ("Could not get the TimeZone data file name"); |
1086 | 443 | return NULL; | 443 | return NULL; |
1088 | 444 | } | 444 | } |
1089 | 445 | 445 | ||
1090 | 446 | admin1_file = tz_data_file_get ("ADMIN1_FILE", ADMIN1_FILE); | 446 | admin1_file = tz_data_file_get ("ADMIN1_FILE", ADMIN1_FILE); |
1092 | 447 | if (!admin1_file) { | 447 | if (!admin1_file) |
1093 | 448 | { | ||
1094 | 448 | g_warning ("Could not get the admin1 data file name"); | 449 | g_warning ("Could not get the admin1 data file name"); |
1095 | 449 | return NULL; | 450 | return NULL; |
1097 | 450 | } | 451 | } |
1098 | 451 | 452 | ||
1099 | 452 | country_file = tz_data_file_get ("COUNTRY_FILE", COUNTRY_FILE); | 453 | country_file = tz_data_file_get ("COUNTRY_FILE", COUNTRY_FILE); |
1101 | 453 | if (!country_file) { | 454 | if (!country_file) |
1102 | 455 | { | ||
1103 | 454 | g_warning ("Could not get the country data file name"); | 456 | g_warning ("Could not get the country data file name"); |
1104 | 455 | return NULL; | 457 | return NULL; |
1106 | 456 | } | 458 | } |
1107 | 457 | 459 | ||
1108 | 458 | GHashTable *stateHash = g_hash_table_new_full (g_str_hash, | 460 | GHashTable *stateHash = g_hash_table_new_full (g_str_hash, |
1109 | 459 | g_str_equal, g_free, g_free); | 461 | g_str_equal, g_free, g_free); |
1110 | @@ -491,9 +493,9 @@ | |||
1111 | 491 | void | 493 | void |
1112 | 492 | tz_db_free (TzDB *db) | 494 | tz_db_free (TzDB *db) |
1113 | 493 | { | 495 | { |
1117 | 494 | g_ptr_array_foreach (db->locations, (GFunc) g_object_unref, NULL); | 496 | g_ptr_array_foreach (db->locations, (GFunc) g_object_unref, NULL); |
1118 | 495 | g_ptr_array_free (db->locations, TRUE); | 497 | g_ptr_array_free (db->locations, TRUE); |
1119 | 496 | g_free (db); | 498 | g_free (db); |
1120 | 497 | } | 499 | } |
1121 | 498 | 500 | ||
1122 | 499 | static gint | 501 | static gint |
1123 | @@ -548,103 +550,103 @@ | |||
1124 | 548 | GPtrArray * | 550 | GPtrArray * |
1125 | 549 | tz_get_locations (TzDB *db) | 551 | tz_get_locations (TzDB *db) |
1126 | 550 | { | 552 | { |
1128 | 551 | return db->locations; | 553 | return db->locations; |
1129 | 552 | } | 554 | } |
1130 | 553 | 555 | ||
1132 | 554 | glong | 556 | glong |
1133 | 555 | tz_location_get_utc_offset (CcTimezoneLocation *loc) | 557 | tz_location_get_utc_offset (CcTimezoneLocation *loc) |
1134 | 556 | { | 558 | { |
1137 | 557 | TzInfo *tz_info; | 559 | TzInfo *tz_info; |
1138 | 558 | glong offset; | 560 | glong offset; |
1139 | 559 | 561 | ||
1144 | 560 | tz_info = tz_info_from_location (loc); | 562 | tz_info = tz_info_from_location (loc); |
1145 | 561 | offset = tz_info->utc_offset; | 563 | offset = tz_info->utc_offset; |
1146 | 562 | tz_info_free (tz_info); | 564 | tz_info_free (tz_info); |
1147 | 563 | return offset; | 565 | return offset; |
1148 | 564 | } | 566 | } |
1149 | 565 | 567 | ||
1150 | 566 | gint | 568 | gint |
1151 | 567 | tz_location_set_locally (CcTimezoneLocation *loc) | 569 | tz_location_set_locally (CcTimezoneLocation *loc) |
1152 | 568 | { | 570 | { |
1166 | 569 | time_t curtime; | 571 | time_t curtime; |
1167 | 570 | struct tm *curzone; | 572 | struct tm *curzone; |
1168 | 571 | gboolean is_dst = FALSE; | 573 | gboolean is_dst = FALSE; |
1169 | 572 | gint correction = 0; | 574 | gint correction = 0; |
1170 | 573 | 575 | ||
1171 | 574 | g_return_val_if_fail (loc != NULL, 0); | 576 | g_return_val_if_fail (loc != NULL, 0); |
1172 | 575 | g_return_val_if_fail (loc->priv->zone != NULL, 0); | 577 | g_return_val_if_fail (loc->priv->zone != NULL, 0); |
1173 | 576 | 578 | ||
1174 | 577 | curtime = time (NULL); | 579 | curtime = time (NULL); |
1175 | 578 | curzone = localtime (&curtime); | 580 | curzone = localtime (&curtime); |
1176 | 579 | is_dst = curzone->tm_isdst; | 581 | is_dst = curzone->tm_isdst; |
1177 | 580 | 582 | ||
1178 | 581 | setenv ("TZ", loc->priv->zone, 1); | 583 | setenv ("TZ", loc->priv->zone, 1); |
1179 | 582 | #if 0 | 584 | #if 0 |
1182 | 583 | curtime = time (NULL); | 585 | curtime = time (NULL); |
1183 | 584 | curzone = localtime (&curtime); | 586 | curzone = localtime (&curtime); |
1184 | 585 | 587 | ||
1191 | 586 | if (!is_dst && curzone->tm_isdst) { | 588 | if (!is_dst && curzone->tm_isdst) { |
1192 | 587 | correction = (60 * 60); | 589 | correction = (60 * 60); |
1193 | 588 | } | 590 | } |
1194 | 589 | else if (is_dst && !curzone->tm_isdst) { | 591 | else if (is_dst && !curzone->tm_isdst) { |
1195 | 590 | correction = 0; | 592 | correction = 0; |
1196 | 591 | } | 593 | } |
1197 | 592 | #endif | 594 | #endif |
1198 | 593 | 595 | ||
1200 | 594 | return correction; | 596 | return correction; |
1201 | 595 | } | 597 | } |
1202 | 596 | 598 | ||
1204 | 597 | TzInfo * | 599 | TzInfo * |
1205 | 598 | tz_info_from_location (CcTimezoneLocation *loc) | 600 | tz_info_from_location (CcTimezoneLocation *loc) |
1206 | 599 | { | 601 | { |
1216 | 600 | TzInfo *tzinfo; | 602 | TzInfo *tzinfo; |
1217 | 601 | time_t curtime; | 603 | time_t curtime; |
1218 | 602 | struct tm *curzone; | 604 | struct tm *curzone; |
1219 | 603 | 605 | ||
1220 | 604 | g_return_val_if_fail (loc != NULL, NULL); | 606 | g_return_val_if_fail (loc != NULL, NULL); |
1221 | 605 | g_return_val_if_fail (loc->priv->zone != NULL, NULL); | 607 | g_return_val_if_fail (loc->priv->zone != NULL, NULL); |
1222 | 606 | 608 | ||
1223 | 607 | setenv ("TZ", loc->priv->zone, 1); | 609 | setenv ("TZ", loc->priv->zone, 1); |
1224 | 608 | 610 | ||
1225 | 609 | #if 0 | 611 | #if 0 |
1227 | 610 | tzset (); | 612 | tzset (); |
1228 | 611 | #endif | 613 | #endif |
1230 | 612 | tzinfo = g_new0 (TzInfo, 1); | 614 | tzinfo = g_new0 (TzInfo, 1); |
1231 | 613 | 615 | ||
1234 | 614 | curtime = time (NULL); | 616 | curtime = time (NULL); |
1235 | 615 | curzone = localtime (&curtime); | 617 | curzone = localtime (&curtime); |
1236 | 616 | 618 | ||
1237 | 617 | #ifndef __sun | 619 | #ifndef __sun |
1246 | 618 | /* Currently this solution doesnt seem to work - I get that */ | 620 | /* Currently this solution doesnt seem to work - I get that */ |
1247 | 619 | /* America/Phoenix uses daylight savings, which is wrong */ | 621 | /* America/Phoenix uses daylight savings, which is wrong */ |
1248 | 620 | tzinfo->tzname_normal = g_strdup (curzone->tm_zone); | 622 | tzinfo->tzname_normal = g_strdup (curzone->tm_zone); |
1249 | 621 | if (curzone->tm_isdst) | 623 | if (curzone->tm_isdst) |
1250 | 622 | tzinfo->tzname_daylight = | 624 | tzinfo->tzname_daylight = |
1251 | 623 | g_strdup (&curzone->tm_zone[curzone->tm_isdst]); | 625 | g_strdup (&curzone->tm_zone[curzone->tm_isdst]); |
1252 | 624 | else | 626 | else |
1253 | 625 | tzinfo->tzname_daylight = NULL; | 627 | tzinfo->tzname_daylight = NULL; |
1254 | 626 | 628 | ||
1256 | 627 | tzinfo->utc_offset = curzone->tm_gmtoff; | 629 | tzinfo->utc_offset = curzone->tm_gmtoff; |
1257 | 628 | #else | 630 | #else |
1261 | 629 | tzinfo->tzname_normal = NULL; | 631 | tzinfo->tzname_normal = NULL; |
1262 | 630 | tzinfo->tzname_daylight = NULL; | 632 | tzinfo->tzname_daylight = NULL; |
1263 | 631 | tzinfo->utc_offset = 0; | 633 | tzinfo->utc_offset = 0; |
1264 | 632 | #endif | 634 | #endif |
1265 | 633 | 635 | ||
1269 | 634 | tzinfo->daylight = curzone->tm_isdst; | 636 | tzinfo->daylight = curzone->tm_isdst; |
1270 | 635 | 637 | ||
1271 | 636 | return tzinfo; | 638 | return tzinfo; |
1272 | 637 | } | 639 | } |
1273 | 638 | 640 | ||
1274 | 639 | 641 | ||
1276 | 640 | void | 642 | void |
1277 | 641 | tz_info_free (TzInfo *tzinfo) | 643 | tz_info_free (TzInfo *tzinfo) |
1278 | 642 | { | 644 | { |
1284 | 643 | g_return_if_fail (tzinfo != NULL); | 645 | g_return_if_fail (tzinfo != NULL); |
1285 | 644 | 646 | ||
1286 | 645 | if (tzinfo->tzname_normal) g_free (tzinfo->tzname_normal); | 647 | if (tzinfo->tzname_normal) g_free (tzinfo->tzname_normal); |
1287 | 646 | if (tzinfo->tzname_daylight) g_free (tzinfo->tzname_daylight); | 648 | if (tzinfo->tzname_daylight) g_free (tzinfo->tzname_daylight); |
1288 | 647 | g_free (tzinfo); | 649 | g_free (tzinfo); |
1289 | 648 | } | 650 | } |
1290 | 649 | 651 | ||
1291 | 650 | /* ----------------- * | 652 | /* ----------------- * |
1292 | @@ -665,38 +667,38 @@ | |||
1293 | 665 | static float | 667 | static float |
1294 | 666 | convert_pos (gchar *pos, int digits) | 668 | convert_pos (gchar *pos, int digits) |
1295 | 667 | { | 669 | { |
1312 | 668 | gchar whole[10]; | 670 | gchar whole[10]; |
1313 | 669 | gchar *fraction; | 671 | gchar *fraction; |
1314 | 670 | gint i; | 672 | gint i; |
1315 | 671 | float t1, t2; | 673 | float t1, t2; |
1316 | 672 | 674 | ||
1317 | 673 | if (!pos || strlen(pos) < 4 || digits > 9) return 0.0; | 675 | if (!pos || strlen(pos) < 4 || digits > 9) return 0.0; |
1318 | 674 | 676 | ||
1319 | 675 | for (i = 0; i < digits + 1; i++) whole[i] = pos[i]; | 677 | for (i = 0; i < digits + 1; i++) whole[i] = pos[i]; |
1320 | 676 | whole[i] = '\0'; | 678 | whole[i] = '\0'; |
1321 | 677 | fraction = pos + digits + 1; | 679 | fraction = pos + digits + 1; |
1322 | 678 | 680 | ||
1323 | 679 | t1 = g_strtod (whole, NULL); | 681 | t1 = g_strtod (whole, NULL); |
1324 | 680 | t2 = g_strtod (fraction, NULL); | 682 | t2 = g_strtod (fraction, NULL); |
1325 | 681 | 683 | ||
1326 | 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)); |
1327 | 683 | else return t1 - t2/pow (10.0, strlen(fraction)); | 685 | else return t1 - t2/pow (10.0, strlen(fraction)); |
1328 | 684 | } | 686 | } |
1329 | 685 | #endif | 687 | #endif |
1330 | 686 | 688 | ||
1332 | 687 | static int | 689 | static int |
1333 | 688 | compare_country_names (const void *a, const void *b) | 690 | compare_country_names (const void *a, const void *b) |
1334 | 689 | { | 691 | { |
1339 | 690 | const CcTimezoneLocation *tza = * (CcTimezoneLocation **) a; | 692 | const CcTimezoneLocation *tza = * (CcTimezoneLocation **) a; |
1340 | 691 | const CcTimezoneLocation *tzb = * (CcTimezoneLocation **) b; | 693 | const CcTimezoneLocation *tzb = * (CcTimezoneLocation **) b; |
1341 | 692 | 694 | ||
1342 | 693 | return strcmp (tza->priv->zone, tzb->priv->zone); | 695 | return strcmp (tza->priv->zone, tzb->priv->zone); |
1343 | 694 | } | 696 | } |
1344 | 695 | 697 | ||
1345 | 696 | 698 | ||
1347 | 697 | static void | 699 | static void |
1348 | 698 | sort_locations_by_country (GPtrArray *locations) | 700 | sort_locations_by_country (GPtrArray *locations) |
1349 | 699 | { | 701 | { |
1352 | 700 | qsort (locations->pdata, locations->len, sizeof (gpointer), | 702 | qsort (locations->pdata, locations->len, sizeof (gpointer), |
1353 | 701 | compare_country_names); | 703 | compare_country_names); |
1354 | 702 | } | 704 | } |