File indexing completed on 2024-09-08 03:37:33
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2003 Carsten Pfeiffer <pfeiffer@kde.org> 0004 0005 This SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "addresseehelper_p.h" 0009 0010 #include <KConfig> 0011 #include <KConfigGroup> 0012 #include <KLocalizedString> 0013 0014 using namespace KContacts; 0015 0016 Q_GLOBAL_STATIC(AddresseeHelper, s_self) 0017 0018 // static 0019 AddresseeHelper *AddresseeHelper::self() 0020 { 0021 return s_self; 0022 } 0023 0024 AddresseeHelper::AddresseeHelper() 0025 { 0026 initSettings(); 0027 } 0028 0029 AddresseeHelper::~AddresseeHelper() = default; 0030 0031 static void addToSet(const QStringList &list, QSet<QString> &container) 0032 { 0033 for (const auto &str : list) { 0034 if (!str.isEmpty()) { 0035 container.insert(str); 0036 } 0037 } 0038 } 0039 0040 void AddresseeHelper::initSettings() 0041 { 0042 mTitles.clear(); 0043 mSuffixes.clear(); 0044 mPrefixes.clear(); 0045 0046 mTitles.insert(i18n("Dr.")); 0047 mTitles.insert(i18n("Miss")); 0048 mTitles.insert(i18n("Mr.")); 0049 mTitles.insert(i18n("Mrs.")); 0050 mTitles.insert(i18n("Ms.")); 0051 mTitles.insert(i18n("Prof.")); 0052 0053 mSuffixes.insert(i18n("I")); 0054 mSuffixes.insert(i18n("II")); 0055 mSuffixes.insert(i18n("III")); 0056 mSuffixes.insert(i18n("Jr.")); 0057 mSuffixes.insert(i18n("Sr.")); 0058 0059 mPrefixes.insert(QStringLiteral("van")); 0060 mPrefixes.insert(QStringLiteral("von")); 0061 mPrefixes.insert(QStringLiteral("de")); 0062 0063 KConfig _config(QStringLiteral("kabcrc"), KConfig::NoGlobals); 0064 KConfigGroup config(&_config, QStringLiteral("General")); 0065 0066 addToSet(config.readEntry("Prefixes", QStringList()), mTitles); 0067 addToSet(config.readEntry("Inclusions", QStringList()), mPrefixes); 0068 addToSet(config.readEntry("Suffixes", QStringList()), mSuffixes); 0069 mTreatAsFamilyName = config.readEntry("TreatAsFamilyName", true); 0070 } 0071 0072 bool AddresseeHelper::containsTitle(const QString &title) const 0073 { 0074 return mTitles.contains(title); 0075 } 0076 0077 bool AddresseeHelper::containsPrefix(const QString &prefix) const 0078 { 0079 return mPrefixes.contains(prefix); 0080 } 0081 0082 bool AddresseeHelper::containsSuffix(const QString &suffix) const 0083 { 0084 return mSuffixes.contains(suffix); 0085 } 0086 0087 bool AddresseeHelper::treatAsFamilyName() const 0088 { 0089 return mTreatAsFamilyName; 0090 }