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