summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2010-01-21 15:29:32 +0000
committerCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2010-01-21 15:29:32 +0000
commit81699fa85b073e21b89c9a85187ce2dd3c0b7756 (patch)
tree3155df228e44b3cf621672a1563446101d648295
parent20bcca610a3382d95284122443a9139b64bb263a (diff)
Moved TplContact using a priv struct
-rw-r--r--telepathy-logger/contact.c131
-rw-r--r--telepathy-logger/contact.h13
2 files changed, 97 insertions, 47 deletions
diff --git a/telepathy-logger/contact.c b/telepathy-logger/contact.c
index 0c77e4961..93496fd0e 100644
--- a/telepathy-logger/contact.c
+++ b/telepathy-logger/contact.c
@@ -27,19 +27,34 @@
G_DEFINE_TYPE (TplContact, tpl_contact, G_TYPE_OBJECT)
+#define GET_PRIV(obj) TPL_GET_PRIV (obj, TplContact)
+struct _TplContactPriv
+{
+ TpContact *contact;
+ TplContactType contact_type;
+ gchar *alias;
+ gchar *identifier;
+ gchar *presence_status;
+ gchar *presence_message;
+ gchar *avatar_token;
+
+ TpAccount *account;
+};
+
static void
tpl_contact_finalize (GObject * obj)
{
TplContact *self = TPL_CONTACT (obj);
+ TplContactPriv *priv = GET_PRIV (self);
- g_free (self->alias);
- self->alias = NULL;
- g_free (self->identifier);
- self->identifier = NULL;
- g_free (self->presence_status);
- self->presence_status = NULL;
- g_free (self->presence_message);
- self->presence_message = NULL;
+ g_free (priv->alias);
+ priv->alias = NULL;
+ g_free (priv->identifier);
+ priv->identifier = NULL;
+ g_free (priv->presence_status);
+ priv->presence_status = NULL;
+ g_free (priv->presence_message);
+ priv->presence_message = NULL;
G_OBJECT_CLASS (tpl_contact_parent_class)->finalize (obj);
}
@@ -48,9 +63,10 @@ static void
tpl_contact_dispose (GObject * obj)
{
TplContact *self = TPL_CONTACT (obj);
+ TplContactPriv *priv = GET_PRIV (self);
- tpl_object_unref_if_not_null (self->contact);
- self->contact = NULL;
+ tpl_object_unref_if_not_null (priv->contact);
+ priv->contact = NULL;
G_OBJECT_CLASS (tpl_contact_parent_class)->dispose (obj);
}
@@ -60,13 +76,20 @@ tpl_contact_dispose (GObject * obj)
static void tpl_contact_class_init (TplContactClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
object_class->finalize = tpl_contact_finalize;
object_class->dispose = tpl_contact_dispose;
+
+ g_type_class_add_private (object_class, sizeof (TplContactPriv));
}
static void
tpl_contact_init (TplContact * self)
{
+ TplContactPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ TPL_TYPE_CONTACT, TplContactPriv);
+ self->priv = priv;
+
}
@@ -75,10 +98,10 @@ tpl_contact_from_tp_contact (TpContact * contact)
{
TplContact *ret;
- ret = tpl_contact_new ();
+ g_return_val_if_fail (TP_IS_CONTACT (contact), NULL);
+
+ ret = tpl_contact_new (tp_contact_get_identifier (contact));
tpl_contact_set_contact (ret, contact);
- tpl_contact_set_identifier (ret,
- tp_contact_get_identifier (contact));
tpl_contact_set_alias (ret, (gchar *) tp_contact_get_alias (contact));
tpl_contact_set_presence_status (ret,
tp_contact_get_presence_status (contact));
@@ -89,149 +112,183 @@ tpl_contact_from_tp_contact (TpContact * contact)
}
TplContact *
-tpl_contact_new (void)
+tpl_contact_new (const gchar *identifier)
{
+ g_return_val_if_fail (!TPL_STR_EMPTY (identifier), NULL);
+
return g_object_new (TPL_TYPE_CONTACT, NULL);
}
TpContact *
tpl_contact_get_contact (TplContact * self)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_val_if_fail (TPL_IS_CONTACT (self), NULL);
- return self->contact;
+ return priv->contact;
}
const gchar *
tpl_contact_get_alias (TplContact * self)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_val_if_fail (TPL_IS_CONTACT (self), NULL);
- return self->alias;
+ return priv->alias;
}
const gchar *
tpl_contact_get_identifier (TplContact * self)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_val_if_fail (TPL_IS_CONTACT (self), NULL);
- return self->identifier;
+ return priv->identifier;
}
const gchar *
tpl_contact_get_presence_status (TplContact * self)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_val_if_fail (TPL_IS_CONTACT (self), NULL);
- return self->presence_status;
+ return priv->presence_status;
}
const gchar *
tpl_contact_get_presence_message (TplContact * self)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_val_if_fail (TPL_IS_CONTACT (self), NULL);
- return self->presence_message;
+ return priv->presence_message;
}
TplContactType
tpl_contact_get_contact_type (TplContact * self)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_val_if_fail (TPL_IS_CONTACT (self), TPL_CONTACT_UNKNOWN);
- return self->contact_type;
+ return priv->contact_type;
}
const gchar *
tpl_contact_get_avatar_token (TplContact * self)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_val_if_fail (TPL_IS_CONTACT (self), NULL);
- return self->avatar_token;
+ return priv->avatar_token;
}
TpAccount *
tpl_contact_get_account (TplContact * self)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_val_if_fail (TPL_IS_CONTACT (self), NULL);
- return self->account;
+ return priv->account;
}
void
tpl_contact_set_contact (TplContact * self, TpContact * data)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_if_fail (TPL_IS_CONTACT (self));
g_return_if_fail (TP_IS_CONTACT (data) || data == NULL);
- tpl_object_unref_if_not_null (self->contact);
- self->contact = data;
+ tpl_object_unref_if_not_null (priv->contact);
+ priv->contact = data;
tpl_object_ref_if_not_null (data);
}
void
tpl_contact_set_account (TplContact * self, TpAccount * data)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_if_fail (TPL_IS_CONTACT (self));
g_return_if_fail (TP_IS_ACCOUNT (data) || data == NULL);
- tpl_object_unref_if_not_null (self->account);
- self->account = data;
+ tpl_object_unref_if_not_null (priv->account);
+ priv->account = data;
tpl_object_ref_if_not_null (data);
}
void
tpl_contact_set_alias (TplContact * self, const gchar * data)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_if_fail (TPL_IS_CONTACT (self));
g_return_if_fail (!TPL_STR_EMPTY (data));
- g_free (self->alias);
- self->alias = g_strdup (data);
+ g_free (priv->alias);
+ priv->alias = g_strdup (data);
}
void
tpl_contact_set_identifier (TplContact * self, const gchar * data)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_if_fail (TPL_IS_CONTACT (self));
- g_free (self->identifier);
- self->identifier = g_strdup (data);
+ g_free (priv->identifier);
+ priv->identifier = g_strdup (data);
}
void
tpl_contact_set_presence_status (TplContact * self, const gchar * data)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_if_fail (TPL_IS_CONTACT (self));
- g_free (self->presence_status);
- self->presence_status = g_strdup (data);
+ g_free (priv->presence_status);
+ priv->presence_status = g_strdup (data);
}
void
tpl_contact_set_presence_message (TplContact * self, const gchar * data)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_if_fail (TPL_IS_CONTACT (self));
- g_free (self->presence_message);
- self->presence_message = g_strdup (data);
+ g_free (priv->presence_message);
+ priv->presence_message = g_strdup (data);
}
void
tpl_contact_set_contact_type (TplContact * self, TplContactType data)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_if_fail (TPL_IS_CONTACT (self));
- self->contact_type = data;
+ priv->contact_type = data;
}
void
tpl_contact_set_avatar_token (TplContact * self, const gchar *data)
{
+ TplContactPriv *priv = GET_PRIV (self);
+
g_return_if_fail (TPL_IS_CONTACT (self));
- g_free (self->avatar_token);
- self->avatar_token = g_strdup (data);
+ g_free (priv->avatar_token);
+ priv->avatar_token = g_strdup (data);
}
diff --git a/telepathy-logger/contact.h b/telepathy-logger/contact.h
index 407a6c0ae..b1c4f5e11 100644
--- a/telepathy-logger/contact.h
+++ b/telepathy-logger/contact.h
@@ -40,20 +40,13 @@ G_BEGIN_DECLS
TPL_CONTACT_GROUP
} TplContactType;
+typedef struct _TplContactPriv TplContactPriv;
typedef struct
{
GObject parent;
/* Private */
- TpContact *contact;
- TplContactType contact_type;
- gchar *alias;
- gchar *identifier;
- gchar *presence_status;
- gchar *presence_message;
- gchar *avatar_token;
-
- TpAccount *account;
+ TplContactPriv *priv;
} TplContact;
@@ -67,7 +60,7 @@ GType tpl_contact_get_type (void);
TplContact *tpl_contact_from_tp_contact (TpContact * contact);
-TplContact *tpl_contact_new (void);
+TplContact *tpl_contact_new (const gchar *identifier);
TpContact *tpl_contact_get_contact (TplContact * self);