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> #include <FilePanel.h>
class BTextControl;
class BButton; class BButton;
class BMailAddOnSettings;
class BTextControl;
namespace BPrivate { namespace BPrivate {
@@ -53,7 +54,7 @@ public:
void SetTo(const BMessage* archive, void SetTo(const BMessage* archive,
BMessage* metadata); BMessage* metadata);
virtual status_t Archive(BMessage* into, bool deep = true) const; status_t SaveInto(BMailAddOnSettings& settings) const;
private: private:
BMessage* fMeta; BMessage* fMeta;
+10 -10
View File
@@ -14,6 +14,7 @@
#include <View.h> #include <View.h>
#include <MailSettings.h> #include <MailSettings.h>
#include <MailSettingsView.h>
class BCheckBox; class BCheckBox;
@@ -29,17 +30,16 @@ class BodyDownloadConfig : public BView {
public: public:
BodyDownloadConfig(); BodyDownloadConfig();
void SetTo(BMailProtocolSettings& settings); void SetTo(const BMailProtocolSettings& settings);
void MessageReceived(BMessage* message); status_t SaveInto(BMailAddOnSettings& settings) const;
void AttachedToWindow();
void GetPreferredSize(float* width, float* height); virtual void MessageReceived(BMessage* message);
status_t Archive(BMessage* into, bool deep = true) const; virtual void AttachedToWindow();
private: private:
BTextControl* fSizeBox; BTextControl* fSizeControl;
BCheckBox* fPartialBox; BCheckBox* fPartialBox;
BStringView* fBytesLabel;
}; };
@@ -54,7 +54,7 @@ enum mail_protocol_config_options {
}; };
class MailProtocolConfigView : public BView { class MailProtocolConfigView : public BMailSettingsView {
public: public:
MailProtocolConfigView(uint32 optionsMask MailProtocolConfigView(uint32 optionsMask
= B_MAIL_PROTOCOL_HAS_FLAVORS = B_MAIL_PROTOCOL_HAS_FLAVORS
@@ -63,7 +63,7 @@ public:
| B_MAIL_PROTOCOL_HAS_HOSTNAME); | B_MAIL_PROTOCOL_HAS_HOSTNAME);
virtual ~MailProtocolConfigView(); virtual ~MailProtocolConfigView();
void SetTo(BMailProtocolSettings& settings); void SetTo(const BMailProtocolSettings& settings);
void AddFlavor(const char* label); void AddFlavor(const char* label);
void AddAuthMethod(const char* label, void AddAuthMethod(const char* label,
@@ -71,7 +71,7 @@ public:
BGridLayout* Layout() const; 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 AttachedToWindow();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);
@@ -11,6 +11,7 @@
#include <GridLayout.h> #include <GridLayout.h>
#include <MailFilter.h> #include <MailFilter.h>
#include <MenuField.h> #include <MenuField.h>
#include <SpaceLayoutItem.h>
#include <TextControl.h> #include <TextControl.h>
#include <FileConfigView.h> #include <FileConfigView.h>
@@ -27,17 +28,17 @@ using namespace BPrivate;
class SMTPConfigView : public MailProtocolConfigView { class SMTPConfigView : public MailProtocolConfigView {
public: public:
SMTPConfigView(BMailAccountSettings& settings); SMTPConfigView(
const BMailAccountSettings& settings);
status_t Archive(BMessage* into, virtual status_t SaveInto(BMailAddOnSettings& settings) const;
bool deep = true) const;
private: private:
MailFileConfigView* fFileView; MailFileConfigView* fFileView;
}; };
SMTPConfigView::SMTPConfigView(BMailAccountSettings& settings) SMTPConfigView::SMTPConfigView(const BMailAccountSettings& settings)
: :
MailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS MailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS
| B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD | 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()->AddView(fFileView, 0, Layout()->CountRows(),
Layout()->CountColumns()); Layout()->CountColumns());
Layout()->AddItem(BSpaceLayoutItem::CreateGlue(), 0, Layout()->CountRows());
Layout()->SetRowWeight(Layout()->CountRows() - 1, 1.0f);
} }
status_t status_t
SMTPConfigView::Archive(BMessage* into, bool deep) const SMTPConfigView::SaveInto(BMailAddOnSettings& settings) const
{ {
fFileView->Archive(into, deep); status_t status = fFileView->SaveInto(settings);
return MailProtocolConfigView::Archive(into, deep); if (status != B_OK)
return status;
return MailProtocolConfigView::SaveInto(settings);
} }
// #pragma mark - // #pragma mark -
BView* BMailSettingsView*
instantiate_protocol_config_panel(BMailAccountSettings& settings) 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 <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <GroupLayout.h> #include <GroupLayout.h>
#include <MailSettingsView.h>
#include <Message.h> #include <Message.h>
#include <Path.h> #include <Path.h>
#include <String.h> #include <String.h>
@@ -146,14 +147,10 @@ MailFileConfigView::SetTo(const BMessage* archive, BMessage* meta)
status_t status_t
MailFileConfigView::Archive(BMessage* into, bool /*deep*/) const MailFileConfigView::SaveInto(BMailAddOnSettings& settings) const
{ {
BMessage* archive = fUseMeta ? fMeta : into; BMessage* archive = fUseMeta ? fMeta : &settings;
return archive->SetString(fName, Text());
if (archive->ReplaceString(fName, Text()) != B_OK)
archive->AddString(fName, Text());
return B_OK;
} }
+91 -112
View File
@@ -15,7 +15,9 @@
#include <Catalog.h> #include <Catalog.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <ControlLook.h>
#include <GridLayout.h> #include <GridLayout.h>
#include <LayoutBuilder.h>
#include <MenuField.h> #include <MenuField.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Message.h> #include <Message.h>
@@ -42,60 +44,61 @@ namespace BPrivate {
BodyDownloadConfig::BodyDownloadConfig() 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( fPartialBox = new BCheckBox("size_if", B_TRANSLATE(
"Partially download messages larger than"); "Partially download messages larger than"), new BMessage('SIZF'));
BRect r(0, 0, 280, 15); fSizeControl = new BTextControl("size",
fPartialBox = new BCheckBox(r, "size_if", partial_text, B_TRANSLATE_COMMENT("KB", "kilo byte"), "", NULL);
new BMessage('SIZF')); fSizeControl->SetExplicitMinSize(BSize(be_plain_font->StringWidth("0000"),
fPartialBox->ResizeToPreferred(); B_SIZE_UNSET));
r = fPartialBox->Frame(); BLayoutBuilder::Group<>(this, B_HORIZONTAL,
r.OffsetBy(17,r.Height() + 1); be_control_look->DefaultLabelSpacing())
r.right = r.left + be_plain_font->StringWidth("0000") + 10; .Add(fPartialBox)
fSizeBox = new BTextControl(r, "size", "", "", NULL); .Add(fSizeControl->CreateTextViewLayoutItem())
.Add(fSizeControl->CreateLabelLayoutItem());
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();
} }
void void
BodyDownloadConfig::SetTo(BMailProtocolSettings& settings) BodyDownloadConfig::SetTo(const BMailProtocolSettings& settings)
{ {
int32 limit = 0; int32 limit = settings.GetInt32(kPartialDownloadLimit, -1);
if (settings.HasInt32(kPartialDownloadLimit))
limit = settings.FindInt32(kPartialDownloadLimit);
if (limit < 0) { if (limit < 0) {
fPartialBox->SetValue(B_CONTROL_OFF); fPartialBox->SetValue(B_CONTROL_OFF);
fSizeBox->SetText("0"); fSizeControl->SetText("0");
fSizeBox->SetEnabled(false); fSizeControl->SetEnabled(false);
} else { } else {
limit = int32(limit / 1024);
BString kb; BString kb;
kb << limit; kb << int32(limit / 1024);
fSizeBox->SetText(kb); fSizeControl->SetText(kb);
fPartialBox->SetValue(B_CONTROL_ON); 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 void
BodyDownloadConfig::MessageReceived(BMessage *msg) BodyDownloadConfig::MessageReceived(BMessage *msg)
{ {
if (msg->what != 'SIZF') if (msg->what != 'SIZF')
return BView::MessageReceived(msg); 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 - // #pragma mark -
MailProtocolConfigView::MailProtocolConfigView(uint32 optionsMask) MailProtocolConfigView::MailProtocolConfigView(uint32 optionsMask)
: :
BView("protocol_config_view", B_WILL_DRAW), BMailSettingsView("protocol_config_view"),
fHostControl(NULL), fHostControl(NULL),
fUserControl(NULL), fUserControl(NULL),
fPasswordControl(NULL), fPasswordControl(NULL),
@@ -196,7 +178,7 @@ MailProtocolConfigView::~MailProtocolConfigView()
void void
MailProtocolConfigView::SetTo(BMailProtocolSettings& settings) MailProtocolConfigView::SetTo(const BMailProtocolSettings& settings)
{ {
BString host = settings.FindString("server"); BString host = settings.FindString("server");
if (settings.HasInt32("port")) 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 void
MailProtocolConfigView::AttachedToWindow() 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* BTextControl*
MailProtocolConfigView::_AddTextControl(BGridLayout* layout, const char* name, MailProtocolConfigView::_AddTextControl(BGridLayout* layout, const char* name,
const char* label) const char* label)
@@ -399,8 +380,7 @@ MailProtocolConfigView::_StoreIndexOfMarked(BMessage& message, const char* name,
if (item != NULL) if (item != NULL)
index = field->Menu()->IndexOf(item); index = field->Menu()->IndexOf(item);
} }
if (message.ReplaceInt32(name, index) != B_OK) message.SetInt32(name, index);
message.AddInt32(name, index);
} }
@@ -409,10 +389,9 @@ MailProtocolConfigView::_StoreCheckBox(BMessage& message, const char* name,
BCheckBox* checkBox) const BCheckBox* checkBox) const
{ {
bool value = checkBox != NULL && checkBox->Value() == B_CONTROL_ON; bool value = checkBox != NULL && checkBox->Value() == B_CONTROL_ON;
if (value) { if (value)
if (message.ReplaceBool(name, value) != B_OK) message.SetBool(name, value);
message.AddBool(name, value); else
} else
message.RemoveName(name); message.RemoveName(name);
} }
+2 -2
View File
@@ -185,10 +185,10 @@ ProtocolSettingsView::_CreateSettingsView(const entry_ref& ref,
if (image < 0) if (image < 0)
return image; 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) { B_SYMBOL_TYPE_TEXT, (void**)&instantiateConfig) != B_OK) {
unload_add_on(image); unload_add_on(image);
return B_BAD_VALUE; return B_MISSING_SYMBOL;
} }
fImage = image; fImage = image;