• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knode

  • sources
  • kde-4.12
  • kdepim
  • knode
  • configuration
identity_edition_dialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2009 Olivier Trichet <nive@nivalis.org>
3 
4  Permission to use, copy, modify, and distribute this software
5  and its documentation for any purpose and without fee is hereby
6  granted, provided that the above copyright notice appear in all
7  copies and that both that the copyright notice and this
8  permission notice and warranty disclaimer appear in supporting
9  documentation, and that the name of the author not be used in
10  advertising or publicity pertaining to distribution of the
11  software without specific, written prior permission.
12 
13  The author disclaim all warranties with regard to this
14  software, including all implied warranties of merchantability
15  and fitness. In no event shall the author be liable for any
16  special, indirect or consequential damages or any damages
17  whatsoever resulting from loss of use, data or profits, whether
18  in an action of contract, negligence or other tortious action,
19  arising out of or in connection with the use or performance of
20  this software.
21 */
22 
23 #include "identity_edition_dialog.h"
24 
25 #include "knglobals.h"
26 
27 #include <KDebug>
28 #include <KMessageBox>
29 #include <KPIMIdentities/Identity>
30 #include <KPIMIdentities/IdentityManager>
31 
32 using namespace KPIMIdentities;
33 
34 namespace KNode {
35 
36 
37 IdentityEditionDialog::IdentityEditionDialog( uint uoid, QWidget *parent )
38  : KDialog( parent ),
39  mCurrentIdentityUoid( -1 )
40 {
41  setupUi( this );
42 
43  setCaption( i18nc( "@title:window", "Manage your identities" ) );
44 
45  mSigningKeyRequester->dialogButton()->setText( i18nc( "@action:button Change signing key", "Change..." ) );
46  mSigningKeyRequester->setDialogCaption( i18nc( "@title:window PGP key chooser", "Your OpenPGP Key") );
47  mSigningKeyRequester->setDialogMessage( i18n( "Select the OpenPGP key which should be "
48  "used for signing articles." ) );
49  mSigningKeyRequester->setAllowedKeys( Kleo::SigningKeyRequester::OpenPGP );
50 
51  mButtonNewIdentity->setIcon( KIcon( "list-add" ) );
52  mButtonDuplicateIdentity->setIcon( KIcon( "edit-copy" ) );
53  mButtonRenameIdentity->setIcon( KIcon( "edit-rename" ) );
54  mButtonRemoveIdentity->setIcon( KIcon( "edit-delete" ) );
55 
56  setMainWidget( page );
57 
58 
59  connect( mIdentitySelector, SIGNAL(currentIndexChanged(int)),
60  this, SLOT(identitySelected(int)) );
61 
62  connect( mButtonNewIdentity, SIGNAL(clicked(bool)),
63  this, SLOT(createNewIdentity()) );
64  connect( mButtonDuplicateIdentity, SIGNAL(clicked(bool)),
65  this, SLOT(duplicateCurrentIdentity()) );
66  connect( mButtonRenameIdentity, SIGNAL(clicked(bool)),
67  this, SLOT(startIdentityRenaming()) );
68  connect( mButtonRemoveIdentity, SIGNAL(clicked(bool)),
69  this, SLOT(deleteCurrentIdentity()) );
70 
71 
72  reload();
73  setCurrentIdentity( uoid );
74 }
75 
76 IdentityEditionDialog::~IdentityEditionDialog()
77 {
78 }
79 
80 
81 void IdentityEditionDialog::reload()
82 {
83  IdentityManager *im = KNGlobals::self()->identityManager();
84 
85  IdentityManager::Iterator it = im->modifyBegin();
86  IdentityManager::Iterator end = im->modifyEnd();
87  mUoids.clear();
88  mIdentitySelector->blockSignals( true ); // We don't want to call identitySelected()
89  mIdentitySelector->clear();
90  while ( it != end ) {
91  mUoids << (*it).uoid();
92  mIdentitySelector->addItem( (*it).identityName(), (*it).uoid() );
93  ++it;
94  }
95  mIdentitySelector->blockSignals( false );
96 
97  bool canDelIdentity = ( mUoids.size() > 1 );
98  mButtonRemoveIdentity->setEnabled( canDelIdentity );
99  mIdentitySelector->setEditable( false );
100 }
101 
102 
103 void IdentityEditionDialog::slotButtonClicked( int button )
104 {
105  IdentityManager *im = KNGlobals::self()->identityManager();
106 
107  switch ( button ) {
108 
109  case KDialog::Ok:
110  case KDialog::Apply:
111  if ( mCurrentIdentityUoid != -1 ) {
112  saveIntoIdentity( mCurrentIdentityUoid );
113  }
114  im->commit();
115  break;
116 
117  case KDialog::Cancel:
118  case KDialog::Close:
119  im->rollback();
120  break;
121  }
122 
123  KDialog::slotButtonClicked( button );
124 }
125 
126 
127 void IdentityEditionDialog::identitySelected( int index )
128 {
129  if ( index < 0 || index >= mUoids.size() ) {
130  kWarning() << "Bad state: called with the index" << index << "when mUoids.size()==" << mUoids.size();
131  return;
132  }
133 
134  setCurrentIdentity( mUoids[ index ] );
135 }
136 
137 
138 void IdentityEditionDialog::loadFromIdentity( uint uoid )
139 {
140  IdentityManager *im = KNGlobals::self()->identityManager();
141 
142  Identity identity = im->modifyIdentityForUoid( uoid );
143 
144  mNameEdit->setText( identity.fullName() );
145  mOrganisationEdit->setText( identity.organization() );
146  mEmailEdit->setText( identity.primaryEmailAddress() );
147  mReplytoEdit->setText( identity.replyToAddr() );
148  mMailcopiestoEdit->setText( identity.property( "Mail-Copies-To" ).toString() );
149  mSignatureConfigurator->setSignature( identity.signature() );
150  mSigningKeyRequester->setFingerprint( QString::fromLatin1( identity.pgpSigningKey() ) );
151  mSigningKeyRequester->setInitialQuery( identity.primaryEmailAddress() );
152 }
153 
154 void IdentityEditionDialog::saveIntoIdentity( uint uoid ) const
155 {
156  IdentityManager *im = KNGlobals::self()->identityManager();
157  Identity &identity = im->modifyIdentityForUoid( uoid );
158 
159  identity.setFullName( mNameEdit->text().trimmed() );
160  identity.setOrganization( mOrganisationEdit->text().trimmed() );
161  identity.setPrimaryEmailAddress( mEmailEdit->text().trimmed() );
162  identity.setReplyToAddr( mReplytoEdit->text().trimmed() );
163  identity.setProperty( "Mail-Copies-To", mMailcopiestoEdit->text().trimmed() );
164  identity.setSignature( mSignatureConfigurator->signature() );
165  identity.setPGPSigningKey( mSigningKeyRequester->fingerprint().toLatin1() );
166 }
167 
168 void IdentityEditionDialog::setCurrentIdentity( uint uoid )
169 {
170  stopIdentityRenaming();
171  if ( mCurrentIdentityUoid != -1 ) {
172  saveIntoIdentity( mCurrentIdentityUoid );
173  }
174 
175  int index = mUoids.indexOf( uoid );
176  if ( index == -1 ) {
177  index = 0;
178  }
179 
180  mCurrentIdentityUoid = mUoids[ index ];
181  mIdentitySelector->blockSignals( true ); // We don't want to call identitySelected()
182  mIdentitySelector->setCurrentIndex( index );
183  mIdentitySelector->blockSignals( false );
184  loadFromIdentity( mCurrentIdentityUoid );
185 }
186 
187 void IdentityEditionDialog::createNewIdentity()
188 {
189  IdentityManager *im = KNGlobals::self()->identityManager();
190  const QString idName = im->makeUnique( i18nc( "Name of a newly created identity", "New identity" ) );
191  Identity &identity = im->newFromScratch( idName );
192 
193  reload();
194  setCurrentIdentity( identity.uoid() );
195  startIdentityRenaming();
196 }
197 
198 void IdentityEditionDialog::duplicateCurrentIdentity()
199 {
200  IdentityManager *im = KNGlobals::self()->identityManager();
201  const Identity &currentIdentity = im->modifyIdentityForUoid( mCurrentIdentityUoid );
202  const QString newName = im->makeUnique( currentIdentity.identityName() );
203  const Identity &newIdentity = im->newFromExisting( currentIdentity, newName );
204 
205  reload();
206  setCurrentIdentity( newIdentity.uoid() );
207  startIdentityRenaming();
208 }
209 
210 void IdentityEditionDialog::startIdentityRenaming()
211 {
212  if ( !mIdentitySelector->isEditable() ) {
213  mIdentitySelector->setEditable( true );
214  if ( !mIdentityNameEdit ) {
215  mIdentityNameEdit = new IdentityNameEditPrivate();
216  mIdentitySelector->setLineEdit( mIdentityNameEdit );
217  connect( mIdentityNameEdit, SIGNAL(identityNameChanged(QString)),
218  this, SLOT(changeIdentityName(QString)) );
219  }
220  mIdentitySelector->setTrapReturnKey( true );
221  mIdentitySelector->lineEdit()->selectAll();
222  mIdentitySelector->lineEdit()->setFocus( Qt::OtherFocusReason );
223  }
224 }
225 
226 void IdentityEditionDialog::stopIdentityRenaming()
227 {
228  if ( mIdentitySelector->isEditable() ) {
229  mIdentitySelector->setEditable( false );
230  }
231 }
232 
233 void IdentityEditionDialog::changeIdentityName( const QString &newName )
234 {
235  IdentityManager *im = KNGlobals::self()->identityManager();
236  Identity &identity = im->modifyIdentityForUoid( mCurrentIdentityUoid );
237  kDebug() << "Change identity name from" << identity.identityName() << "to" << newName;
238  Q_ASSERT( !identity.isNull() );
239  identity.setIdentityName( newName );
240 
241  stopIdentityRenaming();
242 
243  reload();
244  setCurrentIdentity( identity.uoid() );
245 
246  mNameEdit->setFocus( Qt::OtherFocusReason );
247 }
248 
249 
250 void IdentityEditionDialog::deleteCurrentIdentity()
251 {
252  if ( mUoids.size() <= 1 ) {
253  kWarning() << "Only one identity left and deleteCurrentIdentity() was called!";
254  return;
255  }
256 
257  IdentityManager *im = KNGlobals::self()->identityManager();
258  const Identity identity = im->modifyIdentityForUoid( mUoids[ mIdentitySelector->currentIndex() ] );
259  int answer = KMessageBox::questionYesNo( this,
260  i18n( "<qt>Do you really want to remove the identity <emphasis>%1</emphasis>?</qt>",
261  identity.identityName() ),
262  i18nc( "@title:window", "Delete identity" ) );
263  if ( answer == KMessageBox::Yes ) {
264  mCurrentIdentityUoid = -1;
265  im->removeIdentity( identity.identityName() );
266 
267  reload();
268  setCurrentIdentity( mUoids[ 0 ] );
269  }
270 }
271 
272 } // namespace KNode
273 
274 #include "identity_edition_dialog.moc"
identity_edition_dialog.h
QWidget
KNGlobals::self
static KNGlobals * self()
Return the KNGlobals instance.
Definition: knglobals.cpp:72
KDialog
KNode::IdentityEditionDialog::~IdentityEditionDialog
~IdentityEditionDialog()
Destructor.
Definition: identity_edition_dialog.cpp:76
KNGlobals::identityManager
KPIMIdentities::IdentityManager * identityManager()
Returns the identity manager.
Definition: knglobals.cpp:167
KNode::IdentityEditionDialog::slotButtonClicked
virtual void slotButtonClicked(int button)
Handles button clicks.
Definition: identity_edition_dialog.cpp:103
knglobals.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knode

Skip menu "knode"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



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