Debian Codegraph @

Dekko/backend/mail/MessageBuilder.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 MESSAGEBUILDER_H
19 #define MESSAGEBUILDER_H
20
21 #include <QObject>
22 #include <QmlObjectListModel.h>
23 #include <QQuickTextDocument>
24 #include <QTextDocument>
25 #include <QStringList>
26 #include <qmailmessage.h>
27 #include "Attachments.h"
28 #include "MailAddress.h"
29 #include "SenderIdentities.h"
30
31
32 class MessageBuilder : public QObject
33 {
34 Q_OBJECT
35 Q_PROPERTY(QObject *to READ to NOTIFY modelsChanged)
36 Q_PROPERTY(QObject *cc READ cc NOTIFY modelsChanged)
37 Q_PROPERTY(QObject *bcc READ bcc NOTIFY modelsChanged)
38 Q_PROPERTY(QObject *attachments READ attachments NOTIFY modelsChanged)
39 Q_PROPERTY(QQuickTextDocument *subject READ subject WRITE setSubject NOTIFY subjectChanged)
40 Q_PROPERTY(QQuickTextDocument *body READ body WRITE setBody NOTIFY bodyChanged)
41 Q_PROPERTY(QObject *identities READ identities WRITE setIdentities NOTIFY identitiesChanged)
42 Q_PROPERTY(bool hasDraft READ hasDraft CONSTANT)
43 Q_ENUMS(RecipientModels)
44 public:
45 explicit MessageBuilder(QObject *parent = Q_NULLPTR);
46
47 enum RecipientModels { To, Cc, Bcc };
48 enum ReplyType { Reply, ReplyAll, ReplyList };
49 enum ForwardType { Inline, Attach };
50
51 QObject *to() const { return m_to; }
52 QObject *cc() const { return m_cc; }
53 QObject *bcc() const {return m_bcc; }
54 QObject *attachments() const { return m_attachments; }
55
56 QQuickTextDocument *subject() const;
57 QQuickTextDocument *body() const;
58 QMailMessage message();
59
60 bool hasRecipients() { return !m_to->isEmpty(); }
61 bool hasIdentities() { return !m_identities->isEmpty(); }
62 int selectedIdentity() { return m_identities->selectedIndex(); }
63 QObject *identities() const;
64 QMailMessageId lastDraftId() const {return m_lastDraftId;}
65 void setLastDraftId(const QMailMessageId &id);
66
67 bool hasDraft() { return m_lastDraftId.isValid(); }
68
69 void buildResponse(const ReplyType &type, const QMailMessage &src);
70 void buildForward(const ForwardType &type, const QMailMessage &src);
71 Q_INVOKABLE void composeMailTo(const QString &mailtoUri);
72 void reloadLastDraftId();
73
74 signals:
75 void modelsChanged();
76 void subjectChanged(QQuickTextDocument *subject);
77 void bodyChanged(QQuickTextDocument *body);
78 void identitiesChanged();
79 void maybeStartSaveTimer();
80
81 public slots:
82 void addRecipient(const RecipientModels which, const QString &emailAddress);
83 void addRecipient(const RecipientModels which, const QString &name, const QString &address);
84 void addRecipients(const RecipientModels which, const QMailAddressList &addresses);
85 void removeRecipient(const RecipientModels which, const int &index);
86 void addFileAttachment(const QString &file);
87 void addFileAttachments(const QStringList &files);
88 void appendTextToSubject(const QString &text);
89 void appendTextToBody(const QString &text);
90 // TODO: inline/attached messages and messageparts
91
92 void removeAttachment(const int &index);
93 void reset();
94 void setSubject(QQuickTextDocument *subject);
95
96 void setBody(QQuickTextDocument *body);
97 void setIdentities(QObject *identities);
98
99 protected:
100 void buildRecipientsLists(const ReplyType &type, const QMailMessage &src);
101
102 private slots:
103 void subjectChanged(int position, int charsRemoved, int charsAdded);
104 void bodyChanged(int position, int charsRemoved, int charsAdded);
105
106 private:
107 enum Mode { New, Rply, Fwd };
108 QQmlObjectListModel<MailAddress> *m_to;
109 QQmlObjectListModel<MailAddress> *m_cc;
110 QQmlObjectListModel<MailAddress> *m_bcc;
111 QQmlObjectListModel<Attachment> *m_attachments;
112 QQuickTextDocument *m_subject;
113 QTextDocument *m_internalSubject;
114 QQuickTextDocument *m_body;
115 QTextDocument *m_internalBody;
116 SenderIdentities *m_identities;
117 quint64 m_sourceStatus;
118 QMailMessageId m_lastDraftId;
119 QMailMessageId m_srcMessageId;
120 Mode m_mode;
121 ReplyType m_replyType;
122
123 QByteArray getListPostAddress(const QMailMessage &src);
124 void setSubjectText(const QString &text);
125 void setBodyText(const QString &body);
126
127 };
128
129
130
131 #endif // MESSAGEBUILDER_H