]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-account-manager.c
Add api to create accounts, by cm and proto name
[empathy.git] / libempathy / empathy-account-manager.c
index fd8a21b1d5c95c9353e0c4bed622c0948ca6ed9f..0d09ec5f0819d80e3f029b687be91e6c0741d1d5 100644 (file)
@@ -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)
 {