[empathy] location-manager: use the self->priv pattern



commit 2f5f9eb6d3d4185f9a20c158567ccdd969df52d9
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Tue Apr 19 17:25:15 2011 +0200

    location-manager: use the self->priv pattern

 libempathy-gtk/empathy-location-manager.c |  194 ++++++++++++++---------------
 libempathy-gtk/empathy-location-manager.h |    3 +-
 2 files changed, 94 insertions(+), 103 deletions(-)
---
diff --git a/libempathy-gtk/empathy-location-manager.c b/libempathy-gtk/empathy-location-manager.c
index b4d9f67..93dda08 100644
--- a/libempathy-gtk/empathy-location-manager.c
+++ b/libempathy-gtk/empathy-location-manager.c
@@ -48,8 +48,7 @@
 #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,
@@ -69,7 +68,7 @@ typedef struct {
 
     /* The idle id for publish_on_idle func */
     guint timeout_id;
-} EmpathyLocationManagerPriv;
+};
 
 G_DEFINE_TYPE (EmpathyLocationManager, empathy_location_manager, G_TYPE_OBJECT);
 
@@ -99,16 +98,16 @@ location_manager_constructor (GType type,
 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;
 
-  tp_clear_object (&priv->account_manager);
-  tp_clear_object (&priv->gsettings_loc);
-  tp_clear_object (&priv->gc_client);
-  tp_clear_object (&priv->gc_position);
-  tp_clear_object (&priv->gc_address);
-  tp_clear_pointer (&priv->location, g_hash_table_unref);
+  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);
@@ -124,7 +123,7 @@ empathy_location_manager_class_init (EmpathyLocationManagerClass *class)
   object_class->constructor = location_manager_constructor;
   object_class->dispose = location_manager_dispose;
 
-  g_type_class_add_private (object_class, sizeof (EmpathyLocationManagerPriv));
+  g_type_class_add_private (object_class, sizeof (EmpathyLocationManagerPrivate));
 }
 
 static void
