]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-location-manager.c
Merge branch 'gnome-3-8'
[empathy.git] / libempathy-gtk / empathy-location-manager.c
index 94df2783595341a9b61dda2be53e9a56c942e01f..3a97c94cf49009b50dcd5f48e0fd00447c3441da 100644 (file)
  */
 
 #include "config.h"
-
-#include <string.h>
-#include <time.h>
-
-#include <glib/gi18n-lib.h>
-
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/util.h>
+#include "empathy-location-manager.h"
 
 #include <geoclue/geoclue-master.h>
 
-#include <extensions/extensions.h>
-
-#include "empathy-location-manager.h"
-
-#include "libempathy/empathy-enum-types.h"
-#include "libempathy/empathy-gsettings.h"
-#include "libempathy/empathy-location.h"
-#include "libempathy/empathy-utils.h"
-#include "libempathy/empathy-time.h"
+#include "empathy-gsettings.h"
+#include "empathy-location.h"
+#include "empathy-time.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_LOCATION
-#include "libempathy/empathy-debug.h"
+#include "empathy-debug.h"
 
 /* Seconds before updating the location */
 #define TIMEOUT 10
@@ -189,7 +176,7 @@ publish_to_all_am_prepared_cb (GObject *source_object,
       goto out;
     }
 
-  accounts = tp_account_manager_get_valid_accounts (manager);
+  accounts = tp_account_manager_dup_valid_accounts (manager);
   for (l = accounts; l; l = l->next)
     {
       TpConnection *conn = tp_account_get_connection (TP_ACCOUNT (l->data));
@@ -197,7 +184,7 @@ publish_to_all_am_prepared_cb (GObject *source_object,
       if (conn != NULL)
         publish_location (data->self, conn, data->force_publication);
     }
-  g_list_free (accounts);
+  g_list_free_full (accounts, g_object_unref);
 
 out:
   g_object_unref (data->self);
@@ -433,21 +420,33 @@ initial_position_cb (GeocluePosition *position,
     }
 }
 
-static gboolean
-set_requirements (EmpathyLocationManager *self)
+static void
+set_requirements (EmpathyLocationManager *self,
+    GeoclueSetRequirementsCallback callback)
 {
-  GError *error = NULL;
+  geoclue_master_client_set_requirements_async (self->priv->gc_client,
+      GEOCLUE_ACCURACY_LEVEL_COUNTRY, 0, FALSE, self->priv->resources,
+      callback, self);
+}
 
-  if (!geoclue_master_client_set_requirements (self->priv->gc_client,
-          GEOCLUE_ACCURACY_LEVEL_COUNTRY, 0, FALSE, self->priv->resources,
-          &error))
+static void
+update_resources_set_requirements_cb (GeoclueMasterClient *client,
+    GError *error,
+    gpointer userdata)
+{
+  EmpathyLocationManager *self = userdata;
+
+  if (error != NULL)
     {
       DEBUG ("set_requirements failed: %s", error->message);
       g_error_free (error);
-      return FALSE;
+      return;
     }
 
-  return TRUE;
+  geoclue_address_get_address_async (self->priv->gc_address,
+      initial_address_cb, self);
+  geoclue_position_get_position_async (self->priv->gc_position,
+      initial_position_cb, self);
 }
 
 static void
@@ -461,65 +460,112 @@ update_resources (EmpathyLocationManager *self)
   /* As per Geoclue bug #15126, using NONE results in no address
    * being found as geoclue-manual report an empty address with
    * accuracy = NONE */
-  if (!set_requirements (self))
-    return;
-
-  geoclue_address_get_address_async (self->priv->gc_address,
-      initial_address_cb, self);
-  geoclue_position_get_position_async (self->priv->gc_position,
-      initial_position_cb, self);
+  set_requirements (self, update_resources_set_requirements_cb);
 }
 
 static void
