From c35d24e90357c5098638961610abbb15c3c48209 Mon Sep 17 00:00:00 2001
From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Date: Thu, 16 Apr 2009 17:23:21 -0400
Subject: [PATCH] Restore adding account - ticket #1172

---
 src/managerimpl.cpp | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp
index b661c209d4..a5c25abb96 100644
--- a/src/managerimpl.cpp
+++ b/src/managerimpl.cpp
@@ -2159,7 +2159,7 @@ ManagerImpl::getAccountList()
     // Otherelse, load the custom one
     // ie according to the saved order
     else {
-
+               
         for (i=0; i<account_order.size (); i++) {
             // This account has not been loaded, so we ignore it
             if ( (iter=_accountMap.find (account_order[i])) != _accountMap.end() )
@@ -2171,6 +2171,8 @@ ManagerImpl::getAccountList()
                 }
             }
         }
+
+        
     }
    
     return v;
@@ -2269,11 +2271,17 @@ ManagerImpl::addAccount(const std::map< std::string, std::string >& details)
 {
 
     /** @todo Deal with both the _accountMap and the Configuration */
-    std::string accountType = (*details.find(CONFIG_ACCOUNT_TYPE)).second;
+    std::string accountType, account_list;
     Account* newAccount;
     std::stringstream accountID;
+    AccountID newAccountID;
+
     accountID << "Account:" << time(NULL);
-    AccountID newAccountID = accountID.str();
+    newAccountID = accountID.str();
+    
+    // Get the type
+    accountType = (*details.find(CONFIG_ACCOUNT_TYPE)).second;
+
     /** @todo Verify the uniqueness, in case a program adds accounts, two in a row. */
 
     if (accountType == "SIP") {
@@ -2289,6 +2297,16 @@ ManagerImpl::addAccount(const std::map< std::string, std::string >& details)
     _accountMap[newAccountID] = newAccount;
     setAccountDetails(accountID.str(), details);
 
+    // Add the newly created account in the account order list
+    account_list = getConfigString (PREFERENCES, CONFIG_ACCOUNTS_ORDER);
+    if (account_list != "")
+    {
+        newAccountID += "/";
+        // Prepend the new account 
+        account_list.insert (0, newAccountID);
+        setConfig (PREFERENCES, CONFIG_ACCOUNTS_ORDER, account_list);
+    }
+
     saveConfig();
 
     if (_dbus) _dbus->getConfigurationManager()->accountsChanged();
-- 
GitLab