#include <extensions/extensions.h>
#include "empathy-location-manager.h"
-#include "empathy-conf.h"
#include "libempathy/empathy-enum-types.h"
+#include "libempathy/empathy-gsettings.h"
#include "libempathy/empathy-location.h"
-#include "libempathy/empathy-tp-contact-factory.h"
#include "libempathy/empathy-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_LOCATION
*/
GHashTable *location;
+ GSettings *gsettings_loc;
+
GeoclueResourceFlags resources;
GeoclueMasterClient *gc_client;
GeocluePosition *gc_position;
priv->account_manager = NULL;
}
+ if (priv->gsettings_loc != NULL)
+ {
+ g_object_unref (priv->gsettings_loc);
+ priv->gsettings_loc = NULL;
+ }
+
if (priv->gc_client != NULL)
{
g_object_unref (priv->gc_client);
g_type_class_add_private (object_class, sizeof (EmpathyLocationManagerPriv));
}
+static void
+publish_location_cb (TpConnection *connection,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ if (error != NULL)
+ DEBUG ("Error setting location: %s", error->message);
+}
+
static void
publish_location (EmpathyLocationManager *self,
TpConnection *conn,
{
EmpathyLocationManagerPriv *priv = GET_PRIV (self);
guint connection_status = -1;
- gboolean can_publish;
- EmpathyConf *conf = empathy_conf_get ();
- EmpathyTpContactFactory *factory;
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 (priv->gsettings_loc,
+ EMPATHY_PREFS_LOCATION_PUBLISH))
return;
}
(g_hash_table_size (priv->location) == 0 ? "empty" : ""),
conn);
- factory = empathy_tp_contact_factory_dup_singleton (conn);
- empathy_tp_contact_factory_set_location (factory, priv->location);
- g_object_unref (factory);
+ tp_cli_connection_interface_location_call_set_location (conn, -1,
+ priv->location, publish_location_cb, NULL, NULL, G_OBJECT (self));
}
typedef struct
}
}
+static gboolean
+set_requirements (EmpathyLocationManager *self)
+{
+ EmpathyLocationManagerPriv *priv = GET_PRIV (self);
+ GError *error = NULL;
+
+ if (!geoclue_master_client_set_requirements (priv->gc_client,
+ GEOCLUE_ACCURACY_LEVEL_COUNTRY, 0, FALSE, priv->resources,
+ &error))
+ {
+ DEBUG ("set_requirements failed: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static void
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 (!geoclue_master_client_set_requirements (priv->gc_client,
- GEOCLUE_ACCURACY_LEVEL_COUNTRY, 0, TRUE, priv->resources,
- NULL))
- {
- DEBUG ("set_requirements failed");
- return;
- }
+ if (!set_requirements (self))
+ return;
geoclue_address_get_address_async (priv->gc_address,
initial_address_cb, self);
return;
}
- update_resources (self);
+ if (!set_requirements (self))
+ return;
/* Get updated when the position is changes */
priv->gc_position = geoclue_master_client_create_position (
}
static void
-publish_cb (EmpathyConf *conf,
+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;
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);
}
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);
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)
+ if (g_settings_get_boolean (gsettings_loc, key))
priv->resources |= resource;
else
priv->resources &= ~resource;
}
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;
-
DEBUG ("%s changed", key);
- if (!empathy_conf_get_bool (conf, key, &enabled))
- return;
- priv->reduce_accuracy = enabled;
+ priv->reduce_accuracy = g_settings_get_boolean (gsettings_loc, key);
if (!priv->geoclue_is_setup)
return;
static void
empathy_location_manager_init (EmpathyLocationManager *self)
{
- EmpathyConf *conf;
EmpathyLocationManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
EMPATHY_TYPE_LOCATION_MANAGER, EmpathyLocationManagerPriv);
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->gsettings_loc = g_settings_new (EMPATHY_PREFS_LOCATION_SCHEMA);
/* Setup account status callbacks */
priv->account_manager = tp_account_manager_dup ();
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 *