addresseehelper.cpp
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
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 
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 
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 ); 
00085   config.setGroup( "General" );
00086 
00087   addToSet( config.readListEntry( "Prefixes" ),   mTitles );
00088   addToSet( config.readListEntry( "Inclusions" ), mPrefixes );
00089   addToSet( config.readListEntry( "Suffixes" ),   mSuffixes );
00090 }
00091 
00092 bool AddresseeHelper::containsTitle( const QString& title ) const
00093 {
00094   return mTitles.find( title ) != mTitles.end();
00095 }
00096 
00097 bool AddresseeHelper::containsPrefix( const QString& prefix ) const
00098 {
00099   return mPrefixes.find( prefix ) != mPrefixes.end();
00100 }
00101 
00102 bool AddresseeHelper::containsSuffix( const QString& suffix ) const
00103 {
00104   return mSuffixes.find( suffix ) != mSuffixes.end();
00105 }
 
This file is part of the documentation for kabc Library Version 3.2.0.