diff options
Diffstat (limited to 'framework/src/domain/mime/partmodel.cpp')
-rw-r--r-- | framework/src/domain/mime/partmodel.cpp | 74 |
1 files changed, 66 insertions, 8 deletions
diff --git a/framework/src/domain/mime/partmodel.cpp b/framework/src/domain/mime/partmodel.cpp index ea3e90e1..6ee3d46f 100644 --- a/framework/src/domain/mime/partmodel.cpp +++ b/framework/src/domain/mime/partmodel.cpp | |||
@@ -35,6 +35,8 @@ public: | |||
35 | void createTree(); | 35 | void createTree(); |
36 | PartModel *q; | 36 | PartModel *q; |
37 | QVector<MimeTreeParser::MessagePartPtr> mParts; | 37 | QVector<MimeTreeParser::MessagePartPtr> mParts; |
38 | QHash<MimeTreeParser::MessagePart*, QVector<MimeTreeParser::MessagePartPtr>> mEncapsulatedParts; | ||
39 | QHash<MimeTreeParser::MessagePart*, MimeTreeParser::MessagePart*> mParents; | ||
38 | std::shared_ptr<MimeTreeParser::ObjectTreeParser> mParser; | 40 | std::shared_ptr<MimeTreeParser::ObjectTreeParser> mParser; |
39 | }; | 41 | }; |
40 | 42 | ||
@@ -44,6 +46,14 @@ PartModelPrivate::PartModelPrivate(PartModel *q_ptr, const std::shared_ptr<MimeT | |||
44 | { | 46 | { |
45 | mParts = mParser->collectContentParts(); | 47 | mParts = mParser->collectContentParts(); |
46 | qWarning() << "Collected content parts: " << mParts.size(); | 48 | qWarning() << "Collected content parts: " << mParts.size(); |
49 | for (auto p : mParts) { | ||
50 | if (auto e = p.dynamicCast<MimeTreeParser::EncapsulatedRfc822MessagePart>()) { | ||
51 | mEncapsulatedParts[e.data()] = mParser->collectContentParts(e); | ||
52 | for (auto subPart : mEncapsulatedParts[e.data()]) { | ||
53 | mParents[subPart.data()] = e.data(); | ||
54 | } | ||
55 | } | ||
56 | } | ||
47 | } | 57 | } |
48 | 58 | ||
49 | PartModelPrivate::~PartModelPrivate() | 59 | PartModelPrivate::~PartModelPrivate() |
@@ -71,6 +81,8 @@ QHash<int, QByteArray> PartModel::roleNames() const | |||
71 | roles[EncryptionErrorType] = "errorType"; | 81 | roles[EncryptionErrorType] = "errorType"; |
72 | roles[EncryptionErrorString] = "errorString"; | 82 | roles[EncryptionErrorString] = "errorString"; |
73 | roles[IsErrorRole] = "error"; | 83 | roles[IsErrorRole] = "error"; |
84 | roles[SenderRole] = "sender"; | ||
85 | roles[DateRole] = "date"; | ||
74 | return roles; | 86 | return roles; |
75 | } | 87 | } |
76 | 88 | ||
@@ -79,6 +91,15 @@ QModelIndex PartModel::index(int row, int column, const QModelIndex &parent) con | |||
79 | if (row < 0 || column != 0) { | 91 | if (row < 0 || column != 0) { |
80 | return QModelIndex(); | 92 | return QModelIndex(); |
81 | } | 93 | } |
94 | if (parent.isValid()) { | ||
95 | if (auto e = dynamic_cast<MimeTreeParser::EncapsulatedRfc822MessagePart*>(static_cast<MimeTreeParser::MessagePart*>(parent.internalPointer()))) { | ||
96 | const auto parts = d->mEncapsulatedParts[e]; | ||
97 | if (row < parts.size()) { | ||
98 | return createIndex(row, column, parts.at(row).data()); | ||
99 | } | ||
100 | } | ||
101 | return QModelIndex(); | ||
102 | } | ||
82 | if (row < d->mParts.size()) { | 103 | if (row < d->mParts.size()) { |
83 | return createIndex(row, column, d->mParts.at(row).data()); | 104 | return createIndex(row, column, d->mParts.at(row).data()); |
84 | } | 105 | } |
@@ -88,26 +109,35 @@ QModelIndex PartModel::index(int row, int column, const QModelIndex &parent) con | |||
88 | QVariant PartModel::data(const QModelIndex &index, int role) const | 109 | QVariant PartModel::data(const QModelIndex &index, int role) const |
89 | { | 110 | { |
90 | if (!index.isValid()) { | 111 | if (!index.isValid()) { |
91 | switch (role) { | ||
92 | case Qt::DisplayRole: | ||
93 | return QString("root"); | ||
94 | case IsEmbededRole: | ||
95 | return false; | ||
96 | } | ||
97 | return QVariant(); | 112 | return QVariant(); |
98 | } | 113 | } |
99 | 114 | ||
100 | if (index.internalPointer()) { | 115 | if (index.internalPointer()) { |
101 | const auto messagePart = static_cast<MimeTreeParser::MessagePart*>(index.internalPointer()); | 116 | const auto messagePart = static_cast<MimeTreeParser::MessagePart*>(index.internalPointer()); |
102 | qWarning() << "Found message part " << messagePart->metaObject()->className() << messagePart->partMetaData()->status << messagePart->error(); | 117 | // qWarning() << "Found message part " << messagePart->metaObject()->className() << messagePart->partMetaData()->status << messagePart->error(); |
103 | Q_ASSERT(messagePart); | 118 | Q_ASSERT(messagePart); |
104 | switch(role) { | 119 | switch(role) { |
105 | case Qt::DisplayRole: | 120 | case Qt::DisplayRole: |
106 | return QStringLiteral("Content%1"); | 121 | return QStringLiteral("Content%1"); |
122 | case SenderRole: { | ||
123 | if (auto e = dynamic_cast<MimeTreeParser::EncapsulatedRfc822MessagePart*>(messagePart)) { | ||
124 | return e->from(); | ||
125 | } | ||
126 | return {}; | ||
127 | } | ||
128 | case DateRole: { | ||
129 | if (auto e = dynamic_cast<MimeTreeParser::EncapsulatedRfc822MessagePart*>(messagePart)) { | ||
130 | return e->date(); | ||
131 | } | ||
132 | return {}; | ||
133 | } | ||
107 | case TypeRole: { | 134 | case TypeRole: { |
108 | if (messagePart->error()) { | 135 | if (messagePart->error()) { |
109 | return "error"; | 136 | return "error"; |
110 | } | 137 | } |
138 | if (dynamic_cast<MimeTreeParser::EncapsulatedRfc822MessagePart*>(messagePart)) { | ||
139 | return "encapsulated"; | ||
140 | } | ||
111 | //For simple html we don't need a browser | 141 | //For simple html we don't need a browser |
112 | auto complexHtml = [&] { | 142 | auto complexHtml = [&] { |
113 | if (messagePart->isHtml()) { | 143 | if (messagePart->isHtml()) { |
@@ -165,11 +195,39 @@ QVariant PartModel::data(const QModelIndex &index, int role) const | |||
165 | 195 | ||
166 | QModelIndex PartModel::parent(const QModelIndex &index) const | 196 | QModelIndex PartModel::parent(const QModelIndex &index) const |
167 | { | 197 | { |
168 | return QModelIndex(); | 198 | if (index.isValid()) { |
199 | if (auto e = static_cast<MimeTreeParser::MessagePart*>(index.internalPointer())) { | ||
200 | for (const auto &p : d->mParts) { | ||
201 | if (p.data() == e) { | ||
202 | return QModelIndex(); | ||
203 | } | ||
204 | } | ||
205 | const auto parentPart = d->mParents[e]; | ||
206 | Q_ASSERT(parentPart); | ||
207 | int row = 0; | ||
208 | const auto parts = d->mEncapsulatedParts[parentPart]; | ||
209 | for (const auto &p : parts) { | ||
210 | if (p.data() == e) { | ||
211 | break; | ||
212 | } | ||
213 | row++; | ||
214 | } | ||
215 | return createIndex(row, 0, parentPart); | ||
216 | } | ||
217 | return {}; | ||
218 | } | ||
219 | return {}; | ||
169 | } | 220 | } |
170 | 221 | ||
171 | int PartModel::rowCount(const QModelIndex &parent) const | 222 | int PartModel::rowCount(const QModelIndex &parent) const |
172 | { | 223 | { |
224 | if (parent.isValid()) { | ||
225 | if (auto e = dynamic_cast<MimeTreeParser::EncapsulatedRfc822MessagePart*>(static_cast<MimeTreeParser::MessagePart*>(parent.internalPointer()))) { | ||
226 | const auto parts = d->mEncapsulatedParts[e]; | ||
227 | return parts.size(); | ||
228 | } | ||
229 | return 0; | ||
230 | } | ||
173 | return d->mParts.count(); | 231 | return d->mParts.count(); |
174 | } | 232 | } |
175 | 233 | ||