[haiku-commits] r40983 - in haiku/trunk: headers/os/mail src/kits/mail

  • From: clemens.zeidler@xxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 17 Mar 2011 01:45:31 +0100 (CET)

Author: czeidler
Date: 2011-03-17 01:45:30 +0100 (Thu, 17 Mar 2011)
New Revision: 40983
Changeset: https://dev.haiku-os.org/changeset/40983

Modified:
   haiku/trunk/headers/os/mail/MailSettings.h
   haiku/trunk/src/kits/mail/MailSettings.cpp
Log:
Do not recreate the account file when saving the settings. This fix 
alternating account names (once AccountName_1 the other time just 
AccountName).
Sort accounts by creation time. This fix the order in mail
preferences.



Modified: haiku/trunk/headers/os/mail/MailSettings.h
===================================================================
--- haiku/trunk/headers/os/mail/MailSettings.h  2011-03-16 23:47:16 UTC (rev 
40982)
+++ haiku/trunk/headers/os/mail/MailSettings.h  2011-03-17 00:45:30 UTC (rev 
40983)
@@ -172,7 +172,7 @@
 
        const   BEntry&                         AccountFile();
 private:
-                       status_t                        _CreateAccountFile();
+                       status_t                        
_CreateAccountFilePath();
 
                        status_t                        fStatus;
                        BEntry                          fAccountFile;

Modified: haiku/trunk/src/kits/mail/MailSettings.cpp
===================================================================
--- haiku/trunk/src/kits/mail/MailSettings.cpp  2011-03-16 23:47:16 UTC (rev 
40982)
+++ haiku/trunk/src/kits/mail/MailSettings.cpp  2011-03-17 00:45:30 UTC (rev 
40983)
@@ -335,12 +335,38 @@
        BDirectory dir(path.Path());
        if (dir.InitCheck() != B_OK)
                return;
+
+       std::vector<time_t> creationTimeList;
        BEntry entry;
        while (dir.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) {
+               BNode node(&entry);
+               time_t creationTime;
+               if (node.GetCreationTime(&creationTime) != B_OK)
+                       continue;
+
                BMailAccountSettings* account = new BMailAccountSettings(entry);
-               if (account->InitCheck() != B_OK)
+               if (account->InitCheck() != B_OK) {
+                       delete account;
                        continue;
-               fAccounts.AddItem(account);
+               }
+
+               // sort by creation time
+               int insertIndex = -1;
+               for (unsigned int i = 0; i < creationTimeList.size(); i++) {
+                       if (creationTimeList[i] > creationTime) {
+                               insertIndex = i;
+                               break;
+                       }
+               }
+               if (insertIndex < 0) {
+                       fAccounts.AddItem(account);
+                       creationTimeList.push_back(creationTime);
+               } else {
+                       fAccounts.AddItem(account, insertIndex);
+                       creationTimeList.insert(creationTimeList.begin() + 
insertIndex,
+                               creationTime);
+               }
+               
        }
 }
 
@@ -793,15 +819,10 @@
        fOutboundSettings.Save(outboundSettings);
        settings.AddMessage("outbound", &outboundSettings);
 
-       BEntry oldEntry = fAccountFile;
-       status_t status = _CreateAccountFile();
+       status_t status = _CreateAccountFilePath();
        if (status != B_OK)
                return status;
-       oldEntry.Remove();
 
-       BPath path;
-       fAccountFile.GetPath(&path);
-
        BFile file(&fAccountFile, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
        status = file.InitCheck();
        if (status != B_OK)
@@ -836,7 +857,7 @@
 
 
 status_t
-BMailAccountSettings::_CreateAccountFile()
+BMailAccountSettings::_CreateAccountFilePath()
 {
        BPath path;
        status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
@@ -845,6 +866,9 @@
        path.Append("Mail/accounts");
        create_directory(path.Path(), 777);
 
+       if (fAccountFile.InitCheck() == B_OK)
+               return B_OK;
+
        BString fileName = fAccountName;
        if (fileName == "")
                fileName << fAccountID; 


Other related posts:

  • » [haiku-commits] r40983 - in haiku/trunk: headers/os/mail src/kits/mail - clemens . zeidler