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 #include <KTextTemplate/Context>
11 #include <KTextTemplate/Engine>
12 #include <KTextTemplate/MetaType>
13 #include <KTextTemplate/TemplateLoader>
14 
15 #include <QMetaProperty>
16 #include <QVariant>
17 
18 KTEXTTEMPLATE_BEGIN_LOOKUP(QUrl)
19 if (property == QLatin1String("scheme")) {
20  return object.scheme();
21 }
22 KTEXTTEMPLATE_END_LOOKUP
23 
24 using namespace KAddressBookGrantlee;
25 
26 GrantleePrint::GrantleePrint()
27 {
28  init();
29 }
30 
31 GrantleePrint::GrantleePrint(const QString &themePath)
32  : GrantleeTheme::GenericFormatter(QStringLiteral("theme.html"), themePath)
33 {
34  init();
35 }
36 
37 GrantleePrint::~GrantleePrint() = default;
38 
39 void GrantleePrint::init()
40 {
41  KTextTemplate::registerMetaType<QUrl>();
42 }
43 
44 QString GrantleePrint::contactsToHtml(const KContacts::Addressee::List &contacts)
45 {
46  if (!errorMessage().isEmpty()) {
47  return errorMessage();
48  }
49 
50  if (contacts.isEmpty()) {
51  return {};
52  }
53  QVariantList contactsList;
54  contactsList.reserve(contacts.count());
55  for (const KContacts::Addressee &contact : contacts) {
56  contactsList.push_back(QVariant::fromValue(ContactGrantleeWrapper(contact)));
57  }
58  QVariantHash mapping;
59  mapping.insert(QStringLiteral("contacts"), contactsList);
60 
61  return render(mapping);
62 }
QVariant fromValue(const T &value)
KCALUTILS_EXPORT QString errorMessage(const KCalendarCore::Exception &exception)
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
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 Wed Dec 6 2023 04:02:52 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.