Debian Codegraph @

Dekko/backend/mail/Attachments.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 ATTACHMENTS_H
19 #define ATTACHMENTS_H
20
21 #include <QObject>
22 #include <QUrl>
23 #include <QMap>
24 #include <QmlObjectListModel.h>
25 #include <qmailmessage.h>
26 #include <QNetworkAccessManager>
27 #include <QNetworkReply>
28
29 class Attachment;
30
31 class Attachments : public QObject
32 {
33 Q_OBJECT
34 Q_PROPERTY(QObject *model READ model NOTIFY modelChanged)
35 public:
36 explicit Attachments(QObject *parent = 0);
37 QObject *model() { return m_model; }
38
39 void setMessageId(const QMailMessageId &id);
40 signals:
41 void modelChanged();
42 private:
43 void initModel();
44 QMailMessageId m_id;
45 QQmlObjectListModel<Attachment> *m_model;
46 };
47
48 class Attachment : public QObject
49 {
50 Q_OBJECT
51 Q_PROPERTY(QString displayName READ displayName NOTIFY attachmentChanged)
52 Q_PROPERTY(QString mimeType READ mimeType NOTIFY attachmentChanged)
53 Q_PROPERTY(QString url READ url NOTIFY urlChanged)
54 Q_PROPERTY(QString size READ size NOTIFY attachmentChanged)
55 Q_PROPERTY(int sizeInBytes READ sizeInBytes CONSTANT)
56 Q_PROPERTY(bool contentAvailable READ contentAvailable NOTIFY attachmentChanged)
57 Q_PROPERTY(QString location READ location NOTIFY attachmentChanged)
58 Q_PROPERTY(Type type READ type NOTIFY attachmentChanged)
59 Q_PROPERTY(bool fetchInProgress READ fetchInProgress NOTIFY progressChanged)
60 Q_PROPERTY(QString mimeTypeIcon READ mimeTypeIcon NOTIFY attachmentChanged)
61
62 Q_ENUMS(Type)
63 Q_ENUMS(PartType)
64 Q_ENUMS(Disposition)
65
66 public:
67 enum Type {
68 Text,
69 Image,
70 Media,
71 Multipart,
72 Other
73 };
74 enum PartType {
75 Message,
76 MessagePart,
77 File
78 };
79 enum Disposition {
80 Inline,
81 Attached
82 };
83
84 explicit Attachment(QObject *parent = 0);
85 Attachment(QObject *parent, const QString &attachment, const PartType &partType, const Disposition &disposition);
86
87 QString displayName();
88 QString mimeType() const;
89 QString size();
90 int sizeInBytes() const;
91 Type type() const;
92 bool contentAvailable() const;
93 QString location() const;
94 QString url() const;
95 bool fetchInProgress() const;
96 QString mimeTypeIcon() const;
97 PartType partType() const { return m_partType; }
98 Disposition contentDisposition() const { return m_disposition; }
99
100 void init(const QMailMessageId &id, const QMailMessagePartContainer::Location &location);
101
102 void addToMessage(QMailMessage &msg);
103
104 signals:
105 void attachmentChanged();
106 void readyToOpen(QString url);
107 void progressChanged();
108 void urlChanged();
109
110 public slots:
111 // This is a quick hack passing in a qml object to avoid a circular dependency.
112 // ideally we should split the Client* classes into another lib
113 // and avoid a circular dependency properly in the long term.
114 void open(QObject *qmlObject);
115
116 private slots:
117 void fetch();
118 void handlePartFetched();
119
120 private:
121 QString writePartToFile();
122 QUrl partFetchUrl();
123 QUrl saveToAccessibleFile();
124 QString sizeToReadableString(const int &size);
125 bool isRfc822();
126
127 QMailMessageId m_id;
128 QMailMessagePartContainer::Location m_location;
129 Type m_type;
130 QMailMessagePart m_part;
131 QString m_url;
132 bool m_fetching;
133 QNetworkAccessManager *m_qnam;
134 QNetworkReply *m_reply;
135 PartType m_partType;
136 Disposition m_disposition;
137 QString m_filePath;
138 bool m_hasRefs;
139 };
140
141 #endif // ATTACHMENTS_H