[haiku-commits] haiku: hrev49767 - src/kits/mail headers/os/mail

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 7 Nov 2015 21:05:29 +0100 (CET)

hrev49767 adds 1 changeset to branch 'master'
old head: 617793f41b37bc5338b116b0a829a4be066d0696
new head: d8c022250dcfaaf6cba80a709147f5d626108492
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=d8c022250dcf+%5E617793f41b37

----------------------------------------------------------------------------

d8c022250dcf: BMailAccountSettings: use BPathFinder.

* This allows to put add-ons in non-packaged folders, too.
* Also, Set{In|Out}boundAddOn() only ever looked in the system dir.

[ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision: hrev49767
Commit: d8c022250dcfaaf6cba80a709147f5d626108492
URL: http://cgit.haiku-os.org/haiku/commit/?id=d8c022250dcf
Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date: Sat Nov 7 19:46:45 2015 UTC

----------------------------------------------------------------------------

2 files changed, 41 insertions(+), 30 deletions(-)
headers/os/mail/MailSettings.h | 2 ++
src/kits/mail/MailSettings.cpp | 69 +++++++++++++++++++++-----------------

----------------------------------------------------------------------------

diff --git a/headers/os/mail/MailSettings.h b/headers/os/mail/MailSettings.h
index eac7c85..26b6336 100644
--- a/headers/os/mail/MailSettings.h
+++ b/headers/os/mail/MailSettings.h
@@ -171,6 +171,8 @@ public:

private:
status_t
_CreateAccountFilePath();
+ status_t _GetAddOnRef(const
char* subPath,
+ const
char* name, entry_ref& ref);

private:
status_t fStatus;
diff --git a/src/kits/mail/MailSettings.cpp b/src/kits/mail/MailSettings.cpp
index 9898420..52cabe4 100644
--- a/src/kits/mail/MailSettings.cpp
+++ b/src/kits/mail/MailSettings.cpp
@@ -23,6 +23,7 @@
#include <Message.h>
#include <Messenger.h>
#include <Path.h>
+#include <PathFinder.h>
#include <String.h>
#include <Window.h>

@@ -431,23 +432,24 @@ BMailAddOnSettings::Load(const BMessage& message)
return B_BAD_VALUE;

BPath path(pathString);
- if (!path.IsAbsolute()) {
- directory_which which[] = {
- B_USER_ADDONS_DIRECTORY,
- B_SYSTEM_ADDONS_DIRECTORY
- };

- for (size_t i = 0; i < sizeof(which) / sizeof(which[0]); i++) {
- status_t status = find_directory(which[i], &path);
- if (status != B_OK)
- continue;
+ if (!path.IsAbsolute()) {
+ BStringList paths;
+ BPathFinder().FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY,
"mail_daemon",
+ paths);

- path.Append("mail_daemon");
- path.Append(pathString);
+ status_t status = B_ENTRY_NOT_FOUND;

- if (BEntry(path.Path()).Exists())
+ for (int32 i = 0; i < paths.CountStrings(); i++) {
+ path.SetTo(paths.StringAt(i), pathString);
+ BEntry entry(path.Path());
+ if (entry.Exists()) {
+ status = B_OK;
break;
+ }
}
+ if (status != B_OK)
+ return status;
}

status_t status = get_ref_for_path(path.Path(), &fRef);
@@ -737,17 +739,11 @@ BMailAccountSettings::ReturnAddress() const
bool
BMailAccountSettings::SetInboundAddOn(const char* name)
{
- BPath path;
- status_t status = find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
- if (status != B_OK)
- return false;
- path.Append("mail_daemon");
- path.Append("inbound_protocols");
- path.Append(name);
entry_ref ref;
- get_ref_for_path(path.Path(), &ref);
- fInboundSettings.SetAddOnRef(ref);
+ if (_GetAddOnRef("mail_daemon/inbound_protocols", name, ref) != B_OK)
+ return false;

+ fInboundSettings.SetAddOnRef(ref);
return true;
}

@@ -755,17 +751,11 @@ BMailAccountSettings::SetInboundAddOn(const char* name)
bool
BMailAccountSettings::SetOutboundAddOn(const char* name)
{
- BPath path;
- status_t status = find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
- if (status != B_OK)
- return false;
- path.Append("mail_daemon");
- path.Append("outbound_protocols");
- path.Append(name);
entry_ref ref;
- get_ref_for_path(path.Path(), &ref);
- fOutboundSettings.SetAddOnRef(ref);
+ if (_GetAddOnRef("mail_daemon/outbound_protocols", name, ref) != B_OK)
+ return false;

+ fOutboundSettings.SetAddOnRef(ref);
return true;
}

@@ -980,3 +970,22 @@ BMailAccountSettings::_CreateAccountFilePath()
path.Append(fileName);
return fAccountFile.SetTo(path.Path());
}
+
+
+status_t
+BMailAccountSettings::_GetAddOnRef(const char* subPath, const char* name,
+ entry_ref& ref)
+{
+ BStringList paths;
+ BPathFinder().FindPaths(B_FIND_PATH_ADD_ONS_DIRECTORY, subPath, paths);
+
+ for (int32 i = 0; i < paths.CountStrings(); i++) {
+ BPath path(paths.StringAt(i), name);
+ BEntry entry(path.Path());
+ if (entry.Exists()) {
+ if (entry.GetRef(&ref) == B_OK)
+ return B_OK;
+ }
+ }
+ return B_ENTRY_NOT_FOUND;
+}


Other related posts:

  • » [haiku-commits] haiku: hrev49767 - src/kits/mail headers/os/mail - axeld