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 #include "customfieldmanager_p.h"
0010 
0011 #include <KConfig>
0012 #include <KConfigGroup>
0013 
0014 void CustomFieldManager::setGlobalCustomFieldDescriptions(const CustomField::List &customFields)
0015 {
0016     KConfig config(QStringLiteral("akonadi_contactrc"));
0017     KConfigGroup group(&config, QStringLiteral("GlobalCustomFields"));
0018 
0019     group.deleteGroup();
0020     for (const CustomField &field : customFields) {
0021         const QString key = field.key();
0022         const QString value = CustomField::typeToString(field.type()) + QLatin1Char(':') + field.title();
0023 
0024         group.writeEntry(key, value);
0025     }
0026 }
0027 
0028 CustomField::List CustomFieldManager::globalCustomFieldDescriptions()
0029 {
0030     KConfig config(QStringLiteral("akonadi_contactrc"));
0031     const KConfigGroup group(&config, QStringLiteral("GlobalCustomFields"));
0032 
0033     CustomField::List customFields;
0034 
0035     const QStringList keys = group.keyList();
0036     customFields.reserve(keys.count());
0037     for (const QString &key : keys) {
0038         CustomField field;
0039         field.setKey(key);
0040         field.setScope(CustomField::GlobalScope);
0041 
0042         const QString value = group.readEntry(key, QString());
0043         const int pos = value.indexOf(QLatin1Char(':'));
0044         if (pos != -1) {
0045             field.setType(CustomField::stringToType(value.left(pos - 1)));
0046             field.setTitle(value.mid(pos + 1));
0047         }
0048 
0049         customFields << field;
0050     }
0051 
0052     return customFields;
0053 }