Debian Codegraph @

Dekko/backend/mail/service/MailServiceClient.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 CLIENT_H
19 #define CLIENT_H
20
21 #include <QObject>
22 #include <QQmlEngine>
23 #include <QJSEngine>
24 #include <QDBusConnection>
25 #include "ClientService.h"
26 #include <qmailstore.h>
27 #include "Folder.h"
28 #include "MailServiceInterface.h"
29
30
31 class Client : public QObject
32 {
33 Q_OBJECT
34 Q_PROPERTY(QObject *service READ service NOTIFY serviceChanged)
35 Q_PROPERTY(bool hasConfiguredAccounts READ hasConfiguredAccounts CONSTANT)
36 Q_PROPERTY(bool hasUndoableActions READ hasUndoableActions NOTIFY undoCountChanged)
37 Q_PROPERTY(QString undoableActionDescription READ undoDescription NOTIFY undoCountChanged)
38 Q_ENUMS(Error)
39
40 public:
41 static Client *instance();
42 static QObject *factory(QQmlEngine *engine, QJSEngine *scriptEngine);
43 explicit Client(QObject *parent = 0);
44
45 enum Error {
46 NoError,
47 FrameworkFault,
48 SystemError,
49 InternalServerError,
50 UnexpectedResponse,
51 LoginFailed,
52 CancelError,
53 FileSystemFull,
54 MessageNotExist,
55 EnqueueFailed,
56 NoConnection,
57 ConnectionInUse,
58 ConnectionNotReady,
59 ConfigurationError,
60 InvalidAddress,
61 InvalidData,
62 TimeoutError,
63 InternalStateReset,
64 SslNotSupported,
65 UntrustedCertificate,
66 UnknownError
67 };
68
69 bool hasUndoableActions() const;
70 QString undoDescription() const;
71
72 QObject *service() const { return m_service; }
73 bool hasConfiguredAccounts(); // account service
74
75 Q_INVOKABLE void deleteMessage(const int &msgId); // done
76 Q_INVOKABLE void restoreMessage(const int &msgId); // done
77 void deleteMessages(const QMailMessageIdList &idList); // done
78
79 Q_INVOKABLE void synchronizeAccount(const int &id); // account service
80 void synchronizeAccount(const QMailAccountId &id); // account service
81
82 Q_INVOKABLE void syncStandardFolder(const int &standardFolder); //Folder::FolderType
83 Q_INVOKABLE void syncStandardFolder(const quint64 &accountId, const int &standardFolder);
84 Q_INVOKABLE void syncFolder(const quint64 &accountId, const quint64 &folderId);
85 void syncFolders(const QMailAccountId &accountId, const QMailFolderIdList &folders);
86
87 Q_INVOKABLE void markMessageImportant(const int &msgId, const bool important);
88 void markMessagesImportant(const QMailMessageIdList &idList, const bool important);
89
90 Q_INVOKABLE void markMessageRead(const int &msgId, const bool read);
91 void markMessagesRead(const QMailMessageIdList &idList, const bool read);
92
93 Q_INVOKABLE void markMessageTodo(const int &msgId, const bool todo);
94 void markMessagesTodo(const QMailMessageIdList &idList, const bool todo);
95
96 Q_INVOKABLE void markMessageDone(const int &msgId, const bool done);
97 void markMessagesDone(const QMailMessageIdList &idList, const bool done);
98
99 Q_INVOKABLE void createStandardFolders(const quint64 &accountId);
100 void createStandardFolders(const QMailAccountId &accountId);
101 Q_INVOKABLE void moveToStandardFolder(const int &msgId, const int &standardFolder); // standardFolder is a Folder::FolderType
102 void moveToStandardFolder(const QMailMessageIdList &msgIds, const Folder::FolderType &folder, const bool userTriggered = true);
103 Q_INVOKABLE void moveToFolder(const quint64 &msgId, const quint64 &folderId);
104 void moveToFolder(const QMailMessageIdList &ids, const QMailFolderId &folderId);
105 Q_INVOKABLE bool detectStandardFolders(const quint64 &id);
106
107 Q_INVOKABLE void emptyTrash();
108 Q_INVOKABLE void emptyTrash(const int &accountId);
109 void emptyTrash(const QMailAccountIdList &ids);
110
111 Q_INVOKABLE void markStandardFolderRead(const int &standardFolder); // Folder::FolderType
112 Q_INVOKABLE void markStandardFolderRead(const quint64 &accountId, const int &standardFolder);
113 void markFolderRead(const QMailFolderId &id);
114
115 void markMessagesReplied(const QMailMessageIdList &idList, const bool all);
116 void markMessageForwarded(const QMailMessageIdList &idList);
117
118 void downloadMessagePart(const QMailMessagePart *msgPart);
119 void downloadMessage(const QMailMessageId &msgId);
120 void downloadMessages(const QMailMessageIdList &idList);
121
122 bool addMessage(QMailMessage *msg);
123 bool removeMessage(const QMailMessageId &id, const QMailStore::MessageRemovalOption &option);
124 // void addMessages(const QMailMessageList &msgList);
125 // void updateMessages(const QMailMessageList &msgList);
126
127 // C++ Submission api
128 void sendMessage(const QMailMessage &msg);
129 Q_INVOKABLE void sendPendingMessages();
130
131 Q_INVOKABLE void undoActions();
132
133 MailServiceInterface *bus() { return m_mService; }
134
135 void pruneCache(const QMailMessageIdList &msgIds);
136
137 signals:
138 void undoCountChanged();
139 void serviceChanged();
140 void messagePartNowAvailable(const quint64 &msgId, const QString &partLocation);
141 void messagePartFetchFailed(const quint64 &msgId, const QString &partLocation);
142 void messagesNowAvailable(const QMailMessageIdList &idList);
143 void messageFetchFailed(const QMailMessageIdList &ids);
144 void messagesSent(const QMailMessageIdList &ids);
145 void messageSendingFailed(const QMailMessageIdList &ids, QMailServiceAction::Status::ErrorCode error);
146 void accountSynced(const quint64 &id);
147 void syncAccountFailed(const quint64 &id);
148 void clientError(const quint64 &accountId, const Error &error, const QString &errorString);
149 void standardFoldersCreated(const quint64 &accountId, const bool &created);
150 void foldersSynced(const bool folderSyncErrorOccurred);
151
152 public slots:
153 void handleFailure(const quint64 &id, const int &statusCode, const QString &statusText);
154
155 private slots:
156 void handleMessagesNowAvailable(const QList<quint64> &msgIds);
157 void handleMessageFetchFailed(const QList<quint64> &msgIds);
158 void handleMessagesSent(const QList<quint64> &msgIds);
159 void handleMessageSendingFailed(const QList<quint64> &msgIds, const int &error);
160 void handleFoldersSynced(const quint64 &accountId, const QList<quint64> &folderIds);
161 void handleFoldersSyncFailed(const quint64 &accountId, const QList<quint64> &folderIds);
162
163 protected:
164 QMailAccountIdList getEnabledAccountIds() const;
165
166 private:
167
168 ClientService *m_service;
169 MailServiceInterface *m_mService;
170 uint m_folderSyncsInProgress;
171 bool m_folderSyncErrorOccurred;
172
173 };
174
175 #endif // CLIENT_H