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.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40983 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler 2011-03-17 00:45:30 +00:00
parent 18bfd5000e
commit 495ecdfea8
2 changed files with 35 additions and 11 deletions

View File

@ -172,7 +172,7 @@ class BMailAccountSettings
const BEntry& AccountFile();
private:
status_t _CreateAccountFile();
status_t _CreateAccountFilePath();
status_t fStatus;
BEntry fAccountFile;

View File

@ -335,12 +335,38 @@ BMailAccounts::BMailAccounts()
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) {
BMailAccountSettings* account = new BMailAccountSettings(entry);
if (account->InitCheck() != B_OK)
BNode node(&entry);
time_t creationTime;
if (node.GetCreationTime(&creationTime) != B_OK)
continue;
fAccounts.AddItem(account);
BMailAccountSettings* account = new BMailAccountSettings(entry);
if (account->InitCheck() != B_OK) {
delete account;
continue;
}
// 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,14 +819,9 @@ BMailAccountSettings::Save()
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();
@ -836,7 +857,7 @@ BMailAccountSettings::AccountFile()
status_t
BMailAccountSettings::_CreateAccountFile()
BMailAccountSettings::_CreateAccountFilePath()
{
BPath path;
status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
@ -845,6 +866,9 @@ BMailAccountSettings::_CreateAccountFile()
path.Append("Mail/accounts");
create_directory(path.Path(), 777);
if (fAccountFile.InitCheck() == B_OK)
return B_OK;
BString fileName = fAccountName;
if (fileName == "")
fileName << fAccountID;