Akonadi Contacts

grantleeprint.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2023 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "grantleeprint.h"
8 #include "contactgrantleewrapper.h"
9 
10 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
11 #include <grantlee/context.h>
12 #include <grantlee/engine.h>
13 #include <grantlee/metatype.h>
14 #include <grantlee/templateloader.h>
15 #else
16 #include <KTextTemplate/Context>
17 #include <KTextTemplate/Engine>
18 #include <KTextTemplate/MetaType>
19 #include <KTextTemplate/TemplateLoader>
20 #endif
21 
22 #include <QMetaProperty>
23 #include <QVariant>
24 
25 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
26 GRANTLEE_BEGIN_LOOKUP(QUrl)
27 #else
29 #endif
30 if (property == QLatin1String("scheme")) {
31  return object.scheme();
32 }
33 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
34 GRANTLEE_END_LOOKUP
35 #else
37 #endif
38 
39 using namespace KAddressBookGrantlee;
40 
41 GrantleePrint::GrantleePrint()
42 {
43  init();
44 }
45 
46 GrantleePrint::GrantleePrint(const QString &themePath)
47  : GrantleeTheme::GenericFormatter(QStringLiteral("theme.html"), themePath)
48 {
49  init();
50 }
51 
52 GrantleePrint::~GrantleePrint() = default;
53 
54 void GrantleePrint::init()
55 {
56 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
57  Grantlee::registerMetaType<QUrl>();
58 #else
59  KTextTemplate::registerMetaType<QUrl>();
60 #endif
61 }
62 
63 QString GrantleePrint::contactsToHtml(const KContacts::Addressee::List &contacts)
64 {
65  if (!errorMessage().isEmpty()) {
66  return errorMessage();
67  }
68 
69  if (contacts.isEmpty()) {
70  return {};
71  }
72  QVariantList contactsList;
73  contactsList.reserve(contacts.count());
74  for (const KContacts::Addressee &contact : contacts) {
75  contactsList.push_back(QVariant::fromValue(ContactGrantleeWrapper(contact)));
76  }
77  QVariantHash mapping;
78  mapping.insert(QStringLiteral("contacts"), contactsList);
79 
80  return render(mapping);
81 }
QVariant fromValue(const T &value)
KCALUTILS_EXPORT QString errorMessage(const KCalendarCore::Exception &exception)
void init(KXmlGuiWindow *window, KgDifficulty *difficulty=nullptr)
#define KTEXTTEMPLATE_BEGIN_LOOKUP(Type)
#define KTEXTTEMPLATE_END_LOOKUP
Additional properties for the KContacts::Addressee Grantlee model.
AddresseeList List
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:09:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.