KContacts

addresseehelper.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2003 Carsten Pfeiffer <[email protected]>
4 
5  This SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "addresseehelper.h"
9 
10 #include <KConfig>
11 #include <KConfigGroup>
12 #include <KLocalizedString>
13 
14 using namespace KContacts;
15 
16 class Q_DECL_HIDDEN KContacts::AddresseeHelperPrivate
17 {
18 public:
19  QSet<QString> mTitles;
20  QSet<QString> mPrefixes;
21  QSet<QString> mSuffixes;
22  bool mTreatAsFamilyName;
23 };
24 
26 
27 // static
29 {
30  return s_self;
31 }
32 
34  : QObject()
35  , d(new AddresseeHelperPrivate)
36 {
37  initSettings();
38 }
39 
40 AddresseeHelper::~AddresseeHelper()
41 {
42 }
43 
44 static void addToSet(const QStringList &list, QSet<QString> &container)
45 {
46  for (const auto &str : list) {
47  if (!str.isEmpty()) {
48  container.insert(str);
49  }
50  }
51 }
52 
54 {
55  d->mTitles.clear();
56  d->mSuffixes.clear();
57  d->mPrefixes.clear();
58 
59  d->mTitles.insert(i18n("Dr."));
60  d->mTitles.insert(i18n("Miss"));
61  d->mTitles.insert(i18n("Mr."));
62  d->mTitles.insert(i18n("Mrs."));
63  d->mTitles.insert(i18n("Ms."));
64  d->mTitles.insert(i18n("Prof."));
65 
66  d->mSuffixes.insert(i18n("I"));
67  d->mSuffixes.insert(i18n("II"));
68  d->mSuffixes.insert(i18n("III"));
69  d->mSuffixes.insert(i18n("Jr."));
70  d->mSuffixes.insert(i18n("Sr."));
71 
72  d->mPrefixes.insert(QStringLiteral("van"));
73  d->mPrefixes.insert(QStringLiteral("von"));
74  d->mPrefixes.insert(QStringLiteral("de"));
75 
76  KConfig _config(QStringLiteral("kabcrc"), KConfig::NoGlobals);
77  KConfigGroup config(&_config, "General");
78 
79  addToSet(config.readEntry("Prefixes", QStringList()), d->mTitles);
80  addToSet(config.readEntry("Inclusions", QStringList()), d->mPrefixes);
81  addToSet(config.readEntry("Suffixes", QStringList()), d->mSuffixes);
82  d->mTreatAsFamilyName = config.readEntry("TreatAsFamilyName", true);
83 }
84 
85 bool AddresseeHelper::containsTitle(const QString &title) const
86 {
87  return d->mTitles.contains(title);
88 }
89 
90 bool AddresseeHelper::containsPrefix(const QString &prefix) const
91 {
92  return d->mPrefixes.contains(prefix);
93 }
94 
95 bool AddresseeHelper::containsSuffix(const QString &suffix) const
96 {
97  return d->mSuffixes.contains(suffix);
98 }
99 
101 {
102  return d->mTreatAsFamilyName;
103 }
bool containsSuffix(const QString &suffix) const
Queries the list of honoric suffixes.
bool treatAsFamilyName() const
Returns whether or not a single name component should be interpreted as a family name.
Q_GLOBAL_STATIC(Internal::StaticControl, s_instance) class ControlPrivate
This singleton class stores static data, which is shared by all Addressee objects.
void initSettings()
Recreates the static data and reparses the configuration.
QSet::iterator insert(const T &value)
bool containsPrefix(const QString &prefix) const
Queries the list of inclusions.
bool containsTitle(const QString &title) const
Queries the list of honoric prefixes.
QString i18n(const char *text, const TYPE &arg...)
T readEntry(const QString &key, const T &aDefault) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jan 24 2022 22:50:08 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.