File indexing completed on 2024-11-24 04:39:27
0001 /* 0002 This file is part of Akonadi Contact. 0003 0004 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "akonadi-contact-core_export.h" 0012 0013 #include <QVariantMap> 0014 0015 #include <memory> 0016 0017 namespace KContacts 0018 { 0019 class Addressee; 0020 } 0021 0022 namespace Akonadi 0023 { 0024 class Item; 0025 class AbstractContactFormatterPrivate; 0026 0027 /** 0028 * @short The interface for all contact formatters. 0029 * 0030 * This is the interface that can be used to format an Akonadi 0031 * item with a contact payload or a contact itself as HTML. 0032 * 0033 * @see StandardContactFormatter 0034 * @author Tobias Koenig <tokoe@kde.org> 0035 * @since 4.5 0036 */ 0037 class AKONADI_CONTACT_CORE_EXPORT AbstractContactFormatter 0038 { 0039 public: 0040 /** 0041 * Describes the form of the HTML that is created. 0042 */ 0043 enum HtmlForm { 0044 SelfcontainedForm, ///< Creates a complete HTML document 0045 EmbeddableForm, ///< Creates a div HTML element that can be embedded. 0046 UserForm = SelfcontainedForm + 42 ///< Point for extension 0047 }; 0048 0049 /** 0050 * Creates a new abstract contact formatter. 0051 */ 0052 AbstractContactFormatter(); 0053 0054 /** 0055 * Destroys the abstract contact formatter. 0056 */ 0057 virtual ~AbstractContactFormatter(); 0058 0059 /** 0060 * Sets the @p contact that will be formatted. 0061 * @param contact contact to be formatted 0062 */ 0063 void setContact(const KContacts::Addressee &contact); 0064 0065 /** 0066 * Returns the contact that will be formatted. 0067 */ 0068 [[nodiscard]] KContacts::Addressee contact() const; 0069 0070 /** 0071 * Sets the @p item who's payload will be formatted. 0072 * 0073 * @note The payload must be a valid KContacts::Addressee object. 0074 * @param item item, who's payload will be formatted. 0075 */ 0076 void setItem(const Akonadi::Item &item); 0077 0078 /** 0079 * Returns the item who's payload will be formatted. 0080 */ 0081 [[nodiscard]] Akonadi::Item item() const; 0082 0083 /** 0084 * Sets the custom field @p descriptions that will be used. 0085 * 0086 * The description list contains a QVariantMap for each custom field 0087 * with the following keys: 0088 * - key (string) The identifier of the field 0089 * - title (string) The i18n'ed title of the field 0090 * - type (string) The type description of the field 0091 * Possible values for type description are 0092 * - text 0093 * - numeric 0094 * - boolean 0095 * - date 0096 * - time 0097 * - datetime 0098 * 0099 * @param descriptions list with field descriptions 0100 */ 0101 void setCustomFieldDescriptions(const QList<QVariantMap> &descriptions); 0102 0103 /** 0104 * Returns the custom field descriptions that will be used. 0105 */ 0106 [[nodiscard]] QList<QVariantMap> customFieldDescriptions() const; 0107 0108 /** 0109 * This method must be reimplemented to return the contact formatted as HTML 0110 * according to the requested @p form. 0111 * @param form how to render the contact into HTML 0112 */ 0113 virtual QString toHtml(HtmlForm form = SelfcontainedForm) const = 0; 0114 0115 private: 0116 //@cond PRIVATE 0117 Q_DISABLE_COPY(AbstractContactFormatter) 0118 0119 std::unique_ptr<AbstractContactFormatterPrivate> const d; 0120 //@endcond 0121 }; 0122 }