Debian Codegraph @

Dekko/backend/settings/SettingsPolicies.cpp

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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 #include "SettingsPolicies.h"
20
21 int AccountPolicy::accountId() const { return m_accountId.toULongLong(); }
22
23 void AccountPolicy::setAccountId(const int &id) {
24 setAccountId(QMailAccountId(id));
25 }
26
27 void AccountPolicy::setAccountId(const QMailAccountId &id) {
28 m_accountId = id;
29 emit accountIdChanged();
30 }
31
32 void AccountPolicy::setPolicy(const QString &policy, const QString &value) {
33 QMailAccount account(m_accountId);
34 account.setCustomField(QString("policy.%1").arg(policy), value);
35 QMailStore::instance()->updateAccount(&account);
36 }
37
38 QString AccountPolicy::readPolicy(const QString &policy) {
39 return QMailAccount(m_accountId).customField(QString("policy.%1").arg(policy));
40 }
41
42 MailPolicy::MailPolicy(QObject *parent) : AccountPolicy(parent) {
43 connect(this, &MailPolicy::accountIdChanged, this, &MailPolicy::policyChanged);
44 }
45
46 MailPolicy::MailPolicy(QObject *parent, const int &id) : AccountPolicy(parent, id) {
47 connect(this, &MailPolicy::accountIdChanged, this, &MailPolicy::policyChanged);
48 }
49
50 MailPolicy::MailPolicy(QObject *parent, const QMailAccountId &id) : AccountPolicy(parent, id) {
51 connect(this, &MailPolicy::accountIdChanged, this, &MailPolicy::policyChanged);
52 }
53
54 int MailPolicy::markInterval()
55 {
56 if (idValid()) {
57 return readPolicy(QStringLiteral("mail.markReadInterval")).toInt();
58 }
59 return 1000;
60 }
61
62 void MailPolicy::setMarkInterval(const int &interval)
63 {
64 if (!idValid()) {
65 qDebug() << "Invalid ID cannot set interval policy";
66 }
67 setPolicy(QStringLiteral("mail.markReadInterval"), QString::number(interval));
68 emit policyChanged();
69 }
70
71 MailPolicy::MarkReadMode MailPolicy::markRead()
72 {
73 QString policy = readPolicy(QStringLiteral("mail.markAsRead"));
74 if (!policy.isEmpty()) {
75 if (policy == QStringLiteral("never")) {
76 return MarkReadMode::Never;
77 } else if ( policy == QStringLiteral("interval")) {
78 return MarkReadMode::AfterInterval;
79 } else if (policy == QStringLiteral("immediate")) {
80 return MarkReadMode::Immediately;
81 }
82 }
83 return MarkReadMode::AfterInterval;
84 }
85
86 void MailPolicy::setMarkRead(const MailPolicy::MarkReadMode mode)
87 {
88 switch(mode) {
89 case MarkReadMode::Never:
90 setPolicy(QStringLiteral("mail.markAsRead"), QStringLiteral("never"));
91 break;
92 case MarkReadMode::AfterInterval:
93 setPolicy(QStringLiteral("mail.markAsRead"), QStringLiteral("interval"));
94 break;
95 case MarkReadMode::Immediately:
96 setPolicy(QStringLiteral("mail.markAsRead"), QStringLiteral("immediate"));
97 break;
98 default:
99 setPolicy(QStringLiteral("mail.markAsRead"), QStringLiteral("interval"));
100 break;
101 }
102 emit policyChanged();
103 }
104
105 QString MailPolicy::ccIncludes()
106 {
107 return readPolicy(QStringLiteral("submission.ccIncludes"));
108 }
109
110 void MailPolicy::setCCIncludes(const QString &includes)
111 {
112 setPolicy(QStringLiteral("submission.ccIncludes"), includes);
113 emit policyChanged();
114 }
115
116 QString MailPolicy::bccIncludes()
117 {
118 return readPolicy(QStringLiteral("submission.bccIncludes"));
119 }
120
121 void MailPolicy::setBCCIncludes(const QString &includes)
122 {
123 setPolicy(QStringLiteral("submission.bccIncludes"), includes);
124 emit policyChanged();
125 }
126
127 void MailPolicy::setDefaults()
128 {
129 setMarkRead(MarkReadMode::AfterInterval);
130 setMarkInterval(1000);
131 setCCIncludes(QString(""));
132 setBCCIncludes(QString(""));
133 }
134
135
136 PrivacyPolicy::PrivacyPolicy(QObject *parent) : GlobalPolicy(parent) {
137 setSettingsKey(QStringLiteral("privacy"));
138 connect(this, &PrivacyPolicy::dataChanged, this, &PrivacyPolicy::policyChanged);
139 }
140
141 bool PrivacyPolicy::allowRemoteContent() {
142 return readPolicy(QStringLiteral("remote.contentAllowed")).toInt() != 0;
143 }
144
145 void PrivacyPolicy::setAllowRemoteContent(const bool allowed) {
146 setPolicy(QStringLiteral("remote.contentAllowed"), QString::number(allowed ? 1 : 0));
147 }
148
149 void PrivacyPolicy::setDefaults() {
150 if (read("defaults_created").toBool()) {
151 return;
152 }
153 setAllowRemoteContent(false);
154 write("defaults_created", true);
155 }
156
157 void PrivacyPolicy::createDefaultsIfNotExist() {
158 setDefaults();
159 }
160
161 ViewPolicy::ViewPolicy(QObject *parent) : GlobalPolicy(parent) {
162 connect(this, &ViewPolicy::dataChanged, this, &ViewPolicy::policyChanged);
163 setSettingsKey(QStringLiteral("views"));
164 }
165
166 bool ViewPolicy::unifiedInboxExpanded()
167 {
168 return readPolicy(QStringLiteral("navigation.unified.expanded")).toInt() != 0;
169 }
170
171 void ViewPolicy::setUnifiedInboxExpanded(const bool expanded)
172 {
173 setPolicy(QStringLiteral("navigation.unified.expanded"), QString::number(expanded ? 1 : 0));
174 }
175
176 bool ViewPolicy::favouritesExpanded()
177 {
178 return readPolicy(QStringLiteral("navigation.favourites.expanded")).toInt() != 0;
179 }
180
181 void ViewPolicy::setFavouritesExpanded(const bool expanded)
182 {
183 setPolicy(QStringLiteral("navigation.favourites.expanded"), QString::number(expanded ? 1 : 0));
184 }
185
186 bool ViewPolicy::favouritesVisible()
187 {
188 return readPolicy(QStringLiteral("navigation.favourites.visible")).toInt() != 0;
189 }
190
191 void ViewPolicy::setFavouritesVisible(const bool visible)
192 {
193 setPolicy(QStringLiteral("navigation.favourites.visible"), QString::number(visible ? 1 : 0));
194 }
195
196 bool ViewPolicy::smartFoldersExpanded()
197 {
198 return readPolicy(QStringLiteral("navigation.smartfolders.expanded")).toInt() != 0;
199 }
200
201 void ViewPolicy::setSmartFoldersExpanded(const bool expanded)
202 {
203 setPolicy(QStringLiteral("navigation.smartfolders.expanded"), QString::number(expanded ? 1 : 0));
204 }
205
206 bool ViewPolicy::smartFoldersVisible()
207 {
208 return readPolicy(QStringLiteral("navigation.smartfolders.visible")).toInt() != 0;
209 }
210
211 void ViewPolicy::setSmartFoldersVisible(const bool visible)
212 {
213 setPolicy(QStringLiteral("navigation.smartfolders.visible"), QString::number(visible ? 1 : 0));
214 }
215
216 bool ViewPolicy::accountsExpanded()
217 {
218 return readPolicy(QStringLiteral("navigation.accounts.expanded")).toInt() != 0;
219 }
220
221 void ViewPolicy::setAccountsExpanded(const bool expanded)
222 {
223 setPolicy(QStringLiteral("navigation.accounts.expanded"), QString::number(expanded ? 1 : 0));
224 }
225
226 bool ViewPolicy::accountsVisible()
227 {
228 return readPolicy(QStringLiteral("navigation.accounts.visible")).toInt() != 0;
229 }
230
231 void ViewPolicy::setAccountsVisible(const bool visible)
232 {
233 setPolicy(QStringLiteral("navigation.accounts.visible"), QString::number(visible ? 1 : 0));
234 }
235
236 bool ViewPolicy::gravatarEnabled()
237 {
238 return readPolicy(QStringLiteral("avatars.gravatarEnabled")).toInt() != 0;
239 }
240
241 void ViewPolicy::setGravatarEnabled(const bool enabled)
242 {
243 setPolicy(QStringLiteral("avatars.gravatarEnabled"), QString::number(enabled ? 1 : 0));
244 }
245
246 bool ViewPolicy::hideMarkedDeleted()
247 {
248 return readPolicy(QStringLiteral("view.hideMarkedDeleted")).toInt() != 0;
249 }
250
251 void ViewPolicy::setHideMarkedDeleted(const bool hide)
252 {
253 setPolicy(QStringLiteral("view.hideMarkedDeleted"), QString::number(hide ? 1 : 0));
254 }
255
256 bool ViewPolicy::preferPlainText()
257 {
258 return readPolicy(QStringLiteral("view.preferPlainText")).toInt() != 0;
259 }
260
261 void ViewPolicy::setPreferPlainText(const bool prefer)
262 {
263 setPolicy(QStringLiteral("view.preferPlainText"), QString::number(prefer ? 1 : 0));
264 }
265
266 int ViewPolicy::previewLines()
267 {
268 return readPolicy(QStringLiteral("view.previewLines")).toInt();
269 }
270
271 void ViewPolicy::setPreviewLines(const int &lines)
272 {
273 static int maxCount = 3;
274 static int minCount = 1;
275
276 int num = minCount;
277 if (lines > maxCount) {
278 num = maxCount;
279 } else if (lines >= minCount) {
280 num = lines;
281 }
282 setPolicy(QStringLiteral("view.previewLines"), QString::number(num));
283 }
284
285 bool ViewPolicy::threadViewEnabled()
286 {
287 return readPolicy(QStringLiteral("view.threadViewEnabled")).toInt() != 0;
288 }
289
290 void ViewPolicy::setThreadViewEnabled(const bool enabled)
291 {
292 setPolicy(QStringLiteral("view.threadViewEnabled"), QString::number(enabled ? 1 : 0));
293 }
294
295 bool ViewPolicy::showToasts()
296 {
297 return readPolicy(QStringLiteral("view.showToasts")).toInt() != 0;
298 }
299
300 void ViewPolicy::setShowToasts(const bool show)
301 {
302 setPolicy(QStringLiteral("view.showToasts"), QString::number(show ? 1 : 0));
303 }
304
305 void ViewPolicy::setDefaults() {
306 if (read("defaults_created").toBool()) {
307 return;
308 }
309 setUnifiedInboxExpanded(false);
310 setFavouritesExpanded(false);
311 setFavouritesVisible(false);
312 setSmartFoldersExpanded(true);
313 setSmartFoldersVisible(true);
314 setAccountsExpanded(true);
315 setAccountsVisible(true);
316 setGravatarEnabled(true);
317 setHideMarkedDeleted(true);
318 setPreferPlainText(false);
319 setThreadViewEnabled(false);
320 setShowToasts(true);
321 setPreviewLines(2);
322 write("defaults_created", true);
323 }