kmail Library API Documentation

identitycombo.cpp

00001 /* -*- c++ -*- 00002 identitycombo.cpp 00003 00004 This file is part of KMail, the KDE mail client. 00005 Copyright (c) 2002 Marc Mutz <mutz@kde.org> 00006 00007 KMail is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License, version 2, as 00009 published by the Free Software Foundation. 00010 00011 KMail is distributed in the hope that it will be useful, but 00012 WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 In addition, as a special exception, the copyright holders give 00021 permission to link the code of this program with any edition of 00022 the Qt library by Trolltech AS, Norway (or with modified versions 00023 of Qt that use the same license as Qt), and distribute linked 00024 combinations including the two. You must obey the GNU General 00025 Public License in all respects for all of the code used other than 00026 Qt. If you modify this file, you may extend this exception to 00027 your version of the file, but you are not obligated to do so. If 00028 you do not wish to do so, delete this exception statement from 00029 your version. 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 ); // just in case Qt gets fixed to emit activated() here 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 ); // just in case Qt gets fixed to emit activated() here 00087 setCurrentItem( idx ); 00088 blockSignals( false ); 00089 00090 slotEmitChanged( idx ); 00091 } 00092 00093 void IdentityCombo::reloadCombo() { 00094 QStringList identities = kmkernel->identityManager()->identities(); 00095 // the IM should prevent this from happening: 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 // apparently our oldIdentity got deleted: 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"
KDE Logo
This file is part of the documentation for kmail Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:57:58 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003