Akonadi Contacts

customfieldmanager.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2010 Tobias Koenig <[email protected]>
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 
14 void 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 
28 CustomField::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 }
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
void reserve(int alloc)
KSharedConfigPtr config()
int count(const T &value) const const
QString mid(int position, int n) const const
QString left(int n) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Jun 17 2021 23:09:02 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.