xref: /haiku/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp (revision 9829800d2c60d6aba146af7fde09601929161730)
1 /*
2  * Copyright 2007-2011, Haiku, Inc. All rights reserved.
3  * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
4  * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
5  *
6  * Distributed under the terms of the MIT License.
7  */
8 
9 
10 #include <TextControl.h>
11 
12 #include <Catalog.h>
13 #include <FileConfigView.h>
14 #include <MailAddon.h>
15 #include <MenuField.h>
16 #include <MailPrivate.h>
17 #include <ProtocolConfigView.h>
18 
19 
20 #undef B_TRANSLATE_CONTEXT
21 #define B_TRANSLATE_CONTEXT "ConfigView"
22 
23 
24 class SMTPConfigView : public BMailProtocolConfigView {
25 public:
26 								SMTPConfigView(MailAddonSettings& settings,
27 									BMailAccountSettings& accountSettings);
28 			status_t			Archive(BMessage *into, bool deep = true) const;
29 			void				GetPreferredSize(float *width, float *height);
30 private:
31 			BMailFileConfigView* fFileView;
32 };
33 
34 
35 SMTPConfigView::SMTPConfigView(MailAddonSettings& settings,
36 	BMailAccountSettings& accountSettings)
37 	:
38 	BMailProtocolConfigView(B_MAIL_PROTOCOL_HAS_AUTH_METHODS
39 		| B_MAIL_PROTOCOL_HAS_USERNAME | B_MAIL_PROTOCOL_HAS_PASSWORD
40 		| B_MAIL_PROTOCOL_HAS_HOSTNAME
41 #ifdef USE_SSL
42 		| B_MAIL_PROTOCOL_HAS_FLAVORS
43 #endif
44 		)
45 {
46 #ifdef USE_SSL
47 	AddFlavor(B_TRANSLATE("Unencrypted"));
48 	AddFlavor(B_TRANSLATE("SSL"));
49 	AddFlavor(B_TRANSLATE("STARTTLS"));
50 #endif
51 
52 	AddAuthMethod(B_TRANSLATE("None"), false);
53 	AddAuthMethod(B_TRANSLATE("ESMTP"));
54 	AddAuthMethod(B_TRANSLATE("POP3 before SMTP"), false);
55 
56 	BTextControl *control = (BTextControl *)(FindView("host"));
57 	control->SetLabel(B_TRANSLATE("SMTP server:"));
58 
59 	// Reset the dividers after changing one
60 	float widestLabel = 0;
61 	for (int32 i = CountChildren(); i-- > 0;) {
62 		if (BTextControl *text = dynamic_cast<BTextControl *>(ChildAt(i)))
63 			widestLabel = MAX(widestLabel,text->StringWidth(text->Label()) + 5);
64 	}
65 	for (int32 i = CountChildren(); i-- > 0;) {
66 		if (BTextControl *text = dynamic_cast<BTextControl *>(ChildAt(i)))
67 			text->SetDivider(widestLabel);
68 	}
69 
70 	BMenuField *field = (BMenuField *)(FindView("auth_method"));
71 	field->SetDivider(widestLabel);
72 
73 	SetTo(settings);
74 
75 	fFileView = new BMailFileConfigView(B_TRANSLATE("Destination:"), "path",
76 		false, BPrivate::default_mail_out_directory().Path());
77 	fFileView->SetTo(&settings.Settings(), NULL);
78 	AddChild(fFileView);
79 	float w, h;
80 	BMailProtocolConfigView::GetPreferredSize(&w, &h);
81 	fFileView->MoveBy(0, h - 10);
82 	GetPreferredSize(&w, &h);
83 	ResizeTo(w, h);
84 }
85 
86 
87 status_t
88 SMTPConfigView::Archive(BMessage *into, bool deep) const
89 {
90 	fFileView->Archive(into, deep);
91 	return BMailProtocolConfigView::Archive(into, deep);
92 }
93 
94 
95 void
96 SMTPConfigView::GetPreferredSize(float* width, float* height)
97 {
98 	BMailProtocolConfigView::GetPreferredSize(width, height);
99 	*width += 20;
100 	*height += 20;
101 }
102 
103 
104 BView*
105 instantiate_config_panel(MailAddonSettings& settings,
106 	BMailAccountSettings& accountSettings)
107 {
108 	return new SMTPConfigView(settings, accountSettings);
109 }
110 
111