File indexing completed on 2024-11-17 04:40:41

0001 /*
0002     This file is part of Contact Editor.
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-widgets_export.h"
0012 #include <QList>
0013 #include <QString>
0014 #include <QVariant>
0015 template<typename T>
0016 class QList;
0017 
0018 /**
0019  * @short A class that represents non-standard contact fields.
0020  *
0021  * There exists three scopes of fields. To the local scope belong all
0022  * custom fields that are defined by the user and that exists only for one
0023  * contact. The description for these fields are stored inside ContactMetaData
0024  * as custom attribute of the Akonadi item that represents the contact.
0025  * To the global scope belong all custom fields that are defined by the user but
0026  * shall be available in all contacts of the address book. Their description
0027  * is stored by CustomFieldManager in $HOME/.kde/share/config/akonadi_contactrc.
0028  * All other custom fields belong to the external scope, they come with import
0029  * of contacts from other PIM applications (e.g. further X- entries in vCards).
0030  * Their description is created on the fly when editing the custom fields.
0031  *
0032  * The description of a custom field covers the key, title and type.
0033  */
0034 class AKONADI_CONTACT_WIDGETS_EXPORT CustomField
0035 {
0036 public:
0037     using List = QList<CustomField>;
0038 
0039     enum Type { TextType, NumericType, BooleanType, DateType, TimeType, DateTimeType, UrlType };
0040 
0041     enum Scope {
0042         LocalScope, ///< Field has been defined by user for one contact
0043         GlobalScope, ///< Field has been defined by user for all contacts
0044         ExternalScope ///< Field has been defined by the external data source (e.g. vCard)
0045     };
0046 
0047     CustomField();
0048     CustomField(const QString &key, const QString &title, Type type, Scope scope);
0049 
0050     static CustomField fromVariantMap(const QVariantMap &map, Scope scope);
0051 
0052     void setKey(const QString &key);
0053     QString key() const;
0054 
0055     void setTitle(const QString &title);
0056     QString title() const;
0057 
0058     void setType(Type type);
0059     Type type() const;
0060 
0061     void setScope(Scope scope);
0062     Scope scope() const;
0063 
0064     void setValue(const QString &value);
0065     QString value() const;
0066 
0067     QVariantMap toVariantMap() const;
0068 
0069     static QString typeToString(Type type);
0070     static Type stringToType(const QString &type);
0071 
0072 private:
0073     QString mKey;
0074     QString mTitle;
0075     Type mType;
0076     Scope mScope;
0077     QString mValue;
0078 };