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
14using namespace KContacts;
15
16Q_GLOBAL_STATIC(AddresseeHelper, s_self)
17
18// static
19AddresseeHelper *AddresseeHelper::self()
20{
21 return s_self;
22}
23
24AddresseeHelper::AddresseeHelper()
25{
26 initSettings();
27}
28
29AddresseeHelper::~AddresseeHelper() = default;
30
31static 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
40void 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
72bool AddresseeHelper::containsTitle(const QString &title) const
73{
74 return mTitles.contains(title);
75}
76
77bool AddresseeHelper::containsPrefix(const QString &prefix) const
78{
79 return mPrefixes.contains(prefix);
80}
81
82bool AddresseeHelper::containsSuffix(const QString &suffix) const
83{
84 return mSuffixes.contains(suffix);
85}
86
87bool AddresseeHelper::treatAsFamilyName() const
88{
89 return mTreatAsFamilyName;
90}
QString i18n(const char *text, const TYPE &arg...)
iterator insert(const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 11:58:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.