00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifdef HAVE_CONFIG_H
00033 #include <config.h>
00034 #endif
00035
00036 #include "identitycombo.h"
00037 #include "identity.h"
00038 #include "identitymanager.h"
00039
00040 #include <klocale.h>
00041
00042 #include <assert.h>
00043
00044 using namespace KPIM;
00045
00046 IdentityCombo::IdentityCombo( IdentityManager* manager, TQWidget * parent, const char * name )
00047 : TQComboBox( false, parent, name ), mIdentityManager( manager )
00048 {
00049 reloadCombo();
00050 reloadUoidList();
00051 connect( this, TQT_SIGNAL(activated(int)), TQT_SLOT(slotEmitChanged(int)) );
00052 connect( manager, TQT_SIGNAL(changed()),
00053 TQT_SLOT(slotIdentityManagerChanged()) );
00054 }
00055
00056 TQString IdentityCombo::currentIdentityName() const {
00057 return mIdentityManager->identities()[ currentItem() ];
00058 }
00059
00060 uint IdentityCombo::currentIdentity() const {
00061 return mUoidList[ currentItem() ];
00062 }
00063
00064 void IdentityCombo::setCurrentIdentity( const Identity & identity ) {
00065 setCurrentIdentity( identity.uoid() );
00066 }
00067
00068 void IdentityCombo::setCurrentIdentity( const TQString & name ) {
00069 int idx = mIdentityManager->identities().findIndex( name );
00070 if ( idx < 0 ) return;
00071 if ( idx == currentItem() ) return;
00072
00073 blockSignals( true );
00074 setCurrentItem( idx );
00075 blockSignals( false );
00076
00077 slotEmitChanged( idx );
00078 }
00079
00080 void IdentityCombo::setCurrentIdentity( uint uoid ) {
00081 int idx = mUoidList.findIndex( uoid );
00082 if ( idx < 0 ) return;
00083 if ( idx == currentItem() ) return;
00084
00085 blockSignals( true );
00086 setCurrentItem( idx );
00087 blockSignals( false );
00088
00089 slotEmitChanged( idx );
00090 }
00091
00092 void IdentityCombo::reloadCombo() {
00093 TQStringList identities = mIdentityManager->identities();
00094
00095 assert( !identities.isEmpty() );
00096 identities.first() = i18n("%1 (Default)").arg( identities.first() );
00097 clear();
00098 insertStringList( identities );
00099 }
00100
00101 void IdentityCombo::reloadUoidList() {
00102 mUoidList.clear();
00103 IdentityManager::ConstIterator it;
00104 for ( it = mIdentityManager->begin() ; it != mIdentityManager->end() ; ++it )
00105 mUoidList << (*it).uoid();
00106 }
00107
00108 void IdentityCombo::slotIdentityManagerChanged() {
00109 uint oldIdentity = mUoidList[ currentItem() ];
00110
00111 reloadUoidList();
00112 int idx = mUoidList.findIndex( oldIdentity );
00113
00114 blockSignals( true );
00115 reloadCombo();
00116 setCurrentItem( idx < 0 ? 0 : idx );
00117 blockSignals( false );
00118
00119 if ( idx < 0 )
00120
00121 slotEmitChanged( currentItem() );
00122 }
00123
00124 void IdentityCombo::slotEmitChanged( int idx ) {
00125 emit identityChanged( mIdentityManager->identities()[idx] );
00126 emit identityChanged( mUoidList[idx] );
00127 }
00128
00129 #include "identitycombo.moc"