[empathy] remove empathy_tp_chat_get_connection and priv->connection



commit 1a076de82797676d80ce3273dfe075d06111a446
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Fri Nov 12 16:48:42 2010 +0100

    remove empathy_tp_chat_get_connection and priv->connection

 libempathy-gtk/empathy-chat.c           |    5 +--
 libempathy/empathy-tp-chat.c            |   47 +++++++++++++++----------------
 libempathy/empathy-tp-chat.h            |    1 -
 src/empathy-chat-window.c               |    2 +-
 src/empathy-invite-participant-dialog.c |    2 +-
 5 files changed, 27 insertions(+), 30 deletions(-)
---
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index ef4d7a5..cf3336b 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -700,7 +700,7 @@ nick_command_supported (EmpathyChat *chat)
 	EmpathyChatPriv * priv = GET_PRIV (chat);
 	TpConnection    *connection;
 
-	connection = empathy_tp_chat_get_connection (priv->tp_chat);
+	connection = tp_channel_borrow_connection (TP_CHANNEL (priv->tp_chat));
 	return tp_proxy_has_interface_by_id (connection,
 		EMP_IFACE_QUARK_CONNECTION_INTERFACE_RENAMING);
 }
@@ -975,7 +975,7 @@ chat_command_whois (EmpathyChat *chat,
 	EmpathyChatPriv *priv = GET_PRIV (chat);
 	TpConnection *conn;
 
-	conn = empathy_tp_chat_get_connection (priv->tp_chat);
+	conn = tp_channel_borrow_connection ((TpChannel *) priv->tp_chat);
 	tp_connection_get_contacts_by_id (conn,
 		/* Element 0 of 'strv' is "whois"; element 1 is the contact ID
 		 * entered by the user (including spaces, if any). */
@@ -3636,7 +3636,6 @@ empathy_chat_set_tp_chat (EmpathyChat   *chat,
 
 	g_return_if_fail (EMPATHY_IS_CHAT (chat));
 	g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
-	g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
 
 	if (priv->tp_chat) {
 		return;
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index d1338f2..b33b41e 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -41,7 +41,6 @@
 struct _EmpathyTpChatPrivate {
 	gboolean               dispose_has_run;
 	TpAccount             *account;
-	TpConnection          *connection;
 	EmpathyContact        *user;
 	EmpathyContact        *remote_contact;
 	GList                 *members;
@@ -331,7 +330,10 @@ tp_chat_build_message (EmpathyTpChat *self,
 		empathy_message_set_sender (message, self->priv->user);
 		tp_chat_emit_queued_messages (self);
 	} else {
-		empathy_tp_contact_factory_get_from_handle (self->priv->connection,
+		TpConnection *connection = tp_channel_borrow_connection (
+			(TpChannel *) self);
+
+		empathy_tp_contact_factory_get_from_handle (connection,
 			tp_contact_get_handle (sender),
 			tp_chat_got_sender_cb,
 			message, NULL, G_OBJECT (self));
@@ -572,7 +574,10 @@ tp_chat_state_changed_cb (TpChannel *channel,
 			  TpChannelChatState state,
 			  EmpathyTpChat *self)
 {
-	empathy_tp_contact_factory_get_from_handle (self->priv->connection, handle,
+	TpConnection *connection = tp_channel_borrow_connection (
+		(TpChannel *) self);
+
+	empathy_tp_contact_factory_get_from_handle (connection, handle,
 		tp_chat_state_changed_got_contact_cb, GUINT_TO_POINTER (state),
 		NULL, G_OBJECT (self));
 }
@@ -823,10 +828,6 @@ tp_chat_dispose (GObject *object)
 
 	tp_clear_object (&self->priv->account);
 
-	if (self->priv->connection != NULL)
-		g_object_unref (self->priv->connection);
-	self->priv->connection = NULL;
-
 	if (self->priv->remote_contact != NULL)
 		g_object_unref (self->priv->remote_contact);
 	self->priv->remote_contact = NULL;
@@ -1141,6 +1142,8 @@ tp_chat_group_members_changed_cb (TpChannel     *channel,
 	guint i;
 	ContactRenameData *rename_data;
 	TpHandle old_handle;
+	TpConnection *connection = tp_channel_borrow_connection (
+		(TpChannel *) self);
 
 	/* Contact renamed */
 	if (reason == TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED) {
@@ -1154,7 +1157,7 @@ tp_chat_group_members_changed_cb (TpChannel     *channel,
 		old_handle = g_array_index (removed, guint, 0);
 
 		rename_data = contact_rename_data_new (old_handle, reason, message);
-		empathy_tp_contact_factory_get_from_handles (self->priv->connection,
+		empathy_tp_contact_factory_get_from_handles (connection,
 			added->len, (TpHandle *) added->data,
 			tp_chat_got_renamed_contacts_cb,
 			rename_data, (GDestroyNotify) contact_rename_data_free,
@@ -1188,7 +1191,7 @@ tp_chat_group_members_changed_cb (TpChannel     *channel,
 
 	/* Request added contacts */
 	if (added->len > 0) {
-		empathy_tp_contact_factory_get_from_handles (self->priv->connection,
+		empathy_tp_contact_factory_get_from_handles (connection,
 			added->len, (TpHandle *) added->data,
 			tp_chat_got_added_contacts_cb, NULL, NULL,
 			G_OBJECT (self));
@@ -1322,17 +1325,20 @@ tp_chat_constructor (GType                  type,
 	EmpathyTpChat *self;
 	TpHandle           handle;
 	TpChannel         *channel;
+	TpConnection *connection;
+
 
 	object = G_OBJECT_CLASS (empathy_tp_chat_parent_class)->constructor (type, n_props, props);
 	self = (EmpathyTpChat *) object;
 	channel = (TpChannel *) object;
 
-	self->priv->connection = g_object_ref (tp_account_get_connection (self->priv->account));
+	connection = tp_channel_borrow_connection (channel);
+
 	tp_g_signal_connect_object (self, "invalidated",
 			  G_CALLBACK (tp_chat_invalidated_cb),
 			  self, 0);
 
-	g_assert (tp_proxy_is_prepared (self->priv->connection,
+	g_assert (tp_proxy_is_prepared (connection,
 		TP_CONNECTION_FEATURE_CAPABILITIES));
 
 	if (tp_proxy_has_interface_by_id (self,
@@ -1342,14 +1348,14 @@ tp_chat_constructor (GType                  type,
 
 		/* Get self contact from the group's self handle */
 		handle = tp_channel_group_get_self_handle (channel);
-		empathy_tp_contact_factory_get_from_handle (self->priv->connection,
+		empathy_tp_contact_factory_get_from_handle (connection,
 			handle, tp_chat_got_self_contact_cb,
 			NULL, NULL, object);
 
 		/* Get initial member contacts */
 		members = tp_channel_group_get_members (channel);
 		handles = tp_intset_to_array (members);
-		empathy_tp_contact_factory_get_from_handles (self->priv->connection,
+		empathy_tp_contact_factory_get_from_handles (connection,
 			handles->len, (TpHandle *) handles->data,
 			tp_chat_got_added_contacts_cb, NULL, NULL, object);
 
@@ -1363,18 +1369,18 @@ tp_chat_constructor (GType                  type,
 		guint i;
 
 		/* Get the self contact from the connection's self handle */
-		handle = tp_connection_get_self_handle (self->priv->connection);
-		empathy_tp_contact_factory_get_from_handle (self->priv->connection,
+		handle = tp_connection_get_self_handle (connection);
+		empathy_tp_contact_factory_get_from_handle (connection,
 			handle, tp_chat_got_self_contact_cb,
 			NULL, NULL, object);
 
 		/* Get the remote contact */
 		handle = tp_channel_get_handle (channel, NULL);
-		empathy_tp_contact_factory_get_from_handle (self->priv->connection,
+		empathy_tp_contact_factory_get_from_handle (connection,
 			handle, tp_chat_got_remote_contact_cb,
 			NULL, NULL, object);
 
-		caps = tp_connection_get_capabilities (self->priv->connection);
+		caps = tp_connection_get_capabilities (connection);
 		g_assert (caps != NULL);
 
 		classes = tp_capabilities_get_channel_classes (caps);
@@ -1690,13 +1696,6 @@ empathy_tp_chat_get_account (EmpathyTpChat *self)
 	return self->priv->account;
 }
 
-TpConnection *
-empathy_tp_chat_get_connection (EmpathyTpChat *self)
-{
-	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (self), NULL);
-
-	return tp_channel_borrow_connection ((TpChannel *) self);
-}
 gboolean
 empathy_tp_chat_is_ready (EmpathyTpChat *self)
 {
diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h
index f303254..b5119fc 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -76,7 +76,6 @@ EmpathyTpChat *empathy_tp_chat_new                  (TpAccount *account,
 const gchar *  empathy_tp_chat_get_id               (EmpathyTpChat      *chat);
 EmpathyContact *empathy_tp_chat_get_remote_contact   (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,
 						     TpMessage     *message);
diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c
index c0d1b15..01736d7 100644
--- a/src/empathy-chat-window.c
+++ b/src/empathy-chat-window.c
@@ -403,7 +403,7 @@ chat_window_conversation_menu_update (EmpathyChatWindowPriv *priv,
 	tp_chat = empathy_chat_get_tp_chat (priv->current_chat);
 
 	if (tp_chat != NULL) {
-		connection = empathy_tp_chat_get_connection (tp_chat);
+		connection = tp_channel_borrow_connection (TP_CHANNEL (tp_chat));
 
 		sensitive = empathy_tp_chat_can_add_contact (tp_chat) &&
 			(tp_connection_get_status (connection, NULL) ==
diff --git a/src/empathy-invite-participant-dialog.c b/src/empathy-invite-participant-dialog.c
index c40bb94..4a66946 100644
--- a/src/empathy-invite-participant-dialog.c
+++ b/src/empathy-invite-participant-dialog.c
@@ -130,7 +130,7 @@ get_tp_contact_for_chat (EmpathyInviteParticipantDialog *self,
   GList *personas, *l;
   TpConnection *chat_conn;
 
-  chat_conn = empathy_tp_chat_get_connection (self->priv->tp_chat);
+  chat_conn = tp_channel_borrow_connection ((TpChannel *) self->priv->tp_chat);
 
   personas = folks_individual_get_personas (individual);
 



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