* Style cleanup, no functional change. There would be still lots of stuff to

do, though.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36650 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2010-05-06 14:16:19 +00:00
parent 83bc49d051
commit d55567bbf9
3 changed files with 602 additions and 575 deletions

View File

@ -1,7 +1,9 @@
/* Account - provides an "account" view on the mail chains
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
/*
* Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
//! Provides an "account" view on the mail chains.
#include "Account.h"
@ -30,9 +32,11 @@
#include <MDRLanguage.h>
#undef TR_CONTEXT
#define TR_CONTEXT "Account"
static BList gAccounts;
static BListView *gListView;
static BView *gConfigView;
@ -44,12 +48,12 @@ const char *kInboundProtocolAddOnPath = "mail_daemon/inbound_protocols";
const char *kOutboundProtocolAddOnPath = "mail_daemon/outbound_protocols";
//---------------------------------------------------------------------------------------
// #pragma mark -
AccountItem::AccountItem(const char *label,Account *account,int32 type)
: BStringItem(label),
AccountItem::AccountItem(const char *label, Account *account, int32 type)
:
BStringItem(label),
account(account),
type(type)
{
@ -61,7 +65,8 @@ AccountItem::~AccountItem()
}
void AccountItem::Update(BView *owner, const BFont *font)
void
AccountItem::Update(BView *owner, const BFont *font)
{
if (type == ACCOUNT_ITEM)
font = be_bold_font;
@ -70,11 +75,11 @@ void AccountItem::Update(BView *owner, const BFont *font)
}
void AccountItem::DrawItem(BView *owner, BRect rect, bool complete)
void
AccountItem::DrawItem(BView *owner, BRect rect, bool complete)
{
owner->PushState();
if (type == ACCOUNT_ITEM)
{
if (type == ACCOUNT_ITEM) {
// BFont font;
// owner->GetFont(&font);
// font.SetFace(B_BOLD_FACE);
@ -85,12 +90,12 @@ void AccountItem::DrawItem(BView *owner, BRect rect, bool complete)
}
//---------------------------------------------------------------------------------------
// #pragma mark -
Account::Account(BMailChain *inbound,BMailChain *outbound)
: fInbound(inbound),
Account::Account(BMailChain *inbound, BMailChain *outbound)
:
fInbound(inbound),
fOutbound(outbound),
fAccountItem(NULL),
@ -105,32 +110,34 @@ Account::Account(BMailChain *inbound,BMailChain *outbound)
label << fSettings->Name();
else
label << TR("Unnamed");
fAccountItem = new AccountItem(label.String(),this,ACCOUNT_ITEM);
fAccountItem = new AccountItem(label.String(), this, ACCOUNT_ITEM);
fInboundItem = new AccountItem(TR (" · Incoming"),this,INBOUND_ITEM);
fOutboundItem = new AccountItem(TR (" · Outgoing"),this,OUTBOUND_ITEM);
fFilterItem = new AccountItem(TR (" · E-mail filters"),this,FILTER_ITEM);
fInboundItem = new AccountItem(TR(" · Incoming"), this, INBOUND_ITEM);
fOutboundItem = new AccountItem(TR(" · Outgoing"), this, OUTBOUND_ITEM);
fFilterItem = new AccountItem(TR(" · E-mail filters"), this, FILTER_ITEM);
}
Account::~Account()
{
if (gListView)
{
if (gListView) {
gListView->RemoveItem(fAccountItem);
gListView->RemoveItem(fInboundItem);
gListView->RemoveItem(fOutboundItem);
gListView->RemoveItem(fFilterItem);
}
delete fAccountItem; delete fFilterItem;
delete fInboundItem; delete fOutboundItem;
delete fAccountItem;
delete fFilterItem;
delete fInboundItem;
delete fOutboundItem;
delete fInbound;
delete fOutbound;
}
void Account::AddToListView()
void
Account::AddToListView()
{
if (!gListView)
return;
@ -148,22 +155,23 @@ void Account::AddToListView()
}
void Account::SetName(const char *name)
void
Account::SetName(const char *name)
{
if (fInbound)
fInbound->SetName(name);
if (fOutbound)
fOutbound->SetName(name);
if (name && *name)
{
if (name && *name) {
fAccountItem->SetText(name);
gListView->InvalidateItem(gListView->IndexOf(fAccountItem));
}
}
const char *Account::Name() const
const char *
Account::Name() const
{
if (fInbound)
return fInbound->Name();
@ -174,23 +182,23 @@ const char *Account::Name() const
}
void Account::SetRealName(const char *realName)
void
Account::SetRealName(const char *realName)
{
BMessage *msg;
if (fInbound && (msg = fInbound->MetaData()) != NULL)
{
if (msg->ReplaceString("real_name",realName) < B_OK)
msg->AddString("real_name",realName);
if (fInbound && (msg = fInbound->MetaData()) != NULL) {
if (msg->ReplaceString("real_name", realName) < B_OK)
msg->AddString("real_name", realName);
}
if (fOutbound && (msg = fOutbound->MetaData()) != NULL)
{
if (msg->ReplaceString("real_name",realName) < B_OK)
msg->AddString("real_name",realName);
if (fOutbound && (msg = fOutbound->MetaData()) != NULL) {
if (msg->ReplaceString("real_name", realName) < B_OK)
msg->AddString("real_name", realName);
}
}
const char *Account::RealName() const
const char *
Account::RealName() const
{
if (fInbound && fInbound->MetaData())
return fInbound->MetaData()->FindString("real_name");
@ -204,23 +212,23 @@ const char *Account::RealName() const
}
void Account::SetReturnAddress(const char *returnAddress)
void
Account::SetReturnAddress(const char *returnAddress)
{
BMessage *msg;
if (fInbound && (msg = fInbound->MetaData()) != NULL)
{
if (msg->ReplaceString("reply_to",returnAddress) < B_OK)
msg->AddString("reply_to",returnAddress);
if (fInbound && (msg = fInbound->MetaData()) != NULL) {
if (msg->ReplaceString("reply_to", returnAddress) < B_OK)
msg->AddString("reply_to", returnAddress);
}
if (fOutbound && (msg = fOutbound->MetaData()) != NULL)
{
if (msg->ReplaceString("reply_to",returnAddress) < B_OK)
msg->AddString("reply_to",returnAddress);
if (fOutbound && (msg = fOutbound->MetaData()) != NULL) {
if (msg->ReplaceString("reply_to", returnAddress) < B_OK)
msg->AddString("reply_to", returnAddress);
}
}
const char *Account::ReturnAddress() const
const char *
Account::ReturnAddress() const
{
if (fInbound && fInbound->MetaData())
return fInbound->MetaData()->FindString("reply_to");
@ -231,22 +239,20 @@ const char *Account::ReturnAddress() const
}
void Account::CopyMetaData(BMailChain *targetChain, BMailChain *sourceChain)
void
Account::CopyMetaData(BMailChain *targetChain, BMailChain *sourceChain)
{
BMessage *otherMsg, *thisMsg;
if (sourceChain && (otherMsg = sourceChain->MetaData()) != NULL
&& (thisMsg = targetChain->MetaData()) != NULL)
{
&& (thisMsg = targetChain->MetaData()) != NULL) {
const char *string;
if ((string = otherMsg->FindString("real_name")) != NULL)
{
if (thisMsg->ReplaceString("real_name",string) < B_OK)
thisMsg->AddString("real_name",string);
if ((string = otherMsg->FindString("real_name")) != NULL) {
if (thisMsg->ReplaceString("real_name", string) < B_OK)
thisMsg->AddString("real_name", string);
}
if ((string = otherMsg->FindString("reply_to")) != NULL)
{
if (thisMsg->ReplaceString("reply_to",string) < B_OK)
thisMsg->AddString("reply_to",string);
if ((string = otherMsg->FindString("reply_to")) != NULL) {
if (thisMsg->ReplaceString("reply_to", string) < B_OK)
thisMsg->AddString("reply_to", string);
}
if ((string = sourceChain->Name()) != NULL)
targetChain->SetName(string);
@ -254,21 +260,18 @@ void Account::CopyMetaData(BMailChain *targetChain, BMailChain *sourceChain)
}
void Account::CreateInbound()
void
Account::CreateInbound()
{
if (!(fInbound = NewMailChain()))
{
(new BAlert(
TR ("E-mail"),
TR ("Could not create inbound chain."),
TR ("OK")))->Go();
if (!(fInbound = NewMailChain())) {
(new BAlert(TR("E-mail"), TR("Could not create inbound chain."),
TR("OK")))->Go();
return;
}
fInbound->SetChainDirection(inbound);
BPath path,addOnPath;
find_directory(B_USER_ADDONS_DIRECTORY,&addOnPath);
find_directory(B_USER_ADDONS_DIRECTORY, &addOnPath);
BMessage msg;
entry_ref ref;
@ -278,69 +281,66 @@ void Account::CreateInbound()
path.Append(kInboundProtocolAddOnPath);
path.Append("POP3");
if (!BEntry(path.Path()).Exists()) {
find_directory(B_BEOS_ADDONS_DIRECTORY,&path);
find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
path.Append(kInboundProtocolAddOnPath);
path.Append("POP3");
}
BEntry(path.Path()).GetRef(&ref);
fInbound->AddFilter(msg,ref);
fInbound->AddFilter(msg, ref);
// Message Parser
path = addOnPath;
path.Append(kSystemFilterAddOnPath);
path.Append("Message Parser");
if (!BEntry(path.Path()).Exists()) {
find_directory(B_BEOS_ADDONS_DIRECTORY,&path);
find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
path.Append(kSystemFilterAddOnPath);
path.Append("Message Parser");
}
BEntry(path.Path()).GetRef(&ref);
fInbound->AddFilter(msg,ref);
fInbound->AddFilter(msg, ref);
// New Mail Notification
path = addOnPath;
path.Append(kSystemFilterAddOnPath);
path.Append(TR ("New mail notification"));
path.Append(TR("New mail notification"));
if (!BEntry(path.Path()).Exists()) {
find_directory(B_BEOS_ADDONS_DIRECTORY,&path);
find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
path.Append(kSystemFilterAddOnPath);
path.Append("New mail notification");
}
BEntry(path.Path()).GetRef(&ref);
fInbound->AddFilter(msg,ref);
fInbound->AddFilter(msg, ref);
// Inbox
path = addOnPath;
path.Append(kSystemFilterAddOnPath);
path.Append("Inbox");
if (!BEntry(path.Path()).Exists()) {
find_directory(B_BEOS_ADDONS_DIRECTORY,&path);
find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
path.Append(kSystemFilterAddOnPath);
path.Append("Inbox");
}
BEntry(path.Path()).GetRef(&ref);
fInbound->AddFilter(msg,ref);
fInbound->AddFilter(msg, ref);
// set already made account settings
CopyMetaData(fInbound,fOutbound);
}
void Account::CreateOutbound()
void
Account::CreateOutbound()
{
if (!(fOutbound = NewMailChain()))
{
(new BAlert(
TR ("E-mail"),
TR ("Could not create outbound chain."),
TR ("OK")))->Go();
if (!(fOutbound = NewMailChain())) {
(new BAlert(TR("E-mail"), TR("Could not create outbound chain."),
TR("OK")))->Go();
return;
}
fOutbound->SetChainDirection(outbound);
BPath path,addOnPath;
find_directory(B_USER_ADDONS_DIRECTORY,&addOnPath);
find_directory(B_USER_ADDONS_DIRECTORY, &addOnPath);
BMessage msg;
entry_ref ref;
@ -349,30 +349,31 @@ void Account::CreateOutbound()
path.Append(kSystemFilterAddOnPath);
path.Append("Outbox");
if (!BEntry(path.Path()).Exists()) {
find_directory(B_BEOS_ADDONS_DIRECTORY,&path);
find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
path.Append(kSystemFilterAddOnPath);
path.Append("Outbox");
}
BEntry(path.Path()).GetRef(&ref);
fOutbound->AddFilter(msg,ref);
fOutbound->AddFilter(msg, ref);
path = addOnPath;
path.Append(kOutboundProtocolAddOnPath);
path.Append("SMTP");
if (!BEntry(path.Path()).Exists()) {
find_directory(B_BEOS_ADDONS_DIRECTORY,&path);
find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
path.Append(kOutboundProtocolAddOnPath);
path.Append("SMTP");
}
BEntry(path.Path()).GetRef(&ref);
fOutbound->AddFilter(msg,ref);
fOutbound->AddFilter(msg, ref);
// set already made account settings
CopyMetaData(fOutbound,fInbound);
}
void Account::SetType(int32 type)
void
Account::SetType(int32 type)
{
if (type < INBOUND_TYPE || type > IN_AND_OUTBOUND_TYPE)
return;
@ -380,8 +381,7 @@ void Account::SetType(int32 type)
int32 index = gListView->IndexOf(fAccountItem) + 1;
// missing inbound
if ((type == INBOUND_TYPE || type == IN_AND_OUTBOUND_TYPE) && !Inbound())
{
if ((type == INBOUND_TYPE || type == IN_AND_OUTBOUND_TYPE) && !Inbound()) {
if (!fInbound)
CreateInbound();
@ -392,20 +392,20 @@ void Account::SetType(int32 type)
index++;
// missing outbound
if ((type == OUTBOUND_TYPE || type == IN_AND_OUTBOUND_TYPE) && !Outbound())
{
if ((type == OUTBOUND_TYPE || type == IN_AND_OUTBOUND_TYPE)
&& !Outbound()) {
if (!fOutbound)
CreateOutbound();
if (fOutbound)
gListView->AddItem(fOutboundItem,index);
gListView->AddItem(fOutboundItem, index);
}
if (Outbound())
index++;
// missing filter
if (!gListView->HasItem(fFilterItem))
gListView->AddItem(fFilterItem,index);
gListView->AddItem(fFilterItem, index);
// remove inbound
if (type == OUTBOUND_TYPE && Inbound())
@ -417,13 +417,15 @@ void Account::SetType(int32 type)
}
int32 Account::Type() const
int32
Account::Type() const
{
return Inbound() ? (Outbound() ? 2 : 0) : (Outbound() ? 1 : -1);
}
void Account::Selected(int32 type)
void
Account::Selected(int32 type)
{
if (!gConfigView)
return;
@ -431,10 +433,10 @@ void Account::Selected(int32 type)
gConfigView->Hide();
((CenterContainer *)gConfigView)->DeleteChildren();
switch (type)
{
switch (type) {
case ACCOUNT_ITEM:
gConfigView->AddChild(new AccountConfigView(gConfigView->Bounds(),this));
gConfigView->AddChild(new AccountConfigView(gConfigView->Bounds(),
this));
break;
case INBOUND_ITEM:
{
@ -442,22 +444,19 @@ void Account::Selected(int32 type)
break;
int32 count = fInbound->CountFilters();
for (int32 i = 0;;i++)
{
for (int32 i = 0;; i++) {
BMessage *msg = new BMessage();
entry_ref *ref = new entry_ref;
// we just want to have the first and the last two filters:
// Protocol, Parser, Notifier, Folder
if (i == 2)
{
if (i == 2) {
i = count - 2;
if (i < 2) // defensive programming...
i = 3;
}
if (fInbound->GetFilter(i,msg,ref) < B_OK)
{
if (fInbound->GetFilter(i, msg, ref) < B_OK) {
delete msg;
delete ref;
break;
@ -466,9 +465,9 @@ void Account::Selected(int32 type)
// the filter view takes ownership of "msg" and "ref"
FilterConfigView *view;
if (i == 0)
view = new ProtocolsConfigView(fInbound,i,msg,ref);
view = new ProtocolsConfigView(fInbound, i, msg, ref);
else
view = new FilterConfigView(fInbound,i,msg,ref);
view = new FilterConfigView(fInbound, i, msg, ref);
if (view->InitCheck() >= B_OK)
gConfigView->AddChild(view);
@ -484,32 +483,31 @@ void Account::Selected(int32 type)
// we just want to have the first and the last filter here
int32 count = fOutbound->CountFilters();
for (int32 i = 0;i < count;i += count-1)
{
for (int32 i = 0; i < count; i += count - 1) {
BMessage *msg = new BMessage();
entry_ref *ref = new entry_ref;
if (fOutbound->GetFilter(i,msg,ref) < B_OK)
{
if (fOutbound->GetFilter(i, msg, ref) < B_OK) {
delete msg;
delete ref;
break;
}
// the filter view takes ownership of "msg" and "ref"
if (FilterConfigView *view = new FilterConfigView(fOutbound,i,msg,ref))
{
FilterConfigView *view = new FilterConfigView(fOutbound, i, msg,
ref);
if (view->InitCheck() >= B_OK)
gConfigView->AddChild(view);
else
delete view;
}
}
break;
}
case FILTER_ITEM:
{
gConfigView->AddChild(new FiltersConfigView(gConfigView->Bounds(),this));
gConfigView->AddChild(new FiltersConfigView(gConfigView->Bounds(),
this));
break;
}
}
@ -518,14 +516,14 @@ void Account::Selected(int32 type)
}
void Account::Remove(int32 type)
void
Account::Remove(int32 type)
{
// this should only be called if necessary, but if it's used
// in the GUI, this will always be the case
((CenterContainer *)gConfigView)->DeleteChildren();
switch (type)
{
switch (type) {
case ACCOUNT_ITEM:
gListView->RemoveItem(fAccountItem);
gListView->RemoveItem(fInboundItem);
@ -552,19 +550,22 @@ void Account::Remove(int32 type)
}
BMailChain *Account::Inbound() const
BMailChain *
Account::Inbound() const
{
return gListView && gListView->HasItem(fInboundItem) ? fInbound : NULL;
}
BMailChain *Account::Outbound() const
BMailChain *
Account::Outbound() const
{
return gListView && gListView->HasItem(fOutboundItem) ? fOutbound : NULL;
}
void Account::Save()
void
Account::Save()
{
if (Inbound())
fInbound->Save();
@ -578,7 +579,8 @@ void Account::Save()
}
void Account::Delete(int32 type)
void
Account::Delete(int32 type)
{
if (fInbound && (type == INBOUND_TYPE || type == IN_AND_OUTBOUND_TYPE))
fInbound->Delete();
@ -591,7 +593,8 @@ void Account::Delete(int32 type)
// #pragma mark -
int Accounts::Compare(const void *_a, const void *_b)
int
Accounts::Compare(const void *_a, const void *_b)
{
const char *a = (*(Account **)_a)->Name();
const char *b = (*(Account **)_b)->Name();
@ -603,7 +606,8 @@ int Accounts::Compare(const void *_a, const void *_b)
}
void Accounts::Create(BListView *listView, BView *configView)
void
Accounts::Create(BListView *listView, BView *configView)
{
gListView = listView;
gConfigView = configView;
@ -615,19 +619,16 @@ void Accounts::Create(BListView *listView, BView *configView)
// create inbound accounts and assign matching outbound chains
for (int32 i = inbound.CountItems();i-- > 0;)
{
for (int32 i = inbound.CountItems(); i-- > 0;) {
BMailChain *inChain = (BMailChain *)inbound.ItemAt(i);
BMailChain *outChain = NULL;
for (int32 j = outbound.CountItems();j-- > 0;)
{
for (int32 j = outbound.CountItems(); j-- > 0;) {
outChain = (BMailChain *)outbound.ItemAt(j);
if (!strcmp(inChain->Name(),outChain->Name()))
if (!strcmp(inChain->Name(), outChain->Name()))
break;
outChain = NULL;
}
gAccounts.AddItem(new Account(inChain,outChain));
gAccounts.AddItem(new Account(inChain, outChain));
inbound.RemoveItem(i);
if (outChain)
outbound.RemoveItem(outChain);
@ -635,23 +636,23 @@ void Accounts::Create(BListView *listView, BView *configView)
// create remaining outbound only accounts
for (int32 i = outbound.CountItems();i-- > 0;)
{
for (int32 i = outbound.CountItems(); i-- > 0;) {
BMailChain *outChain = (BMailChain *)outbound.ItemAt(i);
gAccounts.AddItem(new Account(NULL,outChain));
gAccounts.AddItem(new Account(NULL, outChain));
outbound.RemoveItem(i);
}
// sort the list alphabetically
gAccounts.SortItems(Accounts::Compare);
for (int32 i = 0;Account *account = (Account *)gAccounts.ItemAt(i);i++)
for (int32 i = 0; Account *account = (Account *)gAccounts.ItemAt(i); i++)
account->AddToListView();
}
Account* Accounts::NewAccount()
Account*
Accounts::NewAccount()
{
Account *account = new Account();
gAccounts.AddItem(account);
@ -663,19 +664,19 @@ Account* Accounts::NewAccount()
}
void Accounts::Save()
void
Accounts::Save()
{
for (int32 i = gAccounts.CountItems();i-- > 0;)
for (int32 i = gAccounts.CountItems(); i-- > 0;)
((Account *)gAccounts.ItemAt(i))->Save();
}
void Accounts::Delete()
void
Accounts::Delete()
{
for (int32 i = gAccounts.CountItems();i-- > 0;)
{
for (int32 i = gAccounts.CountItems(); i-- > 0;) {
Account *account = (Account *)gAccounts.RemoveItem(i);
delete account;
}
}

View File

@ -1,7 +1,9 @@
/* ConfigViews - config views for the account, protocols, and filters
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
/*
* Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
//! Config views for the account, protocols, and filters.
#include "ConfigViews.h"
@ -53,58 +55,66 @@ const uint32 kMsgRemoveFilter = 'rmfi';
const uint32 kMsgFilterSelected = 'fsel';
AccountConfigView::AccountConfigView(BRect rect,Account *account)
: BBox(rect),
AccountConfigView::AccountConfigView(BRect rect, Account *account)
:
BBox(rect),
fAccount(account)
{
SetLabel(TR ("Account settings"));
SetLabel(TR("Account settings"));
rect = Bounds().InsetByCopy(8,8);
rect = Bounds().InsetByCopy(8, 8);
rect.top += 10;
CenterContainer *view = new CenterContainer(rect,false);
CenterContainer *view = new CenterContainer(rect, false);
view->SetSpacing(5);
// determine font height
font_height fontHeight;
view->GetFontHeight(&fontHeight);
int32 height = (int32)(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 5;
int32 height = (int32)(fontHeight.ascent + fontHeight.descent
+ fontHeight.leading) + 5;
rect = view->Bounds();
rect.bottom = height + 5;
float labelWidth = view->StringWidth(TR ("Account name:")) + 6;
float labelWidth = view->StringWidth(TR("Account name:")) + 6;
view->AddChild(fNameControl = new BTextControl(rect,NULL,TR ("Account name:"),NULL,new BMessage(kMsgAccountNameChanged)));
view->AddChild(fNameControl = new BTextControl(rect, NULL,
TR("Account name:"), NULL, new BMessage(kMsgAccountNameChanged)));
fNameControl->SetDivider(labelWidth);
view->AddChild(fRealNameControl = new BTextControl(rect,NULL,TR ("Real name:"),NULL,NULL));
view->AddChild(fRealNameControl = new BTextControl(rect, NULL,
TR("Real name:"), NULL, NULL));
fRealNameControl->SetDivider(labelWidth);
view->AddChild(fReturnAddressControl = new BTextControl(rect,NULL,TR ("Return address:"),NULL,NULL));
view->AddChild(fReturnAddressControl = new BTextControl(rect, NULL,
TR("Return address:"), NULL, NULL));
fReturnAddressControl->SetDivider(labelWidth);
// control->TextView()->HideTyping(true);
BPopUpMenu *chainsPopUp = new BPopUpMenu(B_EMPTY_STRING);
const char *chainModes[] = {
TR ("Receive mail only"),
TR ("Send mail only"),
TR ("Send and receive mail")};
TR("Receive mail only"),
TR("Send mail only"),
TR("Send and receive mail")};
BMenuItem *item;
for (int32 i = 0;i < 3;i++)
chainsPopUp->AddItem(item = new BMenuItem(chainModes[i],new BMessage(kMsgAccountTypeChanged)));
for (int32 i = 0;i < 3;i++) {
chainsPopUp->AddItem(item = new BMenuItem(chainModes[i],
new BMessage(kMsgAccountTypeChanged)));
}
fTypeField = new BMenuField(rect,NULL,TR ("Account type:"),chainsPopUp);
fTypeField = new BMenuField(rect, NULL, TR("Account type:"), chainsPopUp);
fTypeField->SetDivider(labelWidth + 3);
view->AddChild(fTypeField);
float w,h;
view->GetPreferredSize(&w,&h);
ResizeTo(w + 15,h + 22);
view->ResizeTo(w,h);
float w, h;
view->GetPreferredSize(&w, &h);
ResizeTo(w + 15, h + 22);
view->ResizeTo(w, h);
AddChild(view);
}
void AccountConfigView::DetachedFromWindow()
void
AccountConfigView::DetachedFromWindow()
{
fAccount->SetName(fNameControl->Text());
fAccount->SetRealName(fRealNameControl->Text());
@ -112,7 +122,8 @@ void AccountConfigView::DetachedFromWindow()
}
void AccountConfigView::AttachedToWindow()
void
AccountConfigView::AttachedToWindow()
{
UpdateViews();
fNameControl->SetTarget(this);
@ -120,18 +131,17 @@ void AccountConfigView::AttachedToWindow()
}
void AccountConfigView::MessageReceived(BMessage *msg)
void
AccountConfigView::MessageReceived(BMessage *msg)
{
switch (msg->what)
{
switch (msg->what) {
case kMsgAccountTypeChanged:
{
int32 index;
if (msg->FindInt32("index",&index) < B_OK)
if (msg->FindInt32("index", &index) < B_OK)
break;
if (fAccount->Type() < 0)
{
if (fAccount->Type() < 0) {
fNameControl->SetEnabled(true);
fRealNameControl->SetEnabled(true);
fReturnAddressControl->SetEnabled(true);
@ -150,13 +160,13 @@ void AccountConfigView::MessageReceived(BMessage *msg)
}
void AccountConfigView::UpdateViews()
void
AccountConfigView::UpdateViews()
{
if (!fAccount->Inbound() && !fAccount->Outbound())
{
if (!fAccount->Inbound() && !fAccount->Outbound()) {
if (BMenuItem *item = fTypeField->Menu()->FindMarked())
item->SetMarked(false);
fTypeField->Menu()->Superitem()->SetLabel(TR ("Select account type"));
fTypeField->Menu()->Superitem()->SetLabel(TR("Select account type"));
fNameControl->SetEnabled(false);
fRealNameControl->SetEnabled(false);
@ -172,12 +182,13 @@ void AccountConfigView::UpdateViews()
}
//---------------------------------------------------------------------------------------
// #pragma mark -
#include <stdio.h>
FilterConfigView::FilterConfigView(BMailChain *chain,int32 index,BMessage *msg,entry_ref *ref)
: BBox(BRect(0,0,100,100)),
FilterConfigView::FilterConfigView(BMailChain *chain, int32 index,
BMessage *msg, entry_ref *ref)
:
BBox(BRect(0,0,100,100)),
fConfigView(NULL),
fChain(chain),
fIndex(index),
@ -196,46 +207,46 @@ FilterConfigView::~FilterConfigView()
}
void FilterConfigView::Load(BMessage *msg,entry_ref *ref)
void
FilterConfigView::Load(BMessage *msg, entry_ref *ref)
{
ResizeTo(264,30);
BView *(* instantiate_config)(BMessage *,BMessage *);
BView *(* instantiate_config)(BMessage *, BMessage *);
BPath addon(ref);
fImage = load_add_on(addon.Path());
if (fImage < B_OK)
return;
if (get_image_symbol(fImage,"instantiate_config_panel",B_SYMBOL_TYPE_TEXT,(void **)&instantiate_config) < B_OK)
{
if (get_image_symbol(fImage, "instantiate_config_panel",
B_SYMBOL_TYPE_TEXT,(void **)&instantiate_config) < B_OK) {
unload_add_on(fImage);
fImage = B_MISSING_SYMBOL;
return;
}
fConfigView = (*instantiate_config)(msg,fChain->MetaData());
fConfigView = (*instantiate_config)(msg, fChain->MetaData());
float w = fConfigView->Bounds().Width();
float h = fConfigView->Bounds().Height();
fConfigView->MoveTo(3,13);
ResizeTo(w + 6,h + 16);
fConfigView->MoveTo(3, 13);
ResizeTo(w + 6, h + 16);
AddChild(fConfigView);
}
void FilterConfigView::Remove(bool deleteMessage)
void
FilterConfigView::Remove(bool deleteMessage)
{
// remove config view here, because they may not be available
// anymore, if the add-on is unloaded
if (fConfigView && RemoveChild(fConfigView))
{
if (fConfigView && RemoveChild(fConfigView)) {
delete fConfigView;
fConfigView = NULL;
}
unload_add_on(fImage);
if (deleteMessage)
{
if (deleteMessage) {
delete fMessage;
fMessage = NULL;
}
@ -244,41 +255,45 @@ void FilterConfigView::Remove(bool deleteMessage)
}
status_t FilterConfigView::InitCheck()
status_t
FilterConfigView::InitCheck()
{
return fImage;
}
void FilterConfigView::DetachedFromWindow()
void
FilterConfigView::DetachedFromWindow()
{
if (fConfigView == NULL)
return;
if (fConfigView->Archive(fMessage) >= B_OK)
fChain->SetFilter(fIndex,*fMessage,*fEntryRef);
fChain->SetFilter(fIndex, *fMessage, *fEntryRef);
}
void FilterConfigView::AttachedToWindow()
void
FilterConfigView::AttachedToWindow()
{
}
//---------------------------------------------------------------------------------------
// #pragma mark -
ProtocolsConfigView::ProtocolsConfigView(BMailChain *chain,int32 index,BMessage *msg,entry_ref *ref)
: FilterConfigView(chain,index,msg,ref)
ProtocolsConfigView::ProtocolsConfigView(BMailChain *chain, int32 index,
BMessage *msg, entry_ref *ref)
:
FilterConfigView(chain, index, msg, ref)
{
BPopUpMenu *menu = new BPopUpMenu("Choose Protocol");
for (int i = 0; i < 2; i++) {
BPath path;
status_t status = find_directory((i == 0) ? B_USER_ADDONS_DIRECTORY : B_BEOS_ADDONS_DIRECTORY,&path);
if (status != B_OK)
{
status_t status = find_directory(
i == 0 ? B_USER_ADDONS_DIRECTORY : B_BEOS_ADDONS_DIRECTORY, &path);
if (status != B_OK) {
fImage = status;
return;
}
@ -292,51 +307,51 @@ ProtocolsConfigView::ProtocolsConfigView(BMailChain *chain,int32 index,BMessage
BDirectory dir(path.Path());
entry_ref protocolRef;
while (dir.GetNextRef(&protocolRef) == B_OK)
{
while (dir.GetNextRef(&protocolRef) == B_OK) {
char name[B_FILE_NAME_LENGTH];
BEntry entry(&protocolRef);
entry.GetName(name);
BMenuItem *item;
BMessage *msg;
menu->AddItem(item = new BMenuItem(name,msg = new BMessage(kMsgProtocolChanged)));
msg->AddRef("protocol",&protocolRef);
menu->AddItem(item = new BMenuItem(name,
msg = new BMessage(kMsgProtocolChanged)));
msg->AddRef("protocol", &protocolRef);
if (*ref == protocolRef)
item->SetMarked(true);
}
}
fProtocolsMenuField = new BMenuField(BRect(0,0,200,40),NULL,NULL,menu);
fProtocolsMenuField
= new BMenuField(BRect(0, 0, 200, 40), NULL, NULL, menu);
fProtocolsMenuField->ResizeToPreferred();
SetLabel(fProtocolsMenuField);
if (fConfigView)
{
fConfigView->MoveTo(3,21);
ResizeBy(0,8);
}
else
if (fConfigView) {
fConfigView->MoveTo(3, 21);
ResizeBy(0, 8);
} else
fImage = B_OK;
}
void ProtocolsConfigView::AttachedToWindow()
void
ProtocolsConfigView::AttachedToWindow()
{
FilterConfigView::AttachedToWindow();
fProtocolsMenuField->Menu()->SetTargetForItems(this);
}
void ProtocolsConfigView::MessageReceived(BMessage *msg)
void
ProtocolsConfigView::MessageReceived(BMessage *msg)
{
switch (msg->what)
{
switch (msg->what) {
case kMsgProtocolChanged:
{
entry_ref ref;
if (msg->FindRef("protocol",&ref) < B_OK)
if (msg->FindRef("protocol", &ref) < B_OK)
break;
DetachedFromWindow();
@ -344,19 +359,18 @@ void ProtocolsConfigView::MessageReceived(BMessage *msg)
fEntryRef = new entry_ref(ref);
Load(fMessage,fEntryRef);
fChain->SetFilter(fIndex,*fMessage,*fEntryRef);
fChain->SetFilter(fIndex, *fMessage, *fEntryRef);
// resize view
if (LockLooperWithTimeout(1000000L) == B_OK)
{
if (fConfigView)
{
fConfigView->MoveTo(3,21);
ResizeBy(0,8);
if (LockLooperWithTimeout(1000000L) == B_OK) {
if (fConfigView) {
fConfigView->MoveTo(3, 21);
ResizeBy(0, 8);
}
UnlockLooper();
if (CenterContainer *container = dynamic_cast<CenterContainer *>(Parent()))
if (CenterContainer *container
= dynamic_cast<CenterContainer *>(Parent()))
container->Layout();
}
break;
@ -368,39 +382,40 @@ void ProtocolsConfigView::MessageReceived(BMessage *msg)
}
//---------------------------------------------------------------------------------------
// #pragma mark -
#include <stdio.h>
class DragListView : public BListView
{
public:
DragListView(BRect frame,const char *name,list_view_type type = B_SINGLE_SELECTION_LIST,
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,BMessage *itemMovedMsg = NULL)
: BListView(frame,name,type,resizingMode),
class DragListView : public BListView {
public:
DragListView(BRect frame, const char *name,
list_view_type type = B_SINGLE_SELECTION_LIST,
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
BMessage *itemMovedMsg = NULL)
:
BListView(frame, name, type, resizingMode),
fDragging(false),
fItemMovedMessage(itemMovedMsg)
{
}
virtual bool InitiateDrag(BPoint point,int32 index,bool wasSelected)
virtual bool InitiateDrag(BPoint point, int32 index, bool wasSelected)
{
BRect frame(ItemFrame(index));
BBitmap *bitmap = new BBitmap(frame.OffsetToCopy(B_ORIGIN),B_RGBA32,true);
BView *view = new BView(bitmap->Bounds(),NULL,0,0);
BBitmap *bitmap = new BBitmap(frame.OffsetToCopy(B_ORIGIN), B_RGBA32,
true);
BView *view = new BView(bitmap->Bounds(), NULL, 0, 0);
bitmap->AddChild(view);
if (view->LockLooper())
{
if (view->LockLooper()) {
BListItem *item = ItemAt(index);
bool selected = item->IsSelected();
view->SetLowColor(225,225,225,128);
view->SetLowColor(225, 225, 225, 128);
view->FillRect(view->Bounds());
if (selected)
item->Deselect();
ItemAt(index)->DrawItem(view,view->Bounds(),true);
ItemAt(index)->DrawItem(view, view->Bounds(), true);
if (selected)
item->Select();
@ -411,8 +426,8 @@ class DragListView : public BListView
fDragging = true;
BMessage drag(kMsgItemDragged);
drag.AddInt32("index",index);
DragMessage(&drag,bitmap,B_OP_ALPHA,point - frame.LeftTop(),this);
drag.AddInt32("index", index);
DragMessage(&drag, bitmap, B_OP_ALPHA, point - frame.LeftTop(), this);
return true;
}
@ -436,11 +451,12 @@ class DragListView : public BListView
PopState();
}
virtual void MouseMoved(BPoint point,uint32 transit,const BMessage *msg)
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *msg)
{
BListView::MouseMoved(point,transit,msg);
BListView::MouseMoved(point, transit, msg);
if ((transit != B_ENTERED_VIEW && transit != B_INSIDE_VIEW) || !fDragging)
if ((transit != B_ENTERED_VIEW && transit != B_INSIDE_VIEW)
|| !fDragging)
return;
int32 target = IndexOf(point);
@ -466,8 +482,7 @@ class DragListView : public BListView
virtual void MouseUp(BPoint point)
{
if (fDragging)
{
if (fDragging) {
fDragging = false;
if (fLastDragTarget != -1)
DrawDragTargetIndicator(fLastDragTarget);
@ -477,8 +492,7 @@ class DragListView : public BListView
virtual void MessageReceived(BMessage *msg)
{
switch(msg->what)
{
switch (msg->what) {
case kMsgItemDragged:
{
int32 source = msg->FindInt32("index");
@ -490,12 +504,10 @@ class DragListView : public BListView
if (to == -1)
to = CountItems() - 1;
if (source != to)
{
if (source != to) {
MoveItem(source,to);
if (fItemMovedMessage != NULL)
{
if (fItemMovedMessage != NULL) {
BMessage msg(fItemMovedMessage->what);
msg.AddInt32("from",source);
msg.AddInt32("to",to);
@ -508,14 +520,15 @@ class DragListView : public BListView
BListView::MessageReceived(msg);
}
private:
private:
bool fDragging;
int32 fLastDragTarget,fDragIndex;
BMessage *fItemMovedMessage;
};
void GetPrettyDescriptiveName(BPath &path, char *name, BMessage *msg = NULL)
void
GetPrettyDescriptiveName(BPath &path, char *name, BMessage *msg = NULL)
{
strcpy(name, path.Leaf());
@ -536,8 +549,9 @@ void GetPrettyDescriptiveName(BPath &path, char *name, BMessage *msg = NULL)
// #pragma mark -
FiltersConfigView::FiltersConfigView(BRect rect,Account *account)
: BBox(rect),
FiltersConfigView::FiltersConfigView(BRect rect, Account *account)
:
BBox(rect),
fAccount(account),
fFilterView(NULL)
{
@ -545,58 +559,65 @@ FiltersConfigView::FiltersConfigView(BRect rect,Account *account)
BMenuItem *item;
BMessage *msg;
if ((fChain = fAccount->Inbound()))
{
menu->AddItem(item = new BMenuItem(TR ("Incoming mail filters"),msg = new BMessage(kMsgChainSelected)));
msg->AddPointer("chain",fChain);
if ((fChain = fAccount->Inbound())) {
menu->AddItem(item = new BMenuItem(TR("Incoming mail filters"),
msg = new BMessage(kMsgChainSelected)));
msg->AddPointer("chain", fChain);
item->SetMarked(true);
}
if (BMailChain *chain = fAccount->Outbound())
{
menu->AddItem(item = new BMenuItem(TR ("Outgoing mail filters"),msg = new BMessage(kMsgChainSelected)));
msg->AddPointer("chain",chain);
if (fChain == NULL)
{
if (BMailChain *chain = fAccount->Outbound()) {
menu->AddItem(item = new BMenuItem(TR("Outgoing mail filters"),
msg = new BMessage(kMsgChainSelected)));
msg->AddPointer("chain", chain);
if (fChain == NULL) {
item->SetMarked(true);
fChain = chain;
}
}
fChainsField = new BMenuField(BRect(0,0,200,40),NULL,NULL,menu);
fChainsField = new BMenuField(BRect(0, 0, 200, 40), NULL, NULL, menu);
fChainsField->ResizeToPreferred();
SetLabel(fChainsField);
// determine font height
font_height fontHeight;
fChainsField->GetFontHeight(&fontHeight);
int32 height = (int32)(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 5;
int32 height = (int32)(fontHeight.ascent + fontHeight.descent
+ fontHeight.leading) + 5;
rect = Bounds().InsetByCopy(10,10);
rect = Bounds().InsetByCopy(10, 10);
rect.top += 18;
rect.right -= B_V_SCROLL_BAR_WIDTH;
rect.bottom = rect.top + 4 * height + 2;
fListView = new DragListView(rect,NULL,B_SINGLE_SELECTION_LIST,B_FOLLOW_ALL,new BMessage(kMsgFilterMoved));
AddChild(new BScrollView(NULL,fListView,B_FOLLOW_ALL,0,false,true));
fListView = new DragListView(rect, NULL, B_SINGLE_SELECTION_LIST,
B_FOLLOW_ALL, new BMessage(kMsgFilterMoved));
AddChild(new BScrollView(NULL, fListView, B_FOLLOW_ALL, 0, false, true));
rect.right += B_V_SCROLL_BAR_WIDTH;
// fListView->Select(gSettings.formats.IndexOf(format));
fListView->SetSelectionMessage(new BMessage(kMsgFilterSelected));
rect.top = rect.bottom + 8; rect.bottom = rect.top + height;
BRect sizeRect = rect; sizeRect.right = sizeRect.left + 30 + fChainsField->StringWidth(TR ("Add filter"));
rect.top = rect.bottom + 8;
rect.bottom = rect.top + height;
BRect sizeRect = rect;
sizeRect.right = sizeRect.left + 30
+ fChainsField->StringWidth(TR("Add filter"));
menu = new BPopUpMenu(TR ("Add filter"));
menu = new BPopUpMenu(TR("Add filter"));
menu->SetRadioMode(false);
fAddField = new BMenuField(rect,NULL,NULL,menu);
fAddField = new BMenuField(rect, NULL, NULL, menu);
fAddField->ResizeToPreferred();
AddChild(fAddField);
sizeRect.left = sizeRect.right + 5; sizeRect.right = sizeRect.left + 30 + fChainsField->StringWidth(TR ("Remove"));
sizeRect.left = sizeRect.right + 5;
sizeRect.right = sizeRect.left + 30
+ fChainsField->StringWidth(TR("Remove"));
sizeRect.top--;
AddChild(fRemoveButton = new BButton(sizeRect,NULL,TR ("Remove"),new BMessage(kMsgRemoveFilter),B_FOLLOW_BOTTOM));
AddChild(fRemoveButton = new BButton(sizeRect, NULL, TR("Remove"),
new BMessage(kMsgRemoveFilter), B_FOLLOW_BOTTOM));
ResizeTo(Bounds().Width(),sizeRect.bottom + 10);
ResizeTo(Bounds().Width(), sizeRect.bottom + 10);
SetTo(fChain);
}
@ -606,18 +627,19 @@ FiltersConfigView::~FiltersConfigView()
}
void FiltersConfigView::SelectFilter(int32 index)
void
FiltersConfigView::SelectFilter(int32 index)
{
if (Parent())
Parent()->Hide();
// remove old config view
if (fFilterView)
{
if (fFilterView) {
Parent()->RemoveChild(fFilterView);
// update the name in the list
BStringItem *item = (BStringItem *)fListView->ItemAt(fFilterView->fIndex - fFirst);
BStringItem *item = (BStringItem *)fListView->ItemAt(
fFilterView->fIndex - fFirst);
char name[B_FILE_NAME_LENGTH];
BPath path(fFilterView->fEntryRef);
@ -628,24 +650,19 @@ void FiltersConfigView::SelectFilter(int32 index)
fFilterView = NULL;
}
if (index >= 0)
{
if (index >= 0) {
// add new config view
BMessage *msg = new BMessage();
entry_ref *ref = new entry_ref();
if (fChain->GetFilter(index + fFirst,msg,ref) >= B_OK && Parent())
{
fFilterView = new FilterConfigView(fChain,index + fFirst,msg,ref);
if (fChain->GetFilter(index + fFirst, msg, ref) >= B_OK && Parent()) {
fFilterView = new FilterConfigView(fChain,index + fFirst, msg, ref);
if (fFilterView->InitCheck() >= B_OK)
Parent()->AddChild(fFilterView);
else
{
else {
delete fFilterView;
fFilterView = NULL;
}
}
else
{
} else {
delete msg;
delete ref;
}
@ -660,34 +677,30 @@ void FiltersConfigView::SelectFilter(int32 index)
}
void FiltersConfigView::SetTo(BMailChain *chain)
void
FiltersConfigView::SetTo(BMailChain *chain)
{
// remove the filter config view
SelectFilter(-1);
for (int32 i = fListView->CountItems();i-- > 0;)
{
for (int32 i = fListView->CountItems(); i-- > 0;) {
BStringItem *item = (BStringItem *)fListView->RemoveItem(i);
delete item;
}
if (chain->ChainDirection() == inbound)
{
if (chain->ChainDirection() == inbound) {
fFirst = 2; // skip protocol (e.g. POP3), and Parser
fLast = 2; // skip Notifier, and Folder
}
else
{
} else {
fFirst = 1; // skip Producer
fLast = 1; // skip protocol (e.g. SMTP)
}
int32 last = chain->CountFilters() - fLast;
for (int32 i = fFirst;i < last;i++)
{
for (int32 i = fFirst; i < last; i++) {
BMessage msg;
entry_ref ref;
if (chain->GetFilter(i,&msg,&ref) == B_OK)
{
if (chain->GetFilter(i, &msg, &ref) == B_OK) {
char name[B_FILE_NAME_LENGTH];
BPath addon(&ref);
GetPrettyDescriptiveName(addon, name, &msg);
@ -701,15 +714,15 @@ void FiltersConfigView::SetTo(BMailChain *chain)
// remove old filter items
BMenu *menu = fAddField->Menu();
for (int32 i = menu->CountItems();i-- > 0;)
{
for (int32 i = menu->CountItems(); i-- > 0;) {
BMenuItem *item = menu->RemoveItem(i);
delete item;
}
for (int i = 0; i < 2; i++) {
BPath path;
status_t status = find_directory((i == 0) ? B_USER_ADDONS_DIRECTORY : B_BEOS_ADDONS_DIRECTORY,&path);
status_t status = find_directory(
i == 0 ? B_USER_ADDONS_DIRECTORY : B_BEOS_ADDONS_DIRECTORY, &path);
if (status != B_OK)
return;
@ -722,23 +735,24 @@ void FiltersConfigView::SetTo(BMailChain *chain)
BDirectory dir(path.Path());
entry_ref ref;
while (dir.GetNextRef(&ref) == B_OK)
{
while (dir.GetNextRef(&ref) == B_OK) {
char name[B_FILE_NAME_LENGTH];
BPath path(&ref);
GetPrettyDescriptiveName(path, name);
BMenuItem *item;
BMessage *msg;
menu->AddItem(item = new BMenuItem(name,msg = new BMessage(kMsgAddFilter)));
msg->AddRef("filter",&ref);
menu->AddItem(item = new BMenuItem(name,
msg = new BMessage(kMsgAddFilter)));
msg->AddRef("filter", &ref);
}
}
menu->SetTargetForItems(this);
}
void FiltersConfigView::AttachedToWindow()
void
FiltersConfigView::AttachedToWindow()
{
fChainsField->Menu()->SetTargetForItems(this);
fListView->SetTarget(this);
@ -747,14 +761,14 @@ void FiltersConfigView::AttachedToWindow()
}
void FiltersConfigView::MessageReceived(BMessage *msg)
void
FiltersConfigView::MessageReceived(BMessage *msg)
{
switch (msg->what)
{
switch (msg->what) {
case kMsgChainSelected:
{
BMailChain *chain;
if (msg->FindPointer("chain",(void **)&chain) < B_OK)
if (msg->FindPointer("chain", (void **)&chain) < B_OK)
break;
SetTo(chain);
@ -763,12 +777,12 @@ void FiltersConfigView::MessageReceived(BMessage *msg)
case kMsgAddFilter:
{
entry_ref ref;
if (msg->FindRef("filter",&ref) < B_OK)
if (msg->FindRef("filter", &ref) < B_OK)
break;
BMessage msg;
if (fChain->AddFilter(fChain->CountFilters() - fLast, msg, ref) >= B_OK)
{
if (fChain->AddFilter(fChain->CountFilters() - fLast, msg, ref)
>= B_OK) {
char name[B_FILE_NAME_LENGTH];
BPath path(&ref);
GetPrettyDescriptiveName(path, name, &msg);
@ -783,8 +797,8 @@ void FiltersConfigView::MessageReceived(BMessage *msg)
break;
SelectFilter(-1);
if (BStringItem *item = (BStringItem *)fListView->RemoveItem(index))
{
if (BStringItem *item
= (BStringItem *)fListView->RemoveItem(index)) {
fChain->RemoveFilter(index + fFirst);
delete item;
}
@ -811,39 +825,36 @@ void FiltersConfigView::MessageReceived(BMessage *msg)
entry_ref ref;
BMessage settings;
if (fChain->GetFilter(from,&settings,&ref) == B_OK)
{
if (fChain->GetFilter(from, &settings, &ref) == B_OK) {
// disable filter view saving
if (fFilterView && fFilterView->fIndex == from)
fFilterView->fIndex = -1;
fChain->RemoveFilter(from);
if (fChain->AddFilter(to,settings,ref) < B_OK)
{
(new BAlert("E-mail",TR (
"The filter could not be moved. Deleting filter."
),TR("OK")))->Go();
if (fChain->AddFilter(to, settings, ref) < B_OK) {
(new BAlert("E-mail",
TR("The filter could not be moved. Deleting filter."),
TR("OK")))->Go();
// the filter view belongs to the moved filter
if (fFilterView && fFilterView->fIndex == -1)
SelectFilter(-1);
fListView->RemoveItem(msg->FindInt32("to"));
}
else if (fFilterView)
{
} else if (fFilterView) {
int32 index = fFilterView->fIndex;
if (index == -1)
if (index == -1) {
// the view belongs to the moved filter
fFilterView->fIndex = to;
else if (index > from && index < to)
} else if (index > from && index < to) {
// the view belongs to another filter (between the
// 'from' & 'to' positions) - all others can keep
// their index value
fFilterView->fIndex--;
}
}
}
break;
}
default:
@ -851,4 +862,3 @@ void FiltersConfigView::MessageReceived(BMessage *msg)
break;
}
}

View File

@ -1,12 +1,14 @@
/*
* Copyright 2007-2008, Haiku, Inc. All rights reserved.
* Copyright 2007-2010, Haiku, Inc. All rights reserved.
* Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
*
* Distributed under the terms of the MIT License.
*/
//! main E-Mail config window
#include "ConfigWindow.h"
#include "CenterContainer.h"
#include "Account.h"
@ -244,12 +246,12 @@ class AboutTextView : public BTextView
};
//--------------------------------------------------------------------------------------
// #pragma mark -
ConfigWindow::ConfigWindow()
: BWindow(BRect(100.0, 100.0, 580.0, 540.0), "E-mail", B_TITLED_WINDOW,
:
BWindow(BRect(100.0, 100.0, 580.0, 540.0), "E-mail", B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE),
fLastSelectedAccount(NULL),
fSaveSettings(false)
@ -257,43 +259,46 @@ ConfigWindow::ConfigWindow()
// create controls
BRect rect(Bounds());
BView *top = new BView(rect,NULL,B_FOLLOW_ALL,0);
BView *top = new BView(rect, NULL, B_FOLLOW_ALL, 0);
top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(top);
// determine font height
font_height fontHeight;
top->GetFontHeight(&fontHeight);
int32 height = (int32)(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 5;
int32 height = (int32)(fontHeight.ascent + fontHeight.descent
+ fontHeight.leading) + 5;
rect.InsetBy(5,5); rect.bottom -= 11 + height;
BTabView *tabView = new BTabView(rect,NULL);
rect.InsetBy(5, 5); rect.bottom -= 11 + height;
BTabView *tabView = new BTabView(rect, NULL);
BView *view;
rect = tabView->Bounds(); rect.bottom -= tabView->TabHeight() + 4;
tabView->AddTab(view = new BView(rect,NULL,B_FOLLOW_ALL,0));
tabView->TabAt(0)->SetLabel(TR ("Accounts"));
rect = tabView->Bounds();
rect.bottom -= tabView->TabHeight() + 4;
tabView->AddTab(view = new BView(rect, NULL, B_FOLLOW_ALL, 0));
tabView->TabAt(0)->SetLabel(TR("Accounts"));
view->SetViewColor(top->ViewColor());
// accounts listview
rect = view->Bounds().InsetByCopy(8,8);
rect = view->Bounds().InsetByCopy(8, 8);
rect.right = 140 - B_V_SCROLL_BAR_WIDTH;
rect.bottom -= height + 12;
fAccountsListView = new AccountsListView(rect);
view->AddChild(new BScrollView(NULL,fAccountsListView,B_FOLLOW_ALL,0,false,true));
view->AddChild(new BScrollView(NULL, fAccountsListView, B_FOLLOW_ALL, 0,
false, true));
rect.right += B_V_SCROLL_BAR_WIDTH;
rect.top = rect.bottom + 8; rect.bottom = rect.top + height;
BRect sizeRect = rect;
sizeRect.right = sizeRect.left + 30 + view->StringWidth(TR ("Add"));
view->AddChild(new BButton(sizeRect,NULL,TR ("Add"),
new BMessage(kMsgAddAccount),B_FOLLOW_BOTTOM));
sizeRect.right = sizeRect.left + 30 + view->StringWidth(TR("Add"));
view->AddChild(new BButton(sizeRect, NULL, TR("Add"),
new BMessage(kMsgAddAccount), B_FOLLOW_BOTTOM));
sizeRect.left = sizeRect.right+3;
sizeRect.right = sizeRect.left + 30 + view->StringWidth(TR ("Remove"));
view->AddChild(fRemoveButton = new BButton(sizeRect,NULL,TR ("Remove"),
new BMessage(kMsgRemoveAccount),B_FOLLOW_BOTTOM));
sizeRect.right = sizeRect.left + 30 + view->StringWidth(TR("Remove"));
view->AddChild(fRemoveButton = new BButton(sizeRect, NULL, TR("Remove"),
new BMessage(kMsgRemoveAccount), B_FOLLOW_BOTTOM));
// accounts config view
rect = view->Bounds();
@ -305,92 +310,97 @@ ConfigWindow::ConfigWindow()
// general settings
rect = tabView->Bounds(); rect.bottom -= tabView->TabHeight() + 4;
rect = tabView->Bounds();
rect.bottom -= tabView->TabHeight() + 4;
tabView->AddTab(view = new CenterContainer(rect));
tabView->TabAt(1)->SetLabel(TR ("Settings"));
tabView->TabAt(1)->SetLabel(TR("Settings"));
rect = view->Bounds().InsetByCopy(8,8);
rect.right -= 1; rect.bottom = rect.top + height * 5 + 15;
rect = view->Bounds().InsetByCopy(8, 8);
rect.right -= 1;
rect.bottom = rect.top + height * 5 + 15;
BBox *box = new BBox(rect);
box->SetLabel(TR ("Mail checking"));
box->SetLabel(TR("Mail checking"));
view->AddChild(box);
rect = box->Bounds().InsetByCopy(8,8);
rect.top += 7; rect.bottom = rect.top + height + 5;
BRect tile = rect.OffsetByCopy(0,1);
int32 labelWidth = (int32)view->StringWidth(TR ("Check every"))+6;
rect = box->Bounds().InsetByCopy(8, 8);
rect.top += 7;
rect.bottom = rect.top + height + 5;
BRect tile = rect.OffsetByCopy(0, 1);
int32 labelWidth = (int32)view->StringWidth(TR("Check every")) + 6;
tile.right = 80 + labelWidth;
fIntervalControl = new BTextControl(tile,"time",TR ("Check every"),
NULL,NULL);
fIntervalControl = new BTextControl(tile, "time", TR("Check every"), NULL,
NULL);
fIntervalControl->SetDivider(labelWidth);
box->AddChild(fIntervalControl);
BPopUpMenu *frequencyPopUp = new BPopUpMenu(B_EMPTY_STRING);
const char *frequencyStrings[] = {
TR ("never"),
TR ("minutes"),
TR ("hours"),
TR ("days")};
TR("never"),
TR("minutes"),
TR("hours"),
TR("days")};
BMenuItem *item;
for (int32 i = 0;i < 4;i++)
{
frequencyPopUp->AddItem(item = new BMenuItem(frequencyStrings[i],new BMessage(kMsgIntervalUnitChanged)));
for (int32 i = 0; i < 4; i++) {
frequencyPopUp->AddItem(item = new BMenuItem(frequencyStrings[i],
new BMessage(kMsgIntervalUnitChanged)));
if (i == 1)
item->SetMarked(true);
}
tile.left = tile.right + 5; tile.right = rect.right;
tile.left = tile.right + 5;
tile.right = rect.right;
tile.OffsetBy(0,-1);
fIntervalUnitField = new BMenuField(tile,"frequency", B_EMPTY_STRING, frequencyPopUp);
fIntervalUnitField = new BMenuField(tile, "frequency", B_EMPTY_STRING,
frequencyPopUp);
fIntervalUnitField->SetDivider(0.0);
box->AddChild(fIntervalUnitField);
rect.OffsetBy(0,height + 9); rect.bottom -= 2;
fPPPActiveCheckBox = new BCheckBox(rect,"ppp active",
TR ("Only when dial-up is connected"), NULL);
rect.OffsetBy(0,height + 9);
rect.bottom -= 2;
fPPPActiveCheckBox = new BCheckBox(rect, "ppp active",
TR("Only when dial-up is connected"), NULL);
box->AddChild(fPPPActiveCheckBox);
rect.OffsetBy(0,height + 9); rect.bottom -= 2;
fPPPActiveSendCheckBox = new BCheckBox(rect,"ppp activesend",
TR ("Schedule outgoing mail when dial-up is disconnected"), NULL);
rect.OffsetBy(0,height + 9);
rect.bottom -= 2;
fPPPActiveSendCheckBox = new BCheckBox(rect, "ppp activesend",
TR("Schedule outgoing mail when dial-up is disconnected"), NULL);
box->AddChild(fPPPActiveSendCheckBox);
// Miscellaneous settings box
rect = box->Frame(); rect.bottom = rect.top + 3*height + 30;
rect = box->Frame(); rect.bottom = rect.top + 3 * height + 30;
box = new BBox(rect);
box->SetLabel(TR ("Miscellaneous"));
box->SetLabel(TR("Miscellaneous"));
view->AddChild(box);
BPopUpMenu *statusPopUp = new BPopUpMenu(B_EMPTY_STRING);
const char *statusModes[] = {
TR ("Never"),
TR ("While sending"),
TR ("While sending and receiving"),
TR ("Always")};
TR("Never"),
TR("While sending"),
TR("While sending and receiving"),
TR("Always")};
BMessage *msg;
for (int32 i = 0;i < 4;i++)
{
statusPopUp->AddItem(item = new BMenuItem(statusModes[i],msg = new BMessage(kMsgShowStatusWindowChanged)));
msg->AddInt32("ShowStatusWindow",i);
for (int32 i = 0; i < 4; i++) {
statusPopUp->AddItem(item = new BMenuItem(statusModes[i],
msg = new BMessage(kMsgShowStatusWindowChanged)));
msg->AddInt32("ShowStatusWindow", i);
if (i == 0)
item->SetMarked(true);
}
rect = box->Bounds().InsetByCopy(8,8);
rect.top += 7;
rect.bottom = rect.top + height + 5;
labelWidth = (int32)view->StringWidth(
TR ("Show connection status window:")) + 8;
fStatusModeField = new BMenuField(rect,"show status",
TR ("Show connection status window:"),
statusPopUp);
labelWidth
= (int32)view->StringWidth(TR("Show connection status window:")) + 8;
fStatusModeField = new BMenuField(rect, "show status",
TR("Show connection status window:"), statusPopUp);
fStatusModeField->SetDivider(labelWidth);
box->AddChild(fStatusModeField);
rect = fStatusModeField->Frame();;
rect.OffsetBy(0, rect.Height() + 10);
BButton *button = new BButton(rect,B_EMPTY_STRING,
TR ("Edit mailbox menu…"),
msg = new BMessage(B_REFS_RECEIVED));
BButton *button = new BButton(rect, B_EMPTY_STRING,
TR("Edit mailbox menu…"), msg = new BMessage(B_REFS_RECEIVED));
button->ResizeToPreferred();
box->AddChild(button);
button->SetTarget(BMessenger("application/x-vnd.Be-TRAK"));
@ -409,8 +419,8 @@ ConfigWindow::ConfigWindow()
rect = button->Frame();
rect.OffsetBy(rect.Width() + 30,0);
fAutoStartCheckBox = new BCheckBox(rect,"start daemon",
TR ("Start mail services on startup"),NULL);
fAutoStartCheckBox = new BCheckBox(rect, "start daemon",
TR("Start mail services on startup"), NULL);
fAutoStartCheckBox->ResizeToPreferred();
box->AddChild(fAutoStartCheckBox);
@ -419,20 +429,19 @@ ConfigWindow::ConfigWindow()
top->AddChild(tabView);
rect = tabView->Frame();
rect.top = rect.bottom + 5; rect.bottom = rect.top + height + 5;
BButton *saveButton = new BButton(rect,"apply",
TR ("Apply"),
rect.top = rect.bottom + 5;
rect.bottom = rect.top + height + 5;
BButton *saveButton = new BButton(rect, "apply", TR("Apply"),
new BMessage(kMsgSaveSettings));
float w,h;
saveButton->GetPreferredSize(&w,&h);
saveButton->ResizeTo(w,h);
saveButton->GetPreferredSize(&w, &h);
saveButton->ResizeTo(w, h);
saveButton->MoveTo(rect.right - w, rect.top);
top->AddChild(saveButton);
BButton *revertButton = new BButton(rect,"revert",
TR ("Revert"),
BButton *revertButton = new BButton(rect, "revert", TR("Revert"),
new BMessage(kMsgRevertSettings));
revertButton->GetPreferredSize(&w,&h);
revertButton->GetPreferredSize(&w, &h);
revertButton->ResizeTo(w,h);
revertButton->MoveTo(saveButton->Frame().left - 25 - w, rect.top);
top->AddChild(revertButton);
@ -457,9 +466,11 @@ ConfigWindow::MakeHowToView()
BResources *resources = BApplication::AppResources();
if (resources) {
size_t length;
char *buffer = (char *)resources->FindResource(B_LARGE_ICON_TYPE, 101, &length);
char *buffer = (char *)resources->FindResource(B_LARGE_ICON_TYPE, 101,
&length);
if (buffer) {
BBitmap *bitmap = new (nothrow) BBitmap(BRect(0, 0, 63, 63), B_CMAP8);
BBitmap *bitmap = new (nothrow) BBitmap(BRect(0, 0, 63, 63),
B_CMAP8);
if (bitmap && bitmap->InitCheck() == B_OK) {
// copy and enlarge a 32x32 8-bit bitmap
char *bits = (char *)bitmap->Bits();
@ -481,7 +492,8 @@ ConfigWindow::MakeHowToView()
BFile appFile(&info.ref, B_READ_ONLY);
BAppFileInfo appFileInfo(&appFile);
if (appFileInfo.InitCheck() == B_OK) {
BBitmap *bitmap = new (nothrow) BBitmap(BRect(0, 0, 63, 63), B_RGBA32);
BBitmap *bitmap = new (nothrow) BBitmap(BRect(0, 0, 63, 63),
B_RGBA32);
if (appFileInfo.GetIcon(bitmap, B_LARGE_ICON) == B_OK) {
fConfigView->AddChild(new BitmapView(bitmap));
} else
@ -491,14 +503,13 @@ ConfigWindow::MakeHowToView()
#endif // HAIKU_TARGET_PLATFORM_HAIKU
BRect rect = fConfigView->Bounds();
BTextView *text = new BTextView(rect, NULL, rect, B_FOLLOW_NONE, B_WILL_DRAW);
BTextView *text = new BTextView(rect, NULL, rect, B_FOLLOW_NONE,
B_WILL_DRAW);
text->SetViewColor(fConfigView->Parent()->ViewColor());
text->SetAlignment(B_ALIGN_CENTER);
text->SetText(
TR ("\n\nCreate a new account with the Add button.\n\n"
text->SetText(TR("\n\nCreate a new account with the Add button.\n\n"
"Remove an account with the Remove button on the selected item.\n\n"
"Select an item in the list to change its settings."
));
"Select an item in the list to change its settings."));
rect = text->Bounds();
text->ResizeTo(rect.Width(), text->TextHeight(0, 42));
text->SetTextRect(rect);
@ -525,8 +536,8 @@ ConfigWindow::LoadSettings()
// move own window
MoveTo(settings.ConfigWindowFrame().LeftTop());
} else {
fprintf(stderr, TR("Error retrieving general settings: %s\n"
), strerror(status));
fprintf(stderr, TR("Error retrieving general settings: %s\n"),
strerror(status));
}
BScreen screen(this);
@ -555,7 +566,8 @@ ConfigWindow::SaveSettings()
float interval;
sscanf(fIntervalControl->Text(),"%f",&interval);
float multiplier = 0;
switch (fIntervalUnitField->Menu()->IndexOf(fIntervalUnitField->Menu()->FindMarked())) {
switch (fIntervalUnitField->Menu()->IndexOf(
fIntervalUnitField->Menu()->FindMarked())) {
case 1: // minutes
multiplier = 60;
break;
@ -572,12 +584,16 @@ ConfigWindow::SaveSettings()
BMailSettings settings;
if (fSaveSettings) {
settings.SetAutoCheckInterval(time * 1e6);
settings.SetCheckOnlyIfPPPUp(fPPPActiveCheckBox->Value() == B_CONTROL_ON);
settings.SetSendOnlyIfPPPUp(fPPPActiveSendCheckBox->Value() == B_CONTROL_ON);
settings.SetDaemonAutoStarts(fAutoStartCheckBox->Value() == B_CONTROL_ON);
settings.SetCheckOnlyIfPPPUp(fPPPActiveCheckBox->Value()
== B_CONTROL_ON);
settings.SetSendOnlyIfPPPUp(fPPPActiveSendCheckBox->Value()
== B_CONTROL_ON);
settings.SetDaemonAutoStarts(fAutoStartCheckBox->Value()
== B_CONTROL_ON);
// status mode (alway, fetching/retrieving, ...)
int32 index = fStatusModeField->Menu()->IndexOf(fStatusModeField->Menu()->FindMarked());
int32 index = fStatusModeField->Menu()->IndexOf(
fStatusModeField->Menu()->FindMarked());
settings.SetShowStatusWindow(index);
} else {
@ -639,10 +655,10 @@ ConfigWindow::MessageReceived(BMessage *msg)
case kMsgAddAccount:
{
frame = Frame();
autoConfigRect.OffsetTo(frame.left + (frame.Width() - autoConfigRect.Width()) / 2,
autoConfigRect.OffsetTo(
frame.left + (frame.Width() - autoConfigRect.Width()) / 2,
frame.top + (frame.Width() - autoConfigRect.Height()) / 2);
autoConfigWindow = new AutoConfigWindow(autoConfigRect,
this);
autoConfigWindow = new AutoConfigWindow(autoConfigRect, this);
autoConfigWindow->Show();
break;
}
@ -650,8 +666,9 @@ ConfigWindow::MessageReceived(BMessage *msg)
{
int32 index = fAccountsListView->CurrentSelection();
if (index >= 0) {
AccountItem *item = (AccountItem *)fAccountsListView->ItemAt(index);
if (item) {
AccountItem *item = (AccountItem *)fAccountsListView->ItemAt(
index);
if (item != NULL) {
item->account->Remove(item->type);
MakeHowToView();
}
@ -731,7 +748,8 @@ ConfigWindow::SetToGeneralSettings(BMailSettings *settings)
fAutoStartCheckBox->SetValue(settings->DaemonAutoStarts());
if (BMenuItem *item = fStatusModeField->Menu()->ItemAt(settings->ShowStatusWindow()))
if (BMenuItem *item
= fStatusModeField->Menu()->ItemAt(settings->ShowStatusWindow()))
item->SetMarked(true);
return B_OK;
@ -748,14 +766,13 @@ ConfigWindow::RevertToLastSettings()
settings.SetStatusWindowLook(settings.StatusWindowLook());
status_t status = SetToGeneralSettings(&settings);
if (status != B_OK)
{
if (status != B_OK) {
char text[256];
sprintf(text,
TR ("\nThe general settings couldn't be reverted.\n\n"
sprintf(text, TR("\nThe general settings couldn't be reverted.\n\n"
"Error retrieving general settings:\n%s\n"),
strerror(status));
(new BAlert("Error",text,"OK",NULL,NULL,B_WIDTH_AS_USUAL,B_WARNING_ALERT))->Go();
(new BAlert("Error", text, "OK", NULL, NULL, B_WIDTH_AS_USUAL,
B_WARNING_ALERT))->Go();
}
// revert account data
@ -769,4 +786,3 @@ ConfigWindow::RevertToLastSettings()
if (fConfigView->CountChildren() == 0)
MakeHowToView();
}