[Telepathy-commits] [telepathy-gabble/master] OLPC views: simplify access to private data struct

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Mar 3 05:38:04 PST 2009


---
 src/olpc-activity-view.c |   23 +++++----------------
 src/olpc-activity-view.h |    3 +-
 src/olpc-activity.c      |   15 ++++---------
 src/olpc-activity.h      |    3 +-
 src/olpc-buddy-view.c    |   17 +++++----------
 src/olpc-buddy-view.h    |    3 +-
 src/olpc-view.c          |   47 ++++++++++++++++-----------------------------
 src/olpc-view.h          |    3 +-
 8 files changed, 42 insertions(+), 72 deletions(-)

diff --git a/src/olpc-activity-view.c b/src/olpc-activity-view.c
index c266076..378e328 100644
--- a/src/olpc-activity-view.c
+++ b/src/olpc-activity-view.c
@@ -54,7 +54,6 @@ enum
   LAST_PROPERTY
 };
 
-typedef struct _GabbleOlpcActivityViewPrivate GabbleOlpcActivityViewPrivate;
 struct _GabbleOlpcActivityViewPrivate
 {
   GHashTable *properties;
@@ -69,10 +68,6 @@ G_DEFINE_TYPE_WITH_CODE (
       NULL);
     );
 
-#define GABBLE_OLPC_ACTIVITY_VIEW_GET_PRIVATE(obj) \
-    ((GabbleOlpcActivityViewPrivate *) obj->priv)
-
-
 static void
 gabble_olpc_activity_view_init (GabbleOlpcActivityView *self)
 {
@@ -88,8 +83,7 @@ static void
 gabble_olpc_activity_view_dispose (GObject *object)
 {
   GabbleOlpcActivityView *self = GABBLE_OLPC_ACTIVITY_VIEW (object);
-  GabbleOlpcActivityViewPrivate *priv = GABBLE_OLPC_ACTIVITY_VIEW_GET_PRIVATE (
-      self);
+  GabbleOlpcActivityViewPrivate *priv = self->priv;
 
   if (priv->dispose_has_run)
     return;
@@ -104,8 +98,7 @@ static void
 gabble_olpc_activity_view_finalize (GObject *object)
 {
   GabbleOlpcActivityView *self = GABBLE_OLPC_ACTIVITY_VIEW (object);
-  GabbleOlpcActivityViewPrivate *priv = GABBLE_OLPC_ACTIVITY_VIEW_GET_PRIVATE (
-      self);
+  GabbleOlpcActivityViewPrivate *priv = self->priv;
 
   g_hash_table_destroy (priv->properties);
   tp_handle_set_destroy (priv->participants);
@@ -121,8 +114,7 @@ gabble_olpc_activity_view_get_property (GObject *object,
                                         GParamSpec *pspec)
 {
   GabbleOlpcActivityView *self = GABBLE_OLPC_ACTIVITY_VIEW (object);
-  GabbleOlpcActivityViewPrivate *priv = GABBLE_OLPC_ACTIVITY_VIEW_GET_PRIVATE (
-      self);
+  GabbleOlpcActivityViewPrivate *priv = self->priv;
 
   switch (property_id)
     {
@@ -166,8 +158,7 @@ gabble_olpc_activity_view_set_property (GObject *object,
                                         GParamSpec *pspec)
 {
   GabbleOlpcActivityView *self = GABBLE_OLPC_ACTIVITY_VIEW (object);
-  GabbleOlpcActivityViewPrivate *priv = GABBLE_OLPC_ACTIVITY_VIEW_GET_PRIVATE (
-      self);
+  GabbleOlpcActivityViewPrivate *priv = self->priv;
 
   switch (property_id)
     {
@@ -228,8 +219,7 @@ gabble_olpc_activity_view_constructor (GType type,
 
   view = GABBLE_OLPC_VIEW (obj);
 
-  priv = GABBLE_OLPC_ACTIVITY_VIEW_GET_PRIVATE (GABBLE_OLPC_ACTIVITY_VIEW (
-        obj));
+  priv = GABBLE_OLPC_ACTIVITY_VIEW (obj)->priv;
   conn = (TpBaseConnection *) view->conn;
 
   bus = tp_get_bus ();
@@ -299,8 +289,7 @@ gabble_olpc_activity_view_send_request (GabbleOlpcView *view,
                                         GError **error)
 {
   GabbleOlpcActivityView *self = GABBLE_OLPC_ACTIVITY_VIEW (view);
-  GabbleOlpcActivityViewPrivate *priv = \
-      GABBLE_OLPC_ACTIVITY_VIEW_GET_PRIVATE (self);
+  GabbleOlpcActivityViewPrivate *priv = self->priv;
   LmMessage *query;
   LmMessageNode *activity_node;
   gchar *max_str, *id_str;
diff --git a/src/olpc-activity-view.h b/src/olpc-activity-view.h
index a5d3ccb..80ee24f 100644
--- a/src/olpc-activity-view.h
+++ b/src/olpc-activity-view.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 
 typedef struct _GabbleOlpcActivityView GabbleOlpcActivityView;
 typedef struct _GabbleOlpcActivityViewClass GabbleOlpcActivityViewClass;
+typedef struct _GabbleOlpcActivityViewPrivate GabbleOlpcActivityViewPrivate;
 
 struct _GabbleOlpcActivityViewClass {
   GabbleOlpcViewClass parent_class;
@@ -41,7 +42,7 @@ struct _GabbleOlpcActivityViewClass {
 struct _GabbleOlpcActivityView {
   GabbleOlpcView parent;
 
-  gpointer priv;
+  GabbleOlpcActivityViewPrivate *priv;
 };
 
 GType gabble_olpc_activity_view_get_type (void);
diff --git a/src/olpc-activity.c b/src/olpc-activity.c
index 5d72f7d..3bfb965 100644
--- a/src/olpc-activity.c
+++ b/src/olpc-activity.c
@@ -42,7 +42,6 @@ enum
   LAST_PROPERTY
 };
 
-typedef struct _GabbleOlpcActivityPrivate GabbleOlpcActivityPrivate;
 struct _GabbleOlpcActivityPrivate
 {
   GabbleConnection *conn;
@@ -52,9 +51,6 @@ struct _GabbleOlpcActivityPrivate
 
 G_DEFINE_TYPE (GabbleOlpcActivity, gabble_olpc_activity, G_TYPE_OBJECT);
 
-#define GABBLE_OLPC_ACTIVITY_GET_PRIVATE(obj) \
-    ((GabbleOlpcActivityPrivate *) obj->priv)
-
 static void
 gabble_olpc_activity_init (GabbleOlpcActivity *self)
 {
@@ -70,7 +66,7 @@ static void
 gabble_olpc_activity_dispose (GObject *object)
 {
   GabbleOlpcActivity *self = GABBLE_OLPC_ACTIVITY (object);
-  GabbleOlpcActivityPrivate *priv = GABBLE_OLPC_ACTIVITY_GET_PRIVATE (self);
+  GabbleOlpcActivityPrivate *priv = self->priv;
   TpHandleRepoIface *room_repo;
 
   if (priv->dispose_has_run)
@@ -113,7 +109,7 @@ gabble_olpc_activity_get_property (GObject *object,
                                    GParamSpec *pspec)
 {
   GabbleOlpcActivity *self = GABBLE_OLPC_ACTIVITY (object);
-  GabbleOlpcActivityPrivate *priv = GABBLE_OLPC_ACTIVITY_GET_PRIVATE (self);
+  GabbleOlpcActivityPrivate *priv = self->priv;
 
   switch (property_id)
     {
@@ -142,7 +138,7 @@ gabble_olpc_activity_set_property (GObject *object,
                                    GParamSpec *pspec)
 {
   GabbleOlpcActivity *self = GABBLE_OLPC_ACTIVITY (object);
-  GabbleOlpcActivityPrivate *priv = GABBLE_OLPC_ACTIVITY_GET_PRIVATE (self);
+  GabbleOlpcActivityPrivate *priv = self->priv;
 
   switch (property_id)
     {
@@ -182,7 +178,7 @@ gabble_olpc_activity_constructor (GType type,
            constructor (type, n_props, props);
 
   self = GABBLE_OLPC_ACTIVITY (obj);
-  priv = GABBLE_OLPC_ACTIVITY_GET_PRIVATE (self);
+  priv = self->priv;
 
   room_repo = tp_base_connection_get_handles (
       (TpBaseConnection *) priv->conn,
@@ -261,9 +257,8 @@ gabble_olpc_activity_new (GabbleConnection *conn,
 const gchar *
 gabble_olpc_activity_get_room (GabbleOlpcActivity *self)
 {
-  GabbleOlpcActivityPrivate *priv = GABBLE_OLPC_ACTIVITY_GET_PRIVATE (self);
   TpHandleRepoIface *room_repo = tp_base_connection_get_handles (
-      (TpBaseConnection *) priv->conn,
+      (TpBaseConnection *) self->priv->conn,
       TP_HANDLE_TYPE_ROOM);
 
   return tp_handle_inspect (room_repo, self->room);
diff --git a/src/olpc-activity.h b/src/olpc-activity.h
index ac455f3..47101bd 100644
--- a/src/olpc-activity.h
+++ b/src/olpc-activity.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 
 typedef struct _GabbleOlpcActivity GabbleOlpcActivity;
 typedef struct _GabbleOlpcActivityClass GabbleOlpcActivityClass;
+typedef struct _GabbleOlpcActivityPrivate GabbleOlpcActivityPrivate;
 
 struct _GabbleOlpcActivityClass {
   GObjectClass parent_class;
@@ -43,7 +44,7 @@ struct _GabbleOlpcActivity {
   gchar *id;
   GHashTable *properties;
 
-  gpointer priv;
+  GabbleOlpcActivityPrivate *priv;
 };
 
 GType gabble_olpc_activity_get_type (void);
diff --git a/src/olpc-buddy-view.c b/src/olpc-buddy-view.c
index e5e93d9..4298a93 100644
--- a/src/olpc-buddy-view.c
+++ b/src/olpc-buddy-view.c
@@ -54,7 +54,6 @@ enum
   LAST_PROPERTY
 };
 
-typedef struct _GabbleOlpcBuddyViewPrivate GabbleOlpcBuddyViewPrivate;
 struct _GabbleOlpcBuddyViewPrivate
 {
   GHashTable *properties;
@@ -69,10 +68,6 @@ G_DEFINE_TYPE_WITH_CODE (
       NULL);
     );
 
-#define GABBLE_OLPC_BUDDY_VIEW_GET_PRIVATE(obj) \
-    ((GabbleOlpcBuddyViewPrivate *) obj->priv)
-
-
 static void
 gabble_olpc_buddy_view_init (GabbleOlpcBuddyView *self)
 {
@@ -88,7 +83,7 @@ static void
 gabble_olpc_buddy_view_dispose (GObject *object)
 {
   GabbleOlpcBuddyView *self = GABBLE_OLPC_BUDDY_VIEW (object);
-  GabbleOlpcBuddyViewPrivate *priv = GABBLE_OLPC_BUDDY_VIEW_GET_PRIVATE (self);
+  GabbleOlpcBuddyViewPrivate *priv = self->priv;
 
   if (priv->dispose_has_run)
     return;
@@ -103,7 +98,7 @@ static void
 gabble_olpc_buddy_view_finalize (GObject *object)
 {
   GabbleOlpcBuddyView *self = GABBLE_OLPC_BUDDY_VIEW (object);
-  GabbleOlpcBuddyViewPrivate *priv = GABBLE_OLPC_BUDDY_VIEW_GET_PRIVATE (self);
+  GabbleOlpcBuddyViewPrivate *priv = self->priv;
 
   g_hash_table_destroy (priv->properties);
   g_free (priv->alias);
@@ -119,7 +114,7 @@ gabble_olpc_buddy_view_get_property (GObject *object,
                                GParamSpec *pspec)
 {
   GabbleOlpcBuddyView *self = GABBLE_OLPC_BUDDY_VIEW (object);
-  GabbleOlpcBuddyViewPrivate *priv = GABBLE_OLPC_BUDDY_VIEW_GET_PRIVATE (self);
+  GabbleOlpcBuddyViewPrivate *priv = self->priv;
 
   switch (property_id)
     {
@@ -163,7 +158,7 @@ gabble_olpc_buddy_view_set_property (GObject *object,
                                      GParamSpec *pspec)
 {
   GabbleOlpcBuddyView *self = GABBLE_OLPC_BUDDY_VIEW (object);
-  GabbleOlpcBuddyViewPrivate *priv = GABBLE_OLPC_BUDDY_VIEW_GET_PRIVATE (self);
+  GabbleOlpcBuddyViewPrivate *priv = self->priv;
 
   switch (property_id)
     {
@@ -200,7 +195,7 @@ gabble_olpc_buddy_view_constructor (GType type,
 
   view = GABBLE_OLPC_VIEW (obj);
 
-  priv = GABBLE_OLPC_BUDDY_VIEW_GET_PRIVATE (GABBLE_OLPC_BUDDY_VIEW (obj));
+  priv = GABBLE_OLPC_BUDDY_VIEW (obj)->priv;
   conn = (TpBaseConnection *) view->conn;
 
   bus = tp_get_bus ();
@@ -262,7 +257,7 @@ gabble_olpc_buddy_view_send_request (GabbleOlpcView *view,
                                      GError **error)
 {
   GabbleOlpcBuddyView *self = GABBLE_OLPC_BUDDY_VIEW (view);
-  GabbleOlpcBuddyViewPrivate *priv = GABBLE_OLPC_BUDDY_VIEW_GET_PRIVATE (self);
+  GabbleOlpcBuddyViewPrivate *priv = self->priv;
   LmMessage *query;
   LmMessageNode *buddy_node;
   gchar *max_str, *id_str;
diff --git a/src/olpc-buddy-view.h b/src/olpc-buddy-view.h
index 203913b..c8f21f5 100644
--- a/src/olpc-buddy-view.h
+++ b/src/olpc-buddy-view.h
@@ -31,6 +31,7 @@ G_BEGIN_DECLS
 
 typedef struct _GabbleOlpcBuddyView GabbleOlpcBuddyView;
 typedef struct _GabbleOlpcBuddyViewClass GabbleOlpcBuddyViewClass;
+typedef struct _GabbleOlpcBuddyViewPrivate GabbleOlpcBuddyViewPrivate;
 
 struct _GabbleOlpcBuddyViewClass {
   GabbleOlpcViewClass parent_class;
@@ -41,7 +42,7 @@ struct _GabbleOlpcBuddyViewClass {
 struct _GabbleOlpcBuddyView {
   GabbleOlpcView parent;
 
-  gpointer priv;
+  GabbleOlpcBuddyViewPrivate *priv;
 };
 
 GType gabble_olpc_buddy_view_get_type (void);
diff --git a/src/olpc-view.c b/src/olpc-view.c
index 0fe7324..607ce6a 100644
--- a/src/olpc-view.c
+++ b/src/olpc-view.c
@@ -79,7 +79,6 @@ enum
   LAST_PROPERTY
 };
 
-typedef struct _GabbleOlpcViewPrivate GabbleOlpcViewPrivate;
 struct _GabbleOlpcViewPrivate
 {
   gboolean closed;
@@ -113,10 +112,6 @@ static const gchar *gabble_olpc_view_interfaces[] = {
     NULL
 };
 
-#define GABBLE_OLPC_VIEW_GET_PRIVATE(obj) \
-    ((GabbleOlpcViewPrivate *) obj->priv)
-
-
 static void
 gabble_olpc_view_init (GabbleOlpcView *self)
 {
@@ -132,7 +127,7 @@ static void
 gabble_olpc_view_dispose (GObject *object)
 {
   GabbleOlpcView *self = GABBLE_OLPC_VIEW (object);
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GabbleOlpcViewPrivate *priv = self->priv;
 
   if (priv->dispose_has_run)
     return;
@@ -198,12 +193,11 @@ add_activity_to_array (TpHandle handle,
 static GPtrArray *
 create_activities_array (GabbleOlpcView *self)
 {
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
   GPtrArray *activities;
 
   activities = g_ptr_array_new ();
 
-  g_hash_table_foreach (priv->activities, (GHFunc) add_activity_to_array,
+  g_hash_table_foreach (self->priv->activities, (GHFunc) add_activity_to_array,
       activities);
 
   return activities;
@@ -216,7 +210,7 @@ gabble_olpc_view_get_property (GObject *object,
                                GParamSpec *pspec)
 {
   GabbleOlpcView *self = GABBLE_OLPC_VIEW (object);
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GabbleOlpcViewPrivate *priv = self->priv;
   TpBaseConnection *base_conn = (TpBaseConnection *) self->conn;
 
   switch (property_id)
@@ -334,7 +328,7 @@ gabble_olpc_view_constructor (GType type,
            constructor (type, n_props, props);
 
   self = GABBLE_OLPC_VIEW (obj);
-  priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  priv = self->priv;
   conn = (TpBaseConnection *) self->conn;
 
   contact_handles = tp_base_connection_get_handles (conn,
@@ -506,10 +500,8 @@ buddy_left_activities_foreach (TpHandleSet *set,
                                TpHandle buddy,
                                GabbleOlpcView *self)
 {
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
-
   /* Remove all the activity of this buddy */
-  if (!g_hash_table_remove (priv->buddy_rooms, GUINT_TO_POINTER (buddy)))
+  if (!g_hash_table_remove (self->priv->buddy_rooms, GUINT_TO_POINTER (buddy)))
     return;
 
   g_signal_emit (G_OBJECT (self), signals[BUDDY_ACTIVITIES_CHANGED],
@@ -520,7 +512,7 @@ static gboolean
 do_close (GabbleOlpcView *self,
           GError **error)
 {
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GabbleOlpcViewPrivate *priv = self->priv;
   LmMessage *msg;
 
   msg = GABBLE_OLPC_VIEW_GET_CLASS (self)->create_close_msg (self);
@@ -563,10 +555,9 @@ gabble_olpc_view_close_dbus (TpSvcChannel *iface,
                              DBusGMethodInvocation *context)
 {
   GabbleOlpcView *self = GABBLE_OLPC_VIEW (iface);
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
   GError *error = NULL;
 
-  if (priv->closed)
+  if (self->priv->closed)
     {
       DEBUG ("Already closed. Doing nothing");
     }
@@ -636,7 +627,7 @@ gabble_olpc_view_add_buddies (GabbleOlpcView *self,
                               GPtrArray *buddies_properties,
                               TpHandle room)
 {
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GabbleOlpcViewPrivate *priv = self->priv;
   guint i;
   GArray *empty;
   TpHandleRepoIface *room_repo, *contact_repo;
@@ -732,11 +723,9 @@ remove_buddy_foreach (TpHandleSet *buddies,
                       TpHandle handle,
                       GabbleOlpcView *self)
 {
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
-
-  tp_handle_set_remove (priv->buddies, handle);
-  g_hash_table_remove (priv->buddy_properties, GUINT_TO_POINTER (handle));
-  g_hash_table_remove (priv->buddy_rooms, GUINT_TO_POINTER (handle));
+  tp_handle_set_remove (self->priv->buddies, handle);
+  g_hash_table_remove (self->priv->buddy_properties, GUINT_TO_POINTER (handle));
+  g_hash_table_remove (self->priv->buddy_rooms, GUINT_TO_POINTER (handle));
 }
 
 void
@@ -769,7 +758,7 @@ gabble_olpc_view_set_buddy_properties (GabbleOlpcView *self,
                                        TpHandle buddy,
                                        GHashTable *properties)
 {
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GabbleOlpcViewPrivate *priv = self->priv;
 
   if (!tp_handle_set_is_member (priv->buddies, buddy))
     {
@@ -789,9 +778,7 @@ GHashTable *
 gabble_olpc_view_get_buddy_properties (GabbleOlpcView *self,
                                        TpHandle buddy)
 {
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
-
-  return g_hash_table_lookup (priv->buddy_properties,
+  return g_hash_table_lookup (self->priv->buddy_properties,
       GUINT_TO_POINTER (buddy));
 }
 
@@ -799,7 +786,7 @@ void
 gabble_olpc_view_add_activities (GabbleOlpcView *self,
                                  GHashTable *activities)
 {
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GabbleOlpcViewPrivate *priv = self->priv;
   GPtrArray *added, *empty;
 
   if (g_hash_table_size (activities) == 0)
@@ -852,7 +839,7 @@ void
 gabble_olpc_view_remove_activities (GabbleOlpcView *self,
                                     TpHandleSet *rooms)
 {
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GabbleOlpcViewPrivate *priv = self->priv;
   GPtrArray *removed, *empty;
   GArray *array;
   guint i;
@@ -911,7 +898,7 @@ GPtrArray *
 gabble_olpc_view_get_buddy_activities (GabbleOlpcView *self,
                                        TpHandle buddy)
 {
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GabbleOlpcViewPrivate *priv = self->priv;
   GPtrArray *activities;
   TpHandleSet *rooms_set;
   GArray *rooms;
@@ -963,7 +950,7 @@ gabble_olpc_view_buddies_left_activity (GabbleOlpcView *self,
                                         GArray *buddies,
                                         TpHandle room)
 {
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GabbleOlpcViewPrivate *priv = self->priv;
   guint i;
   TpHandleRepoIface *contact_repo;
   TpHandleSet *removed;
diff --git a/src/olpc-view.h b/src/olpc-view.h
index 3b284fc..a3945b7 100644
--- a/src/olpc-view.h
+++ b/src/olpc-view.h
@@ -30,6 +30,7 @@
 G_BEGIN_DECLS
 
 typedef struct _GabbleOlpcViewClass GabbleOlpcViewClass;
+typedef struct _GabbleOlpcViewPrivate GabbleOlpcViewPrivate;
 
 struct _GabbleOlpcViewClass {
   GObjectClass parent_class;
@@ -52,7 +53,7 @@ struct _GabbleOlpcView {
   guint id;
   guint max_size;
 
-  gpointer priv;
+  GabbleOlpcViewPrivate *priv;
 };
 
 GType gabble_olpc_view_get_type (void);
-- 
1.5.6.5



More information about the telepathy-commits mailing list