Debian Codegraph @

Dekko/backend/accounts/Account.h

raw symbols SCIP
1 /* Copyright (C) 2016 - 2017 Dan Chapman <[email protected]>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef ACCOUNT_H
19 #define ACCOUNT_H
20
21 #include <QLoggingCategory>
22 #include <QObject>
23 #include <QPointer>
24 #include <qmailaccount.h>
25 #include <qmailaccountconfiguration.h>
26 #include "AccountConfiguration.h"
27
28 Q_DECLARE_LOGGING_CATEGORY(D_ACCOUNT)
29
30 /** @ingroup group_accounts */
31 class Account : public QObject
32 {
33 Q_OBJECT
34 // TODO: add last synchronized properties to this as well as the other account properties
35 Q_PROPERTY(int id READ id WRITE setId NOTIFY accountChanged)
36 Q_PROPERTY(int accountId READ id WRITE setId NOTIFY accountChanged)
37 Q_PROPERTY(QString name READ name WRITE setName NOTIFY accountChanged)
38 Q_PROPERTY(QStringList messageSources READ messageSources NOTIFY accountChanged)
39 Q_PROPERTY(QStringList messageSinks READ messageSinks NOTIFY accountChanged)
40 Q_PROPERTY(QObject *incoming READ incoming NOTIFY accountChanged)
41 Q_PROPERTY(QObject *outgoing READ outgoing NOTIFY accountChanged)
42 Q_PROPERTY(bool enabled READ enabled NOTIFY accountChanged)
43 Q_PROPERTY(bool isValid READ isValid CONSTANT)
44
45 Q_ENUMS(SpecialUseFolder)
46 Q_ENUMS(Error)
47
48 public:
49 explicit Account(QObject *parent = 0);
50
51 ~Account() {
52 delete m_account;
53 delete m_accountConfig;
54 m_incoming->deleteLater();
55 m_outgoing->deleteLater();
56 }
57
58 /** @short Maps to QMailFolder::StandardFolder */
59 enum SpecialUseFolder {
60 InboxFolder = 1,
61 OutboxFolder,
62 DraftsFolder,
63 SentFolder,
64 TrashFolder,
65 JunkFolder
66 };
67 /** @short Error reasons */
68 enum Error {
69 EmptyName,
70 InvalidAccountId,
71 InvalidFolderId
72 };
73
74 /** @short The account's id */
75 int id() const { return m_account->id().toULongLong(); }
76 QMailAccountId accountId() const { return m_account->id(); }
77
78 /** @short The accounts name/description
79 *
80 * Note: This isn't the same as a service configuration name (i.e username)
81 */
82 QString name() const { return m_account->name(); }
83
84 /** @short List of protocol plugins for retrieiving mail */
85 QStringList messageSources() const { return m_account->messageSources(); }
86
87 /** @short List of protocol plugins for sending mail */
88 QStringList messageSinks() const { return m_account->messageSinks(); }
89
90 /** @short Incoming message service configuration */
91 QObject *incoming() { return m_incoming; }
92
93 /** @short Outgoing message service configuration */
94 QObject *outgoing() { return m_outgoing; }
95
96 /** @short Is this account enabled and can be used */
97 bool enabled() const { return m_account->status() & QMailAccount::Enabled; }
98
99 /** @short Is this account the preferred sending account **/
100 bool isPreferredSender() const { return m_account->status() & QMailAccount::PreferredSender; }
101
102 /** @short Get QMailFolderId for SpecialUseFolder */
103 Q_INVOKABLE quint64 specialUseFolder(SpecialUseFolder folder)
104 {
105 return m_account->standardFolder((QMailFolder::StandardFolder)folder).toULongLong();
106 }
107 /** @short Map a QMailFolderId to SpecialUseFolder
108 *
109 * emits InvalidFolderId on error
110 */
111 Q_INVOKABLE void setSpecialUseFolder(SpecialUseFolder folder, const quint64 &folderId);
112 Q_INVOKABLE void setSpecialUseFolder(SpecialUseFolder folder, const QString &path);
113 Q_INVOKABLE QString specialUseFolderPath(SpecialUseFolder folder);
114
115 QMailAccount *qMailAccount() const { return m_account; }
116
117 static const QString imapServiceType, popServiceType, qmfStorage, smtpServiceType;
118 /** @short used by Accounts.h to indicate the account has been updates
119 *
120 * This is triggered as a result of QMailStore::accountUpdated
121 */
122 void emitAccountChanged() {
123 emit accountChanged(id());
124 }
125
126 bool isValid() const { return m_account->id().isValid(); }
127
128 signals:
129 void accountChanged(const int &id);
130 void error(Error error, const int &accountId);
131
132 public slots:
133 /** @short Set the account's id
134 *
135 * emits InvalidAccountId on invalid id
136 */
137 void setId(const int &id);
138 /** @short Set the account's name/description
139 *
140 * emits EmptyName on error
141 */
142 void setName(const QString &name);
143 /** @short Save account settings
144 *
145 * Updates or creates a new account if it doesn't already exist
146 */
147 bool save();
148
149 QString customValue(const QString &ns, const QString &key);
150 void setCustomValue(const QString &ns, const QString &key, const QString &value);
151 protected:
152 QMailAccount *m_account;
153 QMailAccountConfiguration *m_accountConfig;
154 AccountConfiguration *m_incoming;
155 AccountConfiguration *m_outgoing;
156
157 void initialize();
158
159 private slots:
160 void reload(const QMailAccountIdList &ids);
161
162 };
163
164 /** @ingroup group_accounts */
165 class NewAccount : public Account
166 {
167 Q_OBJECT
168 AccountConfiguration::ServiceType m_type;
169 public:
170 explicit NewAccount(QObject *parent = 0);
171
172 Q_INVOKABLE void setSourceType(const int &srcType);
173 };
174
175 #endif // ACCOUNT_H