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