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 
25 Q_GLOBAL_STATIC(AddresseeHelper, s_self)
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 {
47  QStringList::ConstIterator end(list.end());
48  for (it = list.begin(); it != end; ++it) {
49  if (!(*it).isEmpty()) {
50  container.insert(*it);
51  }
52  }
53 }
54 
56 {
57  d->mTitles.clear();
58  d->mSuffixes.clear();
59  d->mPrefixes.clear();
60 
61  d->mTitles.insert(i18n("Dr."));
62  d->mTitles.insert(i18n("Miss"));
63  d->mTitles.insert(i18n("Mr."));
64  d->mTitles.insert(i18n("Mrs."));
65  d->mTitles.insert(i18n("Ms."));
66  d->mTitles.insert(i18n("Prof."));
67 
68  d->mSuffixes.insert(i18n("I"));
69  d->mSuffixes.insert(i18n("II"));
70  d->mSuffixes.insert(i18n("III"));
71  d->mSuffixes.insert(i18n("Jr."));
72  d->mSuffixes.insert(i18n("Sr."));
73 
74  d->mPrefixes.insert(QStringLiteral("van"));
75  d->mPrefixes.insert(QStringLiteral("von"));
76  d->mPrefixes.insert(QStringLiteral("de"));
77 
78  KConfig _config(QStringLiteral("kabcrc"), KConfig::NoGlobals);
79  KConfigGroup config(&_config, "General");
80 
81  addToSet(config.readEntry("Prefixes", QStringList()), d->mTitles);
82  addToSet(config.readEntry("Inclusions", QStringList()), d->mPrefixes);
83  addToSet(config.readEntry("Suffixes", QStringList()), d->mSuffixes);
84  d->mTreatAsFamilyName = config.readEntry("TreatAsFamilyName", true);
85 }
86 
87 bool AddresseeHelper::containsTitle(const QString &title) const
88 {
89  return d->mTitles.contains(title);
90 }
91 
92 bool AddresseeHelper::containsPrefix(const QString &prefix) const
93 {
94  return d->mPrefixes.contains(prefix);
95 }
96 
97 bool AddresseeHelper::containsSuffix(const QString &suffix) const
98 {
99  return d->mSuffixes.contains(suffix);
100 }
101 
103 {
104  return d->mTreatAsFamilyName;
105 }
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.
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.
QList::iterator end()
QString i18n(const char *text, const TYPE &arg...)
typedef ConstIterator
T readEntry(const QString &key, const T &aDefault) const
QList::iterator begin()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jun 12 2021 22:55:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.