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 
15 void CustomFieldManager::setGlobalCustomFieldDescriptions(const CustomField::List &customFields)
16 {
17  KConfig config(QStringLiteral("akonadi_contactrc"));
18  KConfigGroup group(&config, QStringLiteral("GlobalCustomFields"));
19 
20  group.deleteGroup();
21  for (const CustomField &field : customFields) {
22  const QString key = field.key();
23  const QString value = CustomField::typeToString(field.type()) + QLatin1Char(':') + field.title();
24 
25  group.writeEntry(key, value);
26  }
27 }
28 
29 CustomField::List CustomFieldManager::globalCustomFieldDescriptions()
30 {
31  KConfig config(QStringLiteral("akonadi_contactrc"));
32  const KConfigGroup group(&config, QStringLiteral("GlobalCustomFields"));
33 
34  CustomField::List customFields;
35 
36  const QStringList keys = group.keyList();
37  customFields.reserve(keys.count());
38  for (const QString &key : keys) {
39  CustomField field;
40  field.setKey(key);
41  field.setScope(CustomField::GlobalScope);
42 
43  const QString value = group.readEntry(key, QString());
44  const int pos = value.indexOf(QLatin1Char(':'));
45  if (pos != -1) {
46  field.setType(CustomField::stringToType(value.left(pos - 1)));
47  field.setTitle(value.mid(pos + 1));
48  }
49 
50  customFields << field;
51  }
52 
53  return customFields;
54 }
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-2020 The KDE developers.
Generated on Wed Sep 23 2020 23:08:59 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.