[empathy/mc5: 226/483] Chang the API of AccountManager to have the get lookup the account by name



commit c9ef23052d2e5007e6120dcc881d6c382fcf48d3
Author: Sjoerd Simons <sjoerd simons collabora co uk>
Date:   Thu Jul 30 17:35:38 2009 +0200

    Chang the API of AccountManager to have the get lookup the account by name
    
    EmpathyAccountManager used to have a _lookup function that looked up accounts
    by name and a _get function that lookup up accounts by connection. This is
    confusing, as looking up an account for a connection is less common rename have
    the _get_account be the same _lookup (but without returning a ref) and add a
    _get_account_for_connection function lookup by account

 libempathy-gtk/empathy-chat.c              |    6 ++++--
 libempathy-gtk/empathy-contact-list-view.c |    2 +-
 libempathy/empathy-account-manager.c       |   15 +++++----------
 libempathy/empathy-account-manager.h       |    4 ++--
 libempathy/empathy-chatroom-manager.c      |    8 ++++----
 libempathy/empathy-contact.c               |    3 ++-
 libempathy/empathy-dispatcher.c            |    4 +---
 libempathy/empathy-log-store-empathy.c     |    4 +++-
 megaphone/src/megaphone-applet.c           |    3 ++-
 src/empathy-chat-window.c                  |    4 +---
 src/empathy.c                              |    2 +-
 11 files changed, 26 insertions(+), 29 deletions(-)