@@ -142,7 +141,6 @@ publish_location (EmpathyLocationManager *self,
     TpConnection *conn,
     gboolean force_publication)
 {
-  EmpathyLocationManagerPriv *priv = GET_PRIV (self);
   guint connection_status = -1;
 
   if (!conn)
@@ -150,7 +148,7 @@ publish_location (EmpathyLocationManager *self,
 
   if (!force_publication)
     {
-      if (!g_settings_get_boolean (priv->gsettings_loc,
+      if (!g_settings_get_boolean (self->priv->gsettings_loc,
             EMPATHY_PREFS_LOCATION_PUBLISH))
         return;
     }
@@ -161,11 +159,11 @@ publish_location (EmpathyLocationManager *self,
     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
@@ -210,14 +208,13 @@ static void
 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_account_manager_prepare_async (self->priv->account_manager, NULL,
       publish_to_all_am_prepared_cb, data);
 }
 
@@ -225,9 +222,8 @@ static gboolean
 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;
 }
@@ -239,9 +235,9 @@ new_connection_cb (TpAccount *account,
     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);
@@ -249,7 +245,7 @@ new_connection_cb (TpAccount *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);
@@ -259,11 +255,11 @@ new_connection_cb (TpAccount *account,
 static void
 update_timestamp (EmpathyLocationManager *self)
 {
-  EmpathyLocationManagerPriv *priv= GET_PRIV (self);
   gint64 timestamp;
 
   timestamp = empathy_time_get_current ();
-  tp_asv_set_int64 (priv->location, EMPATHY_LOCATION_TIMESTAMP, timestamp);
+  tp_asv_set_int64 (self->priv->location, EMPATHY_LOCATION_TIMESTAMP,
+      timestamp);
 
   DEBUG ("\t - Timestamp: %" G_GINT64_FORMAT, timestamp);
 }
@@ -273,10 +269,10 @@ address_changed_cb (GeoclueAddress *address,
                     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;
 
@@ -284,12 +280,12 @@ address_changed_cb (GeoclueAddress *address,
   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)
     {
@@ -302,19 +298,20 @@ address_changed_cb (GeoclueAddress *address,
     {
       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);
+      g_hash_table_insert (self->priv->location, g_strdup (key), new_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
@@ -344,9 +341,9 @@ position_changed_cb (GeocluePosition *position,
                      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;
@@ -360,64 +357,65 @@ position_changed_cb (GeocluePosition *position,
   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);
+      g_hash_table_insert (self->priv->location,
+          g_strdup (EMPATHY_LOCATION_LON), new_value);
       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);
+      g_hash_table_replace (self->priv->location,
+          g_strdup (EMPATHY_LOCATION_LAT), new_value);
       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);
+      g_hash_table_replace (self->priv->location,
+          g_strdup (EMPATHY_LOCATION_ALT), new_value);
       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_hash_table_replace (self->priv->location,
           g_strdup (EMPATHY_LOCATION_ACCURACY), new_value);
       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
@@ -446,11 +444,10 @@ initial_position_cb (GeocluePosition *position,
 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,
+  if (!geoclue_master_client_set_requirements (self->priv->gc_client,
+          GEOCLUE_ACCURACY_LEVEL_COUNTRY, 0, FALSE, self->priv->resources,
           &error))
     {
       DEBUG ("set_requirements failed: %s", error->message);
@@ -464,11 +461,9 @@ set_requirements (EmpathyLocationManager *self)
 static void
 update_resources (EmpathyLocationManager *self)
 {
-  EmpathyLocationManagerPriv *priv = GET_PRIV (self);
+  DEBUG ("Updating resources %d", self->priv->resources);
 
-  DEBUG ("Updating resources %d", priv->resources);
-
-  if (!priv->geoclue_is_setup)
+  if (!self->priv->geoclue_is_setup)
     return;
 
   /* As per Geoclue bug #15126, using NONE results in no address
@@ -477,26 +472,24 @@ update_resources (EmpathyLocationManager *self)
   if (!set_requirements (self))
     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)
 {
-  EmpathyLocationManagerPriv *priv = GET_PRIV (self);
-
   GeoclueMaster *master;
   GError *error = NULL;
 
   DEBUG ("Setting up Geoclue");
   master = geoclue_master_get_default ();
-  priv->gc_client = geoclue_master_create_client (master, NULL, &error);
+  self->priv->gc_client = geoclue_master_create_client (master, NULL, &error);
   g_object_unref (master);
 
-  if (priv->gc_client == NULL)
+  if (self->priv->gc_client == NULL)
     {
       DEBUG ("Failed to GeoclueMasterClient: %s", error->message);
       g_error_free (error);
@@ -507,32 +500,32 @@ setup_geoclue (EmpathyLocationManager *self)
     return;
 
   /* Get updated when the position is changes */
-  priv->gc_position = geoclue_master_client_create_position (
-      priv->gc_client, &error);
-  if (priv->gc_position == NULL)
+  self->priv->gc_position = geoclue_master_client_create_position (
+      self->priv->gc_client, &error);
+  if (self->priv->gc_position == NULL)
     {
       DEBUG ("Failed to create GeocluePosition: %s", error->message);
       g_error_free (error);
       return;
     }
 
-  g_signal_connect (G_OBJECT (priv->gc_position), "position-changed",
+  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)
+  self->priv->gc_address = geoclue_master_client_create_address (
+      self->priv->gc_client, &error);
+  if (self->priv->gc_address == NULL)
     {
       DEBUG ("Failed to create GeoclueAddress: %s", error->message);
       g_error_free (error);
       return;
     }
 
-  g_signal_connect (G_OBJECT (priv->gc_address), "address-changed",
+  g_signal_connect (G_OBJECT (self->priv->gc_address), "address-changed",
       G_CALLBACK (address_changed_cb), self);
 
-  priv->geoclue_is_setup = TRUE;
+  self->priv->geoclue_is_setup = TRUE;
 }
 
 static void
@@ -540,31 +533,30 @@ publish_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);
 
   DEBUG ("Publish Conf changed");
 
   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);
     }
 
 }
@@ -574,8 +566,7 @@ 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;
 
   DEBUG ("%s changed", key);
@@ -588,12 +579,12 @@ resource_cb (GSettings *gsettings_loc,
     resource = GEOCLUE_RESOURCE_GPS;
 
   if (g_settings_get_boolean (gsettings_loc, key))
-    priv->resources |= resource;
+    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
@@ -601,20 +592,19 @@ accuracy_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);
 
   DEBUG ("%s changed", key);
 
-  priv->reduce_accuracy = g_settings_get_boolean (gsettings_loc, key);
+  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
@@ -648,8 +638,8 @@ account_manager_prepared_cb (GObject *source_object,
 static void
 empathy_location_manager_init (EmpathyLocationManager *self)
 {
-  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;
diff --git a/libempathy-gtk/empathy-location-manager.h b/libempathy-gtk/empathy-location-manager.h
index 092ef08..525e490 100644
--- a/libempathy-gtk/empathy-location-manager.h
+++ b/libempathy-gtk/empathy-location-manager.h
@@ -37,11 +37,12 @@ G_BEGIN_DECLS
 
 typedef struct _EmpathyLocationManager      EmpathyLocationManager;
 typedef struct _EmpathyLocationManagerClass EmpathyLocationManagerClass;
+typedef struct _EmpathyLocationManagerPrivate EmpathyLocationManagerPrivate;
 
 struct _EmpathyLocationManager
 {
   GObject parent;
-  gpointer priv;
+  EmpathyLocationManagerPrivate *priv;
 };
 
 struct _EmpathyLocationManagerClass



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]