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;
+40 -46
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,39 +76,39 @@ 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;
BPath path; for (size_t i = 0; i < sizeof(which) / sizeof(which[0]); i++) {
ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path); BPath path;
if (ret != B_OK) { status = find_directory(which[i], &path);
fprintf(stderr, "Couldn't find user settings directory: %s\n", if (status != B_OK)
strerror(ret)); continue;
return ret;
path.Append("Mail/new_mail_daemon");
BFile file;
status = file.SetTo(path.Path(), B_READ_ONLY);
if (status != B_OK)
continue;
// read settings
BMessage settings;
status = settings.Unflatten(&file);
if (status != B_OK) {
fprintf(stderr, "Couldn't read settings from '%s': %s\n",
path.Path(), strerror(status));
continue;
}
// clobber old settings
fData = settings;
return B_OK;
} }
path.Append("Mail/new_mail_daemon"); return status;
// open
BFile settings(path.Path(),B_READ_ONLY);
ret = settings.InitCheck();
if (ret != B_OK) {
fprintf(stderr, "Couldn't open settings file '%s': %s\n",
path.Path(), strerror(ret));
return ret;
}
// read settings
BMessage tmp;
ret = tmp.Unflatten(&settings);
if (ret != B_OK) {
fprintf(stderr, "Couldn't read settings from '%s': %s\n",
path.Path(), strerror(ret));
return ret;
}
// clobber old settings
fData = tmp;
return B_OK;
} }