Debian Codegraph @

Dekko/backend/mail/MessageSet.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 MESSAGESET_H
19 #define MESSAGESET_H
20
21 #include <QObject>
22 #include <QDBusPendingCallWatcher>
23 #include <QFlags>
24 #include <QmlObjectListModel.h>
25 #include <qmailmessagekey.h>
26 #include <qmailfolder.h>
27 #include <QTimer>
28
29 class MessageSet : public QObject
30 {
31 Q_OBJECT
32 Q_PROPERTY(QString hasDescendents READ hasDecendents NOTIFY descendentsCountChanged)
33 Q_PROPERTY(QString displayName READ displayName WRITE setDisplayName NOTIFY displayNameChanged)
34 Q_PROPERTY(QObject *descendents READ children CONSTANT)
35 Q_PROPERTY(QVariant messageKey READ messageKey NOTIFY messageKeyChanged)
36 Q_PROPERTY(QVariant descendentsKey READ descendentsKey NOTIFY descendentsCountChanged)
37 Q_PROPERTY(int unreadCount READ unreadCount NOTIFY unreadCountChanged)
38 Q_PROPERTY(int totalCount READ totalCount NOTIFY totalCountChanged)
39 Q_PROPERTY(SupportedActions supportedActions READ supportedActions CONSTANT)
40
41 public:
42 explicit MessageSet(QObject *parent = 0);
43
44 enum SupportedAction {
45 NoActions = 0,
46 SyncAction = 1 << 0,
47 MarkAsRead = 1 << 1,
48 ExportPending = 1 << 2,
49 Expunge = 1 << 3,
50 RenameAllowed = 1 << 4,
51 SearchFolder = 1 << 5,
52 ShowProperties = 1 << 6,
53 MarkAsDone = 1 << 7, // for the Todo Items
54 EmptyTrash = 1 << 8
55 };
56
57 Q_DECLARE_FLAGS(SupportedActions, SupportedAction)
58 Q_FLAGS(SupportedActions)
59 Q_ENUMS(SupportedAction)
60
61 virtual void init(const QString &displayName, const QMailMessageKey &messageKey) = 0;
62 QObject *children() { return m_children; }
63 QVariant messageKey() const { return m_key; }
64 virtual QVariant descendentsKey() = 0;
65 QString displayName() const { return m_name; }
66 bool hasDecendents() const { return !m_children->isEmpty(); }
67 int unreadCount();
68 int totalCount();
69 SupportedActions supportedActions() const { return m_actions; }
70 void setSupportedActions(const SupportedActions &actions) { m_actions = actions; }
71
72 signals:
73 void messageKeyChanged();
74 void descendentsCountChanged();
75 void displayNameChanged();
76 void countChanged();
77 void unreadCountChanged();
78 void totalCountChanged();
79
80 public slots:
81 void setMessageKey(const QMailMessageKey &key);
82 void setDisplayName(const QString &displayName);
83 void updateCounts();
84
85 private slots:
86 void updateUnreadCount(QDBusPendingCallWatcher *call);
87 void updateTotalCount(QDBusPendingCallWatcher *call);
88
89 protected:
90 QString m_name;
91 QQmlObjectListModel<MessageSet> *m_children;
92 QMailMessageKey m_key;
93 SupportedActions m_actions;
94 int m_unreadCount;
95 int m_totalCount;
96 };
97
98 Q_DECLARE_OPERATORS_FOR_FLAGS(MessageSet::SupportedActions)
99
100
101 class StandardFolderSet : public MessageSet
102 {
103 Q_OBJECT
104 Q_PROPERTY(FolderType folderType READ type WRITE setType NOTIFY standardFolderChanged)
105 Q_ENUMS(FolderType)
106 public:
107 explicit StandardFolderSet(QObject *parent = 0);
108 // Kind of annoying we have to duplicate this here for QML :-(
109 // But i much prefer declaring the type in the qproperty rather than just an int.
110 enum FolderType {
111 StandardFolder,
112 SpecialUseInboxFolder,
113 SpecialUseOutboxFolder,
114 SpecialUseDraftsFolder,
115 SpecialUseSentFolder,
116 SpecialUseTrashFolder,
117 SpecialUseJunkFolder
118 };
119 virtual void init(const QString &displayName, const QMailMessageKey &messageKey);
120 void initNoDecendents(const QString &displayName, const QMailMessageKey &messageKey);
121 virtual QVariant descendentsKey() override;
122 FolderType type() const { return m_type; }
123
124 signals:
125 void standardFolderChanged();
126
127 public slots:
128 void setType(FolderType type);
129
130 private slots:
131 // initiate tracking of account changes. THis is particluarly
132 // useful for the SpecialUseInboxFolder set where we have decendent
133 // Inbox account folders. We want to make sure we add/remove/update on all changes
134 void trackAccountChanges();
135 void accountsAdded(const QMailAccountIdList &idList);
136 void accountsRemove(const QMailAccountIdList &idList);
137 void accountsChanged(const QMailAccountIdList &idList);
138
139 private:
140 FolderType m_type;
141 QMailAccountIdList m_inboxList;
142 void appendInboxDescendents();
143 QMailMessageKey createAccountDescendentKey(const QMailAccountId &id, const QMailFolder::StandardFolder &folderType);
144 QMailAccountIdList queryEnabledAccounts();
145 };
146
147 class SmartFolderSet : public MessageSet
148 {
149 Q_OBJECT
150 Q_PROPERTY(SmartFolderType type READ type WRITE setType NOTIFY typeChanged)
151 Q_PROPERTY(int smartCount READ smartCount NOTIFY smartCountChanged)
152
153 Q_ENUMS(SmartFolderType)
154
155 public:
156 explicit SmartFolderSet(QObject *parent =0);
157
158 enum SmartFolderType {
159 SmartTodoFolder,
160 SmartDoneFolder,
161 SmartTodayFolder,
162 SmartCustomFolder
163 };
164
165 virtual void init(const QString &displayName, const QMailMessageKey &messageKey);
166 virtual QVariant descendentsKey() { return QVariant(); } // We don't do descendents yet
167 SmartFolderType type() const;
168 int smartCount();
169 public slots:
170 void setType(SmartFolderType type);
171 signals:
172 void typeChanged(SmartFolderType type);
173 void smartCountChanged();
174
175 private slots:
176 void updateDescription();
177
178 private:
179 SmartFolderType m_type;
180 QTimer *m_timer; // Used to update SmartTodayFolder description
181 };
182
183 #endif // MESSAGESET_H