Merge lp:~ted/indicator-datetime/geoclue-timezone-support into lp:indicator-datetime/0.3
- geoclue-timezone-support
- Merge into trunk
Proposed by
Ted Gould
Status: | Merged |
---|---|
Merged at revision: | 25 |
Proposed branch: | lp:~ted/indicator-datetime/geoclue-timezone-support |
Merge into: | lp:indicator-datetime/0.3 |
Diff against target: |
349 lines (+266/-1) 2 files modified
configure.ac (+5/-1) src/datetime-service.c (+261/-0) |
To merge this branch: | bzr merge lp:~ted/indicator-datetime/geoclue-timezone-support |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Cody Russell (community) | Approve | ||
Review via email: mp+39144@code.launchpad.net |
Commit message
Description of the change
Add support for looking for timezones in GeoClue
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 'configure.ac' | |||
2 | --- configure.ac 2010-09-09 17:43:03 +0000 | |||
3 | +++ configure.ac 2010-10-22 13:41:00 +0000 | |||
4 | @@ -38,12 +38,16 @@ | |||
5 | 38 | GIO_REQUIRED_VERSION=2.25.11 | 38 | GIO_REQUIRED_VERSION=2.25.11 |
6 | 39 | # Note: the GIO check below also ensures the proper glib with gsettings support is present | 39 | # Note: the GIO check below also ensures the proper glib with gsettings support is present |
7 | 40 | INDICATOR_DISPLAY_OBJECTS=0.1.10 | 40 | INDICATOR_DISPLAY_OBJECTS=0.1.10 |
8 | 41 | GEOCLUE_REQUIRED_VERSION=0.12.0 | ||
9 | 42 | OOBS_REQUIRED_VERSION=2.31.0 | ||
10 | 41 | 43 | ||
11 | 42 | PKG_CHECK_MODULES(INDICATOR, indicator >= $INDICATOR_REQUIRED_VERSION | 44 | PKG_CHECK_MODULES(INDICATOR, indicator >= $INDICATOR_REQUIRED_VERSION |
12 | 43 | dbusmenu-glib >= $DBUSMENUGLIB_REQUIRED_VERSION | 45 | dbusmenu-glib >= $DBUSMENUGLIB_REQUIRED_VERSION |
13 | 44 | dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION | 46 | dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION |
14 | 45 | libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS | 47 | libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS |
16 | 46 | gio-2.0 >= $GIO_REQUIRED_VERSION) | 48 | gio-2.0 >= $GIO_REQUIRED_VERSION |
17 | 49 | geoclue >= $GEOCLUE_REQUIRED_VERSION | ||
18 | 50 | liboobs-1 >= $OOBS_REQUIRED_VERSION) | ||
19 | 47 | 51 | ||
20 | 48 | AC_SUBST(INDICATOR_CFLAGS) | 52 | AC_SUBST(INDICATOR_CFLAGS) |
21 | 49 | AC_SUBST(INDICATOR_LIBS) | 53 | AC_SUBST(INDICATOR_LIBS) |
22 | 50 | 54 | ||
23 | === modified file 'src/datetime-service.c' | |||
24 | --- src/datetime-service.c 2010-10-06 13:28:50 +0000 | |||
25 | +++ src/datetime-service.c 2010-10-22 13:41:00 +0000 | |||
26 | @@ -30,9 +30,15 @@ | |||
27 | 30 | #include <libdbusmenu-glib/client.h> | 30 | #include <libdbusmenu-glib/client.h> |
28 | 31 | #include <libdbusmenu-glib/menuitem.h> | 31 | #include <libdbusmenu-glib/menuitem.h> |
29 | 32 | 32 | ||
30 | 33 | #include <geoclue/geoclue-master.h> | ||
31 | 34 | #include <geoclue/geoclue-master-client.h> | ||
32 | 35 | |||
33 | 36 | #include <oobs/oobs-timeconfig.h> | ||
34 | 37 | |||
35 | 33 | #include "datetime-interface.h" | 38 | #include "datetime-interface.h" |
36 | 34 | #include "dbus-shared.h" | 39 | #include "dbus-shared.h" |
37 | 35 | 40 | ||
38 | 41 | static void geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data); | ||
39 | 36 | static void setup_timer (void); | 42 | static void setup_timer (void); |
40 | 37 | 43 | ||
41 | 38 | static IndicatorService * service = NULL; | 44 | static IndicatorService * service = NULL; |
42 | @@ -40,11 +46,122 @@ | |||
43 | 40 | static DbusmenuServer * server = NULL; | 46 | static DbusmenuServer * server = NULL; |
44 | 41 | static DbusmenuMenuitem * root = NULL; | 47 | static DbusmenuMenuitem * root = NULL; |
45 | 42 | static DatetimeInterface * dbus = NULL; | 48 | static DatetimeInterface * dbus = NULL; |
46 | 49 | static gchar * current_timezone = NULL; | ||
47 | 43 | 50 | ||
48 | 44 | /* Global Items */ | 51 | /* Global Items */ |
49 | 45 | static DbusmenuMenuitem * date = NULL; | 52 | static DbusmenuMenuitem * date = NULL; |
50 | 46 | static DbusmenuMenuitem * calendar = NULL; | 53 | static DbusmenuMenuitem * calendar = NULL; |
51 | 47 | static DbusmenuMenuitem * settings = NULL; | 54 | static DbusmenuMenuitem * settings = NULL; |
52 | 55 | static DbusmenuMenuitem * tzchange = NULL; | ||
53 | 56 | |||
54 | 57 | /* Geoclue trackers */ | ||
55 | 58 | static GeoclueMasterClient * geo_master = NULL; | ||
56 | 59 | static GeoclueAddress * geo_address = NULL; | ||
57 | 60 | static gchar * geo_timezone = NULL; | ||
58 | 61 | |||
59 | 62 | /* Check to see if our timezones are the same */ | ||
60 | 63 | static void | ||
61 | 64 | check_timezone_sync (void) { | ||
62 | 65 | gboolean in_sync = FALSE; | ||
63 | 66 | |||
64 | 67 | if (geo_timezone == NULL) { | ||
65 | 68 | in_sync = TRUE; | ||
66 | 69 | } | ||
67 | 70 | |||
68 | 71 | if (current_timezone == NULL) { | ||
69 | 72 | in_sync = TRUE; | ||
70 | 73 | } | ||
71 | 74 | |||
72 | 75 | if (!in_sync && g_strcmp0(geo_timezone, current_timezone) == 0) { | ||
73 | 76 | in_sync = TRUE; | ||
74 | 77 | } | ||
75 | 78 | |||
76 | 79 | if (in_sync) { | ||
77 | 80 | g_debug("Timezones in sync"); | ||
78 | 81 | } else { | ||
79 | 82 | g_debug("Timezones are different"); | ||
80 | 83 | } | ||
81 | 84 | |||
82 | 85 | if (tzchange != NULL) { | ||
83 | 86 | if (in_sync) { | ||
84 | 87 | dbusmenu_menuitem_property_set_bool(tzchange, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); | ||
85 | 88 | } else { | ||
86 | 89 | gchar * label = g_strdup_printf(_("Change timezone to: %s"), geo_timezone); | ||
87 | 90 | |||
88 | 91 | dbusmenu_menuitem_property_set(tzchange, DBUSMENU_MENUITEM_PROP_LABEL, label); | ||
89 | 92 | dbusmenu_menuitem_property_set_bool(tzchange, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); | ||
90 | 93 | |||
91 | 94 | g_free(label); | ||
92 | 95 | } | ||
93 | 96 | } | ||
94 | 97 | |||
95 | 98 | return; | ||
96 | 99 | } | ||
97 | 100 | |||
98 | 101 | /* Update the current timezone */ | ||
99 | 102 | static void | ||
100 | 103 | update_current_timezone (void) { | ||
101 | 104 | /* Clear old data */ | ||
102 | 105 | if (current_timezone != NULL) { | ||
103 | 106 | g_free(current_timezone); | ||
104 | 107 | current_timezone = NULL; | ||
105 | 108 | } | ||
106 | 109 | |||
107 | 110 | GError * error = NULL; | ||
108 | 111 | gchar * tempzone = NULL; | ||
109 | 112 | if (!g_file_get_contents(TIMEZONE_FILE, &tempzone, NULL, &error)) { | ||
110 | 113 | g_warning("Unable to read timezone file '" TIMEZONE_FILE "': %s", error->message); | ||
111 | 114 | g_error_free(error); | ||
112 | 115 | return; | ||
113 | 116 | } | ||
114 | 117 | |||
115 | 118 | /* This shouldn't happen, so let's make it a big boom! */ | ||
116 | 119 | g_return_if_fail(tempzone != NULL); | ||
117 | 120 | |||
118 | 121 | /* Note: this really makes sense as strstrip works in place | ||
119 | 122 | so we end up with something a little odd without the dup | ||
120 | 123 | so we have the dup to make sure everything is as expected | ||
121 | 124 | for everyone else. */ | ||
122 | 125 | current_timezone = g_strdup(g_strstrip(tempzone)); | ||
123 | 126 | g_free(tempzone); | ||
124 | 127 | |||
125 | 128 | g_debug("System timezone is: %s", current_timezone); | ||
126 | 129 | |||
127 | 130 | check_timezone_sync(); | ||
128 | 131 | |||
129 | 132 | return; | ||
130 | 133 | } | ||
131 | 134 | |||
132 | 135 | /* See how our timezone setting went */ | ||
133 | 136 | static void | ||
134 | 137 | quick_set_tz_cb (OobsObject * obj, OobsResult result, gpointer user_data) | ||
135 | 138 | { | ||
136 | 139 | if (result == OOBS_RESULT_OK) { | ||
137 | 140 | g_debug("Timezone set"); | ||
138 | 141 | } else { | ||
139 | 142 | g_warning("Unable to quick set timezone"); | ||
140 | 143 | } | ||
141 | 144 | return; | ||
142 | 145 | } | ||
143 | 146 | |||
144 | 147 | /* Set the timezone to the Geoclue discovered one */ | ||
145 | 148 | static void | ||
146 | 149 | quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, const gchar *command) | ||
147 | 150 | { | ||
148 | 151 | g_debug("Quick setting timezone to: %s", geo_timezone); | ||
149 | 152 | |||
150 | 153 | g_return_if_fail(geo_timezone != NULL); | ||
151 | 154 | |||
152 | 155 | OobsObject * obj = oobs_time_config_get(); | ||
153 | 156 | g_return_if_fail(obj != NULL); | ||
154 | 157 | |||
155 | 158 | OobsTimeConfig * timeconfig = OOBS_TIME_CONFIG(obj); | ||
156 | 159 | oobs_time_config_set_timezone(timeconfig, geo_timezone); | ||
157 | 160 | |||
158 | 161 | oobs_object_commit_async(obj, quick_set_tz_cb, NULL); | ||
159 | 162 | |||
160 | 163 | return; | ||
161 | 164 | } | ||
162 | 48 | 165 | ||
163 | 49 | /* Updates the label in the date menuitem */ | 166 | /* Updates the label in the date menuitem */ |
164 | 50 | static gboolean | 167 | static gboolean |
165 | @@ -160,6 +277,13 @@ | |||
166 | 160 | dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); | 277 | dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); |
167 | 161 | dbusmenu_menuitem_child_append(root, separator); | 278 | dbusmenu_menuitem_child_append(root, separator); |
168 | 162 | 279 | ||
169 | 280 | tzchange = dbusmenu_menuitem_new(); | ||
170 | 281 | dbusmenu_menuitem_property_set(tzchange, DBUSMENU_MENUITEM_PROP_LABEL, "Set specific timezone"); | ||
171 | 282 | dbusmenu_menuitem_property_set_bool(tzchange, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); | ||
172 | 283 | g_signal_connect(G_OBJECT(tzchange), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL); | ||
173 | 284 | dbusmenu_menuitem_child_append(root, tzchange); | ||
174 | 285 | check_timezone_sync(); | ||
175 | 286 | |||
176 | 163 | settings = dbusmenu_menuitem_new(); | 287 | settings = dbusmenu_menuitem_new(); |
177 | 164 | dbusmenu_menuitem_property_set (settings, DBUSMENU_MENUITEM_PROP_LABEL, _("Time & Date Settings...")); | 288 | dbusmenu_menuitem_property_set (settings, DBUSMENU_MENUITEM_PROP_LABEL, _("Time & Date Settings...")); |
178 | 165 | /* insensitive until we check for available apps */ | 289 | /* insensitive until we check for available apps */ |
179 | @@ -175,6 +299,7 @@ | |||
180 | 175 | static void | 299 | static void |
181 | 176 | timezone_changed (GFileMonitor * monitor, GFile * file, GFile * otherfile, GFileMonitorEvent event, gpointer user_data) | 300 | timezone_changed (GFileMonitor * monitor, GFile * file, GFile * otherfile, GFileMonitorEvent event, gpointer user_data) |
182 | 177 | { | 301 | { |
183 | 302 | update_current_timezone(); | ||
184 | 178 | datetime_interface_update(DATETIME_INTERFACE(user_data)); | 303 | datetime_interface_update(DATETIME_INTERFACE(user_data)); |
185 | 179 | update_datetime(NULL); | 304 | update_datetime(NULL); |
186 | 180 | setup_timer(); | 305 | setup_timer(); |
187 | @@ -233,6 +358,134 @@ | |||
188 | 233 | return; | 358 | return; |
189 | 234 | } | 359 | } |
190 | 235 | 360 | ||
191 | 361 | /* Callback from getting the address */ | ||
192 | 362 | static void | ||
193 | 363 | geo_address_cb (GeoclueAddress * address, int timestamp, GHashTable * addy_data, GeoclueAccuracy * accuracy, GError * error, gpointer user_data) | ||
194 | 364 | { | ||
195 | 365 | if (error != NULL) { | ||
196 | 366 | g_warning("Unable to get Geoclue address: %s", error->message); | ||
197 | 367 | return; | ||
198 | 368 | } | ||
199 | 369 | |||
200 | 370 | g_debug("Geoclue timezone is: %s", (gchar *)g_hash_table_lookup(addy_data, "timezone")); | ||
201 | 371 | |||
202 | 372 | if (geo_timezone != NULL) { | ||
203 | 373 | g_free(geo_timezone); | ||
204 | 374 | geo_timezone = NULL; | ||
205 | 375 | } | ||
206 | 376 | |||
207 | 377 | gpointer tz_hash = g_hash_table_lookup(addy_data, "timezone"); | ||
208 | 378 | if (tz_hash != NULL) { | ||
209 | 379 | geo_timezone = g_strdup((gchar *)tz_hash); | ||
210 | 380 | } | ||
211 | 381 | |||
212 | 382 | check_timezone_sync(); | ||
213 | 383 | |||
214 | 384 | return; | ||
215 | 385 | } | ||
216 | 386 | |||
217 | 387 | /* Callback from creating the address */ | ||
218 | 388 | static void | ||
219 | 389 | geo_create_address (GeoclueMasterClient * master, GeoclueAddress * address, GError * error, gpointer user_data) | ||
220 | 390 | { | ||
221 | 391 | if (error != NULL) { | ||
222 | 392 | g_warning("Unable to create GeoClue address: %s", error->message); | ||
223 | 393 | return; | ||
224 | 394 | } | ||
225 | 395 | |||
226 | 396 | g_debug("Created Geoclue Address"); | ||
227 | 397 | geo_address = address; | ||
228 | 398 | g_object_ref(G_OBJECT(geo_address)); | ||
229 | 399 | |||
230 | 400 | geoclue_address_get_address_async(geo_address, geo_address_cb, NULL); | ||
231 | 401 | |||
232 | 402 | g_signal_connect(G_OBJECT(address), "address-changed", G_CALLBACK(geo_address_cb), NULL); | ||
233 | 403 | |||
234 | 404 | return; | ||
235 | 405 | } | ||
236 | 406 | |||
237 | 407 | /* Callback from setting requirements */ | ||
238 | 408 | static void | ||
239 | 409 | geo_req_set (GeoclueMasterClient * master, GError * error, gpointer user_data) | ||
240 | 410 | { | ||
241 | 411 | if (error != NULL) { | ||
242 | 412 | g_warning("Unable to set Geoclue requirements: %s", error->message); | ||
243 | 413 | } | ||
244 | 414 | return; | ||
245 | 415 | } | ||
246 | 416 | |||
247 | 417 | /* Client is killing itself rather oddly */ | ||
248 | 418 | static void | ||
249 | 419 | geo_client_invalid (GeoclueMasterClient * client, gpointer user_data) | ||
250 | 420 | { | ||
251 | 421 | g_warning("Master client invalid, rebuilding."); | ||
252 | 422 | |||
253 | 423 | if (geo_master != NULL) { | ||
254 | 424 | g_object_unref(G_OBJECT(geo_master)); | ||
255 | 425 | } | ||
256 | 426 | geo_master = NULL; | ||
257 | 427 | |||
258 | 428 | GeoclueMaster * master = geoclue_master_get_default(); | ||
259 | 429 | geoclue_master_create_client_async(master, geo_create_client, NULL); | ||
260 | 430 | |||
261 | 431 | if (geo_timezone != NULL) { | ||
262 | 432 | g_free(geo_timezone); | ||
263 | 433 | geo_timezone = NULL; | ||
264 | 434 | } | ||
265 | 435 | |||
266 | 436 | check_timezone_sync(); | ||
267 | 437 | |||
268 | 438 | return; | ||
269 | 439 | } | ||
270 | 440 | |||
271 | 441 | /* Address provider changed, we need to get that one */ | ||
272 | 442 | static void | ||
273 | 443 | geo_address_change (GeoclueMasterClient * client, gchar * a, gchar * b, gchar * c, gchar * d, gpointer user_data) | ||
274 | 444 | { | ||
275 | 445 | g_warning("Address provider changed. Let's change"); | ||
276 | 446 | |||
277 | 447 | if (geo_address != NULL) { | ||
278 | 448 | g_object_unref(G_OBJECT(geo_address)); | ||
279 | 449 | } | ||
280 | 450 | geo_address = NULL; | ||
281 | 451 | |||
282 | 452 | geoclue_master_client_create_address_async(geo_master, geo_create_address, NULL); | ||
283 | 453 | |||
284 | 454 | if (geo_timezone != NULL) { | ||
285 | 455 | g_free(geo_timezone); | ||
286 | 456 | geo_timezone = NULL; | ||
287 | 457 | } | ||
288 | 458 | |||
289 | 459 | check_timezone_sync(); | ||
290 | 460 | |||
291 | 461 | return; | ||
292 | 462 | } | ||
293 | 463 | |||
294 | 464 | /* Callback from creating the client */ | ||
295 | 465 | static void | ||
296 | 466 | geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data) | ||
297 | 467 | { | ||
298 | 468 | g_debug("Created Geoclue client at: %s", path); | ||
299 | 469 | |||
300 | 470 | geo_master = client; | ||
301 | 471 | g_object_ref(G_OBJECT(geo_master)); | ||
302 | 472 | |||
303 | 473 | geoclue_master_client_set_requirements_async(geo_master, | ||
304 | 474 | GEOCLUE_ACCURACY_LEVEL_REGION, | ||
305 | 475 | 0, | ||
306 | 476 | FALSE, | ||
307 | 477 | GEOCLUE_RESOURCE_ALL, | ||
308 | 478 | geo_req_set, | ||
309 | 479 | NULL); | ||
310 | 480 | |||
311 | 481 | geoclue_master_client_create_address_async(geo_master, geo_create_address, NULL); | ||
312 | 482 | |||
313 | 483 | g_signal_connect(G_OBJECT(client), "invalidated", G_CALLBACK(geo_client_invalid), NULL); | ||
314 | 484 | g_signal_connect(G_OBJECT(client), "address-provider-changed", G_CALLBACK(geo_address_change), NULL); | ||
315 | 485 | |||
316 | 486 | return; | ||
317 | 487 | } | ||
318 | 488 | |||
319 | 236 | /* Repsonds to the service object saying it's time to shutdown. | 489 | /* Repsonds to the service object saying it's time to shutdown. |
320 | 237 | It stops the mainloop. */ | 490 | It stops the mainloop. */ |
321 | 238 | static void | 491 | static void |
322 | @@ -259,12 +512,19 @@ | |||
323 | 259 | bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); | 512 | bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); |
324 | 260 | textdomain (GETTEXT_PACKAGE); | 513 | textdomain (GETTEXT_PACKAGE); |
325 | 261 | 514 | ||
326 | 515 | /* Cache the timezone */ | ||
327 | 516 | update_current_timezone(); | ||
328 | 517 | |||
329 | 262 | /* Building the base menu */ | 518 | /* Building the base menu */ |
330 | 263 | server = dbusmenu_server_new(MENU_OBJ); | 519 | server = dbusmenu_server_new(MENU_OBJ); |
331 | 264 | root = dbusmenu_menuitem_new(); | 520 | root = dbusmenu_menuitem_new(); |
332 | 265 | dbusmenu_server_set_root(server, root); | 521 | dbusmenu_server_set_root(server, root); |
333 | 266 | build_menus(root); | 522 | build_menus(root); |
334 | 267 | 523 | ||
335 | 524 | /* Setup geoclue */ | ||
336 | 525 | GeoclueMaster * master = geoclue_master_get_default(); | ||
337 | 526 | geoclue_master_create_client_async(master, geo_create_client, NULL); | ||
338 | 527 | |||
339 | 268 | /* Setup dbus interface */ | 528 | /* Setup dbus interface */ |
340 | 269 | dbus = g_object_new(DATETIME_INTERFACE_TYPE, NULL); | 529 | dbus = g_object_new(DATETIME_INTERFACE_TYPE, NULL); |
341 | 270 | 530 | ||
342 | @@ -277,6 +537,7 @@ | |||
343 | 277 | mainloop = g_main_loop_new(NULL, FALSE); | 537 | mainloop = g_main_loop_new(NULL, FALSE); |
344 | 278 | g_main_loop_run(mainloop); | 538 | g_main_loop_run(mainloop); |
345 | 279 | 539 | ||
346 | 540 | g_object_unref(G_OBJECT(master)); | ||
347 | 280 | g_object_unref(G_OBJECT(dbus)); | 541 | g_object_unref(G_OBJECT(dbus)); |
348 | 281 | g_object_unref(G_OBJECT(service)); | 542 | g_object_unref(G_OBJECT(service)); |
349 | 282 | g_object_unref(G_OBJECT(server)); | 543 | g_object_unref(G_OBJECT(server)); |
Wicked.