Akonadi Contacts

customfieldmanager.cpp
1/*
2 This file is part of Contact Editor.
3
4 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "customfieldmanager_p.h"
10
11#include <KConfig>
12#include <KConfigGroup>
13
14void CustomFieldManager::setGlobalCustomFieldDescriptions(const CustomField::List &customFields)
15{
16 KConfig config(QStringLiteral("akonadi_contactrc"));
17 KConfigGroup group(&config, QStringLiteral("GlobalCustomFields"));
18
19 group.deleteGroup();
20 for (const CustomField &field : customFields) {
21 const QString key = field.key();
22 const QString value = CustomField::typeToString(field.type()) + QLatin1Char(':') + field.title();
23
24 group.writeEntry(key, value);
25 }
26}
27
28CustomField::List CustomFieldManager::globalCustomFieldDescriptions()
29{
30 KConfig config(QStringLiteral("akonadi_contactrc"));
31 const KConfigGroup group(&config, QStringLiteral("GlobalCustomFields"));
32
33 CustomField::List customFields;
34
35 const QStringList keys = group.keyList();
36 customFields.reserve(keys.count());
37 for (const QString &key : keys) {
38 CustomField field;
39 field.setKey(key);
40 field.setScope(CustomField::GlobalScope);
41
42 const QString value = group.readEntry(key, QString());
43 const int pos = value.indexOf(QLatin1Char(':'));
44 if (pos != -1) {
45 field.setType(CustomField::stringToType(value.left(pos - 1)));
46 field.setTitle(value.mid(pos + 1));
47 }
48
49 customFields << field;
50 }
51
52 return customFields;
53}
qsizetype count() const const
void reserve(qsizetype size)
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
QString left(qsizetype n) const const
QString mid(qsizetype position, qsizetype n) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.