[empathy] tp-chat: add 'account' property



commit 567a34cbbb5c93b40ee44739fff9a908bd31195b
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Thu Aug 12 16:16:27 2010 +0200

    tp-chat: add 'account' property

 libempathy/empathy-tp-chat.c |   40 +++++++++++++++++++++++++++++++++++-----
 libempathy/empathy-tp-chat.h |    4 +++-
 src/empathy-chat-manager.c   |    2 +-
 src/empathy-event-manager.c  |    2 +-
 4 files changed, 40 insertions(+), 8 deletions(-)
---
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index 9a4e56a..7bc9a9c 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -41,6 +41,7 @@
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpChat)
 typedef struct {
 	gboolean               dispose_has_run;
+	TpAccount             *account;
 	TpConnection          *connection;
 	EmpathyContact        *user;
 	EmpathyContact        *remote_contact;
@@ -65,6 +66,7 @@ static void tp_chat_iface_init         (EmpathyContactListIface *iface);
 
 enum {
 	PROP_0,
+	PROP_ACCOUNT,
 	PROP_CHANNEL,
 	PROP_REMOTE_CONTACT,
 	PROP_PASSWORD_NEEDED,
@@ -164,8 +166,7 @@ tp_chat_add (EmpathyContactList *list,
 		    /* FIXME: InvitationMessage ? */
 		    NULL);
 
-		req = tp_account_channel_request_new (
-			empathy_get_account_for_connection (priv->connection), props,
+		req = tp_account_channel_request_new (priv->account, props,
 			EMPATHY_DISPATCHER_NON_USER_ACTION);
 
 		/* Although this is a MUC, it's anonymous, so CreateChannel is
@@ -778,6 +779,8 @@ tp_chat_dispose (GObject *object)
 
 	priv->dispose_has_run = TRUE;
 
+	tp_clear_object (&priv->account);
+
 	if (priv->connection != NULL)
 		g_object_unref (priv->connection);
 	priv->connection = NULL;
@@ -1261,7 +1264,7 @@ tp_chat_constructor (GType                  type,
 
 	priv = GET_PRIV (chat);
 
-	priv->connection = g_object_ref (tp_channel_borrow_connection (priv->channel));
+	priv->connection = g_object_ref (tp_account_get_connection (priv->account));
 	tp_g_signal_connect_object (priv->channel, "invalidated",
 			  G_CALLBACK (tp_chat_invalidated_cb),
 			  chat, 0);
@@ -1369,6 +1372,9 @@ tp_chat_get_property (GObject    *object,
 	EmpathyTpChatPriv *priv = GET_PRIV (object);
 
 	switch (param_id) {
+	case PROP_ACCOUNT:
+		g_value_set_object (value, priv->account);
+		break;
 	case PROP_CHANNEL:
 		g_value_set_object (value, priv->channel);
 		break;
@@ -1396,6 +1402,9 @@ tp_chat_set_property (GObject      *object,
 	EmpathyTpChatPriv *priv = GET_PRIV (object);
 
 	switch (param_id) {
+	case PROP_ACCOUNT:
+		priv->account = g_value_dup_object (value);
+		break;
 	case PROP_CHANNEL:
 		priv->channel = g_value_dup_object (value);
 		break;
@@ -1417,6 +1426,16 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
 	object_class->set_property = tp_chat_set_property;
 
 	g_object_class_install_property (object_class,
+					 PROP_ACCOUNT,
+					 g_param_spec_object ("account",
+							      "TpAccount",
+							      "the account associated with the chat",
+							      TP_TYPE_ACCOUNT,
+							      G_PARAM_READWRITE |
+							      G_PARAM_CONSTRUCT_ONLY |
+							      G_PARAM_STATIC_STRINGS));
+
+	g_object_class_install_property (object_class,
 					 PROP_CHANNEL,
 					 g_param_spec_object ("channel",
 							      "telepathy channel",
@@ -1523,9 +1542,11 @@ tp_chat_iface_init (EmpathyContactListIface *iface)
 }
 
 EmpathyTpChat *
-empathy_tp_chat_new (TpChannel *channel)
+empathy_tp_chat_new (TpAccount *account,
+		     TpChannel *channel)
 {
 	return g_object_new (EMPATHY_TYPE_TP_CHAT,
+			     "account", account,
 			     "channel", channel,
 			     NULL);
 }
@@ -1580,6 +1601,16 @@ empathy_tp_chat_get_channel (EmpathyTpChat *chat)
 	return priv->channel;
 }
 
+TpAccount *
+empathy_tp_chat_get_account (EmpathyTpChat *chat)
+{
+	EmpathyTpChatPriv *priv = GET_PRIV (chat);
+
+	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
+
+	return priv->account;
+}
+
 TpConnection *
 empathy_tp_chat_get_connection (EmpathyTpChat *chat)
 {
@@ -1589,7 +1620,6 @@ empathy_tp_chat_get_connection (EmpathyTpChat *chat)
 
 	return tp_channel_borrow_connection (priv->channel);
 }
-
 gboolean
 empathy_tp_chat_is_ready (EmpathyTpChat *chat)
 {
diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h
index 3ac5eaf..8858f49 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -60,10 +60,12 @@ typedef struct {
 } EmpathyTpChatProperty;
 
 GType          empathy_tp_chat_get_type             (void) G_GNUC_CONST;
-EmpathyTpChat *empathy_tp_chat_new                  (TpChannel          *channel);
+EmpathyTpChat *empathy_tp_chat_new                  (TpAccount *account,
+						     TpChannel *channel);
 const gchar *  empathy_tp_chat_get_id               (EmpathyTpChat      *chat);
 EmpathyContact *empathy_tp_chat_get_remote_contact   (EmpathyTpChat      *chat);
 TpChannel *    empathy_tp_chat_get_channel          (EmpathyTpChat      *chat);
+TpAccount    * empathy_tp_chat_get_account          (EmpathyTpChat      *chat);
 TpConnection * empathy_tp_chat_get_connection       (EmpathyTpChat      *chat);
 gboolean       empathy_tp_chat_is_ready             (EmpathyTpChat      *chat);
 void           empathy_tp_chat_send                 (EmpathyTpChat      *chat,
diff --git a/src/empathy-chat-manager.c b/src/empathy-chat-manager.c
index 8b9a73b..fdc4451 100644
--- a/src/empathy-chat-manager.c
+++ b/src/empathy-chat-manager.c
@@ -218,7 +218,7 @@ handle_channels (TpSimpleHandler *handler,
       TpChannel *channel = l->data;
       EmpathyTpChat *tp_chat;
 
-      tp_chat = empathy_tp_chat_new (channel);
+      tp_chat = empathy_tp_chat_new (account, channel);
 
       if (empathy_tp_chat_is_ready (tp_chat))
         {
diff --git a/src/empathy-event-manager.c b/src/empathy-event-manager.c
index e60a9b1..bc998a8 100644
--- a/src/empathy-event-manager.c
+++ b/src/empathy-event-manager.c
@@ -866,7 +866,7 @@ approve_channels (TpSimpleApprover *approver,
     {
       EmpathyTpChat *tp_chat;
 
-      tp_chat = empathy_tp_chat_new (channel);
+      tp_chat = empathy_tp_chat_new (account, channel);
       approval->handler_instance = G_OBJECT (tp_chat);
 
       if (tp_proxy_has_interface (channel, TP_IFACE_CHANNEL_INTERFACE_GROUP))



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