kpimidentities
identitycombo.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00030 #include "identitycombo.h"
00031 #include "identity.h"
00032 #include "identitymanager.h"
00033
00034 #include <klocale.h>
00035
00036 #include <assert.h>
00037
00038 using namespace KPIMIdentities;
00039
00044
00045 class KPIMIdentities::IdentityCombo::Private
00046 {
00047 };
00048
00049
00050 IdentityCombo::IdentityCombo( IdentityManager *manager, QWidget *parent )
00051 : QComboBox( parent ), mIdentityManager( manager ), d( 0 )
00052 {
00053 reloadCombo();
00054 reloadUoidList();
00055 connect( this, SIGNAL( activated( int ) ), SLOT( slotEmitChanged( int ) ) );
00056 connect( this, SIGNAL(identityChanged( uint ) ), this, SLOT(slotUpdateTooltip( uint ) ) );
00057 connect( manager, SIGNAL( changed() ),
00058 SLOT( slotIdentityManagerChanged() ) );
00059 slotUpdateTooltip( currentIdentity() );
00060 }
00061
00062 IdentityCombo::~IdentityCombo()
00063 {
00064 delete d;
00065 }
00066
00067 QString IdentityCombo::currentIdentityName() const
00068 {
00069 return mIdentityManager->identities()[ currentIndex()];
00070 }
00071
00072 uint IdentityCombo::currentIdentity() const
00073 {
00074 return mUoidList[ currentIndex()];
00075 }
00076
00077 void IdentityCombo::setCurrentIdentity( const Identity &identity )
00078 {
00079 setCurrentIdentity( identity.uoid() );
00080 }
00081
00082 void IdentityCombo::setCurrentIdentity( const QString &name )
00083 {
00084 int idx = mIdentityManager->identities().indexOf( name );
00085 if ( ( idx < 0 ) || ( idx == currentIndex() ) ) {
00086 return;
00087 }
00088
00089 blockSignals( true );
00090 setCurrentIndex( idx );
00091 blockSignals( false );
00092
00093 slotEmitChanged( idx );
00094 }
00095
00096 void IdentityCombo::setCurrentIdentity( uint uoid )
00097 {
00098 int idx = mUoidList.indexOf( uoid );
00099 if ( ( idx < 0 ) || ( idx == currentIndex() ) ) {
00100 return;
00101 }
00102
00103 blockSignals( true );
00104 setCurrentIndex( idx );
00105 blockSignals( false );
00106
00107 slotEmitChanged( idx );
00108 }
00109
00110 void IdentityCombo::reloadCombo()
00111 {
00112 QStringList identities = mIdentityManager->identities();
00113
00114 assert( !identities.isEmpty() );
00115 clear();
00116 addItems( identities );
00117 }
00118
00119 void IdentityCombo::reloadUoidList()
00120 {
00121 mUoidList.clear();
00122 IdentityManager::ConstIterator it;
00123 for ( it = mIdentityManager->begin(); it != mIdentityManager->end(); ++it ) {
00124 mUoidList << ( *it ).uoid();
00125 }
00126 }
00127
00128 void IdentityCombo::slotIdentityManagerChanged()
00129 {
00130 uint oldIdentity = mUoidList[ currentIndex()];
00131
00132 reloadUoidList();
00133 int idx = mUoidList.indexOf( oldIdentity );
00134
00135 blockSignals( true );
00136 reloadCombo();
00137 setCurrentIndex( idx < 0 ? 0 : idx );
00138 blockSignals( false );
00139
00140 slotUpdateTooltip( currentIdentity() );
00141
00142 if ( idx < 0 ) {
00143
00144 slotEmitChanged( currentIndex() );
00145 }
00146 }
00147
00148 void IdentityCombo::slotEmitChanged( int idx )
00149 {
00150 emit identityChanged( mUoidList[idx] );
00151 }
00152
00153 void IdentityCombo::slotUpdateTooltip( uint uoid )
00154 {
00155 setToolTip( mIdentityManager->identityForUoid( uoid ).fullEmailAddr() );
00156 }
00157
00158 #include "identitycombo.moc"