1/*
2 This file is part of the KDE libraries
3 Copyright (C) 2003 Carsten Pfeiffer <pfeiffer@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation, version 2.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KABC_ADDRESSEEHELPER_H
21#define KABC_ADDRESSEEHELPER_H
22
23#include "kabc_export.h"
24
25#include <QtCore/QObject>
26#include <QtCore/QStringList>
27#include <QtCore/QSet>
28
29namespace KABC {
30
31/**
32 * This singleton class stores static data, which is shared
33 * by all Addressee objects. It maintains three lists of
34 * strings, which can be queried using this class:
35 *
36 * - a list of honoric prefixes, like "Mrs.", "Prof." etc,
37 * see containsTitle()
38 * - a list of inclusions, such as "van" or "de", see
39 * containsPrefix()
40 * - a list of honoric suffixes, such as "I" or "Jr.", see
41 * containsSuffix()
42 *
43 * All of these lists have a hardcoded and a configurable
44 * part. The configurable part is found in @c kabcrc, group
45 * @c General, fields @c Prefixes, @c Inclusions, and
46 * @c Suffixes.
47 *
48 * In addition to the above, this class stores one conveniece
49 * setting: it stores whether or not a single name component
50 * should be interpreted as a family name (see
51 * tradeAsFamilyName()). The corresponding configuration
52 * field is @c TradeAsFamilyName.
53 */
54class KABC_EXPORT AddresseeHelper : public QObject
55{
56 Q_OBJECT
57
58 public:
59 /**
60 * Singleton interface to this class
61 *
62 * @return a pointer to the unique instance of this class.
63 */
64 static AddresseeHelper *self();
65
66 /**
67 * Queries the list of honoric prefixes.
68 *
69 * @param title the honoric prefix to search for
70 * @return @c true, if @p title was found in the list,
71 * @c false otherwise
72 */
73 bool containsTitle( const QString &title ) const;
74
75 /**
76 * Queries the list of inclusions.
77 *
78 * @param prefix the inclusion to search for
79 * @return @c true, if @p prefix was found in the list,
80 * @c false otherwise
81 */
82 bool containsPrefix( const QString &prefix ) const;
83
84 /**
85 * Queries the list of honoric suffixes.
86 *
87 * @param suffix the honoric suffix to search for
88 * @return @c true, if @p suffix was found in the list,
89 * @c false otherwise
90 */
91 bool containsSuffix( const QString &suffix ) const;
92
93 /**
94 * Returns whether or not a single name component should
95 * be interpreted as a family name.
96 *
97 * @return @c true if single name component is a family name,
98 * @c false otherwise.
99 */
100 bool tradeAsFamilyName() const;
101
102 public Q_SLOTS:
103 /**
104 * Recreates the static data and reparses the configuration.
105 */
106 void initSettings();
107
108 private:
109 AddresseeHelper();
110
111 static void addToSet( const QStringList &list, QSet<QString> &container );
112 QSet<QString> mTitles;
113 QSet<QString> mPrefixes;
114 QSet<QString> mSuffixes;
115 bool mTradeAsFamilyName;
116
117 static AddresseeHelper *s_self;
118};
119
120}
121
122#endif
123