xref: /haiku/src/add-ons/mail_daemon/outbound_protocols/smtp/ConfigView.cpp (revision 4fd62caa9acc437534c41bbb7d3fc9d53e915005)
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_TRANSLATION_CONTEXT
21 #define B_TRANSLATION_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 	B_TRANSLATE_MARK_VOID("Unencrypted");
47 	B_TRANSLATE_MARK_VOID("SSL");
48 	B_TRANSLATE_MARK_VOID("STARTTLS");
49 
50 #ifdef USE_SSL
51 	AddFlavor(B_TRANSLATE_NOCOLLECT("Unencrypted"));
52 	AddFlavor(B_TRANSLATE("SSL"));
53 	AddFlavor(B_TRANSLATE("STARTTLS"));
54 #endif
55 
56 	AddAuthMethod(B_TRANSLATE("None"), false);
57 	AddAuthMethod(B_TRANSLATE("ESMTP"));
58 	AddAuthMethod(B_TRANSLATE("POP3 before SMTP"), false);
59 
60 	BTextControl *control = (BTextControl *)(FindView("host"));
61 	control->SetLabel(B_TRANSLATE("SMTP server:"));
62 
63 	// Reset the dividers after changing one
64 	float widestLabel = 0;
65 	for (int32 i = CountChildren(); i-- > 0;) {
66 		if (BTextControl *text = dynamic_cast<BTextControl *>(ChildAt(i)))
67 			widestLabel = MAX(widestLabel,text->StringWidth(text->Label()) + 5);
68 	}
69 	for (int32 i = CountChildren(); i-- > 0;) {
70 		if (BTextControl *text = dynamic_cast<BTextControl *>(ChildAt(i)))
71 			text->SetDivider(widestLabel);
72 	}
73 
74 	BMenuField *field = (BMenuField *)(FindView("auth_method"));
75 	field->SetDivider(widestLabel);
76 
77 	SetTo(settings);
78 
79 	fFileView = new BMailFileConfigView(B_TRANSLATE("Destination:"), "path",
80 		false, BPrivate::default_mail_out_directory().Path());
81 	fFileView->SetTo(&settings.Settings(), NULL);
82 	AddChild(fFileView);
83 	float w, h;
84 	BMailProtocolConfigView::GetPreferredSize(&w, &h);
85 	fFileView->MoveBy(0, h - 10);
86 	GetPreferredSize(&w, &h);
87 	ResizeTo(w, h);
88 }
89 
90 
91 status_t
92 SMTPConfigView::Archive(BMessage *into, bool deep) const
93 {
94 	fFileView->Archive(into, deep);
95 	return BMailProtocolConfigView::Archive(into, deep);
96 }
97 
98 
99 void
100 SMTPConfigView::GetPreferredSize(float* width, float* height)
101 {
102 	BMailProtocolConfigView::GetPreferredSize(width, height);
103 	*width += 20;
104 	*height += 20;
105 }
106 
107 
108 BView*
109 instantiate_config_panel(MailAddonSettings& settings,
110 	BMailAccountSettings& accountSettings)
111 {
112 	return new SMTPConfigView(settings, accountSettings);
113 }
114 
115