diff options
author | Sandro Knauß <sknauss@kde.org> | 2016-10-11 16:18:50 +0200 |
---|---|---|
committer | Sandro Knauß <sknauss@kde.org> | 2016-10-11 16:18:50 +0200 |
commit | 1974c19eadd497e355ac985a00d0571f3e6c7712 (patch) | |
tree | 051b61cfe222150dc114e5da04fdd072ceffb3b7 /framework/domain/messageparser_new.cpp | |
parent | 6b6f20ffbe06402abcc7d4721ad1f647c3fc4c46 (diff) | |
download | kube-1974c19eadd497e355ac985a00d0571f3e6c7712.tar.gz kube-1974c19eadd497e355ac985a00d0571f3e6c7712.zip |
create model for new mailviewer
Diffstat (limited to 'framework/domain/messageparser_new.cpp')
-rw-r--r-- | framework/domain/messageparser_new.cpp | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/framework/domain/messageparser_new.cpp b/framework/domain/messageparser_new.cpp new file mode 100644 index 00000000..d1b956f5 --- /dev/null +++ b/framework/domain/messageparser_new.cpp | |||
@@ -0,0 +1,148 @@ | |||
1 | |||
2 | /* | ||
3 | 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 | the Free Software Foundation; either version 2 of the License, or (at your | ||
6 | option) any later version. | ||
7 | |||
8 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
9 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
10 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
11 | License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU Library General Public License | ||
14 | along with this library; see the file COPYING.LIB. If not, write to the | ||
15 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
16 | 02110-1301, USA. | ||
17 | */ | ||
18 | |||
19 | #include "messageparser.h" | ||
20 | #include "mimetreeparser/interface.h" | ||
21 | |||
22 | #include <QDebug> | ||
23 | |||
24 | NewModel::NewModel(std::shared_ptr<Parser> parser) | ||
25 | : mParser(parser) | ||
26 | { | ||
27 | mParts = mParser->collectContentParts(); | ||
28 | foreach(const auto &part, mParts) { | ||
29 | mContentMap.insert(part.get(), std::shared_ptr<NewContentModel>(new NewContentModel(part))); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | QHash<int, QByteArray> NewModel::roleNames() const | ||
34 | { | ||
35 | QHash<int, QByteArray> roles; | ||
36 | roles[TypeRole] = "type"; | ||
37 | roles[ContentsRole] = "contents"; | ||
38 | roles[IsEmbededRole] = "embeded"; | ||
39 | roles[SecurityLevelRole] = "securityLevel"; | ||
40 | return roles; | ||
41 | } | ||
42 | |||
43 | QModelIndex NewModel::index(int row, int column, const QModelIndex &parent) const | ||
44 | { | ||
45 | if (!parent.isValid()) { | ||
46 | if (row < mParts.size()) { | ||
47 | auto part = mParts.at(row); | ||
48 | return createIndex(row, column, part.get()); | ||
49 | } | ||
50 | } | ||
51 | return QModelIndex(); | ||
52 | } | ||
53 | |||
54 | QVariant NewModel::data(const QModelIndex &index, int role) const | ||
55 | { | ||
56 | if (!index.parent().isValid()) { | ||
57 | auto part = static_cast<Part *>(index.internalPointer()); | ||
58 | switch (role) { | ||
59 | case TypeRole: | ||
60 | return QString::fromLatin1(part->type()); | ||
61 | case IsEmbededRole: | ||
62 | return index.parent().isValid(); | ||
63 | case SecurityLevelRole: | ||
64 | return QStringLiteral("GRAY"); | ||
65 | case ContentsRole: | ||
66 | return QVariant::fromValue<QAbstractItemModel *>(mContentMap.value(part).get()); | ||
67 | } | ||
68 | } | ||
69 | return QVariant(); | ||
70 | } | ||
71 | |||
72 | QModelIndex NewModel::parent(const QModelIndex &index) const | ||
73 | { | ||
74 | return QModelIndex(); | ||
75 | } | ||
76 | |||
77 | int NewModel::rowCount(const QModelIndex &parent) const | ||
78 | { | ||
79 | if (!parent.isValid()) { | ||
80 | return mParts.size(); | ||
81 | } | ||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | int NewModel::columnCount(const QModelIndex &parent) const | ||
86 | { | ||
87 | return 1; | ||
88 | } | ||
89 | |||
90 | NewContentModel::NewContentModel(const Part::Ptr &part) | ||
91 | : mPart(part) | ||
92 | { | ||
93 | } | ||
94 | |||
95 | QHash<int, QByteArray> NewContentModel::roleNames() const | ||
96 | { | ||
97 | QHash<int, QByteArray> roles; | ||
98 | roles[TypeRole] = "type"; | ||
99 | roles[ContentRole] = "content"; | ||
100 | roles[IsEmbededRole] = "embeded"; | ||
101 | roles[SecurityLevelRole] = "securityLevel"; | ||
102 | return roles; | ||
103 | } | ||
104 | |||
105 | QModelIndex NewContentModel::index(int row, int column, const QModelIndex &parent) const | ||
106 | { | ||
107 | if (!parent.isValid()) { | ||
108 | if (row < mPart->content().size()) { | ||
109 | auto part = mPart->content().at(row); | ||
110 | return createIndex(row, column, part.get()); | ||
111 | } | ||
112 | } | ||
113 | return QModelIndex(); | ||
114 | } | ||
115 | |||
116 | QVariant NewContentModel::data(const QModelIndex &index, int role) const | ||
117 | { | ||
118 | auto content = static_cast<Content *>(index.internalPointer()); | ||
119 | switch (role) { | ||
120 | case TypeRole: | ||
121 | return QString::fromLatin1(content->type()); | ||
122 | case IsEmbededRole: | ||
123 | return false; | ||
124 | case ContentRole: | ||
125 | return content->encodedContent(); | ||
126 | case SecurityLevelRole: | ||
127 | return content->encryptions().size() > mPart->encryptions().size() ? "red": "black"; //test for gpg inline | ||
128 | } | ||
129 | return QVariant(); | ||
130 | } | ||
131 | |||
132 | QModelIndex NewContentModel::parent(const QModelIndex &index) const | ||
133 | { | ||
134 | return QModelIndex(); | ||
135 | } | ||
136 | |||
137 | int NewContentModel::rowCount(const QModelIndex &parent) const | ||
138 | { | ||
139 | if (!parent.isValid()) { | ||
140 | return mPart->content().size(); | ||
141 | } | ||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | int NewContentModel::columnCount(const QModelIndex &parent) const | ||
146 | { | ||
147 | return 1; | ||
148 | } | ||