Debian Codegraph @

Dekko/backend/settings/SettingsPolicies.h

raw symbols SCIP
1 /**************************************************************************
2 Copyright (C) 2016 Dan Chapman <[email protected]>
3
4 This file is part of Dekko email client for Ubuntu devices
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 **************************************************************************/
19 #ifndef SETTINGSPOLICIES_H
20 #define SETTINGSPOLICIES_H
21
22 #include <QObject>
23 #include <qmailaccount.h>
24 #include <qmailstore.h>
25 #include "SettingsObjectBase.h"
26
27 /**
28 * @brief The PolicyInterface class
29 *
30 * Interface that all policies should implement.
31 *
32 * A Policy is a group of related configurations/settings.
33 */
34 class PolicyInterface
35 {
36 public:
37 /**
38 * @brief readPolicy
39 * @param policy
40 * @return policy value
41 */
42 virtual QString readPolicy(const QString &policy) = 0;
43 /**
44 * @brief setPolicy
45 * @param policy
46 * @param value
47 */
48 virtual void setPolicy(const QString &policy, const QString &value) = 0;
49 /**
50 * @brief setDefaults
51 */
52 virtual void setDefaults() = 0;
53 };
54 Q_DECLARE_INTERFACE(PolicyInterface, "PolicyInterface")
55
56 /**
57 * @brief The GlobalPolicy class
58 *
59 * This is the base class for all application wide policies. Each derived policy
60 * will get it's own atomic settings file located in the cache directory. You
61 * need to set the policies key in the constructor \see setSettingsKey().
62 *
63 * You also need to re-implement setDefaults() and createDefaultsIfNotExist(),
64 * usually createDefaultsIfNotExist() can just directly call setDefaults() but is
65 * left to the subclass implementor to do incase they want to add some extra logic
66 * before creating the default values.
67 */
68 class GlobalPolicy : public SettingsObjectBase, public PolicyInterface
69 {
70 Q_OBJECT
71 Q_INTERFACES(PolicyInterface)
72 public:
73 /**
74 * @brief GlobalPolicy
75 * @param parent
76 */
77 explicit GlobalPolicy(QObject *parent) : SettingsObjectBase(parent) {}
78
79 // PolicyInterface interface
80 public:
81 virtual QString readPolicy(const QString &policy) override {
82 return read(policy, QString()).toString();
83 }
84 virtual void setPolicy(const QString &policy, const QString &value) override {
85 write(policy, value);
86 }
87 virtual void setDefaults() override {}
88
89 // SettingsObjectBase interface
90 protected:
91 virtual void createDefaultsIfNotExist() override {}
92 };
93
94 class PrivacyPolicy : public GlobalPolicy
95 {
96 Q_OBJECT
97 /**
98 * @brief Allow automatic loading of remote content
99 * @accessors %allowRemoteContent(), setAllowRemoteContent()
100 */
101 Q_PROPERTY(bool allowRemoteContent READ allowRemoteContent WRITE setAllowRemoteContent NOTIFY policyChanged)
102 public:
103 explicit PrivacyPolicy(QObject *parent = 0);
104
105 bool allowRemoteContent();
106 void setAllowRemoteContent(const bool allowed);
107
108 // PolicyInterface interface
109 public:
110 virtual void setDefaults() override;
111
112 signals:
113 void policyChanged();
114
115 // SettingsObjectBase interface
116 protected:
117 virtual void createDefaultsIfNotExist() override;
118 };
119
120 class ViewPolicy : public GlobalPolicy
121 {
122 Q_OBJECT
123 /**
124 * @brief Crontrol and retain the state of the unified inbox expansion
125 * @accessors %unifiedInboxExpanded(), setUnifiedInboxExpanded()
126 */
127 Q_PROPERTY(bool unifiedInboxExpanded READ unifiedInboxExpanded WRITE setUnifiedInboxExpanded NOTIFY policyChanged)
128 /**
129 * @brief Crontrol and retain the state of the favourite folders expansion
130 * @accessors %favouritesExpanded(), favouritesExpanded()
131 */
132 Q_PROPERTY(bool favouritesExpanded READ favouritesExpanded WRITE setFavouritesExpanded NOTIFY policyChanged)
133 Q_PROPERTY(bool favouritesVisible READ favouritesVisible WRITE setFavouritesVisible NOTIFY policyChanged)
134 Q_PROPERTY(bool smartFoldersExpanded READ smartFoldersExpanded WRITE setSmartFoldersExpanded NOTIFY policyChanged)
135 Q_PROPERTY(bool smartFoldersVisible READ smartFoldersVisible WRITE setSmartFoldersVisible NOTIFY policyChanged)
136 Q_PROPERTY(bool accountsExpanded READ accountsExpanded WRITE setAccountsExpanded NOTIFY policyChanged)
137 Q_PROPERTY(bool accountsVisible READ accountsVisible WRITE setAccountsVisible NOTIFY policyChanged)
138 Q_PROPERTY(bool gravatarEnabled READ gravatarEnabled WRITE setGravatarEnabled NOTIFY policyChanged)
139 Q_PROPERTY(bool hideMarkedDeleted READ hideMarkedDeleted WRITE setHideMarkedDeleted NOTIFY policyChanged)
140 Q_PROPERTY(bool preferPlainText READ preferPlainText WRITE setPreferPlainText NOTIFY policyChanged)
141 Q_PROPERTY(int previewLines READ previewLines WRITE setPreviewLines NOTIFY policyChanged)
142 Q_PROPERTY(bool threadViewEnabled READ threadViewEnabled WRITE setThreadViewEnabled NOTIFY policyChanged)
143 Q_PROPERTY(bool showToasts READ showToasts WRITE setShowToasts NOTIFY policyChanged)
144 public:
145 explicit ViewPolicy(QObject *parent = 0);
146
147 bool unifiedInboxExpanded();
148 void setUnifiedInboxExpanded(const bool expanded);
149
150 bool favouritesExpanded();
151 void setFavouritesExpanded(const bool expanded);
152
153 bool favouritesVisible();
154 void setFavouritesVisible(const bool visible);
155
156 bool smartFoldersExpanded();
157 void setSmartFoldersExpanded(const bool expanded);
158
159 bool smartFoldersVisible();
160 void setSmartFoldersVisible(const bool visible);
161
162 bool accountsExpanded();
163 void setAccountsExpanded(const bool expanded);
164
165 bool accountsVisible();
166 void setAccountsVisible(const bool visible);
167
168 bool gravatarEnabled();
169 void setGravatarEnabled(const bool enabled);
170
171 bool hideMarkedDeleted();
172 void setHideMarkedDeleted(const bool hide);
173
174 bool preferPlainText();
175 void setPreferPlainText(const bool prefer);
176
177 int previewLines();
178 void setPreviewLines(const int &lines);
179
180 bool threadViewEnabled();
181 void setThreadViewEnabled(const bool enabled);
182
183 bool showToasts();
184 void setShowToasts(const bool show);
185 signals:
186 void policyChanged();
187 // PolicyInterface interface
188 public:
189 virtual void setDefaults() override;
190
191 // SettingsObjectBase interface
192 protected:
193 virtual void createDefaultsIfNotExist() override {
194 setDefaults();
195 }
196 };
197
198 /**
199 * @brief The AccountPolicy class
200 */
201 class AccountPolicy : public QObject, public PolicyInterface
202 {
203 Q_OBJECT
204 Q_INTERFACES(PolicyInterface)
205 /**
206 * @brief The account id this policy belongs to
207 * @accessors %accountId(), setAccountId()
208 */
209 Q_PROPERTY(int accountId READ accountId WRITE setAccountId NOTIFY accountIdChanged)
210
211 public:
212 explicit AccountPolicy(QObject *parent = 0) : QObject(parent) {}
213 AccountPolicy(QObject *parent, const QMailAccountId &id): QObject(parent), m_accountId(id) {}
214 AccountPolicy(QObject *parent, const int &id): QObject(parent), m_accountId(QMailAccountId(id)) {}
215
216 int accountId() const;
217 void setAccountId(const int &id);
218 void setAccountId(const QMailAccountId &id);
219 // policy interfact
220 Q_INVOKABLE virtual void setPolicy(const QString &policy, const QString &value) override;
221 Q_INVOKABLE virtual QString readPolicy(const QString &policy) override;
222 virtual void setDefaults() {}
223
224 signals:
225 void accountIdChanged();
226 void accountUpdated();
227
228 protected:
229 bool idValid() { return QMailAccountId(m_accountId).isValid(); }
230
231 private:
232 QMailAccountId m_accountId;
233 };
234
235 /**
236 * @brief The MailPolicy class
237 */
238 class MailPolicy : public AccountPolicy
239 {
240 Q_OBJECT
241 /**
242 * @brief How long to wait before marking a message read
243 * @accessors markInterval(), setMarkInterval()
244 */
245 Q_PROPERTY(int markAsReadInterval READ markInterval WRITE setMarkInterval NOTIFY policyChanged)
246 /**
247 * @brief The MarkAsRead policy applied to just opened messages
248 * @accessors %markRead(), setMarkRead()
249 */
250 Q_PROPERTY(MarkReadMode markRead READ markRead WRITE setMarkRead NOTIFY policyChanged)
251 Q_PROPERTY(QString ccIncludes READ ccIncludes WRITE setCCIncludes NOTIFY policyChanged)
252 Q_PROPERTY(QString bccIncludes READ bccIncludes WRITE setBCCIncludes NOTIFY policyChanged)
253 Q_ENUMS(MarkReadMode)
254
255 public:
256 explicit MailPolicy(QObject *parent = 0);
257 MailPolicy(QObject *parent, const int &id);
258 MailPolicy(QObject *parent, const QMailAccountId &id);
259
260 /**
261 * @brief The MarkReadMode enum
262 *
263 * The mode applied to a recently opened message. This is evaluated
264 * after the main body part has been displayed on the screen as there maybe
265 * a delay between the message being fetched and it actually being displayed
266 */
267 enum MarkReadMode {
268 Never, /**< @short Never automatically mark the message read */
269 AfterInterval,/**< @short Mark message read after set interval \see markAsReadInterval() */
270 Immediately /**< @short Mark message read immediately */
271 };
272
273 /** @short How long to wait before marking a message as read. */
274 int markInterval();
275 /** @short Set interval for how long to wait before marking a message as read. */
276 void setMarkInterval(const int &interval);
277 /** @short The MarkAsRead policy applied to just opened messages. */
278 MarkReadMode markRead();
279 /** @short Set the MarkAsRead policy applied to just opened messages */
280 void setMarkRead(const MarkReadMode mode);
281
282 QString ccIncludes();
283 void setCCIncludes(const QString &includes);
284 QString bccIncludes();
285 void setBCCIncludes(const QString &includes);
286
287 virtual void setDefaults() override;
288
289 signals:
290 void policyChanged();
291
292 };
293
294 #endif // SETTINGSPOLICIES_H