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 kdenetwork headers:
00048 #include <kpgpui.h>
00049 
00050 // other KDE headers:
00051 #include <klineedit.h>
00052 #include <klocale.h>
00053 #include <kmessagebox.h>
00054 #include <kconfig.h>
00055 
00056 // Qt headers:
00057 #include <qtabwidget.h>
00058 #include <qlabel.h>
00059 #include <qwhatsthis.h>
00060 
00061 // other headers: (none)
00062 
00063 namespace KMail {
00064 
00065   IdentityDialog::IdentityDialog( QWidget * parent, const char * name )
00066     : KDialogBase( Plain, i18n("Edit Identity"), Ok|Cancel|Help, Ok,
00067                    parent, name )
00068   {
00069     // tmp. vars:
00070     QWidget * tab;
00071     QLabel  * label;
00072     int row;
00073     QGridLayout * glay;
00074     QString msg;
00075 
00076     //
00077     // Tab Widget: General
00078     //
00079     row = -1;
00080     QVBoxLayout * vlay = new QVBoxLayout( plainPage(), 0, spacingHint() );
00081     QTabWidget *tabWidget = new QTabWidget( plainPage(), "config-identity-tab" );
00082     vlay->addWidget( tabWidget );
00083 
00084     tab = new QWidget( tabWidget );
00085     tabWidget->addTab( tab, i18n("&General") );
00086     glay = new QGridLayout( tab, 4, 2, marginHint(), spacingHint() );
00087     glay->setRowStretch( 3, 1 );
00088     glay->setColStretch( 1, 1 );
00089 
00090     // "Name" line edit and label:
00091     ++row;
00092     mNameEdit = new KLineEdit( tab );
00093     glay->addWidget( mNameEdit, row, 1 );
00094     label = new QLabel( mNameEdit, i18n("&Your name:"), tab );
00095     glay->addWidget( label, row, 0 );
00096     msg = i18n("<qt><h3>Your name</h3>"
00097                "<p>This field should have your name, as you'd like "
00098                "it to appear in the email header that is sent out.</p>"
00099                "<p>If you leave this blank, your real name won't "
00100                "appear, only the email address.</p></qt>");
00101     QWhatsThis::add( label, msg );
00102     QWhatsThis::add( mNameEdit, msg );
00103 
00104     // "Organization" line edit and label:
00105     ++row;
00106     mOrganizationEdit = new KLineEdit( tab );
00107     glay->addWidget( mOrganizationEdit, row, 1 );
00108     label =  new QLabel( mOrganizationEdit, i18n("Organi&zation:"), tab );
00109     glay->addWidget( label, row, 0 );
00110     msg = i18n("<qt><h3>Organization</h3>"
00111                "<p>This field should have the name of your organization "
00112                "if you'd like it to be shown in the email header that "
00113                "is sent out.</p>"
00114                "<p>It is safe (and normal) to leave this blank.</p></qt>");
00115     QWhatsThis::add( label, msg );
00116     QWhatsThis::add( mOrganizationEdit, msg );
00117 
00118     // "Email Address" line edit and label:
00119     // (row 3: spacer)
00120     ++row;
00121     mEmailEdit = new KLineEdit( tab );
00122     glay->addWidget( mEmailEdit, row, 1 );
00123     label = new QLabel( mEmailEdit, i18n("&Email address:"), tab );
00124     glay->addWidget( label, row, 0 );
00125     msg = i18n("<qt><h3>Email address</h3>"
00126                "<p>This field should have your full email address.</p>"
00127                "<p>If you leave this blank, or get it wrong, people "
00128                "will have trouble replying to you.</p></qt>");
00129     QWhatsThis::add( label, msg );
00130     QWhatsThis::add( mEmailEdit, msg );
00131 
00132     //
00133     // Tab Widget: Advanced
00134     //
00135     row = -1;
00136     tab = new QWidget( tabWidget );
00137     tabWidget->addTab( tab, i18n("&Advanced") );
00138     glay = new QGridLayout( tab, 7, 2, marginHint(), spacingHint() );
00139     // the last (empty) row takes all the remaining space
00140     glay->setRowStretch( 7-1, 1 );
00141     glay->setColStretch( 1, 1 );
00142 
00143     // "Reply-To Address" line edit and label:
00144     ++row;
00145     mReplyToEdit = new KLineEdit( tab );
00146     glay->addWidget( mReplyToEdit, row, 1 );
00147     label = new QLabel ( mReplyToEdit, i18n("&Reply-To address:"), tab);
00148     glay->addWidget( label , row, 0 );
00149     msg = i18n("<qt><h3>Reply-To addresses</h3>"
00150                "<p>This sets the <tt>Reply-to:</tt> header to contain a "
00151                "different email address to the normal <tt>From:</tt> "
00152                "address.</p>"
00153                "<p>This can be useful when you have a group of people "
00154                "working together in similar roles. For example, you "
00155                "might want any emails sent to have your email in the "
00156                "<tt>From:</tt> field, but any responses to go to "
00157                "a group address.</p>"
00158                "<p>If in doubt, leave this field blank.</p></qt>");
00159     QWhatsThis::add( label, msg );
00160     QWhatsThis::add( mReplyToEdit, msg );
00161 
00162     // "BCC addresses" line edit and label:
00163     ++row;
00164     mBccEdit = new KLineEdit( tab );
00165     glay->addWidget( mBccEdit, row, 1 );
00166     label = new QLabel( mBccEdit, i18n("&BCC addresses:"), tab );
00167     glay->addWidget( label, row, 0 );
00168     msg = i18n("<qt><h3>BCC (Blind Carbon Copy) addresses</h3>"
00169                "<p>The addresses that you enter here will be added to each "
00170                "outgoing mail that is sent with this identity. They will not "
00171                "be visible to other recipients.</p>"
00172                "<p>This is commonly used to send a copy of each sent message to "
00173                "another account of yours.</p>"
00174                "<p>If in doubt, leave this field blank.</p></qt>");
00175     QWhatsThis::add( label, msg );
00176     QWhatsThis::add( mBccEdit, msg );
00177 
00178     // "OpenPGP Key" requester and label:
00179     ++row;
00180     mPgpKeyRequester = new Kpgp::SecretKeyRequester( tab );
00181     mPgpKeyRequester->dialogButton()->setText( i18n("Chang&e...") );
00182     mPgpKeyRequester->setDialogCaption( i18n("Your OpenPGP Key") );
00183     mPgpKeyRequester->setDialogMessage( i18n("Select the OpenPGP key which "
00184                                              "should be used to sign your "
00185                                              "messages and when encrypting to "
00186                                              "yourself.") );
00187     msg = i18n("<qt><p>The OpenPGP key you choose here will be used "
00188                "to sign messages and to encrypt messages to "
00189                "yourself. You can also use GnuPG keys.</p>"
00190                "You can leave this blank, but KMail won't be able "
00191                "to cryptographically sign emails. Normal mail functions won't "
00192                "be affected.</p>"
00193                "You can find out more about keys at <a>http://www.gnupg.org</a></qt>");
00194 
00195     label = new QLabel( mPgpKeyRequester, i18n("OpenPGP key:"), tab );
00196     QWhatsThis::add( mPgpKeyRequester, msg );
00197     QWhatsThis::add( label, msg );
00198 
00199     glay->addWidget( label, row, 0 );
00200     glay->addWidget( mPgpKeyRequester, row, 1 );
00201 
00202     // "Dictionary" combo box and label:
00203     ++row;
00204     mDictionaryCombo = new DictionaryComboBox( tab );
00205     glay->addWidget( mDictionaryCombo, row, 1 );
00206     glay->addWidget( new QLabel( mDictionaryCombo, i18n("D&ictionary:"), tab ),
00207                      row, 0 );
00208 
00209     // "Sent-mail Folder" combo box and label:
00210     ++row;
00211     mFccCombo = new KMFolderComboBox( tab );
00212     mFccCombo->showOutboxFolder( false );
00213     glay->addWidget( mFccCombo, row, 1 );
00214     glay->addWidget( new QLabel( mFccCombo, i18n("Sent-mail &folder:"), tab ),
00215                      row, 0 );
00216 
00217     // "Drafts Folder" combo box and label:
00218     ++row;
00219     mDraftsCombo = new KMFolderComboBox( tab );
00220     mDraftsCombo->showOutboxFolder( false );
00221     glay->addWidget( mDraftsCombo, row, 1 );
00222     glay->addWidget( new QLabel( mDraftsCombo, i18n("&Drafts folder:"), tab ),
00223                      row, 0 );
00224 
00225     // "Special transport" combobox and label:
00226     ++row;
00227     mTransportCheck = new QCheckBox( i18n("Special &transport:"), tab );
00228     glay->addWidget( mTransportCheck, row, 0 );
00229     mTransportCombo = new QComboBox( true, tab );
00230     mTransportCombo->setEnabled( false ); // since !mTransportCheck->isChecked()
00231     mTransportCombo->insertStringList( KMail::TransportManager::transportNames() );
00232     glay->addWidget( mTransportCombo, row, 1 );
00233     connect( mTransportCheck, SIGNAL(toggled(bool)),
00234              mTransportCombo, SLOT(setEnabled(bool)) );
00235 
00236     // the last row is a spacer
00237 
00238     //
00239     // Tab Widget: Signature
00240     //
00241     mSignatureConfigurator = new SignatureConfigurator( tabWidget );
00242     mSignatureConfigurator->layout()->setMargin( KDialog::marginHint() );
00243     tabWidget->addTab( mSignatureConfigurator, i18n("&Signature") );
00244 
00245     KConfigGroup geometry( KMKernel::config(), "Geometry" );
00246     if ( geometry.hasKey( "Identity Dialog size" ) )
00247       resize( geometry.readSizeEntry( "Identity Dialog size" ) );
00248     mNameEdit->setFocus();
00249   }
00250 
00251   IdentityDialog::~IdentityDialog() {
00252     KConfigGroup geometry( KMKernel::config(), "Geometry" );
00253     geometry.writeEntry( "Identity Dialog size", size() );
00254   }
00255 
00256   bool IdentityDialog::checkFolderExists( const QString & folderID,
00257                                           const QString & msg ) {
00258     KMFolder * folder = kmkernel->folderMgr()->findIdString( folderID );
00259     if ( !folder )
00260       folder = kmkernel->imapFolderMgr()->findIdString( folderID );
00261     if ( !folder )
00262       folder = kmkernel->dimapFolderMgr()->findIdString( folderID );
00263     if ( !folder ) {
00264       KMessageBox::sorry( this, msg );
00265       return false;
00266     }
00267     return true;
00268   }
00269 
00270   void IdentityDialog::setIdentity( KMIdentity & ident ) {
00271 
00272     setCaption( i18n("Edit Identity \"%1\"").arg( ident.identityName() ) );
00273 
00274     // "General" tab:
00275     mNameEdit->setText( ident.fullName() );
00276     mOrganizationEdit->setText( ident.organization() );
00277     mEmailEdit->setText( ident.emailAddr() );
00278 
00279     // "Advanced" tab:
00280     mPgpKeyRequester->setKeyIDs( Kpgp::KeyIDList() << ident.pgpIdentity() );
00281     mReplyToEdit->setText( ident.replyToAddr() );
00282     mBccEdit->setText( ident.bcc() );
00283     mTransportCheck->setChecked( !ident.transport().isEmpty() );
00284     mTransportCombo->setEditText( ident.transport() );
00285     mTransportCombo->setEnabled( !ident.transport().isEmpty() );
00286     mDictionaryCombo->setCurrentByDictionary( ident.dictionary() );
00287 
00288     if ( ident.fcc().isEmpty() ||
00289          !checkFolderExists( ident.fcc(),
00290                              i18n("The custom sent-mail folder for identity "
00291                                   "\"%1\" doesn't exist (anymore). "
00292                                   "Therefore the default sent-mail folder "
00293                                   "will be used.")
00294                              .arg( ident.identityName() ) ) )
00295       mFccCombo->setFolder( kmkernel->sentFolder() );
00296     else
00297       mFccCombo->setFolder( ident.fcc() );
00298 
00299     if ( ident.drafts().isEmpty() ||
00300          !checkFolderExists( ident.drafts(),
00301                              i18n("The custom drafts folder for identity "
00302                                   "\"%1\" doesn't exist (anymore). "
00303                                   "Therefore the default drafts folder "
00304                                   "will be used.")
00305                              .arg( ident.identityName() ) ) )
00306       mDraftsCombo->setFolder( kmkernel->draftsFolder() );
00307     else
00308       mDraftsCombo->setFolder( ident.drafts() );
00309 
00310     // "Signature" tab:
00311     mSignatureConfigurator->setSignature( ident.signature() );
00312   }
00313 
00314   void IdentityDialog::updateIdentity( KMIdentity & ident ) {
00315     // "General" tab:
00316     ident.setFullName( mNameEdit->text() );
00317     ident.setOrganization( mOrganizationEdit->text() );
00318     QString email = mEmailEdit->text();
00319     int atCount = email.contains('@');
00320     if ( email.isEmpty() || atCount == 0 )
00321       KMessageBox::sorry( this, "<qt>"+
00322                           i18n("Your email address is not valid because it "
00323                                "doesn't contain a <emph>@</emph>. "
00324                                "You won't create valid messages if you don't "
00325                                "change your address.") + "</qt>",
00326                           i18n("Invalid Email Address") );
00327     else if ( atCount > 1 ) {
00328       KMessageBox::sorry( this, "<qt>" +
00329                           i18n("Your email address is not valid because it "
00330                                "contains more than one <emph>@</emph>. "
00331                                "You won't create valid messages if you don't "
00332                                "change your address.") + "</qt>",
00333                           i18n("Invalid Email Address") );
00334     }
00335     ident.setEmailAddr( email );
00336     // "Advanced" tab:
00337     ident.setPgpIdentity( mPgpKeyRequester->keyIDs().first() );
00338     ident.setReplyToAddr( mReplyToEdit->text() );
00339     ident.setBcc( mBccEdit->text() );
00340     ident.setTransport( ( mTransportCheck->isChecked() ) ?
00341                         mTransportCombo->currentText() : QString::null );
00342     ident.setDictionary( mDictionaryCombo->currentDictionary() );
00343     ident.setFcc( mFccCombo->getFolder() ?
00344                   mFccCombo->getFolder()->idString() : QString::null );
00345     ident.setDrafts( mDraftsCombo->getFolder() ?
00346                      mDraftsCombo->getFolder()->idString() : QString::null );
00347     // "Signature" tab:
00348     ident.setSignature( mSignatureConfigurator->signature() );
00349   }
00350 
00351   void IdentityDialog::slotUpdateTransportCombo( const QStringList & sl ) {
00352     // save old setting:
00353     QString content = mTransportCombo->currentText();
00354     // update combo box:
00355     mTransportCombo->clear();
00356     mTransportCombo->insertStringList( sl );
00357     // restore saved setting:
00358     mTransportCombo->setEditText( content );
00359   }
00360 
00361 }
00362 
00363 #include "identitydialog.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:37:18 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003