diff options
-rw-r--r-- | components/package/contents/ui/MailViewer.qml | 41 | ||||
-rw-r--r-- | framework/domain/CMakeLists.txt | 1 | ||||
-rw-r--r-- | framework/domain/attachmentmodel.cpp | 141 | ||||
-rw-r--r-- | framework/domain/messageparser.cpp | 7 | ||||
-rw-r--r-- | framework/domain/messageparser.h | 28 | ||||
-rw-r--r-- | framework/domain/messageparser_new.cpp | 3 |
6 files changed, 217 insertions, 4 deletions
diff --git a/components/package/contents/ui/MailViewer.qml b/components/package/contents/ui/MailViewer.qml index 2c45a49f..01163277 100644 --- a/components/package/contents/ui/MailViewer.qml +++ b/components/package/contents/ui/MailViewer.qml | |||
@@ -28,7 +28,7 @@ Item { | |||
28 | id: root | 28 | id: root |
29 | property variant message; | 29 | property variant message; |
30 | property string html; | 30 | property string html; |
31 | property int desiredHeight: topPartLoader.height + newMailViewer.height + 5 | 31 | property int desiredHeight: topPartLoader.height + newMailViewer.height + attachments.height + mailStructure.height + 5 |
32 | 32 | ||
33 | clip: true | 33 | clip: true |
34 | 34 | ||
@@ -55,9 +55,46 @@ Item { | |||
55 | width: topPartLoader.contentWidth >= parent.width ? topPartLoader.contentWidth : parent.width | 55 | width: topPartLoader.contentWidth >= parent.width ? topPartLoader.contentWidth : parent.width |
56 | } | 56 | } |
57 | 57 | ||
58 | //END old mail viewer | ||
59 | |||
60 | TreeView { | ||
61 | id: attachments | ||
62 | anchors.top: newMailViewer.bottom | ||
63 | visible: messageParser.attachments.rowCount() > 0 | ||
64 | width: parent.width | ||
65 | height: 200 | ||
66 | TableViewColumn { | ||
67 | role: "name" | ||
68 | title: "Filename" | ||
69 | width: 300 | ||
70 | } | ||
71 | TableViewColumn { | ||
72 | role: "type" | ||
73 | title: "Type" | ||
74 | width: 60 | ||
75 | } | ||
76 | TableViewColumn { | ||
77 | role: "size" | ||
78 | title: "Size" | ||
79 | width: 60 | ||
80 | } | ||
81 | TableViewColumn { | ||
82 | role: "encrypted" | ||
83 | title: "Encrypted" | ||
84 | width: 60 | ||
85 | } | ||
86 | TableViewColumn { | ||
87 | role: "signed" | ||
88 | title: "Signed" | ||
89 | width: 60 | ||
90 | } | ||
91 | model: messageParser.attachments | ||
92 | } | ||
93 | |||
58 | TreeView { | 94 | TreeView { |
59 | id: mailStructure | 95 | id: mailStructure |
60 | visible: false | 96 | visible: false |
97 | anchors.top: messageParser.attachments.rowCount() > 0 ? attachments.bottom : newMailViewer.bottom | ||
61 | width: parent.width | 98 | width: parent.width |
62 | height: 400 | 99 | height: 400 |
63 | TableViewColumn { | 100 | TableViewColumn { |
@@ -80,10 +117,8 @@ Item { | |||
80 | title: "Content" | 117 | title: "Content" |
81 | width: 200 | 118 | width: 200 |
82 | } | 119 | } |
83 | //model: messageParser.partTree | ||
84 | model: messageParser.newTree | 120 | model: messageParser.newTree |
85 | } | 121 | } |
86 | //END old mail viewer | ||
87 | 122 | ||
88 | KubeFramework.MessageParser { | 123 | KubeFramework.MessageParser { |
89 | id: messageParser | 124 | id: messageParser |
diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt index a31bb016..094eac04 100644 --- a/framework/domain/CMakeLists.txt +++ b/framework/domain/CMakeLists.txt | |||
@@ -1,4 +1,5 @@ | |||
1 | set(mailplugin_SRCS | 1 | set(mailplugin_SRCS |
2 | attachmentmodel.cpp | ||
2 | mailplugin.cpp | 3 | mailplugin.cpp |
3 | maillistmodel.cpp | 4 | maillistmodel.cpp |
4 | folderlistmodel.cpp | 5 | folderlistmodel.cpp |
diff --git a/framework/domain/attachmentmodel.cpp b/framework/domain/attachmentmodel.cpp new file mode 100644 index 00000000..35e94e2e --- /dev/null +++ b/framework/domain/attachmentmodel.cpp | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Sandro Knauß <knauss@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | #include "messageparser.h" | ||
21 | #include "mimetreeparser/interface.h" | ||
22 | |||
23 | #include <QDebug> | ||
24 | |||
25 | QString sizeHuman(const Content::Ptr &content) | ||
26 | { | ||
27 | float num = content->content().size(); | ||
28 | QStringList list; | ||
29 | list << "KB" << "MB" << "GB" << "TB"; | ||
30 | |||
31 | QStringListIterator i(list); | ||
32 | QString unit("Bytes"); | ||
33 | |||
34 | while(num >= 1024.0 && i.hasNext()) | ||
35 | { | ||
36 | unit = i.next(); | ||
37 | num /= 1024.0; | ||
38 | } | ||
39 | |||
40 | if (unit == "Bytes") { | ||
41 | return QString().setNum(num) + " " + unit; | ||
42 | } else { | ||
43 | return QString().setNum(num,'f',2)+" "+unit; | ||
44 | } | ||
45 | } | ||
46 | |||
47 | class AttachmentModelPrivate | ||
48 | { | ||
49 | public: | ||
50 | AttachmentModelPrivate(AttachmentModel *q_ptr, const std::shared_ptr<Parser> &parser); | ||
51 | |||
52 | AttachmentModel *q; | ||
53 | std::shared_ptr<Parser> mParser; | ||
54 | QVector<Part::Ptr> mAttachments; | ||
55 | }; | ||
56 | |||
57 | AttachmentModelPrivate::AttachmentModelPrivate(AttachmentModel* q_ptr, const std::shared_ptr<Parser>& parser) | ||
58 | : q(q_ptr) | ||
59 | , mParser(parser) | ||
60 | { | ||
61 | mAttachments = mParser->collectAttachmentParts(); | ||
62 | } | ||
63 | |||
64 | AttachmentModel::AttachmentModel(std::shared_ptr<Parser> parser) | ||
65 | : d(std::unique_ptr<AttachmentModelPrivate>(new AttachmentModelPrivate(this, parser))) | ||
66 | { | ||
67 | } | ||
68 | |||
69 | AttachmentModel::~AttachmentModel() | ||
70 | { | ||
71 | } | ||
72 | |||
73 | QHash<int, QByteArray> AttachmentModel::roleNames() const | ||
74 | { | ||
75 | QHash<int, QByteArray> roles; | ||
76 | roles[TypeRole] = "type"; | ||
77 | roles[NameRole] = "name"; | ||
78 | roles[SizeRole] = "size"; | ||
79 | roles[IsEncryptedRole] = "encrypted"; | ||
80 | roles[IsSignedRole] = "signed"; | ||
81 | return roles; | ||
82 | } | ||
83 | |||
84 | QModelIndex AttachmentModel::index(int row, int column, const QModelIndex &parent) const | ||
85 | { | ||
86 | if (row < 0 || column != 0) { | ||
87 | return QModelIndex(); | ||
88 | } | ||
89 | |||
90 | if (row < d->mAttachments.size()) { | ||
91 | return createIndex(row, column, d->mAttachments.at(row).get()); | ||
92 | } | ||
93 | return QModelIndex(); | ||
94 | } | ||
95 | |||
96 | QVariant AttachmentModel::data(const QModelIndex &index, int role) const | ||
97 | { | ||
98 | if (!index.isValid()) { | ||
99 | switch (role) { | ||
100 | case Qt::DisplayRole: | ||
101 | return QString("root"); | ||
102 | } | ||
103 | return QVariant(); | ||
104 | } | ||
105 | |||
106 | if (index.internalPointer()) { | ||
107 | const auto entry = static_cast<Part *>(index.internalPointer()); | ||
108 | const auto content = entry->content().at(0); | ||
109 | switch(role) { | ||
110 | case TypeRole: | ||
111 | return content->mailMime()->mimetype().name(); | ||
112 | case NameRole: | ||
113 | return entry->mailMime()->filename(); | ||
114 | case SizeRole: | ||
115 | return sizeHuman(content); | ||
116 | case IsEncryptedRole: | ||
117 | return content->encryptions().size() > 0; | ||
118 | case IsSignedRole: | ||
119 | return content->signatures().size() > 0; | ||
120 | } | ||
121 | } | ||
122 | return QVariant(); | ||
123 | } | ||
124 | |||
125 | QModelIndex AttachmentModel::parent(const QModelIndex &index) const | ||
126 | { | ||
127 | return QModelIndex(); | ||
128 | } | ||
129 | |||
130 | int AttachmentModel::rowCount(const QModelIndex &parent) const | ||
131 | { | ||
132 | if (!parent.isValid()) { | ||
133 | return d->mAttachments.size(); | ||
134 | } | ||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | int AttachmentModel::columnCount(const QModelIndex &parent) const | ||
139 | { | ||
140 | return 1; | ||
141 | } | ||
diff --git a/framework/domain/messageparser.cpp b/framework/domain/messageparser.cpp index ec79d50b..2b8d3afe 100644 --- a/framework/domain/messageparser.cpp +++ b/framework/domain/messageparser.cpp | |||
@@ -105,3 +105,10 @@ QAbstractItemModel *MessageParser::newTree() const | |||
105 | new ModelTest(model, model); | 105 | new ModelTest(model, model); |
106 | return model; | 106 | return model; |
107 | } | 107 | } |
108 | |||
109 | QAbstractItemModel *MessageParser::attachments() const | ||
110 | { | ||
111 | const auto model = new AttachmentModel(d->mParser); | ||
112 | new ModelTest(model, model); | ||
113 | return model; | ||
114 | } | ||
diff --git a/framework/domain/messageparser.h b/framework/domain/messageparser.h index 559fa6f9..203f7576 100644 --- a/framework/domain/messageparser.h +++ b/framework/domain/messageparser.h | |||
@@ -41,6 +41,7 @@ typedef std::shared_ptr<Content> ContentPtr; | |||
41 | class MessagePartPrivate; | 41 | class MessagePartPrivate; |
42 | 42 | ||
43 | class NewModelPrivate; | 43 | class NewModelPrivate; |
44 | class AttachmentModelPrivate; | ||
44 | 45 | ||
45 | class MessageParser : public QObject | 46 | class MessageParser : public QObject |
46 | { | 47 | { |
@@ -49,6 +50,7 @@ class MessageParser : public QObject | |||
49 | Q_PROPERTY (QString html READ html NOTIFY htmlChanged) | 50 | Q_PROPERTY (QString html READ html NOTIFY htmlChanged) |
50 | Q_PROPERTY (QAbstractItemModel* partTree READ partTree NOTIFY htmlChanged) | 51 | Q_PROPERTY (QAbstractItemModel* partTree READ partTree NOTIFY htmlChanged) |
51 | Q_PROPERTY (QAbstractItemModel* newTree READ newTree NOTIFY htmlChanged) | 52 | Q_PROPERTY (QAbstractItemModel* newTree READ newTree NOTIFY htmlChanged) |
53 | Q_PROPERTY (QAbstractItemModel* attachments READ attachments NOTIFY htmlChanged) | ||
52 | 54 | ||
53 | public: | 55 | public: |
54 | explicit MessageParser(QObject *parent = Q_NULLPTR); | 56 | explicit MessageParser(QObject *parent = Q_NULLPTR); |
@@ -60,6 +62,7 @@ public: | |||
60 | void setMessage(const QVariant &to); | 62 | void setMessage(const QVariant &to); |
61 | QAbstractItemModel *partTree() const; | 63 | QAbstractItemModel *partTree() const; |
62 | QAbstractItemModel *newTree() const; | 64 | QAbstractItemModel *newTree() const; |
65 | QAbstractItemModel *attachments() const; | ||
63 | 66 | ||
64 | signals: | 67 | signals: |
65 | void htmlChanged(); | 68 | void htmlChanged(); |
@@ -124,3 +127,28 @@ private: | |||
124 | std::unique_ptr<NewModelPrivate> d; | 127 | std::unique_ptr<NewModelPrivate> d; |
125 | }; | 128 | }; |
126 | 129 | ||
130 | class AttachmentModel : public QAbstractItemModel { | ||
131 | Q_OBJECT | ||
132 | public: | ||
133 | AttachmentModel(std::shared_ptr<Parser> parser); | ||
134 | ~AttachmentModel(); | ||
135 | |||
136 | public: | ||
137 | enum Roles { | ||
138 | TypeRole = Qt::UserRole + 1, | ||
139 | NameRole, | ||
140 | SizeRole, | ||
141 | IsEncryptedRole, | ||
142 | IsSignedRole | ||
143 | }; | ||
144 | |||
145 | QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE; | ||
146 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; | ||
147 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; | ||
148 | QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; | ||
149 | int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; | ||
150 | int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; | ||
151 | |||
152 | private: | ||
153 | std::unique_ptr<AttachmentModelPrivate> d; | ||
154 | }; | ||
diff --git a/framework/domain/messageparser_new.cpp b/framework/domain/messageparser_new.cpp index b930f33d..8afd5956 100644 --- a/framework/domain/messageparser_new.cpp +++ b/framework/domain/messageparser_new.cpp | |||
@@ -1,5 +1,6 @@ | |||
1 | |||
2 | /* | 1 | /* |
2 | Copyright (c) 2016 Sandro Knauß <knauss@kolabsys.com> | ||
3 | |||
3 | This library is free software; you can redistribute it and/or modify it | 4 | This library is free software; you can redistribute it and/or modify it |
4 | under the terms of the GNU Library General Public License as published by | 5 | under the terms of the GNU Library General Public License as published by |
5 | the Free Software Foundation; either version 2 of the License, or (at your | 6 | the Free Software Foundation; either version 2 of the License, or (at your |