[empathy/mc5: 26/483] Add api to create accounts, by cm and proto name



commit 7445fd6d08294399972dd0c2c808d9aabfc11b20
Author: Sjoerd Simons <sjoerd simons collabora co uk>
Date:   Sun Jul 5 16:19:59 2009 +0100

    Add api to create accounts, by cm and proto name

 libempathy/empathy-account-manager.c |   42 +++++++++++++++++++++++++++++++++-
 libempathy/empathy-account-manager.h |    8 +++++-
 tests/check-empathy-helpers.c        |    3 +-
 3 files changed, 50 insertions(+), 3 deletions(-)
---
diff --git a/libempathy/empathy-account-manager.c b/libempathy/empathy-account-manager.c
index fd8a21b..0d09ec5 100644
--- a/libempathy/empathy-account-manager.c
+++ b/libempathy/empathy-account-manager.c
@@ -22,6 +22,7 @@
 #include "config.h"
 
 #include <libmissioncontrol/mc-account-monitor.h>
+#include <telepathy-glib/util.h>
 
 #include "empathy-account-manager.h"
 #include "empathy-account-priv.h"
@@ -582,7 +583,7 @@ empathy_account_manager_dup_singleton (void)
 }
 
 EmpathyAccount *
-empathy_account_manager_create (EmpathyAccountManager *manager,
+empathy_account_manager_create_by_profile (EmpathyAccountManager *manager,
   McProfile *profile)
 {
   McAccount *mc_account = mc_account_create (profile);
@@ -591,6 +592,45 @@ empathy_account_manager_create (EmpathyAccountManager *manager,
       mc_account));
 }
 
+EmpathyAccount *
+empathy_account_manager_create (EmpathyAccountManager *manager,
+	const gchar *connection_manager,
+	const gchar *protocol,
+	const gchar *display_name)
+{
+	McProfile *profile;
+	gboolean found;
+	GList *profiles, *l;
+	EmpathyAccount *result = NULL;
+
+	profiles = mc_profiles_list_by_protocol (protocol);
+
+	for (l = profiles; l != NULL;  l = g_list_next (l)) {
+		McProtocol *protocol;
+		McManager *cm;
+
+		profile = MC_PROFILE (l->data);
+
+		protocol = mc_profile_get_protocol (profile);
+		cm = mc_protocol_get_manager (protocol);
+		found = !tp_strdiff (mc_manager_get_unique_name (cm),
+			connection_manager);
+		
+		g_object_unref (protocol);
+		g_object_unref (manager);
+		
+		if (found) {
+			result = empathy_account_manager_create_by_profile (manager, profile);
+			empathy_account_set_display_name (result, display_name);
+			break;
+		}
+	}
+
+	mc_profiles_free_list (profiles);
+	
+	return result;
+}
+
 int
 empathy_account_manager_get_connected_accounts (EmpathyAccountManager *manager)
 {
diff --git a/libempathy/empathy-account-manager.h b/libempathy/empathy-account-manager.h
index b04571f..2d77610 100644
--- a/libempathy/empathy-account-manager.h
+++ b/libempathy/empathy-account-manager.h
@@ -52,7 +52,13 @@ GType empathy_account_manager_get_type (void);
 /* public methods */
 
 EmpathyAccountManager * empathy_account_manager_dup_singleton (void);
-EmpathyAccount *        empathy_account_manager_create
+EmpathyAccount *        empathy_account_manager_create (
+    EmpathyAccountManager *manager,
+    const gchar *connection_manager,
+    const gchar *protocol,
+    const gchar *display_name);
+
+EmpathyAccount *        empathy_account_manager_create_by_profile
                                 (EmpathyAccountManager *manager,
                                  McProfile *profile);
 int                     empathy_account_manager_get_connected_accounts
diff --git a/tests/check-empathy-helpers.c b/tests/check-empathy-helpers.c
index c77cf9b..fc6f044 100644
--- a/tests/check-empathy-helpers.c
+++ b/tests/check-empathy-helpers.c
@@ -79,7 +79,8 @@ get_test_account (void)
   if (g_list_length (accounts) == 0)
     {
       /* need to create a test account */
-      account = empathy_account_manager_create (account_manager, profile);
+      account = empathy_account_manager_create_by_profile (account_manager,
+          profile);
     }
   else
     {



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