KContacts

addresseehelper.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2003 Carsten Pfeiffer <pfeiffer@kde.org>
4 
5  This SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "addresseehelper_p.h"
9 
10 #include <KConfig>
11 #include <KConfigGroup>
12 #include <KLocalizedString>
13 
14 using namespace KContacts;
15 
16 Q_GLOBAL_STATIC(AddresseeHelper, s_self)
17 
18 // static
19 AddresseeHelper *AddresseeHelper::self()
20 {
21  return s_self;
22 }
23 
24 AddresseeHelper::AddresseeHelper()
25 {
26  initSettings();
27 }
28 
29 AddresseeHelper::~AddresseeHelper() = default;
30 
31 static void addToSet(const QStringList &list, QSet<QString> &container)
32 {
33  for (const auto &str : list) {
34  if (!str.isEmpty()) {
35  container.insert(str);
36  }
37  }
38 }
39 
40 void AddresseeHelper::initSettings()
41 {
42  mTitles.clear();
43  mSuffixes.clear();
44  mPrefixes.clear();
45 
46  mTitles.insert(i18n("Dr."));
47  mTitles.insert(i18n("Miss"));
48  mTitles.insert(i18n("Mr."));
49  mTitles.insert(i18n("Mrs."));
50  mTitles.insert(i18n("Ms."));
51  mTitles.insert(i18n("Prof."));
52 
53  mSuffixes.insert(i18n("I"));
54  mSuffixes.insert(i18n("II"));
55  mSuffixes.insert(i18n("III"));
56  mSuffixes.insert(i18n("Jr."));
57  mSuffixes.insert(i18n("Sr."));
58 
59  mPrefixes.insert(QStringLiteral("van"));
60  mPrefixes.insert(QStringLiteral("von"));
61  mPrefixes.insert(QStringLiteral("de"));
62 
63  KConfig _config(QStringLiteral("kabcrc"), KConfig::NoGlobals);
64  KConfigGroup config(&_config, QStringLiteral("General"));
65 
66  addToSet(config.readEntry("Prefixes", QStringList()), mTitles);
67  addToSet(config.readEntry("Inclusions", QStringList()), mPrefixes);
68  addToSet(config.readEntry("Suffixes", QStringList()), mSuffixes);
69  mTreatAsFamilyName = config.readEntry("TreatAsFamilyName", true);
70 }
71 
72 bool AddresseeHelper::containsTitle(const QString &title) const
73 {
74  return mTitles.contains(title);
75 }
76 
77 bool AddresseeHelper::containsPrefix(const QString &prefix) const
78 {
79  return mPrefixes.contains(prefix);
80 }
81 
82 bool AddresseeHelper::containsSuffix(const QString &suffix) const
83 {
84  return mSuffixes.contains(suffix);
85 }
86 
87 bool AddresseeHelper::treatAsFamilyName() const
88 {
89  return mTreatAsFamilyName;
90 }
Q_GLOBAL_STATIC(Internal::StaticControl, s_instance) class ControlPrivate
QString i18n(const char *text, const TYPE &arg...)
QSet::iterator insert(const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:50:13 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.