---
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index 0358b0a..d52d7af 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -203,7 +203,8 @@ chat_new_connection_cb (EmpathyAccountManager *manager,
 	EmpathyChatPriv *priv = GET_PRIV (chat);
 	EmpathyAccount *account;
 
-	account = empathy_account_manager_get_account (manager, connection);
+	account = empathy_account_manager_get_account_for_connection (manager,
+		connection);
 	if (!priv->tp_chat && account == priv->account &&
 	    priv->handle_type != TP_HANDLE_TYPE_NONE &&
 	    !EMP_STR_EMPTY (priv->id)) {
@@ -1766,7 +1767,8 @@ empathy_chat_set_tp_chat (EmpathyChat   *chat,
 
 	priv->tp_chat = g_object_ref (tp_chat);
 	connection = empathy_tp_chat_get_connection (priv->tp_chat);
-	priv->account = empathy_account_manager_get_account (priv->account_manager,
+	priv->account = empathy_account_manager_get_account_for_connection (
+							     priv->account_manager,
 							     connection);
 	g_object_ref (priv->account);
 
diff --git a/libempathy-gtk/empathy-contact-list-view.c b/libempathy-gtk/empathy-contact-list-view.c
index 783d986..2ff27b1 100644
--- a/libempathy-gtk/empathy-contact-list-view.c
+++ b/libempathy-gtk/empathy-contact-list-view.c
@@ -302,7 +302,7 @@ contact_list_view_drag_data_received (GtkWidget         *view,
 	account_id = strv[0];
 	contact_id = strv[1];
   account_manager = empathy_account_manager_dup_singleton ();
-	account = empathy_account_manager_lookup (account_manager, account_id);
+	account = empathy_account_manager_get_account (account_manager, account_id);
 	if (account) {
 		TpConnection *connection;
 
diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c
index 7339acb..c199e1d 100644
--- a/libempathy/empathy-account-manager.c
+++ b/libempathy/empathy-account-manager.c
@@ -665,8 +665,9 @@ empathy_account_manager_get_count (EmpathyAccountManager *manager)
 }
 
 EmpathyAccount *
-empathy_account_manager_get_account (EmpathyAccountManager *manager,
-                                     TpConnection          *connection)
+empathy_account_manager_get_account_for_connection (
+    EmpathyAccountManager *manager,
+    TpConnection          *connection)
 {
   EmpathyAccountManagerPriv *priv;
   GHashTableIter iter;
@@ -689,18 +690,12 @@ empathy_account_manager_get_account (EmpathyAccountManager *manager,
 }
 
 EmpathyAccount *
-empathy_account_manager_lookup (EmpathyAccountManager *manager,
+empathy_account_manager_get_account (EmpathyAccountManager *manager,
     const gchar *unique_name)
 {
   EmpathyAccountManagerPriv *priv = GET_PRIV (manager);
-  EmpathyAccount *account;
-
-  account = g_hash_table_lookup (priv->accounts, unique_name);
 
-  if (account != NULL)
-    g_object_ref (account);
-
-  return account;
+  return g_hash_table_lookup (priv->accounts, unique_name);
 }
 
 GList *
diff --git a/libempathy/empathy-account-manager.h b/libempathy/empathy-account-manager.h
index 953d8bc..1f73f63 100644
--- a/libempathy/empathy-account-manager.h
+++ b/libempathy/empathy-account-manager.h
@@ -66,10 +66,10 @@ int                     empathy_account_manager_get_connecting_accounts
                                 (EmpathyAccountManager *manager);
 int                     empathy_account_manager_get_count
                                 (EmpathyAccountManager *manager);
-EmpathyAccount *        empathy_account_manager_get_account
+EmpathyAccount *        empathy_account_manager_get_account_for_connection
                                 (EmpathyAccountManager *manager,
                                  TpConnection          *connection);
-EmpathyAccount *        empathy_account_manager_lookup
+EmpathyAccount *        empathy_account_manager_get_account
                                 (EmpathyAccountManager *manager,
                                  const gchar *unique_name);
 GList *                 empathy_account_manager_dup_accounts
diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c
index c5f9864..7c3559e 100644
--- a/libempathy/empathy-chatroom-manager.c
+++ b/libempathy/empathy-chatroom-manager.c
@@ -223,7 +223,8 @@ chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager,
 		xmlFree (str);
 	}
 
-	account = empathy_account_manager_lookup (priv->account_manager, account_id);
+	account = empathy_account_manager_get_account (priv->account_manager,
+		account_id);
 	if (!account) {
 		g_free (name);
 		g_free (room);
@@ -236,7 +237,6 @@ chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager,
 	add_chatroom (manager, chatroom);
 	g_signal_emit (manager, signals[CHATROOM_ADDED], 0, chatroom);
 
-	g_object_unref (account);
 	g_free (name);
 	g_free (room);
 	g_free (account_id);
@@ -704,8 +704,8 @@ chatroom_manager_observe_channel_cb (EmpathyDispatcher *dispatcher,
   chat = EMPATHY_TP_CHAT (
     empathy_dispatch_operation_get_channel_wrapper (operation));
   connection = empathy_tp_chat_get_connection (chat);
-  account = empathy_account_manager_get_account (priv->account_manager,
-      connection);
+  account = empathy_account_manager_get_account_for_connection (
+      priv->account_manager, connection);
 
   roomname = empathy_tp_chat_get_id (chat);
 
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index c82ecd4..bbce927 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -570,7 +570,8 @@ empathy_contact_get_account (EmpathyContact *contact)
       /* FIXME: This assume the account manager already exists */
       manager = empathy_account_manager_dup_singleton ();
       connection = tp_contact_get_connection (priv->tp_contact);
-      priv->account = empathy_account_manager_get_account (manager, connection);
+      priv->account = empathy_account_manager_get_account_for_connection (
+          manager, connection);
       g_object_ref (priv->account);
       g_object_unref (manager);
     }
diff --git a/libempathy/empathy-dispatcher.c b/libempathy/empathy-dispatcher.c
index 0b2a74a..fe33025 100644
--- a/libempathy/empathy-dispatcher.c
+++ b/libempathy/empathy-dispatcher.c
@@ -1801,7 +1801,7 @@ empathy_dispatcher_handle_channels (TpSvcClientHandler *self,
   EmpathyAccount *account;
   TpConnection *connection;
 
-  account = empathy_account_manager_lookup (priv->account_manager,
+  account = empathy_account_manager_get_account (priv->account_manager,
     account_path);
   /* FIXME */
   g_assert (account != NULL);
@@ -1824,8 +1824,6 @@ empathy_dispatcher_handle_channels (TpSvcClientHandler *self,
     }
 
   tp_svc_client_handler_return_from_handle_channels (context);
-
-  g_object_unref (account);
 }
 
 static void
diff --git a/libempathy/empathy-log-store-empathy.c b/libempathy/empathy-log-store-empathy.c
index 4bb17e4..81cbcad 100644
--- a/libempathy/empathy-log-store-empathy.c
+++ b/libempathy/empathy-log-store-empathy.c
@@ -405,8 +405,10 @@ log_store_empathy_search_hit_new (EmpathyLogStore *self,
 
   unescaped = g_strdup_printf ("/%s", g_strdelimit (account_name, "%", '/'));
 
-  hit->account = empathy_account_manager_lookup (priv->account_manager,
+  hit->account = empathy_account_manager_get_account (priv->account_manager,
     unescaped);
+  if (hit->account != NULL)
+    g_object_ref (hit->account);
   hit->filename = g_strdup (filename);
 
   g_free (unescaped);
diff --git a/megaphone/src/megaphone-applet.c b/megaphone/src/megaphone-applet.c
index 1ef88eb..c269c7c 100644
--- a/megaphone/src/megaphone-applet.c
+++ b/megaphone/src/megaphone-applet.c
@@ -443,7 +443,7 @@ megaphone_applet_set_contact (MegaphoneApplet *applet,
 	/* Lookup the new contact */
 	if (str) {
 		strv = g_strsplit (str, "/", 2);
-		priv->account = empathy_account_manager_lookup (priv->account_manager, 
+		priv->account = empathy_account_manager_get_account (priv->account_manager,
 			strv[0]);
 		priv->id = strv[1];
 		g_free (strv[0]);
@@ -451,6 +451,7 @@ megaphone_applet_set_contact (MegaphoneApplet *applet,
 	}
 
 	if (priv->account) {
+		g_object_ref (priv->account);
 		connection = empathy_account_get_connection (priv->account);
 		if (connection) {
 			megaphone_applet_new_connection_cb (priv->account_manager,
diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c
index 9694a65..47ef37c 100644
--- a/src/empathy-chat-window.c
+++ b/src/empathy-chat-window.c
@@ -1269,7 +1269,7 @@ chat_window_drag_data_received (GtkWidget        *widget,
 		strv = g_strsplit (id, "/", 2);
 		account_id = strv[0];
 		contact_id = strv[1];
-		account = empathy_account_manager_lookup (account_manager, account_id);
+		account = empathy_account_manager_get_account (account_manager, account_id);
 		chat = empathy_chat_window_find_chat (account, contact_id);
 
 		if (!chat) {
@@ -1282,11 +1282,9 @@ chat_window_drag_data_received (GtkWidget        *widget,
 					connection, contact_id, NULL, NULL);
 			}
 
-			g_object_unref (account);
 			g_strfreev (strv);
 			return;
 		}
-		g_object_unref (account);
 		g_object_unref (account_manager);
 		g_strfreev (strv);
 
diff --git a/src/empathy.c b/src/empathy.c
index 4e824bc..956b05e 100644
--- a/src/empathy.c
+++ b/src/empathy.c
@@ -113,7 +113,7 @@ dispatch_cb (EmpathyDispatcher *dispatcher,
 
 			manager = empathy_account_manager_dup_singleton ();
 			connection = empathy_tp_chat_get_connection (tp_chat);
-			account = empathy_account_manager_get_account (manager,
+			account = empathy_account_manager_get_account_for_connection (manager,
 								       connection);
 			chat = empathy_chat_window_find_chat (account, id);
 			g_object_unref (manager);



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