Akonadi Contacts

grantleeprint.cpp
1 /*
2  SPDX-FileCopyrightText: 2015-2021 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 <grantlee/context.h>
11 #include <grantlee/engine.h>
12 #include <grantlee/metatype.h>
13 #include <grantlee/templateloader.h>
14 
15 #include <QMetaProperty>
16 #include <QVariant>
17 
18 GRANTLEE_BEGIN_LOOKUP(QUrl)
19 if (property == QLatin1String("scheme")) {
20  return object.scheme();
21 }
22 GRANTLEE_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  Grantlee::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 QString();
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 }
Akonadi::Item contact() const
Returns the contact that is currently displayed.
Additional properties for the KContacts::Addressee Grantlee model.
KCALUTILS_EXPORT QString errorMessage(const KCalendarCore::Exception &exception)
QVariant fromValue(const T &value)
QCA_EXPORT void init()
AddresseeList List
void render(QPaintDevice *target, const QPoint &targetOffset, const QRegion &sourceRegion, QWidget::RenderFlags renderFlags)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jun 23 2021 23:09:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.