File indexing completed on 2024-04-28 03:53:33
0001 /* 0002 This file is part of the KContacts framework. 0003 SPDX-FileCopyrightText: 2003 Tobias Koenig <tokoe@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "vcardline_p.h" 0009 0010 #include "parametermap_p.h" 0011 0012 using namespace KContacts; 0013 0014 VCardLine::VCardLine() 0015 { 0016 } 0017 0018 VCardLine::VCardLine(const QString &identifier) 0019 : VCardLine(identifier, {}) 0020 { 0021 } 0022 0023 VCardLine::VCardLine(const QString &identifier, const QVariant &value) 0024 : mIdentifier(identifier) 0025 , mValue(value) 0026 { 0027 } 0028 0029 VCardLine::VCardLine(const VCardLine &line) 0030 : mParamMap(line.mParamMap) 0031 , mIdentifier(line.mIdentifier) 0032 , mGroup(line.mGroup) 0033 , mValue(line.mValue) 0034 { 0035 } 0036 0037 VCardLine::~VCardLine() 0038 { 0039 } 0040 0041 VCardLine &VCardLine::operator=(const VCardLine &line) 0042 { 0043 if (&line == this) { 0044 return *this; 0045 } 0046 0047 mParamMap = line.mParamMap; 0048 mValue = line.mValue; 0049 mIdentifier = line.mIdentifier; 0050 mGroup = line.mGroup; 0051 0052 return *this; 0053 } 0054 0055 bool VCardLine::operator==(const VCardLine &other) const 0056 { 0057 // clang-format off 0058 return (mParamMap == other.parameterMap()) 0059 && (mValue == other.value()) 0060 && (mIdentifier == other.identifier()) 0061 && (mGroup == other.group()); 0062 // clang-format on 0063 } 0064 0065 void VCardLine::setIdentifier(const QString &identifier) 0066 { 0067 mIdentifier = identifier; 0068 } 0069 0070 QString VCardLine::identifier() const 0071 { 0072 return mIdentifier; 0073 } 0074 0075 void VCardLine::setValue(const QVariant &value) 0076 { 0077 mValue = value; 0078 } 0079 0080 QVariant VCardLine::value() const 0081 { 0082 return mValue; 0083 } 0084 0085 void VCardLine::setGroup(const QString &group) 0086 { 0087 mGroup = group; 0088 } 0089 0090 QString VCardLine::group() const 0091 { 0092 return mGroup; 0093 } 0094 0095 bool VCardLine::hasGroup() const 0096 { 0097 return !mGroup.isEmpty(); 0098 } 0099 0100 QStringList VCardLine::parameterList() const 0101 { 0102 QStringList list; 0103 list.reserve(mParamMap.size()); 0104 for (const auto &[param, values] : mParamMap) { 0105 list.append(param); 0106 } 0107 0108 return list; 0109 } 0110 0111 void VCardLine::addParameters(const ParameterMap ¶ms) 0112 { 0113 for (const auto &[param, list] : params) { 0114 addParameter(param, list.join(QLatin1Char(','))); 0115 } 0116 } 0117 0118 void VCardLine::addParameter(const QString ¶m, const QString &value) 0119 { 0120 auto it = mParamMap.findParam(param); 0121 if (it != mParamMap.end()) { 0122 if (!it->paramValues.contains(value)) { // not included yet 0123 it->paramValues.push_back(value); 0124 } 0125 } else { 0126 mParamMap.insertParam({param, QStringList{value}}); 0127 } 0128 } 0129 0130 QStringList VCardLine::parameters(const QString ¶m) const 0131 { 0132 auto it = mParamMap.findParam(param); 0133 return it != mParamMap.cend() ? it->paramValues : QStringList{}; 0134 } 0135 0136 QString VCardLine::parameter(const QString ¶m) const 0137 { 0138 auto it = mParamMap.findParam(param); 0139 return it != mParamMap.cend() && !it->paramValues.isEmpty() ? it->paramValues.at(0) : QString{}; 0140 } 0141 0142 ParameterMap VCardLine::parameterMap() const 0143 { 0144 return mParamMap; 0145 }