aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-location-manager.c
diff options
context:
space:
mode:
authorPierre-Luc Beaudoin <pierre-luc.beaudoin@collabora.co.uk>2009-06-01 00:03:36 +0800
committerPierre-Luc Beaudoin <pierre-luc.beaudoin@collabora.co.uk>2009-06-01 23:35:33 +0800
commit861762f5dd3181f47b6dcb03d1c830100d26ad3d (patch)
treee49bd84aa3c37d99ae44b8d5a68d2ac83fae8415 /libempathy-gtk/empathy-location-manager.c
parentf24134c23869a0a1749a7b8f8bc2347011050a4f (diff)
downloadgsoc2013-empathy-861762f5dd3181f47b6dcb03d1c830100d26ad3d.tar
gsoc2013-empathy-861762f5dd3181f47b6dcb03d1c830100d26ad3d.tar.gz
gsoc2013-empathy-861762f5dd3181f47b6dcb03d1c830100d26ad3d.tar.bz2
gsoc2013-empathy-861762f5dd3181f47b6dcb03d1c830100d26ad3d.tar.lz
gsoc2013-empathy-861762f5dd3181f47b6dcb03d1c830100d26ad3d.tar.xz
gsoc2013-empathy-861762f5dd3181f47b6dcb03d1c830100d26ad3d.tar.zst
gsoc2013-empathy-861762f5dd3181f47b6dcb03d1c830100d26ad3d.zip
Reorder functions to get rid of the function declarations
Diffstat (limited to 'libempathy-gtk/empathy-location-manager.c')
-rw-r--r--libempathy-gtk/empathy-location-manager.c455
1 files changed, 214 insertions, 241 deletions
diff --git a/libempathy-gtk/empathy-location-manager.c b/libempathy-gtk/empathy-location-manager.c
index 3da7f7590..3fb3c7b05 100644
--- a/libempathy-gtk/empathy-location-manager.c
+++ b/libempathy-gtk/empathy-location-manager.c
@@ -72,33 +72,6 @@ typedef struct {
guint timeout_id;
} EmpathyLocationManagerPriv;
-static void location_manager_dispose (GObject *object);
-static void location_manager_get_property (GObject *object, guint param_id,
- GValue *value, GParamSpec *pspec);
-static void location_manager_set_property (GObject *object, guint param_id,
- const GValue *value, GParamSpec *pspec);
-static void position_changed_cb (GeocluePosition *position,
- GeocluePositionFields fields, int timestamp, double latitude,
- double longitude, double altitude, GeoclueAccuracy *accuracy,
- gpointer user_data);
-static void address_changed_cb (GeoclueAddress *address, int timestamp,
- GHashTable *details, GeoclueAccuracy *accuracy, gpointer user_data);
-static void setup_geoclue (EmpathyLocationManager *location_manager);
-static void publish_cb (EmpathyConf *conf, const gchar *key,
- gpointer user_data);
-static void update_resources (EmpathyLocationManager *location_manager);
-static void resource_cb (EmpathyConf *conf, const gchar *key,
- gpointer user_data);
-static void accuracy_cb (EmpathyConf *conf, const gchar *key,
- gpointer user_data);
-static void account_connection_changed_cb (EmpathyAccountManager *manager,
- McAccount *account, TpConnectionStatusReason reason,
- TpConnectionStatus current, TpConnectionStatus previous,
- gpointer *location_manager);
-static void publish_to_all_accounts (EmpathyLocationManager *location_manager,
- gboolean force_publication);
-static gboolean publish_on_idle (gpointer user_data);
-
G_DEFINE_TYPE (EmpathyLocationManager, empathy_location_manager, G_TYPE_OBJECT);
static GObject *
@@ -125,6 +98,81 @@ location_manager_constructor (GType type,
}
static void
+location_manager_dispose (GObject *object)
+{
+ EmpathyLocationManagerPriv *priv;
+ priv = GET_PRIV (object);
+
+ 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;
+ }
+
+ G_OBJECT_CLASS (empathy_location_manager_parent_class)->finalize (object);
+}
+
+static void
+location_manager_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyLocationManagerPriv *priv;
+
+ 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;
+
+ 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)
{
GObjectClass *object_class;
@@ -139,17 +187,6 @@ empathy_location_manager_class_init (EmpathyLocationManagerClass *class)
g_type_class_add_private (object_class, sizeof (EmpathyLocationManagerPriv));
}
-static gboolean
-publish_on_idle (gpointer user_data)
-{
- EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
- EmpathyLocationManagerPriv *priv = GET_PRIV (manager);
-
- priv->timeout_id = 0;
- publish_to_all_accounts (manager, TRUE);
- return FALSE;
-}
-
static void
publish_location (EmpathyLocationManager *location_manager,
McAccount *account,
@@ -208,6 +245,17 @@ publish_to_all_accounts (EmpathyLocationManager *location_manager,
mc_accounts_list_free (accounts);
}
+static gboolean
+publish_on_idle (gpointer user_data)
+{
+ EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
+ EmpathyLocationManagerPriv *priv = GET_PRIV (manager);
+
+ priv->timeout_id = 0;
+ publish_to_all_accounts (manager, TRUE);
+ return FALSE;
+}
+
static void
account_connection_changed_cb (EmpathyAccountManager *manager,
McAccount *account,
@@ -225,154 +273,72 @@ account_connection_changed_cb (EmpathyAccountManager *manager,
}
static void
-empathy_location_manager_init (EmpathyLocationManager *location_manager)
-{
- EmpathyConf *conf;
- EmpathyLocationManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (location_manager,
- EMPATHY_TYPE_LOCATION_MANAGER, EmpathyLocationManagerPriv);
-
- location_manager->priv = priv;
- priv->geoclue_is_setup = FALSE;
- priv->mc = empathy_mission_control_dup_singleton ();
- priv->location = g_hash_table_new_full (g_direct_hash, g_direct_equal,
- g_free, (GDestroyNotify) tp_g_value_slice_free);
-
- /* Setup settings status callbacks */
- conf = empathy_conf_get ();
- empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_PUBLISH, publish_cb,
- location_manager);
- empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
- resource_cb, location_manager);
- empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
- resource_cb, location_manager);
- empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
- resource_cb, location_manager);
- empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
- accuracy_cb, location_manager);
-
- resource_cb (conf, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK, location_manager);
- resource_cb (conf, EMPATHY_PREFS_LOCATION_RESOURCE_CELL, location_manager);
- resource_cb (conf, EMPATHY_PREFS_LOCATION_RESOURCE_GPS, location_manager);
- accuracy_cb (conf, EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY, location_manager);
- publish_cb (conf, EMPATHY_PREFS_LOCATION_PUBLISH, location_manager);
-
- /* Setup account status callbacks */
- priv->account_manager = empathy_account_manager_dup_singleton ();
- g_signal_connect (priv->account_manager,
- "account-connection-changed",
- G_CALLBACK (account_connection_changed_cb), location_manager);
-}
-
-static void
-location_manager_dispose (GObject *object)
+update_timestamp (EmpathyLocationManager *location_manager)
{
EmpathyLocationManagerPriv *priv;
- priv = GET_PRIV (object);
-
- 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;
- }
+ priv = GET_PRIV (location_manager);
+ GValue *new_value;
+ gint64 stamp64;
+ time_t timestamp;
- G_OBJECT_CLASS (empathy_location_manager_parent_class)->finalize (object);
+ timestamp = time (NULL);
+ stamp64 = (gint64) timestamp;
+ new_value = tp_g_value_slice_new (G_TYPE_INT64);
+ g_value_set_int64 (new_value, stamp64);
+ g_hash_table_insert (priv->location, g_strdup (EMPATHY_LOCATION_TIMESTAMP),
+ new_value);
+ DEBUG ("\t - Timestamp: %" G_GINT64_FORMAT, stamp64);
}
static void
-location_manager_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec)
+address_changed_cb (GeoclueAddress *address,
+ int timestamp,
+ GHashTable *details,
+ GeoclueAccuracy *accuracy,
+ gpointer location_manager)
{
+ GeoclueAccuracyLevel level;
+ geoclue_accuracy_get_details (accuracy, &level, NULL, NULL);
EmpathyLocationManagerPriv *priv;
+ GHashTableIter iter;
+ gpointer key, value;
- priv = GET_PRIV (object);
-
- switch (param_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- };
-}
+ DEBUG ("New address (accuracy level %d):", level);
-static void
-location_manager_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- EmpathyLocationManagerPriv *priv;
+ priv = GET_PRIV (location_manager);
+ g_hash_table_remove_all (priv->location);
- priv = GET_PRIV (object);
+ if (g_hash_table_size (details) == 0)
+ return;
- switch (param_id)
+ g_hash_table_iter_init (&iter, details);
+ while (g_hash_table_iter_next (&iter, &key, &value))
{
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- };
-}
+ GValue *new_value;
+ /* do something with key and value */
+ /* Discard street information if reduced accuracy is on */
+ if (priv->reduce_accuracy && strcmp (key, EMPATHY_LOCATION_STREET) == 0)
+ continue;
-EmpathyLocationManager *
-empathy_location_manager_dup_singleton (void)
-{
- return EMPATHY_LOCATION_MANAGER (g_object_new (EMPATHY_TYPE_LOCATION_MANAGER,
- NULL));
-}
+ new_value = tp_g_value_slice_new_string (value);
+ g_hash_table_insert (priv->location, g_strdup (key), new_value);
-static void
-update_timestamp (EmpathyLocationManager *location_manager)
-{
- EmpathyLocationManagerPriv *priv;
- priv = GET_PRIV (location_manager);
- GValue *new_value;
- gint64 stamp64;
- time_t timestamp;
+ DEBUG ("\t - %s: %s", (gchar *) key, (gchar *) value);
+ }
- timestamp = time (NULL);
- stamp64 = (gint64) timestamp;
- new_value = tp_g_value_slice_new (G_TYPE_INT64);
- g_value_set_int64 (new_value, stamp64);
- g_hash_table_insert (priv->location, g_strdup (EMPATHY_LOCATION_TIMESTAMP),
- new_value);
- DEBUG ("\t - Timestamp: %" G_GINT64_FORMAT, stamp64);
+
+ update_timestamp (location_manager);
+ if (priv->timeout_id == 0)
+ priv->timeout_id = g_timeout_add_seconds (TIMEOUT, publish_on_idle, location_manager);
}
static void
-initial_position_cb (GeocluePosition *position,
- GeocluePositionFields fields,
- int timestamp,
- double latitude,
- double longitude,
- double altitude,
- GeoclueAccuracy *accuracy,
- GError *error,
- gpointer location_manager)
+initial_address_cb (GeoclueAddress *address,
+ int timestamp,
+ GHashTable *details,
+ GeoclueAccuracy *accuracy,
+ GError *error,
+ gpointer location_manager)
{
if (error)
{
@@ -381,8 +347,7 @@ initial_position_cb (GeocluePosition *position,
}
else
{
- position_changed_cb (position, fields, timestamp, latitude, longitude,
- altitude, accuracy, location_manager);
+ address_changed_cb (address, timestamp, details, accuracy, location_manager);
}
}
@@ -450,12 +415,15 @@ position_changed_cb (GeocluePosition *position,
}
static void
-initial_address_cb (GeoclueAddress *address,
- int timestamp,
- GHashTable *details,
- GeoclueAccuracy *accuracy,
- GError *error,
- gpointer location_manager)
+initial_position_cb (GeocluePosition *position,
+ GeocluePositionFields fields,
+ int timestamp,
+ double latitude,
+ double longitude,
+ double altitude,
+ GeoclueAccuracy *accuracy,
+ GError *error,
+ gpointer location_manager)
{
if (error)
{
@@ -464,50 +432,9 @@ initial_address_cb (GeoclueAddress *address,
}
else
{
- address_changed_cb (address, timestamp, details, accuracy, location_manager);
- }
-}
-
-static void
-address_changed_cb (GeoclueAddress *address,
- int timestamp,
- GHashTable *details,
- GeoclueAccuracy *accuracy,
- gpointer location_manager)
-{
- GeoclueAccuracyLevel level;
- geoclue_accuracy_get_details (accuracy, &level, NULL, NULL);
- EmpathyLocationManagerPriv *priv;
- GHashTableIter iter;
- gpointer key, value;
-
- DEBUG ("New address (accuracy level %d):", level);
-
- priv = GET_PRIV (location_manager);
- g_hash_table_remove_all (priv->location);
-
- if (g_hash_table_size (details) == 0)
- return;
-
- g_hash_table_iter_init (&iter, details);
- while (g_hash_table_iter_next (&iter, &key, &value))
- {
- GValue *new_value;
- /* do something with key and value */
- /* Discard street information if reduced accuracy is on */
- if (priv->reduce_accuracy && strcmp (key, EMPATHY_LOCATION_STREET) == 0)
- continue;
-
- new_value = tp_g_value_slice_new_string (value);
- g_hash_table_insert (priv->location, g_strdup (key), new_value);
-
- DEBUG ("\t - %s: %s", (gchar *) key, (gchar *) value);
+ position_changed_cb (position, fields, timestamp, latitude, longitude,
+ altitude, accuracy, location_manager);
}
-
-
- update_timestamp (location_manager);
- if (priv->timeout_id == 0)
- priv->timeout_id = g_timeout_add_seconds (TIMEOUT, publish_on_idle, location_manager);
}
static void
@@ -623,6 +550,38 @@ publish_cb (EmpathyConf *conf,
}
static void
+resource_cb (EmpathyConf *conf,
+ const gchar *key,
+ gpointer user_data)
+{
+ EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
+ EmpathyLocationManagerPriv *priv;
+ GeoclueResourceFlags resource = 0;
+ gboolean resource_enabled;
+
+ priv = GET_PRIV (manager);
+ DEBUG ("%s changed", key);
+
+ if (!empathy_conf_get_bool (conf, key, &resource_enabled))
+ return;
+
+ if (strcmp (key, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK) == 0)
+ resource = GEOCLUE_RESOURCE_NETWORK;
+ if (strcmp (key, EMPATHY_PREFS_LOCATION_RESOURCE_CELL) == 0)
+ resource = GEOCLUE_RESOURCE_CELL;
+ if (strcmp (key, EMPATHY_PREFS_LOCATION_RESOURCE_GPS) == 0)
+ resource = GEOCLUE_RESOURCE_GPS;
+
+ if (resource_enabled)
+ priv->resources |= resource;
+ else
+ priv->resources &= ~resource;
+
+ if (priv->geoclue_is_setup)
+ update_resources (manager);
+}
+
+static void
accuracy_cb (EmpathyConf *conf,
const gchar *key,
gpointer user_data)
@@ -660,33 +619,47 @@ accuracy_cb (EmpathyConf *conf,
}
static void
-resource_cb (EmpathyConf *conf,
- const gchar *key,
- gpointer user_data)
+empathy_location_manager_init (EmpathyLocationManager *location_manager)
{
- EmpathyLocationManager *manager = EMPATHY_LOCATION_MANAGER (user_data);
- EmpathyLocationManagerPriv *priv;
- GeoclueResourceFlags resource = 0;
- gboolean resource_enabled;
+ EmpathyConf *conf;
+ EmpathyLocationManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (location_manager,
+ EMPATHY_TYPE_LOCATION_MANAGER, EmpathyLocationManagerPriv);
- priv = GET_PRIV (manager);
- DEBUG ("%s changed", key);
+ location_manager->priv = priv;
+ priv->geoclue_is_setup = FALSE;
+ priv->mc = empathy_mission_control_dup_singleton ();
+ priv->location = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ g_free, (GDestroyNotify) tp_g_value_slice_free);
- if (!empathy_conf_get_bool (conf, key, &resource_enabled))
- return;
+ /* Setup settings status callbacks */
+ conf = empathy_conf_get ();
+ empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_PUBLISH, publish_cb,
+ location_manager);
+ empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK,
+ resource_cb, location_manager);
+ empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_RESOURCE_CELL,
+ resource_cb, location_manager);
+ empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_RESOURCE_GPS,
+ resource_cb, location_manager);
+ empathy_conf_notify_add (conf, EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY,
+ accuracy_cb, location_manager);
- if (strcmp (key, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK) == 0)
- resource = GEOCLUE_RESOURCE_NETWORK;
- if (strcmp (key, EMPATHY_PREFS_LOCATION_RESOURCE_CELL) == 0)
- resource = GEOCLUE_RESOURCE_CELL;
- if (strcmp (key, EMPATHY_PREFS_LOCATION_RESOURCE_GPS) == 0)
- resource = GEOCLUE_RESOURCE_GPS;
+ resource_cb (conf, EMPATHY_PREFS_LOCATION_RESOURCE_NETWORK, location_manager);
+ resource_cb (conf, EMPATHY_PREFS_LOCATION_RESOURCE_CELL, location_manager);
+ resource_cb (conf, EMPATHY_PREFS_LOCATION_RESOURCE_GPS, location_manager);
+ accuracy_cb (conf, EMPATHY_PREFS_LOCATION_REDUCE_ACCURACY, location_manager);
+ publish_cb (conf, EMPATHY_PREFS_LOCATION_PUBLISH, location_manager);
- if (resource_enabled)
- priv->resources |= resource;
- else
- priv->resources &= ~resource;
+ /* Setup account status callbacks */
+ priv->account_manager = empathy_account_manager_dup_singleton ();
+ g_signal_connect (priv->account_manager,
+ "account-connection-changed",
+ G_CALLBACK (account_connection_changed_cb), location_manager);
+}
- if (priv->geoclue_is_setup)
- update_resources (manager);
+EmpathyLocationManager *
+empathy_location_manager_dup_singleton (void)
+{
+ return EMPATHY_LOCATION_MANAGER (g_object_new (EMPATHY_TYPE_LOCATION_MANAGER,
+ NULL));
}