2 * Copyright 2007-2012, Haiku, Inc. All rights reserved.
3 * Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
5 * Distributed under the terms of the MIT License.
9 //! Config views for the account, protocols, and filters.
12 #include "ConfigViews.h"
17 #include <Directory.h>
19 #include <FindDirectory.h>
21 #include <LayoutBuilder.h>
24 #include <MenuField.h>
27 #include <PopUpMenu.h>
28 #include <TextControl.h>
32 #include <MailSettings.h>
34 #include "FilterConfigView.h"
37 #undef B_TRANSLATION_CONTEXT
38 #define B_TRANSLATION_CONTEXT "Config Views"
42 const uint32 kMsgAccountNameChanged
= 'anmc';
44 // ProtocolsConfigView
45 const uint32 kMsgProtocolChanged
= 'prch';
51 AccountConfigView::AccountConfigView(BMailAccountSettings
* account
)
56 SetLabel(B_TRANSLATE("Account settings"));
58 fNameControl
= new BTextControl(NULL
, B_TRANSLATE("Account name:"), NULL
,
59 new BMessage(kMsgAccountNameChanged
));
60 fRealNameControl
= new BTextControl(NULL
, B_TRANSLATE("Real name:"), NULL
,
62 fReturnAddressControl
= new BTextControl(NULL
,
63 B_TRANSLATE("Return address:"), NULL
, NULL
);
65 BView
* contents
= new BView(NULL
, 0);
68 BLayoutBuilder::Grid
<>(contents
, 0.f
)
69 .SetInsets(B_USE_DEFAULT_SPACING
)
70 .Add(fNameControl
->CreateLabelLayoutItem(), 0, 0)
71 .Add(fNameControl
->CreateTextViewLayoutItem(), 1, 0)
72 .Add(fRealNameControl
->CreateLabelLayoutItem(), 0, 1)
73 .Add(fRealNameControl
->CreateTextViewLayoutItem(), 1, 1)
74 .Add(fReturnAddressControl
->CreateLabelLayoutItem(), 0, 2)
75 .Add(fReturnAddressControl
->CreateTextViewLayoutItem(), 1, 2)
81 AccountConfigView::DetachedFromWindow()
83 fAccount
->SetName(fNameControl
->Text());
84 fAccount
->SetRealName(fRealNameControl
->Text());
85 fAccount
->SetReturnAddress(fReturnAddressControl
->Text());
90 AccountConfigView::AttachedToWindow()
93 fNameControl
->SetTarget(this);
98 AccountConfigView::MessageReceived(BMessage
*msg
)
101 case kMsgAccountNameChanged
:
102 fAccount
->SetName(fNameControl
->Text());
106 BView::MessageReceived(msg
);
112 AccountConfigView::UpdateViews()
114 fNameControl
->SetText(fAccount
->Name());
115 fRealNameControl
->SetText(fAccount
->RealName());
116 fReturnAddressControl
->SetText(fAccount
->ReturnAddress());
123 ProtocolSettingsView::ProtocolSettingsView(const entry_ref
& ref
,
124 const BMailAccountSettings
& accountSettings
,
125 BMailProtocolSettings
& settings
)
131 status_t status
= _CreateSettingsView(ref
, accountSettings
, settings
);
132 BView
* view
= fSettingsView
;
134 if (status
== B_OK
) {
137 BString
text(B_TRANSLATE("An error occurred while creating the "
138 "config view: %error."));
139 text
.ReplaceAll("%error", strerror(status
));
140 view
= new BStringView("error", text
.String());
142 SetLabel(B_TRANSLATE("Error!"));
145 BView
* contents
= new BView(NULL
, 0);
148 BLayoutBuilder::Group
<>(contents
, B_VERTICAL
)
149 .SetInsets(B_USE_DEFAULT_SPACING
)
156 ProtocolSettingsView::DetachedFromWindow()
158 if (fSettingsView
== NULL
)
161 if (fSettingsView
->SaveInto(fSettings
) != B_OK
)
164 // We need to remove the settings view before unloading its add-on
165 fSettingsView
->RemoveSelf();
166 delete fSettingsView
;
167 fSettingsView
= NULL
;
168 unload_add_on(fImage
);
173 ProtocolSettingsView::_CreateSettingsView(const entry_ref
& ref
,
174 const BMailAccountSettings
& accountSettings
,
175 BMailProtocolSettings
& settings
)
177 BMailSettingsView
* (*instantiateConfig
)(
178 const BMailAccountSettings
& accountSettings
,
179 BMailProtocolSettings
& settings
);
181 image_id image
= load_add_on(path
.Path());
185 if (get_image_symbol(image
, "instantiate_protocol_settings_view",
186 B_SYMBOL_TYPE_TEXT
, (void**)&instantiateConfig
) != B_OK
) {
187 unload_add_on(image
);
188 return B_MISSING_SYMBOL
;
192 fSettingsView
= instantiateConfig(accountSettings
, settings
);