Reworked the mail preferences.

* Made it use the layout API.
* Removed options that no longer apply (dial-up, for example).
* Cleanup.
* There are a few issues left, though, for example, the BTextView is not
  correctly sized, and it currently crashes in the protocol panels.
This commit is contained in:
Axel Dörfler
2015-01-06 15:22:47 +01:00
parent 58b56ffc80
commit 5faab458af
10 changed files with 314 additions and 688 deletions
+2 -2
View File
@@ -505,8 +505,8 @@ ServerSettingsView::_GetAuthEncrMenu(entry_ref protocol,
BMenuField** authField, BMenuField** sslField) BMenuField** authField, BMenuField** sslField)
{ {
BMailAccountSettings dummySettings; BMailAccountSettings dummySettings;
BView *view = CreateConfigView(protocol, dummySettings.InboundSettings(), BView *view = new BStringView("", "Not here!");//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");
-105
View File
@@ -1,105 +0,0 @@
/* CenterContainer - a container which centers its contents in the middle
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
#include "CenterContainer.h"
#include <ObjectList.h>
CenterContainer::CenterContainer(BRect rect,bool centerHoriz)
: BView(rect,NULL,B_FOLLOW_ALL,0),
fSpacing(7),
fWidth(0),
fCenterHoriz(centerHoriz)
{
}
void CenterContainer::AttachedToWindow()
{
if (Parent() != NULL)
SetViewColor(Parent()->ViewColor());
}
void CenterContainer::AllAttached()
{
Layout();
}
void CenterContainer::FrameResized(float width,float height)
{
Layout();
}
void CenterContainer::GetPreferredSize(float *width, float *height)
{
// calculate dimensions (and, well, layout views)
if (fWidth == 0)
Layout();
if (width)
*width = fWidth;
if (height)
*height = fHeight;
}
void CenterContainer::Layout()
{
// compute the size of all views
fHeight = 0; fWidth = 0;
for (int32 i = 0;BView *view = ChildAt(i);i++)
{
if (i != 0) // the spacing between to items
fHeight += fSpacing;
fHeight += view->Bounds().Height();
if (view->Bounds().Width() > fWidth)
fWidth = view->Bounds().Width();
}
// layout views
float y = (Bounds().Height() - fHeight) / 2;
for (int32 i = 0;BView *view = ChildAt(i);i++)
{
view->MoveTo(fCenterHoriz ? (Bounds().Width() - view->Bounds().Width()) / 2
: view->Frame().left,
y);
y += view->Bounds().Height() + fSpacing;
}
}
void CenterContainer::SetSpacing(float spacing)
{
if (fSpacing == spacing)
return;
fSpacing = spacing;
Layout();
}
void CenterContainer::DeleteChildren()
{
// there happens some magic in DetachedFromWindow and therefore all views
// have to exist so delete them later...
// TODO: maybe rethink this
BObjectList<BView> temp;
// remove all child views
for (int32 i = CountChildren();i-- > 0;)
{
BView *view = ChildAt(i);
temp.AddItem(view);
RemoveChild(view);
}
for (int32 i = 0; i < temp.CountItems(); i++)
delete temp.ItemAt(i);
}
-31
View File
@@ -1,31 +0,0 @@
#ifndef CENTER_CONTAINER_H
#define CENTER_CONTAINER_H
/* CenterContainer - a container which centers its contents in the middle
**
** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
*/
#include <View.h>
class CenterContainer : public BView
{
public:
CenterContainer(BRect rect,bool centerHoriz = true);
virtual void AttachedToWindow();
virtual void AllAttached();
virtual void FrameResized(float width, float height);
virtual void GetPreferredSize(float *width, float *height);
void Layout();
void SetSpacing(float spacing);
void DeleteChildren();
private:
float fSpacing, fWidth, fHeight;
bool fCenterHoriz;
};
#endif /* CENTER_CONTAINER_H */
+71 -144
View File
@@ -10,22 +10,22 @@
#include "ConfigViews.h" #include "ConfigViews.h"
#include "CenterContainer.h"
#include <TextControl.h>
#include <ListView.h>
#include <PopUpMenu.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <Button.h>
#include <Looper.h>
#include <Path.h>
#include <Alert.h> #include <Alert.h>
#include <Button.h>
#include <Catalog.h>
#include <Directory.h>
#include <Entry.h> #include <Entry.h>
#include <FindDirectory.h> #include <FindDirectory.h>
#include <Directory.h> #include <ListView.h>
#include <Catalog.h> #include <LayoutBuilder.h>
#include <Locale.h> #include <Locale.h>
#include <Looper.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <Path.h>
#include <PopUpMenu.h>
#include <TextControl.h>
#include <string.h> #include <string.h>
@@ -45,72 +45,35 @@ const uint32 kMsgAccountNameChanged = 'anmc';
const uint32 kMsgProtocolChanged = 'prch'; const uint32 kMsgProtocolChanged = 'prch';
BView*
CreateConfigView(const entry_ref& addon, BMailProtocolSettings& settings,
BMailAccountSettings& accountSettings, image_id& image)
{
BView* (*instantiateConfig)(BMailProtocolSettings& settings,
BMailAccountSettings& accountSettings);
BPath path(&addon);
image = load_add_on(path.Path());
if (image < 0)
return NULL;
if (get_image_symbol(image, "instantiate_config_panel", B_SYMBOL_TYPE_TEXT,
(void **)&instantiateConfig) != B_OK) {
unload_add_on(image);
image = -1;
return NULL;
}
return instantiateConfig(settings, accountSettings);
}
// #pragma mark - // #pragma mark -
AccountConfigView::AccountConfigView(BRect rect, BMailAccountSettings* account) AccountConfigView::AccountConfigView(BMailAccountSettings* account)
: :
BBox(rect), BBox("account"),
fAccount(account) fAccount(account)
{ {
SetLabel(B_TRANSLATE("Account settings")); SetLabel(B_TRANSLATE("Account settings"));
rect = Bounds().InsetByCopy(8, 8); fNameControl = new BTextControl(NULL, B_TRANSLATE("Account name:"), NULL,
rect.top += 10; new BMessage(kMsgAccountNameChanged));
CenterContainer *view = new CenterContainer(rect, false); fRealNameControl = new BTextControl(NULL, B_TRANSLATE("Real name:"), NULL,
view->SetSpacing(5); NULL);
fReturnAddressControl = new BTextControl(NULL,
B_TRANSLATE("Return address:"), NULL, NULL);
// determine font height BView* contents = new BView(NULL, 0);
font_height fontHeight; AddChild(contents);
view->GetFontHeight(&fontHeight);
int32 height = (int32)(fontHeight.ascent + fontHeight.descent
+ fontHeight.leading) + 5;
rect = view->Bounds(); BLayoutBuilder::Grid<>(contents, 0.f)
rect.bottom = height + 5; .SetInsets(B_USE_DEFAULT_SPACING)
.Add(fNameControl->CreateLabelLayoutItem(), 0, 0)
float labelWidth = view->StringWidth(B_TRANSLATE("Account name:")) + 6; .Add(fNameControl->CreateTextViewLayoutItem(), 1, 0)
.Add(fRealNameControl->CreateLabelLayoutItem(), 0, 1)
view->AddChild(fNameControl = new BTextControl(rect, NULL, .Add(fRealNameControl->CreateTextViewLayoutItem(), 1, 1)
B_TRANSLATE("Account name:"), NULL, .Add(fReturnAddressControl->CreateLabelLayoutItem(), 0, 2)
new BMessage(kMsgAccountNameChanged))); .Add(fReturnAddressControl->CreateTextViewLayoutItem(), 1, 2)
fNameControl->SetDivider(labelWidth); .AddGlue(0, 3);
view->AddChild(fRealNameControl = new BTextControl(rect, NULL,
B_TRANSLATE("Real name:"), NULL, NULL));
fRealNameControl->SetDivider(labelWidth);
view->AddChild(fReturnAddressControl = new BTextControl(rect, NULL,
B_TRANSLATE("Return address:"), NULL, NULL));
fReturnAddressControl->SetDivider(labelWidth);
// control->TextView()->HideTyping(true);
float w, h;
view->GetPreferredSize(&w, &h);
ResizeTo(w + 15, h + 22);
view->ResizeTo(w, h);
AddChild(view);
} }
@@ -154,46 +117,41 @@ AccountConfigView::UpdateViews()
} }
// #pragma mark - // #pragma mark -
InProtocolsConfigView::InProtocolsConfigView(BMailAccountSettings* account) ProtocolConfigView::ProtocolConfigView(BMailAccountSettings& accountSettings,
const entry_ref& ref, BMailProtocolSettings& settings)
: :
BBox(BRect(0, 0, 100, 100)), BBox("protocol"),
fAccount(account), fSettings(settings),
fConfigView(NULL) fConfigView(NULL)
{ {
BString label = "Can't find protocol."; status_t status = _CreateConfigView(ref, settings, accountSettings);
entry_ref protocol = fAccount->InboundAddOnRef(); BView* view = fConfigView;
BMailProtocolSettings& inboundSettings = fAccount->InboundSettings();
fConfigView = CreateConfigView(protocol, inboundSettings, *account,
fImageID);
if (fConfigView != NULL) { if (fConfigView != NULL) {
float w = fConfigView->Bounds().Width(); SetLabel(ref.name);
float h = fConfigView->Bounds().Height(); } else {
fConfigView->MoveTo(3, 13); BString text(B_TRANSLATE("An error occurred while creating the "
ResizeTo(w + 6, h + 16); "config view: %error."));
AddChild(fConfigView); text.ReplaceAll("%error", strerror(status));
view = new BStringView("error", text.String());
fConfigView->MoveTo(3, 21); SetLabel(B_TRANSLATE("Error!"));
ResizeBy(0, 8);
if (CenterContainer *container
= dynamic_cast<CenterContainer *>(Parent())) {
container->Layout();
}
label = protocol.name;
fConfigView->MoveTo(3, 21);
ResizeBy(0, 8);
} }
SetLabel(label);
BView* contents = new BView(NULL, 0);
AddChild(contents);
BLayoutBuilder::Group<>(contents, B_VERTICAL)
.SetInsets(B_USE_DEFAULT_SPACING)
.Add(view);
} }
void void
InProtocolsConfigView::DetachedFromWindow() ProtocolConfigView::DetachedFromWindow()
{ {
if (fConfigView == NULL) if (fConfigView == NULL)
return; return;
@@ -201,65 +159,34 @@ InProtocolsConfigView::DetachedFromWindow()
if (fConfigView->Archive(&settings) != B_OK) if (fConfigView->Archive(&settings) != B_OK)
return; return;
fAccount->InboundSettings().MakeEmpty(); fSettings.MakeEmpty();
fAccount->InboundSettings().Append(settings); fSettings.Append(settings);
RemoveChild(fConfigView); RemoveChild(fConfigView);
delete fConfigView; delete fConfigView;
fConfigView = NULL; fConfigView = NULL;
unload_add_on(fImageID); unload_add_on(fImage);
} }
OutProtocolsConfigView::OutProtocolsConfigView(BMailAccountSettings* account) status_t
: ProtocolConfigView::_CreateConfigView(const entry_ref& ref,
BBox(BRect(0, 0, 100, 100)), BMailProtocolSettings& settings, BMailAccountSettings& accountSettings)
fAccount(account),
fConfigView(NULL)
{ {
BString label = "Can't find protocol."; BView* (*instantiateConfig)(BMailProtocolSettings& settings,
entry_ref protocol = fAccount->OutboundAddOnRef(); BMailAccountSettings& accountSettings);
BMailProtocolSettings& outboundSettings = fAccount->OutboundSettings(); BPath path(&ref);
fConfigView = CreateConfigView(protocol, outboundSettings, *account, image_id image = load_add_on(path.Path());
fImageID); if (image < 0)
return image;
if (fConfigView != NULL) { if (get_image_symbol(image, "instantiate_protocol_config_panel",
float w = fConfigView->Bounds().Width(); B_SYMBOL_TYPE_TEXT, (void**)&instantiateConfig) != B_OK) {
float h = fConfigView->Bounds().Height(); unload_add_on(image);
fConfigView->MoveTo(3, 13); return B_BAD_VALUE;
ResizeTo(w + 6, h + 16);
AddChild(fConfigView);
fConfigView->MoveTo(3, 21);
ResizeBy(0, 8);
if (CenterContainer *container
= dynamic_cast<CenterContainer *>(Parent())) {
container->Layout();
}
label = protocol.name;
fConfigView->MoveTo(3, 21);
ResizeBy(0, 8);
} }
SetLabel(label); fImage = image;
} fConfigView = instantiateConfig(settings, accountSettings);
return B_OK;
void
OutProtocolsConfigView::DetachedFromWindow()
{
if (fConfigView == NULL)
return;
BMessage settings;
if (fConfigView->Archive(&settings) != B_OK)
return;
fAccount->OutboundSettings().MakeEmpty();
fAccount->OutboundSettings().Append(settings);
RemoveChild(fConfigView);
delete fConfigView;
fConfigView = NULL;
unload_add_on(fImageID);
} }
+16 -27
View File
@@ -24,21 +24,14 @@ class BButton;
struct entry_ref; struct entry_ref;
class ProtocolsConfigView;
BView* CreateConfigView(const entry_ref& ref, BMailProtocolSettings& settings,
BMailAccountSettings& accountSettings, image_id& image);
class AccountConfigView : public BBox { class AccountConfigView : public BBox {
public: public:
AccountConfigView(BRect rect, AccountConfigView(
BMailAccountSettings *account); BMailAccountSettings* account);
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *msg); virtual void MessageReceived(BMessage* message);
void UpdateViews(); void UpdateViews();
@@ -46,32 +39,28 @@ private:
BTextControl* fNameControl; BTextControl* fNameControl;
BTextControl* fRealNameControl; BTextControl* fRealNameControl;
BTextControl* fReturnAddressControl; BTextControl* fReturnAddressControl;
BMailAccountSettings *fAccount; BMailAccountSettings* fAccount;
}; };
class InProtocolsConfigView : public BBox { class ProtocolConfigView : public BBox {
public: public:
InProtocolsConfigView( ProtocolConfigView(
BMailAccountSettings* account); BMailAccountSettings& accountSettings,
const entry_ref& ref,
BMailProtocolSettings& settings);
void DetachedFromWindow(); void DetachedFromWindow();
private:
BMailAccountSettings* fAccount;
BView* fConfigView;
image_id fImageID;
};
class OutProtocolsConfigView : public BBox {
public:
OutProtocolsConfigView(
BMailAccountSettings* account);
void DetachedFromWindow();
private: private:
BMailAccountSettings* fAccount; status_t _CreateConfigView(const entry_ref& ref,
BMailProtocolSettings& settings,
BMailAccountSettings& accountSettings);
private:
BMailProtocolSettings& fSettings;
BView* fConfigView; BView* fConfigView;
image_id fImageID; image_id fImage;
}; };
+179 -303
View File
@@ -1,12 +1,12 @@
/* /*
* Copyright 2007-2014, Haiku, Inc. All rights reserved. * Copyright 2007-2015 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"
@@ -15,44 +15,41 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <Application.h>
#include <Catalog.h>
#include <ListView.h>
#include <ScrollView.h>
#include <StringView.h>
#include <Button.h>
#include <CheckBox.h>
#include <MenuField.h>
#include <TextControl.h>
#include <TextView.h>
#include <MenuItem.h>
#include <Screen.h>
#include <PopUpMenu.h>
#include <MenuBar.h>
#include <TabView.h>
#include <Box.h>
#include <Alert.h> #include <Alert.h>
#include <Bitmap.h>
#include <Roster.h>
#include <Resources.h>
#include <Region.h>
#include <AppFileInfo.h> #include <AppFileInfo.h>
#include <Entry.h> #include <Application.h>
#include <Directory.h> #include <Bitmap.h>
#include <FindDirectory.h> #include <Box.h>
#include <Path.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <CheckBox.h>
#include <ControlLook.h>
#include <Directory.h>
#include <Entry.h>
#include <FindDirectory.h>
#include <LayoutBuilder.h>
#include <ListView.h>
#include <Locale.h> #include <Locale.h>
#include <MailDaemon.h> #include <MailDaemon.h>
#include <MailSettings.h> #include <MailSettings.h>
#include <MenuBar.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <Path.h>
#include <PopUpMenu.h>
#include <Region.h>
#include <Resources.h>
#include <Roster.h>
#include <Screen.h>
#include <ScrollView.h>
#include <StringView.h>
#include <TabView.h>
#include <TextControl.h>
#include <TextView.h>
#include <MailPrivate.h> #include <MailPrivate.h>
#include "AutoConfigWindow.h" #include "AutoConfigWindow.h"
#include "CenterContainer.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
@@ -134,9 +131,9 @@ AccountItem::ConfigPanel()
class AccountsListView : public BListView { class AccountsListView : public BListView {
public: public:
AccountsListView(BRect rect, BHandler* target) AccountsListView(BHandler* target)
: :
BListView(rect, NULL, B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL), BListView(NULL, B_SINGLE_SELECTION_LIST),
fTarget(target) fTarget(target)
{ {
} }
@@ -185,12 +182,13 @@ class BitmapView : public BView {
public: public:
BitmapView(BBitmap *bitmap) BitmapView(BBitmap *bitmap)
: :
BView(bitmap->Bounds(), NULL, B_FOLLOW_NONE, B_WILL_DRAW) BView(NULL, B_WILL_DRAW)
{ {
fBitmap = bitmap; fBitmap = bitmap;
SetDrawingMode(B_OP_ALPHA); SetDrawingMode(B_OP_ALPHA);
SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
SetExplicitSize(bitmap->Bounds().Size());
} }
~BitmapView() ~BitmapView()
@@ -201,9 +199,6 @@ class BitmapView : public BView {
virtual void AttachedToWindow() virtual void AttachedToWindow()
{ {
SetViewColor(Parent()->ViewColor()); SetViewColor(Parent()->ViewColor());
MoveTo((Parent()->Bounds().Width() - Bounds().Width()) / 2,
Frame().top);
} }
virtual void Draw(BRect updateRect) virtual void Draw(BRect updateRect)
@@ -223,161 +218,77 @@ ConfigWindow::ConfigWindow()
: :
BWindow(BRect(100, 100, 600, 540), B_TRANSLATE_SYSTEM_NAME("E-mail"), BWindow(BRect(100, 100, 600, 540), B_TRANSLATE_SYSTEM_NAME("E-mail"),
B_TITLED_WINDOW, B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_NOT_RESIZABLE), B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS),
fLastSelectedAccount(NULL), fLastSelectedAccount(NULL),
fSaveSettings(false) fSaveSettings(false)
{ {
// create controls BTabView* tabView = new BTabView("tab");
BRect rect(Bounds());
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;
rect.InsetBy(10, 10);
rect.bottom -= 18 + 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(B_TRANSLATE("Accounts"));
view->SetViewColor(top->ViewColor());
// accounts listview // accounts listview
rect = view->Bounds().InsetByCopy(10, 10); BView* view = new BView("accounts", 0);
rect.right = 190 - B_V_SCROLL_BAR_WIDTH; tabView->AddTab(view);
rect.bottom -= height + 18; tabView->TabAt(0)->SetLabel(B_TRANSLATE("Accounts"));
fAccountsListView = new AccountsListView(rect, this);
view->AddChild(new BScrollView(NULL, fAccountsListView, B_FOLLOW_ALL, 0,
false, true));
rect.right += B_V_SCROLL_BAR_WIDTH;
rect.left -= 2; fAccountsListView = new AccountsListView(this);
rect.top = rect.bottom + 10;
rect.bottom = rect.top + height;
BRect sizeRect = rect;
sizeRect.right = sizeRect.left + 30 + view->StringWidth(
B_TRANSLATE("Add"));
view->AddChild(new BButton(sizeRect, NULL, B_TRANSLATE("Add"),
new BMessage(kMsgAddAccount), B_FOLLOW_BOTTOM));
sizeRect.left = sizeRect.right + 5; BButton* addButton = new BButton(NULL, B_TRANSLATE("Add"),
sizeRect.right = sizeRect.left + 30 + view->StringWidth( new BMessage(kMsgAddAccount));
B_TRANSLATE("Remove")); fRemoveButton = new BButton(NULL, B_TRANSLATE("Remove"),
view->AddChild(fRemoveButton = new BButton( new BMessage(kMsgRemoveAccount));
sizeRect, NULL, B_TRANSLATE("Remove"),
new BMessage(kMsgRemoveAccount), B_FOLLOW_BOTTOM));
// accounts config view fConfigView = new BView(NULL, 0);
rect = view->Bounds(); fConfigView->SetLayout(new BGroupLayout(B_VERTICAL));
rect.left = fAccountsListView->Frame().right + B_V_SCROLL_BAR_WIDTH + 16; fConfigView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
rect.right -= 10; fConfigView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fConfigView = new CenterContainer(rect);
view->AddChild(fConfigView);
_MakeHowToView(); BScrollView* scroller = new BScrollView(NULL, fAccountsListView, 0,
false, true);
BLayoutBuilder::Group<>(view, B_HORIZONTAL)
.SetInsets(B_USE_DEFAULT_SPACING)
.AddGroup(B_VERTICAL)
.Add(scroller)
.AddGroup(B_HORIZONTAL)
.Add(addButton)
.Add(fRemoveButton)
.End()
.End()
.Add(fConfigView, 2.0f);
_ReplaceConfigView(_BuildHowToView());
// general settings // general settings
rect = tabView->ContainerView()->Bounds(); view = new BView("general", 0);
tabView->AddTab(view = new CenterContainer(rect)); view->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
tabView->AddTab(view);
tabView->TabAt(1)->SetLabel(B_TRANSLATE("Settings")); tabView->TabAt(1)->SetLabel(B_TRANSLATE("Settings"));
rect = view->Bounds().InsetByCopy(10, 10); fCheckMailCheckBox = new BCheckBox("check", B_TRANSLATE("Check every"),
rect.bottom = rect.top + height * 5 + 15; NULL);
BBox *box = new BBox(rect); fIntervalControl = new BTextControl("time", B_TRANSLATE("minutes"), NULL,
box->SetLabel(B_TRANSLATE("Mail checking"));
view->AddChild(box);
rect = box->Bounds().InsetByCopy(10, 10);
rect.top += 7;
rect.bottom = rect.top + height;
BRect tile = rect.OffsetByCopy(0, 1);
int32 labelWidth = (int32)view->StringWidth(B_TRANSLATE("Check every")) + 6;
tile.right = 80 + labelWidth;
fIntervalControl = new BTextControl(tile, "time",
B_TRANSLATE("Check every"), NULL, NULL);
fIntervalControl->SetDivider(labelWidth);
box->AddChild(fIntervalControl);
BPopUpMenu* frequencyPopUp = new BPopUpMenu(B_EMPTY_STRING);
const char* frequencyStrings[] = {
B_TRANSLATE_COMMENT("never", "mail checking frequency"),
B_TRANSLATE("minutes"),
B_TRANSLATE("hours"),
B_TRANSLATE("days")};
for (int32 i = 0; i < 4; i++) {
BMenuItem* item = new BMenuItem(frequencyStrings[i],
new BMessage(kMsgIntervalUnitChanged));
frequencyPopUp->AddItem(item);
}
tile.left = tile.right + 5;
tile.right = rect.right;
tile.OffsetBy(0,-1);
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",
B_TRANSLATE("Only when dial-up is connected"), NULL);
box->AddChild(fPPPActiveCheckBox);
rect.OffsetBy(0,height + 9);
rect.bottom -= 2;
fPPPActiveSendCheckBox = new BCheckBox(rect, "ppp activesend",
B_TRANSLATE("Schedule outgoing mail when dial-up is disconnected"),
NULL); NULL);
box->AddChild(fPPPActiveSendCheckBox);
// Miscellaneous settings box BPopUpMenu* statusPopUp = new BPopUpMenu(B_EMPTY_STRING);
const char* statusModes[] = {
rect = box->Frame(); rect.bottom = rect.top + 3 * height + 33;
box = new BBox(rect);
box->SetLabel(B_TRANSLATE("Miscellaneous"));
view->AddChild(box);
BPopUpMenu *statusPopUp = new BPopUpMenu(B_EMPTY_STRING);
const char *statusModes[] = {
B_TRANSLATE_COMMENT("Never", "show status window"), B_TRANSLATE_COMMENT("Never", "show status window"),
B_TRANSLATE("While sending"), B_TRANSLATE("While sending"),
B_TRANSLATE("While sending and receiving"), B_TRANSLATE("While sending and receiving")};
B_TRANSLATE("Always")}; for (size_t i = 0; i < sizeof(statusModes) / sizeof(statusModes[0]); i++) {
for (int32 i = 0; i < 4; i++) {
BMessage* msg = new BMessage(kMsgShowStatusWindowChanged); BMessage* msg = new BMessage(kMsgShowStatusWindowChanged);
BMenuItem* item = new BMenuItem(statusModes[i], msg); BMenuItem* item = new BMenuItem(statusModes[i], msg);
statusPopUp->AddItem(item); statusPopUp->AddItem(item);
msg->AddInt32("ShowStatusWindow", i); msg->AddInt32("ShowStatusWindow", i);
} }
rect = box->Bounds().InsetByCopy(10, 10);
rect.top += 7;
rect.bottom = rect.top + height + 5;
labelWidth = (int32)view->StringWidth(
B_TRANSLATE("Show connection status window:")) + 8;
fStatusModeField = new BMenuField(rect, "show status",
B_TRANSLATE("Show connection status window:"), statusPopUp);
fStatusModeField->SetDivider(labelWidth);
box->AddChild(fStatusModeField);
rect = fStatusModeField->Frame();; fStatusModeField = new BMenuField("show status",
rect.OffsetBy(0, rect.Height() + 10); B_TRANSLATE("Show notifications:"), statusPopUp);
BMessage* msg = new BMessage(B_REFS_RECEIVED); BMessage* msg = new BMessage(B_REFS_RECEIVED);
BButton *button = new BButton(rect, B_EMPTY_STRING, BButton* editMenuButton = new BButton(B_EMPTY_STRING,
B_TRANSLATE("Edit mailbox menu…"), msg); B_TRANSLATE("Edit mailbox menu…"), msg);
button->ResizeToPreferred(); editMenuButton->SetTarget(BMessenger("application/x-vnd.Be-TRAK"));
box->AddChild(button);
button->SetTarget(BMessenger("application/x-vnd.Be-TRAK"));
BPath path; BPath path;
find_directory(B_USER_SETTINGS_DIRECTORY, &path); find_directory(B_USER_SETTINGS_DIRECTORY, &path);
@@ -387,38 +298,43 @@ ConfigWindow::ConfigWindow()
entry_ref ref; entry_ref ref;
entry.GetRef(&ref); entry.GetRef(&ref);
msg->AddRef("refs", &ref); msg->AddRef("refs", &ref);
} } else
else editMenuButton->SetEnabled(false);
button->SetEnabled(false);
rect = button->Frame(); BLayoutBuilder::Group<>(view, B_VERTICAL)
rect.OffsetBy(rect.Width() + 30,0); .SetInsets(B_USE_DEFAULT_SPACING)
fAutoStartCheckBox = new BCheckBox(rect, "start daemon", .AddGlue()
B_TRANSLATE("Start mail services on startup"), NULL); .AddGroup(B_HORIZONTAL, 0.f)
fAutoStartCheckBox->ResizeToPreferred(); .AddGlue()
box->AddChild(fAutoStartCheckBox); .Add(fCheckMailCheckBox)
.Add(fIntervalControl->CreateTextViewLayoutItem())
.AddStrut(be_control_look->DefaultLabelSpacing())
.Add(fIntervalControl->CreateLabelLayoutItem())
.AddGlue()
.End()
.AddGroup(B_HORIZONTAL, 0.f)
.AddGlue()
.Add(fStatusModeField->CreateLabelLayoutItem())
.Add(fStatusModeField->CreateMenuBarLayoutItem())
.AddGlue()
.End()
.Add(editMenuButton)
.AddGlue();
// save/revert buttons // save/revert buttons
top->AddChild(tabView); BButton* applyButton = new BButton("apply", B_TRANSLATE("Apply"),
rect = tabView->Frame();
rect.top = rect.bottom + 10;
rect.bottom = rect.top + height + 5;
BButton *saveButton = new BButton(rect, "apply", B_TRANSLATE("Apply"),
new BMessage(kMsgSaveSettings)); new BMessage(kMsgSaveSettings));
float w,h; BButton* revertButton = new BButton("revert", B_TRANSLATE("Revert"),
saveButton->GetPreferredSize(&w, &h);
saveButton->ResizeTo(w, h);
saveButton->MoveTo(rect.right - w, rect.top);
top->AddChild(saveButton);
BButton *revertButton = new BButton(rect, "revert", B_TRANSLATE("Revert"),
new BMessage(kMsgRevertSettings)); new BMessage(kMsgRevertSettings));
revertButton->GetPreferredSize(&w, &h);
revertButton->ResizeTo(w, h); BLayoutBuilder::Group<>(this, B_VERTICAL)
revertButton->MoveTo(rect.left, rect.top); .SetInsets(B_USE_DEFAULT_SPACING)
top->AddChild(revertButton); .Add(tabView)
.AddGroup(B_HORIZONTAL)
.AddGlue()
.Add(revertButton)
.Add(applyButton);
_LoadSettings(); _LoadSettings();
// this will also move our window to the stored position // this will also move our window to the stored position
@@ -437,42 +353,46 @@ ConfigWindow::~ConfigWindow()
} }
void BView*
ConfigWindow::_MakeHowToView() ConfigWindow::_BuildHowToView()
{ {
BView* groupView = new BView("howTo", 0);
BitmapView* bitmapView = NULL;
app_info info; app_info info;
if (be_app->GetAppInfo(&info) == B_OK) { if (be_app->GetAppInfo(&info) == B_OK) {
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), BBitmap* bitmap = new (std::nothrow) BBitmap(BRect(0, 0, 63, 63),
B_RGBA32); 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)); bitmapView = new BitmapView(bitmap);
} else else
delete bitmap; delete bitmap;
} }
} }
BRect rect = fConfigView->Bounds(); BTextView* text = new BTextView(NULL, 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->SetAlignment(B_ALIGN_CENTER);
text->SetText(B_TRANSLATE( text->SetText(B_TRANSLATE(
"\n\nCreate a new account with the Add button.\n\n" "Create 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();
text->ResizeTo(rect.Width(), text->TextHeight(0, 42));
text->SetTextRect(rect);
text->MakeEditable(false); text->MakeEditable(false);
text->MakeSelectable(false); text->MakeSelectable(false);
fConfigView->AddChild(text); BLayoutBuilder::Group<>(groupView, B_VERTICAL)
.AddGlue()
.Add(text)
.AddGlue();
fConfigView->Layout(); if (bitmapView != NULL)
groupView->GetLayout()->AddView(1, bitmapView);
text->SetViewColor(groupView->ViewColor());
return groupView;
} }
@@ -503,11 +423,8 @@ ConfigWindow::_LoadSettings()
|| !screenFrame.Contains(Frame().RightBottom())) || !screenFrame.Contains(Frame().RightBottom()))
status = B_ERROR; status = B_ERROR;
if (status != B_OK) { if (status != B_OK)
// center window on screen CenterOnScreen();
MoveTo((screenFrame.Width() - Frame().Width()) / 2,
(screenFrame.Height() - Frame().Height()) / 2);
}
} }
@@ -528,9 +445,6 @@ ConfigWindow::_LoadAccounts()
void void
ConfigWindow::_SaveSettings() ConfigWindow::_SaveSettings()
{ {
// remove config views (trigger view archive)
fConfigView->DeleteChildren();
// collect changed accounts // collect changed accounts
BMessage changedAccounts(BPrivate::kMsgAccountsChanged); BMessage changedAccounts(BPrivate::kMsgAccountsChanged);
for (int32 i = 0; i < fAccounts.CountItems(); i++) { for (int32 i = 0; i < fAccounts.CountItems(); i++) {
@@ -554,40 +468,21 @@ ConfigWindow::_SaveSettings()
/*** save general settings ***/ /*** save general settings ***/
// figure out time interval
float interval;
sscanf(fIntervalControl->Text(),"%f",&interval);
float multiplier = 0;
switch (fIntervalUnitField->Menu()->IndexOf(
fIntervalUnitField->Menu()->FindMarked())) {
case 1: // minutes
multiplier = 60;
break;
case 2: // hours
multiplier = 60 * 60;
break;
case 3: // days
multiplier = 24 * 60 * 60;
break;
}
time_t time = (time_t)(multiplier * interval);
// apply and save general settings // apply and save general settings
BMailSettings settings; BMailSettings settings;
if (fSaveSettings) { if (fSaveSettings) {
settings.SetAutoCheckInterval(time * 1e6); // figure out time interval
settings.SetCheckOnlyIfPPPUp(fPPPActiveCheckBox->Value() float floatInterval;
== B_CONTROL_ON); sscanf(fIntervalControl->Text(), "%f", &floatInterval);
settings.SetSendOnlyIfPPPUp(fPPPActiveSendCheckBox->Value() bigtime_t interval = bigtime_t(60000000L * floatInterval);
== B_CONTROL_ON);
settings.SetDaemonAutoStarts(fAutoStartCheckBox->Value() settings.SetAutoCheckInterval(interval);
== B_CONTROL_ON); settings.SetDaemonAutoStarts(interval != 0);
// status mode (alway, fetching/retrieving, ...) // status mode (alway, fetching/retrieving, ...)
int32 index = fStatusModeField->Menu()->IndexOf( int32 index = fStatusModeField->Menu()->IndexOf(
fStatusModeField->Menu()->FindMarked()); fStatusModeField->Menu()->FindMarked());
settings.SetShowStatusWindow(index); settings.SetShowStatusWindow(index);
} else { } else {
// restore status window look // restore status window look
settings.SetStatusWindowLook(settings.StatusWindowLook()); settings.SetStatusWindowLook(settings.StatusWindowLook());
@@ -611,12 +506,10 @@ ConfigWindow::_SaveSettings()
messenger.SendMessage(&changedAccounts); messenger.SendMessage(&changedAccounts);
} }
// start the mail_daemon if auto start was selected // Start the mail_daemon if auto start was selected
if (fSaveSettings && fAutoStartCheckBox->Value() == B_CONTROL_ON BMailDaemon daemon;
&& !be_roster->IsRunning("application/x-vnd.Be-POST")) if (fSaveSettings && settings.DaemonAutoStarts() && !daemon.IsRunning())
{ daemon.Launch();
be_roster->Launch("application/x-vnd.Be-POST");
}
} }
@@ -698,12 +591,11 @@ ConfigWindow::MessageReceived(BMessage *msg)
int32 index; int32 index;
if (msg->FindInt32("index", &index) != B_OK || index < 0) { if (msg->FindInt32("index", &index) != B_OK || index < 0) {
// deselect current item // deselect current item
fConfigView->DeleteChildren(); _ReplaceConfigView(_BuildHowToView());
_MakeHowToView();
break; break;
} }
AccountItem *item = (AccountItem *)fAccountsListView->ItemAt(index); AccountItem* item = (AccountItem*)fAccountsListView->ItemAt(index);
if (item) if (item != NULL)
_AccountSelected(item); _AccountSelected(item);
break; break;
} }
@@ -727,7 +619,7 @@ ConfigWindow::MessageReceived(BMessage *msg)
index); index);
if (item != NULL) { if (item != NULL) {
_RemoveAccount(item->GetAccount()); _RemoveAccount(item->GetAccount());
_MakeHowToView(); _ReplaceConfigView(_BuildHowToView());
} }
} }
break; break;
@@ -758,7 +650,7 @@ ConfigWindow::MessageReceived(BMessage *msg)
fSaveSettings = true; fSaveSettings = true;
_SaveSettings(); _SaveSettings();
AccountUpdated(fLastSelectedAccount); AccountUpdated(fLastSelectedAccount);
_MakeHowToView(); _ReplaceConfigView(_BuildHowToView());
fAccountsListView->DeselectAll(); fAccountsListView->DeselectAll();
break; break;
@@ -800,9 +692,9 @@ ConfigWindow::AccountUpdated(BMailAccountSettings* account)
status_t status_t
ConfigWindow::_SetToGeneralSettings(BMailSettings *settings) ConfigWindow::_SetToGeneralSettings(BMailSettings* settings)
{ {
if (!settings) if (settings == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
status_t status = settings->InitCheck(); status_t status = settings->InitCheck();
@@ -810,37 +702,20 @@ ConfigWindow::_SetToGeneralSettings(BMailSettings *settings)
return status; return status;
// retrieval frequency // retrieval frequency
uint32 interval = uint32(settings->AutoCheckInterval() / 60000000L);
fCheckMailCheckBox->SetValue(settings->DaemonAutoStarts()
&& interval != 0 ? B_CONTROL_ON : B_CONTROL_OFF);
time_t interval = time_t(settings->AutoCheckInterval() / 1e6L); if (interval == 0)
char text[25]; interval = 5;
text[0] = 0;
int timeIndex = 0;
if (interval >= 60) {
timeIndex = 1;
sprintf(text, "%" B_PRIdTIME, interval / (60));
}
if (interval >= (60*60)) {
timeIndex = 2;
sprintf(text, "%" B_PRIdTIME, interval / (60*60));
}
if (interval >= (60*60*24)) {
timeIndex = 3;
sprintf(text, "%" B_PRIdTIME, interval / (60*60*24));
}
fIntervalControl->SetText(text);
if (BMenuItem *item = fIntervalUnitField->Menu()->ItemAt(timeIndex)) BString intervalText;
item->SetMarked(true); intervalText.SetToFormat("%" B_PRIu32, interval);
fIntervalControl->SetEnabled(timeIndex != 0); fIntervalControl->SetText(intervalText.String());
fPPPActiveCheckBox->SetValue(settings->CheckOnlyIfPPPUp());
fPPPActiveSendCheckBox->SetValue(settings->SendOnlyIfPPPUp());
fAutoStartCheckBox->SetValue(settings->DaemonAutoStarts());
int32 showStatusIndex = settings->ShowStatusWindow(); int32 showStatusIndex = settings->ShowStatusWindow();
BMenuItem *item = fStatusModeField->Menu()->ItemAt(showStatusIndex); BMenuItem* item = fStatusModeField->Menu()->ItemAt(showStatusIndex);
if (item) { if (item != NULL) {
item->SetMarked(true); item->SetMarked(true);
// send live update to the server by simulating a menu click // send live update to the server by simulating a menu click
BMessage msg(kMsgShowStatusWindowChanged); BMessage msg(kMsgShowStatusWindowChanged);
@@ -877,18 +752,16 @@ ConfigWindow::_RevertToLastSettings()
// revert account data // revert account data
if (fAccountsListView->CurrentSelection() != -1) if (fAccountsListView->CurrentSelection() != -1)
fConfigView->DeleteChildren(); _ReplaceConfigView(_BuildHowToView());
for (int32 i = 0; i < fAccounts.CountItems(); i++) { for (int32 i = 0; i < fAccounts.CountItems(); i++) {
BMailAccountSettings* account = fAccounts.ItemAt(i); BMailAccountSettings* account = fAccounts.ItemAt(i);
_RemoveAccountFromListView(account); _RemoveAccountFromListView(account);
delete account; delete account;
} }
fAccounts.MakeEmpty(); fAccounts.MakeEmpty();
_LoadAccounts(); _LoadAccounts();
if (fConfigView->CountChildren() == 0)
_MakeHowToView();
} }
@@ -951,38 +824,41 @@ ConfigWindow::_AccountSelected(AccountItem* item)
BMailAccountSettings* account = item->GetAccount(); BMailAccountSettings* account = item->GetAccount();
fLastSelectedAccount = account; fLastSelectedAccount = account;
fConfigView->Hide();
fConfigView->DeleteChildren();
BView* view = NULL; BView* view = NULL;
switch (item->GetType()) { switch (item->GetType()) {
case ACCOUNT_ITEM: case ACCOUNT_ITEM:
view = new AccountConfigView(fConfigView->Bounds(), account); view = new AccountConfigView(account);
break; break;
case INBOUND_ITEM: case INBOUND_ITEM:
{ view = new ProtocolConfigView(*account, account->InboundAddOnRef(),
view = new InProtocolsConfigView(account); account->InboundSettings());
break; break;
}
case OUTBOUND_ITEM: case OUTBOUND_ITEM:
{ view = new ProtocolConfigView(*account, account->OutboundAddOnRef(),
view = new OutProtocolsConfigView(account); account->OutboundSettings());
break; break;
}
case FILTER_ITEM: case FILTER_ITEM:
{ view = new FiltersConfigView(*account);
view = new FiltersConfigView(fConfigView->Bounds(), *account);
break; break;
}
} }
if (view) { if (view != NULL)
item->SetConfigPanel(view); item->SetConfigPanel(view);
fConfigView->AddChild(view);
_ReplaceConfigView(view);
}
void
ConfigWindow::_ReplaceConfigView(BView* view)
{
while (BView* child = fConfigView->ChildAt(0)) {
fConfigView->RemoveChild(child);
delete child;
} }
fConfigView->Layout(); if (view != NULL)
fConfigView->Show(); fConfigView->AddChild(view);
} }
+14 -14
View File
@@ -1,10 +1,12 @@
/*
* Copyright 2004-2012, Haiku Inc. All rights reserved.
* Copyright 2001, Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
*
* Distributed under the terms of the MIT License.
*/
#ifndef CONFIG_WINDOW_H #ifndef CONFIG_WINDOW_H
#define CONFIG_WINDOW_H #define CONFIG_WINDOW_H
/* ConfigWindow - main eMail config window
*
* Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
* Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
*/
#include <Window.h> #include <Window.h>
@@ -24,8 +26,7 @@ class BMailSettings;
class CenterContainer; class CenterContainer;
enum item_types enum item_types {
{
ACCOUNT_ITEM = 0, ACCOUNT_ITEM = 0,
INBOUND_ITEM, INBOUND_ITEM,
OUTBOUND_ITEM, OUTBOUND_ITEM,
@@ -66,7 +67,7 @@ public:
void AccountUpdated(BMailAccountSettings* account); void AccountUpdated(BMailAccountSettings* account);
private: private:
void _MakeHowToView(); BView* _BuildHowToView();
void _LoadSettings(); void _LoadSettings();
void _LoadAccounts(); void _LoadAccounts();
@@ -81,18 +82,17 @@ private:
void _RemoveAccountFromListView( void _RemoveAccountFromListView(
BMailAccountSettings* account); BMailAccountSettings* account);
void _AccountSelected(AccountItem* item); void _AccountSelected(AccountItem* item);
void _ReplaceConfigView(BView* view);
private:
BListView* fAccountsListView; BListView* fAccountsListView;
BMailAccountSettings* fLastSelectedAccount; BMailAccountSettings* fLastSelectedAccount;
CenterContainer* fConfigView; BView* fConfigView;
BButton* fRemoveButton; BButton* fRemoveButton;
BCheckBox* fCheckMailCheckBox;
BTextControl* fIntervalControl; BTextControl* fIntervalControl;
BMenuField* fIntervalUnitField;
BCheckBox* fPPPActiveCheckBox;
BCheckBox* fPPPActiveSendCheckBox;
BMenuField* fStatusModeField; BMenuField* fStatusModeField;
BCheckBox* fAutoStartCheckBox;
bool fSaveSettings; bool fSaveSettings;
BObjectList<BMailAccountSettings> fAccounts; BObjectList<BMailAccountSettings> fAccounts;
+31 -60
View File
@@ -12,12 +12,12 @@
#include <Bitmap.h> #include <Bitmap.h>
#include <Box.h> #include <Box.h>
#include <Catalog.h> #include <Catalog.h>
#include <LayoutBuilder.h>
#include <Locale.h> #include <Locale.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <ScrollView.h> #include <ScrollView.h>
#include "CenterContainer.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Config Views" #define B_TRANSLATION_CONTEXT "Config Views"
@@ -35,12 +35,11 @@ const uint32 kMsgItemDragged = 'itdr';
class DragListView : public BListView { class DragListView : public BListView {
public: public:
DragListView(BRect frame, const char *name, DragListView(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)
BMessage *itemMovedMsg = NULL)
: :
BListView(frame, name, type, resizingMode), BListView(name, type),
fDragging(false), fDragging(false),
fItemMovedMessage(itemMovedMsg) fItemMovedMessage(itemMovedMsg)
{ {
@@ -207,9 +206,9 @@ private:
// #pragma mark - // #pragma mark -
FiltersConfigView::FiltersConfigView(BRect rect, BMailAccountSettings& account) FiltersConfigView::FiltersConfigView(BMailAccountSettings& account)
: :
BBox(rect), BBox("filters"),
fAccount(account), fAccount(account),
fDirection(kIncoming), fDirection(kIncoming),
fInboundFilters(kIncoming, false), fInboundFilters(kIncoming, false),
@@ -217,64 +216,44 @@ FiltersConfigView::FiltersConfigView(BRect rect, BMailAccountSettings& account)
fFilterView(NULL), fFilterView(NULL),
fCurrentIndex(-1) fCurrentIndex(-1)
{ {
BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING); BView* contents = new BView(NULL, 0);
AddChild(contents);
BMessage* msg; BMessage* msg = new BMessage(kMsgChainSelected);
BMenuItem *item;
msg = new BMessage(kMsgChainSelected);
item = new BMenuItem(B_TRANSLATE("Incoming mail filters"), msg);
menu->AddItem(item);
msg->AddInt32("direction", kIncoming); msg->AddInt32("direction", kIncoming);
BMenuItem* item = new BMenuItem(B_TRANSLATE("Incoming mail filters"), msg);
item->SetMarked(true); item->SetMarked(true);
BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING);
menu->AddItem(item);
msg = new BMessage(kMsgChainSelected); msg = new BMessage(kMsgChainSelected);
msg->AddInt32("direction", kOutgoing);
item = new BMenuItem(B_TRANSLATE("Outgoing mail filters"), msg); item = new BMenuItem(B_TRANSLATE("Outgoing mail filters"), msg);
menu->AddItem(item); menu->AddItem(item);
msg->AddInt32("direction", kOutgoing);
fChainsField = new BMenuField(BRect(0, 0, 200, 40), NULL, NULL, menu); fChainsField = new BMenuField(NULL, NULL, menu);
fChainsField->ResizeToPreferred(); fChainsField->ResizeToPreferred();
SetLabel(fChainsField); SetLabel(fChainsField);
// determine font height fListView = new DragListView(NULL, B_SINGLE_SELECTION_LIST,
font_height fontHeight; new BMessage(kMsgFilterMoved));
fChainsField->GetFontHeight(&fontHeight);
int32 height = (int32)(fontHeight.ascent + fontHeight.descent
+ fontHeight.leading) + 5;
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));
rect.right += B_V_SCROLL_BAR_WIDTH;
// 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;
BRect sizeRect = rect;
sizeRect.right = sizeRect.left + 30
+ fChainsField->StringWidth(B_TRANSLATE("Add filter"));
menu = new BPopUpMenu(B_TRANSLATE("Add filter")); menu = new BPopUpMenu(B_TRANSLATE("Add filter"));
menu->SetRadioMode(false); menu->SetRadioMode(false);
fAddField = new BMenuField(rect, NULL, NULL, menu); fAddField = new BMenuField(NULL, NULL, menu);
fAddField->ResizeToPreferred();
AddChild(fAddField);
sizeRect.left = sizeRect.right + 5; fRemoveButton = new BButton(NULL, B_TRANSLATE("Remove"),
sizeRect.right = sizeRect.left + 30 new BMessage(kMsgRemoveFilter));
+ fChainsField->StringWidth(B_TRANSLATE("Remove"));
sizeRect.top--;
AddChild(fRemoveButton = new BButton(sizeRect, NULL, B_TRANSLATE("Remove"),
new BMessage(kMsgRemoveFilter), B_FOLLOW_BOTTOM));
ResizeTo(Bounds().Width(), sizeRect.bottom + 10); BLayoutBuilder::Group<>(contents, B_VERTICAL)
.SetInsets(B_USE_DEFAULT_SPACING)
.Add(new BScrollView(NULL, fListView, 0, false, true))
.AddGroup(B_HORIZONTAL)
.Add(fAddField)
.Add(fRemoveButton)
.AddGlue();
_SetDirection(fDirection); _SetDirection(fDirection);
} }
@@ -282,7 +261,6 @@ FiltersConfigView::FiltersConfigView(BRect rect, BMailAccountSettings& account)
FiltersConfigView::~FiltersConfigView() FiltersConfigView::~FiltersConfigView()
{ {
} }
@@ -318,10 +296,6 @@ FiltersConfigView::_SelectFilter(int32 index)
fCurrentIndex = index; fCurrentIndex = index;
// re-layout the view containing the config view
if (CenterContainer* container = dynamic_cast<CenterContainer*>(Parent()))
container->Layout();
if (Parent()) if (Parent())
Parent()->Show(); Parent()->Show();
} }
@@ -414,7 +388,7 @@ 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;
::FilterList* filters = _FilterList(); ::FilterList* filters = _FilterList();
@@ -443,7 +417,7 @@ FiltersConfigView::MessageReceived(BMessage *msg)
case kMsgFilterSelected: case kMsgFilterSelected:
{ {
int32 index = -1; int32 index = -1;
if (msg->FindInt32("index",&index) < B_OK) if (msg->FindInt32("index",&index) != B_OK)
break; break;
_SelectFilter(index); _SelectFilter(index);
@@ -478,18 +452,15 @@ FiltersConfigView::MessageReceived(BMessage *msg)
BMailProtocolSettings* BMailProtocolSettings*
FiltersConfigView::_MailSettings() FiltersConfigView::_MailSettings()
{ {
if (fDirection == kIncoming) return fDirection == kIncoming
return &fAccount.InboundSettings(); ? &fAccount.InboundSettings() : &fAccount.OutboundSettings();
return &fAccount.OutboundSettings();
} }
FilterList* FilterList*
FiltersConfigView::_FilterList() FiltersConfigView::_FilterList()
{ {
if (fDirection == kIncoming) return fDirection == kIncoming ? &fInboundFilters : &fOutboundFilters;
return &fInboundFilters;
return &fOutboundFilters;
} }
+1 -1
View File
@@ -25,7 +25,7 @@ class FilterConfigBox;
class FiltersConfigView : public BBox { class FiltersConfigView : public BBox {
public: public:
FiltersConfigView(BRect rect, FiltersConfigView(
BMailAccountSettings& account); BMailAccountSettings& account);
~FiltersConfigView(); ~FiltersConfigView();
-1
View File
@@ -13,7 +13,6 @@ local sources =
AutoConfig.cpp AutoConfig.cpp
AutoConfigView.cpp AutoConfigView.cpp
AutoConfigWindow.cpp AutoConfigWindow.cpp
CenterContainer.cpp
ConfigViews.cpp ConfigViews.cpp
ConfigWindow.cpp ConfigWindow.cpp
FilterList.cpp FilterList.cpp