added 3 changesets to branch 'refs/remotes/axeld-github/imap' old head: 076dba5626c865673f36b5ebd4dc134c108234b1 new head: 05cba71820df4f8bc312938c4878f358573bacc8 overview: https://github.com/axeld/haiku/compare/076dba5...05cba71 ---------------------------------------------------------------------------- 9eccfaf: 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. 4338b54: Removed commented out method in BMailSettingsView. 05cba71: Renamed BodyDownloadConfig to BodyDownloadConfigView. [ Axel DÃrfler <axeld@xxxxxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- 7 files changed, 135 insertions(+), 153 deletions(-) .../os/add-ons/mail_daemon/MailSettingsView.h | 2 - headers/private/mail/FileConfigView.h | 5 +- headers/private/mail/ProtocolConfigView.h | 26 +-- .../outbound_protocols/smtp/ConfigView.cpp | 27 ++- src/kits/mail/FileConfigView.cpp | 11 +- src/kits/mail/ProtocolConfigView.cpp | 213 +++++++++---------- src/preferences/mail/ConfigViews.cpp | 4 +- ############################################################################ Commit: 9eccfafd77a15d5bd859c7078629bc221dde5d46 Author: Axel DÃrfler <axeld@xxxxxxxxxxxxxxxx> Date: Thu Nov 22 22:51:48 2012 UTC 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. ---------------------------------------------------------------------------- diff --git a/headers/private/mail/FileConfigView.h b/headers/private/mail/FileConfigView.h index 40cc402..2f43667 100644 --- a/headers/private/mail/FileConfigView.h +++ b/headers/private/mail/FileConfigView.h @@ -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; diff --git a/headers/private/mail/ProtocolConfigView.h b/headers/private/mail/ProtocolConfigView.h index 7d79b81..b395c9a 100644 --- a/headers/private/mail/ProtocolConfigView.h +++ b/headers/private/mail/ProtocolConfigView.h @@ -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); diff --git a/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp b/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp index 990ca9d..01c472b 100644 --- a/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp +++ b/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp @@ -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); } diff --git a/src/kits/mail/FileConfigView.cpp b/src/kits/mail/FileConfigView.cpp index cd463cd..432a889 100644 --- a/src/kits/mail/FileConfigView.cpp +++ b/src/kits/mail/FileConfigView.cpp @@ -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()); } diff --git a/src/kits/mail/ProtocolConfigView.cpp b/src/kits/mail/ProtocolConfigView.cpp index 0fb4ec7..4edebc6 100644 --- a/src/kits/mail/ProtocolConfigView.cpp +++ b/src/kits/mail/ProtocolConfigView.cpp @@ -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"); - - BRect r(0, 0, 280, 15); - fPartialBox = new BCheckBox(r, "size_if", partial_text, - new BMessage('SIZF')); - fPartialBox->ResizeToPreferred(); - - 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", "KB"); - AddChild(fBytesLabel); - fSizeBox->SetDivider(0); - - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - AddChild(fPartialBox); - AddChild(fSizeBox); - ResizeToPreferred(); + fPartialBox = new BCheckBox("size_if", B_TRANSLATE( + "Partially download messages larger than"), new BMessage('SIZF')); + + fSizeControl = new BTextControl("size", + B_TRANSLATE_COMMENT("KB", "kilo byte"), "", NULL); + fSizeControl->SetExplicitMinSize(BSize(be_plain_font->StringWidth("0000"), + B_SIZE_UNSET)); + + 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,38 +265,8 @@ MailProtocolConfigView::Layout() const } -void -MailProtocolConfigView::AttachedToWindow() -{ - if (fAuthenticationField != NULL) - fAuthenticationField->Menu()->SetTargetForItems(this); - - if (fLeaveOnServerCheckBox != NULL) - fLeaveOnServerCheckBox->SetTarget(this); -} - - -void -MailProtocolConfigView::MessageReceived(BMessage* message) -{ - switch (message->what) { - case kMsgNeedPassword: - _SetCredentialsEnabled(true); - break; - case kMsgNoPassword: - _SetCredentialsEnabled(false); - break; - - case kMsgLeaveOnServer: - fRemoveFromServerCheckBox->SetEnabled( - message->FindInt32("be:value") == B_CONTROL_ON); - break; - } -} - - status_t -MailProtocolConfigView::Archive(BMessage* into, bool deep) const +MailProtocolConfigView::SaveInto(BMailAddOnSettings& settings) const { if (fHostControl != NULL) { int32 port = -1; @@ -324,46 +276,75 @@ MailProtocolConfigView::Archive(BMessage* into, bool deep) const hostName.Truncate(hostName.FindFirst(':')); } - if (into->ReplaceString("server", hostName.String()) != B_OK) - into->AddString("server", hostName.String()); + settings.SetString("server", hostName); // since there is no need for the port option, remove it here - into->RemoveName("port"); if (port != -1) - into->AddInt32("port", port); + settings.SetInt32("port", port); + else + settings.RemoveName("port"); } else { - into->RemoveName("server"); - into->RemoveName("port"); + settings.RemoveName("server"); + settings.RemoveName("port"); } - if (fUserControl != NULL) { - if (into->ReplaceString("username", fUserControl->Text()) != B_OK) - into->AddString("username", fUserControl->Text()); - } else - into->RemoveName("username"); + if (fUserControl != NULL) + settings.SetString("username", fUserControl->Text()); + else + settings.RemoveName("username"); // remove old unencrypted passwords - into->RemoveName("password"); + settings.RemoveName("password"); if (fPasswordControl != NULL) - set_passwd(into, "cpasswd", fPasswordControl->Text()); + set_passwd(&settings, "cpasswd", fPasswordControl->Text()); else - into->RemoveName("cpasswd"); + settings.RemoveName("cpasswd"); - _StoreIndexOfMarked(*into, "flavor", fFlavorField); - _StoreIndexOfMarked(*into, "auth_method", fAuthenticationField); + _StoreIndexOfMarked(settings, "flavor", fFlavorField); + _StoreIndexOfMarked(settings, "auth_method", fAuthenticationField); - _StoreCheckBox(*into, "leave_mail_on_server", fLeaveOnServerCheckBox); - _StoreCheckBox(*into, "delete_remote_when_local", + _StoreCheckBox(settings, "leave_mail_on_server", fLeaveOnServerCheckBox); + _StoreCheckBox(settings, "delete_remote_when_local", fRemoveFromServerCheckBox); if (fBodyDownloadConfig != NULL) - return fBodyDownloadConfig->Archive(into, deep); + return fBodyDownloadConfig->SaveInto(settings); return B_OK; } +void +MailProtocolConfigView::AttachedToWindow() +{ + if (fAuthenticationField != NULL) + fAuthenticationField->Menu()->SetTargetForItems(this); + + if (fLeaveOnServerCheckBox != NULL) + fLeaveOnServerCheckBox->SetTarget(this); +} + + +void +MailProtocolConfigView::MessageReceived(BMessage* message) +{ + switch (message->what) { + case kMsgNeedPassword: + _SetCredentialsEnabled(true); + break; + case kMsgNoPassword: + _SetCredentialsEnabled(false); + break; + + case kMsgLeaveOnServer: + fRemoveFromServerCheckBox->SetEnabled( + message->FindInt32("be:value") == B_CONTROL_ON); + break; + } +} + + 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); } diff --git a/src/preferences/mail/ConfigViews.cpp b/src/preferences/mail/ConfigViews.cpp index 5df3f1f..05c66f7 100644 --- a/src/preferences/mail/ConfigViews.cpp +++ b/src/preferences/mail/ConfigViews.cpp @@ -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; ############################################################################ Commit: 4338b542806516695a1f6c18b0d17ec58f37f181 Author: Axel DÃrfler <axeld@xxxxxxxxxxxxxxxx> Date: Thu Nov 22 22:53:56 2012 UTC Removed commented out method in BMailSettingsView. ---------------------------------------------------------------------------- diff --git a/headers/os/add-ons/mail_daemon/MailSettingsView.h b/headers/os/add-ons/mail_daemon/MailSettingsView.h index 30f2892..2d0b6a7 100644 --- a/headers/os/add-ons/mail_daemon/MailSettingsView.h +++ b/headers/os/add-ons/mail_daemon/MailSettingsView.h @@ -15,8 +15,6 @@ public: BMailSettingsView(const char* name); virtual ~BMailSettingsView(); -// virtual BString DescriptiveName() const = 0; - virtual status_t SaveInto( BMailAddOnSettings& settings) const = 0; }; ############################################################################ Commit: 05cba71820df4f8bc312938c4878f358573bacc8 Author: Axel DÃrfler <axeld@xxxxxxxxxxxxxxxx> Date: Thu Nov 22 22:55:30 2012 UTC Renamed BodyDownloadConfig to BodyDownloadConfigView. ---------------------------------------------------------------------------- diff --git a/headers/private/mail/ProtocolConfigView.h b/headers/private/mail/ProtocolConfigView.h index b395c9a..7248d94 100644 --- a/headers/private/mail/ProtocolConfigView.h +++ b/headers/private/mail/ProtocolConfigView.h @@ -26,9 +26,9 @@ class BTextControl; namespace BPrivate { -class BodyDownloadConfig : public BView { +class BodyDownloadConfigView : public BView { public: - BodyDownloadConfig(); + BodyDownloadConfigView(); void SetTo(const BMailProtocolSettings& settings); @@ -96,7 +96,7 @@ private: BMenuField* fAuthenticationField; BCheckBox* fLeaveOnServerCheckBox; BCheckBox* fRemoveFromServerCheckBox; - BodyDownloadConfig* fBodyDownloadConfig; + BodyDownloadConfigView* fBodyDownloadConfig; }; diff --git a/src/kits/mail/ProtocolConfigView.cpp b/src/kits/mail/ProtocolConfigView.cpp index 4edebc6..3235bfc 100644 --- a/src/kits/mail/ProtocolConfigView.cpp +++ b/src/kits/mail/ProtocolConfigView.cpp @@ -42,7 +42,7 @@ static const uint32 kMsgNeedPassword = 'some'; namespace BPrivate { -BodyDownloadConfig::BodyDownloadConfig() +BodyDownloadConfigView::BodyDownloadConfigView() : BView("body_config", 0) { @@ -63,7 +63,7 @@ BodyDownloadConfig::BodyDownloadConfig() void -BodyDownloadConfig::SetTo(const BMailProtocolSettings& settings) +BodyDownloadConfigView::SetTo(const BMailProtocolSettings& settings) { int32 limit = settings.GetInt32(kPartialDownloadLimit, -1); if (limit < 0) { @@ -81,7 +81,7 @@ BodyDownloadConfig::SetTo(const BMailProtocolSettings& settings) status_t -BodyDownloadConfig::SaveInto(BMailAddOnSettings& settings) const +BodyDownloadConfigView::SaveInto(BMailAddOnSettings& settings) const { if (fPartialBox->Value() == B_CONTROL_ON) { settings.SetInt32(kPartialDownloadLimit, @@ -94,7 +94,7 @@ BodyDownloadConfig::SaveInto(BMailAddOnSettings& settings) const void -BodyDownloadConfig::MessageReceived(BMessage *msg) +BodyDownloadConfigView::MessageReceived(BMessage *msg) { if (msg->what != 'SIZF') return BView::MessageReceived(msg); @@ -103,7 +103,7 @@ BodyDownloadConfig::MessageReceived(BMessage *msg) void -BodyDownloadConfig::AttachedToWindow() +BodyDownloadConfigView::AttachedToWindow() { fPartialBox->SetTarget(this); fPartialBox->ResizeToPreferred(); @@ -166,7 +166,7 @@ MailProtocolConfigView::MailProtocolConfigView(uint32 optionsMask) } if ((optionsMask & B_MAIL_PROTOCOL_PARTIAL_DOWNLOAD) != 0) { - fBodyDownloadConfig = new BodyDownloadConfig(); + fBodyDownloadConfig = new BodyDownloadConfigView(); layout->AddView(fBodyDownloadConfig, 0, layout->CountRows(), 2); } }