* Reverted accidental commit to the wrong branch.

git-svn-id: file:///srv/svn/repos/haiku/haiku/branches/releases/r1alpha3@42244 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2011-06-19 14:40:37 +00:00
parent c521b159e6
commit b031258f27
2 changed files with 89 additions and 97 deletions

View File

@ -3,8 +3,6 @@
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de> * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "AutoConfigView.h" #include "AutoConfigView.h"
#include <Catalog.h> #include <Catalog.h>
@ -140,7 +138,7 @@ AutoConfigView::GetBasicAccountInfo(account_info &info)
info.inboundType = IMAP; info.inboundType = IMAP;
else else
info.inboundType = POP; info.inboundType = POP;
info.outboundProtocol = fSMTPAddonRef; info.outboundProtocol = fSMTPAddonRef;
info.name = fNameView->Text(); info.name = fNameView->Text();
info.accountName = fAccountNameView->Text(); info.accountName = fAccountNameView->Text();
@ -166,7 +164,7 @@ AutoConfigView::SetupProtocolView(BRect rect)
path.Append("mail_daemon"); path.Append("mail_daemon");
path.Append("inbound_protocols"); path.Append("inbound_protocols");
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)
@ -198,27 +196,27 @@ AutoConfigView::SetupProtocolView(BRect rect)
status_t status_t
AutoConfigView::GetSMTPAddonRef(entry_ref *ref) AutoConfigView::GetSMTPAddonRef(entry_ref *ref)
{ {
directory_which which[] = { for (int i = 0; i < 2; i++) {
B_USER_ADDONS_DIRECTORY,
B_BEOS_ADDONS_DIRECTORY
};
for (size_t i = 0; i < sizeof(which) / sizeof(which[0]); i++) {
BPath path; BPath path;
status_t status = find_directory(which[i], &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 B_ERROR; return B_ERROR;
}
path.Append("mail_daemon"); path.Append("mail_daemon");
path.Append("outbound_protocols"); path.Append("outbound_protocols");
path.Append("SMTP");
BDirectory dir(path.Path());
BEntry entry(path.Path());
if (entry.Exists() && entry.GetRef(ref) == B_OK) while (dir.GetNextRef(ref) == B_OK)
{
return B_OK; return B_OK;
}
} }
return B_FILE_NOT_FOUND; return B_ERROR;
} }
@ -271,23 +269,19 @@ AutoConfigView::IsValidMailAddress(BString email)
email.CopyInto(provider, atPos + 1, email.Length() - atPos); email.CopyInto(provider, atPos + 1, email.Length() - atPos);
if (provider.FindLast(".") < 0) if (provider.FindLast(".") < 0)
return false; return false;
return true; return true;
} }
// #pragma mark -
ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info) ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info)
: : BView(rect, NULL,B_FOLLOW_ALL,0),
BView(rect, NULL,B_FOLLOW_ALL,0), fInboundAccount(true),
fInboundAccount(true), fOutboundAccount(true),
fOutboundAccount(true), fInboundAuthMenu(NULL),
fInboundAuthMenu(NULL), fOutboundAuthMenu(NULL),
fOutboundAuthMenu(NULL), fInboundEncrItemStart(NULL),
fInboundEncrItemStart(NULL), fOutboundEncrItemStart(NULL),
fOutboundEncrItemStart(NULL), fImageId(-1)
fImageId(-1)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@ -302,7 +296,7 @@ ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info)
boxRect.bottom -= 5; boxRect.bottom -= 5;
BBox *box = new BBox(boxRect); BBox *box = new BBox(boxRect);
box->SetLabel(B_TRANSLATE("Incoming")); box->SetLabel(B_TRANSLATE("Inbound"));
AddChild(box); AddChild(box);
BString serverName; BString serverName;
@ -317,10 +311,10 @@ ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info)
fInboundNameView->SetDivider(divider); fInboundNameView->SetDivider(divider);
box->AddChild(fInboundNameView); box->AddChild(fInboundNameView);
GetAuthEncrMenu(info.inboundProtocol, &fInboundAuthMenu, GetAuthEncrMenu(info.inboundProtocol, &fInboundAuthMenu,
&fInboundEncryptionMenu); &fInboundEncryptionMenu);
if (fInboundAuthMenu != NULL) { if (fInboundAuthMenu) {
int authID = info.providerInfo.authentification_pop; int authID = info.providerInfo.authentification_pop;
if (info.inboundType == POP) if (info.inboundType == POP)
fInboundAuthMenu->Menu()->ItemAt(authID)->SetMarked(true); fInboundAuthMenu->Menu()->ItemAt(authID)->SetMarked(true);
@ -332,16 +326,16 @@ ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info)
if (fInboundEncryptionMenu) { if (fInboundEncryptionMenu) {
BMenuItem *item = NULL; BMenuItem *item = NULL;
if (info.inboundType == POP) { if (info.inboundType == POP) {
item = fInboundEncryptionMenu->Menu()->ItemAt( item = fInboundEncryptionMenu->Menu()
info.providerInfo.ssl_pop); ->ItemAt(info.providerInfo.ssl_pop);
if (item != NULL) if (item)
item->SetMarked(true); item->SetMarked(true);
fInboundEncryptionMenu->MoveTo(10, 80); fInboundEncryptionMenu->MoveTo(10, 80);
} }
if (info.inboundType == IMAP) { if (info.inboundType == IMAP) {
item = fInboundEncryptionMenu->Menu()->ItemAt( item = fInboundEncryptionMenu->Menu()->ItemAt(
info.providerInfo.ssl_imap); info.providerInfo.ssl_imap);
if (item != NULL) if (item)
item->SetMarked(true); item->SetMarked(true);
fInboundEncryptionMenu->MoveTo(10, 50); fInboundEncryptionMenu->MoveTo(10, 50);
} }
@ -349,7 +343,7 @@ ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info)
box->AddChild(fInboundEncryptionMenu); box->AddChild(fInboundEncryptionMenu);
fInboundEncryptionMenu->SetDivider(divider); fInboundEncryptionMenu->SetDivider(divider);
} }
if (!fInboundAccount) { if (!fInboundAccount) {
fInboundNameView->SetEnabled(false); fInboundNameView->SetEnabled(false);
if (fInboundAuthMenu) if (fInboundAuthMenu)
@ -362,7 +356,7 @@ ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info)
boxRect.top += 5; boxRect.top += 5;
box = new BBox(boxRect); box = new BBox(boxRect);
box->SetLabel(B_TRANSLATE("Outgoing")); box->SetLabel(B_TRANSLATE("Outbound"));
AddChild(box); AddChild(box);
serverName = info.providerInfo.smtp_server; serverName = info.providerInfo.smtp_server;
@ -372,23 +366,23 @@ ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info)
fOutboundNameView->SetDivider(divider); fOutboundNameView->SetDivider(divider);
box->AddChild(fOutboundNameView); box->AddChild(fOutboundNameView);
GetAuthEncrMenu(info.outboundProtocol, &fOutboundAuthMenu, GetAuthEncrMenu(info.outboundProtocol, &fOutboundAuthMenu,
&fOutboundEncryptionMenu); &fOutboundEncryptionMenu);
if (fOutboundAuthMenu != NULL) { if (fOutboundAuthMenu) {
BMenuItem *item = fOutboundAuthMenu->Menu()->ItemAt( BMenuItem *item = fOutboundAuthMenu->Menu()->ItemAt(
info.providerInfo.authentification_smtp); info.providerInfo.authentification_smtp);
if (item != NULL) if (item)
item->SetMarked(true); item->SetMarked(true);
fOutboundAuthItemStart = item; fOutboundAuthItemStart = item;
box->AddChild(fOutboundAuthMenu); box->AddChild(fOutboundAuthMenu);
fOutboundAuthMenu->SetDivider(divider); fOutboundAuthMenu->SetDivider(divider);
fOutboundAuthMenu->MoveTo(10, 50); fOutboundAuthMenu->MoveTo(10, 50);
} }
if (fOutboundEncryptionMenu != NULL) { if (fOutboundEncryptionMenu) {
BMenuItem *item = fOutboundEncryptionMenu->Menu()->ItemAt( BMenuItem *item = fOutboundEncryptionMenu->Menu()->ItemAt(
info.providerInfo.ssl_smtp); info.providerInfo.ssl_smtp);
if (item != NULL) if (item)
item->SetMarked(true); item->SetMarked(true);
fOutboundEncrItemStart = item; fOutboundEncrItemStart = item;
box->AddChild(fOutboundEncryptionMenu); box->AddChild(fOutboundEncryptionMenu);
@ -401,7 +395,7 @@ ServerSettingsView::ServerSettingsView(BRect rect, const account_info &info)
if (fOutboundAuthMenu) if (fOutboundAuthMenu)
fOutboundAuthMenu->SetEnabled(false); fOutboundAuthMenu->SetEnabled(false);
} }
} }
@ -420,47 +414,43 @@ ServerSettingsView::GetServerInfo(account_info &info)
{ {
if (info.inboundType == IMAP) { if (info.inboundType == IMAP) {
info.providerInfo.imap_server = fInboundNameView->Text(); info.providerInfo.imap_server = fInboundNameView->Text();
if (fInboundEncryptionMenu != NULL) { if (fInboundEncryptionMenu) {
BMenuItem* item = fInboundEncryptionMenu->Menu()->FindMarked(); BMenuItem* item = fInboundEncryptionMenu->Menu()->FindMarked();
if (item != NULL) { if (item)
info.providerInfo.ssl_imap info.providerInfo.ssl_imap = fInboundEncryptionMenu->Menu()
= fInboundEncryptionMenu->Menu()->IndexOf(item); ->IndexOf(item);
}
} }
} else { } else {
info.providerInfo.pop_server = fInboundNameView->Text(); info.providerInfo.pop_server = fInboundNameView->Text();
BMenuItem* item = NULL; BMenuItem* item = NULL;
if (fInboundAuthMenu != NULL) { if (fInboundAuthMenu) {
item = fInboundAuthMenu->Menu()->FindMarked(); item = fInboundAuthMenu->Menu()->FindMarked();
if (item != NULL) { if (item)
info.providerInfo.authentification_pop info.providerInfo.authentification_pop = fInboundAuthMenu
= fInboundAuthMenu->Menu()->IndexOf(item); ->Menu()
} ->IndexOf(item);
} }
if (fInboundEncryptionMenu != NULL) { if (fInboundEncryptionMenu) {
item = fInboundEncryptionMenu->Menu()->FindMarked(); item = fInboundEncryptionMenu->Menu()->FindMarked();
if (item != NULL) { if (item)
info.providerInfo.ssl_pop info.providerInfo.ssl_pop = fInboundEncryptionMenu->Menu()
= fInboundEncryptionMenu->Menu()->IndexOf(item); ->IndexOf(item);
}
} }
} }
info.providerInfo.smtp_server = fOutboundNameView->Text(); info.providerInfo.smtp_server = fOutboundNameView->Text();
BMenuItem* item = NULL; BMenuItem* item = NULL;
if (fOutboundAuthMenu != NULL) { if (fOutboundAuthMenu) {
item = fOutboundAuthMenu->Menu()->FindMarked(); item = fOutboundAuthMenu->Menu()->FindMarked();
if (item != NULL) { if (item)
info.providerInfo.authentification_smtp info.providerInfo.authentification_smtp = fOutboundAuthMenu->Menu()
= fOutboundAuthMenu->Menu()->IndexOf(item); ->IndexOf(item);
}
} }
if (fOutboundEncryptionMenu != NULL) { if (fOutboundEncryptionMenu) {
item = fOutboundEncryptionMenu->Menu()->FindMarked(); item = fOutboundEncryptionMenu->Menu()->FindMarked();
if (item != NULL) { if (item)
info.providerInfo.ssl_smtp info.providerInfo.ssl_smtp = fOutboundEncryptionMenu->Menu()
= fOutboundEncryptionMenu->Menu()->IndexOf(item); ->IndexOf(item);
}
} }
DetectMenuChanges(); DetectMenuChanges();
} }
@ -470,22 +460,22 @@ void
ServerSettingsView::DetectMenuChanges() ServerSettingsView::DetectMenuChanges()
{ {
bool changed = false; bool changed = false;
if (fInboundAuthMenu != NULL) { if (fInboundAuthMenu) {
BMenuItem *item = fInboundAuthMenu->Menu()->FindMarked(); BMenuItem *item = fInboundAuthMenu->Menu()->FindMarked();
if (fInboundAuthItemStart != item) if (fInboundAuthItemStart != item)
changed = true; changed = true;
} }
if (fInboundEncryptionMenu != NULL) { if (fInboundEncryptionMenu) {
BMenuItem *item = fInboundEncryptionMenu->Menu()->FindMarked(); BMenuItem *item = fInboundEncryptionMenu->Menu()->FindMarked();
if (fInboundEncrItemStart != item) if (fInboundEncrItemStart != item)
changed = true; changed = true;
} }
if (fOutboundAuthMenu != NULL) { if (fOutboundAuthMenu) {
BMenuItem *item = fOutboundAuthMenu->Menu()->FindMarked(); BMenuItem *item = fOutboundAuthMenu->Menu()->FindMarked();
if (fOutboundAuthItemStart != item) if (fOutboundAuthItemStart != item)
changed = true; changed = true;
} }
if (fOutboundEncryptionMenu != NULL) { if (fOutboundEncryptionMenu) {
BMenuItem *item = fOutboundEncryptionMenu->Menu()->FindMarked(); BMenuItem *item = fOutboundEncryptionMenu->Menu()->FindMarked();
if (fOutboundEncrItemStart != item) if (fOutboundEncrItemStart != item)
changed = true; changed = true;
@ -506,8 +496,8 @@ ServerSettingsView::GetAuthEncrMenu(entry_ref protocol,
BView *view = CreateConfigView(protocol, dummySettings.InboundSettings(), BView *view = CreateConfigView(protocol, dummySettings.InboundSettings(),
dummySettings, &fImageId); dummySettings, &fImageId);
*authField = (BMenuField *)view->FindView("auth_method"); *authField = (BMenuField *)(view->FindView("auth_method"));
*sslField = (BMenuField *)view->FindView("flavor"); *sslField = (BMenuField *)(view->FindView("flavor"));
view->RemoveChild(*authField); view->RemoveChild(*authField);
view->RemoveChild(*sslField); view->RemoveChild(*sslField);

View File

@ -55,10 +55,9 @@ AutoConfigWindow::AutoConfigWindow(BRect rect, ConfigWindow *parent)
fBackButton->SetEnabled(false); fBackButton->SetEnabled(false);
fRootView->AddChild(fBackButton); fRootView->AddChild(fBackButton);
buttonRect.left += 5 + buttonWidth; buttonRect.left+= 5 + buttonWidth;
buttonRect.right = buttonRect.left + buttonWidth; buttonRect.right = buttonRect.left + buttonWidth;
fNextButton = new BButton(buttonRect, "next", B_TRANSLATE("Next"), fNextButton = new BButton(buttonRect, "ok", B_TRANSLATE("OK"), new BMessage(kOkMsg));
new BMessage(kOkMsg));
fNextButton->MakeDefault(true); fNextButton->MakeDefault(true);
fRootView->AddChild(fNextButton); fRootView->AddChild(fNextButton);
@ -86,9 +85,10 @@ AutoConfigWindow::MessageReceived(BMessage* msg)
{ {
status_t status = B_ERROR; status_t status = B_ERROR;
BAlert* invalidMailAlert = NULL; BAlert* invalidMailAlert = NULL;
switch (msg->what)
switch (msg->what) { {
case kOkMsg: case kOkMsg:
{
if (fMainConfigState) { if (fMainConfigState) {
fMainView->GetBasicAccountInfo(fAccountInfo); fMainView->GetBasicAccountInfo(fAccountInfo);
if (!fMainView->IsValidMailAddress(fAccountInfo.email)) { if (!fMainView->IsValidMailAddress(fAccountInfo.email)) {
@ -100,9 +100,9 @@ AutoConfigWindow::MessageReceived(BMessage* msg)
if (fAutoConfigServer) { if (fAutoConfigServer) {
status = fAutoConfig.GetInfoFromMailAddress( status = fAutoConfig.GetInfoFromMailAddress(
fAccountInfo.email.String(), fAccountInfo.email.String(),
&fAccountInfo.providerInfo); &(fAccountInfo.providerInfo));
} }
if (status == B_OK) { if(status == B_OK){
fParentWindow->Lock(); fParentWindow->Lock();
GenerateBasicAccount(); GenerateBasicAccount();
fParentWindow->Unlock(); fParentWindow->Unlock();
@ -111,13 +111,13 @@ AutoConfigWindow::MessageReceived(BMessage* msg)
fMainConfigState = false; fMainConfigState = false;
fServerConfigState = true; fServerConfigState = true;
fMainView->Hide(); fMainView->Hide();
fServerView = new ServerSettingsView(fBoxRect, fAccountInfo); fServerView = new ServerSettingsView(fBoxRect, fAccountInfo);
fRootView->AddChild(fServerView); fRootView->AddChild(fServerView);
fBackButton->SetEnabled(true); fBackButton->SetEnabled(true);
fNextButton->SetLabel(B_TRANSLATE("Finish")); }
} else { else{
fServerView->GetServerInfo(fAccountInfo); fServerView->GetServerInfo(fAccountInfo);
fParentWindow->Lock(); fParentWindow->Lock();
GenerateBasicAccount(); GenerateBasicAccount();
@ -125,26 +125,28 @@ AutoConfigWindow::MessageReceived(BMessage* msg)
Quit(); Quit();
} }
break; break;
}
case kBackMsg: case kBackMsg:
if (fServerConfigState) { {
if(fServerConfigState){
fServerView->GetServerInfo(fAccountInfo); fServerView->GetServerInfo(fAccountInfo);
fMainConfigState = true; fMainConfigState = true;
fServerConfigState = false; fServerConfigState = false;
fRootView->RemoveChild(fServerView); fRootView->RemoveChild(fServerView);
delete fServerView; delete fServerView;
fMainView->Show(); fMainView->Show();
fBackButton->SetEnabled(false); fBackButton->SetEnabled(false);
} }
break; break;
}
case kServerChangedMsg: case kServerChangedMsg:
{
fAutoConfigServer = false; fAutoConfigServer = false;
break; break;
}
default: default:
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
break; break;
@ -152,8 +154,8 @@ AutoConfigWindow::MessageReceived(BMessage* msg)
} }
bool bool
AutoConfigWindow::QuitRequested() AutoConfigWindow::QuitRequested(void)
{ {
return true; return true;
} }
@ -162,7 +164,7 @@ AutoConfigWindow::QuitRequested()
BMailAccountSettings* BMailAccountSettings*
AutoConfigWindow::GenerateBasicAccount() AutoConfigWindow::GenerateBasicAccount()
{ {
if (!fAccount) { if(!fAccount) {
fParentWindow->Lock(); fParentWindow->Lock();
fAccount = fParentWindow->AddAccount(); fAccount = fParentWindow->AddAccount();
fParentWindow->Unlock(); fParentWindow->Unlock();