E-mail now also builds, but doesn't work yet.

This commit is contained in:
Axel Dörfler 2012-10-31 01:13:02 +01:00
parent bcf60bbb83
commit 9d8cf1b6f7
13 changed files with 366 additions and 363 deletions

View File

@ -40,12 +40,12 @@ AutoConfigView::AutoConfigView(BRect rect, AutoConfig &config)
// protocol view // protocol view
topLeft.y += stepSize; topLeft.y += stepSize;
rightDown.y += stepSize; rightDown.y += stepSize;
fInProtocolsField = SetupProtocolView(BRect(topLeft, rightDown)); fInProtocolsField = _SetupProtocolView(BRect(topLeft, rightDown));
if (fInProtocolsField) if (fInProtocolsField)
AddChild(fInProtocolsField); AddChild(fInProtocolsField);
// search for smtp ref // search for smtp ref
GetSMTPAddonRef(&fSMTPAddonRef); _GetSMTPAddonRef(&fSMTPAddonRef);
// email view // email view
topLeft.y += stepSize; topLeft.y += stepSize;
@ -105,14 +105,12 @@ AutoConfigView::AttachedToWindow()
void void
AutoConfigView::MessageReceived(BMessage *msg) AutoConfigView::MessageReceived(BMessage *msg)
{ {
BString text, login; switch (msg->what) {
switch (msg->what)
{
case kEMailChangedMsg: case kEMailChangedMsg:
{ {
text = fLoginNameView->Text(); BString text = fLoginNameView->Text();
if (text == "") if (text == "")
ProposeUsername(); _ProposeUsername();
fLoginNameView->MakeFocus(); fLoginNameView->MakeFocus();
fLoginNameView->TextView()->SelectAll(); fLoginNameView->TextView()->SelectAll();
@ -159,9 +157,9 @@ AutoConfigView::GetBasicAccountInfo(account_info &info)
BMenuField* 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++) { for (int i = 0; i < 2; i++) {
BPath path; BPath path;
@ -202,10 +200,11 @@ AutoConfigView::SetupProtocolView(BRect rect)
status_t status_t
AutoConfigView::GetSMTPAddonRef(entry_ref *ref) AutoConfigView::_GetSMTPAddonRef(entry_ref *ref)
{ {
directory_which which[] = { directory_which which[] = {
B_USER_ADDONS_DIRECTORY, B_USER_ADDONS_DIRECTORY,
B_COMMON_ADDONS_DIRECTORY,
B_BEOS_ADDONS_DIRECTORY B_BEOS_ADDONS_DIRECTORY
}; };
@ -229,24 +228,21 @@ AutoConfigView::GetSMTPAddonRef(entry_ref *ref)
BString BString
AutoConfigView::ExtractLocalPart(const char* email) AutoConfigView::_ExtractLocalPart(const char* email)
{ {
BString emailS(email); const char* at = strrchr(email, '@');
BString localPart; return BString(email, at - email);
int32 at = emailS.FindLast("@");
emailS.CopyInto(localPart, 0, at);
return localPart;
} }
void void
AutoConfigView::ProposeUsername() AutoConfigView::_ProposeUsername()
{ {
const char* email = fEmailView->Text(); const char* email = fEmailView->Text();
provider_info info; provider_info info;
status_t status = fAutoConfig.GetInfoFromMailAddress(email, &info); status_t status = fAutoConfig.GetInfoFromMailAddress(email, &info);
if (status == B_OK) { if (status == B_OK) {
BString localPart = ExtractLocalPart(email); BString localPart = _ExtractLocalPart(email);
switch (info.username_pattern) { switch (info.username_pattern) {
case 0: case 0:
// username is the mail address // username is the mail address
@ -324,7 +320,7 @@ ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info)
box->AddChild(fInboundNameView); box->AddChild(fInboundNameView);
GetAuthEncrMenu(info.inboundProtocol, &fInboundAuthMenu, _GetAuthEncrMenu(info.inboundProtocol, &fInboundAuthMenu,
&fInboundEncryptionMenu); &fInboundEncryptionMenu);
if (fInboundAuthMenu != NULL) { if (fInboundAuthMenu != NULL) {
int authID = info.providerInfo.authentification_pop; int authID = info.providerInfo.authentification_pop;
@ -379,7 +375,7 @@ ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info)
box->AddChild(fOutboundNameView); box->AddChild(fOutboundNameView);
GetAuthEncrMenu(info.outboundProtocol, &fOutboundAuthMenu, _GetAuthEncrMenu(info.outboundProtocol, &fOutboundAuthMenu,
&fOutboundEncryptionMenu); &fOutboundEncryptionMenu);
if (fOutboundAuthMenu != NULL) { if (fOutboundAuthMenu != NULL) {
BMenuItem *item = fOutboundAuthMenu->Menu()->ItemAt( BMenuItem *item = fOutboundAuthMenu->Menu()->ItemAt(
@ -468,12 +464,12 @@ ServerSettingsView::GetServerInfo(account_info &info)
= fOutboundEncryptionMenu->Menu()->IndexOf(item); = fOutboundEncryptionMenu->Menu()->IndexOf(item);
} }
} }
DetectMenuChanges(); _DetectMenuChanges();
} }
void void
ServerSettingsView::DetectMenuChanges() ServerSettingsView::_DetectMenuChanges()
{ {
bool changed = false; bool changed = false;
if (fInboundAuthMenu != NULL) { if (fInboundAuthMenu != NULL) {
@ -505,12 +501,12 @@ ServerSettingsView::DetectMenuChanges()
void void
ServerSettingsView::GetAuthEncrMenu(entry_ref protocol, ServerSettingsView::_GetAuthEncrMenu(entry_ref protocol,
BMenuField **authField, BMenuField **sslField) BMenuField** authField, BMenuField** sslField)
{ {
BMailAccountSettings dummySettings; BMailAccountSettings dummySettings;
BView *view = CreateConfigView(protocol, dummySettings.InboundSettings(), BView *view = CreateConfigView(protocol, dummySettings.InboundSettings(),
dummySettings, &fImageId); dummySettings, fImageId);
*authField = (BMenuField *)view->FindView("auth_method"); *authField = (BMenuField *)view->FindView("auth_method");
*sslField = (BMenuField *)view->FindView("flavor"); *sslField = (BMenuField *)view->FindView("flavor");

View File

@ -1,11 +1,12 @@
/* /*
* Copyright 2007-2011, Haiku, Inc. All rights reserved. * Copyright 2007-2012, Haiku, Inc. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de> * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef AUTO_CONFIG_VIEW_H #ifndef AUTO_CONFIG_VIEW_H
#define AUTO_CONFIG_VIEW_H #define AUTO_CONFIG_VIEW_H
#include "AutoConfig.h" #include "AutoConfig.h"
#include "ConfigViews.h" #include "ConfigViews.h"
@ -22,16 +23,14 @@ const int32 kProtokollChangedMsg = '?pch';
const int32 kServerChangedMsg = '?sch'; const int32 kServerChangedMsg = '?sch';
enum protocol_type enum protocol_type {
{
POP, POP,
IMAP, IMAP,
SMTP SMTP
}; };
struct account_info struct account_info {
{
protocol_type inboundType; protocol_type inboundType;
entry_ref inboundProtocol; entry_ref inboundProtocol;
entry_ref outboundProtocol; entry_ref outboundProtocol;
@ -44,50 +43,51 @@ struct account_info
}; };
class AutoConfigView : public BBox class AutoConfigView : public BBox {
{ public:
public: AutoConfigView(BRect rect, AutoConfig& config);
AutoConfigView(BRect rect, AutoConfig &config);
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *msg);
bool GetBasicAccountInfo(account_info &info); virtual void AttachedToWindow();
bool IsValidMailAddress(BString email); virtual void MessageReceived(BMessage *msg);
private: bool GetBasicAccountInfo(account_info &info);
BMenuField* SetupProtocolView(BRect rect); bool IsValidMailAddress(BString email);
status_t GetSMTPAddonRef(entry_ref *ref);
BString ExtractLocalPart(const char* email); private:
void ProposeUsername(); BMenuField* _SetupProtocolView(BRect rect);
status_t _GetSMTPAddonRef(entry_ref *ref);
entry_ref fSMTPAddonRef; BString _ExtractLocalPart(const char* email);
BMenuField *fInProtocolsField; void _ProposeUsername();
BTextControl *fNameView;
BTextControl *fAccountNameView;
BTextControl *fEmailView;
BTextControl *fLoginNameView;
BTextControl *fPasswordView;
// ref to the parent autoconfig so you only ones read the database private:
AutoConfig &fAutoConfig; 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: public:
ServerSettingsView(BRect rect, ServerSettingsView(BRect rect,
const account_info &info); const account_info& info);
~ServerSettingsView(); ~ServerSettingsView();
void GetServerInfo(account_info &info); void GetServerInfo(account_info& info);
private:
void _DetectMenuChanges();
void _GetAuthEncrMenu(entry_ref protocol,
BMenuField** authField,
BMenuField** sslField);
private: private:
void DetectMenuChanges();
void GetAuthEncrMenu(entry_ref protocol,
BMenuField **authField,
BMenuField **sslField);
bool fInboundAccount; bool fInboundAccount;
bool fOutboundAccount; bool fOutboundAccount;
BTextControl* fInboundNameView; BTextControl* fInboundNameView;
@ -106,4 +106,4 @@ private:
}; };
#endif #endif // AUTO_CONFIG_VIEW_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2007-2011, Haiku, Inc. All rights reserved. * Copyright 2007-2012, Haiku, Inc. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de> * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
@ -174,7 +174,7 @@ AutoConfigWindow::GenerateBasicAccount()
fAccount->SetRealName(fAccountInfo.name.String()); fAccount->SetRealName(fAccountInfo.name.String());
fAccount->SetReturnAddress(fAccountInfo.email.String()); fAccount->SetReturnAddress(fAccountInfo.email.String());
BMessage& inboundArchive = fAccount->InboundSettings().EditSettings(); BMessage& inboundArchive = fAccount->InboundSettings();
inboundArchive.MakeEmpty(); inboundArchive.MakeEmpty();
BString inServerName; BString inServerName;
int32 authType = 0; int32 authType = 0;
@ -182,12 +182,12 @@ AutoConfigWindow::GenerateBasicAccount()
if (fAccountInfo.inboundType == IMAP) { if (fAccountInfo.inboundType == IMAP) {
inServerName = fAccountInfo.providerInfo.imap_server; inServerName = fAccountInfo.providerInfo.imap_server;
ssl = fAccountInfo.providerInfo.ssl_imap; ssl = fAccountInfo.providerInfo.ssl_imap;
fAccount->SetInboundAddon("IMAP"); fAccount->SetInboundAddOn("IMAP");
} else { } else {
inServerName = fAccountInfo.providerInfo.pop_server; inServerName = fAccountInfo.providerInfo.pop_server;
authType = fAccountInfo.providerInfo.authentification_pop; authType = fAccountInfo.providerInfo.authentification_pop;
ssl = fAccountInfo.providerInfo.ssl_pop; ssl = fAccountInfo.providerInfo.ssl_pop;
fAccount->SetInboundAddon("POP3"); fAccount->SetInboundAddOn("POP3");
} }
inboundArchive.AddString("server", inServerName); inboundArchive.AddString("server", inServerName);
inboundArchive.AddInt32("auth_method", authType); inboundArchive.AddInt32("auth_method", authType);
@ -197,9 +197,9 @@ AutoConfigWindow::GenerateBasicAccount()
inboundArchive.AddBool("leave_mail_on_server", true); inboundArchive.AddBool("leave_mail_on_server", true);
inboundArchive.AddBool("delete_remote_when_local", true); inboundArchive.AddBool("delete_remote_when_local", true);
BMessage& outboundArchive = fAccount->OutboundSettings().EditSettings(); BMessage& outboundArchive = fAccount->OutboundSettings();
outboundArchive.MakeEmpty(); outboundArchive.MakeEmpty();
fAccount->SetOutboundAddon("SMTP"); fAccount->SetOutboundAddOn("SMTP");
outboundArchive.AddString("server", outboundArchive.AddString("server",
fAccountInfo.providerInfo.smtp_server); fAccountInfo.providerInfo.smtp_server);
outboundArchive.AddString("username", fAccountInfo.loginName); outboundArchive.AddString("username", fAccountInfo.loginName);

View File

@ -1,5 +1,8 @@
/* /*
* Copyright 2007-2012, Haiku, Inc. All rights reserved.
* Copyright 2001 Dr. Zoidberg Enterprises. 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* BView*
CreateConfigView(entry_ref addon, MailAddonSettings& settings, CreateConfigView(const entry_ref& addon, BMailProtocolSettings& settings,
BMailAccountSettings& accountSettings, image_id* image) BMailAccountSettings& accountSettings, image_id& image)
{ {
BView* (*instantiate_config)(MailAddonSettings& settings, BView* (*instantiateConfig)(BMailProtocolSettings& settings,
BMailAccountSettings& accountSettings); BMailAccountSettings& accountSettings);
BPath path(&addon); BPath path(&addon);
*image = load_add_on(path.Path()); image = load_add_on(path.Path());
if (image < 0) if (image < 0)
return NULL; return NULL;
if (get_image_symbol(*image, "instantiate_config_panel", B_SYMBOL_TYPE_TEXT, if (get_image_symbol(image, "instantiate_config_panel", B_SYMBOL_TYPE_TEXT,
(void **)&instantiate_config) != B_OK) { (void **)&instantiateConfig) != B_OK) {
unload_add_on(*image); unload_add_on(image);
*image = -1; image = -1;
return NULL; return NULL;
} }
BView* view = (*instantiate_config)(settings, accountSettings); return instantiateConfig(settings, accountSettings);
return view;
} }
// #pragma mark -
AccountConfigView::AccountConfigView(BRect rect, BMailAccountSettings* account) AccountConfigView::AccountConfigView(BRect rect, BMailAccountSettings* account)
: :
BBox(rect), BBox(rect),
@ -159,13 +164,13 @@ InProtocolsConfigView::InProtocolsConfigView(BMailAccountSettings* account)
fConfigView(NULL) fConfigView(NULL)
{ {
BString label = "Can't find protocol."; BString label = "Can't find protocol.";
entry_ref protocol = fAccount->InboundPath(); entry_ref protocol = fAccount->InboundAddOnRef();
MailAddonSettings& inboundSettings = fAccount->InboundSettings(); BMailProtocolSettings& inboundSettings = fAccount->InboundSettings();
fConfigView = CreateConfigView(protocol, inboundSettings, *account, fConfigView = CreateConfigView(protocol, inboundSettings, *account,
&fImageID); fImageID);
if (fConfigView) { if (fConfigView != NULL) {
float w = fConfigView->Bounds().Width(); float w = fConfigView->Bounds().Width();
float h = fConfigView->Bounds().Height(); float h = fConfigView->Bounds().Height();
fConfigView->MoveTo(3, 13); fConfigView->MoveTo(3, 13);
@ -195,7 +200,9 @@ InProtocolsConfigView::DetachedFromWindow()
BMessage settings; BMessage settings;
if (fConfigView->Archive(&settings) != B_OK) if (fConfigView->Archive(&settings) != B_OK)
return; return;
fAccount->InboundSettings().EditSettings() = settings;
fAccount->InboundSettings().MakeEmpty();
fAccount->InboundSettings().Append(settings);
RemoveChild(fConfigView); RemoveChild(fConfigView);
delete fConfigView; delete fConfigView;
@ -211,12 +218,12 @@ OutProtocolsConfigView::OutProtocolsConfigView(BMailAccountSettings* account)
fConfigView(NULL) fConfigView(NULL)
{ {
BString label = "Can't find protocol."; BString label = "Can't find protocol.";
entry_ref protocol = fAccount->OutboundPath(); entry_ref protocol = fAccount->OutboundAddOnRef();
MailAddonSettings& outboundSettings = fAccount->OutboundSettings(); BMailProtocolSettings& outboundSettings = fAccount->OutboundSettings();
fConfigView = CreateConfigView(protocol, outboundSettings, *account, fConfigView = CreateConfigView(protocol, outboundSettings, *account,
&fImageID); fImageID);
if (fConfigView) { if (fConfigView != NULL) {
float w = fConfigView->Bounds().Width(); float w = fConfigView->Bounds().Width();
float h = fConfigView->Bounds().Height(); float h = fConfigView->Bounds().Height();
fConfigView->MoveTo(3, 13); fConfigView->MoveTo(3, 13);
@ -247,7 +254,9 @@ OutProtocolsConfigView::DetachedFromWindow()
BMessage settings; BMessage settings;
if (fConfigView->Archive(&settings) != B_OK) if (fConfigView->Archive(&settings) != B_OK)
return; return;
fAccount->OutboundSettings().EditSettings() = settings;
fAccount->OutboundSettings().MakeEmpty();
fAccount->OutboundSettings().Append(settings);
RemoveChild(fConfigView); RemoveChild(fConfigView);
delete fConfigView; delete fConfigView;

View File

@ -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 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de> * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
*
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef CONFIG_VIEWS_H #ifndef CONFIG_VIEWS_H
@ -26,8 +27,8 @@ struct entry_ref;
class ProtocolsConfigView; class ProtocolsConfigView;
BView* CreateConfigView(entry_ref addon, MailAddonSettings& settings, BView* CreateConfigView(const entry_ref& ref, BMailProtocolSettings& settings,
BMailAccountSettings& accountSettings, image_id* image); BMailAccountSettings& accountSettings, image_id& image);
class AccountConfigView : public BBox { class AccountConfigView : public BBox {

View File

@ -49,6 +49,8 @@
#include <MailDaemon.h> #include <MailDaemon.h>
#include <MailSettings.h> #include <MailSettings.h>
#include <MailPrivate.h>
#include "AutoConfigWindow.h" #include "AutoConfigWindow.h"
#include "CenterContainer.h" #include "CenterContainer.h"
@ -530,7 +532,7 @@ ConfigWindow::_SaveSettings()
fConfigView->DeleteChildren(); fConfigView->DeleteChildren();
// collect changed accounts // collect changed accounts
BMessage changedAccounts(kMsgAccountsChanged); BMessage changedAccounts(BPrivate::kMsgAccountsChanged);
for (int32 i = 0; i < fAccounts.CountItems(); i++) { for (int32 i = 0; i < fAccounts.CountItems(); i++) {
BMailAccountSettings* account = fAccounts.ItemAt(i); BMailAccountSettings* account = fAccounts.ItemAt(i);
if (account && account->HasBeenModified()) if (account && account->HasBeenModified())
@ -601,10 +603,10 @@ ConfigWindow::_SaveSettings()
fAccounts.ItemAt(i)->Save(); fAccounts.ItemAt(i)->Save();
} }
BMessenger messenger("application/x-vnd.Be-POST"); BMessenger messenger(B_MAIL_DAEMON_SIGNATURE);
if (messenger.IsValid()) { if (messenger.IsValid()) {
// server should reload general settings // server should reload general settings
messenger.SendMessage(kMsgSettingsUpdated); messenger.SendMessage(BPrivate::kMsgSettingsUpdated);
// notify server about changed accounts // notify server about changed accounts
messenger.SendMessage(&changedAccounts); messenger.SendMessage(&changedAccounts);
} }

View File

@ -1,155 +0,0 @@
/*
* Copyright 2011, Haiku, Inc. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
* Distributed under the terms of the MIT License.
*/
#include "FilterAddonList.h"
#include <Directory.h>
#include <FindDirectory.h>
#include <Path.h>
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);
}

View File

@ -1,54 +0,0 @@
/*
* Copyright 2011, Haiku, Inc. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
* Distributed under the terms of the MIT License.
*/
#ifndef FILTER_ADDON_LIST_H
#define FILTER_ADDON_LIST_H
#include "MailSettings.h"
#include <View.h>
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<FilterAddonInfo> fFilterAddonList;
};
#endif //FILTER_ADDON_LIST_H

View File

@ -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 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de> * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@ -180,7 +180,7 @@ private:
class FilterConfigBox : public BBox { class FilterConfigBox : public BBox {
public: public:
FilterConfigBox(BString& label, BView* child) FilterConfigBox(const BString& label, BView* child)
: :
BBox(BRect(0,0,100,100)), BBox(BRect(0,0,100,100)),
fChild(child) fChild(child)
@ -194,7 +194,7 @@ public:
} }
status_t status_t
ArchiveAddon(BMessage* into) const ArchiveAddOn(BMessage* into) const
{ {
return fChild->Archive(into); return fChild->Archive(into);
} }
@ -203,7 +203,7 @@ private:
BView* fChild; BView* fChild;
}; };
// #pragma mark - // #pragma mark -
@ -211,8 +211,8 @@ FiltersConfigView::FiltersConfigView(BRect rect, BMailAccountSettings& account)
: :
BBox(rect), BBox(rect),
fAccount(account), fAccount(account),
fDirection(kIncomming), fDirection(kIncoming),
fInboundFilters(kIncomming, false), fInboundFilters(kIncoming, false),
fOutboundFilters(kOutgoing, false), fOutboundFilters(kOutgoing, false),
fFilterView(NULL), fFilterView(NULL),
fCurrentIndex(-1) fCurrentIndex(-1)
@ -224,7 +224,7 @@ FiltersConfigView::FiltersConfigView(BRect rect, BMailAccountSettings& account)
msg = new BMessage(kMsgChainSelected); msg = new BMessage(kMsgChainSelected);
item = new BMenuItem(B_TRANSLATE("Incoming mail filters"), msg); item = new BMenuItem(B_TRANSLATE("Incoming mail filters"), msg);
menu->AddItem(item); menu->AddItem(item);
msg->AddInt32("direction", kIncomming); msg->AddInt32("direction", kIncoming);
item->SetMarked(true); item->SetMarked(true);
msg = new BMessage(kMsgChainSelected); msg = new BMessage(kMsgChainSelected);
@ -302,14 +302,14 @@ FiltersConfigView::_SelectFilter(int32 index)
if (index >= 0) { if (index >= 0) {
// add new config view // add new config view
AddonSettings* filterSettings = _GetCurrentMailSettings() BMailAddOnSettings* filterSettings
->FilterSettingsAt(index); = _MailSettings()->FilterSettingsAt(index);
if (filterSettings) { if (filterSettings != NULL) {
FilterAddonList* addons = _GetCurrentFilterAddonList(); ::FilterList* filters = _FilterList();
BView* view = addons->CreateConfigView(*filterSettings); BView* view = filters->CreateConfigView(*filterSettings);
if (view) { if (view != NULL) {
BString name; BString name;
addons->GetDescriptiveName(filterSettings->AddonRef(), name); filters->GetDescriptiveName(filterSettings->AddOnRef(), name);
fFilterView = new FilterConfigBox(name, view); fFilterView = new FilterConfigBox(name, view);
Parent()->AddChild(fFilterView); Parent()->AddChild(fFilterView);
} }
@ -319,7 +319,7 @@ FiltersConfigView::_SelectFilter(int32 index)
fCurrentIndex = index; fCurrentIndex = index;
// re-layout the view containing the config view // re-layout the view containing the config view
if (CenterContainer *container = dynamic_cast<CenterContainer *>(Parent())) if (CenterContainer* container = dynamic_cast<CenterContainer*>(Parent()))
container->Layout(); container->Layout();
if (Parent()) if (Parent())
@ -339,19 +339,19 @@ FiltersConfigView::_SetDirection(direction direction)
} }
fDirection = direction; fDirection = direction;
MailAddonSettings* addonSettings = _GetCurrentMailSettings(); BMailProtocolSettings* protocolSettings = _MailSettings();
FilterAddonList* addons = _GetCurrentFilterAddonList(); ::FilterList* filters = _FilterList();
addons->Reload(); filters->Reload();
for (int32 i = 0; i < addonSettings->CountFilterSettings(); i++) { for (int32 i = 0; i < protocolSettings->CountFilterSettings(); i++) {
AddonSettings* filterSettings = addonSettings->FilterSettingsAt(i); BMailAddOnSettings* settings = protocolSettings->FilterSettingsAt(i);
if (addons->FindInfo(filterSettings->AddonRef()) < 0) { if (filters->InfoIndexFor(settings->AddOnRef()) < 0) {
addonSettings->RemoveFilterSettings(i); protocolSettings->RemoveFilterSettings(i);
i--; i--;
continue; continue;
} }
BString name = "Unnamed Filter"; BString name = "Unnamed Filter";
addons->GetDescriptiveName(filterSettings->AddonRef(), name); filters->GetDescriptiveName(settings->AddOnRef(), name);
fListView->AddItem(new BStringItem(name)); fListView->AddItem(new BStringItem(name));
} }
@ -362,11 +362,11 @@ FiltersConfigView::_SetDirection(direction direction)
delete item; delete item;
} }
addons->Reload(); filters->Reload();
for (int32 i = 0; i < addons->CountFilterAddons(); i++) { for (int32 i = 0; i < filters->CountInfos(); i++) {
FilterAddonInfo& info = addons->FilterAddonAt(i); FilterInfo& info = filters->InfoAt(i);
BString name; BString name;
addons->GetDescriptiveName(i, name); filters->GetDescriptiveName(i, name);
BMessage* msg = new BMessage(kMsgAddFilter); BMessage* msg = new BMessage(kMsgAddFilter);
msg->AddRef("filter", &info.ref); msg->AddRef("filter", &info.ref);
@ -417,14 +417,14 @@ FiltersConfigView::MessageReceived(BMessage *msg)
if (msg->FindRef("filter", &ref) < B_OK) if (msg->FindRef("filter", &ref) < B_OK)
break; break;
FilterAddonList* filterAddons = _GetCurrentFilterAddonList(); ::FilterList* filters = _FilterList();
int32 index = filterAddons->FindInfo(ref); int32 index = filters->InfoIndexFor(ref);
if (index < 0) if (index < 0)
break; break;
_GetCurrentMailSettings()->AddFilterSettings(&ref); _MailSettings()->AddFilterSettings(&ref);
BString name; BString name;
filterAddons->GetDescriptiveName(index, name); filters->GetDescriptiveName(index, name);
fListView->AddItem(new BStringItem(name)); fListView->AddItem(new BStringItem(name));
break; break;
} }
@ -433,13 +433,11 @@ FiltersConfigView::MessageReceived(BMessage *msg)
int32 index = fListView->CurrentSelection(); int32 index = fListView->CurrentSelection();
if (index < 0) if (index < 0)
break; break;
BStringItem *item = (BStringItem *)fListView->RemoveItem(index); BStringItem* item = (BStringItem*)fListView->RemoveItem(index);
delete item; delete item;
_SelectFilter(-1); _SelectFilter(-1);
_MailSettings()->RemoveFilterSettings(index);
MailAddonSettings* mailSettings = _GetCurrentMailSettings();
mailSettings->RemoveFilterSettings(index);
break; break;
} }
case kMsgFilterSelected: case kMsgFilterSelected:
@ -458,8 +456,7 @@ FiltersConfigView::MessageReceived(BMessage *msg)
if (from == to) if (from == to)
break; break;
MailAddonSettings* mailSettings = _GetCurrentMailSettings(); if (!_MailSettings()->MoveFilterSettings(from, to)) {
if (!mailSettings->MoveFilterSettings(from, to)) {
BAlert* alert = new BAlert("E-mail", BAlert* alert = new BAlert("E-mail",
B_TRANSLATE("The filter could not be moved. Deleting " B_TRANSLATE("The filter could not be moved. Deleting "
"filter."), B_TRANSLATE("OK")); "filter."), B_TRANSLATE("OK"));
@ -467,7 +464,7 @@ FiltersConfigView::MessageReceived(BMessage *msg)
alert->Go(); alert->Go();
fListView->RemoveItem(to); fListView->RemoveItem(to);
break; break;
} }
break; break;
} }
@ -478,19 +475,19 @@ FiltersConfigView::MessageReceived(BMessage *msg)
} }
MailAddonSettings* BMailProtocolSettings*
FiltersConfigView::_GetCurrentMailSettings() FiltersConfigView::_MailSettings()
{ {
if (fDirection == kIncomming) if (fDirection == kIncoming)
return &fAccount.InboundSettings(); return &fAccount.InboundSettings();
return &fAccount.OutboundSettings(); return &fAccount.OutboundSettings();
} }
FilterAddonList* FilterList*
FiltersConfigView::_GetCurrentFilterAddonList() FiltersConfigView::_FilterList()
{ {
if (fDirection == kIncomming) if (fDirection == kIncoming)
return &fInboundFilters; return &fInboundFilters;
return &fOutboundFilters; return &fOutboundFilters;
} }
@ -499,10 +496,9 @@ FiltersConfigView::_GetCurrentFilterAddonList()
void void
FiltersConfigView::_SaveConfig(int32 index) FiltersConfigView::_SaveConfig(int32 index)
{ {
if (fFilterView) { if (fFilterView != NULL) {
AddonSettings* filterSettings = _GetCurrentMailSettings() BMailAddOnSettings* settings = _MailSettings()->FilterSettingsAt(index);
->FilterSettingsAt(index); if (settings != NULL)
if (filterSettings) fFilterView->ArchiveAddOn(settings);
fFilterView->ArchiveAddon(&filterSettings->EditSettings());
} }
} }

View File

@ -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 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de> * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@ -12,13 +12,12 @@
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
#include <image.h>
#include <ListView.h> #include <ListView.h>
#include <MailSettings.h>
#include <Message.h> #include <Message.h>
#include <MenuField.h> #include <MenuField.h>
#include "FilterAddonList.h" #include "FilterList.h"
#include "MailSettings.h"
class FilterConfigBox; class FilterConfigBox;
@ -35,18 +34,19 @@ public:
void MessageReceived(BMessage *msg); void MessageReceived(BMessage *msg);
private: private:
MailAddonSettings* _GetCurrentMailSettings(); BMailProtocolSettings* _MailSettings();
FilterAddonList* _GetCurrentFilterAddonList(); ::FilterList* _FilterList();
void _SelectFilter(int32 index); void _SelectFilter(int32 index);
void _SetDirection(direction direction); void _SetDirection(direction direction);
void _SaveConfig(int32 index); void _SaveConfig(int32 index);
BMailAccountSettings& fAccount; private:
BMailAccountSettings& fAccount;
direction fDirection; direction fDirection;
FilterAddonList fInboundFilters; ::FilterList fInboundFilters;
FilterAddonList fOutboundFilters; ::FilterList fOutboundFilters;
BMenuField* fChainsField; BMenuField* fChainsField;
BListView* fListView; BListView* fListView;

View File

@ -0,0 +1,155 @@
/*
* Copyright 2011-2012, Haiku, Inc. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
* Distributed under the terms of the MIT License.
*/
#include "FilterList.h"
#include <Directory.h>
#include <FindDirectory.h>
#include <Path.h>
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);
}

View File

@ -0,0 +1,54 @@
/*
* Copyright 2011-2012, Haiku, Inc. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
* Distributed under the terms of the MIT License.
*/
#ifndef FILTER_LIST_H
#define FILTER_LIST_H
#include <MailSettings.h>
#include <View.h>
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<FilterInfo> fList;
};
#endif // FILTER_LIST_H

View File

@ -1,6 +1,5 @@
SubDir HAIKU_TOP src preferences mail ; SubDir HAIKU_TOP src preferences mail ;
UsePublicHeaders [ FDirName add-ons mail_daemon ] ; UsePublicHeaders [ FDirName add-ons mail_daemon ] ;
UsePrivateHeaders mail ; UsePrivateHeaders mail ;
@ -17,7 +16,7 @@ local sources =
CenterContainer.cpp CenterContainer.cpp
ConfigViews.cpp ConfigViews.cpp
ConfigWindow.cpp ConfigWindow.cpp
FilterAddonList.cpp FilterList.cpp
DNSQuery.cpp DNSQuery.cpp
FilterConfigView.cpp FilterConfigView.cpp
main.cpp main.cpp