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( manager, SIGNAL( changed() ),
00057 SLOT( slotIdentityManagerChanged() ) );
00058 }
00059
00060 IdentityCombo::~IdentityCombo()
00061 {
00062 delete d;
00063 }
00064
00065 QString IdentityCombo::currentIdentityName() const
00066 {
00067 return mIdentityManager->identities()[ currentIndex()];
00068 }
00069
00070 uint IdentityCombo::currentIdentity() const
00071 {
00072 return mUoidList[ currentIndex()];
00073 }
00074
00075 void IdentityCombo::setCurrentIdentity( const Identity &identity )
00076 {
00077 setCurrentIdentity( identity.uoid() );
00078 }
00079
00080 void IdentityCombo::setCurrentIdentity( const QString &name )
00081 {
00082 int idx = mIdentityManager->identities().indexOf( name );
00083 if ( ( idx < 0 ) || ( idx == currentIndex() ) ) {
00084 return;
00085 }
00086
00087 blockSignals( true );
00088 setCurrentIndex( idx );
00089 blockSignals( false );
00090
00091 slotEmitChanged( idx );
00092 }
00093
00094 void IdentityCombo::setCurrentIdentity( uint uoid )
00095 {
00096 int idx = mUoidList.indexOf( uoid );
00097 if ( ( idx < 0 ) || ( idx == currentIndex() ) ) {
00098 return;
00099 }
00100
00101 blockSignals( true );
00102 setCurrentIndex( idx );
00103 blockSignals( false );
00104
00105 slotEmitChanged( idx );
00106 }
00107
00108 void IdentityCombo::reloadCombo()
00109 {
00110 QStringList identities = mIdentityManager->identities();
00111
00112 assert( !identities.isEmpty() );
00113 clear();
00114 addItems( identities );
00115 }
00116
00117 void IdentityCombo::reloadUoidList()
00118 {
00119 mUoidList.clear();
00120 IdentityManager::ConstIterator it;
00121 for ( it = mIdentityManager->begin(); it != mIdentityManager->end(); ++it ) {
00122 mUoidList << ( *it ).uoid();
00123 }
00124 }
00125
00126 void IdentityCombo::slotIdentityManagerChanged()
00127 {
00128 uint oldIdentity = mUoidList[ currentIndex()];
00129
00130 reloadUoidList();
00131 int idx = mUoidList.indexOf( oldIdentity );
00132
00133 blockSignals( true );
00134 reloadCombo();
00135 setCurrentIndex( idx < 0 ? 0 : idx );
00136 blockSignals( false );
00137
00138 if ( idx < 0 ) {
00139
00140 slotEmitChanged( currentIndex() );
00141 }
00142 }
00143
00144 void IdentityCombo::slotEmitChanged( int idx )
00145 {
00146 emit identityChanged( mUoidList[idx] );
00147 }
00148
00149 #include "identitycombo.moc"