diff --git a/plugins/messageviewer/bodypartformatter/vcard/text_vcard.cpp b/plugins/messageviewer/bodypartformatter/vcard/text_vcard.cpp --- a/plugins/messageviewer/bodypartformatter/vcard/text_vcard.cpp +++ b/plugins/messageviewer/bodypartformatter/vcard/text_vcard.cpp @@ -33,58 +33,59 @@ #include "updatecontactjob.h" #include "vcardmemento.h" +#include "vcard_debug.h" #include #include - #include +#include #include -#include + #include -#include #include +#include +#include using MimeTreeParser::Interface::BodyPart; #include #include #include - +#include +#include #include #include #include #include #include +#include +#include #include -#include -#include -#include "vcard_debug.h" namespace { -class Formatter : public MimeTreeParser::Interface::BodyPartFormatter +class Formatter : public MessageViewer::MessagePartRendererBase { public: - Formatter() - { - } + Formatter() = default; - Result format(MimeTreeParser::Interface::BodyPart *bodyPart, MimeTreeParser::HtmlWriter *writer) const override + bool render(const MimeTreeParser::MessagePartPtr &msgPart, MimeTreeParser::HtmlWriter *writer, MessageViewer::RenderContext*) const override { - if (!writer) { - return Ok; - } + QMimeDatabase db; + auto mt = db.mimeTypeForName(QString::fromLatin1(msgPart->content()->contentType()->mimeType().toLower())); + if (!mt.isValid() || mt.name() != QLatin1String("text/vcard")) + return false; - const QString vCard = bodyPart->asText(); + const QString vCard = msgPart->text(); if (vCard.isEmpty()) { - return AsIcon; + return false; } KContacts::VCardConverter vcc; - MessageViewer::VcardMemento *memento = dynamic_cast(bodyPart->memento()); + MessageViewer::VcardMemento *memento = dynamic_cast(msgPart->memento()); QStringList lst; // Pre-count the number of non-empty addressees @@ -102,7 +103,7 @@ } } if (!count && !memento) { - return AsIcon; + return false; } writer->write(QStringLiteral("

") @@ -115,9 +116,9 @@ if (!memento) { MessageViewer::VcardMemento *memento = new MessageViewer::VcardMemento(lst); - bodyPart->setBodyPartMemento(memento); + msgPart->setMemento(memento); - auto nodeHelper = bodyPart->nodeHelper(); + auto nodeHelper = msgPart->nodeHelper(); if (nodeHelper) { QObject::connect(memento, &MessageViewer::VcardMemento::update, nodeHelper, &MimeTreeParser::NodeHelper::update); @@ -138,10 +139,10 @@ htmlStr.replace(QStringLiteral("img src=\"contact_photo\""), QStringLiteral("img src=\"%1\"").arg(defaultPixmapPath)); } else { QImage img = a.photo().data(); - const QString dir = bodyPart->nodeHelper()->createTempDir(QStringLiteral("vcard-") + a.uid()); + const QString dir = msgPart->nodeHelper()->createTempDir(QStringLiteral("vcard-") + a.uid()); const QString filename = dir + QDir::separator() + a.uid(); img.save(filename, "PNG"); - bodyPart->nodeHelper()->addTempFile(filename); + msgPart->nodeHelper()->addTempFile(filename); const QString href = QStringLiteral("file:") + QLatin1String(QUrl::toPercentEncoding(filename)); htmlStr.replace(QLatin1String("img src=\"contact_photo\""), QStringLiteral("img src=\"%1\"").arg(href)); } @@ -153,16 +154,16 @@ const QString addToLinkText = i18n("[Add this contact to the address book]"); QString op = QStringLiteral("addToAddressBook:%1").arg(count); writer->write(QStringLiteral("

")); } else { if (memento->address(count) != a) { const QString addToLinkText = i18n("[Update this contact to the address book]"); const QString op = QStringLiteral("updateToAddressBook:%1").arg(count); writer->write(QStringLiteral("

")); @@ -176,7 +177,7 @@ count++; } - return Ok; + return true; } }; @@ -186,7 +187,7 @@ bool handleClick(MessageViewer::Viewer *viewerInstance, BodyPart *bodyPart, const QString &path) const override { Q_UNUSED(viewerInstance); - const QString vCard = bodyPart->asText(); + const QString vCard = bodyPart->content()->decodedText(); if (vCard.isEmpty()) { return true; } @@ -214,7 +215,7 @@ static KContacts::Addressee findAddressee(BodyPart *part, const QString &path) { - const QString vCard = part->asText(); + const QString vCard = part->content()->decodedText(); if (!vCard.isEmpty()) { KContacts::VCardConverter vcc; const KContacts::Addressee::List al = vcc.parseVCards(vCard.toUtf8()); @@ -228,7 +229,7 @@ bool handleContextMenuRequest(BodyPart *part, const QString &path, const QPoint &point) const override { - const QString vCard = part->asText(); + const QString vCard = part->content()->decodedText(); if (vCard.isEmpty()) { return true; } @@ -302,22 +303,15 @@ } }; -class Plugin : public QObject, public MimeTreeParser::Interface::BodyPartFormatterPlugin, public MessageViewer::MessagePartRenderPlugin +class Plugin : public QObject, public MessageViewer::MessagePartRenderPlugin { Q_OBJECT - Q_INTERFACES(MimeTreeParser::Interface::BodyPartFormatterPlugin) Q_INTERFACES(MessageViewer::MessagePartRenderPlugin) Q_PLUGIN_METADATA(IID "com.kde.messageviewer.bodypartformatter" FILE "text_vcard.json") public: - const MimeTreeParser::Interface::BodyPartFormatter *bodyPartFormatter(int idx) const override - { - return validIndex(idx) ? new Formatter() : nullptr; - } - MessageViewer::MessagePartRendererBase* renderer(int index) override { - Q_UNUSED(index); - return nullptr; + return validIndex(index) ? new Formatter() : nullptr; } const MessageViewer::Interface::BodyPartURLHandler *urlHandler(int idx) const override diff --git a/plugins/messageviewer/bodypartformatter/vcard/text_vcard.json b/plugins/messageviewer/bodypartformatter/vcard/text_vcard.json --- a/plugins/messageviewer/bodypartformatter/vcard/text_vcard.json +++ b/plugins/messageviewer/bodypartformatter/vcard/text_vcard.json @@ -3,6 +3,6 @@ { "mimetype": "text/vcard" } ], "renderer": [ - { "type": "MimeTreeParser::AttachmentMessagePart" } + { "type": "MimeTreeParser::AttachmentMessagePart", "mimetype": "text/vcard" } ] }