MailSettings.h revision 1f87386b
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			BMessage			fOriginalSettings;
97			entry_ref			fRef;
98			entry_ref			fOriginalRef;
99};
100
101
102class BMailProtocolSettings : public BMailAddOnSettings {
103public:
104								BMailProtocolSettings();
105	virtual						~BMailProtocolSettings();
106
107	virtual	status_t			Load(const BMessage& message);
108	virtual	status_t			Save(BMessage& message);
109
110			int32				CountFilterSettings() const;
111			int32				AddFilterSettings(const entry_ref* ref = NULL);
112			void				RemoveFilterSettings(int32 index);
113			bool				MoveFilterSettings(int32 from, int32 to);
114			BMailAddOnSettings*	FilterSettingsAt(int32 index) const;
115
116	virtual	bool				HasBeenModified() const;
117
118private:
119			BObjectList<BMailAddOnSettings> fFiltersSettings;
120};
121
122
123class BMailAccountSettings {
124public:
125								BMailAccountSettings();
126								BMailAccountSettings(BEntry account);
127								~BMailAccountSettings();
128
129			status_t			InitCheck() { return fStatus; }
130
131			void				SetAccountID(int32 id);
132			int32				AccountID() const;
133
134			void				SetName(const char* name);
135			const char*			Name() const;
136
137			void				SetRealName(const char* realName);
138			const char*			RealName() const;
139
140			void				SetReturnAddress(const char* returnAddress);
141			const char*			ReturnAddress() const;
142
143			bool				SetInboundAddOn(const char* name);
144			bool				SetOutboundAddOn(const char* name);
145			const entry_ref&	InboundAddOnRef() const;
146			const entry_ref&	OutboundAddOnRef() const;
147
148			BMailProtocolSettings& InboundSettings();
149			const BMailProtocolSettings& InboundSettings() const;
150			BMailProtocolSettings& OutboundSettings();
151			const BMailProtocolSettings& OutboundSettings() const;
152
153			bool				HasInbound();
154			bool				HasOutbound();
155
156			void				SetInboundEnabled(bool enabled = true);
157			bool				IsInboundEnabled() const;
158			void				SetOutboundEnabled(bool enabled = true);
159			bool				IsOutboundEnabled() const;
160
161			status_t			Reload();
162			status_t			Save();
163			status_t			Delete();
164
165			bool				HasBeenModified() const;
166
167			const BEntry&		AccountFile() const;
168
169private:
170			status_t			_CreateAccountFilePath();
171
172private:
173			status_t			fStatus;
174			BEntry				fAccountFile;
175
176			int32				fAccountID;
177
178			BString				fAccountName;
179			BString				fRealName;
180			BString				fReturnAdress;
181
182			BMailProtocolSettings fInboundSettings;
183			BMailProtocolSettings fOutboundSettings;
184
185			bool				fInboundEnabled;
186			bool				fOutboundEnabled;
187
188			bool				fModified;
189};
190
191
192class BMailAccounts {
193public:
194								BMailAccounts();
195								~BMailAccounts();
196
197	static	status_t			AccountsPath(BPath& path);
198
199			int32				CountAccounts();
200			BMailAccountSettings*	AccountAt(int32 index);
201
202			BMailAccountSettings*	AccountByID(int32 id);
203			BMailAccountSettings*	AccountByName(const char* name);
204private:
205			BObjectList<BMailAccountSettings>	fAccounts;
206};
207
208
209#endif	/* ZOIDBERG_MAIL_SETTINGS_H */
210