kmail Library API Documentation

identitydialog.cpp

00001 /* -*- mode: C++; c-file-style: "gnu" -*- 00002 identitydialog.cpp 00003 00004 This file is part of KMail, the KDE mail client. 00005 Copyright (c) 2002 Marc Mutz <mutz@kde.org> 00006 00007 KMail is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License, version 2, as 00009 published by the Free Software Foundation. 00010 00011 KMail is distributed in the hope that it will be useful, but 00012 WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 In addition, as a special exception, the copyright holders give 00021 permission to link the code of this program with any edition of 00022 the Qt library by Trolltech AS, Norway (or with modified versions 00023 of Qt that use the same license as Qt), and distribute linked 00024 combinations including the two. You must obey the GNU General 00025 Public License in all respects for all of the code used other than 00026 Qt. If you modify this file, you may extend this exception to 00027 your version of the file, but you are not obligated to do so. If 00028 you do not wish to do so, delete this exception statement from 00029 your version. 00030 */ 00031 00032 #ifdef HAVE_CONFIG_H 00033 #include <config.h> 00034 #endif 00035 00036 #include "identitydialog.h" 00037 00038 // other KMail headers: 00039 #include "signatureconfigurator.h" 00040 #include "kmfoldercombobox.h" 00041 #include "kmfoldermgr.h" 00042 #include "transportmanager.h" 00043 #include "kmkernel.h" 00044 #include "dictionarycombobox.h" 00045 00046 00047 // other kdepim headers: 00048 // libkdepim 00049 #include <libkpimidentities/identity.h> 00050 #include <libkdepim/addresseelineedit.h> 00051 // libkleopatra: 00052 #include <ui/keyrequester.h> 00053 #include <kleo/cryptobackendfactory.h> 00054 00055 // other KDE headers: 00056 #include <klocale.h> 00057 #include <kmessagebox.h> 00058 #include <kconfig.h> 00059 00060 // Qt headers: 00061 #include <qtabwidget.h> 00062 #include <qlabel.h> 00063 #include <qwhatsthis.h> 00064 #include <qlayout.h> 00065 #include <qpushbutton.h> 00066 #include <qcheckbox.h> 00067 #include <qcombobox.h> 00068 00069 // other headers: 00070 #include <gpgmepp/key.h> 00071 #include <iterator> 00072 #include <algorithm> 00073 00074 static const Kleo::CryptoMessageFormat cryptoMessageFormats[] = { 00075 Kleo::AutoFormat, 00076 Kleo::InlineOpenPGPFormat, 00077 Kleo::OpenPGPMIMEFormat, 00078 Kleo::SMIMEFormat, 00079 Kleo::SMIMEOpaqueFormat, 00080 }; 00081 static const int numCryptoMessageFormats = sizeof cryptoMessageFormats / sizeof *cryptoMessageFormats ; 00082 00083 static inline Kleo::CryptoMessageFormat cb2format( int idx ) { 00084 return cryptoMessageFormats[ idx >= 0 || idx < numCryptoMessageFormats ? idx : 0 ]; 00085 } 00086 00087 static inline int format2cb( Kleo::CryptoMessageFormat f ) { 00088 for ( int i = 0 ; i < numCryptoMessageFormats ; ++i ) 00089 if ( f == cryptoMessageFormats[i] ) 00090 return i; 00091 return 0; 00092 } 00093 00094 namespace KMail { 00095 00096 IdentityDialog::IdentityDialog( QWidget * parent, const char * name ) 00097 : KDialogBase( Plain, i18n("Edit Identity"), Ok|Cancel|Help, Ok, 00098 parent, name ) 00099 { 00100 // tmp. vars: 00101 QWidget * tab; 00102 QLabel * label; 00103 int row; 00104 QGridLayout * glay; 00105 QString msg; 00106 00107 // 00108 // Tab Widget: General 00109 // 00110 row = -1; 00111 QVBoxLayout * vlay = new QVBoxLayout( plainPage(), 0, spacingHint() ); 00112 QTabWidget *tabWidget = new QTabWidget( plainPage(), "config-identity-tab" ); 00113 vlay->addWidget( tabWidget ); 00114 00115 tab = new QWidget( tabWidget ); 00116 tabWidget->addTab( tab, i18n("&General") ); 00117 glay = new QGridLayout( tab, 4, 2, marginHint(), spacingHint() ); 00118 glay->setRowStretch( 3, 1 ); 00119 glay->setColStretch( 1, 1 ); 00120 00121 // "Name" line edit and label: 00122 ++row; 00123 mNameEdit = new KLineEdit( tab ); 00124 glay->addWidget( mNameEdit, row, 1 ); 00125 label = new QLabel( mNameEdit, i18n("&Your name:"), tab ); 00126 glay->addWidget( label, row, 0 ); 00127 msg = i18n("<qt><h3>Your name</h3>" 00128 "<p>This field should contain your name as you would like " 00129 "it to appear in the email header that is sent out;</p>" 00130 "<p>if you leave this blank your real name will not " 00131 "appear, only the email address.</p></qt>"); 00132 QWhatsThis::add( label, msg ); 00133 QWhatsThis::add( mNameEdit, msg ); 00134 00135 // "Organization" line edit and label: 00136 ++row; 00137 mOrganizationEdit = new KLineEdit( tab ); 00138 glay->addWidget( mOrganizationEdit, row, 1 ); 00139 label = new QLabel( mOrganizationEdit, i18n("Organi&zation:"), tab ); 00140 glay->addWidget( label, row, 0 ); 00141 msg = i18n("<qt><h3>Organization</h3>" 00142 "<p>This field should have the name of your organization " 00143 "if you'd like it to be shown in the email header that " 00144 "is sent out.</p>" 00145 "<p>It is safe (and normal) to leave this blank.</p></qt>"); 00146 QWhatsThis::add( label, msg ); 00147 QWhatsThis::add( mOrganizationEdit, msg ); 00148 00149 // "Email Address" line edit and label: 00150 // (row 3: spacer) 00151 ++row; 00152 mEmailEdit = new KLineEdit( tab ); 00153 glay->addWidget( mEmailEdit, row, 1 ); 00154 label = new QLabel( mEmailEdit, i18n("&Email address:"), tab ); 00155 glay->addWidget( label, row, 0 ); 00156 msg = i18n("<qt><h3>Email address</h3>" 00157 "<p>This field should have your full email address.</p>" 00158 "<p>If you leave this blank, or get it wrong, people " 00159 "will have trouble replying to you.</p></qt>"); 00160 QWhatsThis::add( label, msg ); 00161 QWhatsThis::add( mEmailEdit, msg ); 00162 00163 // 00164 // Tab Widget: Cryptography 00165 // 00166 row = -1; 00167 mCryptographyTab = tab = new QWidget( tabWidget ); 00168 tabWidget->addTab( tab, i18n("Cryptograph&y") ); 00169 glay = new QGridLayout( tab, 6, 2, marginHint(), spacingHint() ); 00170 glay->setColStretch( 1, 1 ); 00171 00172 // "OpenPGP Signature Key" requester and label: 00173 ++row; 00174 mPGPSigningKeyRequester = new Kleo::SigningKeyRequester( false, Kleo::SigningKeyRequester::OpenPGP, tab ); 00175 mPGPSigningKeyRequester->dialogButton()->setText( i18n("Chang&e...") ); 00176 mPGPSigningKeyRequester->setDialogCaption( i18n("Your OpenPGP Signature Key") ); 00177 msg = i18n("Select the OpenPGP key which should be used to " 00178 "digitally sign your messages."); 00179 mPGPSigningKeyRequester->setDialogMessage( msg ); 00180 00181 msg = i18n("<qt><p>The OpenPGP key you choose here will be used " 00182 "to digitally sign messages. You can also use GnuPG keys.</p>" 00183 "<p>You can leave this blank, but KMail will not be able " 00184 "to digitally sign emails using OpenPGP; " 00185 "normal mail functions will not be affected.</p>" 00186 "<p>You can find out more about keys at <a>http://www.gnupg.org</a></p></qt>"); 00187 00188 label = new QLabel( mPGPSigningKeyRequester, i18n("OpenPGP signing key:"), tab ); 00189 QWhatsThis::add( mPGPSigningKeyRequester, msg ); 00190 QWhatsThis::add( label, msg ); 00191 00192 glay->addWidget( label, row, 0 ); 00193 glay->addWidget( mPGPSigningKeyRequester, row, 1 ); 00194 00195 00196 // "OpenPGP Encryption Key" requester and label: 00197 ++row; 00198 mPGPEncryptionKeyRequester = new Kleo::EncryptionKeyRequester( false, Kleo::EncryptionKeyRequester::OpenPGP, tab ); 00199 mPGPEncryptionKeyRequester->dialogButton()->setText( i18n("Chang&e...") ); 00200 mPGPEncryptionKeyRequester->setDialogCaption( i18n("Your OpenPGP Encryption Key") ); 00201 msg = i18n("Select the OpenPGP key which should be used when encrypting " 00202 "to yourself and for the \"Attach My Public Key\" " 00203 "feature in the composer."); 00204 mPGPEncryptionKeyRequester->setDialogMessage( msg ); 00205 00206 msg = i18n("<qt><p>The OpenPGP key you choose here will be used " 00207 "to encrypt messages to yourself and for the \"Attach My Public Key\" " 00208 "feature in the composer. You can also use GnuPG keys.</p>" 00209 "<p>You can leave this blank, but KMail will not be able " 00210 "to encrypt copies of outgoing messages to you using OpenPGP; " 00211 "normal mail functions will not be affected.</p>" 00212 "<p>You can find out more about keys at <a>http://www.gnupg.org</a></qt>"); 00213 label = new QLabel( mPGPEncryptionKeyRequester, i18n("OpenPGP encryption key:"), tab ); 00214 QWhatsThis::add( mPGPEncryptionKeyRequester, msg ); 00215 QWhatsThis::add( label, msg ); 00216 00217 glay->addWidget( label, row, 0 ); 00218 glay->addWidget( mPGPEncryptionKeyRequester, row, 1 ); 00219 00220 00221 // "S/MIME Signature Key" requester and label: 00222 ++row; 00223 mSMIMESigningKeyRequester = new Kleo::SigningKeyRequester( false, Kleo::SigningKeyRequester::SMIME, tab ); 00224 mSMIMESigningKeyRequester->dialogButton()->setText( i18n("Chang&e...") ); 00225 mSMIMESigningKeyRequester->setDialogCaption( i18n("Your S/MIME Signature Certificate") ); 00226 msg = i18n("Select the S/MIME certificate which should be used to " 00227 "digitally sign your messages."); 00228 mSMIMESigningKeyRequester->setDialogMessage( msg ); 00229 00230 msg = i18n("<qt><p>The S/MIME (X.509) certificate you choose here will be used " 00231 "to digitally sign messages.</p>" 00232 "<p>You can leave this blank, but KMail will not be able " 00233 "to digitally sign emails using S/MIME; " 00234 "normal mail functions will not be affected.</p></qt>"); 00235 label = new QLabel( mSMIMESigningKeyRequester, i18n("S/MIME signing certificate:"), tab ); 00236 QWhatsThis::add( mSMIMESigningKeyRequester, msg ); 00237 QWhatsThis::add( label, msg ); 00238 glay->addWidget( label, row, 0 ); 00239 glay->addWidget( mSMIMESigningKeyRequester, row, 1 ); 00240 00241 const Kleo::CryptoBackend::Protocol * smimeProtocol 00242 = Kleo::CryptoBackendFactory::instance()->smime(); 00243 00244 label->setEnabled( smimeProtocol ); 00245 mSMIMESigningKeyRequester->setEnabled( smimeProtocol ); 00246 00247 // "S/MIME Encryption Key" requester and label: 00248 ++row; 00249 mSMIMEEncryptionKeyRequester = new Kleo::EncryptionKeyRequester( false, Kleo::EncryptionKeyRequester::SMIME, tab ); 00250 mSMIMEEncryptionKeyRequester->dialogButton()->setText( i18n("Chang&e...") ); 00251 mSMIMEEncryptionKeyRequester->setDialogCaption( i18n("Your S/MIME Encryption Certificate") ); 00252 msg = i18n("Select the S/MIME certificate which should be used when encrypting " 00253 "to yourself and for the \"Attach My Certificate\" " 00254 "feature in the composer."); 00255 mSMIMEEncryptionKeyRequester->setDialogMessage( msg ); 00256 00257 msg = i18n("<qt><p>The S/MIME certificate you choose here will be used " 00258 "to encrypt messages to yourself and for the \"Attach My Certificate\" " 00259 "feature in the composer.</p>" 00260 "<p>You can leave this blank, but KMail will not be able " 00261 "to encrypt copies of outgoing messages to you using S/MIME; " 00262 "normal mail functions will not be affected.</p></qt>"); 00263 label = new QLabel( mSMIMEEncryptionKeyRequester, i18n("S/MIME encryption certificate:"), tab ); 00264 QWhatsThis::add( mSMIMEEncryptionKeyRequester, msg ); 00265 QWhatsThis::add( label, msg ); 00266 00267 glay->addWidget( label, row, 0 ); 00268 glay->addWidget( mSMIMEEncryptionKeyRequester, row, 1 ); 00269 00270 label->setEnabled( smimeProtocol ); 00271 mSMIMEEncryptionKeyRequester->setEnabled( smimeProtocol ); 00272 00273 // "Preferred Crypto Message Format" combobox and label: 00274 ++row; 00275 mPreferredCryptoMessageFormat = new QComboBox( false, tab ); 00276 QStringList l; 00277 l << Kleo::cryptoMessageFormatToLabel( Kleo::AutoFormat ) 00278 << Kleo::cryptoMessageFormatToLabel( Kleo::InlineOpenPGPFormat ) 00279 << Kleo::cryptoMessageFormatToLabel( Kleo::OpenPGPMIMEFormat ) 00280 << Kleo::cryptoMessageFormatToLabel( Kleo::SMIMEFormat ) 00281 << Kleo::cryptoMessageFormatToLabel( Kleo::SMIMEOpaqueFormat ); 00282 mPreferredCryptoMessageFormat->insertStringList( l ); 00283 label = new QLabel( mPreferredCryptoMessageFormat, 00284 i18n("Preferred crypto message format:"), tab ); 00285 00286 glay->addWidget( label, row, 0 ); 00287 glay->addWidget( mPreferredCryptoMessageFormat, row, 1 ); 00288 00289 ++row; 00290 glay->setRowStretch( row, 1 ); 00291 00292 // 00293 // Tab Widget: Advanced 00294 // 00295 row = -1; 00296 tab = new QWidget( tabWidget ); 00297 tabWidget->addTab( tab, i18n("&Advanced") ); 00298 glay = new QGridLayout( tab, 7, 2, marginHint(), spacingHint() ); 00299 // the last (empty) row takes all the remaining space 00300 glay->setRowStretch( 7-1, 1 ); 00301 glay->setColStretch( 1, 1 ); 00302 00303 // "Reply-To Address" line edit and label: 00304 ++row; 00305 mReplyToEdit = new KPIM::AddresseeLineEdit( tab, true, "mReplyToEdit" ); 00306 glay->addWidget( mReplyToEdit, row, 1 ); 00307 label = new QLabel ( mReplyToEdit, i18n("&Reply-To address:"), tab); 00308 glay->addWidget( label , row, 0 ); 00309 msg = i18n("<qt><h3>Reply-To addresses</h3>" 00310 "<p>This sets the <tt>Reply-to:</tt> header to contain a " 00311 "different email address to the normal <tt>From:</tt> " 00312 "address.</p>" 00313 "<p>This can be useful when you have a group of people " 00314 "working together in similar roles. For example, you " 00315 "might want any emails sent to have your email in the " 00316 "<tt>From:</tt> field, but any responses to go to " 00317 "a group address.</p>" 00318 "<p>If in doubt, leave this field blank.</p></qt>"); 00319 QWhatsThis::add( label, msg ); 00320 QWhatsThis::add( mReplyToEdit, msg ); 00321 00322 // "BCC addresses" line edit and label: 00323 ++row; 00324 mBccEdit = new KPIM::AddresseeLineEdit( tab, true, "mBccEdit" ); 00325 glay->addWidget( mBccEdit, row, 1 ); 00326 label = new QLabel( mBccEdit, i18n("&BCC addresses:"), tab ); 00327 glay->addWidget( label, row, 0 ); 00328 msg = i18n("<qt><h3>BCC (Blind Carbon Copy) addresses</h3>" 00329 "<p>The addresses that you enter here will be added to each " 00330 "outgoing mail that is sent with this identity. They will not " 00331 "be visible to other recipients.</p>" 00332 "<p>This is commonly used to send a copy of each sent message to " 00333 "another account of yours.</p>" 00334 "<p>To specify more than one address, use commas to separate " 00335 "the list of BCC recipients.</p>" 00336 "<p>If in doubt, leave this field blank.</p></qt>"); 00337 QWhatsThis::add( label, msg ); 00338 QWhatsThis::add( mBccEdit, msg ); 00339 00340 // "Dictionary" combo box and label: 00341 ++row; 00342 mDictionaryCombo = new DictionaryComboBox( tab ); 00343 glay->addWidget( mDictionaryCombo, row, 1 ); 00344 glay->addWidget( new QLabel( mDictionaryCombo, i18n("D&ictionary:"), tab ), 00345 row, 0 ); 00346 00347 // "Sent-mail Folder" combo box and label: 00348 ++row; 00349 mFccCombo = new KMFolderComboBox( tab ); 00350 mFccCombo->showOutboxFolder( false ); 00351 glay->addWidget( mFccCombo, row, 1 ); 00352 glay->addWidget( new QLabel( mFccCombo, i18n("Sent-mail &folder:"), tab ), 00353 row, 0 ); 00354 00355 // "Drafts Folder" combo box and label: 00356 ++row; 00357 mDraftsCombo = new KMFolderComboBox( tab ); 00358 mDraftsCombo->showOutboxFolder( false ); 00359 glay->addWidget( mDraftsCombo, row, 1 ); 00360 glay->addWidget( new QLabel( mDraftsCombo, i18n("&Drafts folder:"), tab ), 00361 row, 0 ); 00362 00363 // "Special transport" combobox and label: 00364 ++row; 00365 mTransportCheck = new QCheckBox( i18n("Special &transport:"), tab ); 00366 glay->addWidget( mTransportCheck, row, 0 ); 00367 mTransportCombo = new QComboBox( true, tab ); 00368 mTransportCombo->setEnabled( false ); // since !mTransportCheck->isChecked() 00369 mTransportCombo->insertStringList( KMail::TransportManager::transportNames() ); 00370 glay->addWidget( mTransportCombo, row, 1 ); 00371 connect( mTransportCheck, SIGNAL(toggled(bool)), 00372 mTransportCombo, SLOT(setEnabled(bool)) ); 00373 00374 // the last row is a spacer 00375 00376 // 00377 // Tab Widget: Signature 00378 // 00379 mSignatureConfigurator = new SignatureConfigurator( tabWidget ); 00380 mSignatureConfigurator->layout()->setMargin( KDialog::marginHint() ); 00381 tabWidget->addTab( mSignatureConfigurator, i18n("&Signature") ); 00382 00383 KConfigGroup geometry( KMKernel::config(), "Geometry" ); 00384 if ( geometry.hasKey( "Identity Dialog size" ) ) 00385 resize( geometry.readSizeEntry( "Identity Dialog size" ) ); 00386 mNameEdit->setFocus(); 00387 00388 connect( tabWidget, SIGNAL(currentChanged(QWidget*)), 00389 SLOT(slotAboutToShow(QWidget*)) ); 00390 } 00391 00392 IdentityDialog::~IdentityDialog() { 00393 KConfigGroup geometry( KMKernel::config(), "Geometry" ); 00394 geometry.writeEntry( "Identity Dialog size", size() ); 00395 } 00396 00397 void IdentityDialog::slotAboutToShow( QWidget * w ) { 00398 if ( w == mCryptographyTab ) { 00399 // set the configured email address as inital query of the key 00400 // requesters: 00401 const QString email = mEmailEdit->text().stripWhiteSpace(); 00402 mPGPEncryptionKeyRequester->setInitialQuery( email ); 00403 mPGPSigningKeyRequester->setInitialQuery( email ); 00404 mSMIMEEncryptionKeyRequester->setInitialQuery( email ); 00405 mSMIMESigningKeyRequester->setInitialQuery( email ); 00406 } 00407 } 00408 00409 namespace { 00410 struct DoesntMatchEMailAddress { 00411 explicit DoesntMatchEMailAddress( const QString & s ) 00412 : email( s.stripWhiteSpace().lower() ) {} 00413 bool operator()( const GpgME::Key & key ) const; 00414 private: 00415 bool checkForEmail( const char * email ) const; 00416 static QString extractEmail( const char * email ); 00417 const QString email; 00418 }; 00419 00420 bool DoesntMatchEMailAddress::operator()( const GpgME::Key & key ) const { 00421 const std::vector<GpgME::UserID> uids = key.userIDs(); 00422 for ( std::vector<GpgME::UserID>::const_iterator it = uids.begin() ; it != uids.end() ; ++it ) 00423 if ( checkForEmail( it->email() ? it->email() : it->id() ) ) 00424 return false; 00425 return true; // note the negation! 00426 } 00427 00428 bool DoesntMatchEMailAddress::checkForEmail( const char * e ) const { 00429 const QString em = extractEmail( e ); 00430 return !em.isEmpty() && email == em; 00431 } 00432 00433 QString DoesntMatchEMailAddress::extractEmail( const char * e ) { 00434 if ( !e || !*e ) 00435 return QString::null; 00436 const QString em = QString::fromUtf8( e ); 00437 if ( e[0] == '<' ) 00438 return em.mid( 1, em.length() - 2 ); 00439 else 00440 return em; 00441 } 00442 } 00443 00444 void IdentityDialog::slotOk() { 00445 const QString email = mEmailEdit->text().stripWhiteSpace(); 00446 if ( email.isEmpty() ) 00447 return KDialogBase::slotOk(); 00448 const std::vector<GpgME::Key> & pgpSigningKeys = mPGPSigningKeyRequester->keys(); 00449 const std::vector<GpgME::Key> & pgpEncryptionKeys = mPGPEncryptionKeyRequester->keys(); 00450 const std::vector<GpgME::Key> & smimeSigningKeys = mSMIMESigningKeyRequester->keys(); 00451 const std::vector<GpgME::Key> & smimeEncryptionKeys = mSMIMEEncryptionKeyRequester->keys(); 00452 QString msg; 00453 if ( std::find_if( pgpSigningKeys.begin(), pgpSigningKeys.end(), 00454 DoesntMatchEMailAddress( email ) ) != pgpSigningKeys.end() ) 00455 msg = i18n("One of the configured OpenPGP signing keys does not contain " 00456 "any user ID with the configured email address for this " 00457 "identity (%1).\n" 00458 "This might result in warning messages on the receiving side " 00459 "when trying to verify signatures made with this configuration."); 00460 else if ( std::find_if( pgpEncryptionKeys.begin(), pgpEncryptionKeys.end(), 00461 DoesntMatchEMailAddress( email ) ) != pgpEncryptionKeys.end() ) 00462 msg = i18n("One of the configured OpenPGP encryption keys does not contain " 00463 "any user ID with the configured email address for this " 00464 "identity (%1)."); 00465 else if ( std::find_if( smimeSigningKeys.begin(), smimeSigningKeys.end(), 00466 DoesntMatchEMailAddress( email ) ) != smimeSigningKeys.end() ) 00467 msg = i18n("One of the configured S/MIME signing certificates does not contain " 00468 "the configured email address for this " 00469 "identity (%1).\n" 00470 "This might result in warning messages on the receiving side " 00471 "when trying to verify signatures made with this configuration."); 00472 else if ( std::find_if( smimeEncryptionKeys.begin(), smimeEncryptionKeys.end(), 00473 DoesntMatchEMailAddress( email ) ) != smimeEncryptionKeys.end() ) 00474 msg = i18n("One of the configured S/MIME encryption certificates does not contain " 00475 "the configured email address for this " 00476 "identity (%1)."); 00477 else 00478 return KDialogBase::slotOk(); 00479 00480 if ( KMessageBox::warningContinueCancel( this, msg.arg( email ), 00481 i18n("Email Address Not Found in Key/Certificates"), 00482 KStdGuiItem::cont(), "warn_email_not_in_certificate" ) 00483 == KMessageBox::Continue ) 00484 return KDialogBase::slotOk(); 00485 } 00486 00487 bool IdentityDialog::checkFolderExists( const QString & folderID, 00488 const QString & msg ) { 00489 KMFolder * folder = kmkernel->findFolderById( folderID ); 00490 if ( !folder ) { 00491 KMessageBox::sorry( this, msg ); 00492 return false; 00493 } 00494 return true; 00495 } 00496 00497 void IdentityDialog::setIdentity( KPIM::Identity & ident ) { 00498 00499 setCaption( i18n("Edit Identity \"%1\"").arg( ident.identityName() ) ); 00500 00501 // "General" tab: 00502 mNameEdit->setText( ident.fullName() ); 00503 mOrganizationEdit->setText( ident.organization() ); 00504 mEmailEdit->setText( ident.emailAddr() ); 00505 00506 // "Cryptography" tab: 00507 mPGPSigningKeyRequester->setFingerprint( ident.pgpSigningKey() ); 00508 mPGPEncryptionKeyRequester->setFingerprint( ident.pgpEncryptionKey() ); 00509 mSMIMESigningKeyRequester->setFingerprint( ident.smimeSigningKey() ); 00510 mSMIMEEncryptionKeyRequester->setFingerprint( ident.smimeEncryptionKey() ); 00511 mPreferredCryptoMessageFormat->setCurrentItem( format2cb( ident.preferredCryptoMessageFormat() ) ); 00512 00513 // "Advanced" tab: 00514 mReplyToEdit->setText( ident.replyToAddr() ); 00515 mBccEdit->setText( ident.bcc() ); 00516 mTransportCheck->setChecked( !ident.transport().isEmpty() ); 00517 mTransportCombo->setEditText( ident.transport() ); 00518 mTransportCombo->setEnabled( !ident.transport().isEmpty() ); 00519 mDictionaryCombo->setCurrentByDictionary( ident.dictionary() ); 00520 00521 if ( ident.fcc().isEmpty() || 00522 !checkFolderExists( ident.fcc(), 00523 i18n("The custom sent-mail folder for identity " 00524 "\"%1\" does not exist (anymore); " 00525 "therefore, the default sent-mail folder " 00526 "will be used.") 00527 .arg( ident.identityName() ) ) ) 00528 mFccCombo->setFolder( kmkernel->sentFolder() ); 00529 else 00530 mFccCombo->setFolder( ident.fcc() ); 00531 00532 if ( ident.drafts().isEmpty() || 00533 !checkFolderExists( ident.drafts(), 00534 i18n("The custom drafts folder for identity " 00535 "\"%1\" does not exist (anymore); " 00536 "therefore, the default drafts folder " 00537 "will be used.") 00538 .arg( ident.identityName() ) ) ) 00539 mDraftsCombo->setFolder( kmkernel->draftsFolder() ); 00540 else 00541 mDraftsCombo->setFolder( ident.drafts() ); 00542 00543 // "Signature" tab: 00544 mSignatureConfigurator->setSignature( ident.signature() ); 00545 } 00546 00547 void IdentityDialog::updateIdentity( KPIM::Identity & ident ) { 00548 // "General" tab: 00549 ident.setFullName( mNameEdit->text() ); 00550 ident.setOrganization( mOrganizationEdit->text() ); 00551 QString email = mEmailEdit->text(); 00552 int atCount = email.contains('@'); 00553 if ( email.isEmpty() || atCount == 0 ) 00554 KMessageBox::sorry( this, "<qt>"+ 00555 i18n("Your email address is not valid because it " 00556 "does not contain a <emph>@</emph>: " 00557 "you will not create valid messages if you do not " 00558 "change your address.") + "</qt>", 00559 i18n("Invalid Email Address") ); 00560 else if ( atCount > 1 ) { 00561 KMessageBox::sorry( this, "<qt>" + 00562 i18n("Your email address is not valid because it " 00563 "contains more than one <emph>@</emph>: " 00564 "you will not create valid messages if you do not " 00565 "change your address.") + "</qt>", 00566 i18n("Invalid Email Address") ); 00567 } 00568 ident.setEmailAddr( email ); 00569 // "Cryptography" tab: 00570 ident.setPGPSigningKey( mPGPSigningKeyRequester->fingerprint().latin1() ); 00571 ident.setPGPEncryptionKey( mPGPEncryptionKeyRequester->fingerprint().latin1() ); 00572 ident.setSMIMESigningKey( mSMIMESigningKeyRequester->fingerprint().latin1() ); 00573 ident.setSMIMEEncryptionKey( mSMIMEEncryptionKeyRequester->fingerprint().latin1() ); 00574 ident.setPreferredCryptoMessageFormat( cb2format( mPreferredCryptoMessageFormat->currentItem() ) ); 00575 // "Advanced" tab: 00576 ident.setReplyToAddr( mReplyToEdit->text() ); 00577 ident.setBcc( mBccEdit->text() ); 00578 ident.setTransport( ( mTransportCheck->isChecked() ) ? 00579 mTransportCombo->currentText() : QString::null ); 00580 ident.setDictionary( mDictionaryCombo->currentDictionary() ); 00581 ident.setFcc( mFccCombo->getFolder() ? 00582 mFccCombo->getFolder()->idString() : QString::null ); 00583 ident.setDrafts( mDraftsCombo->getFolder() ? 00584 mDraftsCombo->getFolder()->idString() : QString::null ); 00585 // "Signature" tab: 00586 ident.setSignature( mSignatureConfigurator->signature() ); 00587 } 00588 00589 void IdentityDialog::slotUpdateTransportCombo( const QStringList & sl ) { 00590 // save old setting: 00591 QString content = mTransportCombo->currentText(); 00592 // update combo box: 00593 mTransportCombo->clear(); 00594 mTransportCombo->insertStringList( sl ); 00595 // restore saved setting: 00596 mTransportCombo->setEditText( content ); 00597 } 00598 00599 } 00600 00601 #include "identitydialog.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:45 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003