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 | #include "addresseehelper.h" |
21 | |
22 | #include <kconfig.h> |
23 | #include <klocalizedstring.h> |
24 | #include <kconfiggroup.h> |
25 | |
26 | #include <QApplication> |
27 | #include <QtDBus/QtDBus> |
28 | |
29 | using namespace KABC; |
30 | |
31 | AddresseeHelper *AddresseeHelper::s_self; |
32 | |
33 | // static |
34 | AddresseeHelper *AddresseeHelper::self() |
35 | { |
36 | if ( !s_self ) { |
37 | s_self = new AddresseeHelper(); |
38 | } |
39 | |
40 | return s_self; |
41 | } |
42 | |
43 | AddresseeHelper::AddresseeHelper() |
44 | : QObject( qApp ) |
45 | { |
46 | initSettings(); |
47 | |
48 | QDBusConnection::sessionBus().connect( QString(), QLatin1String( "/KABC" ), |
49 | QLatin1String( "org.kde.kabc.AddressBookConfig" ), |
50 | QLatin1String( "changed" ), |
51 | this, SLOT(initSettings())); |
52 | } |
53 | |
54 | // static |
55 | void AddresseeHelper::addToSet( const QStringList &list, QSet<QString> &container ) |
56 | { |
57 | QStringList::ConstIterator it; |
58 | QStringList::ConstIterator end( list.end() ); |
59 | for ( it = list.begin(); it != end; ++it ) { |
60 | if ( !( *it ).isEmpty() ) { |
61 | container.insert( *it ); |
62 | } |
63 | } |
64 | } |
65 | |
66 | void AddresseeHelper::initSettings() |
67 | { |
68 | mTitles.clear(); |
69 | mSuffixes.clear(); |
70 | mPrefixes.clear(); |
71 | |
72 | mTitles.insert( i18n( "Dr." ) ); |
73 | mTitles.insert( i18n( "Miss" ) ); |
74 | mTitles.insert( i18n( "Mr." ) ); |
75 | mTitles.insert( i18n( "Mrs." ) ); |
76 | mTitles.insert( i18n( "Ms." ) ); |
77 | mTitles.insert( i18n( "Prof." ) ); |
78 | |
79 | mSuffixes.insert( i18n( "I" ) ); |
80 | mSuffixes.insert( i18n( "II" ) ); |
81 | mSuffixes.insert( i18n( "III" ) ); |
82 | mSuffixes.insert( i18n( "Jr." ) ); |
83 | mSuffixes.insert( i18n( "Sr." ) ); |
84 | |
85 | mPrefixes.insert( QLatin1String( "van" ) ); |
86 | mPrefixes.insert( QLatin1String( "von" ) ); |
87 | mPrefixes.insert( QLatin1String( "de" ) ); |
88 | |
89 | KConfig _config( QLatin1String( "kabcrc" ), KConfig::NoGlobals ); |
90 | KConfigGroup config(&_config, "General" ); |
91 | |
92 | addToSet( config.readEntry( "Prefixes" , QStringList() ), mTitles ); |
93 | addToSet( config.readEntry( "Inclusions" , QStringList() ), mPrefixes ); |
94 | addToSet( config.readEntry( "Suffixes" , QStringList() ), mSuffixes ); |
95 | mTradeAsFamilyName = config.readEntry( "TradeAsFamilyName" , true ); |
96 | } |
97 | |
98 | bool AddresseeHelper::containsTitle( const QString &title ) const |
99 | { |
100 | return mTitles.contains( title ); |
101 | } |
102 | |
103 | bool AddresseeHelper::containsPrefix( const QString &prefix ) const |
104 | { |
105 | return mPrefixes.contains( prefix ); |
106 | } |
107 | |
108 | bool AddresseeHelper::containsSuffix( const QString &suffix ) const |
109 | { |
110 | return mSuffixes.contains( suffix ); |
111 | } |
112 | |
113 | bool AddresseeHelper::tradeAsFamilyName() const |
114 | { |
115 | return mTradeAsFamilyName; |
116 | } |
117 | |
118 | |