• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

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( 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 );  // just in case Qt gets fixed to emit activated() here
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 );  // just in case Qt gets fixed to emit activated() here
00102   setCurrentIndex( idx );
00103   blockSignals( false );
00104 
00105   slotEmitChanged( idx );
00106 }
00107 
00108 void IdentityCombo::reloadCombo()
00109 {
00110   QStringList identities = mIdentityManager->identities();
00111   // the IM should prevent this from happening:
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     // apparently our oldIdentity got deleted:
00140     slotEmitChanged( currentIndex() );
00141   }
00142 }
00143 
00144 void IdentityCombo::slotEmitChanged( int idx )
00145 {
00146   emit identityChanged( mUoidList[idx] );
00147 }
00148 
00149 #include "identitycombo.moc"

kpimidentities

Skip menu "kpimidentities"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.6
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal