1/*
2 * Copyright 2004-2012, Haiku Inc. All rights reserved.
3 * Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved.
4 * Copyright 2011 Clemens Zeidler.
5 *
6 * Distributed under the terms of the MIT License.
7 */
8#ifndef MAIL_SETTINGS_H
9#define MAIL_SETTINGS_H
10
11
12#include <vector>
13
14#include <Archivable.h>
15#include <Entry.h>
16#include <List.h>
17#include <Message.h>
18#include <ObjectList.h>
19#include <String.h>
20
21
22class BPath;
23
24
25typedef enum {
26	B_MAIL_SHOW_STATUS_WINDOW_NEVER         = 0,
27	B_MAIL_SHOW_STATUS_WINDOW_WHEN_SENDING	= 1,
28	B_MAIL_SHOW_STATUS_WINDOW_WHEN_ACTIVE	= 2,
29	B_MAIL_SHOW_STATUS_WINDOW_ALWAYS        = 3
30} b_mail_status_window_option;
31
32
33class BMailSettings {
34public:
35								BMailSettings();
36								~BMailSettings();
37
38			status_t			Save();
39			status_t			Reload();
40			status_t			InitCheck() const;
41
42			// Global settings
43			int32				WindowFollowsCorner();
44			void				SetWindowFollowsCorner(int32 which_corner);
45
46			uint32				ShowStatusWindow();
47			void				SetShowStatusWindow(uint32 mode);
48
49			bool				DaemonAutoStarts();
50			void				SetDaemonAutoStarts(bool does_it);
51
52			void				SetConfigWindowFrame(BRect frame);
53			BRect				ConfigWindowFrame();
54
55			void				SetStatusWindowFrame(BRect frame);
56			BRect				StatusWindowFrame();
57
58			int32				StatusWindowWorkspaces();
59			void				SetStatusWindowWorkspaces(int32 workspaces);
60
61			int32				StatusWindowLook();
62			void				SetStatusWindowLook(int32 look);
63
64			bigtime_t			AutoCheckInterval();
65			void				SetAutoCheckInterval(bigtime_t);
66
67			bool				CheckOnlyIfPPPUp();
68			void				SetCheckOnlyIfPPPUp(bool yes);
69
70			bool				SendOnlyIfPPPUp();
71			void				SetSendOnlyIfPPPUp(bool yes);
72
73			int32				DefaultOutboundAccount();
74			void				SetDefaultOutboundAccount(int32 to);
75
76private:
77			BMessage			fData;
78			uint32				_reserved[4];
79};
80
81
82class BMailAddOnSettings : public BMessage {
83public:
84								BMailAddOnSettings();
85	virtual						~BMailAddOnSettings();
86
87	virtual status_t			Load(const BMessage& message);
88	virtual	status_t			Save(BMessage& message);
89
90			void				SetAddOnRef(const entry_ref& ref);
91			const entry_ref&	AddOnRef() const;
92
93	virtual	bool				HasBeenModified() const;
94
95private:
96			const char*			_RelativizePath(const BPath& path) const;
97
98private:
99			BMessage			fOriginalSettings;
100			entry_ref			fRef;
101			entry_ref			fOriginalRef;
102};
103
104
105class BMailProtocolSettings : public BMailAddOnSettings {
106public:
107								BMailProtocolSettings();
108	virtual						~BMailProtocolSettings();
109
110	virtual	status_t			Load(const BMessage& message);
111	virtual	status_t			Save(BMessage& message);
112
113			int32				CountFilterSettings() const;
114			int32				AddFilterSettings(const entry_ref* ref = NULL);
115			void				RemoveFilterSettings(int32 index);
116			bool				MoveFilterSettings(int32 from, int32 to);
117			BMailAddOnSettings*	FilterSettingsAt(int32 index) const;
118
119	virtual	bool				HasBeenModified() const;
120
121private:
122			BObjectList<BMailAddOnSettings> fFiltersSettings;
123};
124
125
126class BMailAccountSettings {
127public:
128								BMailAccountSettings();
129								BMailAccountSettings(BEntry account);
130								~BMailAccountSettings();
131
132			status_t			InitCheck() { return fStatus; }
133
134			void				SetAccountID(int32 id);
135			int32				AccountID() const;
136
137			void				SetName(const char* name);
138			const char*			Name() const;
139
140			void				SetRealName(const char* realName);
141			const char*			RealName() const;
142
143			void				SetReturnAddress(const char* returnAddress);
144			const char*			ReturnAddress() const;
145
146			bool				SetInboundAddOn(const char* name);
147			bool				SetOutboundAddOn(const char* name);
148			const entry_ref&	InboundAddOnRef() const;
149			const entry_ref&	OutboundAddOnRef() const;
150
151			BMailProtocolSettings& InboundSettings();
152			const BMailProtocolSettings& InboundSettings() const;
153			BMailProtocolSettings& OutboundSettings();
154			const BMailProtocolSettings& OutboundSettings() const;
155
156			bool				HasInbound();
157			bool				HasOutbound();
158
159			void				SetInboundEnabled(bool enabled = true);
160			bool				IsInboundEnabled() const;
161			void				SetOutboundEnabled(bool enabled = true);
162			bool				IsOutboundEnabled() const;
163
164			status_t			Reload();
165			status_t			Save();
166			status_t			Delete();
167
168			bool				HasBeenModified() const;
169
170			const BEntry&		AccountFile() const;
171
172private:
173			status_t			_CreateAccountFilePath();
174			status_t			_GetAddOnRef(const char* subPath,
175									const char* name, entry_ref& ref);
176
177private:
178			status_t			fStatus;
179			BEntry				fAccountFile;
180
181			int32				fAccountID;
182
183			BString				fAccountName;
184			BString				fRealName;
185			BString				fReturnAdress;
186
187			BMailProtocolSettings fInboundSettings;
188			BMailProtocolSettings fOutboundSettings;
189
190			bool				fInboundEnabled;
191			bool				fOutboundEnabled;
192
193			bool				fModified;
194};
195
196
197class BMailAccounts {
198public:
199								BMailAccounts();
200								~BMailAccounts();
201
202	static	status_t			AccountsPath(BPath& path);
203
204			int32				CountAccounts();
205			BMailAccountSettings*	AccountAt(int32 index);
206
207			BMailAccountSettings*	AccountByID(int32 id);
208			BMailAccountSettings*	AccountByName(const char* name);
209private:
210			BObjectList<BMailAccountSettings>	fAccounts;
211};
212
213
214#endif	/* ZOIDBERG_MAIL_SETTINGS_H */
215