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