*/
#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 "empathy-conf.h"
-
-#include "libempathy/empathy-enum-types.h"
-#include "libempathy/empathy-location.h"
-#include "libempathy/empathy-utils.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
static EmpathyLocationManager *location_manager = NULL;
-#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyLocationManager)
-typedef struct {
+struct _EmpathyLocationManagerPrivate {
gboolean geoclue_is_setup;
/* Contains the location to be sent to accounts. Geoclue is used
* to populate it. This HashTable uses Telepathy's style (string,
*/
GHashTable *location;
+ GSettings *gsettings_loc;
+
GeoclueResourceFlags resources;
GeoclueMasterClient *gc_client;
GeocluePosition *gc_position;
/* The idle id for publish_on_idle func */
guint timeout_id;
-} EmpathyLocationManagerPriv;
+};
G_DEFINE_TYPE (EmpathyLocationManager, empathy_location_manager, G_TYPE_OBJECT);
static void
location_manager_dispose (GObject *object)
{
- EmpathyLocationManagerPriv *priv = GET_PRIV (object);
+ EmpathyLocationManager *self = (EmpathyLocationManager *) object;
void (*dispose) (GObject *) =
G_OBJECT_CLASS (empathy_location_manager_parent_class)->dispose;
- if (priv->account_manager != NULL)
- {
- g_object_unref (priv->account_manager);
- priv->account_manager = NULL;
- }
-
- if (priv->gc_client != NULL)
- {
- g_object_unref (priv->gc_client);
- priv->gc_client = NULL;
- }
-
- if (priv->gc_position != NULL)
- {
- g_object_unref (priv->gc_position);
- priv->gc_position = NULL;
- }
-
- if (priv->gc_address != NULL)
- {
- g_object_unref (priv->gc_address);
- priv->gc_address = NULL;
- }
-
- if (priv->location != NULL)
- {
- g_hash_table_unref (priv->location);
- priv->location = NULL;
- }
+ tp_clear_object (&self->priv->account_manager);
+ tp_clear_object (&self->priv->gsettings_loc);
+ tp_clear_object (&self->priv->gc_client);
+ tp_clear_object (&self->priv->gc_position);
+ tp_clear_object (&self->priv->gc_address);
+ tp_clear_pointer (&self->priv->location, g_hash_table_unref);
if (dispose != NULL)
dispose (object);
}
-static void
-location_manager_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec)
-{
- /*EmpathyLocationManagerPriv *priv = GET_PRIV (object); */
-
- switch (param_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- };
-}
-
-static void
-location_manager_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- /* EmpathyLocationManagerPriv *priv = GET_PRIV (object); */
-
- switch (param_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- };
-}
-
static void
empathy_location_manager_class_init (EmpathyLocationManagerClass *class)
{
object_class->constructor = location_manager_constructor;
object_class->dispose = location_manager_dispose;
- object_class->get_property = location_manager_get_property;
- object_class->set_property = location_manager_set_property;
- g_type_class_add_private (object_class, sizeof (EmpathyLocationManagerPriv));
+ g_type_class_add_private (object_class, sizeof (EmpathyLocationManagerPrivate));
}
static void
TpConnection *conn,
gboolean force_publication)
{
- EmpathyLocationManagerPriv *priv = GET_PRIV (self);
guint connection_status = -1;
- gboolean can_publish;
- EmpathyConf *conf = empathy_conf_get ();
if (!conn)
return;
if (!force_publication)
{
- if (!empathy_conf_get_bool (conf, EMPATHY_PREFS_LOCATION_PUBLISH,
- &can_publish))
- return;
-
- if (!can_publish)
+ if (!g_settings_get_boolean (self->priv->gsettings_loc,
+ EMPATHY_PREFS_LOCATION_PUBLISH))
return;
}
return;
DEBUG ("Publishing %s location to connection %p",
- (g_hash_table_size (priv->location) == 0 ? "empty" : ""),
+ (g_hash_table_size (self->priv->location) == 0 ? "empty" : ""),
conn);
tp_cli_connection_interface_location_call_set_location (conn, -1,
- priv->location, publish_location_cb, NULL, NULL, G_OBJECT (self));
+ self->priv->location, publish_location_cb, NULL, NULL, G_OBJECT (self));
}
typedef struct
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);
publish_to_all_connections (EmpathyLocationManager *self,
gboolean force_publication)
{
- EmpathyLocationManagerPriv *priv = GET_PRIV (self);
PublishToAllData *data;
data = g_slice_new0 (PublishToAllData);
data->self = g_object_ref (self);
data->force_publication = force_publication;
- tp_account_manager_prepare_async (priv->account_manager, NULL,
+ tp_proxy_prepare_async (self->priv->account_manager, NULL,
publish_to_all_am_prepared_cb, data);
}
publish_on_idle (gpointer user_data)
{
EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
- EmpathyLocationManagerPriv *priv = GET_PRIV (manager);
- priv->timeout_id = 0;
+ manager->priv->timeout_id = 0;
publish_to_all_connections (manager, TRUE);
return FALSE;
}
guint reason,
gchar *dbus_error_name,
GHashTable *details,
- gpointer *self)
+ gpointer user_data)
{
- EmpathyLocationManagerPriv *priv = GET_PRIV (self);
+ EmpathyLocationManager *self = user_data;
TpConnection *conn;
conn = tp_account_get_connection (account);
DEBUG ("New connection %p", conn);
/* Don't publish if it is already planned (ie startup) */
- if (priv->timeout_id == 0)
+ if (self->priv->timeout_id == 0)
{
publish_location (EMPATHY_LOCATION_MANAGER (self), conn,
FALSE);
static void
update_timestamp (EmpathyLocationManager *self)
{
- EmpathyLocationManagerPriv *priv= GET_PRIV (self);
- GValue *new_value;
- gint64 stamp64;
- time_t timestamp;
-
- timestamp = time (NULL);
- stamp64 = (gint64) timestamp;
- new_value = tp_g_value_slice_new_int64 (stamp64);
- g_hash_table_insert (priv->location, g_strdup (EMPATHY_LOCATION_TIMESTAMP),
- new_value);
- DEBUG ("\t - Timestamp: %" G_GINT64_FORMAT, stamp64);
+ gint64 timestamp;
+
+ timestamp = empathy_time_get_current ();
+ tp_asv_set_int64 (self->priv->location, EMPATHY_LOCATION_TIMESTAMP,
+ timestamp);
+
+ DEBUG ("\t - Timestamp: %" G_GINT64_FORMAT, timestamp);
}
static void
int timestamp,
GHashTable *details,
GeoclueAccuracy *accuracy,
- gpointer self)
+ gpointer user_data)
{
+ EmpathyLocationManager *self = user_data;
GeoclueAccuracyLevel level;
- EmpathyLocationManagerPriv *priv = GET_PRIV (self);
GHashTableIter iter;
gpointer key, value;
DEBUG ("New address (accuracy level %d):", level);
/* FIXME: Publish accuracy level also considering the position's */
- g_hash_table_remove (priv->location, EMPATHY_LOCATION_STREET);
- g_hash_table_remove (priv->location, EMPATHY_LOCATION_AREA);
- g_hash_table_remove (priv->location, EMPATHY_LOCATION_REGION);
- g_hash_table_remove (priv->location, EMPATHY_LOCATION_COUNTRY);
- g_hash_table_remove (priv->location, EMPATHY_LOCATION_COUNTRY_CODE);
- g_hash_table_remove (priv->location, EMPATHY_LOCATION_POSTAL_CODE);
+ g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_STREET);
+ g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_AREA);
+ g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_REGION);
+ g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_COUNTRY);
+ g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_COUNTRY_CODE);
+ g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_POSTAL_CODE);
if (g_hash_table_size (details) == 0)
{
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 (priv->reduce_accuracy &&
+ 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 (priv->location, g_strdup (key), new_value);
+ tp_asv_set_string (self->priv->location, key, value);
DEBUG ("\t - %s: %s", (gchar *) key, (gchar *) value);
}
update_timestamp (self);
- if (priv->timeout_id == 0)
- priv->timeout_id = g_timeout_add_seconds (TIMEOUT, publish_on_idle, self);
+ if (self->priv->timeout_id == 0)
+ self->priv->timeout_id = g_timeout_add_seconds (TIMEOUT, publish_on_idle,
+ self);
}
static void
double longitude,
double altitude,
GeoclueAccuracy *accuracy,
- gpointer self)
+ gpointer user_data)
{
- EmpathyLocationManagerPriv *priv = GET_PRIV (self);
+ 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);
if (fields & GEOCLUE_POSITION_FIELDS_LONGITUDE)
{
- if (priv->reduce_accuracy)
+ if (self->priv->reduce_accuracy)
/* Truncate at 1 decimal place */
longitude = ((int) (longitude * 10)) / 10.0;
- new_value = tp_g_value_slice_new_double (longitude);
- g_hash_table_insert (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
{
- g_hash_table_remove (priv->location, EMPATHY_LOCATION_LON);
+ g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_LON);
}
if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE)
{
- if (priv->reduce_accuracy)
+ if (self->priv->reduce_accuracy)
/* Truncate at 1 decimal place */
latitude = ((int) (latitude * 10)) / 10.0;
- new_value = tp_g_value_slice_new_double (latitude);
- g_hash_table_replace (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
{
- g_hash_table_remove (priv->location, EMPATHY_LOCATION_LAT);
+ g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_LAT);
}
if (fields & GEOCLUE_POSITION_FIELDS_ALTITUDE)
{
- new_value = tp_g_value_slice_new_double (altitude);
- g_hash_table_replace (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
{
- g_hash_table_remove (priv->location, EMPATHY_LOCATION_ALT);
+ g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_ALT);
}
if (level == GEOCLUE_ACCURACY_LEVEL_DETAILED)
{
mean = (horizontal + vertical) / 2.0;
- new_value = tp_g_value_slice_new_double (mean);
- g_hash_table_replace (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
{
- g_hash_table_remove (priv->location, EMPATHY_LOCATION_ACCURACY);
+ g_hash_table_remove (self->priv->location, EMPATHY_LOCATION_ACCURACY);
}
update_timestamp (self);
- if (priv->timeout_id == 0)
- priv->timeout_id = g_timeout_add_seconds (TIMEOUT, publish_on_idle, self);
+ if (self->priv->timeout_id == 0)
+ self->priv->timeout_id = g_timeout_add_seconds (TIMEOUT, publish_on_idle,
+ self);
}
static void
}
static void
-update_resources (EmpathyLocationManager *self)
+set_requirements (EmpathyLocationManager *self,
+ GeoclueSetRequirementsCallback callback)
{
- EmpathyLocationManagerPriv *priv = GET_PRIV (self);
-
- DEBUG ("Updating resources %d", priv->resources);
+ geoclue_master_client_set_requirements_async (self->priv->gc_client,
+ GEOCLUE_ACCURACY_LEVEL_COUNTRY, 0, FALSE, self->priv->resources,
+ callback, self);
+}
- if (!priv->geoclue_is_setup)
- return;
+static void
+update_resources_set_requirements_cb (GeoclueMasterClient *client,
+ GError *error,
+ gpointer userdata)
+{
+ EmpathyLocationManager *self = userdata;
- /* As per Geoclue bug #15126, using NONE results in no address
- * being found as geoclue-manual report an empty address with
- * accuracy = NONE */
- if (!geoclue_master_client_set_requirements (priv->gc_client,
- GEOCLUE_ACCURACY_LEVEL_COUNTRY, 0, FALSE, priv->resources,
- NULL))
+ if (error != NULL)
{
- DEBUG ("set_requirements failed");
+ DEBUG ("set_requirements failed: %s", error->message);
+ g_error_free (error);
return;
}
- geoclue_address_get_address_async (priv->gc_address,
+ geoclue_address_get_address_async (self->priv->gc_address,
initial_address_cb, self);
- geoclue_position_get_position_async (priv->gc_position,
+ geoclue_position_get_position_async (self->priv->gc_position,
initial_position_cb, self);
}
static void
-setup_geoclue (EmpathyLocationManager *self)
+update_resources (EmpathyLocationManager *self)
{
- EmpathyLocationManagerPriv *priv = GET_PRIV (self);
+ DEBUG ("Updating resources %d", self->priv->resources);
- GeoclueMaster *master;
- GError *error = NULL;
+ if (!self->priv->geoclue_is_setup)
+ return;
- DEBUG ("Setting up Geoclue");
- master = geoclue_master_get_default ();
- priv->gc_client = geoclue_master_create_client (master, NULL, &error);
- g_object_unref (master);
+ /* As per Geoclue bug #15126, using NONE results in no address
+ * being found as geoclue-manual report an empty address with
+ * accuracy = NONE */
+ set_requirements (self, update_resources_set_requirements_cb);
+}
+
+static void
+create_address_cb (GeoclueMasterClient *client,
+ GeoclueAddress *address,
+ GError *error,
+ gpointer userdata)
+{
+ EmpathyLocationManager *self = userdata;
- if (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 (!geoclue_master_client_set_requirements (priv->gc_client,
- GEOCLUE_ACCURACY_LEVEL_COUNTRY, 0, FALSE, priv->resources,
- NULL))
- {
- DEBUG ("set_requirements failed");
- return;
- }
+ self->priv->gc_address = address;
- /* Get updated when the position is changes */
- priv->gc_position = geoclue_master_client_create_position (
- priv->gc_client, &error);
- if (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;
}
- g_signal_connect (G_OBJECT (priv->gc_position), "position-changed",
+ 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 */
- priv->gc_address = geoclue_master_client_create_address (
- priv->gc_client, &error);
- if (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 (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);
+}
+
+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;
- priv->geoclue_is_setup = TRUE;
+ set_requirements (self, create_client_set_requirements_cb);
}
static void
-publish_cb (EmpathyConf *conf,
+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,
gpointer user_data)
{
- EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
- EmpathyLocationManagerPriv *priv = GET_PRIV (manager);
- gboolean can_publish;
+ EmpathyLocationManager *self = EMPATHY_LOCATION_MANAGER (user_data);
DEBUG ("Publish Conf changed");
-
- if (!empathy_conf_get_bool (conf, key, &can_publish))
- return;
-
- if (can_publish)
+ if (g_settings_get_boolean (gsettings_loc, key))
{
- if (!priv->geoclue_is_setup)
- setup_geoclue (manager);
+ if (!self->priv->geoclue_is_setup)
+ setup_geoclue (self);
/* if still not setup than the init failed */
- if (!priv->geoclue_is_setup)
+ if (!self->priv->geoclue_is_setup)
return;
- geoclue_address_get_address_async (priv->gc_address,
- initial_address_cb, manager);
- geoclue_position_get_position_async (priv->gc_position,
- initial_position_cb, manager);
+ 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);
}
else
{
/* As per XEP-0080: send an empty location to have remove current
* location from the servers
*/
- g_hash_table_remove_all (priv->location);
- publish_to_all_connections (manager, TRUE);
+ g_hash_table_remove_all (self->priv->location);
+ publish_to_all_connections (self, TRUE);
}
}
static void
-resource_cb (EmpathyConf *conf,
+resource_cb (GSettings *gsettings_loc,
const gchar *key,
gpointer user_data)
{
- EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
- EmpathyLocationManagerPriv *priv = GET_PRIV (manager);
+ EmpathyLocationManager *self = EMPATHY_LOCATION_MANAGER (user_data);
GeoclueResourceFlags resource = 0;
- gboolean resource_enabled;
DEBUG ("%s changed", key);
- if (!empathy_conf_get_bool (conf, key, &resource_enabled))
- return;
-
if (!tp_strdiff (key, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK))
resource = GEOCLUE_RESOURCE_NETWORK;
if (!tp_strdiff (key, EMPATHY_PREFS_LOCATION_RESOURCE_CELL))
if (!tp_strdiff (key, EMPATHY_PREFS_LOCATION_RESOURCE_GPS))
resource = GEOCLUE_RESOURCE_GPS;
- if (resource_enabled)
- priv->resources |= resource;
+ if (g_settings_get_boolean (gsettings_loc, key))
+ self->priv->resources |= resource;
else
- priv->resources &= ~resource;
+ self->priv->resources &= ~resource;
- if (priv->geoclue_is_setup)
- update_resources (manager);
+ if (self->priv->geoclue_is_setup)
+ update_resources (self);
}
static void
-accuracy_cb (EmpathyConf *conf,
+accuracy_cb (GSettings *gsettings_loc,
const gchar *key,
gpointer user_data)
{
- EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
- EmpathyLocationManagerPriv *priv = GET_PRIV (manager);
-
- gboolean enabled;
+ EmpathyLocationManager *self = EMPATHY_LOCATION_MANAGER (user_data);
DEBUG ("%s changed", key);
- if (!empathy_conf_get_bool (conf, key, &enabled))
- return;
- priv->reduce_accuracy = enabled;
+ self->priv->reduce_accuracy = g_settings_get_boolean (gsettings_loc, key);
- if (!priv->geoclue_is_setup)
+ if (!self->priv->geoclue_is_setup)
return;
- geoclue_address_get_address_async (priv->gc_address,
- initial_address_cb, manager);
- geoclue_position_get_position_async (priv->gc_position,
- initial_position_cb, manager);
+ 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
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
empathy_location_manager_init (EmpathyLocationManager *self)
{
- EmpathyConf *conf;
- EmpathyLocationManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
- EMPATHY_TYPE_LOCATION_MANAGER, EmpathyLocationManagerPriv);
+ EmpathyLocationManagerPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ EMPATHY_TYPE_LOCATION_MANAGER, EmpathyLocationManagerPrivate);
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 */
- conf = empathy_conf_get ();
- empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_PUBLISH, publish_cb,
+ g_signal_connect (priv->gsettings_loc,
+ "changed::" EMPATHY_PREFS_LOCATION_PUBLISH,
+ G_CALLBACK (publish_cb), self);
+ g_signal_connect (priv->gsettings_loc,
+ "changed::" EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
+ G_CALLBACK (resource_cb), self);
+ g_signal_connect (priv->gsettings_loc,
+ "changed::" EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
+ G_CALLBACK (resource_cb), self);
+ g_signal_connect (priv->gsettings_loc,
+ "changed::" EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
+ G_CALLBACK (resource_cb), self);
+ g_signal_connect (priv->gsettings_loc,
+ "changed::" EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
+ G_CALLBACK (accuracy_cb), self);
+
+ resource_cb (priv->gsettings_loc, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
+ self);
+ resource_cb (priv->gsettings_loc, EMPATHY_PREFS_LOCATION_RESOURCE_CELL, self);
+ resource_cb (priv->gsettings_loc, EMPATHY_PREFS_LOCATION_RESOURCE_GPS, self);
+ accuracy_cb (priv->gsettings_loc, EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
self);
- empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
- resource_cb, self);
- empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
- resource_cb, self);
- empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
- resource_cb, self);
- empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
- accuracy_cb, self);
-
- resource_cb (conf, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK, self);
- resource_cb (conf, EMPATHY_PREFS_LOCATION_RESOURCE_CELL, self);
- resource_cb (conf, EMPATHY_PREFS_LOCATION_RESOURCE_GPS, self);
- accuracy_cb (conf, EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY, self);
- publish_cb (conf, EMPATHY_PREFS_LOCATION_PUBLISH, self);
+ publish_cb (priv->gsettings_loc, EMPATHY_PREFS_LOCATION_PUBLISH, self);
}
EmpathyLocationManager *