diff --git a/src/preferences/mail/AutoConfigView.cpp b/src/preferences/mail/AutoConfigView.cpp index 95a92b34b1..d93028ec46 100644 --- a/src/preferences/mail/AutoConfigView.cpp +++ b/src/preferences/mail/AutoConfigView.cpp @@ -40,12 +40,12 @@ AutoConfigView::AutoConfigView(BRect rect, AutoConfig &config) // protocol view topLeft.y += stepSize; rightDown.y += stepSize; - fInProtocolsField = SetupProtocolView(BRect(topLeft, rightDown)); + fInProtocolsField = _SetupProtocolView(BRect(topLeft, rightDown)); if (fInProtocolsField) AddChild(fInProtocolsField); // search for smtp ref - GetSMTPAddonRef(&fSMTPAddonRef); + _GetSMTPAddonRef(&fSMTPAddonRef); // email view topLeft.y += stepSize; @@ -105,14 +105,12 @@ AutoConfigView::AttachedToWindow() void AutoConfigView::MessageReceived(BMessage *msg) { - BString text, login; - switch (msg->what) - { + switch (msg->what) { case kEMailChangedMsg: { - text = fLoginNameView->Text(); + BString text = fLoginNameView->Text(); if (text == "") - ProposeUsername(); + _ProposeUsername(); fLoginNameView->MakeFocus(); fLoginNameView->TextView()->SelectAll(); @@ -159,9 +157,9 @@ AutoConfigView::GetBasicAccountInfo(account_info &info) BMenuField* -AutoConfigView::SetupProtocolView(BRect rect) +AutoConfigView::_SetupProtocolView(BRect rect) { - BPopUpMenu *menu = new BPopUpMenu(B_TRANSLATE("Choose Protocol")); + BPopUpMenu* menu = new BPopUpMenu(B_TRANSLATE("Choose Protocol")); for (int i = 0; i < 2; i++) { BPath path; @@ -202,10 +200,11 @@ AutoConfigView::SetupProtocolView(BRect rect) status_t -AutoConfigView::GetSMTPAddonRef(entry_ref *ref) +AutoConfigView::_GetSMTPAddonRef(entry_ref *ref) { directory_which which[] = { B_USER_ADDONS_DIRECTORY, + B_COMMON_ADDONS_DIRECTORY, B_BEOS_ADDONS_DIRECTORY }; @@ -229,24 +228,21 @@ AutoConfigView::GetSMTPAddonRef(entry_ref *ref) BString -AutoConfigView::ExtractLocalPart(const char* email) +AutoConfigView::_ExtractLocalPart(const char* email) { - BString emailS(email); - BString localPart; - int32 at = emailS.FindLast("@"); - emailS.CopyInto(localPart, 0, at); - return localPart; + const char* at = strrchr(email, '@'); + return BString(email, at - email); } void -AutoConfigView::ProposeUsername() +AutoConfigView::_ProposeUsername() { const char* email = fEmailView->Text(); provider_info info; status_t status = fAutoConfig.GetInfoFromMailAddress(email, &info); if (status == B_OK) { - BString localPart = ExtractLocalPart(email); + BString localPart = _ExtractLocalPart(email); switch (info.username_pattern) { case 0: // username is the mail address @@ -324,7 +320,7 @@ ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info) box->AddChild(fInboundNameView); - GetAuthEncrMenu(info.inboundProtocol, &fInboundAuthMenu, + _GetAuthEncrMenu(info.inboundProtocol, &fInboundAuthMenu, &fInboundEncryptionMenu); if (fInboundAuthMenu != NULL) { int authID = info.providerInfo.authentification_pop; @@ -379,7 +375,7 @@ ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info) box->AddChild(fOutboundNameView); - GetAuthEncrMenu(info.outboundProtocol, &fOutboundAuthMenu, + _GetAuthEncrMenu(info.outboundProtocol, &fOutboundAuthMenu, &fOutboundEncryptionMenu); if (fOutboundAuthMenu != NULL) { BMenuItem *item = fOutboundAuthMenu->Menu()->ItemAt( @@ -468,12 +464,12 @@ ServerSettingsView::GetServerInfo(account_info &info) = fOutboundEncryptionMenu->Menu()->IndexOf(item); } } - DetectMenuChanges(); + _DetectMenuChanges(); } void -ServerSettingsView::DetectMenuChanges() +ServerSettingsView::_DetectMenuChanges() { bool changed = false; if (fInboundAuthMenu != NULL) { @@ -505,12 +501,12 @@ ServerSettingsView::DetectMenuChanges() void -ServerSettingsView::GetAuthEncrMenu(entry_ref protocol, - BMenuField **authField, BMenuField **sslField) +ServerSettingsView::_GetAuthEncrMenu(entry_ref protocol, + BMenuField** authField, BMenuField** sslField) { BMailAccountSettings dummySettings; BView *view = CreateConfigView(protocol, dummySettings.InboundSettings(), - dummySettings, &fImageId); + dummySettings, fImageId); *authField = (BMenuField *)view->FindView("auth_method"); *sslField = (BMenuField *)view->FindView("flavor"); diff --git a/src/preferences/mail/AutoConfigView.h b/src/preferences/mail/AutoConfigView.h index 523d26097d..e22bdbd812 100644 --- a/src/preferences/mail/AutoConfigView.h +++ b/src/preferences/mail/AutoConfigView.h @@ -1,11 +1,12 @@ /* - * Copyright 2007-2011, Haiku, Inc. All rights reserved. + * Copyright 2007-2012, Haiku, Inc. All rights reserved. * Copyright 2011, Clemens Zeidler * Distributed under the terms of the MIT License. */ #ifndef AUTO_CONFIG_VIEW_H #define AUTO_CONFIG_VIEW_H + #include "AutoConfig.h" #include "ConfigViews.h" @@ -22,16 +23,14 @@ const int32 kProtokollChangedMsg = '?pch'; const int32 kServerChangedMsg = '?sch'; -enum protocol_type -{ +enum protocol_type { POP, IMAP, SMTP }; -struct account_info -{ +struct account_info { protocol_type inboundType; entry_ref inboundProtocol; entry_ref outboundProtocol; @@ -44,50 +43,51 @@ struct account_info }; -class AutoConfigView : public BBox -{ - public: - AutoConfigView(BRect rect, AutoConfig &config); - - virtual void AttachedToWindow(); - virtual void MessageReceived(BMessage *msg); +class AutoConfigView : public BBox { +public: + AutoConfigView(BRect rect, AutoConfig& config); - bool GetBasicAccountInfo(account_info &info); - bool IsValidMailAddress(BString email); + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage *msg); - private: - BMenuField* SetupProtocolView(BRect rect); - status_t GetSMTPAddonRef(entry_ref *ref); + bool GetBasicAccountInfo(account_info &info); + bool IsValidMailAddress(BString email); - BString ExtractLocalPart(const char* email); - void ProposeUsername(); +private: + BMenuField* _SetupProtocolView(BRect rect); + status_t _GetSMTPAddonRef(entry_ref *ref); - entry_ref fSMTPAddonRef; - BMenuField *fInProtocolsField; - BTextControl *fNameView; - BTextControl *fAccountNameView; - BTextControl *fEmailView; - BTextControl *fLoginNameView; - BTextControl *fPasswordView; + BString _ExtractLocalPart(const char* email); + void _ProposeUsername(); - // ref to the parent autoconfig so you only ones read the database - AutoConfig &fAutoConfig; +private: + entry_ref fSMTPAddonRef; + BMenuField* fInProtocolsField; + BTextControl* fNameView; + BTextControl* fAccountNameView; + BTextControl* fEmailView; + BTextControl* fLoginNameView; + BTextControl* fPasswordView; + + // ref to the parent autoconfig so you only ones read the database + AutoConfig& fAutoConfig; }; -class ServerSettingsView : public BView -{ +class ServerSettingsView : public BView { public: ServerSettingsView(BRect rect, - const account_info &info); + const account_info& info); ~ServerSettingsView(); - void GetServerInfo(account_info &info); + void GetServerInfo(account_info& info); + +private: + void _DetectMenuChanges(); + void _GetAuthEncrMenu(entry_ref protocol, + BMenuField** authField, + BMenuField** sslField); private: - void DetectMenuChanges(); - void GetAuthEncrMenu(entry_ref protocol, - BMenuField **authField, - BMenuField **sslField); bool fInboundAccount; bool fOutboundAccount; BTextControl* fInboundNameView; @@ -106,4 +106,4 @@ private: }; -#endif +#endif // AUTO_CONFIG_VIEW_H diff --git a/src/preferences/mail/AutoConfigWindow.cpp b/src/preferences/mail/AutoConfigWindow.cpp index 6898cccc21..1f8f33c9dc 100644 --- a/src/preferences/mail/AutoConfigWindow.cpp +++ b/src/preferences/mail/AutoConfigWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2007-2011, Haiku, Inc. All rights reserved. + * Copyright 2007-2012, Haiku, Inc. All rights reserved. * Copyright 2011, Clemens Zeidler * Distributed under the terms of the MIT License. */ @@ -174,7 +174,7 @@ AutoConfigWindow::GenerateBasicAccount() fAccount->SetRealName(fAccountInfo.name.String()); fAccount->SetReturnAddress(fAccountInfo.email.String()); - BMessage& inboundArchive = fAccount->InboundSettings().EditSettings(); + BMessage& inboundArchive = fAccount->InboundSettings(); inboundArchive.MakeEmpty(); BString inServerName; int32 authType = 0; @@ -182,12 +182,12 @@ AutoConfigWindow::GenerateBasicAccount() if (fAccountInfo.inboundType == IMAP) { inServerName = fAccountInfo.providerInfo.imap_server; ssl = fAccountInfo.providerInfo.ssl_imap; - fAccount->SetInboundAddon("IMAP"); + fAccount->SetInboundAddOn("IMAP"); } else { inServerName = fAccountInfo.providerInfo.pop_server; authType = fAccountInfo.providerInfo.authentification_pop; ssl = fAccountInfo.providerInfo.ssl_pop; - fAccount->SetInboundAddon("POP3"); + fAccount->SetInboundAddOn("POP3"); } inboundArchive.AddString("server", inServerName); inboundArchive.AddInt32("auth_method", authType); @@ -197,9 +197,9 @@ AutoConfigWindow::GenerateBasicAccount() inboundArchive.AddBool("leave_mail_on_server", true); inboundArchive.AddBool("delete_remote_when_local", true); - BMessage& outboundArchive = fAccount->OutboundSettings().EditSettings(); + BMessage& outboundArchive = fAccount->OutboundSettings(); outboundArchive.MakeEmpty(); - fAccount->SetOutboundAddon("SMTP"); + fAccount->SetOutboundAddOn("SMTP"); outboundArchive.AddString("server", fAccountInfo.providerInfo.smtp_server); outboundArchive.AddString("username", fAccountInfo.loginName); diff --git a/src/preferences/mail/ConfigViews.cpp b/src/preferences/mail/ConfigViews.cpp index 6e4cbaae9e..ddad2937e5 100644 --- a/src/preferences/mail/ConfigViews.cpp +++ b/src/preferences/mail/ConfigViews.cpp @@ -1,5 +1,8 @@ /* + * Copyright 2007-2012, Haiku, Inc. All rights reserved. * Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. + * + * Distributed under the terms of the MIT License. */ @@ -43,28 +46,30 @@ const uint32 kMsgProtocolChanged = 'prch'; BView* -CreateConfigView(entry_ref addon, MailAddonSettings& settings, - BMailAccountSettings& accountSettings, image_id* image) +CreateConfigView(const entry_ref& addon, BMailProtocolSettings& settings, + BMailAccountSettings& accountSettings, image_id& image) { - BView* (*instantiate_config)(MailAddonSettings& settings, + BView* (*instantiateConfig)(BMailProtocolSettings& settings, BMailAccountSettings& accountSettings); BPath path(&addon); - *image = load_add_on(path.Path()); + image = load_add_on(path.Path()); if (image < 0) return NULL; - if (get_image_symbol(*image, "instantiate_config_panel", B_SYMBOL_TYPE_TEXT, - (void **)&instantiate_config) != B_OK) { - unload_add_on(*image); - *image = -1; + if (get_image_symbol(image, "instantiate_config_panel", B_SYMBOL_TYPE_TEXT, + (void **)&instantiateConfig) != B_OK) { + unload_add_on(image); + image = -1; return NULL; } - BView* view = (*instantiate_config)(settings, accountSettings); - return view; + return instantiateConfig(settings, accountSettings); } +// #pragma mark - + + AccountConfigView::AccountConfigView(BRect rect, BMailAccountSettings* account) : BBox(rect), @@ -159,13 +164,13 @@ InProtocolsConfigView::InProtocolsConfigView(BMailAccountSettings* account) fConfigView(NULL) { BString label = "Can't find protocol."; - entry_ref protocol = fAccount->InboundPath(); - MailAddonSettings& inboundSettings = fAccount->InboundSettings(); + entry_ref protocol = fAccount->InboundAddOnRef(); + BMailProtocolSettings& inboundSettings = fAccount->InboundSettings(); fConfigView = CreateConfigView(protocol, inboundSettings, *account, - &fImageID); + fImageID); - if (fConfigView) { + if (fConfigView != NULL) { float w = fConfigView->Bounds().Width(); float h = fConfigView->Bounds().Height(); fConfigView->MoveTo(3, 13); @@ -195,7 +200,9 @@ InProtocolsConfigView::DetachedFromWindow() BMessage settings; if (fConfigView->Archive(&settings) != B_OK) return; - fAccount->InboundSettings().EditSettings() = settings; + + fAccount->InboundSettings().MakeEmpty(); + fAccount->InboundSettings().Append(settings); RemoveChild(fConfigView); delete fConfigView; @@ -211,12 +218,12 @@ OutProtocolsConfigView::OutProtocolsConfigView(BMailAccountSettings* account) fConfigView(NULL) { BString label = "Can't find protocol."; - entry_ref protocol = fAccount->OutboundPath(); - MailAddonSettings& outboundSettings = fAccount->OutboundSettings(); + entry_ref protocol = fAccount->OutboundAddOnRef(); + BMailProtocolSettings& outboundSettings = fAccount->OutboundSettings(); fConfigView = CreateConfigView(protocol, outboundSettings, *account, - &fImageID); + fImageID); - if (fConfigView) { + if (fConfigView != NULL) { float w = fConfigView->Bounds().Width(); float h = fConfigView->Bounds().Height(); fConfigView->MoveTo(3, 13); @@ -247,7 +254,9 @@ OutProtocolsConfigView::DetachedFromWindow() BMessage settings; if (fConfigView->Archive(&settings) != B_OK) return; - fAccount->OutboundSettings().EditSettings() = settings; + + fAccount->OutboundSettings().MakeEmpty(); + fAccount->OutboundSettings().Append(settings); RemoveChild(fConfigView); delete fConfigView; diff --git a/src/preferences/mail/ConfigViews.h b/src/preferences/mail/ConfigViews.h index 9e0377e25a..afd12e16d9 100644 --- a/src/preferences/mail/ConfigViews.h +++ b/src/preferences/mail/ConfigViews.h @@ -1,7 +1,8 @@ /* - * Copyright 2007-2011, Haiku, Inc. All rights reserved. + * Copyright 2007-2012, Haiku, Inc. All rights reserved. * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved. * Copyright 2011, Clemens Zeidler + * * Distributed under the terms of the MIT License. */ #ifndef CONFIG_VIEWS_H @@ -26,8 +27,8 @@ struct entry_ref; class ProtocolsConfigView; -BView* CreateConfigView(entry_ref addon, MailAddonSettings& settings, - BMailAccountSettings& accountSettings, image_id* image); +BView* CreateConfigView(const entry_ref& ref, BMailProtocolSettings& settings, + BMailAccountSettings& accountSettings, image_id& image); class AccountConfigView : public BBox { diff --git a/src/preferences/mail/ConfigWindow.cpp b/src/preferences/mail/ConfigWindow.cpp index 89e3a84742..59ab7cabb2 100644 --- a/src/preferences/mail/ConfigWindow.cpp +++ b/src/preferences/mail/ConfigWindow.cpp @@ -49,6 +49,8 @@ #include #include +#include + #include "AutoConfigWindow.h" #include "CenterContainer.h" @@ -530,7 +532,7 @@ ConfigWindow::_SaveSettings() fConfigView->DeleteChildren(); // collect changed accounts - BMessage changedAccounts(kMsgAccountsChanged); + BMessage changedAccounts(BPrivate::kMsgAccountsChanged); for (int32 i = 0; i < fAccounts.CountItems(); i++) { BMailAccountSettings* account = fAccounts.ItemAt(i); if (account && account->HasBeenModified()) @@ -601,10 +603,10 @@ ConfigWindow::_SaveSettings() fAccounts.ItemAt(i)->Save(); } - BMessenger messenger("application/x-vnd.Be-POST"); + BMessenger messenger(B_MAIL_DAEMON_SIGNATURE); if (messenger.IsValid()) { // server should reload general settings - messenger.SendMessage(kMsgSettingsUpdated); + messenger.SendMessage(BPrivate::kMsgSettingsUpdated); // notify server about changed accounts messenger.SendMessage(&changedAccounts); } diff --git a/src/preferences/mail/FilterAddonList.cpp b/src/preferences/mail/FilterAddonList.cpp deleted file mode 100644 index 3dfdd57916..0000000000 --- a/src/preferences/mail/FilterAddonList.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 2011, Haiku, Inc. All rights reserved. - * Copyright 2011, Clemens Zeidler - * Distributed under the terms of the MIT License. - */ - - -#include "FilterAddonList.h" - -#include -#include -#include - - -FilterAddonList::FilterAddonList(direction dir, bool loadOnStart) - : - fDirection(dir) -{ - if (loadOnStart) - Reload(); -} - - -FilterAddonList::~FilterAddonList() -{ - _MakeEmpty(); -} - - -void -FilterAddonList::Reload() -{ - _MakeEmpty(); - - BPath path; - status_t status = find_directory(B_SYSTEM_ADDONS_DIRECTORY, &path); - if (status != B_OK) - return; - path.Append("mail_daemon"); - if (fDirection == kIncomming) - path.Append("inbound_filters"); - else - path.Append("outbound_filters"); - - BDirectory dir(path.Path()); - if (dir.InitCheck() != B_OK) - return; - BEntry entry; - while (dir.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) - _LoadAddon(entry); -} - - -int32 -FilterAddonList::CountFilterAddons() -{ - return fFilterAddonList.size(); -} - - -FilterAddonInfo& -FilterAddonList::FilterAddonAt(int32 index) -{ - return fFilterAddonList[index]; -} - - -bool -FilterAddonList::GetDescriptiveName(int32 index, BString& name) -{ - if (index < 0) - return false; - - FilterAddonInfo& info = FilterAddonAt(index); - - BString (*descriptive_name)(); - if (get_image_symbol(info.image, "descriptive_name", B_SYMBOL_TYPE_TEXT, - (void **)&descriptive_name) == B_OK) { - name = (*descriptive_name)(); - } else - name = info.ref.name; - return true; -} - - -bool -FilterAddonList::GetDescriptiveName(const entry_ref& ref, BString& name) -{ - int32 index = FindInfo(ref); - return GetDescriptiveName(index, name); -} - - -BView* -FilterAddonList::CreateConfigView(AddonSettings& settings) -{ - const entry_ref& ref = settings.AddonRef(); - int32 index = FindInfo(ref); - if (index < 0) - return NULL; - FilterAddonInfo& info = FilterAddonAt(index); - - BView* (*instantiate_filter_config_panel)(AddonSettings&); - if (get_image_symbol(info.image, "instantiate_filter_config_panel", - B_SYMBOL_TYPE_TEXT, (void **)&instantiate_filter_config_panel) != B_OK) - return NULL; - return (*instantiate_filter_config_panel)(settings); -} - - -void -FilterAddonList::_MakeEmpty() -{ - for (unsigned int i = 0; i < fFilterAddonList.size(); i++) { - FilterAddonInfo& info = fFilterAddonList[i]; - unload_add_on(info.image); - } - fFilterAddonList.clear(); -} - - -int32 -FilterAddonList::FindInfo(const entry_ref& ref) -{ - for (unsigned int i = 0; i < fFilterAddonList.size(); i++) { - FilterAddonInfo& currentInfo = fFilterAddonList[i]; - if (currentInfo.ref == ref) - return i; - } - return -1; -} - - -void -FilterAddonList::_LoadAddon(BEntry& entry) -{ - FilterAddonInfo info; - - BPath path(&entry); - info.image = load_add_on(path.Path()); - if (info.image < 0) - return; - - BView* (*instantiate_filter_config_panel)(MailAddonSettings&); - if (get_image_symbol(info.image, "instantiate_filter_config_panel", - B_SYMBOL_TYPE_TEXT, (void **)&instantiate_filter_config_panel) - != B_OK) { - unload_add_on(info.image); - return; - } - - entry.GetRef(&info.ref); - - fFilterAddonList.push_back(info); -} diff --git a/src/preferences/mail/FilterAddonList.h b/src/preferences/mail/FilterAddonList.h deleted file mode 100644 index cb3c4899f1..0000000000 --- a/src/preferences/mail/FilterAddonList.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2011, Haiku, Inc. All rights reserved. - * Copyright 2011, Clemens Zeidler - * Distributed under the terms of the MIT License. - */ -#ifndef FILTER_ADDON_LIST_H -#define FILTER_ADDON_LIST_H - - -#include "MailSettings.h" - -#include - - -enum direction { - kIncomming, - kOutgoing -}; - - -struct FilterAddonInfo { - image_id image; - entry_ref ref; -}; - - -class FilterAddonList { -public: - FilterAddonList(direction dir, - bool loadOnStart = true); - ~FilterAddonList(); - - void Reload(); - - int32 CountFilterAddons(); - FilterAddonInfo& FilterAddonAt(int32 index); - - bool GetDescriptiveName(int32 index, BString& name); - bool GetDescriptiveName(const entry_ref& ref, - BString& name); - - BView* CreateConfigView(AddonSettings& settings); - - int32 FindInfo(const entry_ref& ref); -private: - void _MakeEmpty(); - void _LoadAddon(BEntry& entry); - - direction fDirection; - std::vector fFilterAddonList; -}; - - -#endif //FILTER_ADDON_LIST_H diff --git a/src/preferences/mail/FilterConfigView.cpp b/src/preferences/mail/FilterConfigView.cpp index eb4f1272a5..e6bd9e9719 100644 --- a/src/preferences/mail/FilterConfigView.cpp +++ b/src/preferences/mail/FilterConfigView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2007-2011, Haiku, Inc. All rights reserved. + * Copyright 2007-2012, Haiku, Inc. All rights reserved. * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved. * Copyright 2011, Clemens Zeidler * Distributed under the terms of the MIT License. @@ -180,7 +180,7 @@ private: class FilterConfigBox : public BBox { public: - FilterConfigBox(BString& label, BView* child) + FilterConfigBox(const BString& label, BView* child) : BBox(BRect(0,0,100,100)), fChild(child) @@ -194,7 +194,7 @@ public: } status_t - ArchiveAddon(BMessage* into) const + ArchiveAddOn(BMessage* into) const { return fChild->Archive(into); } @@ -203,7 +203,7 @@ private: BView* fChild; }; - + // #pragma mark - @@ -211,8 +211,8 @@ FiltersConfigView::FiltersConfigView(BRect rect, BMailAccountSettings& account) : BBox(rect), fAccount(account), - fDirection(kIncomming), - fInboundFilters(kIncomming, false), + fDirection(kIncoming), + fInboundFilters(kIncoming, false), fOutboundFilters(kOutgoing, false), fFilterView(NULL), fCurrentIndex(-1) @@ -224,7 +224,7 @@ FiltersConfigView::FiltersConfigView(BRect rect, BMailAccountSettings& account) msg = new BMessage(kMsgChainSelected); item = new BMenuItem(B_TRANSLATE("Incoming mail filters"), msg); menu->AddItem(item); - msg->AddInt32("direction", kIncomming); + msg->AddInt32("direction", kIncoming); item->SetMarked(true); msg = new BMessage(kMsgChainSelected); @@ -302,14 +302,14 @@ FiltersConfigView::_SelectFilter(int32 index) if (index >= 0) { // add new config view - AddonSettings* filterSettings = _GetCurrentMailSettings() - ->FilterSettingsAt(index); - if (filterSettings) { - FilterAddonList* addons = _GetCurrentFilterAddonList(); - BView* view = addons->CreateConfigView(*filterSettings); - if (view) { + BMailAddOnSettings* filterSettings + = _MailSettings()->FilterSettingsAt(index); + if (filterSettings != NULL) { + ::FilterList* filters = _FilterList(); + BView* view = filters->CreateConfigView(*filterSettings); + if (view != NULL) { BString name; - addons->GetDescriptiveName(filterSettings->AddonRef(), name); + filters->GetDescriptiveName(filterSettings->AddOnRef(), name); fFilterView = new FilterConfigBox(name, view); Parent()->AddChild(fFilterView); } @@ -319,7 +319,7 @@ FiltersConfigView::_SelectFilter(int32 index) fCurrentIndex = index; // re-layout the view containing the config view - if (CenterContainer *container = dynamic_cast(Parent())) + if (CenterContainer* container = dynamic_cast(Parent())) container->Layout(); if (Parent()) @@ -339,19 +339,19 @@ FiltersConfigView::_SetDirection(direction direction) } fDirection = direction; - MailAddonSettings* addonSettings = _GetCurrentMailSettings(); - FilterAddonList* addons = _GetCurrentFilterAddonList(); - addons->Reload(); + BMailProtocolSettings* protocolSettings = _MailSettings(); + ::FilterList* filters = _FilterList(); + filters->Reload(); - for (int32 i = 0; i < addonSettings->CountFilterSettings(); i++) { - AddonSettings* filterSettings = addonSettings->FilterSettingsAt(i); - if (addons->FindInfo(filterSettings->AddonRef()) < 0) { - addonSettings->RemoveFilterSettings(i); + for (int32 i = 0; i < protocolSettings->CountFilterSettings(); i++) { + BMailAddOnSettings* settings = protocolSettings->FilterSettingsAt(i); + if (filters->InfoIndexFor(settings->AddOnRef()) < 0) { + protocolSettings->RemoveFilterSettings(i); i--; continue; } BString name = "Unnamed Filter"; - addons->GetDescriptiveName(filterSettings->AddonRef(), name); + filters->GetDescriptiveName(settings->AddOnRef(), name); fListView->AddItem(new BStringItem(name)); } @@ -362,11 +362,11 @@ FiltersConfigView::_SetDirection(direction direction) delete item; } - addons->Reload(); - for (int32 i = 0; i < addons->CountFilterAddons(); i++) { - FilterAddonInfo& info = addons->FilterAddonAt(i); + filters->Reload(); + for (int32 i = 0; i < filters->CountInfos(); i++) { + FilterInfo& info = filters->InfoAt(i); BString name; - addons->GetDescriptiveName(i, name); + filters->GetDescriptiveName(i, name); BMessage* msg = new BMessage(kMsgAddFilter); msg->AddRef("filter", &info.ref); @@ -417,14 +417,14 @@ FiltersConfigView::MessageReceived(BMessage *msg) if (msg->FindRef("filter", &ref) < B_OK) break; - FilterAddonList* filterAddons = _GetCurrentFilterAddonList(); - int32 index = filterAddons->FindInfo(ref); + ::FilterList* filters = _FilterList(); + int32 index = filters->InfoIndexFor(ref); if (index < 0) break; - _GetCurrentMailSettings()->AddFilterSettings(&ref); + _MailSettings()->AddFilterSettings(&ref); BString name; - filterAddons->GetDescriptiveName(index, name); + filters->GetDescriptiveName(index, name); fListView->AddItem(new BStringItem(name)); break; } @@ -433,13 +433,11 @@ FiltersConfigView::MessageReceived(BMessage *msg) int32 index = fListView->CurrentSelection(); if (index < 0) break; - BStringItem *item = (BStringItem *)fListView->RemoveItem(index); + BStringItem* item = (BStringItem*)fListView->RemoveItem(index); delete item; _SelectFilter(-1); - - MailAddonSettings* mailSettings = _GetCurrentMailSettings(); - mailSettings->RemoveFilterSettings(index); + _MailSettings()->RemoveFilterSettings(index); break; } case kMsgFilterSelected: @@ -458,8 +456,7 @@ FiltersConfigView::MessageReceived(BMessage *msg) if (from == to) break; - MailAddonSettings* mailSettings = _GetCurrentMailSettings(); - if (!mailSettings->MoveFilterSettings(from, to)) { + if (!_MailSettings()->MoveFilterSettings(from, to)) { BAlert* alert = new BAlert("E-mail", B_TRANSLATE("The filter could not be moved. Deleting " "filter."), B_TRANSLATE("OK")); @@ -467,7 +464,7 @@ FiltersConfigView::MessageReceived(BMessage *msg) alert->Go(); fListView->RemoveItem(to); break; - } + } break; } @@ -478,19 +475,19 @@ FiltersConfigView::MessageReceived(BMessage *msg) } -MailAddonSettings* -FiltersConfigView::_GetCurrentMailSettings() +BMailProtocolSettings* +FiltersConfigView::_MailSettings() { - if (fDirection == kIncomming) + if (fDirection == kIncoming) return &fAccount.InboundSettings(); return &fAccount.OutboundSettings(); } -FilterAddonList* -FiltersConfigView::_GetCurrentFilterAddonList() +FilterList* +FiltersConfigView::_FilterList() { - if (fDirection == kIncomming) + if (fDirection == kIncoming) return &fInboundFilters; return &fOutboundFilters; } @@ -499,10 +496,9 @@ FiltersConfigView::_GetCurrentFilterAddonList() void FiltersConfigView::_SaveConfig(int32 index) { - if (fFilterView) { - AddonSettings* filterSettings = _GetCurrentMailSettings() - ->FilterSettingsAt(index); - if (filterSettings) - fFilterView->ArchiveAddon(&filterSettings->EditSettings()); + if (fFilterView != NULL) { + BMailAddOnSettings* settings = _MailSettings()->FilterSettingsAt(index); + if (settings != NULL) + fFilterView->ArchiveAddOn(settings); } } diff --git a/src/preferences/mail/FilterConfigView.h b/src/preferences/mail/FilterConfigView.h index 7de9c96d89..17aa48fb10 100644 --- a/src/preferences/mail/FilterConfigView.h +++ b/src/preferences/mail/FilterConfigView.h @@ -1,5 +1,5 @@ /* - * Copyright 2007-2011, Haiku, Inc. All rights reserved. + * Copyright 2007-2012, Haiku, Inc. All rights reserved. * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved. * Copyright 2011, Clemens Zeidler * Distributed under the terms of the MIT License. @@ -12,13 +12,12 @@ #include #include -#include #include +#include #include #include -#include "FilterAddonList.h" -#include "MailSettings.h" +#include "FilterList.h" class FilterConfigBox; @@ -35,18 +34,19 @@ public: void MessageReceived(BMessage *msg); private: - MailAddonSettings* _GetCurrentMailSettings(); - FilterAddonList* _GetCurrentFilterAddonList(); + BMailProtocolSettings* _MailSettings(); + ::FilterList* _FilterList(); void _SelectFilter(int32 index); void _SetDirection(direction direction); void _SaveConfig(int32 index); - BMailAccountSettings& fAccount; +private: + BMailAccountSettings& fAccount; direction fDirection; - FilterAddonList fInboundFilters; - FilterAddonList fOutboundFilters; + ::FilterList fInboundFilters; + ::FilterList fOutboundFilters; BMenuField* fChainsField; BListView* fListView; diff --git a/src/preferences/mail/FilterList.cpp b/src/preferences/mail/FilterList.cpp new file mode 100644 index 0000000000..09f03c6036 --- /dev/null +++ b/src/preferences/mail/FilterList.cpp @@ -0,0 +1,155 @@ +/* + * Copyright 2011-2012, Haiku, Inc. All rights reserved. + * Copyright 2011, Clemens Zeidler + * Distributed under the terms of the MIT License. + */ + + +#include "FilterList.h" + +#include +#include +#include + + +FilterList::FilterList(direction dir, bool loadOnStart) + : + fDirection(dir) +{ + if (loadOnStart) + Reload(); +} + + +FilterList::~FilterList() +{ + _MakeEmpty(); +} + + +void +FilterList::Reload() +{ + _MakeEmpty(); + + BPath path; + status_t status = find_directory(B_SYSTEM_ADDONS_DIRECTORY, &path); + if (status != B_OK) + return; + path.Append("mail_daemon"); + if (fDirection == kIncoming) + path.Append("inbound_filters"); + else + path.Append("outbound_filters"); + + BDirectory dir(path.Path()); + if (dir.InitCheck() != B_OK) + return; + BEntry entry; + while (dir.GetNextEntry(&entry) == B_OK) + _LoadAddOn(entry); +} + + +int32 +FilterList::CountInfos() +{ + return fList.size(); +} + + +FilterInfo& +FilterList::InfoAt(int32 index) +{ + return fList[index]; +} + + +bool +FilterList::GetDescriptiveName(int32 index, BString& name) +{ + if (index < 0) + return false; + + FilterInfo& info = InfoAt(index); + + BString (*descriptive_name)(); + if (get_image_symbol(info.image, "descriptive_name", B_SYMBOL_TYPE_TEXT, + (void **)&descriptive_name) == B_OK) { + name = (*descriptive_name)(); + } else + name = info.ref.name; + return true; +} + + +bool +FilterList::GetDescriptiveName(const entry_ref& ref, BString& name) +{ + int32 index = InfoIndexFor(ref); + return GetDescriptiveName(index, name); +} + + +BView* +FilterList::CreateConfigView(BMailAddOnSettings& settings) +{ + const entry_ref& ref = settings.AddOnRef(); + int32 index = InfoIndexFor(ref); + if (index < 0) + return NULL; + FilterInfo& info = InfoAt(index); + + BView* (*instantiateFilterConfigPanel)(BMailAddOnSettings&); + if (get_image_symbol(info.image, "instantiate_filter_config_panel", + B_SYMBOL_TYPE_TEXT, (void **)&instantiateFilterConfigPanel) != B_OK) + return NULL; + return (*instantiateFilterConfigPanel)(settings); +} + + +int32 +FilterList::InfoIndexFor(const entry_ref& ref) +{ + for (size_t i = 0; i < fList.size(); i++) { + FilterInfo& info = fList[i]; + if (info.ref == ref) + return i; + } + return -1; +} + + +void +FilterList::_MakeEmpty() +{ + for (size_t i = 0; i < fList.size(); i++) { + FilterInfo& info = fList[i]; + unload_add_on(info.image); + } + fList.clear(); +} + + +void +FilterList::_LoadAddOn(BEntry& entry) +{ + FilterInfo info; + + BPath path(&entry); + info.image = load_add_on(path.Path()); + if (info.image < 0) + return; + + BView* (*instantiateFilterConfigPanel)(BMailProtocolSettings&); + if (get_image_symbol(info.image, "instantiate_filter_config_panel", + B_SYMBOL_TYPE_TEXT, (void **)&instantiateFilterConfigPanel) + != B_OK) { + unload_add_on(info.image); + return; + } + + entry.GetRef(&info.ref); + + fList.push_back(info); +} diff --git a/src/preferences/mail/FilterList.h b/src/preferences/mail/FilterList.h new file mode 100644 index 0000000000..157851624e --- /dev/null +++ b/src/preferences/mail/FilterList.h @@ -0,0 +1,54 @@ +/* + * Copyright 2011-2012, Haiku, Inc. All rights reserved. + * Copyright 2011, Clemens Zeidler + * Distributed under the terms of the MIT License. + */ +#ifndef FILTER_LIST_H +#define FILTER_LIST_H + + +#include +#include + + +enum direction { + kIncoming, + kOutgoing +}; + + +struct FilterInfo { + image_id image; + entry_ref ref; +}; + + +class FilterList { +public: + FilterList(direction dir, + bool loadOnStart = true); + ~FilterList(); + + void Reload(); + + int32 CountInfos(); + FilterInfo& InfoAt(int32 index); + + bool GetDescriptiveName(int32 index, BString& name); + bool GetDescriptiveName(const entry_ref& ref, + BString& name); + + BView* CreateConfigView(BMailAddOnSettings& settings); + + int32 InfoIndexFor(const entry_ref& ref); + +private: + void _MakeEmpty(); + void _LoadAddOn(BEntry& entry); + + direction fDirection; + std::vector fList; +}; + + +#endif // FILTER_LIST_H diff --git a/src/preferences/mail/Jamfile b/src/preferences/mail/Jamfile index 6b89f8174b..8ae71178e4 100644 --- a/src/preferences/mail/Jamfile +++ b/src/preferences/mail/Jamfile @@ -1,6 +1,5 @@ SubDir HAIKU_TOP src preferences mail ; - UsePublicHeaders [ FDirName add-ons mail_daemon ] ; UsePrivateHeaders mail ; @@ -17,7 +16,7 @@ local sources = CenterContainer.cpp ConfigViews.cpp ConfigWindow.cpp - FilterAddonList.cpp + FilterList.cpp DNSQuery.cpp FilterConfigView.cpp main.cpp