| 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(value: 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(list: config.readEntry(key: "Prefixes" , aDefault: QStringList()), container&: mTitles); |
| 67 | addToSet(list: config.readEntry(key: "Inclusions" , aDefault: QStringList()), container&: mPrefixes); |
| 68 | addToSet(list: config.readEntry(key: "Suffixes" , aDefault: QStringList()), container&: mSuffixes); |
| 69 | mTreatAsFamilyName = config.readEntry(key: "TreatAsFamilyName" , defaultValue: true); |
| 70 | } |
| 71 | |
| 72 | bool AddresseeHelper::containsTitle(const QString &title) const |
| 73 | { |
| 74 | return mTitles.contains(value: title); |
| 75 | } |
| 76 | |
| 77 | bool AddresseeHelper::containsPrefix(const QString &prefix) const |
| 78 | { |
| 79 | return mPrefixes.contains(value: prefix); |
| 80 | } |
| 81 | |
| 82 | bool AddresseeHelper::containsSuffix(const QString &suffix) const |
| 83 | { |
| 84 | return mSuffixes.contains(value: suffix); |
| 85 | } |
| 86 | |
| 87 | bool AddresseeHelper::treatAsFamilyName() const |
| 88 | { |
| 89 | return mTreatAsFamilyName; |
| 90 | } |
| 91 | |