• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • KDE Home
  • 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( 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   for ( it = mIdentityManager->begin(); it != mIdentityManager->end(); ++it ) {
00124     mUoidList << ( *it ).uoid();
00125   }
00126 }
00127 
00128 void IdentityCombo::slotIdentityManagerChanged()
00129 {
00130   uint oldIdentity = mUoidList[ currentIndex()];
00131 
00132   reloadUoidList();
00133   int idx = mUoidList.indexOf( oldIdentity );
00134 
00135   blockSignals( true );
00136   reloadCombo();
00137   setCurrentIndex( idx < 0 ? 0 : idx );
00138   blockSignals( false );
00139 
00140   slotUpdateTooltip( currentIdentity() );
00141 
00142   if ( idx < 0 ) {
00143     // apparently our oldIdentity got deleted:
00144     slotEmitChanged( currentIndex() );
00145   }
00146 }
00147 
00148 void IdentityCombo::slotEmitChanged( int idx )
00149 {
00150   emit identityChanged( mUoidList[idx] );
00151 }
00152 
00153 void IdentityCombo::slotUpdateTooltip( uint uoid )
00154 {
00155   setToolTip( mIdentityManager->identityForUoid( uoid ).fullEmailAddr() );
00156 }
00157 
00158 IdentityManager* IdentityCombo::identityManager() const
00159 {
00160   return mIdentityManager;
00161 }
00162 
00163 
00164 #include "identitycombo.moc"

kpimidentities

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.4
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