7 #include "messagepartrenderermanager.h"
8 #include "messageviewer_debug.h"
9 #include <GrantleeTheme/GrantleeKi18nLocalizer>
10 #include <GrantleeTheme/GrantleeThemeEngine>
11 #include <KIconLoader>
12 #include <QStandardPaths>
14 #include <gpgme++/decryptionresult.h>
15 #include <gpgme++/key.h>
16 #include <gpgme++/verificationresult.h>
18 #include <QGpgME/Protocol>
20 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
21 #include <grantlee/context.h>
22 #include <grantlee/engine.h>
23 #include <grantlee/metatype.h>
24 #include <grantlee/templateloader.h>
26 #include <KTextTemplate/context.h>
27 #include <KTextTemplate/engine.h>
28 #include <KTextTemplate/metatype.h>
29 #include <KTextTemplate/templateloader.h>
32 #include <QGuiApplication>
33 Q_DECLARE_METATYPE(GpgME::DecryptionResult::Recipient)
34 Q_DECLARE_METATYPE(
const QGpgME::Protocol *)
35 Q_DECLARE_METATYPE(GpgME::Key)
38 GRANTLEE_BEGIN_LOOKUP(GpgME::DecryptionResult::Recipient)
47 inline QVariant TypeAccessor<const QGpgME::Protocol *>::lookUp(
const QGpgME::Protocol *
const object,
const QString &property)
50 return object->name();
52 return object->displayName();
63 TypeAccessor<std::pair<GpgME::DecryptionResult::Recipient, GpgME::Key> &>::lookUp(std::pair<GpgME::DecryptionResult::Recipient, GpgME::Key>
const &
object,
79 namespace MessageViewer
81 class GlobalContext :
public QObject
85 Q_PROPERTY(
int iconSize READ iconSize CONSTANT)
87 explicit GlobalContext(
QObject *parent)
92 Q_REQUIRED_RESULT
QString layoutDirection()
const
97 Q_REQUIRED_RESULT
int iconSize()
const
104 using namespace MessageViewer;
106 MessagePartRendererManager::MessagePartRendererManager(
QObject *parent)
108 , m_globalContext(new GlobalContext(this))
110 initializeRenderer();
113 MessagePartRendererManager::~MessagePartRendererManager()
124 void MessagePartRendererManager::initializeRenderer()
126 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
127 Grantlee::registerMetaType<GpgME::DecryptionResult::Recipient>();
128 Grantlee::registerMetaType<const QGpgME::Protocol *>();
129 Grantlee::registerMetaType<std::pair<GpgME::DecryptionResult::Recipient, GpgME::Key>>();
131 KTextTemplate::registerMetaType<GpgME::DecryptionResult::Recipient>();
132 KTextTemplate::registerMetaType<const QGpgME::Protocol *>();
133 KTextTemplate::registerMetaType<std::pair<GpgME::DecryptionResult::Recipient, GpgME::Key>>();
137 for (
const auto &p : libraryPaths) {
138 m_engine->addPluginPath(p + QStringLiteral(
"/messageviewer"));
140 m_engine->addDefaultLibrary(QStringLiteral(
"messageviewer_grantlee_extension"));
141 m_engine->localizer()->setApplicationDomain(QByteArrayLiteral(
"libmessageviewer"));
142 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
147 loader->setTemplateDirs({QStringLiteral(
":/")});
148 m_engine->addTemplateLoader(loader);
150 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
151 Grantlee::Template MessagePartRendererManager::loadByName(
const QString &name)
153 KTextTemplate::Template MessagePartRendererManager::loadByName(
const QString &name)
156 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
157 Grantlee::Template t = m_engine->loadByName(name);
159 KTextTemplate::Template t = m_engine->loadByName(name);
162 qCWarning(MESSAGEVIEWER_LOG) << t->errorString() <<
". Searched in subdir mimetreeparser/themes/default in these locations"
167 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
168 Grantlee::Context MessagePartRendererManager::createContext()
170 KTextTemplate::Context MessagePartRendererManager::createContext()
173 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
176 KTextTemplate::Context c;
180 auto localizer = m_engine->localizer();
181 localizer->setApplicationDomain(QByteArrayLiteral(
"libmessageviewer"));
182 c.setLocalizer(localizer);
184 c.insert(QStringLiteral(
"global"), m_globalContext);
188 #include "messagepartrenderermanager.moc"