-setup_geoclue (EmpathyLocationManager *self)
+create_address_cb (GeoclueMasterClient *client,
+    GeoclueAddress *address,
+    GError *error,
+    gpointer userdata)
 {
-  GeoclueMaster *master;
-  GError *error = NULL;
-
-  DEBUG ("Setting up Geoclue");
-  master = geoclue_master_get_default ();
-  self->priv->gc_client = geoclue_master_create_client (master, NULL, &error);
-  g_object_unref (master);
+  EmpathyLocationManager *self = userdata;
 
-  if (self->priv->gc_client == NULL)
+  if (error != NULL)
     {
-      DEBUG ("Failed to GeoclueMasterClient: %s", error->message);
+      DEBUG ("Failed to create GeoclueAddress: %s", error->message);
       g_error_free (error);
       return;
     }
 
-  if (!set_requirements (self))
-    return;
+  self->priv->gc_address = address;
 
-  /* Get updated when the position is changes */
-  self->priv->gc_position = geoclue_master_client_create_position (
-      self->priv->gc_client, &error);
-  if (self->priv->gc_position == NULL)
+  g_signal_connect (G_OBJECT (self->priv->gc_address), "address-changed",
+      G_CALLBACK (address_changed_cb), self);
+
+  self->priv->geoclue_is_setup = TRUE;
+}
+
+static void
+create_position_cb (GeoclueMasterClient *client,
+    GeocluePosition *position,
+    GError *error,
+    gpointer userdata)
+{
+  EmpathyLocationManager *self = userdata;
+
+  if (error != NULL)
     {
       DEBUG ("Failed to create GeocluePosition: %s", error->message);
       g_error_free (error);
       return;
     }
 
+  self->priv->gc_position = position;
+
   g_signal_connect (G_OBJECT (self->priv->gc_position), "position-changed",
       G_CALLBACK (position_changed_cb), self);
 
   /* Get updated when the address changes */
-  self->priv->gc_address = geoclue_master_client_create_address (
-      self->priv->gc_client, &error);
-  if (self->priv->gc_address == NULL)
+  geoclue_master_client_create_address_async (self->priv->gc_client,
+      create_address_cb, self);
+}
+
+static void
+create_client_set_requirements_cb (GeoclueMasterClient *client,
+    GError *error,
+    gpointer userdata)
+{
+  EmpathyLocationManager *self = userdata;
+
+  if (error != NULL)
     {
-      DEBUG ("Failed to create GeoclueAddress: %s", error->message);
+      DEBUG ("set_requirements failed: %s", error->message);
       g_error_free (error);
       return;
     }
 
-  g_signal_connect (G_OBJECT (self->priv->gc_address), "address-changed",
-      G_CALLBACK (address_changed_cb), self);
+  /* Get updated when the position is changes */
+  geoclue_master_client_create_position_async (self->priv->gc_client,
+      create_position_cb, self);
+}
 
-  self->priv->geoclue_is_setup = TRUE;
+static void
+create_client_cb (GeoclueMaster *master,
+    GeoclueMasterClient *client,
+    char *object_path,
+    GError *error,
+    gpointer userdata)
+{
+  EmpathyLocationManager *self = userdata;
+
+  if (error != NULL)
+    {
+      DEBUG ("Failed to create GeoclueMasterClient: %s", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  /* @client seems be (transfer full) looking at the geoclue code; yeah for
+   * undocumented API... */
+  self->priv->gc_client = client;
+
+  set_requirements (self, create_client_set_requirements_cb);
 }
 
+static void
+setup_geoclue (EmpathyLocationManager *self)
+{
+  GeoclueMaster *master;
+
+  DEBUG ("Setting up Geoclue");
+  master = geoclue_master_get_default ();
+
+  geoclue_master_create_client_async (master, create_client_cb, self);
+
+  g_object_unref (master);
+ }
+
 static void
 publish_cb (GSettings *gsettings_loc,
             const gchar *key,
@@ -616,7 +662,7 @@ account_manager_prepared_cb (GObject *source_object,
       return;
     }
 
-  accounts = tp_account_manager_get_valid_accounts (account_manager);
+  accounts = tp_account_manager_dup_valid_accounts (account_manager);
   for (l = accounts; l != NULL; l = l->next)
     {
       TpAccount *account = TP_ACCOUNT (l->data);
@@ -624,7 +670,7 @@ account_manager_prepared_cb (GObject *source_object,
       tp_g_signal_connect_object (account, "status-changed",
           G_CALLBACK (new_connection_cb), self, 0);
     }
-  g_list_free (accounts);
+  g_list_free_full (accounts, g_object_unref);
 }
 
 static void