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-only
6 */
7 
8 #include "addresseehelper.h"
9 
10 #include <KConfig>
11 #include <KLocalizedString>
12 #include <KConfigGroup>
13 
14 
15 using namespace KContacts;
16 
17 class Q_DECL_HIDDEN KContacts::AddresseeHelperPrivate
18 {
19 public:
20  QSet<QString> mTitles;
21  QSet<QString> mPrefixes;
22  QSet<QString> mSuffixes;
23  bool mTreatAsFamilyName;
24 };
25 
26 Q_GLOBAL_STATIC(AddresseeHelper, s_self)
27 
28 // static
30 {
31  return s_self;
32 }
33 
35  : QObject()
36  , d(new AddresseeHelperPrivate)
37 {
38  initSettings();
39 }
40 
41 AddresseeHelper::~AddresseeHelper()
42 {
43 }
44 
45 static void addToSet(const QStringList &list, QSet<QString> &container)
46 {
48  QStringList::ConstIterator end(list.end());
49  for (it = list.begin(); it != end; ++it) {
50  if (!(*it).isEmpty()) {
51  container.insert(*it);
52  }
53  }
54 }
55 
57 {
58  d->mTitles.clear();
59  d->mSuffixes.clear();
60  d->mPrefixes.clear();
61 
62  d->mTitles.insert(i18n("Dr."));
63  d->mTitles.insert(i18n("Miss"));
64  d->mTitles.insert(i18n("Mr."));
65  d->mTitles.insert(i18n("Mrs."));
66  d->mTitles.insert(i18n("Ms."));
67  d->mTitles.insert(i18n("Prof."));
68 
69  d->mSuffixes.insert(i18n("I"));
70  d->mSuffixes.insert(i18n("II"));
71  d->mSuffixes.insert(i18n("III"));
72  d->mSuffixes.insert(i18n("Jr."));
73  d->mSuffixes.insert(i18n("Sr."));
74 
75  d->mPrefixes.insert(QStringLiteral("van"));
76  d->mPrefixes.insert(QStringLiteral("von"));
77  d->mPrefixes.insert(QStringLiteral("de"));
78 
79  KConfig _config(QStringLiteral("kabcrc"), KConfig::NoGlobals);
80  KConfigGroup config(&_config, "General");
81 
82  addToSet(config.readEntry("Prefixes", QStringList()), d->mTitles);
83  addToSet(config.readEntry("Inclusions", QStringList()), d->mPrefixes);
84  addToSet(config.readEntry("Suffixes", QStringList()), d->mSuffixes);
85  d->mTreatAsFamilyName = config.readEntry("TreatAsFamilyName", true);
86 }
87 
88 bool AddresseeHelper::containsTitle(const QString &title) const
89 {
90  return d->mTitles.contains(title);
91 }
92 
93 bool AddresseeHelper::containsPrefix(const QString &prefix) const
94 {
95  return d->mPrefixes.contains(prefix);
96 }
97 
98 bool AddresseeHelper::containsSuffix(const QString &suffix) const
99 {
100  return d->mSuffixes.contains(suffix);
101 }
102 
104 {
105  return d->mTreatAsFamilyName;
106 }
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-2020 The KDE developers.
Generated on Thu Jul 9 2020 22:54:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.