File indexing completed on 2025-01-19 04:46:50

0001 /*
0002    SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "itinerarykdeconnecthandler.h"
0008 #include "itineraryprocessor.h"
0009 #include "itineraryrenderer.h"
0010 #include "itineraryurlhandler.h"
0011 
0012 #include <MessageViewer/MessagePartRenderPlugin>
0013 #include <MimeTreeParser/BodyPartFormatter>
0014 
0015 namespace
0016 {
0017 class ItineraryPlugin : public QObject, public MimeTreeParser::Interface::BodyPartFormatterPlugin, public MessageViewer::MessagePartRenderPlugin
0018 {
0019     Q_OBJECT
0020     Q_INTERFACES(MimeTreeParser::Interface::BodyPartFormatterPlugin)
0021     Q_INTERFACES(MessageViewer::MessagePartRenderPlugin)
0022     Q_PLUGIN_METADATA(IID "com.kde.messageviewer.bodypartformatter" FILE "itinerary_plugin.json")
0023 public:
0024     explicit ItineraryPlugin(QObject *parent = nullptr)
0025         : QObject(parent)
0026         , m_kdeConnect(new ItineraryKDEConnectHandler(this))
0027     {
0028     }
0029 
0030     [[nodiscard]] const MimeTreeParser::Interface::BodyPartFormatter *bodyPartFormatter(int idx) const override
0031     {
0032         if (idx < 3) {
0033             return new ItineraryProcessor();
0034         }
0035         return nullptr;
0036     }
0037 
0038     MessageViewer::MessagePartRendererBase *renderer(int idx) override
0039     {
0040         if (idx == 0) {
0041             auto renderer = new ItineraryRenderer();
0042             renderer->setKDEConnectHandler(m_kdeConnect);
0043             return renderer;
0044         }
0045         return nullptr;
0046     }
0047 
0048     [[nodiscard]] const MessageViewer::Interface::BodyPartURLHandler *urlHandler(int idx) const override
0049     {
0050         if (idx == 0) {
0051             auto handler = new ItineraryUrlHandler();
0052             handler->setKDEConnectHandler(m_kdeConnect);
0053             return handler;
0054         }
0055         return nullptr;
0056     }
0057 
0058 private:
0059     ItineraryKDEConnectHandler *const m_kdeConnect;
0060 };
0061 }
0062 
0063 #include "itinerary_plugin.moc"