summaryrefslogtreecommitdiffstats
path: root/framework/domain/messageparser_old.cpp
diff options
context:
space:
mode:
authorSandro Knauß <sknauss@kde.org>2016-10-11 16:18:50 +0200
committerSandro Knauß <sknauss@kde.org>2016-10-11 16:18:50 +0200
commit1974c19eadd497e355ac985a00d0571f3e6c7712 (patch)
tree051b61cfe222150dc114e5da04fdd072ceffb3b7 /framework/domain/messageparser_old.cpp
parent6b6f20ffbe06402abcc7d4721ad1f647c3fc4c46 (diff)
downloadkube-1974c19eadd497e355ac985a00d0571f3e6c7712.tar.gz
kube-1974c19eadd497e355ac985a00d0571f3e6c7712.zip
create model for new mailviewer
Diffstat (limited to 'framework/domain/messageparser_old.cpp')
-rw-r--r--framework/domain/messageparser_old.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/framework/domain/messageparser_old.cpp b/framework/domain/messageparser_old.cpp
new file mode 100644
index 00000000..a364c8ab
--- /dev/null
+++ b/framework/domain/messageparser_old.cpp
@@ -0,0 +1,140 @@
1/*
2 This library is free software; you can redistribute it and/or modify it
3 under the terms of the GNU Library General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or (at your
5 option) any later version.
6
7 This library is distributed in the hope that it will be useful, but WITHOUT
8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
10 License for more details.
11
12 You should have received a copy of the GNU Library General Public License
13 along with this library; see the file COPYING.LIB. If not, write to the
14 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 02110-1301, USA.
16*/
17
18#include "messageparser.h"
19#include "mimetreeparser/interface.h"
20
21PartModel::PartModel(QSharedPointer<MimeTreeParser::MessagePart> partTree, std::shared_ptr<Parser> parser)
22 : mPartTree(partTree)
23 , mParser(parser)
24{
25}
26
27QHash<int, QByteArray> PartModel::roleNames() const
28{
29 QHash<int, QByteArray> roles;
30 roles[Text] = "text";
31 roles[IsHtml] = "isHtml";
32 roles[IsHidden] = "isHidden";
33 roles[IsEncrypted] = "isEncrypted";
34 roles[IsAttachment] = "isAttachment";
35 roles[HasContent] = "hasContent";
36 roles[Type] = "type";
37 roles[IsHidden] = "isHidden";
38 return roles;
39}
40
41QModelIndex PartModel::index(int row, int column, const QModelIndex &parent) const
42{
43 // qDebug() << "index " << parent << row << column << mPartTree->subParts().size();
44 if (!parent.isValid()) {
45 if (row < mPartTree->subParts().size()) {
46 auto part = mPartTree->subParts().at(row);
47 return createIndex(row, column, part.data());
48 }
49 } else {
50 auto part = static_cast<MimeTreeParser::MessagePart*>(parent.internalPointer());
51 auto subPart = part->subParts().at(row);
52 return createIndex(row, column, subPart.data());
53 }
54 return QModelIndex();
55}
56
57QVariant PartModel::data(const QModelIndex &index, int role) const
58{
59 // qDebug() << "Getting data for index";
60 if (index.isValid()) {
61 auto part = static_cast<MimeTreeParser::MessagePart*>(index.internalPointer());
62 switch (role) {
63 case Text: {
64 // qDebug() << "Getting text: " << part->property("text").toString();
65 // FIXME: we should have a list per part, and not one for all parts.
66 auto text = part->property("htmlContent").toString();
67 auto rx = QRegExp("src=(\"|')cid:([^\1]*)\1");
68 int pos = 0;
69 while ((pos = rx.indexIn(text, pos)) != -1) {
70 auto repl = mParser->getPart(rx.cap(2).toUtf8());
71 if (repl.isValid()) {
72 text.replace(rx.cap(0), QString("src=\"%1\"").arg(repl.toString()));
73 }
74 pos += rx.matchedLength();
75 }
76 return text;
77 }
78 case IsAttachment:
79 return part->property("attachment").toBool();
80 case IsEncrypted:
81 return part->property("isEncrypted").toBool();
82 case IsHtml:
83 return part->property("isHtml").toBool();
84 case HasContent:
85 return !part->property("htmlContent").toString().isEmpty();
86 case Type:
87 return part->metaObject()->className();
88 case IsHidden:
89 return false;
90 //return part->property("isHidden").toBool();
91
92 }
93 }
94 return QVariant();
95}
96
97QModelIndex PartModel::parent(const QModelIndex &index) const
98{
99 // qDebug() << "parent " << index;
100 if (index.isValid()) {
101 auto part = static_cast<MimeTreeParser::MessagePart*>(index.internalPointer());
102 auto parentPart = static_cast<MimeTreeParser::MessagePart*>(part->parentPart());
103 auto row = 0;//get the parents parent to find the index
104 if (!parentPart) {
105 parentPart = mPartTree.data();
106 }
107 int i = 0;
108 for (const auto &p : parentPart->subParts()) {
109 if (p.data() == part) {
110 row = i;
111 break;
112 }
113 i++;
114 }
115 return createIndex(row, index.column(), parentPart);
116 }
117 return QModelIndex();
118}
119
120int PartModel::rowCount(const QModelIndex &parent) const
121{
122 // qDebug() << "Row count " << parent;
123 if (!parent.isValid()) {
124 // qDebug() << "Row count " << mPartTree->subParts().size();
125 return mPartTree->subParts().size();
126 } else {
127 auto part = static_cast<MimeTreeParser::MessagePart*>(parent.internalPointer());
128 if (part) {
129 return part->subParts().size();
130 }
131 }
132 return 0;
133}
134
135int PartModel::columnCount(const QModelIndex &parent) const
136{
137 // qDebug() << "Column count " << parent;
138 return 1;
139}
140