* 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" #include "Account.h"
@ -30,9 +32,11 @@
#include <MDRLanguage.h> #include <MDRLanguage.h>
#undef TR_CONTEXT #undef TR_CONTEXT
#define TR_CONTEXT "Account" #define TR_CONTEXT "Account"
static BList gAccounts; static BList gAccounts;
static BListView *gListView; static BListView *gListView;
static BView *gConfigView; static BView *gConfigView;
@ -44,12 +48,12 @@ const char *kInboundProtocolAddOnPath = "mail_daemon/inbound_protocols";
const char *kOutboundProtocolAddOnPath = "mail_daemon/outbound_protocols"; const char *kOutboundProtocolAddOnPath = "mail_daemon/outbound_protocols";
//---------------------------------------------------------------------------------------
// #pragma mark - // #pragma mark -
AccountItem::AccountItem(const char *label,Account *account,int32 type) AccountItem::AccountItem(const char *label, Account *account, int32 type)
: BStringItem(label), :
BStringItem(label),
account(account), account(account),
type(type) 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) if (type == ACCOUNT_ITEM)
font = be_bold_font; 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(); owner->PushState();
if (type == ACCOUNT_ITEM) if (type == ACCOUNT_ITEM) {
{
// BFont font; // BFont font;
// owner->GetFont(&font); // owner->GetFont(&font);
// font.SetFace(B_BOLD_FACE); // font.SetFace(B_BOLD_FACE);
@ -85,12 +90,12 @@ void AccountItem::DrawItem(BView *owner, BRect rect, bool complete)
} }
//---------------------------------------------------------------------------------------
// #pragma mark - // #pragma mark -
Account::Account(BMailChain *inbound,BMailChain *outbound) Account::Account(BMailChain *inbound, BMailChain *outbound)
: fInbound(inbound), :
fInbound(inbound),
fOutbound(outbound), fOutbound(outbound),
fAccountItem(NULL), fAccountItem(NULL),
@ -105,32 +110,34 @@ Account::Account(BMailChain *inbound,BMailChain *outbound)
label << fSettings->Name(); label << fSettings->Name();
else else
label << TR("Unnamed"); 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); fInboundItem = new AccountItem(TR(" · Incoming"), this, INBOUND_ITEM);
fOutboundItem = new AccountItem(TR (" · Outgoing"),this,OUTBOUND_ITEM); fOutboundItem = new AccountItem(TR(" · Outgoing"), this, OUTBOUND_ITEM);
fFilterItem = new AccountItem(TR (" · E-mail filters"),this,FILTER_ITEM); fFilterItem = new AccountItem(TR(" · E-mail filters"), this, FILTER_ITEM);
} }
Account::~Account() Account::~Account()
{ {
if (gListView) if (gListView) {
{
gListView->RemoveItem(fAccountItem); gListView->RemoveItem(fAccountItem);
gListView->RemoveItem(fInboundItem); gListView->RemoveItem(fInboundItem);
gListView->RemoveItem(fOutboundItem); gListView->RemoveItem(fOutboundItem);
gListView->RemoveItem(fFilterItem); gListView->RemoveItem(fFilterItem);
} }
delete fAccountItem; delete fFilterItem; delete fAccountItem;
delete fInboundItem; delete fOutboundItem; delete fFilterItem;
delete fInboundItem;
delete fOutboundItem;
delete fInbound; delete fInbound;
delete fOutbound; delete fOutbound;
} }
void Account::AddToListView() void
Account::AddToListView()
{ {
if (!gListView) if (!gListView)
return; return;
@ -148,22 +155,23 @@ void Account::AddToListView()
} }
void Account::SetName(const char *name) void
Account::SetName(const char *name)
{ {
if (fInbound) if (fInbound)
fInbound->SetName(name); fInbound->SetName(name);
if (fOutbound) if (fOutbound)
fOutbound->SetName(name); fOutbound->SetName(name);
if (name && *name) if (name && *name) {
{
fAccountItem->SetText(name); fAccountItem->SetText(name);
gListView->InvalidateItem(gListView->IndexOf(fAccountItem)); gListView->InvalidateItem(gListView->IndexOf(fAccountItem));
} }
} }
const char *Account::Name() const const char *
Account::Name() const
{ {
if (fInbound) if (fInbound)
return fInbound->Name(); 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; BMessage *msg;
if (fInbound && (msg = fInbound->MetaData()) != NULL) if (fInbound && (msg = fInbound->MetaData()) != NULL) {
{ if (msg->ReplaceString("real_name", realName) < B_OK)
if (msg->ReplaceString("real_name",realName) < B_OK) msg->AddString("real_name", realName);
msg->AddString("real_name",realName);
} }
if (fOutbound && (msg = fOutbound->MetaData()) != NULL) if (fOutbound && (msg = fOutbound->MetaData()) != NULL) {
{ if (msg->ReplaceString("real_name", realName) < B_OK)
if (msg->ReplaceString("real_name",realName) < B_OK) msg->AddString("real_name", realName);
msg->AddString("real_name",realName);
} }
} }
const char *Account::RealName() const const char *
Account::RealName() const
{ {
if (fInbound && fInbound->MetaData()) if (fInbound && fInbound->MetaData())
return fInbound->MetaData()->FindString("real_name"); 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; BMessage *msg;
if (fInbound && (msg = fInbound->MetaData()) != NULL) if (fInbound && (msg = fInbound->MetaData()) != NULL) {
{ if (msg->ReplaceString("reply_to", returnAddress) < B_OK)
if (msg->ReplaceString("reply_to",returnAddress) < B_OK) msg->AddString("reply_to", returnAddress);
msg->AddString("reply_to",returnAddress);
} }
if (fOutbound && (msg = fOutbound->MetaData()) != NULL) if (fOutbound && (msg = fOutbound->MetaData()) != NULL) {
{ if (msg->ReplaceString("reply_to", returnAddress) < B_OK)
if (msg->ReplaceString("reply_to",returnAddress) < B_OK) msg->AddString("reply_to", returnAddress);
msg->AddString("reply_to",returnAddress);
} }
} }
const char *Account::ReturnAddress() const const char *
Account::ReturnAddress() const
{ {
if (fInbound && fInbound->MetaData()) if (fInbound && fInbound->MetaData())
return fInbound->MetaData()->FindString("reply_to"); 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; BMessage *otherMsg, *thisMsg;
if (sourceChain && (otherMsg = sourceChain->MetaData()) != NULL if (sourceChain && (otherMsg = sourceChain->MetaData()) != NULL
&& (thisMsg = targetChain->MetaData()) != NULL) && (thisMsg = targetChain->MetaData()) != NULL) {
{
const char *string; const char *string;
if ((string = otherMsg->FindString("real_name")) != NULL) if ((string = otherMsg->FindString("real_name")) != NULL) {
{ if (thisMsg->ReplaceString("real_name", string) < B_OK)
if (thisMsg->ReplaceString("real_name",string) < B_OK) thisMsg->AddString("real_name", string);
thisMsg->AddString("real_name",string);
} }
if ((string = otherMsg->FindString("reply_to")) != NULL) if ((string = otherMsg->FindString("reply_to")) != NULL) {
{ if (thisMsg->ReplaceString("reply_to", string) < B_OK)
if (thisMsg->ReplaceString("reply_to",string) < B_OK) thisMsg->AddString("reply_to", string);
thisMsg->AddString("reply_to",string);
} }
if ((string = sourceChain->Name()) != NULL) if ((string = sourceChain->Name()) != NULL)
targetChain->SetName(string); targetChain->SetName(string);
@ -254,21 +260,18 @@ void Account::CopyMetaData(BMailChain *targetChain, BMailChain *sourceChain)
} }
void Account::CreateInbound() void
Account::CreateInbound()
{ {
if (!(fInbound = NewMailChain())) {
if (!(fInbound = NewMailChain())) (new BAlert(TR("E-mail"), TR("Could not create inbound chain."),
{ TR("OK")))->Go();
(new BAlert(
TR ("E-mail"),
TR ("Could not create inbound chain."),
TR ("OK")))->Go();
return; return;
} }
fInbound->SetChainDirection(inbound); fInbound->SetChainDirection(inbound);
BPath path,addOnPath; BPath path,addOnPath;
find_directory(B_USER_ADDONS_DIRECTORY,&addOnPath); find_directory(B_USER_ADDONS_DIRECTORY, &addOnPath);
BMessage msg; BMessage msg;
entry_ref ref; entry_ref ref;
@ -278,69 +281,66 @@ void Account::CreateInbound()
path.Append(kInboundProtocolAddOnPath); path.Append(kInboundProtocolAddOnPath);
path.Append("POP3"); path.Append("POP3");
if (!BEntry(path.Path()).Exists()) { if (!BEntry(path.Path()).Exists()) {
find_directory(B_BEOS_ADDONS_DIRECTORY,&path); find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
path.Append(kInboundProtocolAddOnPath); path.Append(kInboundProtocolAddOnPath);
path.Append("POP3"); path.Append("POP3");
} }
BEntry(path.Path()).GetRef(&ref); BEntry(path.Path()).GetRef(&ref);
fInbound->AddFilter(msg,ref); fInbound->AddFilter(msg, ref);
// Message Parser // Message Parser
path = addOnPath; path = addOnPath;
path.Append(kSystemFilterAddOnPath); path.Append(kSystemFilterAddOnPath);
path.Append("Message Parser"); path.Append("Message Parser");
if (!BEntry(path.Path()).Exists()) { if (!BEntry(path.Path()).Exists()) {
find_directory(B_BEOS_ADDONS_DIRECTORY,&path); find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
path.Append(kSystemFilterAddOnPath); path.Append(kSystemFilterAddOnPath);
path.Append("Message Parser"); path.Append("Message Parser");
} }
BEntry(path.Path()).GetRef(&ref); BEntry(path.Path()).GetRef(&ref);
fInbound->AddFilter(msg,ref); fInbound->AddFilter(msg, ref);
// New Mail Notification // New Mail Notification
path = addOnPath; path = addOnPath;
path.Append(kSystemFilterAddOnPath); path.Append(kSystemFilterAddOnPath);
path.Append(TR ("New mail notification")); path.Append(TR("New mail notification"));
if (!BEntry(path.Path()).Exists()) { if (!BEntry(path.Path()).Exists()) {
find_directory(B_BEOS_ADDONS_DIRECTORY,&path); find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
path.Append(kSystemFilterAddOnPath); path.Append(kSystemFilterAddOnPath);
path.Append("New mail notification"); path.Append("New mail notification");
} }
BEntry(path.Path()).GetRef(&ref); BEntry(path.Path()).GetRef(&ref);
fInbound->AddFilter(msg,ref); fInbound->AddFilter(msg, ref);
// Inbox // Inbox
path = addOnPath; path = addOnPath;
path.Append(kSystemFilterAddOnPath); path.Append(kSystemFilterAddOnPath);
path.Append("Inbox"); path.Append("Inbox");
if (!BEntry(path.Path()).Exists()) { if (!BEntry(path.Path()).Exists()) {
find_directory(B_BEOS_ADDONS_DIRECTORY,&path); find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
path.Append(kSystemFilterAddOnPath); path.Append(kSystemFilterAddOnPath);
path.Append("Inbox"); path.Append("Inbox");
} }
BEntry(path.Path()).GetRef(&ref); BEntry(path.Path()).GetRef(&ref);
fInbound->AddFilter(msg,ref); fInbound->AddFilter(msg, ref);
// set already made account settings // set already made account settings
CopyMetaData(fInbound,fOutbound); CopyMetaData(fInbound,fOutbound);
} }
void Account::CreateOutbound() void
Account::CreateOutbound()
{ {
if (!(fOutbound = NewMailChain())) {
if (!(fOutbound = NewMailChain())) (new BAlert(TR("E-mail"), TR("Could not create outbound chain."),
{ TR("OK")))->Go();
(new BAlert(
TR ("E-mail"),
TR ("Could not create outbound chain."),
TR ("OK")))->Go();
return; return;
} }
fOutbound->SetChainDirection(outbound); fOutbound->SetChainDirection(outbound);
BPath path,addOnPath; BPath path,addOnPath;
find_directory(B_USER_ADDONS_DIRECTORY,&addOnPath); find_directory(B_USER_ADDONS_DIRECTORY, &addOnPath);
BMessage msg; BMessage msg;
entry_ref ref; entry_ref ref;
@ -349,30 +349,31 @@ void Account::CreateOutbound()
path.Append(kSystemFilterAddOnPath); path.Append(kSystemFilterAddOnPath);
path.Append("Outbox"); path.Append("Outbox");
if (!BEntry(path.Path()).Exists()) { if (!BEntry(path.Path()).Exists()) {
find_directory(B_BEOS_ADDONS_DIRECTORY,&path); find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
path.Append(kSystemFilterAddOnPath); path.Append(kSystemFilterAddOnPath);
path.Append("Outbox"); path.Append("Outbox");
} }
BEntry(path.Path()).GetRef(&ref); BEntry(path.Path()).GetRef(&ref);
fOutbound->AddFilter(msg,ref); fOutbound->AddFilter(msg, ref);
path = addOnPath; path = addOnPath;
path.Append(kOutboundProtocolAddOnPath); path.Append(kOutboundProtocolAddOnPath);
path.Append("SMTP"); path.Append("SMTP");
if (!BEntry(path.Path()).Exists()) { if (!BEntry(path.Path()).Exists()) {
find_directory(B_BEOS_ADDONS_DIRECTORY,&path); find_directory(B_BEOS_ADDONS_DIRECTORY, &path);
path.Append(kOutboundProtocolAddOnPath); path.Append(kOutboundProtocolAddOnPath);
path.Append("SMTP"); path.Append("SMTP");
} }
BEntry(path.Path()).GetRef(&ref); BEntry(path.Path()).GetRef(&ref);
fOutbound->AddFilter(msg,ref); fOutbound->AddFilter(msg, ref);
// set already made account settings // set already made account settings
CopyMetaData(fOutbound,fInbound); CopyMetaData(fOutbound,fInbound);
} }
void Account::SetType(int32 type) void
Account::SetType(int32 type)
{ {
if (type < INBOUND_TYPE || type > IN_AND_OUTBOUND_TYPE) if (type < INBOUND_TYPE || type > IN_AND_OUTBOUND_TYPE)
return; return;
@ -380,8 +381,7 @@ void Account::SetType(int32 type)
int32 index = gListView->IndexOf(fAccountItem) + 1; int32 index = gListView->IndexOf(fAccountItem) + 1;
// missing inbound // missing inbound
if ((type == INBOUND_TYPE || type == IN_AND_OUTBOUND_TYPE) && !Inbound()) if ((type == INBOUND_TYPE || type == IN_AND_OUTBOUND_TYPE) && !Inbound()) {
{
if (!fInbound) if (!fInbound)
CreateInbound(); CreateInbound();
@ -392,20 +392,20 @@ void Account::SetType(int32 type)
index++; index++;
// missing outbound // missing outbound
if ((type == OUTBOUND_TYPE || type == IN_AND_OUTBOUND_TYPE) && !Outbound()) if ((type == OUTBOUND_TYPE || type == IN_AND_OUTBOUND_TYPE)
{ && !Outbound()) {
if (!fOutbound) if (!fOutbound)
CreateOutbound(); CreateOutbound();
if (fOutbound) if (fOutbound)
gListView->AddItem(fOutboundItem,index); gListView->AddItem(fOutboundItem, index);
} }
if (Outbound()) if (Outbound())
index++; index++;
// missing filter // missing filter
if (!gListView->HasItem(fFilterItem)) if (!gListView->HasItem(fFilterItem))
gListView->AddItem(fFilterItem,index); gListView->AddItem(fFilterItem, index);
// remove inbound // remove inbound
if (type == OUTBOUND_TYPE && 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); return Inbound() ? (Outbound() ? 2 : 0) : (Outbound() ? 1 : -1);
} }
void Account::Selected(int32 type) void
Account::Selected(int32 type)
{ {
if (!gConfigView) if (!gConfigView)
return; return;
@ -431,10 +433,10 @@ void Account::Selected(int32 type)
gConfigView->Hide(); gConfigView->Hide();
((CenterContainer *)gConfigView)->DeleteChildren(); ((CenterContainer *)gConfigView)->DeleteChildren();
switch (type) switch (type) {
{
case ACCOUNT_ITEM: case ACCOUNT_ITEM:
gConfigView->AddChild(new AccountConfigView(gConfigView->Bounds(),this)); gConfigView->AddChild(new AccountConfigView(gConfigView->Bounds(),
this));
break; break;
case INBOUND_ITEM: case INBOUND_ITEM:
{ {
@ -442,22 +444,19 @@ void Account::Selected(int32 type)
break; break;
int32 count = fInbound->CountFilters(); int32 count = fInbound->CountFilters();
for (int32 i = 0;;i++) for (int32 i = 0;; i++) {
{
BMessage *msg = new BMessage(); BMessage *msg = new BMessage();
entry_ref *ref = new entry_ref; entry_ref *ref = new entry_ref;
// we just want to have the first and the last two filters: // we just want to have the first and the last two filters:
// Protocol, Parser, Notifier, Folder // Protocol, Parser, Notifier, Folder
if (i == 2) if (i == 2) {
{
i = count - 2; i = count - 2;
if (i < 2) // defensive programming... if (i < 2) // defensive programming...
i = 3; i = 3;
} }
if (fInbound->GetFilter(i,msg,ref) < B_OK) if (fInbound->GetFilter(i, msg, ref) < B_OK) {
{
delete msg; delete msg;
delete ref; delete ref;
break; break;
@ -466,9 +465,9 @@ void Account::Selected(int32 type)
// the filter view takes ownership of "msg" and "ref" // the filter view takes ownership of "msg" and "ref"
FilterConfigView *view; FilterConfigView *view;
if (i == 0) if (i == 0)
view = new ProtocolsConfigView(fInbound,i,msg,ref); view = new ProtocolsConfigView(fInbound, i, msg, ref);
else else
view = new FilterConfigView(fInbound,i,msg,ref); view = new FilterConfigView(fInbound, i, msg, ref);
if (view->InitCheck() >= B_OK) if (view->InitCheck() >= B_OK)
gConfigView->AddChild(view); gConfigView->AddChild(view);
@ -484,32 +483,31 @@ void Account::Selected(int32 type)
// we just want to have the first and the last filter here // we just want to have the first and the last filter here
int32 count = fOutbound->CountFilters(); 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(); BMessage *msg = new BMessage();
entry_ref *ref = new entry_ref; 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 msg;
delete ref; delete ref;
break; break;
} }
// the filter view takes ownership of "msg" and "ref" // 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) if (view->InitCheck() >= B_OK)
gConfigView->AddChild(view); gConfigView->AddChild(view);
else else
delete view; delete view;
} }
}
break; break;
} }
case FILTER_ITEM: case FILTER_ITEM:
{ {
gConfigView->AddChild(new FiltersConfigView(gConfigView->Bounds(),this)); gConfigView->AddChild(new FiltersConfigView(gConfigView->Bounds(),
this));
break; 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 // this should only be called if necessary, but if it's used
// in the GUI, this will always be the case // in the GUI, this will always be the case
((CenterContainer *)gConfigView)->DeleteChildren(); ((CenterContainer *)gConfigView)->DeleteChildren();
switch (type) switch (type) {
{
case ACCOUNT_ITEM: case ACCOUNT_ITEM:
gListView->RemoveItem(fAccountItem); gListView->RemoveItem(fAccountItem);
gListView->RemoveItem(fInboundItem); 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; return gListView && gListView->HasItem(fInboundItem) ? fInbound : NULL;
} }
BMailChain *Account::Outbound() const BMailChain *
Account::Outbound() const
{ {
return gListView && gListView->HasItem(fOutboundItem) ? fOutbound : NULL; return gListView && gListView->HasItem(fOutboundItem) ? fOutbound : NULL;
} }
void Account::Save() void
Account::Save()
{ {
if (Inbound()) if (Inbound())
fInbound->Save(); 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)) if (fInbound && (type == INBOUND_TYPE || type == IN_AND_OUTBOUND_TYPE))
fInbound->Delete(); fInbound->Delete();
@ -591,7 +593,8 @@ void Account::Delete(int32 type)
// #pragma mark - // #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 *a = (*(Account **)_a)->Name();
const char *b = (*(Account **)_b)->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; gListView = listView;
gConfigView = configView; gConfigView = configView;
@ -615,19 +619,16 @@ void Accounts::Create(BListView *listView, BView *configView)
// create inbound accounts and assign matching outbound chains // 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 *inChain = (BMailChain *)inbound.ItemAt(i);
BMailChain *outChain = NULL; BMailChain *outChain = NULL;
for (int32 j = outbound.CountItems();j-- > 0;) for (int32 j = outbound.CountItems(); j-- > 0;) {
{
outChain = (BMailChain *)outbound.ItemAt(j); outChain = (BMailChain *)outbound.ItemAt(j);
if (!strcmp(inChain->Name(), outChain->Name()))
if (!strcmp(inChain->Name(),outChain->Name()))
break; break;
outChain = NULL; outChain = NULL;
} }
gAccounts.AddItem(new Account(inChain,outChain)); gAccounts.AddItem(new Account(inChain, outChain));
inbound.RemoveItem(i); inbound.RemoveItem(i);
if (outChain) if (outChain)
outbound.RemoveItem(outChain); outbound.RemoveItem(outChain);
@ -635,23 +636,23 @@ void Accounts::Create(BListView *listView, BView *configView)
// create remaining outbound only accounts // 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); BMailChain *outChain = (BMailChain *)outbound.ItemAt(i);
gAccounts.AddItem(new Account(NULL,outChain)); gAccounts.AddItem(new Account(NULL, outChain));
outbound.RemoveItem(i); outbound.RemoveItem(i);
} }
// sort the list alphabetically // sort the list alphabetically
gAccounts.SortItems(Accounts::Compare); 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->AddToListView();
} }
Account* Accounts::NewAccount() Account*
Accounts::NewAccount()
{ {
Account *account = new Account(); Account *account = new Account();
gAccounts.AddItem(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(); ((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); Account *account = (Account *)gAccounts.RemoveItem(i);
delete account; 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" #include "ConfigViews.h"
@ -53,58 +55,66 @@ const uint32 kMsgRemoveFilter = 'rmfi';
const uint32 kMsgFilterSelected = 'fsel'; const uint32 kMsgFilterSelected = 'fsel';
AccountConfigView::AccountConfigView(BRect rect,Account *account) AccountConfigView::AccountConfigView(BRect rect, Account *account)
: BBox(rect), :
BBox(rect),
fAccount(account) fAccount(account)
{ {
SetLabel(TR ("Account settings")); SetLabel(TR("Account settings"));
rect = Bounds().InsetByCopy(8,8); rect = Bounds().InsetByCopy(8, 8);
rect.top += 10; rect.top += 10;
CenterContainer *view = new CenterContainer(rect,false); CenterContainer *view = new CenterContainer(rect, false);
view->SetSpacing(5); view->SetSpacing(5);
// determine font height // determine font height
font_height fontHeight; font_height fontHeight;
view->GetFontHeight(&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 = view->Bounds();
rect.bottom = height + 5; 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); 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); 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); fReturnAddressControl->SetDivider(labelWidth);
// control->TextView()->HideTyping(true); // control->TextView()->HideTyping(true);
BPopUpMenu *chainsPopUp = new BPopUpMenu(B_EMPTY_STRING); BPopUpMenu *chainsPopUp = new BPopUpMenu(B_EMPTY_STRING);
const char *chainModes[] = { const char *chainModes[] = {
TR ("Receive mail only"), TR("Receive mail only"),
TR ("Send mail only"), TR("Send mail only"),
TR ("Send and receive mail")}; TR("Send and receive mail")};
BMenuItem *item; BMenuItem *item;
for (int32 i = 0;i < 3;i++) for (int32 i = 0;i < 3;i++) {
chainsPopUp->AddItem(item = new BMenuItem(chainModes[i],new BMessage(kMsgAccountTypeChanged))); 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); fTypeField->SetDivider(labelWidth + 3);
view->AddChild(fTypeField); view->AddChild(fTypeField);
float w,h; float w, h;
view->GetPreferredSize(&w,&h); view->GetPreferredSize(&w, &h);
ResizeTo(w + 15,h + 22); ResizeTo(w + 15, h + 22);
view->ResizeTo(w,h); view->ResizeTo(w, h);
AddChild(view); AddChild(view);
} }
void AccountConfigView::DetachedFromWindow() void
AccountConfigView::DetachedFromWindow()
{ {
fAccount->SetName(fNameControl->Text()); fAccount->SetName(fNameControl->Text());
fAccount->SetRealName(fRealNameControl->Text()); fAccount->SetRealName(fRealNameControl->Text());
@ -112,7 +122,8 @@ void AccountConfigView::DetachedFromWindow()
} }
void AccountConfigView::AttachedToWindow() void
AccountConfigView::AttachedToWindow()
{ {
UpdateViews(); UpdateViews();
fNameControl->SetTarget(this); 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: case kMsgAccountTypeChanged:
{ {
int32 index; int32 index;
if (msg->FindInt32("index",&index) < B_OK) if (msg->FindInt32("index", &index) < B_OK)
break; break;
if (fAccount->Type() < 0) if (fAccount->Type() < 0) {
{
fNameControl->SetEnabled(true); fNameControl->SetEnabled(true);
fRealNameControl->SetEnabled(true); fRealNameControl->SetEnabled(true);
fReturnAddressControl->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()) if (BMenuItem *item = fTypeField->Menu()->FindMarked())
item->SetMarked(false); item->SetMarked(false);
fTypeField->Menu()->Superitem()->SetLabel(TR ("Select account type")); fTypeField->Menu()->Superitem()->SetLabel(TR("Select account type"));
fNameControl->SetEnabled(false); fNameControl->SetEnabled(false);
fRealNameControl->SetEnabled(false); fRealNameControl->SetEnabled(false);
@ -172,12 +182,13 @@ void AccountConfigView::UpdateViews()
} }
//---------------------------------------------------------------------------------------
// #pragma mark - // #pragma mark -
#include <stdio.h>
FilterConfigView::FilterConfigView(BMailChain *chain,int32 index,BMessage *msg,entry_ref *ref) FilterConfigView::FilterConfigView(BMailChain *chain, int32 index,
: BBox(BRect(0,0,100,100)), BMessage *msg, entry_ref *ref)
:
BBox(BRect(0,0,100,100)),
fConfigView(NULL), fConfigView(NULL),
fChain(chain), fChain(chain),
fIndex(index), 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); ResizeTo(264,30);
BView *(* instantiate_config)(BMessage *,BMessage *); BView *(* instantiate_config)(BMessage *, BMessage *);
BPath addon(ref); BPath addon(ref);
fImage = load_add_on(addon.Path()); fImage = load_add_on(addon.Path());
if (fImage < B_OK) if (fImage < B_OK)
return; 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); unload_add_on(fImage);
fImage = B_MISSING_SYMBOL; fImage = B_MISSING_SYMBOL;
return; return;
} }
fConfigView = (*instantiate_config)(msg,fChain->MetaData()); fConfigView = (*instantiate_config)(msg, fChain->MetaData());
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);
ResizeTo(w + 6,h + 16); ResizeTo(w + 6, h + 16);
AddChild(fConfigView); AddChild(fConfigView);
} }
void FilterConfigView::Remove(bool deleteMessage) void
FilterConfigView::Remove(bool deleteMessage)
{ {
// remove config view here, because they may not be available // remove config view here, because they may not be available
// anymore, if the add-on is unloaded // anymore, if the add-on is unloaded
if (fConfigView && RemoveChild(fConfigView)) if (fConfigView && RemoveChild(fConfigView)) {
{
delete fConfigView; delete fConfigView;
fConfigView = NULL; fConfigView = NULL;
} }
unload_add_on(fImage); unload_add_on(fImage);
if (deleteMessage) if (deleteMessage) {
{
delete fMessage; delete fMessage;
fMessage = NULL; fMessage = NULL;
} }
@ -244,41 +255,45 @@ void FilterConfigView::Remove(bool deleteMessage)
} }
status_t FilterConfigView::InitCheck() status_t
FilterConfigView::InitCheck()
{ {
return fImage; return fImage;
} }
void FilterConfigView::DetachedFromWindow() void
FilterConfigView::DetachedFromWindow()
{ {
if (fConfigView == NULL) if (fConfigView == NULL)
return; return;
if (fConfigView->Archive(fMessage) >= B_OK) if (fConfigView->Archive(fMessage) >= B_OK)
fChain->SetFilter(fIndex,*fMessage,*fEntryRef); fChain->SetFilter(fIndex, *fMessage, *fEntryRef);
} }
void FilterConfigView::AttachedToWindow() void
FilterConfigView::AttachedToWindow()
{ {
} }
//---------------------------------------------------------------------------------------
// #pragma mark - // #pragma mark -
ProtocolsConfigView::ProtocolsConfigView(BMailChain *chain,int32 index,BMessage *msg,entry_ref *ref) ProtocolsConfigView::ProtocolsConfigView(BMailChain *chain, int32 index,
: FilterConfigView(chain,index,msg,ref) BMessage *msg, entry_ref *ref)
:
FilterConfigView(chain, index, msg, ref)
{ {
BPopUpMenu *menu = new BPopUpMenu("Choose Protocol"); BPopUpMenu *menu = new BPopUpMenu("Choose Protocol");
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
BPath path; BPath path;
status_t status = find_directory((i == 0) ? B_USER_ADDONS_DIRECTORY : B_BEOS_ADDONS_DIRECTORY,&path); status_t status = find_directory(
if (status != B_OK) i == 0 ? B_USER_ADDONS_DIRECTORY : B_BEOS_ADDONS_DIRECTORY, &path);
{ if (status != B_OK) {
fImage = status; fImage = status;
return; return;
} }
@ -292,51 +307,51 @@ ProtocolsConfigView::ProtocolsConfigView(BMailChain *chain,int32 index,BMessage
BDirectory dir(path.Path()); BDirectory dir(path.Path());
entry_ref protocolRef; entry_ref protocolRef;
while (dir.GetNextRef(&protocolRef) == B_OK) while (dir.GetNextRef(&protocolRef) == B_OK) {
{
char name[B_FILE_NAME_LENGTH]; char name[B_FILE_NAME_LENGTH];
BEntry entry(&protocolRef); BEntry entry(&protocolRef);
entry.GetName(name); entry.GetName(name);
BMenuItem *item; BMenuItem *item;
BMessage *msg; BMessage *msg;
menu->AddItem(item = new BMenuItem(name,msg = new BMessage(kMsgProtocolChanged))); menu->AddItem(item = new BMenuItem(name,
msg->AddRef("protocol",&protocolRef); msg = new BMessage(kMsgProtocolChanged)));
msg->AddRef("protocol", &protocolRef);
if (*ref == protocolRef) if (*ref == protocolRef)
item->SetMarked(true); 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(); fProtocolsMenuField->ResizeToPreferred();
SetLabel(fProtocolsMenuField); SetLabel(fProtocolsMenuField);
if (fConfigView) if (fConfigView) {
{ fConfigView->MoveTo(3, 21);
fConfigView->MoveTo(3,21); ResizeBy(0, 8);
ResizeBy(0,8); } else
}
else
fImage = B_OK; fImage = B_OK;
} }
void ProtocolsConfigView::AttachedToWindow() void
ProtocolsConfigView::AttachedToWindow()
{ {
FilterConfigView::AttachedToWindow(); FilterConfigView::AttachedToWindow();
fProtocolsMenuField->Menu()->SetTargetForItems(this); fProtocolsMenuField->Menu()->SetTargetForItems(this);
} }
void ProtocolsConfigView::MessageReceived(BMessage *msg) void
ProtocolsConfigView::MessageReceived(BMessage *msg)
{ {
switch (msg->what) switch (msg->what) {
{
case kMsgProtocolChanged: case kMsgProtocolChanged:
{ {
entry_ref ref; entry_ref ref;
if (msg->FindRef("protocol",&ref) < B_OK) if (msg->FindRef("protocol", &ref) < B_OK)
break; break;
DetachedFromWindow(); DetachedFromWindow();
@ -344,19 +359,18 @@ void ProtocolsConfigView::MessageReceived(BMessage *msg)
fEntryRef = new entry_ref(ref); fEntryRef = new entry_ref(ref);
Load(fMessage,fEntryRef); Load(fMessage,fEntryRef);
fChain->SetFilter(fIndex,*fMessage,*fEntryRef); fChain->SetFilter(fIndex, *fMessage, *fEntryRef);
// resize view // resize view
if (LockLooperWithTimeout(1000000L) == B_OK) if (LockLooperWithTimeout(1000000L) == B_OK) {
{ if (fConfigView) {
if (fConfigView) fConfigView->MoveTo(3, 21);
{ ResizeBy(0, 8);
fConfigView->MoveTo(3,21);
ResizeBy(0,8);
} }
UnlockLooper(); UnlockLooper();
if (CenterContainer *container = dynamic_cast<CenterContainer *>(Parent())) if (CenterContainer *container
= dynamic_cast<CenterContainer *>(Parent()))
container->Layout(); container->Layout();
} }
break; break;
@ -368,39 +382,40 @@ void ProtocolsConfigView::MessageReceived(BMessage *msg)
} }
//---------------------------------------------------------------------------------------
// #pragma mark - // #pragma mark -
#include <stdio.h>
class DragListView : public BListView class DragListView : public BListView {
{ public:
public: DragListView(BRect frame, const char *name,
DragListView(BRect frame,const char *name,list_view_type type = B_SINGLE_SELECTION_LIST, list_view_type type = B_SINGLE_SELECTION_LIST,
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,BMessage *itemMovedMsg = NULL) uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
: BListView(frame,name,type,resizingMode), BMessage *itemMovedMsg = NULL)
:
BListView(frame, name, type, resizingMode),
fDragging(false), fDragging(false),
fItemMovedMessage(itemMovedMsg) fItemMovedMessage(itemMovedMsg)
{ {
} }
virtual bool InitiateDrag(BPoint point,int32 index,bool wasSelected) virtual bool InitiateDrag(BPoint point, int32 index, bool wasSelected)
{ {
BRect frame(ItemFrame(index)); BRect frame(ItemFrame(index));
BBitmap *bitmap = new BBitmap(frame.OffsetToCopy(B_ORIGIN),B_RGBA32,true); BBitmap *bitmap = new BBitmap(frame.OffsetToCopy(B_ORIGIN), B_RGBA32,
BView *view = new BView(bitmap->Bounds(),NULL,0,0); true);
BView *view = new BView(bitmap->Bounds(), NULL, 0, 0);
bitmap->AddChild(view); bitmap->AddChild(view);
if (view->LockLooper()) if (view->LockLooper()) {
{
BListItem *item = ItemAt(index); BListItem *item = ItemAt(index);
bool selected = item->IsSelected(); bool selected = item->IsSelected();
view->SetLowColor(225,225,225,128); view->SetLowColor(225, 225, 225, 128);
view->FillRect(view->Bounds()); view->FillRect(view->Bounds());
if (selected) if (selected)
item->Deselect(); item->Deselect();
ItemAt(index)->DrawItem(view,view->Bounds(),true); ItemAt(index)->DrawItem(view, view->Bounds(), true);
if (selected) if (selected)
item->Select(); item->Select();
@ -411,8 +426,8 @@ class DragListView : public BListView
fDragging = true; fDragging = true;
BMessage drag(kMsgItemDragged); BMessage drag(kMsgItemDragged);
drag.AddInt32("index",index); drag.AddInt32("index", index);
DragMessage(&drag,bitmap,B_OP_ALPHA,point - frame.LeftTop(),this); DragMessage(&drag, bitmap, B_OP_ALPHA, point - frame.LeftTop(), this);
return true; return true;
} }
@ -436,11 +451,12 @@ class DragListView : public BListView
PopState(); 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; return;
int32 target = IndexOf(point); int32 target = IndexOf(point);
@ -466,8 +482,7 @@ class DragListView : public BListView
virtual void MouseUp(BPoint point) virtual void MouseUp(BPoint point)
{ {
if (fDragging) if (fDragging) {
{
fDragging = false; fDragging = false;
if (fLastDragTarget != -1) if (fLastDragTarget != -1)
DrawDragTargetIndicator(fLastDragTarget); DrawDragTargetIndicator(fLastDragTarget);
@ -477,8 +492,7 @@ class DragListView : public BListView
virtual void MessageReceived(BMessage *msg) virtual void MessageReceived(BMessage *msg)
{ {
switch(msg->what) switch (msg->what) {
{
case kMsgItemDragged: case kMsgItemDragged:
{ {
int32 source = msg->FindInt32("index"); int32 source = msg->FindInt32("index");
@ -490,12 +504,10 @@ class DragListView : public BListView
if (to == -1) if (to == -1)
to = CountItems() - 1; to = CountItems() - 1;
if (source != to) if (source != to) {
{
MoveItem(source,to); MoveItem(source,to);
if (fItemMovedMessage != NULL) if (fItemMovedMessage != NULL) {
{
BMessage msg(fItemMovedMessage->what); BMessage msg(fItemMovedMessage->what);
msg.AddInt32("from",source); msg.AddInt32("from",source);
msg.AddInt32("to",to); msg.AddInt32("to",to);
@ -508,14 +520,15 @@ class DragListView : public BListView
BListView::MessageReceived(msg); BListView::MessageReceived(msg);
} }
private: private:
bool fDragging; bool fDragging;
int32 fLastDragTarget,fDragIndex; int32 fLastDragTarget,fDragIndex;
BMessage *fItemMovedMessage; BMessage *fItemMovedMessage;
}; };
void GetPrettyDescriptiveName(BPath &path, char *name, BMessage *msg = NULL) void
GetPrettyDescriptiveName(BPath &path, char *name, BMessage *msg = NULL)
{ {
strcpy(name, path.Leaf()); strcpy(name, path.Leaf());
@ -536,8 +549,9 @@ void GetPrettyDescriptiveName(BPath &path, char *name, BMessage *msg = NULL)
// #pragma mark - // #pragma mark -
FiltersConfigView::FiltersConfigView(BRect rect,Account *account) FiltersConfigView::FiltersConfigView(BRect rect, Account *account)
: BBox(rect), :
BBox(rect),
fAccount(account), fAccount(account),
fFilterView(NULL) fFilterView(NULL)
{ {
@ -545,58 +559,65 @@ FiltersConfigView::FiltersConfigView(BRect rect,Account *account)
BMenuItem *item; BMenuItem *item;
BMessage *msg; BMessage *msg;
if ((fChain = fAccount->Inbound())) if ((fChain = fAccount->Inbound())) {
{ menu->AddItem(item = new BMenuItem(TR("Incoming mail filters"),
menu->AddItem(item = new BMenuItem(TR ("Incoming mail filters"),msg = new BMessage(kMsgChainSelected))); msg = new BMessage(kMsgChainSelected)));
msg->AddPointer("chain",fChain); msg->AddPointer("chain", fChain);
item->SetMarked(true); item->SetMarked(true);
} }
if (BMailChain *chain = fAccount->Outbound()) if (BMailChain *chain = fAccount->Outbound()) {
{ menu->AddItem(item = new BMenuItem(TR("Outgoing mail filters"),
menu->AddItem(item = new BMenuItem(TR ("Outgoing mail filters"),msg = new BMessage(kMsgChainSelected))); msg = new BMessage(kMsgChainSelected)));
msg->AddPointer("chain",chain); msg->AddPointer("chain", chain);
if (fChain == NULL) if (fChain == NULL) {
{
item->SetMarked(true); item->SetMarked(true);
fChain = chain; 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(); fChainsField->ResizeToPreferred();
SetLabel(fChainsField); SetLabel(fChainsField);
// determine font height // determine font height
font_height fontHeight; font_height fontHeight;
fChainsField->GetFontHeight(&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.top += 18;
rect.right -= B_V_SCROLL_BAR_WIDTH; rect.right -= B_V_SCROLL_BAR_WIDTH;
rect.bottom = rect.top + 4 * height + 2; rect.bottom = rect.top + 4 * height + 2;
fListView = new DragListView(rect,NULL,B_SINGLE_SELECTION_LIST,B_FOLLOW_ALL,new BMessage(kMsgFilterMoved)); fListView = new DragListView(rect, NULL, B_SINGLE_SELECTION_LIST,
AddChild(new BScrollView(NULL,fListView,B_FOLLOW_ALL,0,false,true)); B_FOLLOW_ALL, new BMessage(kMsgFilterMoved));
AddChild(new BScrollView(NULL, fListView, B_FOLLOW_ALL, 0, false, true));
rect.right += B_V_SCROLL_BAR_WIDTH; rect.right += B_V_SCROLL_BAR_WIDTH;
// fListView->Select(gSettings.formats.IndexOf(format)); // fListView->Select(gSettings.formats.IndexOf(format));
fListView->SetSelectionMessage(new BMessage(kMsgFilterSelected)); fListView->SetSelectionMessage(new BMessage(kMsgFilterSelected));
rect.top = rect.bottom + 8; rect.bottom = rect.top + height; rect.top = rect.bottom + 8;
BRect sizeRect = rect; sizeRect.right = sizeRect.left + 30 + fChainsField->StringWidth(TR ("Add filter")); 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); menu->SetRadioMode(false);
fAddField = new BMenuField(rect,NULL,NULL,menu); fAddField = new BMenuField(rect, NULL, NULL, menu);
fAddField->ResizeToPreferred(); fAddField->ResizeToPreferred();
AddChild(fAddField); 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--; 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); SetTo(fChain);
} }
@ -606,18 +627,19 @@ FiltersConfigView::~FiltersConfigView()
} }
void FiltersConfigView::SelectFilter(int32 index) void
FiltersConfigView::SelectFilter(int32 index)
{ {
if (Parent()) if (Parent())
Parent()->Hide(); Parent()->Hide();
// remove old config view // remove old config view
if (fFilterView) if (fFilterView) {
{
Parent()->RemoveChild(fFilterView); Parent()->RemoveChild(fFilterView);
// update the name in the list // 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]; char name[B_FILE_NAME_LENGTH];
BPath path(fFilterView->fEntryRef); BPath path(fFilterView->fEntryRef);
@ -628,24 +650,19 @@ void FiltersConfigView::SelectFilter(int32 index)
fFilterView = NULL; fFilterView = NULL;
} }
if (index >= 0) if (index >= 0) {
{
// add new config view // add new config view
BMessage *msg = new BMessage(); BMessage *msg = new BMessage();
entry_ref *ref = new entry_ref(); entry_ref *ref = new entry_ref();
if (fChain->GetFilter(index + fFirst,msg,ref) >= B_OK && Parent()) if (fChain->GetFilter(index + fFirst, msg, ref) >= B_OK && Parent()) {
{ fFilterView = new FilterConfigView(fChain,index + fFirst, msg, ref);
fFilterView = new FilterConfigView(fChain,index + fFirst,msg,ref);
if (fFilterView->InitCheck() >= B_OK) if (fFilterView->InitCheck() >= B_OK)
Parent()->AddChild(fFilterView); Parent()->AddChild(fFilterView);
else else {
{
delete fFilterView; delete fFilterView;
fFilterView = NULL; fFilterView = NULL;
} }
} } else {
else
{
delete msg; delete msg;
delete ref; 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 // remove the filter config view
SelectFilter(-1); SelectFilter(-1);
for (int32 i = fListView->CountItems();i-- > 0;) for (int32 i = fListView->CountItems(); i-- > 0;) {
{
BStringItem *item = (BStringItem *)fListView->RemoveItem(i); BStringItem *item = (BStringItem *)fListView->RemoveItem(i);
delete item; delete item;
} }
if (chain->ChainDirection() == inbound) if (chain->ChainDirection() == inbound) {
{
fFirst = 2; // skip protocol (e.g. POP3), and Parser fFirst = 2; // skip protocol (e.g. POP3), and Parser
fLast = 2; // skip Notifier, and Folder fLast = 2; // skip Notifier, and Folder
} } else {
else
{
fFirst = 1; // skip Producer fFirst = 1; // skip Producer
fLast = 1; // skip protocol (e.g. SMTP) fLast = 1; // skip protocol (e.g. SMTP)
} }
int32 last = chain->CountFilters() - fLast; int32 last = chain->CountFilters() - fLast;
for (int32 i = fFirst;i < last;i++) for (int32 i = fFirst; i < last; i++) {
{
BMessage msg; BMessage msg;
entry_ref ref; 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]; char name[B_FILE_NAME_LENGTH];
BPath addon(&ref); BPath addon(&ref);
GetPrettyDescriptiveName(addon, name, &msg); GetPrettyDescriptiveName(addon, name, &msg);
@ -701,15 +714,15 @@ void FiltersConfigView::SetTo(BMailChain *chain)
// remove old filter items // remove old filter items
BMenu *menu = fAddField->Menu(); BMenu *menu = fAddField->Menu();
for (int32 i = menu->CountItems();i-- > 0;) for (int32 i = menu->CountItems(); i-- > 0;) {
{
BMenuItem *item = menu->RemoveItem(i); BMenuItem *item = menu->RemoveItem(i);
delete item; delete item;
} }
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
BPath path; 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) if (status != B_OK)
return; return;
@ -722,23 +735,24 @@ void FiltersConfigView::SetTo(BMailChain *chain)
BDirectory dir(path.Path()); BDirectory dir(path.Path());
entry_ref ref; entry_ref ref;
while (dir.GetNextRef(&ref) == B_OK) while (dir.GetNextRef(&ref) == B_OK) {
{
char name[B_FILE_NAME_LENGTH]; char name[B_FILE_NAME_LENGTH];
BPath path(&ref); BPath path(&ref);
GetPrettyDescriptiveName(path, name); GetPrettyDescriptiveName(path, name);
BMenuItem *item; BMenuItem *item;
BMessage *msg; BMessage *msg;
menu->AddItem(item = new BMenuItem(name,msg = new BMessage(kMsgAddFilter))); menu->AddItem(item = new BMenuItem(name,
msg->AddRef("filter",&ref); msg = new BMessage(kMsgAddFilter)));
msg->AddRef("filter", &ref);
} }
} }
menu->SetTargetForItems(this); menu->SetTargetForItems(this);
} }
void FiltersConfigView::AttachedToWindow() void
FiltersConfigView::AttachedToWindow()
{ {
fChainsField->Menu()->SetTargetForItems(this); fChainsField->Menu()->SetTargetForItems(this);
fListView->SetTarget(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: case kMsgChainSelected:
{ {
BMailChain *chain; BMailChain *chain;
if (msg->FindPointer("chain",(void **)&chain) < B_OK) if (msg->FindPointer("chain", (void **)&chain) < B_OK)
break; break;
SetTo(chain); SetTo(chain);
@ -763,12 +777,12 @@ void FiltersConfigView::MessageReceived(BMessage *msg)
case kMsgAddFilter: case kMsgAddFilter:
{ {
entry_ref ref; entry_ref ref;
if (msg->FindRef("filter",&ref) < B_OK) if (msg->FindRef("filter", &ref) < B_OK)
break; break;
BMessage msg; 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]; char name[B_FILE_NAME_LENGTH];
BPath path(&ref); BPath path(&ref);
GetPrettyDescriptiveName(path, name, &msg); GetPrettyDescriptiveName(path, name, &msg);
@ -783,8 +797,8 @@ void FiltersConfigView::MessageReceived(BMessage *msg)
break; break;
SelectFilter(-1); SelectFilter(-1);
if (BStringItem *item = (BStringItem *)fListView->RemoveItem(index)) if (BStringItem *item
{ = (BStringItem *)fListView->RemoveItem(index)) {
fChain->RemoveFilter(index + fFirst); fChain->RemoveFilter(index + fFirst);
delete item; delete item;
} }
@ -811,39 +825,36 @@ void FiltersConfigView::MessageReceived(BMessage *msg)
entry_ref ref; entry_ref ref;
BMessage settings; BMessage settings;
if (fChain->GetFilter(from,&settings,&ref) == B_OK) if (fChain->GetFilter(from, &settings, &ref) == B_OK) {
{
// disable filter view saving // disable filter view saving
if (fFilterView && fFilterView->fIndex == from) if (fFilterView && fFilterView->fIndex == from)
fFilterView->fIndex = -1; fFilterView->fIndex = -1;
fChain->RemoveFilter(from); fChain->RemoveFilter(from);
if (fChain->AddFilter(to,settings,ref) < B_OK) if (fChain->AddFilter(to, settings, ref) < B_OK) {
{ (new BAlert("E-mail",
(new BAlert("E-mail",TR ( TR("The filter could not be moved. Deleting filter."),
"The filter could not be moved. Deleting filter." TR("OK")))->Go();
),TR("OK")))->Go();
// the filter view belongs to the moved filter // the filter view belongs to the moved filter
if (fFilterView && fFilterView->fIndex == -1) if (fFilterView && fFilterView->fIndex == -1)
SelectFilter(-1); SelectFilter(-1);
fListView->RemoveItem(msg->FindInt32("to")); fListView->RemoveItem(msg->FindInt32("to"));
} } else if (fFilterView) {
else if (fFilterView)
{
int32 index = fFilterView->fIndex; int32 index = fFilterView->fIndex;
if (index == -1) if (index == -1) {
// the view belongs to the moved filter // the view belongs to the moved filter
fFilterView->fIndex = to; fFilterView->fIndex = to;
else if (index > from && index < to) } else if (index > from && index < to) {
// the view belongs to another filter (between the // the view belongs to another filter (between the
// 'from' & 'to' positions) - all others can keep // 'from' & 'to' positions) - all others can keep
// their index value // their index value
fFilterView->fIndex--; fFilterView->fIndex--;
} }
} }
}
break; break;
} }
default: default:
@ -851,4 +862,3 @@ void FiltersConfigView::MessageReceived(BMessage *msg)
break; 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. * Copyright 2001-2003 Dr. Zoidberg Enterprises. All rights reserved.
* *
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
//! main E-Mail config window //! main E-Mail config window
#include "ConfigWindow.h" #include "ConfigWindow.h"
#include "CenterContainer.h" #include "CenterContainer.h"
#include "Account.h" #include "Account.h"
@ -244,12 +246,12 @@ class AboutTextView : public BTextView
}; };
//--------------------------------------------------------------------------------------
// #pragma mark - // #pragma mark -
ConfigWindow::ConfigWindow() 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), B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE),
fLastSelectedAccount(NULL), fLastSelectedAccount(NULL),
fSaveSettings(false) fSaveSettings(false)
@ -257,43 +259,46 @@ ConfigWindow::ConfigWindow()
// create controls // create controls
BRect rect(Bounds()); 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)); top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(top); AddChild(top);
// determine font height // determine font height
font_height fontHeight; font_height fontHeight;
top->GetFontHeight(&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; rect.InsetBy(5, 5); rect.bottom -= 11 + height;
BTabView *tabView = new BTabView(rect,NULL); BTabView *tabView = new BTabView(rect, NULL);
BView *view; BView *view;
rect = tabView->Bounds(); rect.bottom -= tabView->TabHeight() + 4; rect = tabView->Bounds();
tabView->AddTab(view = new BView(rect,NULL,B_FOLLOW_ALL,0)); rect.bottom -= tabView->TabHeight() + 4;
tabView->TabAt(0)->SetLabel(TR ("Accounts")); tabView->AddTab(view = new BView(rect, NULL, B_FOLLOW_ALL, 0));
tabView->TabAt(0)->SetLabel(TR("Accounts"));
view->SetViewColor(top->ViewColor()); view->SetViewColor(top->ViewColor());
// accounts listview // accounts listview
rect = view->Bounds().InsetByCopy(8,8); rect = view->Bounds().InsetByCopy(8, 8);
rect.right = 140 - B_V_SCROLL_BAR_WIDTH; rect.right = 140 - B_V_SCROLL_BAR_WIDTH;
rect.bottom -= height + 12; rect.bottom -= height + 12;
fAccountsListView = new AccountsListView(rect); 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.right += B_V_SCROLL_BAR_WIDTH;
rect.top = rect.bottom + 8; rect.bottom = rect.top + height; rect.top = rect.bottom + 8; rect.bottom = rect.top + height;
BRect sizeRect = rect; BRect sizeRect = rect;
sizeRect.right = sizeRect.left + 30 + view->StringWidth(TR ("Add")); sizeRect.right = sizeRect.left + 30 + view->StringWidth(TR("Add"));
view->AddChild(new BButton(sizeRect,NULL,TR ("Add"), view->AddChild(new BButton(sizeRect, NULL, TR("Add"),
new BMessage(kMsgAddAccount),B_FOLLOW_BOTTOM)); new BMessage(kMsgAddAccount), B_FOLLOW_BOTTOM));
sizeRect.left = sizeRect.right+3; sizeRect.left = sizeRect.right+3;
sizeRect.right = sizeRect.left + 30 + view->StringWidth(TR ("Remove")); sizeRect.right = sizeRect.left + 30 + view->StringWidth(TR("Remove"));
view->AddChild(fRemoveButton = new BButton(sizeRect,NULL,TR ("Remove"), view->AddChild(fRemoveButton = new BButton(sizeRect, NULL, TR("Remove"),
new BMessage(kMsgRemoveAccount),B_FOLLOW_BOTTOM)); new BMessage(kMsgRemoveAccount), B_FOLLOW_BOTTOM));
// accounts config view // accounts config view
rect = view->Bounds(); rect = view->Bounds();
@ -305,92 +310,97 @@ ConfigWindow::ConfigWindow()
// general settings // 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->AddTab(view = new CenterContainer(rect));
tabView->TabAt(1)->SetLabel(TR ("Settings")); tabView->TabAt(1)->SetLabel(TR("Settings"));
rect = view->Bounds().InsetByCopy(8,8); rect = view->Bounds().InsetByCopy(8, 8);
rect.right -= 1; rect.bottom = rect.top + height * 5 + 15; rect.right -= 1;
rect.bottom = rect.top + height * 5 + 15;
BBox *box = new BBox(rect); BBox *box = new BBox(rect);
box->SetLabel(TR ("Mail checking")); box->SetLabel(TR("Mail checking"));
view->AddChild(box); view->AddChild(box);
rect = box->Bounds().InsetByCopy(8,8); rect = box->Bounds().InsetByCopy(8, 8);
rect.top += 7; rect.bottom = rect.top + height + 5; rect.top += 7;
BRect tile = rect.OffsetByCopy(0,1); rect.bottom = rect.top + height + 5;
int32 labelWidth = (int32)view->StringWidth(TR ("Check every"))+6; BRect tile = rect.OffsetByCopy(0, 1);
int32 labelWidth = (int32)view->StringWidth(TR("Check every")) + 6;
tile.right = 80 + labelWidth; tile.right = 80 + labelWidth;
fIntervalControl = new BTextControl(tile,"time",TR ("Check every"), fIntervalControl = new BTextControl(tile, "time", TR("Check every"), NULL,
NULL,NULL); NULL);
fIntervalControl->SetDivider(labelWidth); fIntervalControl->SetDivider(labelWidth);
box->AddChild(fIntervalControl); box->AddChild(fIntervalControl);
BPopUpMenu *frequencyPopUp = new BPopUpMenu(B_EMPTY_STRING); BPopUpMenu *frequencyPopUp = new BPopUpMenu(B_EMPTY_STRING);
const char *frequencyStrings[] = { const char *frequencyStrings[] = {
TR ("never"), TR("never"),
TR ("minutes"), TR("minutes"),
TR ("hours"), TR("hours"),
TR ("days")}; TR("days")};
BMenuItem *item; BMenuItem *item;
for (int32 i = 0;i < 4;i++) for (int32 i = 0; i < 4; i++) {
{ frequencyPopUp->AddItem(item = new BMenuItem(frequencyStrings[i],
frequencyPopUp->AddItem(item = new BMenuItem(frequencyStrings[i],new BMessage(kMsgIntervalUnitChanged))); new BMessage(kMsgIntervalUnitChanged)));
if (i == 1) if (i == 1)
item->SetMarked(true); 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); 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); fIntervalUnitField->SetDivider(0.0);
box->AddChild(fIntervalUnitField); box->AddChild(fIntervalUnitField);
rect.OffsetBy(0,height + 9); rect.bottom -= 2; rect.OffsetBy(0,height + 9);
fPPPActiveCheckBox = new BCheckBox(rect,"ppp active", rect.bottom -= 2;
TR ("Only when dial-up is connected"), NULL); fPPPActiveCheckBox = new BCheckBox(rect, "ppp active",
TR("Only when dial-up is connected"), NULL);
box->AddChild(fPPPActiveCheckBox); box->AddChild(fPPPActiveCheckBox);
rect.OffsetBy(0,height + 9); rect.bottom -= 2; rect.OffsetBy(0,height + 9);
fPPPActiveSendCheckBox = new BCheckBox(rect,"ppp activesend", rect.bottom -= 2;
TR ("Schedule outgoing mail when dial-up is disconnected"), NULL); fPPPActiveSendCheckBox = new BCheckBox(rect, "ppp activesend",
TR("Schedule outgoing mail when dial-up is disconnected"), NULL);
box->AddChild(fPPPActiveSendCheckBox); box->AddChild(fPPPActiveSendCheckBox);
// Miscellaneous settings box // 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 = new BBox(rect);
box->SetLabel(TR ("Miscellaneous")); box->SetLabel(TR("Miscellaneous"));
view->AddChild(box); view->AddChild(box);
BPopUpMenu *statusPopUp = new BPopUpMenu(B_EMPTY_STRING); BPopUpMenu *statusPopUp = new BPopUpMenu(B_EMPTY_STRING);
const char *statusModes[] = { const char *statusModes[] = {
TR ("Never"), TR("Never"),
TR ("While sending"), TR("While sending"),
TR ("While sending and receiving"), TR("While sending and receiving"),
TR ("Always")}; TR("Always")};
BMessage *msg; BMessage *msg;
for (int32 i = 0;i < 4;i++) for (int32 i = 0; i < 4; i++) {
{ statusPopUp->AddItem(item = new BMenuItem(statusModes[i],
statusPopUp->AddItem(item = new BMenuItem(statusModes[i],msg = new BMessage(kMsgShowStatusWindowChanged))); msg = new BMessage(kMsgShowStatusWindowChanged)));
msg->AddInt32("ShowStatusWindow",i); msg->AddInt32("ShowStatusWindow", i);
if (i == 0) if (i == 0)
item->SetMarked(true); item->SetMarked(true);
} }
rect = box->Bounds().InsetByCopy(8,8); rect = box->Bounds().InsetByCopy(8,8);
rect.top += 7; rect.top += 7;
rect.bottom = rect.top + height + 5; rect.bottom = rect.top + height + 5;
labelWidth = (int32)view->StringWidth( labelWidth
TR ("Show connection status window:")) + 8; = (int32)view->StringWidth(TR("Show connection status window:")) + 8;
fStatusModeField = new BMenuField(rect,"show status", fStatusModeField = new BMenuField(rect, "show status",
TR ("Show connection status window:"), TR("Show connection status window:"), statusPopUp);
statusPopUp);
fStatusModeField->SetDivider(labelWidth); fStatusModeField->SetDivider(labelWidth);
box->AddChild(fStatusModeField); box->AddChild(fStatusModeField);
rect = fStatusModeField->Frame();; rect = fStatusModeField->Frame();;
rect.OffsetBy(0, rect.Height() + 10); rect.OffsetBy(0, rect.Height() + 10);
BButton *button = new BButton(rect,B_EMPTY_STRING, BButton *button = new BButton(rect, B_EMPTY_STRING,
TR ("Edit mailbox menu…"), TR("Edit mailbox menu…"), msg = new BMessage(B_REFS_RECEIVED));
msg = new BMessage(B_REFS_RECEIVED));
button->ResizeToPreferred(); button->ResizeToPreferred();
box->AddChild(button); box->AddChild(button);
button->SetTarget(BMessenger("application/x-vnd.Be-TRAK")); button->SetTarget(BMessenger("application/x-vnd.Be-TRAK"));
@ -409,8 +419,8 @@ ConfigWindow::ConfigWindow()
rect = button->Frame(); rect = button->Frame();
rect.OffsetBy(rect.Width() + 30,0); rect.OffsetBy(rect.Width() + 30,0);
fAutoStartCheckBox = new BCheckBox(rect,"start daemon", fAutoStartCheckBox = new BCheckBox(rect, "start daemon",
TR ("Start mail services on startup"),NULL); TR("Start mail services on startup"), NULL);
fAutoStartCheckBox->ResizeToPreferred(); fAutoStartCheckBox->ResizeToPreferred();
box->AddChild(fAutoStartCheckBox); box->AddChild(fAutoStartCheckBox);
@ -419,20 +429,19 @@ ConfigWindow::ConfigWindow()
top->AddChild(tabView); top->AddChild(tabView);
rect = tabView->Frame(); rect = tabView->Frame();
rect.top = rect.bottom + 5; rect.bottom = rect.top + height + 5; rect.top = rect.bottom + 5;
BButton *saveButton = new BButton(rect,"apply", rect.bottom = rect.top + height + 5;
TR ("Apply"), BButton *saveButton = new BButton(rect, "apply", TR("Apply"),
new BMessage(kMsgSaveSettings)); new BMessage(kMsgSaveSettings));
float w,h; float w,h;
saveButton->GetPreferredSize(&w,&h); saveButton->GetPreferredSize(&w, &h);
saveButton->ResizeTo(w,h); saveButton->ResizeTo(w, h);
saveButton->MoveTo(rect.right - w, rect.top); saveButton->MoveTo(rect.right - w, rect.top);
top->AddChild(saveButton); top->AddChild(saveButton);
BButton *revertButton = new BButton(rect,"revert", BButton *revertButton = new BButton(rect, "revert", TR("Revert"),
TR ("Revert"),
new BMessage(kMsgRevertSettings)); new BMessage(kMsgRevertSettings));
revertButton->GetPreferredSize(&w,&h); revertButton->GetPreferredSize(&w, &h);
revertButton->ResizeTo(w,h); revertButton->ResizeTo(w,h);
revertButton->MoveTo(saveButton->Frame().left - 25 - w, rect.top); revertButton->MoveTo(saveButton->Frame().left - 25 - w, rect.top);
top->AddChild(revertButton); top->AddChild(revertButton);
@ -457,9 +466,11 @@ ConfigWindow::MakeHowToView()
BResources *resources = BApplication::AppResources(); BResources *resources = BApplication::AppResources();
if (resources) { if (resources) {
size_t length; 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) { 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) { if (bitmap && bitmap->InitCheck() == B_OK) {
// copy and enlarge a 32x32 8-bit bitmap // copy and enlarge a 32x32 8-bit bitmap
char *bits = (char *)bitmap->Bits(); char *bits = (char *)bitmap->Bits();
@ -481,7 +492,8 @@ ConfigWindow::MakeHowToView()
BFile appFile(&info.ref, B_READ_ONLY); BFile appFile(&info.ref, B_READ_ONLY);
BAppFileInfo appFileInfo(&appFile); BAppFileInfo appFileInfo(&appFile);
if (appFileInfo.InitCheck() == B_OK) { 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) { if (appFileInfo.GetIcon(bitmap, B_LARGE_ICON) == B_OK) {
fConfigView->AddChild(new BitmapView(bitmap)); fConfigView->AddChild(new BitmapView(bitmap));
} else } else
@ -491,14 +503,13 @@ ConfigWindow::MakeHowToView()
#endif // HAIKU_TARGET_PLATFORM_HAIKU #endif // HAIKU_TARGET_PLATFORM_HAIKU
BRect rect = fConfigView->Bounds(); 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->SetViewColor(fConfigView->Parent()->ViewColor());
text->SetAlignment(B_ALIGN_CENTER); text->SetAlignment(B_ALIGN_CENTER);
text->SetText( text->SetText(TR("\n\nCreate a new account with the Add button.\n\n"
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" "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(); rect = text->Bounds();
text->ResizeTo(rect.Width(), text->TextHeight(0, 42)); text->ResizeTo(rect.Width(), text->TextHeight(0, 42));
text->SetTextRect(rect); text->SetTextRect(rect);
@ -525,8 +536,8 @@ ConfigWindow::LoadSettings()
// move own window // move own window
MoveTo(settings.ConfigWindowFrame().LeftTop()); MoveTo(settings.ConfigWindowFrame().LeftTop());
} else { } else {
fprintf(stderr, TR("Error retrieving general settings: %s\n" fprintf(stderr, TR("Error retrieving general settings: %s\n"),
), strerror(status)); strerror(status));
} }
BScreen screen(this); BScreen screen(this);
@ -555,7 +566,8 @@ ConfigWindow::SaveSettings()
float interval; float interval;
sscanf(fIntervalControl->Text(),"%f",&interval); sscanf(fIntervalControl->Text(),"%f",&interval);
float multiplier = 0; float multiplier = 0;
switch (fIntervalUnitField->Menu()->IndexOf(fIntervalUnitField->Menu()->FindMarked())) { switch (fIntervalUnitField->Menu()->IndexOf(
fIntervalUnitField->Menu()->FindMarked())) {
case 1: // minutes case 1: // minutes
multiplier = 60; multiplier = 60;
break; break;
@ -572,12 +584,16 @@ ConfigWindow::SaveSettings()
BMailSettings settings; BMailSettings settings;
if (fSaveSettings) { if (fSaveSettings) {
settings.SetAutoCheckInterval(time * 1e6); settings.SetAutoCheckInterval(time * 1e6);
settings.SetCheckOnlyIfPPPUp(fPPPActiveCheckBox->Value() == B_CONTROL_ON); settings.SetCheckOnlyIfPPPUp(fPPPActiveCheckBox->Value()
settings.SetSendOnlyIfPPPUp(fPPPActiveSendCheckBox->Value() == B_CONTROL_ON); == B_CONTROL_ON);
settings.SetDaemonAutoStarts(fAutoStartCheckBox->Value() == B_CONTROL_ON); settings.SetSendOnlyIfPPPUp(fPPPActiveSendCheckBox->Value()
== B_CONTROL_ON);
settings.SetDaemonAutoStarts(fAutoStartCheckBox->Value()
== B_CONTROL_ON);
// status mode (alway, fetching/retrieving, ...) // status mode (alway, fetching/retrieving, ...)
int32 index = fStatusModeField->Menu()->IndexOf(fStatusModeField->Menu()->FindMarked()); int32 index = fStatusModeField->Menu()->IndexOf(
fStatusModeField->Menu()->FindMarked());
settings.SetShowStatusWindow(index); settings.SetShowStatusWindow(index);
} else { } else {
@ -639,10 +655,10 @@ ConfigWindow::MessageReceived(BMessage *msg)
case kMsgAddAccount: case kMsgAddAccount:
{ {
frame = Frame(); 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); frame.top + (frame.Width() - autoConfigRect.Height()) / 2);
autoConfigWindow = new AutoConfigWindow(autoConfigRect, autoConfigWindow = new AutoConfigWindow(autoConfigRect, this);
this);
autoConfigWindow->Show(); autoConfigWindow->Show();
break; break;
} }
@ -650,8 +666,9 @@ ConfigWindow::MessageReceived(BMessage *msg)
{ {
int32 index = fAccountsListView->CurrentSelection(); int32 index = fAccountsListView->CurrentSelection();
if (index >= 0) { if (index >= 0) {
AccountItem *item = (AccountItem *)fAccountsListView->ItemAt(index); AccountItem *item = (AccountItem *)fAccountsListView->ItemAt(
if (item) { index);
if (item != NULL) {
item->account->Remove(item->type); item->account->Remove(item->type);
MakeHowToView(); MakeHowToView();
} }
@ -731,7 +748,8 @@ ConfigWindow::SetToGeneralSettings(BMailSettings *settings)
fAutoStartCheckBox->SetValue(settings->DaemonAutoStarts()); fAutoStartCheckBox->SetValue(settings->DaemonAutoStarts());
if (BMenuItem *item = fStatusModeField->Menu()->ItemAt(settings->ShowStatusWindow())) if (BMenuItem *item
= fStatusModeField->Menu()->ItemAt(settings->ShowStatusWindow()))
item->SetMarked(true); item->SetMarked(true);
return B_OK; return B_OK;
@ -748,14 +766,13 @@ ConfigWindow::RevertToLastSettings()
settings.SetStatusWindowLook(settings.StatusWindowLook()); settings.SetStatusWindowLook(settings.StatusWindowLook());
status_t status = SetToGeneralSettings(&settings); status_t status = SetToGeneralSettings(&settings);
if (status != B_OK) if (status != B_OK) {
{
char text[256]; char text[256];
sprintf(text, sprintf(text, TR("\nThe general settings couldn't be reverted.\n\n"
TR ("\nThe general settings couldn't be reverted.\n\n"
"Error retrieving general settings:\n%s\n"), "Error retrieving general settings:\n%s\n"),
strerror(status)); 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 // revert account data
@ -769,4 +786,3 @@ ConfigWindow::RevertToLastSettings()
if (fConfigView->CountChildren() == 0) if (fConfigView->CountChildren() == 0)
MakeHowToView(); MakeHowToView();
} }