Merge lp:~ted/indicator-datetime/geoclue-timezone-support into lp:indicator-datetime/0.3

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
Reviewer Review Type Date Requested Status
Cody Russell (community) Approve
Review via email: mp+39144@code.launchpad.net

Description of the change

Add support for looking for timezones in GeoClue

To post a comment you must log in.
Revision history for this message
Cody Russell (bratsche) wrote :

Wicked.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configure.ac'
--- configure.ac 2010-09-09 17:43:03 +0000
+++ configure.ac 2010-10-22 13:41:00 +0000
@@ -38,12 +38,16 @@
38GIO_REQUIRED_VERSION=2.25.1138GIO_REQUIRED_VERSION=2.25.11
39# Note: the GIO check below also ensures the proper glib with gsettings support is present39# Note: the GIO check below also ensures the proper glib with gsettings support is present
40INDICATOR_DISPLAY_OBJECTS=0.1.1040INDICATOR_DISPLAY_OBJECTS=0.1.10
41GEOCLUE_REQUIRED_VERSION=0.12.0
42OOBS_REQUIRED_VERSION=2.31.0
4143
42PKG_CHECK_MODULES(INDICATOR, indicator >= $INDICATOR_REQUIRED_VERSION44PKG_CHECK_MODULES(INDICATOR, indicator >= $INDICATOR_REQUIRED_VERSION
43 dbusmenu-glib >= $DBUSMENUGLIB_REQUIRED_VERSION45 dbusmenu-glib >= $DBUSMENUGLIB_REQUIRED_VERSION
44 dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION46 dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION
45 libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS47 libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS
46 gio-2.0 >= $GIO_REQUIRED_VERSION)48 gio-2.0 >= $GIO_REQUIRED_VERSION
49 geoclue >= $GEOCLUE_REQUIRED_VERSION
50 liboobs-1 >= $OOBS_REQUIRED_VERSION)
4751
48AC_SUBST(INDICATOR_CFLAGS)52AC_SUBST(INDICATOR_CFLAGS)
49AC_SUBST(INDICATOR_LIBS)53AC_SUBST(INDICATOR_LIBS)
5054
=== modified file 'src/datetime-service.c'
--- src/datetime-service.c 2010-10-06 13:28:50 +0000
+++ src/datetime-service.c 2010-10-22 13:41:00 +0000
@@ -30,9 +30,15 @@
30#include <libdbusmenu-glib/client.h>30#include <libdbusmenu-glib/client.h>
31#include <libdbusmenu-glib/menuitem.h>31#include <libdbusmenu-glib/menuitem.h>
3232
33#include <geoclue/geoclue-master.h>
34#include <geoclue/geoclue-master-client.h>
35
36#include <oobs/oobs-timeconfig.h>
37
33#include "datetime-interface.h"38#include "datetime-interface.h"
34#include "dbus-shared.h"39#include "dbus-shared.h"
3540
41static void geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data);
36static void setup_timer (void);42static void setup_timer (void);
3743
38static IndicatorService * service = NULL;44static IndicatorService * service = NULL;
@@ -40,11 +46,122 @@
40static DbusmenuServer * server = NULL;46static DbusmenuServer * server = NULL;
41static DbusmenuMenuitem * root = NULL;47static DbusmenuMenuitem * root = NULL;
42static DatetimeInterface * dbus = NULL;48static DatetimeInterface * dbus = NULL;
49static gchar * current_timezone = NULL;
4350
44/* Global Items */51/* Global Items */
45static DbusmenuMenuitem * date = NULL;52static DbusmenuMenuitem * date = NULL;
46static DbusmenuMenuitem * calendar = NULL;53static DbusmenuMenuitem * calendar = NULL;
47static DbusmenuMenuitem * settings = NULL;54static DbusmenuMenuitem * settings = NULL;
55static DbusmenuMenuitem * tzchange = NULL;
56
57/* Geoclue trackers */
58static GeoclueMasterClient * geo_master = NULL;
59static GeoclueAddress * geo_address = NULL;
60static gchar * geo_timezone = NULL;
61
62/* Check to see if our timezones are the same */
63static void
64check_timezone_sync (void) {
65 gboolean in_sync = FALSE;
66
67 if (geo_timezone == NULL) {
68 in_sync = TRUE;
69 }
70
71 if (current_timezone == NULL) {
72 in_sync = TRUE;
73 }
74
75 if (!in_sync && g_strcmp0(geo_timezone, current_timezone) == 0) {
76 in_sync = TRUE;
77 }
78
79 if (in_sync) {
80 g_debug("Timezones in sync");
81 } else {
82 g_debug("Timezones are different");
83 }
84
85 if (tzchange != NULL) {
86 if (in_sync) {
87 dbusmenu_menuitem_property_set_bool(tzchange, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
88 } else {
89 gchar * label = g_strdup_printf(_("Change timezone to: %s"), geo_timezone);
90
91 dbusmenu_menuitem_property_set(tzchange, DBUSMENU_MENUITEM_PROP_LABEL, label);
92 dbusmenu_menuitem_property_set_bool(tzchange, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
93
94 g_free(label);
95 }
96 }
97
98 return;
99}
100
101/* Update the current timezone */
102static void
103update_current_timezone (void) {
104 /* Clear old data */
105 if (current_timezone != NULL) {
106 g_free(current_timezone);
107 current_timezone = NULL;
108 }
109
110 GError * error = NULL;
111 gchar * tempzone = NULL;
112 if (!g_file_get_contents(TIMEZONE_FILE, &tempzone, NULL, &error)) {
113 g_warning("Unable to read timezone file '" TIMEZONE_FILE "': %s", error->message);
114 g_error_free(error);
115 return;
116 }
117
118 /* This shouldn't happen, so let's make it a big boom! */
119 g_return_if_fail(tempzone != NULL);
120
121 /* Note: this really makes sense as strstrip works in place
122 so we end up with something a little odd without the dup
123 so we have the dup to make sure everything is as expected
124 for everyone else. */
125 current_timezone = g_strdup(g_strstrip(tempzone));
126 g_free(tempzone);
127
128 g_debug("System timezone is: %s", current_timezone);
129
130 check_timezone_sync();
131
132 return;
133}
134
135/* See how our timezone setting went */
136static void
137quick_set_tz_cb (OobsObject * obj, OobsResult result, gpointer user_data)
138{
139 if (result == OOBS_RESULT_OK) {
140 g_debug("Timezone set");
141 } else {
142 g_warning("Unable to quick set timezone");
143 }
144 return;
145}
146
147/* Set the timezone to the Geoclue discovered one */
148static void
149quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, const gchar *command)
150{
151 g_debug("Quick setting timezone to: %s", geo_timezone);
152
153 g_return_if_fail(geo_timezone != NULL);
154
155 OobsObject * obj = oobs_time_config_get();
156 g_return_if_fail(obj != NULL);
157
158 OobsTimeConfig * timeconfig = OOBS_TIME_CONFIG(obj);
159 oobs_time_config_set_timezone(timeconfig, geo_timezone);
160
161 oobs_object_commit_async(obj, quick_set_tz_cb, NULL);
162
163 return;
164}
48165
49/* Updates the label in the date menuitem */166/* Updates the label in the date menuitem */
50static gboolean167static gboolean
@@ -160,6 +277,13 @@
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);
161 dbusmenu_menuitem_child_append(root, separator);278 dbusmenu_menuitem_child_append(root, separator);
162279
280 tzchange = dbusmenu_menuitem_new();
281 dbusmenu_menuitem_property_set(tzchange, DBUSMENU_MENUITEM_PROP_LABEL, "Set specific timezone");
282 dbusmenu_menuitem_property_set_bool(tzchange, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
283 g_signal_connect(G_OBJECT(tzchange), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL);
284 dbusmenu_menuitem_child_append(root, tzchange);
285 check_timezone_sync();
286
163 settings = dbusmenu_menuitem_new();287 settings = dbusmenu_menuitem_new();
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..."));
165 /* insensitive until we check for available apps */289 /* insensitive until we check for available apps */
@@ -175,6 +299,7 @@
175static void299static void
176timezone_changed (GFileMonitor * monitor, GFile * file, GFile * otherfile, GFileMonitorEvent event, gpointer user_data)300timezone_changed (GFileMonitor * monitor, GFile * file, GFile * otherfile, GFileMonitorEvent event, gpointer user_data)
177{301{
302 update_current_timezone();
178 datetime_interface_update(DATETIME_INTERFACE(user_data));303 datetime_interface_update(DATETIME_INTERFACE(user_data));
179 update_datetime(NULL);304 update_datetime(NULL);
180 setup_timer();305 setup_timer();
@@ -233,6 +358,134 @@
233 return;358 return;
234}359}
235360
361/* Callback from getting the address */
362static void
363geo_address_cb (GeoclueAddress * address, int timestamp, GHashTable * addy_data, GeoclueAccuracy * accuracy, GError * error, gpointer user_data)
364{
365 if (error != NULL) {
366 g_warning("Unable to get Geoclue address: %s", error->message);
367 return;
368 }
369
370 g_debug("Geoclue timezone is: %s", (gchar *)g_hash_table_lookup(addy_data, "timezone"));
371
372 if (geo_timezone != NULL) {
373 g_free(geo_timezone);
374 geo_timezone = NULL;
375 }
376
377 gpointer tz_hash = g_hash_table_lookup(addy_data, "timezone");
378 if (tz_hash != NULL) {
379 geo_timezone = g_strdup((gchar *)tz_hash);
380 }
381
382 check_timezone_sync();
383
384 return;
385}
386
387/* Callback from creating the address */
388static void
389geo_create_address (GeoclueMasterClient * master, GeoclueAddress * address, GError * error, gpointer user_data)
390{
391 if (error != NULL) {
392 g_warning("Unable to create GeoClue address: %s", error->message);
393 return;
394 }
395
396 g_debug("Created Geoclue Address");
397 geo_address = address;
398 g_object_ref(G_OBJECT(geo_address));
399
400 geoclue_address_get_address_async(geo_address, geo_address_cb, NULL);
401
402 g_signal_connect(G_OBJECT(address), "address-changed", G_CALLBACK(geo_address_cb), NULL);
403
404 return;
405}
406
407/* Callback from setting requirements */
408static void
409geo_req_set (GeoclueMasterClient * master, GError * error, gpointer user_data)
410{
411 if (error != NULL) {
412 g_warning("Unable to set Geoclue requirements: %s", error->message);
413 }
414 return;
415}
416
417/* Client is killing itself rather oddly */
418static void
419geo_client_invalid (GeoclueMasterClient * client, gpointer user_data)
420{
421 g_warning("Master client invalid, rebuilding.");
422
423 if (geo_master != NULL) {
424 g_object_unref(G_OBJECT(geo_master));
425 }
426 geo_master = NULL;
427
428 GeoclueMaster * master = geoclue_master_get_default();
429 geoclue_master_create_client_async(master, geo_create_client, NULL);
430
431 if (geo_timezone != NULL) {
432 g_free(geo_timezone);
433 geo_timezone = NULL;
434 }
435
436 check_timezone_sync();
437
438 return;
439}
440
441/* Address provider changed, we need to get that one */
442static void
443geo_address_change (GeoclueMasterClient * client, gchar * a, gchar * b, gchar * c, gchar * d, gpointer user_data)
444{
445 g_warning("Address provider changed. Let's change");
446
447 if (geo_address != NULL) {
448 g_object_unref(G_OBJECT(geo_address));
449 }
450 geo_address = NULL;
451
452 geoclue_master_client_create_address_async(geo_master, geo_create_address, NULL);
453
454 if (geo_timezone != NULL) {
455 g_free(geo_timezone);
456 geo_timezone = NULL;
457 }
458
459 check_timezone_sync();
460
461 return;
462}
463
464/* Callback from creating the client */
465static void
466geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data)
467{
468 g_debug("Created Geoclue client at: %s", path);
469
470 geo_master = client;
471 g_object_ref(G_OBJECT(geo_master));
472
473 geoclue_master_client_set_requirements_async(geo_master,
474 GEOCLUE_ACCURACY_LEVEL_REGION,
475 0,
476 FALSE,
477 GEOCLUE_RESOURCE_ALL,
478 geo_req_set,
479 NULL);
480
481 geoclue_master_client_create_address_async(geo_master, geo_create_address, NULL);
482
483 g_signal_connect(G_OBJECT(client), "invalidated", G_CALLBACK(geo_client_invalid), NULL);
484 g_signal_connect(G_OBJECT(client), "address-provider-changed", G_CALLBACK(geo_address_change), NULL);
485
486 return;
487}
488
236/* Repsonds to the service object saying it's time to shutdown.489/* Repsonds to the service object saying it's time to shutdown.
237 It stops the mainloop. */490 It stops the mainloop. */
238static void 491static void
@@ -259,12 +512,19 @@
259 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);512 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
260 textdomain (GETTEXT_PACKAGE);513 textdomain (GETTEXT_PACKAGE);
261514
515 /* Cache the timezone */
516 update_current_timezone();
517
262 /* Building the base menu */518 /* Building the base menu */
263 server = dbusmenu_server_new(MENU_OBJ);519 server = dbusmenu_server_new(MENU_OBJ);
264 root = dbusmenu_menuitem_new();520 root = dbusmenu_menuitem_new();
265 dbusmenu_server_set_root(server, root);521 dbusmenu_server_set_root(server, root);
266 build_menus(root);522 build_menus(root);
267523
524 /* Setup geoclue */
525 GeoclueMaster * master = geoclue_master_get_default();
526 geoclue_master_create_client_async(master, geo_create_client, NULL);
527
268 /* Setup dbus interface */528 /* Setup dbus interface */
269 dbus = g_object_new(DATETIME_INTERFACE_TYPE, NULL);529 dbus = g_object_new(DATETIME_INTERFACE_TYPE, NULL);
270530
@@ -277,6 +537,7 @@
277 mainloop = g_main_loop_new(NULL, FALSE);537 mainloop = g_main_loop_new(NULL, FALSE);
278 g_main_loop_run(mainloop);538 g_main_loop_run(mainloop);
279539
540 g_object_unref(G_OBJECT(master));
280 g_object_unref(G_OBJECT(dbus));541 g_object_unref(G_OBJECT(dbus));
281 g_object_unref(G_OBJECT(service));542 g_object_unref(G_OBJECT(service));
282 g_object_unref(G_OBJECT(server));543 g_object_unref(G_OBJECT(server));

Subscribers

People subscribed via source and target branches

to all changes: