From 349e404b539c1f9d1feb54658e2e6fbbd2165462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Wed, 10 Aug 2016 13:20:11 +0200 Subject: Use new mimetreeparser interface --- framework/domain/messageparser.cpp | 49 ++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'framework/domain/messageparser.cpp') diff --git a/framework/domain/messageparser.cpp b/framework/domain/messageparser.cpp index 8363e119..262be0b7 100644 --- a/framework/domain/messageparser.cpp +++ b/framework/domain/messageparser.cpp @@ -21,6 +21,10 @@ #include "stringhtmlwriter.h" #include "objecttreesource.h" +#include "mimetreeparser/interface.h" + +#include + #include #include #include @@ -29,7 +33,9 @@ #include #include -PartModel::PartModel(QSharedPointer partTree, QMap embeddedPartMap) : mPartTree(partTree), mEmbeddedPartMap(embeddedPartMap) +PartModel::PartModel(QSharedPointer partTree, std::shared_ptr parser) + : mPartTree(partTree) + , mParser(parser) { } @@ -73,8 +79,14 @@ QVariant PartModel::data(const QModelIndex &index, int role) const // qDebug() << "Getting text: " << part->property("text").toString(); // FIXME: we should have a list per part, and not one for all parts. auto text = part->property("htmlContent").toString(); - for (const auto &cid : mEmbeddedPartMap.keys()) { - text.replace(QString("src=\"cid:%1\"").arg(QString(cid)), QString("src=\"%1\"").arg(mEmbeddedPartMap.value(cid).toString())); + auto rx = QRegExp("src=(\"|')cid:([^\1]*)\1"); + int pos = 0; + while ((pos = rx.indexIn(text, pos)) != -1) { + auto repl = mParser->getPart(rx.cap(2).toUtf8()); + if (repl.isValid()) { + text.replace(rx.cap(0), QString("src=\"%1\"").arg(repl.toString())); + } + pos += rx.matchedLength(); } return text; } @@ -140,16 +152,31 @@ int PartModel::columnCount(const QModelIndex &parent) const return 1; } +class MessagePartPrivate +{ +public: + QSharedPointer mPartTree; + QString mHtml; + QMap mEmbeddedPartMap; + std::shared_ptr mNodeHelper; + std::shared_ptr mParser; +}; MessageParser::MessageParser(QObject *parent) : QObject(parent) + , d(std::unique_ptr(new MessagePartPrivate)) +{ + +} + +MessageParser::~MessageParser() { } QString MessageParser::html() const { - return mHtml; + return d->mHtml; } QVariant MessageParser::message() const @@ -161,6 +188,8 @@ void MessageParser::setMessage(const QVariant &message) { QTime time; time.start(); + d->mParser = std::shared_ptr(new Parser(message.toByteArray())); + const auto mailData = KMime::CRLFtoLF(message.toByteArray()); KMime::Message::Ptr msg(new KMime::Message); msg->setContent(mailData); @@ -170,20 +199,20 @@ void MessageParser::setMessage(const QVariant &message) // render the mail StringHtmlWriter htmlWriter; //temporary files only have the lifetime of the nodehelper, so we keep it around until the mail changes. - mNodeHelper = std::make_shared(); + d->mNodeHelper = std::make_shared(); ObjectTreeSource source(&htmlWriter); - MimeTreeParser::ObjectTreeParser otp(&source, mNodeHelper.get()); + MimeTreeParser::ObjectTreeParser otp(&source, d->mNodeHelper.get()); otp.parseObjectTree(msg.data()); - mPartTree = otp.parsedPart().dynamicCast(); + d->mPartTree = otp.parsedPart().dynamicCast(); - mEmbeddedPartMap = htmlWriter.embeddedParts(); - mHtml = htmlWriter.html(); + d->mEmbeddedPartMap = htmlWriter.embeddedParts(); + d->mHtml = htmlWriter.html(); emit htmlChanged(); } QAbstractItemModel *MessageParser::partTree() const { - return new PartModel(mPartTree, mEmbeddedPartMap); + return new PartModel(d->mPartTree, d->mParser); } -- cgit v1.2.3 From 1974c19eadd497e355ac985a00d0571f3e6c7712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Tue, 11 Oct 2016 16:18:50 +0200 Subject: create model for new mailviewer --- framework/domain/messageparser.cpp | 123 ++----------------------------------- 1 file changed, 4 insertions(+), 119 deletions(-) (limited to 'framework/domain/messageparser.cpp') diff --git a/framework/domain/messageparser.cpp b/framework/domain/messageparser.cpp index febd1363..ef9fb0d2 100644 --- a/framework/domain/messageparser.cpp +++ b/framework/domain/messageparser.cpp @@ -33,125 +33,6 @@ #include #include -PartModel::PartModel(QSharedPointer partTree, std::shared_ptr parser) - : mPartTree(partTree) - , mParser(parser) -{ -} - -QHash PartModel::roleNames() const -{ - QHash roles; - roles[Text] = "text"; - roles[IsHtml] = "isHtml"; - roles[IsHidden] = "isHidden"; - roles[IsEncrypted] = "isEncrypted"; - roles[IsAttachment] = "isAttachment"; - roles[HasContent] = "hasContent"; - roles[Type] = "type"; - roles[IsHidden] = "isHidden"; - return roles; -} - -QModelIndex PartModel::index(int row, int column, const QModelIndex &parent) const -{ - // qDebug() << "index " << parent << row << column << mPartTree->subParts().size(); - if (!parent.isValid()) { - if (row < mPartTree->subParts().size()) { - auto part = mPartTree->subParts().at(row); - return createIndex(row, column, part.data()); - } - } else { - auto part = static_cast(parent.internalPointer()); - auto subPart = part->subParts().at(row); - return createIndex(row, column, subPart.data()); - } - return QModelIndex(); -} - -QVariant PartModel::data(const QModelIndex &index, int role) const -{ - // qDebug() << "Getting data for index"; - if (index.isValid()) { - auto part = static_cast(index.internalPointer()); - switch (role) { - case Text: { - // qDebug() << "Getting text: " << part->property("text").toString(); - // FIXME: we should have a list per part, and not one for all parts. - auto text = part->property("htmlContent").toString(); - auto rx = QRegExp("src=(\"|')cid:([^\1]*)\1"); - int pos = 0; - while ((pos = rx.indexIn(text, pos)) != -1) { - auto repl = mParser->getPart(rx.cap(2).toUtf8()); - if (repl.isValid()) { - text.replace(rx.cap(0), QString("src=\"%1\"").arg(repl.toString())); - } - pos += rx.matchedLength(); - } - return text; - } - case IsAttachment: - return part->property("attachment").toBool(); - case IsEncrypted: - return part->property("isEncrypted").toBool(); - case IsHtml: - return part->property("isHtml").toBool(); - case HasContent: - return !part->property("htmlContent").toString().isEmpty(); - case Type: - return part->metaObject()->className(); - case IsHidden: - return false; - //return part->property("isHidden").toBool(); - - } - } - return QVariant(); -} - -QModelIndex PartModel::parent(const QModelIndex &index) const -{ - // qDebug() << "parent " << index; - if (index.isValid()) { - auto part = static_cast(index.internalPointer()); - auto parentPart = static_cast(part->parentPart()); - auto row = 0;//get the parents parent to find the index - if (!parentPart) { - parentPart = mPartTree.data(); - } - int i = 0; - for (const auto &p : parentPart->subParts()) { - if (p.data() == part) { - row = i; - break; - } - i++; - } - return createIndex(row, index.column(), parentPart); - } - return QModelIndex(); -} - -int PartModel::rowCount(const QModelIndex &parent) const -{ - // qDebug() << "Row count " << parent; - if (!parent.isValid()) { - // qDebug() << "Row count " << mPartTree->subParts().size(); - return mPartTree->subParts().size(); - } else { - auto part = static_cast(parent.internalPointer()); - if (part) { - return part->subParts().size(); - } - } - return 0; -} - -int PartModel::columnCount(const QModelIndex &parent) const -{ - // qDebug() << "Column count " << parent; - return 1; -} class MessagePartPrivate { @@ -217,3 +98,7 @@ QAbstractItemModel *MessageParser::partTree() const return new PartModel(d->mPartTree, d->mParser); } +QAbstractItemModel *MessageParser::newTree() const +{ + return new NewModel(d->mParser); +} -- cgit v1.2.3 From 0fa8aa51aac15233820b9f9c576584e6ff8ee151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Knau=C3=9F?= Date: Tue, 18 Oct 2016 15:28:45 +0200 Subject: use modeltest fromupstream to make sure, we have a valid model --- framework/domain/messageparser.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'framework/domain/messageparser.cpp') diff --git a/framework/domain/messageparser.cpp b/framework/domain/messageparser.cpp index ef9fb0d2..ec79d50b 100644 --- a/framework/domain/messageparser.cpp +++ b/framework/domain/messageparser.cpp @@ -18,6 +18,7 @@ */ #include "messageparser.h" +#include "modeltest.h" #include "stringhtmlwriter.h" #include "objecttreesource.h" @@ -100,5 +101,7 @@ QAbstractItemModel *MessageParser::partTree() const QAbstractItemModel *MessageParser::newTree() const { - return new NewModel(d->mParser); + const auto model = new NewModel(d->mParser); + new ModelTest(model, model); + return model; } -- cgit v1.2.3