aboutsummaryrefslogtreecommitdiff
path: root/src/datetime-service.c
diff options
context:
space:
mode:
authorkarl-qdh <karl@qdh.org.uk>2011-02-16 14:12:50 +0000
committerkarl-qdh <karl@qdh.org.uk>2011-02-16 14:12:50 +0000
commitaaca2ea0c440491f43bdb0267e82e6f1772a65c7 (patch)
tree674b9d79041824d53f89dce9a68cc86453840786 /src/datetime-service.c
parent97a6b5ae809cd6df25a95207a69da7d93c49bf8e (diff)
parentd0e0e20ee786e3d109306fdf31856cc5f5da925e (diff)
downloadayatana-indicator-datetime-aaca2ea0c440491f43bdb0267e82e6f1772a65c7.tar.gz
ayatana-indicator-datetime-aaca2ea0c440491f43bdb0267e82e6f1772a65c7.tar.bz2
ayatana-indicator-datetime-aaca2ea0c440491f43bdb0267e82e6f1772a65c7.zip
Merged back with trunk
Diffstat (limited to 'src/datetime-service.c')
-rw-r--r--src/datetime-service.c78
1 files changed, 70 insertions, 8 deletions
diff --git a/src/datetime-service.c b/src/datetime-service.c
index 8390652..976e7e6 100644
--- a/src/datetime-service.c
+++ b/src/datetime-service.c
@@ -60,6 +60,8 @@ static void geo_create_client (GeoclueMaster * master, GeoclueMasterClient * cli
static gboolean update_appointment_menu_items (gpointer user_data);
static gboolean update_timezone_menu_items(gpointer user_data);
static void setup_timer (void);
+static void geo_client_invalid (GeoclueMasterClient * client, gpointer user_data);
+static void geo_address_change (GeoclueMasterClient * client, gchar * a, gchar * b, gchar * c, gchar * d, gpointer user_data);
static IndicatorService * service = NULL;
static GMainLoop * mainloop = NULL;
@@ -76,6 +78,10 @@ static DbusmenuMenuitem * geo_location = NULL;
static DbusmenuMenuitem * current_location = NULL;
//static DbusmenuMenuitem * ecal_location = NULL;
static DbusmenuMenuitem * add_appointment = NULL;
+<<<<<<< TREE
+=======
+// static DbusmenuMenuitem * add_location = NULL;
+>>>>>>> MERGE-SOURCE
static GList * appointments = NULL;
static GList * dconflocations = NULL;
GSettings *conf;
@@ -357,6 +363,7 @@ check_for_calendar (gpointer user_data)
return FALSE;
}
+/*
static gboolean
update_timezone_menu_items(gpointer user_data) {
g_debug("Updating timezone menu items");
@@ -415,6 +422,7 @@ update_timezone_menu_items(gpointer user_data) {
// Get the evolution calendar timezone as a place and time and add it
return FALSE;
}
+*/
// Compare function for g_list_sort of ECalComponent objects
static gint
@@ -843,6 +851,41 @@ geo_address_cb (GeoclueAddress * address, int timestamp, GHashTable * addy_data,
return;
}
+/* Clean up the reference we kept to the address and make sure to
+ drop the signals incase someone else has one. */
+static void
+geo_address_clean (void)
+{
+ if (geo_address == NULL) {
+ return;
+ }
+
+ g_signal_handlers_disconnect_by_func(G_OBJECT(geo_address), geo_address_cb, NULL);
+ g_object_unref(G_OBJECT(geo_address));
+
+ geo_address = NULL;
+
+ return;
+}
+
+/* Clean up and remove all signal handlers from the client as we
+ unreference it as well. */
+static void
+geo_client_clean (void)
+{
+ if (geo_master == NULL) {
+ return;
+ }
+
+ g_signal_handlers_disconnect_by_func(G_OBJECT(geo_master), geo_client_invalid, NULL);
+ g_signal_handlers_disconnect_by_func(G_OBJECT(geo_master), geo_address_change, NULL);
+ g_object_unref(G_OBJECT(geo_master));
+
+ geo_master = NULL;
+
+ return;
+}
+
/* Callback from creating the address */
static void
geo_create_address (GeoclueMasterClient * master, GeoclueAddress * address, GError * error, gpointer user_data)
@@ -852,6 +895,12 @@ geo_create_address (GeoclueMasterClient * master, GeoclueAddress * address, GErr
return;
}
+ /* We shouldn't have created a new address if we already had one
+ so this is a warning. But, it really is only a mem-leak so we
+ don't need to error out. */
+ g_warn_if_fail(geo_address == NULL);
+ geo_address_clean();
+
g_debug("Created Geoclue Address");
geo_address = address;
g_object_ref(G_OBJECT(geo_address));
@@ -879,10 +928,12 @@ geo_client_invalid (GeoclueMasterClient * client, gpointer user_data)
{
g_warning("Master client invalid, rebuilding.");
- if (geo_master != NULL) {
- g_object_unref(G_OBJECT(geo_master));
- }
- geo_master = NULL;
+ /* Client changes we can assume the address is now invalid so we
+ need to unreference the one we had. */
+ geo_address_clean();
+
+ /* And our master client is invalid */
+ geo_client_clean();
GeoclueMaster * master = geoclue_master_get_default();
geoclue_master_create_client_async(master, geo_create_client, NULL);
@@ -903,10 +954,9 @@ geo_address_change (GeoclueMasterClient * client, gchar * a, gchar * b, gchar *
{
g_warning("Address provider changed. Let's change");
- if (geo_address != NULL) {
- g_object_unref(G_OBJECT(geo_address));
- }
- geo_address = NULL;
+ /* If the address is supposed to have changed we need to drop the old
+ address before starting to get the new one. */
+ geo_address_clean();
geoclue_master_client_create_address_async(geo_master, geo_create_address, NULL);
@@ -927,8 +977,17 @@ geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar *
g_debug("Created Geoclue client at: %s", path);
geo_master = client;
+
+ if (geo_master != NULL) {
+ g_warning(_("Unable to get a GeoClue client! Geolocation based timezone support will not be available."));
+ return;
+ }
+
g_object_ref(G_OBJECT(geo_master));
+ /* New client, make sure we don't have an address hanging on */
+ geo_address_clean();
+
geoclue_master_client_set_requirements_async(geo_master,
GEOCLUE_ACCURACY_LEVEL_REGION,
0,
@@ -1008,5 +1067,8 @@ main (int argc, char ** argv)
g_object_unref(G_OBJECT(server));
g_object_unref(G_OBJECT(root));
+ geo_address_clean();
+ geo_client_clean();
+
return 0;
}