xref: /haiku/src/add-ons/mail_daemon/inbound_protocols/imap/ConfigView.cpp (revision 90c3b9bf9fe633e4c6a59d42c11c3f523183c553)
1 /*
2  * Copyright 2001-2013, 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 <Button.h>
11 #include <Catalog.h>
12 #include <GridLayout.h>
13 #include <Path.h>
14 #include <TextControl.h>
15 
16 #include <MailFilter.h>
17 
18 #include <FileConfigView.h>
19 #include <ProtocolConfigView.h>
20 #include <MailPrivate.h>
21 
22 #include "FolderConfigWindow.h"
23 
24 
25 #undef B_TRANSLATION_CONTEXT
26 #define B_TRANSLATION_CONTEXT "imap_config"
27 
28 
29 using namespace BPrivate;
30 
31 
32 const uint32 kMsgOpenIMAPFolder = '&OIF';
33 
34 
35 class ConfigView : public MailProtocolConfigView {
36 public:
37 								ConfigView(
38 									const BMailAccountSettings& accountSettings,
39 									const BMailProtocolSettings& settings);
40 	virtual						~ConfigView();
41 
42 	virtual status_t			SaveInto(BMailAddOnSettings& settings) const;
43 
44 	virtual	void				MessageReceived(BMessage* message);
45 	virtual void				AttachedToWindow();
46 
47 private:
48 			MailFileConfigView*	fFileView;
49 			BButton*			fFolderButton;
50 };
51 
52 
53 ConfigView::ConfigView(const BMailAccountSettings& accountSettings,
54 	const BMailProtocolSettings& settings)
55 	:
56 	MailProtocolConfigView(B_MAIL_PROTOCOL_HAS_USERNAME
57 		| B_MAIL_PROTOCOL_HAS_PASSWORD | B_MAIL_PROTOCOL_HAS_HOSTNAME
58 		| B_MAIL_PROTOCOL_CAN_LEAVE_MAIL_ON_SERVER
59 		| B_MAIL_PROTOCOL_PARTIAL_DOWNLOAD
60 #ifdef USE_SSL
61 	 	| B_MAIL_PROTOCOL_HAS_FLAVORS
62 #endif
63 	 )
64 {
65 #ifdef USE_SSL
66 	AddFlavor(B_TRANSLATE("No encryption"));
67 	AddFlavor(B_TRANSLATE("SSL"));
68 #endif
69 
70 	SetTo(settings);
71 
72 	((BControl*)(FindView("leave_mail_on_server")))->SetValue(B_CONTROL_ON);
73 	((BControl*)(FindView("leave_mail_on_server")))->Hide();
74 
75 	fFolderButton = new BButton("IMAP Folders", B_TRANSLATE(
76 		"Configure IMAP Folders"), new BMessage(kMsgOpenIMAPFolder));
77 	Layout()->AddView(fFolderButton, 0, Layout()->CountRows(), 2);
78 
79 	BPath defaultFolder = BPrivate::default_mail_directory();
80 	defaultFolder.Append(accountSettings.Name());
81 
82 	fFileView = new MailFileConfigView(B_TRANSLATE("Destination:"),
83 		"destination", false, defaultFolder.Path());
84 	fFileView->SetTo(&settings, NULL);
85 
86 	Layout()->AddView(fFileView, 0, Layout()->CountRows(),
87 		Layout()->CountColumns());
88 }
89 
90 
91 ConfigView::~ConfigView()
92 {
93 }
94 
95 
96 status_t
97 ConfigView::SaveInto(BMailAddOnSettings& settings) const
98 {
99 	status_t status = fFileView->SaveInto(settings);
100 	if (status != B_OK)
101 		return status;
102 
103 	return MailProtocolConfigView::SaveInto(settings);
104 }
105 
106 
107 void
108 ConfigView::MessageReceived(BMessage* message)
109 {
110 	switch (message->what) {
111 		case kMsgOpenIMAPFolder:
112 		{
113 			// Retrieve current settings
114 			BMailAddOnSettings settings;
115 			SaveInto(settings);
116 
117 			BWindow* window = new FolderConfigWindow(Window()->Frame(),
118 				settings);
119 			window->Show();
120 			break;
121 		}
122 
123 		default:
124 			MailProtocolConfigView::MessageReceived(message);
125 	}
126 }
127 
128 
129 void
130 ConfigView::AttachedToWindow()
131 {
132 	fFolderButton->SetTarget(this);
133 }
134 
135 
136 // #pragma mark -
137 
138 
139 BMailSettingsView*
140 instantiate_protocol_settings_view(const BMailAccountSettings& accountSettings,
141 	const BMailProtocolSettings& settings)
142 {
143 	return new ConfigView(accountSettings, settings);
144 }
145