From d4bd3ad8d6d1f75b6c284336148e3a2c71dc1882 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 2 May 2017 09:25:13 +0200 Subject: Removed the old models that we're not even using anymore --- framework/src/CMakeLists.txt | 1 - framework/src/domain/messageparser.cpp | 52 ---------- framework/src/domain/messageparser.h | 44 --------- framework/src/domain/messageparser_old.cpp | 151 ----------------------------- 4 files changed, 248 deletions(-) delete mode 100644 framework/src/domain/messageparser_old.cpp diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index c82626a0..10773f8a 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt @@ -23,7 +23,6 @@ set(SRCS domain/composercontroller.cpp domain/messageparser.cpp domain/messageparser_new.cpp - domain/messageparser_old.cpp domain/mailtemplates.cpp domain/modeltest.cpp domain/retriever.cpp diff --git a/framework/src/domain/messageparser.cpp b/framework/src/domain/messageparser.cpp index 46ffe79d..6df50ebd 100644 --- a/framework/src/domain/messageparser.cpp +++ b/framework/src/domain/messageparser.cpp @@ -19,29 +19,13 @@ #include "messageparser.h" #include "modeltest.h" -#include "stringhtmlwriter.h" -#include "objecttreesource.h" - #include "mimetreeparser/interface.h" -#include - -#include -#include #include -#include -#include -#include -#include - class MessagePartPrivate { public: - QSharedPointer mPartTree; - QString mHtml; - QMap mEmbeddedPartMap; - std::shared_ptr mNodeHelper; std::shared_ptr mParser; }; @@ -57,16 +41,6 @@ MessageParser::~MessageParser() } -QString MessageParser::html() const -{ - return d->mHtml; -} - -bool MessageParser::isSimpleHtml() const -{ - return d->mHtml.contains("foobar"); -} - QVariant MessageParser::message() const { return QVariant(); @@ -74,36 +48,10 @@ QVariant MessageParser::message() const 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); - msg->parse(); - // qWarning() << "parsed: " << time.elapsed(); - - // render the mail - StringHtmlWriter htmlWriter; - //temporary files only have the lifetime of the nodehelper, so we keep it around until the mail changes. - d->mNodeHelper = std::make_shared(); - ObjectTreeSource source(&htmlWriter); - MimeTreeParser::ObjectTreeParser otp(&source, d->mNodeHelper.get()); - - otp.parseObjectTree(msg.data()); - d->mPartTree = otp.parsedPart().dynamicCast(); - - d->mEmbeddedPartMap = htmlWriter.embeddedParts(); - d->mHtml = htmlWriter.html(); emit htmlChanged(); } -QAbstractItemModel *MessageParser::partTree() const -{ - return new PartModel(d->mPartTree, d->mParser); -} - QAbstractItemModel *MessageParser::newTree() const { const auto model = new NewModel(d->mParser); diff --git a/framework/src/domain/messageparser.h b/framework/src/domain/messageparser.h index 2c4febaf..6d52c4b2 100644 --- a/framework/src/domain/messageparser.h +++ b/framework/src/domain/messageparser.h @@ -27,17 +27,10 @@ #include #include -#include class QAbstractItemModel; class Parser; -class Part; -class Encryption; -class Signature; -typedef std::shared_ptr PartPtr; -class Content; -typedef std::shared_ptr ContentPtr; class MessagePartPrivate; class NewModelPrivate; @@ -47,9 +40,6 @@ class MessageParser : public QObject { Q_OBJECT Q_PROPERTY (QVariant message READ message WRITE setMessage) - Q_PROPERTY (QString html READ html NOTIFY htmlChanged) - Q_PROPERTY (bool isSimpleHtml READ isSimpleHtml NOTIFY htmlChanged) - Q_PROPERTY (QAbstractItemModel* partTree READ partTree NOTIFY htmlChanged) Q_PROPERTY (QAbstractItemModel* newTree READ newTree NOTIFY htmlChanged) Q_PROPERTY (QAbstractItemModel* attachments READ attachments NOTIFY htmlChanged) @@ -57,12 +47,8 @@ public: explicit MessageParser(QObject *parent = Q_NULLPTR); ~MessageParser(); - QString html() const; - bool isSimpleHtml() const; - QVariant message() const; void setMessage(const QVariant &to); - QAbstractItemModel *partTree() const; QAbstractItemModel *newTree() const; QAbstractItemModel *attachments() const; @@ -73,36 +59,6 @@ private: std::unique_ptr d; }; -class PartModel : public QAbstractItemModel { - Q_OBJECT -public: - PartModel(QSharedPointer partTree, std::shared_ptr parser); - -public: - enum Roles { - Text = Qt::UserRole + 1, - IsHtml, - IsEncrypted, - IsAttachment, - HasContent, - Type, - IsHidden - }; - - QHash roleNames() const Q_DECL_OVERRIDE; - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; - QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE; - int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; - int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; - -private: - QSharedPointer mPartTree; - QMap mEmbeddedPartMap; - std::shared_ptr mParser; -}; - - class NewModel : public QAbstractItemModel { Q_OBJECT public: diff --git a/framework/src/domain/messageparser_old.cpp b/framework/src/domain/messageparser_old.cpp deleted file mode 100644 index a4247d8c..00000000 --- a/framework/src/domain/messageparser_old.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "messageparser.h" -#include "mimetreeparser/interface.h" - -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(); - const auto rx = QRegExp("(src)\\s*=\\s*(\"|')(cid:[^\"']+)\\2"); - int pos = 0; - while ((pos = rx.indexIn(text, pos)) != -1) { - const auto link = QUrl(rx.cap(3).toUtf8()); - pos += rx.matchedLength(); - const auto repl = mParser->getPart(link); - if (!repl) { - continue; - } - const auto content = repl->content(); - if(content.size() < 1) { - continue; - } - const auto mailMime = content.first()->mailMime(); - const auto mimetype = mailMime->mimetype().name(); - if (mimetype.startsWith("image/")) { - const auto data = content.first()->content(); - text.replace(rx.cap(0), QString("src=\"data:%1;base64,%2\"").arg(mimetype, QString::fromLatin1(data.toBase64()))); - } - } - 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; -} - -- cgit v1.2.3