MailProtocolConfigView now is a BMailSettingsView.

* Changed the private settings base classes to follow the new style.
* Made BodyDownloadConfig use the layout API.
* Adapted SMTP to these changes.
This commit is contained in:
Axel Dörfler
2015-01-06 15:23:06 +01:00
parent efd1602a79
commit 57b305558b
6 changed files with 127 additions and 143 deletions
+3 -2
View File
@@ -12,8 +12,9 @@
#include <FilePanel.h>
class BTextControl;
class BButton;
class BMailAddOnSettings;
class BTextControl;
namespace BPrivate {
@@ -53,7 +54,7 @@ public:
void SetTo(const BMessage* archive,
BMessage* metadata);
virtual status_t Archive(BMessage* into, bool deep = true) const;
status_t SaveInto(BMailAddOnSettings& settings) const;
private:
BMessage* fMeta;
+10 -10
View File
@@ -14,6 +14,7 @@
#include <View.h>
#include <MailSettings.h>
#include <MailSettingsView.h>
class BCheckBox;
@@ -29,17 +30,16 @@ class BodyDownloadConfig : public BView {
public:
BodyDownloadConfig();
void SetTo(BMailProtocolSettings& settings);
void SetTo(const BMailProtocolSettings& settings);
void MessageReceived(BMessage* message);
void AttachedToWindow();
void GetPreferredSize(float* width, float* height);
status_t Archive(BMessage* into, bool deep = true) const;
status_t SaveInto(BMailAddOnSettings& settings) const;
virtual void MessageReceived(BMessage* message);
virtual void AttachedToWindow();
private:
BTextControl* fSizeBox;
BTextControl* fSizeControl;
BCheckBox* fPartialBox;
BStringView* fBytesLabel;
};
@@ -54,7 +54,7 @@ enum mail_protocol_config_options {
};
class MailProtocolConfigView : public BView {
class MailProtocolConfigView : public BMailSettingsView {
public:
MailProtocolConfigView(uint32 optionsMask
= B_MAIL_PROTOCOL_HAS_FLAVORS
@@ -63,7 +63,7 @@ public:
| B_MAIL_PROTOCOL_HAS_HOSTNAME);
virtual ~MailProtocolConfigView();
void SetTo(BMailProtocolSettings& settings);
void SetTo(const BMailProtocolSettings& settings);
void AddFlavor(const char* label);
void AddAuthMethod(const char* label,
@@ -71,7 +71,7 @@ public:
BGridLayout* Layout() const;
virtual status_t Archive(BMessage* into, bool deep = true) const;
virtual status_t SaveInto(BMailAddOnSettings& settings) const;
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
@@ -11,6 +11,7 @@
#include <GridLayout.h>
#include <MailFilter.h>
#include <MenuField.h>
#include <SpaceLayoutItem.h>
#include <TextControl.h>
#include <FileConfigView.h>
@@ -27,17 +28,17 @@ using namespace BPrivate;
class SMTPConfigView : public MailProtocolConfigView {
public:
SMTPConfigView(BMailAccountSettings& settings);
SMTPConfigView(
const BMailAccountSettings& settings);
status_t Archive(BMessage* into,
bool deep = true) const;
virtual status_t SaveInto(BMailAddOnSettings& settings) const;
private:
MailFileConfigView* fFileView;
};
SMTPConfigView::SMTPConfigView(BMailAccountSettings& settings)
SMTPConfigView::SMTPConfigView(const BMailAccountSettings& settings)
:
MailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS
| B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD
@@ -72,22 +73,28 @@ SMTPConfigView::SMTPConfigView(BMailAccountSettings& settings)
Layout()->AddView(fFileView, 0, Layout()->CountRows(),
Layout()->CountColumns());
Layout()->AddItem(BSpaceLayoutItem::CreateGlue(), 0, Layout()->CountRows());
Layout()->SetRowWeight(Layout()->CountRows() - 1, 1.0f);
}
status_t
SMTPConfigView::Archive(BMessage* into, bool deep) const
SMTPConfigView::SaveInto(BMailAddOnSettings& settings) const
{
fFileView->Archive(into, deep);
return MailProtocolConfigView::Archive(into, deep);
status_t status = fFileView->SaveInto(settings);
if (status != B_OK)
return status;
return MailProtocolConfigView::SaveInto(settings);
}
// #pragma mark -
BView*
instantiate_protocol_config_panel(BMailAccountSettings& settings)
BMailSettingsView*
instantiate_protocol_settings_view(const BMailAccountSettings& accountSettings,
const BMailProtocolSettings& settings)
{
return new SMTPConfigView(settings);
return new SMTPConfigView(accountSettings);
}
+4 -7
View File
@@ -16,6 +16,7 @@
#include <Button.h>
#include <Catalog.h>
#include <GroupLayout.h>
#include <MailSettingsView.h>
#include <Message.h>
#include <Path.h>
#include <String.h>
@@ -146,14 +147,10 @@ MailFileConfigView::SetTo(const BMessage* archive, BMessage* meta)
status_t
MailFileConfigView::Archive(BMessage* into, bool /*deep*/) const
MailFileConfigView::SaveInto(BMailAddOnSettings& settings) const
{
BMessage* archive = fUseMeta ? fMeta : into;
if (archive->ReplaceString(fName, Text()) != B_OK)
archive->AddString(fName, Text());
return B_OK;
BMessage* archive = fUseMeta ? fMeta : &settings;
return archive->SetString(fName, Text());
}
+91 -112
View File
@@ -15,7 +15,9 @@
#include <Catalog.h>
#include <CheckBox.h>
#include <ControlLook.h>
#include <GridLayout.h>
#include <LayoutBuilder.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <Message.h>
@@ -42,60 +44,61 @@ namespace BPrivate {
BodyDownloadConfig::BodyDownloadConfig()
:
BView(BRect(0,0,50,50), "body_config", B_FOLLOW_ALL_SIDES, 0)
BView("body_config", 0)
{
const char *partial_text = B_TRANSLATE(
"Partially download messages larger than");
fPartialBox = new BCheckBox("size_if", B_TRANSLATE(
"Partially download messages larger than"), new BMessage('SIZF'));
BRect r(0, 0, 280, 15);
fPartialBox = new BCheckBox(r, "size_if", partial_text,
new BMessage('SIZF'));
fPartialBox->ResizeToPreferred();
fSizeControl = new BTextControl("size",
B_TRANSLATE_COMMENT("KB", "kilo byte"), "", NULL);
fSizeControl->SetExplicitMinSize(BSize(be_plain_font->StringWidth("0000"),
B_SIZE_UNSET));
r = fPartialBox->Frame();
r.OffsetBy(17,r.Height() + 1);
r.right = r.left + be_plain_font->StringWidth("0000") + 10;
fSizeBox = new BTextControl(r, "size", "", "", NULL);
r.OffsetBy(r.Width() + 5,0);
fBytesLabel = new BStringView(r, "kb", B_TRANSLATE("KiB"));
AddChild(fBytesLabel);
fSizeBox->SetDivider(0);
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(fPartialBox);
AddChild(fSizeBox);
ResizeToPreferred();
BLayoutBuilder::Group<>(this, B_HORIZONTAL,
be_control_look->DefaultLabelSpacing())
.Add(fPartialBox)
.Add(fSizeControl->CreateTextViewLayoutItem())
.Add(fSizeControl->CreateLabelLayoutItem());
}
void
BodyDownloadConfig::SetTo(BMailProtocolSettings& settings)
BodyDownloadConfig::SetTo(const BMailProtocolSettings& settings)
{
int32 limit = 0;
if (settings.HasInt32(kPartialDownloadLimit))
limit = settings.FindInt32(kPartialDownloadLimit);
int32 limit = settings.GetInt32(kPartialDownloadLimit, -1);
if (limit < 0) {
fPartialBox->SetValue(B_CONTROL_OFF);
fSizeBox->SetText("0");
fSizeBox->SetEnabled(false);
fSizeControl->SetText("0");
fSizeControl->SetEnabled(false);
} else {
limit = int32(limit / 1024);
BString kb;
kb << limit;
fSizeBox->SetText(kb);
kb << int32(limit / 1024);
fSizeControl->SetText(kb);
fPartialBox->SetValue(B_CONTROL_ON);
fSizeBox->SetEnabled(true);
fSizeControl->SetEnabled(true);
}
}
status_t
BodyDownloadConfig::SaveInto(BMailAddOnSettings& settings) const
{
if (fPartialBox->Value() == B_CONTROL_ON) {
settings.SetInt32(kPartialDownloadLimit,
atoi(fSizeControl->Text()) * 1024);
} else
settings.RemoveName(kPartialDownloadLimit);
return B_OK;
}
void
BodyDownloadConfig::MessageReceived(BMessage *msg)
{
if (msg->what != 'SIZF')
return BView::MessageReceived(msg);
fSizeBox->SetEnabled(fPartialBox->Value());
fSizeControl->SetEnabled(fPartialBox->Value());
}
@@ -107,33 +110,12 @@ BodyDownloadConfig::AttachedToWindow()
}
void
BodyDownloadConfig::GetPreferredSize(float *width, float *height)
{
*height = fSizeBox->Frame().bottom + 5;
*width = 200;
}
status_t
BodyDownloadConfig::Archive(BMessage* into, bool) const
{
into->RemoveName(kPartialDownloadLimit);
if (fPartialBox->Value() == B_CONTROL_ON)
into->AddInt32(kPartialDownloadLimit, atoi(fSizeBox->Text()) * 1024);
else
into->AddInt32(kPartialDownloadLimit, -1);
return B_OK;
}
// #pragma mark -
MailProtocolConfigView::MailProtocolConfigView(uint32 optionsMask)
:
BView("protocol_config_view", B_WILL_DRAW),
BMailSettingsView("protocol_config_view"),
fHostControl(NULL),
fUserControl(NULL),
fPasswordControl(NULL),
@@ -196,7 +178,7 @@ MailProtocolConfigView::~MailProtocolConfigView()
void
MailProtocolConfigView::SetTo(BMailProtocolSettings& settings)
MailProtocolConfigView::SetTo(const BMailProtocolSettings& settings)
{
BString host = settings.FindString("server");
if (settings.HasInt32("port"))
@@ -283,6 +265,56 @@ MailProtocolConfigView::Layout() const
}
status_t
MailProtocolConfigView::SaveInto(BMailAddOnSettings& settings) const
{
if (fHostControl != NULL) {
int32 port = -1;
BString hostName = fHostControl->Text();
if (hostName.FindFirst(':') > -1) {
port = atol(hostName.String() + hostName.FindFirst(':') + 1);
hostName.Truncate(hostName.FindFirst(':'));
}
settings.SetString("server", hostName);
// since there is no need for the port option, remove it here
if (port != -1)
settings.SetInt32("port", port);
else
settings.RemoveName("port");
} else {
settings.RemoveName("server");
settings.RemoveName("port");
}
if (fUserControl != NULL)
settings.SetString("username", fUserControl->Text());
else
settings.RemoveName("username");
// remove old unencrypted passwords
settings.RemoveName("password");
if (fPasswordControl != NULL)
set_passwd(&settings, "cpasswd", fPasswordControl->Text());
else
settings.RemoveName("cpasswd");
_StoreIndexOfMarked(settings, "flavor", fFlavorField);
_StoreIndexOfMarked(settings, "auth_method", fAuthenticationField);
_StoreCheckBox(settings, "leave_mail_on_server", fLeaveOnServerCheckBox);
_StoreCheckBox(settings, "delete_remote_when_local",
fRemoveFromServerCheckBox);
if (fBodyDownloadConfig != NULL)
return fBodyDownloadConfig->SaveInto(settings);
return B_OK;
}
void
MailProtocolConfigView::AttachedToWindow()
{
@@ -313,57 +345,6 @@ MailProtocolConfigView::MessageReceived(BMessage* message)
}
status_t
MailProtocolConfigView::Archive(BMessage* into, bool deep) const
{
if (fHostControl != NULL) {
int32 port = -1;
BString hostName = fHostControl->Text();
if (hostName.FindFirst(':') > -1) {
port = atol(hostName.String() + hostName.FindFirst(':') + 1);
hostName.Truncate(hostName.FindFirst(':'));
}
if (into->ReplaceString("server", hostName.String()) != B_OK)
into->AddString("server", hostName.String());
// since there is no need for the port option, remove it here
into->RemoveName("port");
if (port != -1)
into->AddInt32("port", port);
} else {
into->RemoveName("server");
into->RemoveName("port");
}
if (fUserControl != NULL) {
if (into->ReplaceString("username", fUserControl->Text()) != B_OK)
into->AddString("username", fUserControl->Text());
} else
into->RemoveName("username");
// remove old unencrypted passwords
into->RemoveName("password");
if (fPasswordControl != NULL)
set_passwd(into, "cpasswd", fPasswordControl->Text());
else
into->RemoveName("cpasswd");
_StoreIndexOfMarked(*into, "flavor", fFlavorField);
_StoreIndexOfMarked(*into, "auth_method", fAuthenticationField);
_StoreCheckBox(*into, "leave_mail_on_server", fLeaveOnServerCheckBox);
_StoreCheckBox(*into, "delete_remote_when_local",
fRemoveFromServerCheckBox);
if (fBodyDownloadConfig != NULL)
return fBodyDownloadConfig->Archive(into, deep);
return B_OK;
}
BTextControl*
MailProtocolConfigView::_AddTextControl(BGridLayout* layout, const char* name,
const char* label)
@@ -399,8 +380,7 @@ MailProtocolConfigView::_StoreIndexOfMarked(BMessage& message, const char* name,
if (item != NULL)
index = field->Menu()->IndexOf(item);
}
if (message.ReplaceInt32(name, index) != B_OK)
message.AddInt32(name, index);
message.SetInt32(name, index);
}
@@ -409,10 +389,9 @@ MailProtocolConfigView::_StoreCheckBox(BMessage& message, const char* name,
BCheckBox* checkBox) const
{
bool value = checkBox != NULL && checkBox->Value() == B_CONTROL_ON;
if (value) {
if (message.ReplaceBool(name, value) != B_OK)
message.AddBool(name, value);
} else
if (value)
message.SetBool(name, value);
else
message.RemoveName(name);
}
+2 -2
View File
@@ -185,10 +185,10 @@ ProtocolSettingsView::_CreateSettingsView(const entry_ref& ref,
if (image < 0)
return image;
if (get_image_symbol(image, "instantiate_protocol_config_panel",
if (get_image_symbol(image, "instantiate_protocol_settings_view",
B_SYMBOL_TYPE_TEXT, (void**)&instantiateConfig) != B_OK) {
unload_add_on(image);
return B_BAD_VALUE;
return B_MISSING_SYMBOL;
}
fImage = image;