Now also loads mail settings from common.

* Also removed the superfluous and unused timeout argument from Save().
This commit is contained in:
Axel Dörfler
2015-01-06 15:22:28 +01:00
parent 9d8cf1b6f7
commit 1f87386b0a
2 changed files with 41 additions and 47 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ public:
BMailSettings(); BMailSettings();
~BMailSettings(); ~BMailSettings();
status_t Save(bigtime_t timeout = B_INFINITE_TIMEOUT); status_t Save();
status_t Reload(); status_t Reload();
status_t InitCheck() const; status_t InitCheck() const;
+32 -38
View File
@@ -51,30 +51,24 @@ BMailSettings::InitCheck() const
status_t status_t
BMailSettings::Save(bigtime_t /*timeout*/) BMailSettings::Save()
{ {
status_t ret;
//
// Find chain-saving directory
//
BPath path; BPath path;
ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path); status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
if (ret != B_OK) { if (status != B_OK) {
fprintf(stderr, "Couldn't find user settings directory: %s\n", fprintf(stderr, "Couldn't find user settings directory: %s\n",
strerror(ret)); strerror(status));
return ret; return status;
} }
path.Append("Mail"); path.Append("Mail");
status_t result = BPrivate::WriteMessageFile(fData, path, status = BPrivate::WriteMessageFile(fData, path, "new_mail_daemon");
"new_mail_daemon"); if (status != B_OK)
if (result < B_OK) return status;
return result;
BMessenger(B_MAIL_DAEMON_SIGNATURE).SendMessage('mrrs');
BMessenger(B_MAIL_DAEMON_SIGNATURE).SendMessage(
BPrivate::kMsgSettingsUpdated);
return B_OK; return B_OK;
} }
@@ -82,41 +76,41 @@ BMailSettings::Save(bigtime_t /*timeout*/)
status_t status_t
BMailSettings::Reload() BMailSettings::Reload()
{ {
status_t ret; // Try directories from most specific to least
directory_which which[] = {
B_USER_SETTINGS_DIRECTORY,
B_COMMON_SETTINGS_DIRECTORY};
status_t status = B_ENTRY_NOT_FOUND;
for (size_t i = 0; i < sizeof(which) / sizeof(which[0]); i++) {
BPath path; BPath path;
ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path); status = find_directory(which[i], &path);
if (ret != B_OK) { if (status != B_OK)
fprintf(stderr, "Couldn't find user settings directory: %s\n", continue;
strerror(ret));
return ret;
}
path.Append("Mail/new_mail_daemon"); path.Append("Mail/new_mail_daemon");
BFile file;
// open status = file.SetTo(path.Path(), B_READ_ONLY);
BFile settings(path.Path(),B_READ_ONLY); if (status != B_OK)
ret = settings.InitCheck(); continue;
if (ret != B_OK) {
fprintf(stderr, "Couldn't open settings file '%s': %s\n",
path.Path(), strerror(ret));
return ret;
}
// read settings // read settings
BMessage tmp; BMessage settings;
ret = tmp.Unflatten(&settings); status = settings.Unflatten(&file);
if (ret != B_OK) { if (status != B_OK) {
fprintf(stderr, "Couldn't read settings from '%s': %s\n", fprintf(stderr, "Couldn't read settings from '%s': %s\n",
path.Path(), strerror(ret)); path.Path(), strerror(status));
return ret; continue;
} }
// clobber old settings // clobber old settings
fData = tmp; fData = settings;
return B_OK; return B_OK;
} }
return status;
}
// # pragma mark - Global settings // # pragma mark - Global settings