kpimidentities
identitycombo.cpp
Go to the documentation of this file.
00001 /* 00002 Copyright (c) 2002 Marc Mutz <mutz@kde.org> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 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 //@cond PRIVATE 00045 class KPIMIdentities::IdentityCombo::Private 00046 { 00047 }; 00048 //@endcond 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 ); // just in case Qt gets fixed to emit activated() here 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 ); // just in case Qt gets fixed to emit activated() here 00104 setCurrentIndex( idx ); 00105 blockSignals( false ); 00106 00107 slotEmitChanged( idx ); 00108 } 00109 00110 void IdentityCombo::reloadCombo() 00111 { 00112 QStringList identities = mIdentityManager->identities(); 00113 // the IM should prevent this from happening: 00114 assert( !identities.isEmpty() ); 00115 clear(); 00116 addItems( identities ); 00117 } 00118 00119 void IdentityCombo::reloadUoidList() 00120 { 00121 mUoidList.clear(); 00122 IdentityManager::ConstIterator it; 00123 IdentityManager::ConstIterator end( mIdentityManager->end() ); 00124 for ( it = mIdentityManager->begin(); it != end; ++it ) { 00125 mUoidList << ( *it ).uoid(); 00126 } 00127 } 00128 00129 void IdentityCombo::slotIdentityManagerChanged() 00130 { 00131 uint oldIdentity = mUoidList[ currentIndex()]; 00132 00133 reloadUoidList(); 00134 int idx = mUoidList.indexOf( oldIdentity ); 00135 00136 blockSignals( true ); 00137 reloadCombo(); 00138 setCurrentIndex( idx < 0 ? 0 : idx ); 00139 blockSignals( false ); 00140 00141 slotUpdateTooltip( currentIdentity() ); 00142 00143 if ( idx < 0 ) { 00144 // apparently our oldIdentity got deleted: 00145 slotEmitChanged( currentIndex() ); 00146 } 00147 } 00148 00149 void IdentityCombo::slotEmitChanged( int idx ) 00150 { 00151 emit identityChanged( mUoidList[idx] ); 00152 } 00153 00154 void IdentityCombo::slotUpdateTooltip( uint uoid ) 00155 { 00156 setToolTip( mIdentityManager->identityForUoid( uoid ).fullEmailAddr() ); 00157 } 00158 00159 IdentityManager* IdentityCombo::identityManager() const 00160 { 00161 return mIdentityManager; 00162 } 00163 00164 00165 #include "identitycombo.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:20:45 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:20:45 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.