libkpimidentities

identitycombo.cpp
1/*
2 identitycombo.cpp
3
4 This file is part of KMail, the KDE mail client.
5 Copyright (c) 2002 Marc Mutz <mutz@kde.org>
6
7 KMail is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License, version 2, as
9 published by the Free Software Foundation.
10
11 KMail is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
20 In addition, as a special exception, the copyright holders give
21 permission to link the code of this program with any edition of
22 the TQt library by Trolltech AS, Norway (or with modified versions
23 of TQt that use the same license as TQt), and distribute linked
24 combinations including the two. You must obey the GNU General
25 Public License in all respects for all of the code used other than
26 TQt. If you modify this file, you may extend this exception to
27 your version of the file, but you are not obligated to do so. If
28 you do not wish to do so, delete this exception statement from
29 your version.
30*/
31
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36#include "identitycombo.h"
37#include "identity.h"
38#include "identitymanager.h"
39
40#include <tdelocale.h>
41
42#include <assert.h>
43
44using namespace KPIM;
45
46IdentityCombo::IdentityCombo( IdentityManager* manager, TQWidget * parent, const char * name )
47 : TQComboBox( false, parent, name ), mIdentityManager( manager )
48{
49 reloadCombo();
50 reloadUoidList();
51 connect( this, TQ_SIGNAL(activated(int)), TQ_SLOT(slotEmitChanged(int)) );
52 connect( manager, TQ_SIGNAL(changed()),
53 TQ_SLOT(slotIdentityManagerChanged()) );
54}
55
56TQString IdentityCombo::currentIdentityName() const {
57 return mIdentityManager->identities()[ currentItem() ];
58}
59
60uint IdentityCombo::currentIdentity() const {
61 return mUoidList[ currentItem() ];
62}
63
64void IdentityCombo::setCurrentIdentity( const Identity & identity ) {
65 setCurrentIdentity( identity.uoid() );
66}
67
68void IdentityCombo::setCurrentIdentity( const TQString & name ) {
69 int idx = mIdentityManager->identities().findIndex( name );
70 if ( idx < 0 ) return;
71 if ( idx == currentItem() ) return;
72
73 blockSignals( true ); // just in case TQt gets fixed to emit activated() here
74 setCurrentItem( idx );
75 blockSignals( false );
76
77 slotEmitChanged( idx );
78}
79
80void IdentityCombo::setCurrentIdentity( uint uoid ) {
81 int idx = mUoidList.findIndex( uoid );
82 if ( idx < 0 ) return;
83 if ( idx == currentItem() ) return;
84
85 blockSignals( true ); // just in case TQt gets fixed to emit activated() here
86 setCurrentItem( idx );
87 blockSignals( false );
88
89 slotEmitChanged( idx );
90}
91
92void IdentityCombo::reloadCombo() {
93 TQStringList identities = mIdentityManager->identities();
94 // the IM should prevent this from happening:
95 assert( !identities.isEmpty() );
96 identities.first() = i18n("%1 (Default)").arg( identities.first() );
97 clear();
98 insertStringList( identities );
99}
100
101void IdentityCombo::reloadUoidList() {
102 mUoidList.clear();
103 IdentityManager::ConstIterator it;
104 for ( it = mIdentityManager->begin() ; it != mIdentityManager->end() ; ++it )
105 mUoidList << (*it).uoid();
106}
107
109 uint oldIdentity = mUoidList[ currentItem() ];
110
111 reloadUoidList();
112 int idx = mUoidList.findIndex( oldIdentity );
113
114 blockSignals( true );
115 reloadCombo();
116 setCurrentItem( idx < 0 ? 0 : idx );
117 blockSignals( false );
118
119 if ( idx < 0 )
120 // apparently our oldIdentity got deleted:
121 slotEmitChanged( currentItem() );
122}
123
124void IdentityCombo::slotEmitChanged( int idx ) {
125 emit identityChanged( mIdentityManager->identities()[idx] );
126 emit identityChanged( mUoidList[idx] );
127}
128
129#include "identitycombo.moc"
void identityChanged(const TQString &identityName)
void slotIdentityManagerChanged()
Connected to IdentityManager::changed().
User identity information.
Definition: identity.h:96
uint uoid() const
Unique Object Identifier for this identity.
Definition: identity.h:164