xref: /haiku/src/preferences/mail/AutoConfigView.h (revision c302a243e15e640fae0f689e32cdf0c18749afee)
1 /*
2  * Copyright 2007-2015, Haiku, Inc. All rights reserved.
3  * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef AUTO_CONFIG_VIEW_H
7 #define AUTO_CONFIG_VIEW_H
8 
9 
10 #include "AutoConfig.h"
11 #include "ConfigViews.h"
12 
13 #include <Box.h>
14 #include <Entry.h>
15 #include <GroupView.h>
16 #include <MenuField.h>
17 #include <String.h>
18 #include <TextControl.h>
19 
20 class BPopUpMenu;
21 
22 
23 const int32	kNameChangedMsg			=	'?nch';
24 const int32	kEMailChangedMsg		=	'?ech';
25 const int32 kProtokollChangedMsg	=	'?pch';
26 const int32 kServerChangedMsg		=	'?sch';
27 
28 
29 enum protocol_type {
30 	POP,
31 	IMAP,
32 	SMTP
33 };
34 
35 
36 struct account_info {
37 	protocol_type	inboundType;
38 	entry_ref		inboundProtocol;
39 	entry_ref		outboundProtocol;
40 	BString			name;
41 	BString			accountName;
42 	BString			email;
43 	BString			loginName;
44 	BString			password;
45 	provider_info	providerInfo;
46 };
47 
48 
49 class AutoConfigView : public BBox {
50 public:
51 								AutoConfigView(AutoConfig& config);
52 
53 	virtual	void				AttachedToWindow();
54 	virtual	void				MessageReceived(BMessage* msg);
55 
56 			bool				GetBasicAccountInfo(account_info& info);
57 			bool				IsValidMailAddress(BString email);
58 
59 private:
60 			BPopUpMenu*			_SetupProtocolMenu();
61 			status_t			_GetSMTPAddOnRef(entry_ref* ref);
62 
63 			BString				_ExtractLocalPart(const char* email);
64 			void				_ProposeUsername();
65 
66 private:
67 			entry_ref			fSMTPAddOnRef;
68 			BMenuField*			fInProtocolsField;
69 			BTextControl*		fNameView;
70 			BTextControl*		fAccountNameView;
71 			BTextControl*		fEmailView;
72 			BTextControl*		fLoginNameView;
73 			BTextControl*		fPasswordView;
74 
75 			// ref to the parent autoconfig so you only ones read the database
76 			AutoConfig&			fAutoConfig;
77 };
78 
79 
80 class ServerSettingsView : public BGroupView {
81 public:
82 								ServerSettingsView(const account_info& info);
83 								~ServerSettingsView();
84 			void				GetServerInfo(account_info& info);
85 
86 private:
87 			void				_DetectMenuChanges();
88 			bool				_HasMarkedChanged(BMenuField* field,
89 									BMenuItem* originalItem);
90 			void				_GetAuthEncrMenu(entry_ref protocol,
91 									BMenuField*& authField,
92 									BMenuField*& sslField);
93 
94 private:
95 			bool				fInboundAccount;
96 			bool				fOutboundAccount;
97 			BTextControl*		fInboundNameView;
98 			BMenuField*			fInboundAuthMenu;
99 			BMenuField*			fInboundEncryptionMenu;
100 			BTextControl*		fOutboundNameView;
101 			BMenuField*			fOutboundAuthMenu;
102 			BMenuField*			fOutboundEncryptionMenu;
103 
104 			BMenuItem*			fInboundAuthItemStart;
105 			BMenuItem*			fInboundEncrItemStart;
106 			BMenuItem*			fOutboundAuthItemStart;
107 			BMenuItem*			fOutboundEncrItemStart;
108 
109 			image_id			fImageID;
110 };
111 
112 
113 #endif	// AUTO_CONFIG_VIEW_H
114