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
ConfigView(const BMailAccountSettings & accountSettings,const BMailProtocolSettings & settings)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 | B_MAIL_PROTOCOL_HAS_FLAVORS
61 )
62 {
63 AddFlavor(B_TRANSLATE("No encryption"));
64 AddFlavor(B_TRANSLATE("SSL"));
65
66 SetTo(settings);
67
68 ((BControl*)(FindView("leave_mail_on_server")))->SetValue(B_CONTROL_ON);
69 ((BControl*)(FindView("leave_mail_on_server")))->Hide();
70
71 fFolderButton = new BButton("IMAP Folders", B_TRANSLATE(
72 "Configure IMAP Folders"), new BMessage(kMsgOpenIMAPFolder));
73 Layout()->AddView(fFolderButton, 0, Layout()->CountRows(), 2);
74
75 BPath defaultFolder = BPrivate::default_mail_directory();
76 defaultFolder.Append(accountSettings.Name());
77
78 fFileView = new MailFileConfigView(B_TRANSLATE("Destination:"),
79 "destination", false, defaultFolder.Path());
80 fFileView->SetTo(&settings, NULL);
81
82 Layout()->AddView(fFileView, 0, Layout()->CountRows(),
83 Layout()->CountColumns());
84 }
85
86
~ConfigView()87 ConfigView::~ConfigView()
88 {
89 }
90
91
92 status_t
SaveInto(BMailAddOnSettings & settings) const93 ConfigView::SaveInto(BMailAddOnSettings& settings) const
94 {
95 status_t status = fFileView->SaveInto(settings);
96 if (status != B_OK)
97 return status;
98
99 return MailProtocolConfigView::SaveInto(settings);
100 }
101
102
103 void
MessageReceived(BMessage * message)104 ConfigView::MessageReceived(BMessage* message)
105 {
106 switch (message->what) {
107 case kMsgOpenIMAPFolder:
108 {
109 // Retrieve current settings
110 BMailAddOnSettings settings;
111 SaveInto(settings);
112
113 BWindow* window = new FolderConfigWindow(Window()->Frame(),
114 settings);
115 window->Show();
116 break;
117 }
118
119 default:
120 MailProtocolConfigView::MessageReceived(message);
121 }
122 }
123
124
125 void
AttachedToWindow()126 ConfigView::AttachedToWindow()
127 {
128 fFolderButton->SetTarget(this);
129 }
130
131
132 // #pragma mark -
133
134
135 BMailSettingsView*
instantiate_protocol_settings_view(const BMailAccountSettings & accountSettings,const BMailProtocolSettings & settings)136 instantiate_protocol_settings_view(const BMailAccountSettings& accountSettings,
137 const BMailProtocolSettings& settings)
138 {
139 return new ConfigView(accountSettings, settings);
140 }
141