File indexing completed on 2024-11-24 04:50:42
0001 // SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org> 0002 // SPDX-License-Identifier: LGPL-2.0-or-later 0003 0004 #include "contactmetadata.h" 0005 0006 #include "attributes/contactmetadataattribute_p.h" 0007 0008 #include <Akonadi/Item> 0009 0010 using namespace Akonadi; 0011 0012 ContactMetaData::ContactMetaData() = default; 0013 0014 ContactMetaData::~ContactMetaData() = default; 0015 0016 void ContactMetaData::load(const Akonadi::Item &contact) 0017 { 0018 if (!contact.hasAttribute("contactmetadata")) { 0019 return; 0020 } 0021 const auto attribute = contact.attribute<ContactMetaDataAttribute>(); 0022 const QVariantMap metaData = attribute->metaData(); 0023 loadMetaData(metaData); 0024 } 0025 0026 void ContactMetaData::store(Akonadi::Item &contact) 0027 { 0028 auto attribute = contact.attribute<ContactMetaDataAttribute>(Item::AddIfMissing); 0029 0030 attribute->setMetaData(storeMetaData()); 0031 } 0032 0033 void ContactMetaData::loadMetaData(const QVariantMap &metaData) 0034 { 0035 m_displayNameMode = metaData.value(QStringLiteral("DisplayNameMode"), -1).toInt(); 0036 0037 m_customFieldDescriptions = metaData.value(QStringLiteral("CustomFieldDescriptions")).toList(); 0038 } 0039 0040 QVariantMap ContactMetaData::storeMetaData() const 0041 { 0042 QVariantMap metaData; 0043 if (m_displayNameMode != -1) { 0044 metaData.insert(QStringLiteral("DisplayNameMode"), QVariant(m_displayNameMode)); 0045 } 0046 0047 if (m_customFieldDescriptions.isEmpty()) { 0048 metaData.insert(QStringLiteral("CustomFieldDescriptions"), m_customFieldDescriptions); 0049 } 0050 return metaData; 0051 } 0052 0053 void ContactMetaData::setDisplayNameMode(int mode) 0054 { 0055 m_displayNameMode = mode; 0056 } 0057 0058 int ContactMetaData::displayNameMode() const 0059 { 0060 return m_displayNameMode; 0061 } 0062 0063 void ContactMetaData::setCustomFieldDescriptions(const QVariantList &descriptions) 0064 { 0065 m_customFieldDescriptions = descriptions; 0066 } 0067 0068 QVariantList ContactMetaData::customFieldDescriptions() const 0069 { 0070 return m_customFieldDescriptions; 0071 }