• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

kpimidentities

  • kpimidentities
identitycombo.cpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2002 Marc Mutz <mutz@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
30#include "identitycombo.h"
31#include "identity.h"
32#include "identitymanager.h"
33
34#include <klocalizedstring.h>
35
36#include <assert.h>
37
38using namespace KPIMIdentities;
39
44//@cond PRIVATE
45class KPIMIdentities::IdentityCombo::Private
46{
47};
48//@endcond
49
50IdentityCombo::IdentityCombo( IdentityManager *manager, QWidget *parent )
51 : QComboBox( parent ), mIdentityManager( manager ), d( 0 )
52{
53 reloadCombo();
54 reloadUoidList();
55 connect( this, SIGNAL(activated(int)), SLOT(slotEmitChanged(int)) );
56 connect( this, SIGNAL(identityChanged(uint)), this, SLOT(slotUpdateTooltip(uint)) );
57 connect( manager, SIGNAL(changed()),
58 SLOT(slotIdentityManagerChanged()) );
59 slotUpdateTooltip( currentIdentity() );
60}
61
62IdentityCombo::~IdentityCombo()
63{
64 delete d;
65}
66
67QString IdentityCombo::currentIdentityName() const
68{
69 return mIdentityManager->identities()[ currentIndex()];
70}
71
72uint IdentityCombo::currentIdentity() const
73{
74 return mUoidList[ currentIndex()];
75}
76
77void IdentityCombo::setCurrentIdentity( const Identity &identity )
78{
79 setCurrentIdentity( identity.uoid() );
80}
81
82void IdentityCombo::setCurrentIdentity( const QString &name )
83{
84 int idx = mIdentityManager->identities().indexOf( name );
85 if ( ( idx < 0 ) || ( idx == currentIndex() ) ) {
86 return;
87 }
88
89 blockSignals( true ); // just in case Qt gets fixed to emit activated() here
90 setCurrentIndex( idx );
91 blockSignals( false );
92
93 slotEmitChanged( idx );
94}
95
96void IdentityCombo::setCurrentIdentity( uint uoid )
97{
98 int idx = mUoidList.indexOf( uoid );
99 if ( ( idx < 0 ) || ( idx == currentIndex() ) ) {
100 return;
101 }
102
103 blockSignals( true ); // just in case Qt gets fixed to emit activated() here
104 setCurrentIndex( idx );
105 blockSignals( false );
106
107 slotEmitChanged( idx );
108}
109
110void IdentityCombo::reloadCombo()
111{
112 QStringList identities = mIdentityManager->identities();
113 // the IM should prevent this from happening:
114 assert( !identities.isEmpty() );
115 clear();
116 addItems( identities );
117}
118
119void IdentityCombo::reloadUoidList()
120{
121 mUoidList.clear();
122 IdentityManager::ConstIterator it;
123 IdentityManager::ConstIterator end( mIdentityManager->end() );
124 for ( it = mIdentityManager->begin(); it != end; ++it ) {
125 mUoidList << ( *it ).uoid();
126 }
127}
128
129void IdentityCombo::slotIdentityManagerChanged()
130{
131 uint oldIdentity = mUoidList[ currentIndex()];
132
133 reloadUoidList();
134 int idx = mUoidList.indexOf( oldIdentity );
135
136 blockSignals( true );
137 reloadCombo();
138 setCurrentIndex( idx < 0 ? 0 : idx );
139 blockSignals( false );
140
141 slotUpdateTooltip( currentIdentity() );
142
143 if ( idx < 0 ) {
144 // apparently our oldIdentity got deleted:
145 slotEmitChanged( currentIndex() );
146 }
147}
148
149void IdentityCombo::slotEmitChanged( int idx )
150{
151 emit identityChanged( mUoidList[idx] );
152}
153
154void IdentityCombo::slotUpdateTooltip( uint uoid )
155{
156 setToolTip( mIdentityManager->identityForUoid( uoid ).fullEmailAddr() );
157}
158
159IdentityManager* IdentityCombo::identityManager() const
160{
161 return mIdentityManager;
162}
163
164
KPIMIdentities::IdentityManager
Manages the list of identities.
Definition: identitymanager.h:40
KPIMIdentities::Identity
User identity information.
Definition: identity.h:84
KPIMIdentities::Identity::uoid
uint uoid() const
Unique Object Identifier for this identity.
Definition: identity.cpp:334
identitycombo.h
This file is part of the API for handling user identities and defines the IdentityCombo class.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kpimidentities

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

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal