addresseehelper.cpp

00001 /*
00002     This file is part of the KDE libraries
00003     Copyright (C) 2003 Carsten Pfeiffer <pfeiffer@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation, version 2.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <qapplication.h>
00021 
00022 #include <kconfig.h>
00023 #include <klocale.h>
00024 
00025 #include "addresseehelper.h"
00026 
00027 using namespace KABC;
00028 
00029 AddresseeHelper * AddresseeHelper::s_self;
00030 
00031 // static
00032 AddresseeHelper *AddresseeHelper::self()
00033 {
00034   if ( !s_self )
00035     s_self = new AddresseeHelper();
00036 
00037   return s_self;
00038 }
00039 
00040 AddresseeHelper::AddresseeHelper()
00041   : QObject( qApp ),
00042     DCOPObject( "KABC::AddresseeHelper" )
00043 {
00044   initSettings();
00045 
00046   connectDCOPSignal( "kaddressbook", "KABC::AddressBookConfig",
00047                      "changed()", "initSettings()", false );
00048 }
00049 
00050 // static
00051 void AddresseeHelper::addToSet( const QStringList& list,
00052                                 std::set<QString>& container )
00053 {
00054   QStringList::ConstIterator it;
00055   for ( it = list.begin(); it != list.end(); ++it ) {
00056     if ( !(*it).isEmpty() )
00057       container.insert( *it );
00058   }
00059 }
00060 
00061 void AddresseeHelper::initSettings()
00062 {
00063   mTitles.clear();
00064   mSuffixes.clear();
00065   mPrefixes.clear();
00066 
00067   mTitles.insert( i18n( "Dr." ) );
00068   mTitles.insert( i18n( "Miss" ) );
00069   mTitles.insert( i18n( "Mr." ) );
00070   mTitles.insert( i18n( "Mrs." ) );
00071   mTitles.insert( i18n( "Ms." ) );
00072   mTitles.insert( i18n( "Prof." ) );
00073 
00074   mSuffixes.insert( i18n( "I" ) );
00075   mSuffixes.insert( i18n( "II" ) );
00076   mSuffixes.insert( i18n( "III" ) );
00077   mSuffixes.insert( i18n( "Jr." ) );
00078   mSuffixes.insert( i18n( "Sr." ) );
00079 
00080   mPrefixes.insert( "van" );
00081   mPrefixes.insert( "von" );
00082   mPrefixes.insert( "de" );
00083 
00084   KConfig config( "kabcrc", true, false ); // readonly, no kdeglobals
00085   config.setGroup( "General" );
00086 
00087   addToSet( config.readListEntry( "Prefixes" ),   mTitles );
00088   addToSet( config.readListEntry( "Inclusions" ), mPrefixes );
00089   addToSet( config.readListEntry( "Suffixes" ),   mSuffixes );
00090   mTradeAsFamilyName = config.readBoolEntry( "TradeAsFamilyName", true );
00091 }
00092 
00093 bool AddresseeHelper::containsTitle( const QString& title ) const
00094 {
00095   return mTitles.find( title ) != mTitles.end();
00096 }
00097 
00098 bool AddresseeHelper::containsPrefix( const QString& prefix ) const
00099 {
00100   return mPrefixes.find( prefix ) != mPrefixes.end();
00101 }
00102 
00103 bool AddresseeHelper::containsSuffix( const QString& suffix ) const
00104 {
00105   return mSuffixes.find( suffix ) != mSuffixes.end();
00106 }
00107 
00108 bool AddresseeHelper::tradeAsFamilyName() const
00109 {
00110   return mTradeAsFamilyName;
00111 }
KDE Home | KDE Accessibility Home | Description of Access Keys