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
00038
#include "kmidentity.h"
00039
#include "identitymanager.h"
00040
#include "kmkernel.h"
00041
00042
#include <klocale.h>
00043
00044
00045
#include "assert.h"
00046
00047 IdentityCombo::IdentityCombo( QWidget * parent,
const char * name )
00048 : QComboBox( false, parent, name )
00049 {
00050 reloadCombo();
00051 reloadUoidList();
00052 connect(
this, SIGNAL(activated(
int)), SLOT(slotEmitChanged(
int)) );
00053 connect( kmkernel->identityManager(), SIGNAL(changed()),
00054 SLOT(slotIdentityManagerChanged()) );
00055 }
00056
00057 QString IdentityCombo::currentIdentityName()
const {
00058
return kmkernel->identityManager()->identities()[ currentItem() ];
00059 }
00060
00061 uint IdentityCombo::currentIdentity()
const {
00062
return mUoidList[ currentItem() ];
00063 }
00064
00065
void IdentityCombo::setCurrentIdentity(
const KMIdentity & identity ) {
00066 setCurrentIdentity( identity.
uoid() );
00067 }
00068
00069
void IdentityCombo::setCurrentIdentity(
const QString & name ) {
00070
int idx = kmkernel->identityManager()->identities().findIndex( name );
00071
if ( idx < 0 )
return;
00072
if ( idx == currentItem() )
return;
00073
00074 blockSignals(
true );
00075 setCurrentItem( idx );
00076 blockSignals(
false );
00077
00078 slotEmitChanged( idx );
00079 }
00080
00081
void IdentityCombo::setCurrentIdentity( uint uoid ) {
00082
int idx = mUoidList.findIndex( uoid );
00083
if ( idx < 0 )
return;
00084
if ( idx == currentItem() )
return;
00085
00086 blockSignals(
true );
00087 setCurrentItem( idx );
00088 blockSignals(
false );
00089
00090 slotEmitChanged( idx );
00091 }
00092
00093
void IdentityCombo::reloadCombo() {
00094 QStringList identities = kmkernel->identityManager()->identities();
00095
00096 assert( !identities.isEmpty() );
00097 identities.first() = i18n(
"%1 (Default)").arg( identities.first() );
00098 clear();
00099 insertStringList( identities );
00100 }
00101
00102
void IdentityCombo::reloadUoidList() {
00103
const IdentityManager * im = kmkernel->identityManager();
00104 mUoidList.clear();
00105
for ( IdentityManager::ConstIterator it = im->
begin() ; it != im->
end() ; ++it )
00106 mUoidList << (*it).uoid();
00107 }
00108
00109 void IdentityCombo::slotIdentityManagerChanged() {
00110 uint oldIdentity = mUoidList[ currentItem() ];
00111
00112 reloadUoidList();
00113
int idx = mUoidList.findIndex( oldIdentity );
00114
00115 blockSignals(
true );
00116 reloadCombo();
00117 setCurrentItem( idx < 0 ? 0 : idx );
00118 blockSignals(
false );
00119
00120
if ( idx < 0 )
00121
00122 slotEmitChanged( currentItem() );
00123 }
00124
00125
void IdentityCombo::slotEmitChanged(
int idx ) {
00126 emit identityChanged( kmkernel->identityManager()->identities()[idx] );
00127 emit identityChanged( mUoidList[idx] );
00128 }
00129
00130
#include "identitycombo.moc"