File indexing completed on 2024-04-28 03:53:35

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 #ifndef KCONTACTS_ADDRESSEEHELPER_P_H
0009 #define KCONTACTS_ADDRESSEEHELPER_P_H
0010 
0011 #include "kcontacts_export.h"
0012 
0013 #include <QSet>
0014 
0015 namespace KContacts
0016 {
0017 
0018 // TODO KF6: unexport and turn into an implementation detail
0019 // this is unused externally, both as code as well as via the config file
0020 // so we only need this internally and can probably also drop the config
0021 // file access
0022 
0023 /**
0024  * This singleton class stores static data, which is shared
0025  * by all Addressee objects. It maintains three lists of
0026  * strings, which can be queried using this class:
0027  *
0028  * - a list of honoric prefixes, like "Mrs.", "Prof." etc,
0029  *   see containsTitle()
0030  * - a list of inclusions, such as "van" or "de", see
0031  *   containsPrefix()
0032  * - a list of honoric suffixes, such as "I" or "Jr.", see
0033  *   containsSuffix()
0034  *
0035  * All of these lists have a hardcoded and a configurable
0036  * part. The configurable part is found in @c kabcrc, group
0037  * @c General, fields @c Prefixes, @c Inclusions, and
0038  * @c Suffixes.
0039  *
0040  * In addition to the above, this class stores one conveniece
0041  * setting: it stores whether or not a single name component
0042  * should be interpreted as a family name (see
0043  * treatAsFamilyName()). The corresponding configuration
0044  * field is @c TreatAsFamilyName.
0045  */
0046 class AddresseeHelper
0047 {
0048 public:
0049     /**
0050      * Singleton interface to this class
0051      *
0052      * @return a pointer to the unique instance of this class.
0053      */
0054     static AddresseeHelper *self();
0055 
0056     /**
0057      * Queries the list of honoric prefixes.
0058      *
0059      * @param title the honoric prefix to search for
0060      * @return @c true, if @p title was found in the list,
0061      *         @c false otherwise
0062      */
0063     Q_REQUIRED_RESULT bool containsTitle(const QString &title) const;
0064 
0065     /**
0066      * Queries the list of inclusions.
0067      *
0068      * @param prefix the inclusion to search for
0069      * @return @c true, if @p prefix was found in the list,
0070      *         @c false otherwise
0071      */
0072     Q_REQUIRED_RESULT bool containsPrefix(const QString &prefix) const;
0073 
0074     /**
0075      * Queries the list of honoric suffixes.
0076      *
0077      * @param suffix the honoric suffix to search for
0078      * @return @c true, if @p suffix was found in the list,
0079      *         @c false otherwise
0080      */
0081     Q_REQUIRED_RESULT bool containsSuffix(const QString &suffix) const;
0082 
0083     /**
0084      * Returns whether or not a single name component should
0085      * be interpreted as a family name.
0086      *
0087      * @return @c true if single name component is a family name,
0088      *         @c false otherwise.
0089      */
0090     Q_REQUIRED_RESULT bool treatAsFamilyName() const;
0091 
0092     /** @internal */
0093     AddresseeHelper();
0094 
0095     ~AddresseeHelper();
0096 
0097 private:
0098     /**
0099      * Recreates the static data and reparses the configuration.
0100      */
0101     void initSettings();
0102 
0103     QSet<QString> mTitles;
0104     QSet<QString> mPrefixes;
0105     QSet<QString> mSuffixes;
0106     bool mTreatAsFamilyName;
0107 };
0108 }
0109 
0110 #endif