*/
#include "config.h"
-
-#include <string.h>
-#include <time.h>
-
-#include <glib/gi18n.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
GList *accounts, *l;
GError *error = NULL;
- if (!tp_account_manager_prepare_finish (manager, result, &error))
+ if (!tp_proxy_prepare_finish (manager, result, &error))
{
DEBUG ("Failed to prepare account manager: %s", error->message);
g_error_free (error);
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);
data->self = g_object_ref (self);
data->force_publication = force_publication;
- tp_account_manager_prepare_async (self->priv->account_manager, NULL,
+ tp_proxy_prepare_async (self->priv->account_manager, NULL,
publish_to_all_am_prepared_cb, data);
}
g_hash_table_iter_init (&iter, details);
while (g_hash_table_iter_next (&iter, &key, &value))
{
- GValue *new_value;
/* Discard street information if reduced accuracy is on */
if (self->priv->reduce_accuracy &&
!tp_strdiff (key, EMPATHY_LOCATION_STREET))
continue;
- new_value = tp_g_value_slice_new_string (value);
- g_hash_table_insert (self->priv->location, g_strdup (key), new_value);
+ tp_asv_set_string (self->priv->location, key, value);
DEBUG ("\t - %s: %s", (gchar *) key, (gchar *) value);
}
EmpathyLocationManager *self = user_data;
GeoclueAccuracyLevel level;
gdouble mean, horizontal, vertical;
- GValue *new_value;
-
geoclue_accuracy_get_details (accuracy, &level, &horizontal, &vertical);
DEBUG ("New position (accuracy level %d)", level);
/* Truncate at 1 decimal place */
longitude = ((int) (longitude * 10)) / 10.0;
- new_value = tp_g_value_slice_new_double (longitude);
- g_hash_table_insert (self->priv->location,
- g_strdup (EMPATHY_LOCATION_LON), new_value);
+ tp_asv_set_double (self->priv->location, EMPATHY_LOCATION_LON, longitude);
+
DEBUG ("\t - Longitude: %f", longitude);
}
else
/* Truncate at 1 decimal place */
latitude = ((int) (latitude * 10)) / 10.0;
- new_value = tp_g_value_slice_new_double (latitude);
- g_hash_table_replace (self->priv->location,
- g_strdup (EMPATHY_LOCATION_LAT), new_value);
+ tp_asv_set_double (self->priv->location, EMPATHY_LOCATION_LAT, latitude);
+
DEBUG ("\t - Latitude: %f", latitude);
}
else
if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE)
{
- new_value = tp_g_value_slice_new_double (altitude);
- g_hash_table_replace (self->priv->location,
- g_strdup (EMPATHY_LOCATION_ALT), new_value);
+ tp_asv_set_double (self->priv->location, EMPATHY_LOCATION_ALT, altitude);
+
DEBUG ("\t - Altitude: %f", altitude);
}
else
if (level == GEOCLUE_ACCURACY_LEVEL_DETAILED)
{
mean = (horizontal + vertical) / 2.0;
- new_value = tp_g_value_slice_new_double (mean);
- g_hash_table_replace (self->priv->location,
- g_strdup (EMPATHY_LOCATION_ACCURACY), new_value);
+ tp_asv_set_double (self->priv->location, EMPATHY_LOCATION_ACCURACY, mean);
+
DEBUG ("\t - Accuracy: %f", mean);
}
else
}
}
-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
-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,
EmpathyLocationManager *self = user_data;
GError *error = NULL;
- if (!tp_account_manager_prepare_finish (account_manager, result, &error))
+ if (!tp_proxy_prepare_finish (account_manager, result, &error))
{
DEBUG ("Failed to prepare account manager: %s", error->message);
g_error_free (error);
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
self->priv = priv;
priv->geoclue_is_setup = FALSE;
- priv->location = g_hash_table_new_full (g_direct_hash, g_direct_equal,
- g_free, (GDestroyNotify) tp_g_value_slice_free);
+ priv->location = tp_asv_new (NULL, NULL);
priv->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
/* Setup account status callbacks */
priv->account_manager = tp_account_manager_dup ();
- tp_account_manager_prepare_async (priv->account_manager, NULL,
+ tp_proxy_prepare_async (priv->account_manager, NULL,
account_manager_prepared_cb, self);
/* Setup settings status callbacks */