*/
#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
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));
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);
}
}
-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
/* 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
-create_client_cb (GeoclueMaster *master,
- GeoclueMasterClient *client,
- char *object_path,
+create_address_cb (GeoclueMasterClient *client,
+ GeoclueAddress *address,
GError *error,
gpointer userdata)
{
if (error != NULL)
{
- DEBUG ("Failed to create GeoclueMasterClient: %s", error->message);
+ DEBUG ("Failed to create GeoclueAddress: %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;
+ self->priv->gc_address = address;
- if (!set_requirements (self))
- 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 */
- self->priv->gc_position = geoclue_master_client_create_position (
- self->priv->gc_client, &error);
- if (self->priv->gc_position == NULL)
+ 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
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);
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