kmail

configuredialog.cpp

00001 /*   -*- mode: C++; c-file-style: "gnu" -*-
00002  *   kmail: KDE mail client
00003  *   This file: Copyright (C) 2000 Espen Sand, espen@kde.org
00004  *              Copyright (C) 2001-2003 Marc Mutz, mutz@kde.org
00005  *   Contains code segments and ideas from earlier kmail dialog code.
00006  *
00007  *   This program is free software; you can redistribute it and/or modify
00008  *   it under the terms of the GNU General Public License as published by
00009  *   the Free Software Foundation; either version 2 of the License, or
00010  *   (at your option) any later version.
00011  *
00012  *   This program is distributed in the hope that it will be useful,
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *   GNU General Public License for more details.
00016  *
00017  *   You should have received a copy of the GNU General Public License
00018  *   along with this program; if not, write to the Free Software
00019  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 // This must be first
00024 #include <config.h>
00025 
00026 // my headers:
00027 #include "configuredialog.h"
00028 #include "configuredialog_p.h"
00029 
00030 #include "globalsettings.h"
00031 #include "replyphrases.h"
00032 
00033 // other KMail headers:
00034 #include "kmkernel.h"
00035 #include "simplestringlisteditor.h"
00036 #include "accountdialog.h"
00037 using KMail::AccountDialog;
00038 #include "colorlistbox.h"
00039 #include "kmacctseldlg.h"
00040 #include "messagesender.h"
00041 #include "kmtransport.h"
00042 #include "kmfoldermgr.h"
00043 #include <libkpimidentities/identitymanager.h>
00044 #include "identitylistview.h"
00045 using KMail::IdentityListView;
00046 using KMail::IdentityListViewItem;
00047 #include "kcursorsaver.h"
00048 #include "accountmanager.h"
00049 #include <composercryptoconfiguration.h>
00050 #include <warningconfiguration.h>
00051 #include <smimeconfiguration.h>
00052 #include "folderrequester.h"
00053 using KMail::FolderRequester;
00054 #include "accountcombobox.h"
00055 #include "imapaccountbase.h"
00056 using KMail::ImapAccountBase;
00057 #include "folderstorage.h"
00058 #include "kmfolder.h"
00059 #include "kmmainwidget.h"
00060 #include "recentaddresses.h"
00061 using KRecentAddress::RecentAddresses;
00062 #include "completionordereditor.h"
00063 #include "ldapclient.h"
00064 #include "index.h"
00065 
00066 using KMail::IdentityListView;
00067 using KMail::IdentityListViewItem;
00068 #include "identitydialog.h"
00069 using KMail::IdentityDialog;
00070 
00071 // other kdenetwork headers:
00072 #include <libkpimidentities/identity.h>
00073 #include <kmime_util.h>
00074 using KMime::DateFormatter;
00075 #include <kleo/cryptoconfig.h>
00076 #include <kleo/cryptobackendfactory.h>
00077 #include <ui/backendconfigwidget.h>
00078 #include <ui/keyrequester.h>
00079 #include <ui/keyselectiondialog.h>
00080 
00081 // other KDE headers:
00082 #include <klocale.h>
00083 #include <kapplication.h>
00084 #include <kcharsets.h>
00085 #include <kasciistringtools.h>
00086 #include <kdebug.h>
00087 #include <knuminput.h>
00088 #include <kfontdialog.h>
00089 #include <kmessagebox.h>
00090 #include <kurlrequester.h>
00091 #include <kseparator.h>
00092 #include <kiconloader.h>
00093 #include <kstandarddirs.h>
00094 #include <kwin.h>
00095 #include <knotifydialog.h>
00096 #include <kconfig.h>
00097 #include <kactivelabel.h>
00098 #include <kcmultidialog.h>
00099 
00100 // Qt headers:
00101 #include <qvalidator.h>
00102 #include <qwhatsthis.h>
00103 #include <qvgroupbox.h>
00104 #include <qvbox.h>
00105 #include <qvbuttongroup.h>
00106 #include <qhbuttongroup.h>
00107 #include <qtooltip.h>
00108 #include <qlabel.h>
00109 #include <qtextcodec.h>
00110 #include <qheader.h>
00111 #include <qpopupmenu.h>
00112 #include <qradiobutton.h>
00113 #include <qlayout.h>
00114 #include <qcheckbox.h>
00115 #include <qwidgetstack.h>
00116 
00117 // other headers:
00118 #include <assert.h>
00119 #include <stdlib.h>
00120 
00121 #ifndef _PATH_SENDMAIL
00122 #define _PATH_SENDMAIL  "/usr/sbin/sendmail"
00123 #endif
00124 
00125 #ifdef DIM
00126 #undef DIM
00127 #endif
00128 #define DIM(x) sizeof(x) / sizeof(*x)
00129 
00130 namespace {
00131 
00132   struct EnumConfigEntryItem {
00133     const char * key; // config key value, as appears in config file
00134     const char * desc; // description, to be i18n()ized
00135   };
00136   struct EnumConfigEntry {
00137     const char * group;
00138     const char * key;
00139     const char * desc;
00140     const EnumConfigEntryItem * items;
00141     int numItems;
00142     int defaultItem;
00143   };
00144   struct BoolConfigEntry {
00145     const char * group;
00146     const char * key;
00147     const char * desc;
00148     bool defaultValue;
00149   };
00150 
00151   static const char * lockedDownWarning =
00152     I18N_NOOP("<qt><p>This setting has been fixed by your administrator.</p>"
00153               "<p>If you think this is an error, please contact him.</p></qt>");
00154 
00155   void checkLockDown( QWidget * w, const KConfigBase & c, const char * key ) {
00156     if ( c.entryIsImmutable( key ) ) {
00157       w->setEnabled( false );
00158       QToolTip::add( w, i18n( lockedDownWarning ) );
00159     } else {
00160       QToolTip::remove( w );
00161     }
00162   }
00163 
00164   void populateButtonGroup( QButtonGroup * g, const EnumConfigEntry & e ) {
00165     g->setTitle( i18n( e.desc ) );
00166     g->layout()->setSpacing( KDialog::spacingHint() );
00167     for ( int i = 0 ; i < e.numItems ; ++i )
00168       g->insert( new QRadioButton( i18n( e.items[i].desc ), g ), i );
00169   }
00170 
00171   void populateCheckBox( QCheckBox * b, const BoolConfigEntry & e ) {
00172     b->setText( i18n( e.desc ) );
00173   }
00174 
00175   void loadWidget( QCheckBox * b, const KConfigBase & c, const BoolConfigEntry & e ) {
00176     Q_ASSERT( c.group() == e.group );
00177     checkLockDown( b, c, e.key );
00178     b->setChecked( c.readBoolEntry( e.key, e.defaultValue ) );
00179   }
00180 
00181   void loadWidget( QButtonGroup * g, const KConfigBase & c, const EnumConfigEntry & e ) {
00182     Q_ASSERT( c.group() == e.group );
00183     Q_ASSERT( g->count() == e.numItems );
00184     checkLockDown( g, c, e.key );
00185     const QString s = c.readEntry( e.key, e.items[e.defaultItem].key );
00186     for ( int i = 0 ; i < e.numItems ; ++i )
00187       if ( s == e.items[i].key ) {
00188         g->setButton( i );
00189         return;
00190       }
00191     g->setButton( e.defaultItem );
00192   }
00193 
00194   void saveCheckBox( QCheckBox * b, KConfigBase & c, const BoolConfigEntry & e ) {
00195     Q_ASSERT( c.group() == e.group );
00196     c.writeEntry( e.key, b->isChecked() );
00197   }
00198 
00199   void saveButtonGroup( QButtonGroup * g, KConfigBase & c, const EnumConfigEntry & e ) {
00200     Q_ASSERT( c.group() == e.group );
00201     Q_ASSERT( g->count() == e.numItems );
00202     c.writeEntry( e.key, e.items[ g->id( g->selected() ) ].key );
00203   }
00204 
00205   template <typename T_Widget, typename T_Entry>
00206   inline void loadProfile( T_Widget * g, const KConfigBase & c, const T_Entry & e ) {
00207     if ( c.hasKey( e.key ) )
00208       loadWidget( g, c, e );
00209   }
00210 }
00211 
00212 
00213 ConfigureDialog::ConfigureDialog( QWidget *parent, const char *name, bool modal )
00214   : KCMultiDialog( KDialogBase::IconList, KGuiItem( i18n( "&Load Profile..." ) ),
00215                    KGuiItem(), User2, i18n( "Configure" ), parent, name, modal )
00216   , mProfileDialog( 0 )
00217 {
00218   KWin::setIcons( winId(), kapp->icon(), kapp->miniIcon() );
00219   showButton( User1, true );
00220 
00221   addModule ( "kmail_config_identity", false );
00222   addModule ( "kmail_config_accounts", false );
00223   addModule ( "kmail_config_appearance", false );
00224   addModule ( "kmail_config_composer", false );
00225   addModule ( "kmail_config_security", false );
00226   addModule ( "kmail_config_misc", false );
00227 
00228   // We store the size of the dialog on hide, because otherwise
00229   // the KCMultiDialog starts with the size of the first kcm, not
00230   // the largest one. This way at least after the first showing of
00231   // the largest kcm the size is kept.
00232   KConfigGroup geometry( KMKernel::config(), "Geometry" );
00233   int width = geometry.readNumEntry( "ConfigureDialogWidth" );
00234   int height = geometry.readNumEntry( "ConfigureDialogHeight" );
00235   if ( width != 0 && height != 0 ) {
00236      setMinimumSize( width, height );
00237   }
00238 
00239 }
00240 
00241 void ConfigureDialog::hideEvent( QHideEvent *ev ) {
00242   KConfigGroup geometry( KMKernel::config(), "Geometry" );
00243   geometry.writeEntry( "ConfigureDialogWidth", width() );
00244   geometry.writeEntry( "ConfigureDialogHeight",height() );
00245   KDialogBase::hideEvent( ev );
00246 }
00247 
00248 ConfigureDialog::~ConfigureDialog() {
00249 }
00250 
00251 void ConfigureDialog::slotApply() {
00252   GlobalSettings::self()->writeConfig();
00253   KCMultiDialog::slotApply();
00254 }
00255 
00256 void ConfigureDialog::slotOk() {
00257   GlobalSettings::self()->writeConfig();
00258   KCMultiDialog::slotOk();
00259 }
00260 
00261 void ConfigureDialog::slotUser2() {
00262   if ( mProfileDialog ) {
00263     mProfileDialog->raise();
00264     return;
00265   }
00266   mProfileDialog = new ProfileDialog( this, "mProfileDialog" );
00267   connect( mProfileDialog, SIGNAL(profileSelected(KConfig*)),
00268                 this, SIGNAL(installProfile(KConfig*)) );
00269   mProfileDialog->show();
00270 }
00271 
00272 // *************************************************************
00273 // *                                                           *
00274 // *                      IdentityPage                         *
00275 // *                                                           *
00276 // *************************************************************
00277 QString IdentityPage::helpAnchor() const {
00278   return QString::fromLatin1("configure-identity");
00279 }
00280 
00281 IdentityPage::IdentityPage( QWidget * parent, const char * name )
00282   : ConfigModule( parent, name ),
00283     mIdentityDialog( 0 )
00284 {
00285   QHBoxLayout * hlay = new QHBoxLayout( this, 0, KDialog::spacingHint() );
00286 
00287   mIdentityList = new IdentityListView( this );
00288   connect( mIdentityList, SIGNAL(selectionChanged()),
00289            SLOT(slotIdentitySelectionChanged()) );
00290   connect( mIdentityList, SIGNAL(itemRenamed(QListViewItem*,const QString&,int)),
00291            SLOT(slotRenameIdentity(QListViewItem*,const QString&,int)) );
00292   connect( mIdentityList, SIGNAL(doubleClicked(QListViewItem*,const QPoint&,int)),
00293            SLOT(slotModifyIdentity()) );
00294   connect( mIdentityList, SIGNAL(contextMenu(KListView*,QListViewItem*,const QPoint&)),
00295            SLOT(slotContextMenu(KListView*,QListViewItem*,const QPoint&)) );
00296   // ### connect dragged(...), ...
00297 
00298   hlay->addWidget( mIdentityList, 1 );
00299 
00300   QVBoxLayout * vlay = new QVBoxLayout( hlay ); // inherits spacing
00301 
00302   QPushButton * button = new QPushButton( i18n("&Add..."), this );
00303   mModifyButton = new QPushButton( i18n("&Modify..."), this );
00304   mRenameButton = new QPushButton( i18n("&Rename"), this );
00305   mRemoveButton = new QPushButton( i18n("Remo&ve"), this );
00306   mSetAsDefaultButton = new QPushButton( i18n("Set as &Default"), this );
00307   button->setAutoDefault( false );
00308   mModifyButton->setAutoDefault( false );
00309   mModifyButton->setEnabled( false );
00310   mRenameButton->setAutoDefault( false );
00311   mRenameButton->setEnabled( false );
00312   mRemoveButton->setAutoDefault( false );
00313   mRemoveButton->setEnabled( false );
00314   mSetAsDefaultButton->setAutoDefault( false );
00315   mSetAsDefaultButton->setEnabled( false );
00316   connect( button, SIGNAL(clicked()),
00317            this, SLOT(slotNewIdentity()) );
00318   connect( mModifyButton, SIGNAL(clicked()),
00319            this, SLOT(slotModifyIdentity()) );
00320   connect( mRenameButton, SIGNAL(clicked()),
00321            this, SLOT(slotRenameIdentity()) );
00322   connect( mRemoveButton, SIGNAL(clicked()),
00323            this, SLOT(slotRemoveIdentity()) );
00324   connect( mSetAsDefaultButton, SIGNAL(clicked()),
00325            this, SLOT(slotSetAsDefault()) );
00326   vlay->addWidget( button );
00327   vlay->addWidget( mModifyButton );
00328   vlay->addWidget( mRenameButton );
00329   vlay->addWidget( mRemoveButton );
00330   vlay->addWidget( mSetAsDefaultButton );
00331   vlay->addStretch( 1 );
00332   load();
00333 }
00334 
00335 void IdentityPage::load()
00336 {
00337   KPIM::IdentityManager * im = kmkernel->identityManager();
00338   mOldNumberOfIdentities = im->shadowIdentities().count();
00339   // Fill the list:
00340   mIdentityList->clear();
00341   QListViewItem * item = 0;
00342   for ( KPIM::IdentityManager::Iterator it = im->modifyBegin() ; it != im->modifyEnd() ; ++it )
00343     item = new IdentityListViewItem( mIdentityList, item, *it  );
00344   mIdentityList->setSelected( mIdentityList->currentItem(), true );
00345 }
00346 
00347 void IdentityPage::save() {
00348   assert( !mIdentityDialog );
00349 
00350   kmkernel->identityManager()->sort();
00351   kmkernel->identityManager()->commit();
00352 
00353   if( mOldNumberOfIdentities < 2 && mIdentityList->childCount() > 1 ) {
00354     // have more than one identity, so better show the combo in the
00355     // composer now:
00356     KConfigGroup composer( KMKernel::config(), "Composer" );
00357     int showHeaders = composer.readNumEntry( "headers", HDR_STANDARD );
00358     showHeaders |= HDR_IDENTITY;
00359     composer.writeEntry( "headers", showHeaders );
00360   }
00361   // and now the reverse
00362   if( mOldNumberOfIdentities > 1 && mIdentityList->childCount() < 2 ) {
00363     // have only one identity, so remove the combo in the composer:
00364     KConfigGroup composer( KMKernel::config(), "Composer" );
00365     int showHeaders = composer.readNumEntry( "headers", HDR_STANDARD );
00366     showHeaders &= ~HDR_IDENTITY;
00367     composer.writeEntry( "headers", showHeaders );
00368   }
00369 }
00370 
00371 void IdentityPage::slotNewIdentity()
00372 {
00373   assert( !mIdentityDialog );
00374 
00375   KPIM::IdentityManager * im = kmkernel->identityManager();
00376   NewIdentityDialog dialog( im->shadowIdentities(), this, "new", true );
00377 
00378   if( dialog.exec() == QDialog::Accepted ) {
00379     QString identityName = dialog.identityName().stripWhiteSpace();
00380     assert( !identityName.isEmpty() );
00381 
00382     //
00383     // Construct a new Identity:
00384     //
00385     switch ( dialog.duplicateMode() ) {
00386     case NewIdentityDialog::ExistingEntry:
00387       {
00388         KPIM::Identity & dupThis = im->modifyIdentityForName( dialog.duplicateIdentity() );
00389         im->newFromExisting( dupThis, identityName );
00390         break;
00391       }
00392     case NewIdentityDialog::ControlCenter:
00393       im->newFromControlCenter( identityName );
00394       break;
00395     case NewIdentityDialog::Empty:
00396       im->newFromScratch( identityName );
00397     default: ;
00398     }
00399 
00400     //
00401     // Insert into listview:
00402     //
00403     KPIM::Identity & newIdent = im->modifyIdentityForName( identityName );
00404     QListViewItem * item = mIdentityList->selectedItem();
00405     if ( item )
00406       item = item->itemAbove();
00407     mIdentityList->setSelected( new IdentityListViewItem( mIdentityList,
00408                                                           /*after*/ item,
00409                                                           newIdent ), true );
00410     slotModifyIdentity();
00411   }
00412 }
00413 
00414 void IdentityPage::slotModifyIdentity() {
00415   assert( !mIdentityDialog );
00416 
00417   IdentityListViewItem * item =
00418     dynamic_cast<IdentityListViewItem*>( mIdentityList->selectedItem() );
00419   if ( !item ) return;
00420 
00421   mIdentityDialog = new IdentityDialog( this );
00422   mIdentityDialog->setIdentity( item->identity() );
00423 
00424   // Hmm, an unmodal dialog would be nicer, but a modal one is easier ;-)
00425   if ( mIdentityDialog->exec() == QDialog::Accepted ) {
00426     mIdentityDialog->updateIdentity( item->identity() );
00427     item->redisplay();
00428     emit changed(true);
00429   }
00430 
00431   delete mIdentityDialog;
00432   mIdentityDialog = 0;
00433 }
00434 
00435 void IdentityPage::slotRemoveIdentity()
00436 {
00437   assert( !mIdentityDialog );
00438 
00439   KPIM::IdentityManager * im = kmkernel->identityManager();
00440   kdFatal( im->shadowIdentities().count() < 2 )
00441     << "Attempted to remove the last identity!" << endl;
00442 
00443   IdentityListViewItem * item =
00444     dynamic_cast<IdentityListViewItem*>( mIdentityList->selectedItem() );
00445   if ( !item ) return;
00446 
00447   QString msg = i18n("<qt>Do you really want to remove the identity named "
00448                      "<b>%1</b>?</qt>").arg( item->identity().identityName() );
00449   if( KMessageBox::warningContinueCancel( this, msg, i18n("Remove Identity"),
00450    KGuiItem(i18n("&Remove"),"editdelete") ) == KMessageBox::Continue )
00451     if ( im->removeIdentity( item->identity().identityName() ) ) {
00452       delete item;
00453       mIdentityList->setSelected( mIdentityList->currentItem(), true );
00454       refreshList();
00455     }
00456 }
00457 
00458 void IdentityPage::slotRenameIdentity() {
00459   assert( !mIdentityDialog );
00460 
00461   QListViewItem * item = mIdentityList->selectedItem();
00462   if ( !item ) return;
00463 
00464   mIdentityList->rename( item, 0 );
00465 }
00466 
00467 void IdentityPage::slotRenameIdentity( QListViewItem * i,
00468                                        const QString & s, int col ) {
00469   assert( col == 0 );
00470   Q_UNUSED( col );
00471 
00472   IdentityListViewItem * item = dynamic_cast<IdentityListViewItem*>( i );
00473   if ( !item ) return;
00474 
00475   QString newName = s.stripWhiteSpace();
00476   if ( !newName.isEmpty() &&
00477        !kmkernel->identityManager()->shadowIdentities().contains( newName ) ) {
00478     KPIM::Identity & ident = item->identity();
00479     ident.setIdentityName( newName );
00480     emit changed(true);
00481   }
00482   item->redisplay();
00483 }
00484 
00485 void IdentityPage::slotContextMenu( KListView *, QListViewItem * i,
00486                                     const QPoint & pos ) {
00487   IdentityListViewItem * item = dynamic_cast<IdentityListViewItem*>( i );
00488 
00489   QPopupMenu * menu = new QPopupMenu( this );
00490   menu->insertItem( i18n("Add..."), this, SLOT(slotNewIdentity()) );
00491   if ( item ) {
00492     menu->insertItem( i18n("Modify..."), this, SLOT(slotModifyIdentity()) );
00493     if ( mIdentityList->childCount() > 1 )
00494       menu->insertItem( i18n("Remove"), this, SLOT(slotRemoveIdentity()) );
00495     if ( !item->identity().isDefault() )
00496       menu->insertItem( i18n("Set as Default"), this, SLOT(slotSetAsDefault()) );
00497   }
00498   menu->exec( pos );
00499   delete menu;
00500 }
00501 
00502 
00503 void IdentityPage::slotSetAsDefault() {
00504   assert( !mIdentityDialog );
00505 
00506   IdentityListViewItem * item =
00507     dynamic_cast<IdentityListViewItem*>( mIdentityList->selectedItem() );
00508   if ( !item ) return;
00509 
00510   KPIM::IdentityManager * im = kmkernel->identityManager();
00511   im->setAsDefault( item->identity().identityName() );
00512   refreshList();
00513 }
00514 
00515 void IdentityPage::refreshList() {
00516   for ( QListViewItemIterator it( mIdentityList ) ; it.current() ; ++it ) {
00517     IdentityListViewItem * item =
00518       dynamic_cast<IdentityListViewItem*>(it.current());
00519     if ( item )
00520       item->redisplay();
00521   }
00522   emit changed(true);
00523 }
00524 
00525 void IdentityPage::slotIdentitySelectionChanged()
00526 {
00527   IdentityListViewItem *item =
00528     dynamic_cast<IdentityListViewItem*>( mIdentityList->selectedItem() );
00529 
00530   mRemoveButton->setEnabled( item && mIdentityList->childCount() > 1 );
00531   mModifyButton->setEnabled( item );
00532   mRenameButton->setEnabled( item );
00533   mSetAsDefaultButton->setEnabled( item && !item->identity().isDefault() );
00534 }
00535 
00536 void IdentityPage::slotUpdateTransportCombo( const QStringList & sl )
00537 {
00538   if ( mIdentityDialog ) mIdentityDialog->slotUpdateTransportCombo( sl );
00539 }
00540 
00541 
00542 
00543 // *************************************************************
00544 // *                                                           *
00545 // *                       AccountsPage                         *
00546 // *                                                           *
00547 // *************************************************************
00548 QString AccountsPage::helpAnchor() const {
00549   return QString::fromLatin1("configure-accounts");
00550 }
00551 
00552 AccountsPage::AccountsPage( QWidget * parent, const char * name )
00553   : ConfigModuleWithTabs( parent, name )
00554 {
00555   //
00556   // "Receiving" tab:
00557   //
00558   mReceivingTab = new ReceivingTab();
00559   addTab( mReceivingTab, i18n( "&Receiving" ) );
00560   connect( mReceivingTab, SIGNAL(accountListChanged(const QStringList &)),
00561            this, SIGNAL(accountListChanged(const QStringList &)) );
00562 
00563   //
00564   // "Sending" tab:
00565   //
00566   mSendingTab = new SendingTab();
00567   addTab( mSendingTab, i18n( "&Sending" ) );
00568   connect( mSendingTab, SIGNAL(transportListChanged(const QStringList&)),
00569            this, SIGNAL(transportListChanged(const QStringList&)) );
00570 
00571   load();
00572 }
00573 
00574 QString AccountsPage::SendingTab::helpAnchor() const {
00575   return QString::fromLatin1("configure-accounts-sending");
00576 }
00577 
00578 AccountsPageSendingTab::AccountsPageSendingTab( QWidget * parent, const char * name )
00579   : ConfigModuleTab( parent, name )
00580 {
00581   mTransportInfoList.setAutoDelete( true );
00582   // temp. vars:
00583   QVBoxLayout *vlay;
00584   QVBoxLayout *btn_vlay;
00585   QHBoxLayout *hlay;
00586   QGridLayout *glay;
00587   QPushButton *button;
00588   QGroupBox   *group;
00589 
00590   vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
00591   // label: zero stretch ### FIXME more
00592   vlay->addWidget( new QLabel( i18n("Outgoing accounts (add at least one):"), this ) );
00593 
00594   // hbox layout: stretch 10, spacing inherited from vlay
00595   hlay = new QHBoxLayout();
00596   vlay->addLayout( hlay, 10 ); // high stretch b/c of the groupbox's sizeHint
00597 
00598   // transport list: left widget in hlay; stretch 1
00599   // ### FIXME: allow inline renaming of the account:
00600   mTransportList = new ListView( this, "transportList", 5 );
00601   mTransportList->addColumn( i18n("Name") );
00602   mTransportList->addColumn( i18n("Type") );
00603   mTransportList->setAllColumnsShowFocus( true );
00604   mTransportList->setSorting( -1 );
00605   connect( mTransportList, SIGNAL(selectionChanged()),
00606            this, SLOT(slotTransportSelected()) );
00607   connect( mTransportList, SIGNAL(doubleClicked( QListViewItem *)),
00608            this, SLOT(slotModifySelectedTransport()) );
00609   hlay->addWidget( mTransportList, 1 );
00610 
00611   // a vbox layout for the buttons: zero stretch, spacing inherited from hlay
00612   btn_vlay = new QVBoxLayout( hlay );
00613 
00614   // "add..." button: stretch 0
00615   button = new QPushButton( i18n("A&dd..."), this );
00616   button->setAutoDefault( false );
00617   connect( button, SIGNAL(clicked()),
00618            this, SLOT(slotAddTransport()) );
00619   btn_vlay->addWidget( button );
00620 
00621   // "modify..." button: stretch 0
00622   mModifyTransportButton = new QPushButton( i18n("&Modify..."), this );
00623   mModifyTransportButton->setAutoDefault( false );
00624   mModifyTransportButton->setEnabled( false ); // b/c no item is selected yet
00625   connect( mModifyTransportButton, SIGNAL(clicked()),
00626            this, SLOT(slotModifySelectedTransport()) );
00627   btn_vlay->addWidget( mModifyTransportButton );
00628 
00629   // "remove" button: stretch 0
00630   mRemoveTransportButton = new QPushButton( i18n("R&emove"), this );
00631   mRemoveTransportButton->setAutoDefault( false );
00632   mRemoveTransportButton->setEnabled( false ); // b/c no item is selected yet
00633   connect( mRemoveTransportButton, SIGNAL(clicked()),
00634            this, SLOT(slotRemoveSelectedTransport()) );
00635   btn_vlay->addWidget( mRemoveTransportButton );
00636 
00637   mSetDefaultTransportButton = new QPushButton( i18n("Set Default"), this );
00638   mSetDefaultTransportButton->setAutoDefault( false );
00639   mSetDefaultTransportButton->setEnabled( false );
00640   connect ( mSetDefaultTransportButton, SIGNAL(clicked()),
00641             this, SLOT(slotSetDefaultTransport()) );
00642   btn_vlay->addWidget( mSetDefaultTransportButton );
00643   btn_vlay->addStretch( 1 ); // spacer
00644 
00645   // "Common options" groupbox:
00646   group = new QGroupBox( 0, Qt::Vertical,
00647                          i18n("Common Options"), this );
00648   vlay->addWidget(group);
00649 
00650   // a grid layout for the contents of the "common options" group box
00651   glay = new QGridLayout( group->layout(), 5, 3, KDialog::spacingHint() );
00652   glay->setColStretch( 2, 10 );
00653 
00654   // "confirm before send" check box:
00655   mConfirmSendCheck = new QCheckBox( i18n("Confirm &before send"), group );
00656   glay->addMultiCellWidget( mConfirmSendCheck, 0, 0, 0, 1 );
00657   connect( mConfirmSendCheck, SIGNAL( stateChanged( int ) ),
00658            this, SLOT( slotEmitChanged( void ) ) );
00659 
00660   // "send on check" combo:
00661   mSendOnCheckCombo = new QComboBox( false, group );
00662   mSendOnCheckCombo->insertStringList( QStringList()
00663                                       << i18n("Never Automatically")
00664                                       << i18n("On Manual Mail Checks")
00665                                       << i18n("On All Mail Checks") );
00666   glay->addWidget( mSendOnCheckCombo, 1, 1 );
00667   connect( mSendOnCheckCombo, SIGNAL( activated( int ) ),
00668            this, SLOT( slotEmitChanged( void ) ) );
00669 
00670   // "default send method" combo:
00671   mSendMethodCombo = new QComboBox( false, group );
00672   mSendMethodCombo->insertStringList( QStringList()
00673                                       << i18n("Send Now")
00674                                       << i18n("Send Later") );
00675   glay->addWidget( mSendMethodCombo, 2, 1 );
00676   connect( mSendMethodCombo, SIGNAL( activated( int ) ),
00677            this, SLOT( slotEmitChanged( void ) ) );
00678 
00679 
00680   // "message property" combo:
00681   // ### FIXME: remove completely?
00682   mMessagePropertyCombo = new QComboBox( false, group );
00683   mMessagePropertyCombo->insertStringList( QStringList()
00684                      << i18n("Allow 8-bit")
00685                      << i18n("MIME Compliant (Quoted Printable)") );
00686   glay->addWidget( mMessagePropertyCombo, 3, 1 );
00687   connect( mMessagePropertyCombo, SIGNAL( activated( int ) ),
00688            this, SLOT( slotEmitChanged( void ) ) );
00689 
00690   // "default domain" input field:
00691   mDefaultDomainEdit = new KLineEdit( group );
00692   glay->addMultiCellWidget( mDefaultDomainEdit, 4, 4, 1, 2 );
00693   connect( mDefaultDomainEdit, SIGNAL( textChanged( const QString& ) ),
00694            this, SLOT( slotEmitChanged( void ) ) );
00695 
00696   // labels:
00697   QLabel *l =  new QLabel( mSendOnCheckCombo, /*buddy*/
00698                             i18n("Send &messages in outbox folder:"), group );
00699   glay->addWidget( l, 1, 0 );
00700 
00701   QString msg = i18n( GlobalSettings::self()->sendOnCheckItem()->whatsThis().utf8() );
00702   QWhatsThis::add( l, msg );
00703   QWhatsThis::add( mSendOnCheckCombo, msg );
00704 
00705   glay->addWidget( new QLabel( mSendMethodCombo, /*buddy*/
00706                                i18n("Defa&ult send method:"), group ), 2, 0 );
00707   glay->addWidget( new QLabel( mMessagePropertyCombo, /*buddy*/
00708                                i18n("Message &property:"), group ), 3, 0 );
00709   l = new QLabel( mDefaultDomainEdit, /*buddy*/
00710                           i18n("Defaul&t domain:"), group );
00711   glay->addWidget( l, 4, 0 );
00712 
00713   // and now: add QWhatsThis:
00714   msg = i18n( "<qt><p>The default domain is used to complete email "
00715               "addresses that only consist of the user's name."
00716               "</p></qt>" );
00717   QWhatsThis::add( l, msg );
00718   QWhatsThis::add( mDefaultDomainEdit, msg );
00719 }
00720 
00721 
00722 void AccountsPage::SendingTab::slotTransportSelected()
00723 {
00724   QListViewItem *cur = mTransportList->selectedItem();
00725   mModifyTransportButton->setEnabled( cur );
00726   mRemoveTransportButton->setEnabled( cur );
00727   mSetDefaultTransportButton->setEnabled( cur );
00728 }
00729 
00730 // adds a number to @p name to make the name unique
00731 static inline QString uniqueName( const QStringList & list,
00732                                   const QString & name )
00733 {
00734   int suffix = 1;
00735   QString result = name;
00736   while ( list.find( result ) != list.end() ) {
00737     result = i18n("%1: name; %2: number appended to it to make it unique "
00738                   "among a list of names", "%1 %2")
00739       .arg( name ).arg( suffix );
00740     suffix++;
00741   }
00742   return result;
00743 }
00744 
00745 void AccountsPage::SendingTab::slotSetDefaultTransport()
00746 {
00747   QListViewItem *item = mTransportList->selectedItem();
00748   if ( !item ) return;
00749 
00750   KMTransportInfo ti;
00751 
00752   QListViewItemIterator it( mTransportList );
00753   for ( ; it.current(); ++it ) {
00754   ti.readConfig( KMTransportInfo::findTransport( it.current()->text(0) ));
00755   if ( ti.type != "sendmail" ) {
00756     it.current()->setText( 1, "smtp" );
00757   } else {
00758     it.current()->setText( 1, "sendmail" );
00759     }
00760   }
00761 
00762   if ( item->text(1) != "sendmail" ) {
00763     item->setText( 1, i18n( "smtp (Default)" ));
00764   } else {
00765     item->setText( 1, i18n( "sendmail (Default)" ));
00766   }
00767 
00768   GlobalSettings::self()->setDefaultTransport( item->text(0) );
00769 
00770 }
00771 
00772 void AccountsPage::SendingTab::slotAddTransport()
00773 {
00774   int transportType;
00775 
00776   { // limit scope of selDialog
00777     KMTransportSelDlg selDialog( this );
00778     if ( selDialog.exec() != QDialog::Accepted ) return;
00779     transportType = selDialog.selected();
00780   }
00781 
00782   KMTransportInfo *transportInfo = new KMTransportInfo();
00783   switch ( transportType ) {
00784   case 0: // smtp
00785     transportInfo->type = QString::fromLatin1("smtp");
00786     break;
00787   case 1: // sendmail
00788     transportInfo->type = QString::fromLatin1("sendmail");
00789     transportInfo->name = i18n("Sendmail");
00790     transportInfo->host = _PATH_SENDMAIL; // ### FIXME: use const, not #define
00791     break;
00792   default:
00793     assert( 0 );
00794   }
00795 
00796   KMTransportDialog dialog( i18n("Add Transport"), transportInfo, this );
00797 
00798   // create list of names:
00799   // ### move behind dialog.exec()?
00800   QStringList transportNames;
00801   QPtrListIterator<KMTransportInfo> it( mTransportInfoList );
00802   for ( it.toFirst() ; it.current() ; ++it )
00803     transportNames << (*it)->name;
00804 
00805   if( dialog.exec() != QDialog::Accepted ) {
00806     delete transportInfo;
00807     return;
00808   }
00809 
00810   // disambiguate the name by appending a number:
00811   // ### FIXME: don't allow this error to happen in the first place!
00812   transportInfo->name = uniqueName( transportNames, transportInfo->name );
00813   // append to names and transportinfo lists:
00814   transportNames << transportInfo->name;
00815   mTransportInfoList.append( transportInfo );
00816 
00817   // append to listview:
00818   // ### FIXME: insert before the selected item, append on empty selection
00819   QListViewItem *lastItem = mTransportList->firstChild();
00820   QString typeDisplayName;
00821   if ( lastItem ) {
00822     typeDisplayName = transportInfo->type;
00823   } else {
00824     typeDisplayName = i18n("%1: type of transport. Result used in "
00825                            "Configure->Accounts->Sending listview, \"type\" "
00826                            "column, first row, to indicate that this is the "
00827                            "default transport", "%1 (Default)")
00828       .arg( transportInfo->type );
00829     GlobalSettings::self()->setDefaultTransport( transportInfo->name );
00830   }
00831   (void) new QListViewItem( mTransportList, lastItem, transportInfo->name,
00832                             typeDisplayName );
00833 
00834   // notify anyone who cares:
00835   emit transportListChanged( transportNames );
00836   emit changed( true );
00837 }
00838 
00839 void AccountsPage::SendingTab::slotModifySelectedTransport()
00840 {
00841   QListViewItem *item = mTransportList->selectedItem();
00842   if ( !item ) return;
00843 
00844   QPtrListIterator<KMTransportInfo> it( mTransportInfoList );
00845   for ( it.toFirst() ; it.current() ; ++it )
00846     if ( (*it)->name == item->text(0) ) break;
00847   if ( !it.current() ) return;
00848 
00849   KMTransportDialog dialog( i18n("Modify Transport"), (*it), this );
00850 
00851   if ( dialog.exec() != QDialog::Accepted ) return;
00852 
00853   // create the list of names of transports, but leave out the current
00854   // item:
00855   QStringList transportNames;
00856   QPtrListIterator<KMTransportInfo> jt( mTransportInfoList );
00857   int entryLocation = -1;
00858   for ( jt.toFirst() ; jt.current() ; ++jt )
00859     if ( jt != it )
00860       transportNames << (*jt)->name;
00861     else
00862       entryLocation = transportNames.count();
00863   assert( entryLocation >= 0 );
00864 
00865   // make the new name unique by appending a high enough number:
00866   (*it)->name = uniqueName( transportNames, (*it)->name );
00867   // change the list item to the new name
00868   item->setText( 0, (*it)->name );
00869   // and insert the new name at the position of the old in the list of
00870   // strings; then broadcast the new list:
00871   transportNames.insert( transportNames.at( entryLocation ), (*it)->name );
00872   emit transportListChanged( transportNames );
00873   emit changed( true );
00874 }
00875 
00876 void AccountsPage::SendingTab::slotRemoveSelectedTransport()
00877 {
00878   QListViewItem *item = mTransportList->selectedItem();
00879   if ( !item ) return;
00880 
00881   QStringList changedIdents;
00882   KPIM::IdentityManager * im = kmkernel->identityManager();
00883   for ( KPIM::IdentityManager::Iterator it = im->modifyBegin(); it != im->modifyEnd(); ++it ) {
00884     if ( item->text( 0 ) == (*it).transport() ) {
00885       (*it).setTransport( QString::null );
00886       changedIdents += (*it).identityName();
00887     }
00888   }
00889 
00890   // if the deleted transport is the currently used transport reset it to default
00891   const QString& currentTransport = GlobalSettings::self()->currentTransport();
00892   if ( item->text( 0 ) == currentTransport ) {
00893     GlobalSettings::self()->setCurrentTransport( QString::null );
00894   }
00895 
00896   if ( !changedIdents.isEmpty() ) {
00897     QString information = i18n( "This identity has been changed to use the default transport:",
00898                           "These %n identities have been changed to use the default transport:",
00899                           changedIdents.count() );
00900     KMessageBox::informationList( this, information, changedIdents );
00901   }
00902 
00903   QPtrListIterator<KMTransportInfo> it( mTransportInfoList );
00904   for ( it.toFirst() ; it.current() ; ++it )
00905     if ( (*it)->name == item->text(0) ) break;
00906   if ( !it.current() ) return;
00907 
00908   KMTransportInfo ti;
00909 
00910   QListViewItem *newCurrent = item->itemBelow();
00911   if ( !newCurrent ) newCurrent = item->itemAbove();
00912   //mTransportList->removeItem( item );
00913   if ( newCurrent ) {
00914     mTransportList->setCurrentItem( newCurrent );
00915     mTransportList->setSelected( newCurrent, true );
00916     GlobalSettings::self()->setDefaultTransport( newCurrent->text(0) );
00917     ti.readConfig( KMTransportInfo::findTransport( newCurrent->text(0) ));
00918     if ( item->text( 0 ) == GlobalSettings::self()->defaultTransport() ) {
00919       if ( ti.type != "sendmail" ) {
00920         newCurrent->setText( 1, i18n("smtp (Default)") );
00921       } else {
00922         newCurrent->setText( 1, i18n("sendmail (Default)" ));
00923       }
00924     }
00925   } else {
00926     GlobalSettings::self()->setDefaultTransport( QString::null );
00927   }
00928 
00929   delete item;
00930   mTransportInfoList.remove( it );
00931 
00932   QStringList transportNames;
00933   for ( it.toFirst() ; it.current() ; ++it )
00934     transportNames << (*it)->name;
00935   emit transportListChanged( transportNames );
00936   emit changed( true );
00937 }
00938 
00939 void AccountsPage::SendingTab::doLoadFromGlobalSettings() {
00940   mSendOnCheckCombo->setCurrentItem( GlobalSettings::self()->sendOnCheck() );
00941 }
00942 
00943 void AccountsPage::SendingTab::doLoadOther() {
00944   KConfigGroup general( KMKernel::config(), "General");
00945   KConfigGroup composer( KMKernel::config(), "Composer");
00946 
00947   int numTransports = general.readNumEntry("transports", 0);
00948 
00949   QListViewItem *top = 0;
00950   mTransportInfoList.clear();
00951   mTransportList->clear();
00952   QStringList transportNames;
00953   for ( int i = 1 ; i <= numTransports ; i++ ) {
00954     KMTransportInfo *ti = new KMTransportInfo();
00955     ti->readConfig(i);
00956     mTransportInfoList.append( ti );
00957     transportNames << ti->name;
00958     top = new QListViewItem( mTransportList, top, ti->name, ti->type );
00959   }
00960   emit transportListChanged( transportNames );
00961 
00962   const QString &defaultTransport = GlobalSettings::self()->defaultTransport();
00963 
00964   QListViewItemIterator it( mTransportList );
00965   for ( ; it.current(); ++it ) {
00966     if ( it.current()->text(0) == defaultTransport ) {
00967       if ( it.current()->text(1) != "sendmail" ) {
00968         it.current()->setText( 1, i18n( "smtp (Default)" ));
00969       } else {
00970         it.current()->setText( 1, i18n( "sendmail (Default)" ));
00971       }
00972     } else {
00973       if ( it.current()->text(1) != "sendmail" ) {
00974         it.current()->setText( 1, "smtp" );
00975       } else {
00976         it.current()->setText( 1, "sendmail" );
00977       }
00978     }
00979   }
00980 
00981   mSendMethodCombo->setCurrentItem(
00982                 kmkernel->msgSender()->sendImmediate() ? 0 : 1 );
00983   mMessagePropertyCombo->setCurrentItem(
00984                 kmkernel->msgSender()->sendQuotedPrintable() ? 1 : 0 );
00985 
00986   mConfirmSendCheck->setChecked( composer.readBoolEntry( "confirm-before-send",
00987                                                          false ) );
00988   QString str = general.readEntry( "Default domain" );
00989   if( str.isEmpty() )
00990   {
00991     //### FIXME: Use the global convenience function instead of the homebrewed
00992     //           solution once we can rely on HEAD kdelibs.
00993     //str = KGlobal::hostname(); ???????
00994     char buffer[256];
00995     if ( !gethostname( buffer, 255 ) )
00996       // buffer need not be NUL-terminated if it has full length
00997       buffer[255] = 0;
00998     else
00999       buffer[0] = 0;
01000     str = QString::fromLatin1( *buffer ? buffer : "localhost" );
01001   }
01002   mDefaultDomainEdit->setText( str );
01003 }
01004 
01005 void AccountsPage::SendingTab::save() {
01006   KConfigGroup general( KMKernel::config(), "General" );
01007   KConfigGroup composer( KMKernel::config(), "Composer" );
01008 
01009   // Save transports:
01010   general.writeEntry( "transports", mTransportInfoList.count() );
01011   QPtrListIterator<KMTransportInfo> it( mTransportInfoList );
01012   for ( int i = 1 ; it.current() ; ++it, ++i )
01013     (*it)->writeConfig(i);
01014 
01015   // Save common options:
01016   GlobalSettings::self()->setSendOnCheck( mSendOnCheckCombo->currentItem() );
01017   kmkernel->msgSender()->setSendImmediate(
01018                              mSendMethodCombo->currentItem() == 0 );
01019   kmkernel->msgSender()->setSendQuotedPrintable(
01020                              mMessagePropertyCombo->currentItem() == 1 );
01021   kmkernel->msgSender()->writeConfig( false ); // don't sync
01022   composer.writeEntry("confirm-before-send", mConfirmSendCheck->isChecked() );
01023   general.writeEntry( "Default domain", mDefaultDomainEdit->text() );
01024 }
01025 
01026 QString AccountsPage::ReceivingTab::helpAnchor() const {
01027   return QString::fromLatin1("configure-accounts-receiving");
01028 }
01029 
01030 AccountsPageReceivingTab::AccountsPageReceivingTab( QWidget * parent, const char * name )
01031   : ConfigModuleTab ( parent, name )
01032 {
01033   // temp. vars:
01034   QVBoxLayout *vlay;
01035   QVBoxLayout *btn_vlay;
01036   QHBoxLayout *hlay;
01037   QPushButton *button;
01038   QGroupBox   *group;
01039 
01040   vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
01041 
01042   // label: zero stretch
01043   vlay->addWidget( new QLabel( i18n("Incoming accounts (add at least one):"), this ) );
01044 
01045   // hbox layout: stretch 10, spacing inherited from vlay
01046   hlay = new QHBoxLayout();
01047   vlay->addLayout( hlay, 10 ); // high stretch to suppress groupbox's growing
01048 
01049   // account list: left widget in hlay; stretch 1
01050   mAccountList = new ListView( this, "accountList", 5 );
01051   mAccountList->addColumn( i18n("Name") );
01052   mAccountList->addColumn( i18n("Type") );
01053   mAccountList->addColumn( i18n("Folder") );
01054   mAccountList->setAllColumnsShowFocus( true );
01055   mAccountList->setSorting( -1 );
01056   connect( mAccountList, SIGNAL(selectionChanged()),
01057            this, SLOT(slotAccountSelected()) );
01058   connect( mAccountList, SIGNAL(doubleClicked( QListViewItem *)),
01059            this, SLOT(slotModifySelectedAccount()) );
01060   hlay->addWidget( mAccountList, 1 );
01061 
01062   // a vbox layout for the buttons: zero stretch, spacing inherited from hlay
01063   btn_vlay = new QVBoxLayout( hlay );
01064 
01065   // "add..." button: stretch 0
01066   button = new QPushButton( i18n("A&dd..."), this );
01067   button->setAutoDefault( false );
01068   connect( button, SIGNAL(clicked()),
01069            this, SLOT(slotAddAccount()) );
01070   btn_vlay->addWidget( button );
01071 
01072   // "modify..." button: stretch 0
01073   mModifyAccountButton = new QPushButton( i18n("&Modify..."), this );
01074   mModifyAccountButton->setAutoDefault( false );
01075   mModifyAccountButton->setEnabled( false ); // b/c no item is selected yet
01076   connect( mModifyAccountButton, SIGNAL(clicked()),
01077            this, SLOT(slotModifySelectedAccount()) );
01078   btn_vlay->addWidget( mModifyAccountButton );
01079 
01080   // "remove..." button: stretch 0
01081   mRemoveAccountButton = new QPushButton( i18n("R&emove"), this );
01082   mRemoveAccountButton->setAutoDefault( false );
01083   mRemoveAccountButton->setEnabled( false ); // b/c no item is selected yet
01084   connect( mRemoveAccountButton, SIGNAL(clicked()),
01085            this, SLOT(slotRemoveSelectedAccount()) );
01086   btn_vlay->addWidget( mRemoveAccountButton );
01087   btn_vlay->addStretch( 1 ); // spacer
01088 
01089   mCheckmailStartupCheck = new QCheckBox( i18n("Chec&k mail on startup"), this );
01090   vlay->addWidget( mCheckmailStartupCheck );
01091   connect( mCheckmailStartupCheck, SIGNAL( stateChanged( int ) ),
01092            this, SLOT( slotEmitChanged( void ) ) );
01093 
01094   // "New Mail Notification" group box: stretch 0
01095   group = new QVGroupBox( i18n("New Mail Notification"), this );
01096   vlay->addWidget( group );
01097   group->layout()->setSpacing( KDialog::spacingHint() );
01098 
01099   // "beep on new mail" check box:
01100   mBeepNewMailCheck = new QCheckBox(i18n("&Beep"), group );
01101   mBeepNewMailCheck->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding,
01102                                                  QSizePolicy::Fixed ) );
01103   connect( mBeepNewMailCheck, SIGNAL( stateChanged( int ) ),
01104            this, SLOT( slotEmitChanged( void ) ) );
01105 
01106   // "Detailed new mail notification" check box
01107   mVerboseNotificationCheck =
01108     new QCheckBox( i18n( "Deta&iled new mail notification" ), group );
01109   mVerboseNotificationCheck->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding,
01110                                                          QSizePolicy::Fixed ) );
01111   QToolTip::add( mVerboseNotificationCheck,
01112                  i18n( "Show for each folder the number of newly arrived "
01113                        "messages" ) );
01114   QWhatsThis::add( mVerboseNotificationCheck,
01115     GlobalSettings::self()->verboseNewMailNotificationItem()->whatsThis() );
01116   connect( mVerboseNotificationCheck, SIGNAL( stateChanged( int ) ),
01117            this, SLOT( slotEmitChanged() ) );
01118 
01119   // "Other Actions" button:
01120   mOtherNewMailActionsButton = new QPushButton( i18n("Other Actio&ns"), group );
01121   mOtherNewMailActionsButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed,
01122                                                           QSizePolicy::Fixed ) );
01123   connect( mOtherNewMailActionsButton, SIGNAL(clicked()),
01124            this, SLOT(slotEditNotifications()) );
01125 }
01126 
01127 
01128 void AccountsPage::ReceivingTab::slotAccountSelected()
01129 {
01130   QListViewItem * item = mAccountList->selectedItem();
01131   mModifyAccountButton->setEnabled( item );
01132   mRemoveAccountButton->setEnabled( item );
01133 }
01134 
01135 QStringList AccountsPage::ReceivingTab::occupiedNames()
01136 {
01137   QStringList accountNames = kmkernel->acctMgr()->getAccounts();
01138 
01139   QValueList<ModifiedAccountsType*>::Iterator k;
01140   for (k = mModifiedAccounts.begin(); k != mModifiedAccounts.end(); ++k )
01141     if ((*k)->oldAccount)
01142       accountNames.remove( (*k)->oldAccount->name() );
01143 
01144   QValueList< QGuardedPtr<KMAccount> >::Iterator l;
01145   for (l = mAccountsToDelete.begin(); l != mAccountsToDelete.end(); ++l )
01146     if (*l)
01147       accountNames.remove( (*l)->name() );
01148 
01149   QValueList< QGuardedPtr<KMAccount> >::Iterator it;
01150   for (it = mNewAccounts.begin(); it != mNewAccounts.end(); ++it )
01151     if (*it)
01152       accountNames += (*it)->name();
01153 
01154   QValueList<ModifiedAccountsType*>::Iterator j;
01155   for (j = mModifiedAccounts.begin(); j != mModifiedAccounts.end(); ++j )
01156     accountNames += (*j)->newAccount->name();
01157 
01158   return accountNames;
01159 }
01160 
01161 void AccountsPage::ReceivingTab::slotAddAccount() {
01162   KMAcctSelDlg accountSelectorDialog( this );
01163   if( accountSelectorDialog.exec() != QDialog::Accepted ) return;
01164 
01165   const char *accountType = 0;
01166   switch ( accountSelectorDialog.selected() ) {
01167     case 0: accountType = "local";      break;
01168     case 1: accountType = "pop";        break;
01169     case 2: accountType = "imap";       break;
01170     case 3: accountType = "cachedimap"; break;
01171     case 4: accountType = "maildir";    break;
01172 
01173     default:
01174       // ### FIXME: How should this happen???
01175       // replace with assert.
01176       KMessageBox::sorry( this, i18n("Unknown account type selected") );
01177       return;
01178   }
01179 
01180   KMAccount *account
01181     = kmkernel->acctMgr()->create( QString::fromLatin1( accountType ) );
01182   if ( !account ) {
01183     // ### FIXME: Give the user more information. Is this error
01184     // recoverable?
01185     KMessageBox::sorry( this, i18n("Unable to create account") );
01186     return;
01187   }
01188 
01189   account->init(); // fill the account fields with good default values
01190 
01191   AccountDialog dialog( i18n("Add Account"), account, this );
01192 
01193   QStringList accountNames = occupiedNames();
01194 
01195   if( dialog.exec() != QDialog::Accepted ) {
01196     delete account;
01197     return;
01198   }
01199 
01200   account->deinstallTimer();
01201   account->setName( uniqueName( accountNames, account->name() ) );
01202 
01203   QListViewItem *after = mAccountList->firstChild();
01204   while ( after && after->nextSibling() )
01205     after = after->nextSibling();
01206 
01207   QListViewItem *listItem =
01208     new QListViewItem( mAccountList, after, account->name(), account->type() );
01209   if( account->folder() )
01210     listItem->setText( 2, account->folder()->label() );
01211 
01212   mNewAccounts.append( account );
01213   emit changed( true );
01214 }
01215 
01216 
01217 
01218 void AccountsPage::ReceivingTab::slotModifySelectedAccount()
01219 {
01220   QListViewItem *listItem = mAccountList->selectedItem();
01221   if( !listItem ) return;
01222 
01223   KMAccount *account = 0;
01224   QValueList<ModifiedAccountsType*>::Iterator j;
01225   for (j = mModifiedAccounts.begin(); j != mModifiedAccounts.end(); ++j )
01226     if ( (*j)->newAccount->name() == listItem->text(0) ) {
01227       account = (*j)->newAccount;
01228       break;
01229     }
01230 
01231   if ( !account ) {
01232     QValueList< QGuardedPtr<KMAccount> >::Iterator it;
01233     for ( it = mNewAccounts.begin() ; it != mNewAccounts.end() ; ++it )
01234       if ( (*it)->name() == listItem->text(0) ) {
01235         account = *it;
01236         break;
01237       }
01238 
01239     if ( !account ) {
01240       account = kmkernel->acctMgr()->findByName( listItem->text(0) );
01241       if( !account ) {
01242         // ### FIXME: How should this happen? See above.
01243         KMessageBox::sorry( this, i18n("Unable to locate account") );
01244         return;
01245       }
01246       if ( account->type() == "imap" || account->type() == "cachedimap" )
01247       {
01248         ImapAccountBase* ai = static_cast<ImapAccountBase*>( account );
01249         if ( ai->namespaces().isEmpty() || ai->namespaceToDelimiter().isEmpty() )
01250         {
01251           // connect to server - the namespaces are fetched automatically
01252           kdDebug(5006) << "slotModifySelectedAccount - connect" << endl;
01253           ai->makeConnection();
01254         }
01255       }
01256 
01257       ModifiedAccountsType *mod = new ModifiedAccountsType;
01258       mod->oldAccount = account;
01259       mod->newAccount = kmkernel->acctMgr()->create( account->type(),
01260                                                    account->name() );
01261       mod->newAccount->pseudoAssign( account );
01262       mModifiedAccounts.append( mod );
01263       account = mod->newAccount;
01264     }
01265   }
01266 
01267   QStringList accountNames = occupiedNames();
01268   accountNames.remove( account->name() );
01269 
01270   AccountDialog dialog( i18n("Modify Account"), account, this );
01271 
01272   if( dialog.exec() != QDialog::Accepted ) return;
01273 
01274   account->setName( uniqueName( accountNames, account->name() ) );
01275 
01276   listItem->setText( 0, account->name() );
01277   listItem->setText( 1, account->type() );
01278   if( account->folder() )
01279     listItem->setText( 2, account->folder()->label() );
01280 
01281   emit changed( true );
01282 }
01283 
01284 
01285 
01286 void AccountsPage::ReceivingTab::slotRemoveSelectedAccount() {
01287   QListViewItem *listItem = mAccountList->selectedItem();
01288   if( !listItem ) return;
01289 
01290   KMAccount *acct = 0;
01291   QValueList<ModifiedAccountsType*>::Iterator j;
01292   for ( j = mModifiedAccounts.begin() ; j != mModifiedAccounts.end() ; ++j )
01293     if ( (*j)->newAccount->name() == listItem->text(0) ) {
01294       acct = (*j)->oldAccount;
01295       mAccountsToDelete.append( acct );
01296       mModifiedAccounts.remove( j );
01297       break;
01298     }
01299   if ( !acct ) {
01300     QValueList< QGuardedPtr<KMAccount> >::Iterator it;
01301     for ( it = mNewAccounts.begin() ; it != mNewAccounts.end() ; ++it )
01302       if ( (*it)->name() == listItem->text(0) ) {
01303         acct = *it;
01304         mNewAccounts.remove( it );
01305         break;
01306       }
01307   }
01308   if ( !acct ) {
01309     acct = kmkernel->acctMgr()->findByName( listItem->text(0) );
01310     if ( acct )
01311       mAccountsToDelete.append( acct );
01312   }
01313   if ( !acct ) {
01314     // ### FIXME: see above
01315     KMessageBox::sorry( this, i18n("<qt>Unable to locate account <b>%1</b>.</qt>")
01316                         .arg(listItem->text(0)) );
01317     return;
01318   }
01319 
01320   QListViewItem * item = listItem->itemBelow();
01321   if ( !item ) item = listItem->itemAbove();
01322   delete listItem;
01323 
01324   if ( item )
01325     mAccountList->setSelected( item, true );
01326 
01327   emit changed( true );
01328 }
01329 
01330 void AccountsPage::ReceivingTab::slotEditNotifications()
01331 {
01332   if(kmkernel->xmlGuiInstance())
01333     KNotifyDialog::configure(this, 0, kmkernel->xmlGuiInstance()->aboutData());
01334   else
01335     KNotifyDialog::configure(this);
01336 }
01337 
01338 void AccountsPage::ReceivingTab::doLoadFromGlobalSettings() {
01339   mVerboseNotificationCheck->setChecked( GlobalSettings::self()->verboseNewMailNotification() );
01340 }
01341 
01342 void AccountsPage::ReceivingTab::doLoadOther() {
01343   KConfigGroup general( KMKernel::config(), "General" );
01344 
01345   mAccountList->clear();
01346   QListViewItem *top = 0;
01347 
01348   for( KMAccount *a = kmkernel->acctMgr()->first(); a!=0;
01349        a = kmkernel->acctMgr()->next() ) {
01350     QListViewItem *listItem =
01351       new QListViewItem( mAccountList, top, a->name(), a->type() );
01352     if( a->folder() )
01353       listItem->setText( 2, a->folder()->label() );
01354     top = listItem;
01355   }
01356   QListViewItem *listItem = mAccountList->firstChild();
01357   if ( listItem ) {
01358     mAccountList->setCurrentItem( listItem );
01359     mAccountList->setSelected( listItem, true );
01360   }
01361 
01362   mBeepNewMailCheck->setChecked( general.readBoolEntry("beep-on-mail", false ) );
01363   mCheckmailStartupCheck->setChecked( general.readBoolEntry("checkmail-startup", false) );
01364   QTimer::singleShot( 0, this, SLOT( slotTweakAccountList() ) );
01365 }
01366 
01367 void AccountsPage::ReceivingTab::slotTweakAccountList()
01368 {
01369   // Force the contentsWidth of mAccountList to be recalculated so that items can be
01370   // selected in the normal way. It would be best if this were not necessary.
01371   mAccountList->resizeContents( mAccountList->visibleWidth(), mAccountList->contentsHeight() );
01372 }
01373 
01374 void AccountsPage::ReceivingTab::save() {
01375   // Add accounts marked as new
01376   QValueList< QGuardedPtr<KMAccount> >::Iterator it;
01377   for (it = mNewAccounts.begin(); it != mNewAccounts.end(); ++it ) {
01378     kmkernel->acctMgr()->add( *it );
01379     (*it)->installTimer();
01380   }
01381 
01382   // Update accounts that have been modified
01383   QValueList<ModifiedAccountsType*>::Iterator j;
01384   for ( j = mModifiedAccounts.begin() ; j != mModifiedAccounts.end() ; ++j ) {
01385     (*j)->oldAccount->pseudoAssign( (*j)->newAccount );
01386     delete (*j)->newAccount;
01387     delete (*j);
01388   }
01389   mModifiedAccounts.clear();
01390 
01391   // Delete accounts marked for deletion
01392   for ( it = mAccountsToDelete.begin() ;
01393         it != mAccountsToDelete.end() ; ++it ) {
01394     kmkernel->acctMgr()->writeConfig( true );
01395     if ( (*it) && !kmkernel->acctMgr()->remove(*it) )
01396       KMessageBox::sorry( this, i18n("<qt>Unable to locate account <b>%1</b>.</qt>")
01397                           .arg( (*it)->name() ) );
01398   }
01399   mAccountsToDelete.clear();
01400 
01401   // Incoming mail
01402   kmkernel->acctMgr()->writeConfig( false );
01403   kmkernel->cleanupImapFolders();
01404 
01405   // Save Mail notification settings
01406   KConfigGroup general( KMKernel::config(), "General" );
01407   general.writeEntry( "beep-on-mail", mBeepNewMailCheck->isChecked() );
01408   GlobalSettings::self()->setVerboseNewMailNotification( mVerboseNotificationCheck->isChecked() );
01409 
01410   general.writeEntry( "checkmail-startup", mCheckmailStartupCheck->isChecked() );
01411 
01412   // Sync new IMAP accounts ASAP:
01413   for (it = mNewAccounts.begin(); it != mNewAccounts.end(); ++it ) {
01414     KMAccount *macc = (*it);
01415     ImapAccountBase *acc = dynamic_cast<ImapAccountBase*> (macc);
01416     if ( acc ) {
01417       AccountUpdater *au = new AccountUpdater( acc );
01418       au->update();
01419     }
01420   }
01421   mNewAccounts.clear();
01422 
01423 }
01424 
01425 // *************************************************************
01426 // *                                                           *
01427 // *                     AppearancePage                        *
01428 // *                                                           *
01429 // *************************************************************
01430 QString AppearancePage::helpAnchor() const {
01431   return QString::fromLatin1("configure-appearance");
01432 }
01433 
01434 AppearancePage::AppearancePage( QWidget * parent, const char * name )
01435   : ConfigModuleWithTabs( parent, name )
01436 {
01437   //
01438   // "Fonts" tab:
01439   //
01440   mFontsTab = new FontsTab();
01441   addTab( mFontsTab, i18n("&Fonts") );
01442 
01443   //
01444   // "Colors" tab:
01445   //
01446   mColorsTab = new ColorsTab();
01447   addTab( mColorsTab, i18n("Color&s") );
01448 
01449   //
01450   // "Layout" tab:
01451   //
01452   mLayoutTab = new LayoutTab();
01453   addTab( mLayoutTab, i18n("La&yout") );
01454 
01455   //
01456   // "Headers" tab:
01457   //
01458   mHeadersTab = new HeadersTab();
01459   addTab( mHeadersTab, i18n("M&essage List") );
01460 
01461   //
01462   // "Reader window" tab:
01463   //
01464   mReaderTab = new ReaderTab();
01465   addTab( mReaderTab, i18n("Message W&indow") );
01466 
01467   //
01468   // "System Tray" tab:
01469   //
01470   mSystemTrayTab = new SystemTrayTab();
01471   addTab( mSystemTrayTab, i18n("System &Tray") );
01472 
01473   load();
01474 }
01475 
01476 
01477 QString AppearancePage::FontsTab::helpAnchor() const {
01478   return QString::fromLatin1("configure-appearance-fonts");
01479 }
01480 
01481 static const struct {
01482   const char * configName;
01483   const char * displayName;
01484   bool   enableFamilyAndSize;
01485   bool   onlyFixed;
01486 } fontNames[] = {
01487   { "body-font", I18N_NOOP("Message Body"), true, false },
01488   { "list-font", I18N_NOOP("Message List"), true, false },
01489   { "list-new-font", I18N_NOOP("Message List - New Messages"), true, false },
01490   { "list-unread-font", I18N_NOOP("Message List - Unread Messages"), true, false },
01491   { "list-important-font", I18N_NOOP("Message List - Important Messages"), true, false },
01492   { "list-todo-font", I18N_NOOP("Message List - Todo Messages"), true, false },
01493   { "list-date-font", I18N_NOOP("Message List - Date Field"), true, false },
01494   { "folder-font", I18N_NOOP("Folder List"), true, false },
01495   { "quote1-font", I18N_NOOP("Quoted Text - First Level"), false, false },
01496   { "quote2-font", I18N_NOOP("Quoted Text - Second Level"), false, false },
01497   { "quote3-font", I18N_NOOP("Quoted Text - Third Level"), false, false },
01498   { "fixed-font", I18N_NOOP("Fixed Width Font"), true, true },
01499   { "composer-font", I18N_NOOP("Composer"), true, false },
01500   { "print-font",  I18N_NOOP("Printing Output"), true, false },
01501 };
01502 static const int numFontNames = sizeof fontNames / sizeof *fontNames;
01503 
01504 AppearancePageFontsTab::AppearancePageFontsTab( QWidget * parent, const char * name )
01505   : ConfigModuleTab( parent, name ), mActiveFontIndex( -1 )
01506 {
01507   assert( numFontNames == sizeof mFont / sizeof *mFont );
01508   // tmp. vars:
01509   QVBoxLayout *vlay;
01510   QHBoxLayout *hlay;
01511   QLabel      *label;
01512 
01513   // "Use custom fonts" checkbox, followed by <hr>
01514   vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
01515   mCustomFontCheck = new QCheckBox( i18n("&Use custom fonts"), this );
01516   vlay->addWidget( mCustomFontCheck );
01517   vlay->addWidget( new KSeparator( KSeparator::HLine, this ) );
01518   connect ( mCustomFontCheck, SIGNAL( stateChanged( int ) ),
01519             this, SLOT( slotEmitChanged( void ) ) );
01520 
01521   // "font location" combo box and label:
01522   hlay = new QHBoxLayout( vlay ); // inherites spacing
01523   mFontLocationCombo = new QComboBox( false, this );
01524   mFontLocationCombo->setEnabled( false ); // !mCustomFontCheck->isChecked()
01525 
01526   QStringList fontDescriptions;
01527   for ( int i = 0 ; i < numFontNames ; i++ )
01528     fontDescriptions << i18n( fontNames[i].displayName );
01529   mFontLocationCombo->insertStringList( fontDescriptions );
01530 
01531   label = new QLabel( mFontLocationCombo, i18n("Apply &to:"), this );
01532   label->setEnabled( false ); // since !mCustomFontCheck->isChecked()
01533   hlay->addWidget( label );
01534 
01535   hlay->addWidget( mFontLocationCombo );
01536   hlay->addStretch( 10 );
01537   vlay->addSpacing( KDialog::spacingHint() );
01538   mFontChooser = new KFontChooser( this, "font", false, QStringList(),
01539                                    false, 4 );
01540   mFontChooser->setEnabled( false ); // since !mCustomFontCheck->isChecked()
01541   vlay->addWidget( mFontChooser );
01542   connect ( mFontChooser, SIGNAL( fontSelected( const QFont& ) ),
01543             this, SLOT( slotEmitChanged( void ) ) );
01544 
01545 
01546   // {en,dis}able widgets depending on the state of mCustomFontCheck:
01547   connect( mCustomFontCheck, SIGNAL(toggled(bool)),
01548            label, SLOT(setEnabled(bool)) );
01549   connect( mCustomFontCheck, SIGNAL(toggled(bool)),
01550            mFontLocationCombo, SLOT(setEnabled(bool)) );
01551   connect( mCustomFontCheck, SIGNAL(toggled(bool)),
01552            mFontChooser, SLOT(setEnabled(bool)) );
01553   // load the right font settings into mFontChooser:
01554   connect( mFontLocationCombo, SIGNAL(activated(int) ),
01555            this, SLOT(slotFontSelectorChanged(int)) );
01556 }
01557 
01558 
01559 void AppearancePage::FontsTab::slotFontSelectorChanged( int index )
01560 {
01561   kdDebug(5006) << "slotFontSelectorChanged() called" << endl;
01562   if( index < 0 || index >= mFontLocationCombo->count() )
01563     return; // Should never happen, but it is better to check.
01564 
01565   // Save current fontselector setting before we install the new:
01566   if( mActiveFontIndex == 0 ) {
01567     mFont[0] = mFontChooser->font();
01568     // hardcode the family and size of "message body" dependant fonts:
01569     for ( int i = 0 ; i < numFontNames ; i++ )
01570       if ( !fontNames[i].enableFamilyAndSize ) {
01571         // ### shall we copy the font and set the save and re-set
01572         // {regular,italic,bold,bold italic} property or should we
01573         // copy only family and pointSize?
01574         mFont[i].setFamily( mFont[0].family() );
01575         mFont[i].setPointSize/*Float?*/( mFont[0].pointSize/*Float?*/() );
01576       }
01577   } else if ( mActiveFontIndex > 0 )
01578     mFont[ mActiveFontIndex ] = mFontChooser->font();
01579   mActiveFontIndex = index;
01580 
01581   // Disonnect so the "Apply" button is not activated by the change
01582   disconnect ( mFontChooser, SIGNAL( fontSelected( const QFont& ) ),
01583             this, SLOT( slotEmitChanged( void ) ) );
01584 
01585   // Display the new setting:
01586   mFontChooser->setFont( mFont[index], fontNames[index].onlyFixed );
01587 
01588   connect ( mFontChooser, SIGNAL( fontSelected( const QFont& ) ),
01589             this, SLOT( slotEmitChanged( void ) ) );
01590 
01591   // Disable Family and Size list if we have selected a quote font:
01592   mFontChooser->enableColumn( KFontChooser::FamilyList|KFontChooser::SizeList,
01593                               fontNames[ index ].enableFamilyAndSize );
01594 }
01595 
01596 void AppearancePage::FontsTab::doLoadOther() {
01597   KConfigGroup fonts( KMKernel::config(), "Fonts" );
01598 
01599   mFont[0] = KGlobalSettings::generalFont();
01600   QFont fixedFont = KGlobalSettings::fixedFont();
01601   for ( int i = 0 ; i < numFontNames ; i++ )
01602     mFont[i] = fonts.readFontEntry( fontNames[i].configName,
01603       (fontNames[i].onlyFixed) ? &fixedFont : &mFont[0] );
01604 
01605   mCustomFontCheck->setChecked( !fonts.readBoolEntry( "defaultFonts", true ) );
01606   mFontLocationCombo->setCurrentItem( 0 );
01607   slotFontSelectorChanged( 0 );
01608 }
01609 
01610 void AppearancePage::FontsTab::installProfile( KConfig * profile ) {
01611   KConfigGroup fonts( profile, "Fonts" );
01612 
01613   // read fonts that are defined in the profile:
01614   bool needChange = false;
01615   for ( int i = 0 ; i < numFontNames ; i++ )
01616     if ( fonts.hasKey( fontNames[i].configName ) ) {
01617       needChange = true;
01618       mFont[i] = fonts.readFontEntry( fontNames[i].configName );
01619       kdDebug(5006) << "got font \"" << fontNames[i].configName
01620                 << "\" thusly: \"" << mFont[i].toString() << "\"" << endl;
01621     }
01622   if ( needChange && mFontLocationCombo->currentItem() > 0 )
01623     mFontChooser->setFont( mFont[ mFontLocationCombo->currentItem() ],
01624       fontNames[ mFontLocationCombo->currentItem() ].onlyFixed );
01625 
01626   if ( fonts.hasKey( "defaultFonts" ) )
01627     mCustomFontCheck->setChecked( !fonts.readBoolEntry( "defaultFonts" ) );
01628 }
01629 
01630 void AppearancePage::FontsTab::save() {
01631   KConfigGroup fonts( KMKernel::config(), "Fonts" );
01632 
01633   // read the current font (might have been modified)
01634   if ( mActiveFontIndex >= 0 )
01635     mFont[ mActiveFontIndex ] = mFontChooser->font();
01636 
01637   bool customFonts = mCustomFontCheck->isChecked();
01638   fonts.writeEntry( "defaultFonts", !customFonts );
01639   for ( int i = 0 ; i < numFontNames ; i++ )
01640     if ( customFonts || fonts.hasKey( fontNames[i].configName ) )
01641       // Don't write font info when we use default fonts, but write
01642       // if it's already there:
01643       fonts.writeEntry( fontNames[i].configName, mFont[i] );
01644 }
01645 
01646 QString AppearancePage::ColorsTab::helpAnchor() const {
01647   return QString::fromLatin1("configure-appearance-colors");
01648 }
01649 
01650 
01651 static const struct {
01652   const char * configName;
01653   const char * displayName;
01654 } colorNames[] = { // adjust setup() if you change this:
01655   { "BackgroundColor", I18N_NOOP("Composer Background") },
01656   { "AltBackgroundColor", I18N_NOOP("Alternative Background Color") },
01657   { "ForegroundColor", I18N_NOOP("Normal Text") },
01658   { "QuotedText1", I18N_NOOP("Quoted Text - First Level") },
01659   { "QuotedText2", I18N_NOOP("Quoted Text - Second Level") },
01660   { "QuotedText3", I18N_NOOP("Quoted Text - Third Level") },
01661   { "LinkColor", I18N_NOOP("Link") },
01662   { "FollowedColor", I18N_NOOP("Followed Link") },
01663   { "MisspelledColor", I18N_NOOP("Misspelled Words") },
01664   { "NewMessage", I18N_NOOP("New Message") },
01665   { "UnreadMessage", I18N_NOOP("Unread Message") },
01666   { "FlagMessage", I18N_NOOP("Important Message") },
01667   { "TodoMessage", I18N_NOOP("Todo Message") },
01668   { "PGPMessageEncr", I18N_NOOP("OpenPGP Message - Encrypted") },
01669   { "PGPMessageOkKeyOk", I18N_NOOP("OpenPGP Message - Valid Signature with Trusted Key") },
01670   { "PGPMessageOkKeyBad", I18N_NOOP("OpenPGP Message - Valid Signature with Untrusted Key") },
01671   { "PGPMessageWarn", I18N_NOOP("OpenPGP Message - Unchecked Signature") },
01672   { "PGPMessageErr", I18N_NOOP("OpenPGP Message - Bad Signature") },
01673   { "HTMLWarningColor", I18N_NOOP("Border Around Warning Prepending HTML Messages") },
01674   { "ColorbarBackgroundPlain", I18N_NOOP("HTML Status Bar Background - No HTML Message") },
01675   { "ColorbarForegroundPlain", I18N_NOOP("HTML Status Bar Foreground - No HTML Message") },
01676   { "ColorbarBackgroundHTML",  I18N_NOOP("HTML Status Bar Background - HTML Message") },
01677   { "ColorbarForegroundHTML",  I18N_NOOP("HTML Status Bar Foreground - HTML Message") },
01678 };
01679 static const int numColorNames = sizeof colorNames / sizeof *colorNames;
01680 
01681 AppearancePageColorsTab::AppearancePageColorsTab( QWidget * parent, const char * name )
01682   : ConfigModuleTab( parent, name )
01683 {
01684   // tmp. vars:
01685   QVBoxLayout *vlay;
01686 
01687   // "use custom colors" check box
01688   vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
01689   mCustomColorCheck = new QCheckBox( i18n("&Use custom colors"), this );
01690   vlay->addWidget( mCustomColorCheck );
01691   connect( mCustomColorCheck, SIGNAL( stateChanged( int ) ),
01692            this, SLOT( slotEmitChanged( void ) ) );
01693 
01694   // color list box:
01695   mColorList = new ColorListBox( this );
01696   mColorList->setEnabled( false ); // since !mCustomColorCheck->isChecked()
01697   QStringList modeList;
01698   for ( int i = 0 ; i < numColorNames ; i++ )
01699     mColorList->insertItem( new ColorListItem( i18n( colorNames[i].displayName ) ) );
01700   vlay->addWidget( mColorList, 1 );
01701 
01702   // "recycle colors" check box:
01703   mRecycleColorCheck =
01704     new QCheckBox( i18n("Recycle colors on deep &quoting"), this );
01705   mRecycleColorCheck->setEnabled( false );
01706   vlay->addWidget( mRecycleColorCheck );
01707   connect( mRecycleColorCheck, SIGNAL( stateChanged( int ) ),
01708            this, SLOT( slotEmitChanged( void ) ) );
01709 
01710   // {en,dir}able widgets depending on the state of mCustomColorCheck:
01711   connect( mCustomColorCheck, SIGNAL(toggled(bool)),
01712            mColorList, SLOT(setEnabled(bool)) );
01713   connect( mCustomColorCheck, SIGNAL(toggled(bool)),
01714            mRecycleColorCheck, SLOT(setEnabled(bool)) );
01715   connect( mCustomColorCheck, SIGNAL( stateChanged( int ) ),
01716            this, SLOT( slotEmitChanged( void ) ) );
01717 }
01718 
01719 void AppearancePage::ColorsTab::doLoadOther() {
01720   KConfigGroup reader( KMKernel::config(), "Reader" );
01721 
01722   mCustomColorCheck->setChecked( !reader.readBoolEntry( "defaultColors", true ) );
01723   mRecycleColorCheck->setChecked( reader.readBoolEntry( "RecycleQuoteColors", false ) );
01724 
01725   static const QColor defaultColor[ numColorNames ] = {
01726     kapp->palette().active().base(), // bg
01727     KGlobalSettings::alternateBackgroundColor(), // alt bg
01728     kapp->palette().active().text(), // fg
01729     QColor( 0x00, 0x80, 0x00 ), // quoted l1
01730     QColor( 0x00, 0x70, 0x00 ), // quoted l2
01731     QColor( 0x00, 0x60, 0x00 ), // quoted l3
01732     KGlobalSettings::linkColor(), // link
01733     KGlobalSettings::visitedLinkColor(), // visited link
01734     Qt::red, // misspelled words
01735     Qt::red, // new msg
01736     Qt::blue, // unread mgs
01737     QColor( 0x00, 0x7F, 0x00 ), // important msg
01738     QColor( 0x00, 0x80, 0xFF ), // light blue // pgp encrypted
01739     QColor( 0x40, 0xFF, 0x40 ), // light green // pgp ok, trusted key
01740     QColor( 0xFF, 0xFF, 0x40 ), // light yellow // pgp ok, untrusted key
01741     QColor( 0xFF, 0xFF, 0x40 ), // light yellow // pgp unchk
01742     Qt::red, // pgp bad
01743     QColor( 0xFF, 0x40, 0x40 ), // warning text color: light red
01744     Qt::lightGray, // colorbar plain bg
01745     Qt::black,     // colorbar plain fg
01746     Qt::black,     // colorbar html  bg
01747     Qt::white,     // colorbar html  fg
01748   };
01749 
01750   for ( int i = 0 ; i < numColorNames ; i++ )
01751     mColorList->setColor( i,
01752       reader.readColorEntry( colorNames[i].configName, &defaultColor[i] ) );
01753   connect( mColorList, SIGNAL( changed( ) ),
01754            this, SLOT( slotEmitChanged( void ) ) );
01755 }
01756 
01757 void AppearancePage::ColorsTab::installProfile( KConfig * profile ) {
01758   KConfigGroup reader( profile, "Reader" );
01759 
01760   if ( reader.hasKey( "defaultColors" ) )
01761     mCustomColorCheck->setChecked( !reader.readBoolEntry( "defaultColors" ) );
01762   if ( reader.hasKey( "RecycleQuoteColors" ) )
01763     mRecycleColorCheck->setChecked( reader.readBoolEntry( "RecycleQuoteColors" ) );
01764 
01765   for ( int i = 0 ; i < numColorNames ; i++ )
01766     if ( reader.hasKey( colorNames[i].configName ) )
01767       mColorList->setColor( i, reader.readColorEntry( colorNames[i].configName ) );
01768 }
01769 
01770 void AppearancePage::ColorsTab::save() {
01771   KConfigGroup reader( KMKernel::config(), "Reader" );
01772 
01773   bool customColors = mCustomColorCheck->isChecked();
01774   reader.writeEntry( "defaultColors", !customColors );
01775 
01776   for ( int i = 0 ; i < numColorNames ; i++ )
01777     // Don't write color info when we use default colors, but write
01778     // if it's already there:
01779     if ( customColors || reader.hasKey( colorNames[i].configName ) )
01780       reader.writeEntry( colorNames[i].configName, mColorList->color(i) );
01781 
01782   reader.writeEntry( "RecycleQuoteColors", mRecycleColorCheck->isChecked() );
01783 }
01784 
01785 QString AppearancePage::LayoutTab::helpAnchor() const {
01786   return QString::fromLatin1("configure-appearance-layout");
01787 }
01788 
01789 static const EnumConfigEntryItem folderListModes[] = {
01790   { "long", I18N_NOOP("Lon&g folder list") },
01791   { "short", I18N_NOOP("Shor&t folder list" ) }
01792 };
01793 static const EnumConfigEntry folderListMode = {
01794   "Geometry", "FolderList", I18N_NOOP("Folder List"),
01795   folderListModes, DIM(folderListModes), 0
01796 };
01797 
01798 
01799 static const EnumConfigEntryItem mimeTreeLocations[] = {
01800   { "top", I18N_NOOP("Abo&ve the message pane") },
01801   { "bottom", I18N_NOOP("&Below the message pane") }
01802 };
01803 static const EnumConfigEntry mimeTreeLocation = {
01804   "Reader", "MimeTreeLocation", I18N_NOOP("Message Structure Viewer Placement"),
01805   mimeTreeLocations, DIM(mimeTreeLocations), 1
01806 };
01807 
01808 static const EnumConfigEntryItem mimeTreeModes[] = {
01809   { "never", I18N_NOOP("Show &never") },
01810   { "smart", I18N_NOOP("Show only for non-plaintext &messages") },
01811   { "always", I18N_NOOP("Show alway&s") }
01812 };
01813 static const EnumConfigEntry mimeTreeMode = {
01814   "Reader", "MimeTreeMode", I18N_NOOP("Message Structure Viewer"),
01815   mimeTreeModes, DIM(mimeTreeModes), 1
01816 };
01817 
01818 
01819 static const EnumConfigEntryItem readerWindowModes[] = {
01820   { "hide", I18N_NOOP("&Do not show a message preview pane") },
01821   { "below", I18N_NOOP("Show the message preview pane belo&w the message list") },
01822   { "right", I18N_NOOP("Show the message preview pane ne&xt to the message list") }
01823 };
01824 static const EnumConfigEntry readerWindowMode = {
01825   "Geometry", "readerWindowMode", I18N_NOOP("Message Preview Pane"),
01826   readerWindowModes, DIM(readerWindowModes), 1
01827 };
01828 
01829 AppearancePageLayoutTab::AppearancePageLayoutTab( QWidget * parent, const char * name )
01830   : ConfigModuleTab( parent, name )
01831 {
01832   // tmp. vars:
01833   QVBoxLayout * vlay;
01834 
01835   vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
01836 
01837   // "folder list" radio buttons:
01838   populateButtonGroup( mFolderListGroup = new QHButtonGroup( this ), folderListMode );
01839   vlay->addWidget( mFolderListGroup );
01840   connect( mFolderListGroup, SIGNAL ( clicked( int ) ),
01841            this, SLOT( slotEmitChanged() ) );
01842 
01843   // "show reader window" radio buttons:
01844   populateButtonGroup( mReaderWindowModeGroup = new QVButtonGroup( this ), readerWindowMode );
01845   vlay->addWidget( mReaderWindowModeGroup );
01846   connect( mReaderWindowModeGroup, SIGNAL ( clicked( int ) ),
01847            this, SLOT( slotEmitChanged() ) );
01848 
01849   // "Show MIME Tree" radio buttons:
01850   populateButtonGroup( mMIMETreeModeGroup = new QVButtonGroup( this ), mimeTreeMode );
01851   vlay->addWidget( mMIMETreeModeGroup );
01852   connect( mMIMETreeModeGroup, SIGNAL ( clicked( int ) ),
01853            this, SLOT( slotEmitChanged() ) );
01854 
01855   // "MIME Tree Location" radio buttons:
01856   populateButtonGroup( mMIMETreeLocationGroup = new QHButtonGroup( this ), mimeTreeLocation );
01857   vlay->addWidget( mMIMETreeLocationGroup );
01858   connect( mMIMETreeLocationGroup, SIGNAL ( clicked( int ) ),
01859            this, SLOT( slotEmitChanged() ) );
01860 
01861   vlay->addStretch( 10 ); // spacer
01862 }
01863 
01864 void AppearancePage::LayoutTab::doLoadOther() {
01865   const KConfigGroup reader( KMKernel::config(), "Reader" );
01866   const KConfigGroup geometry( KMKernel::config(), "Geometry" );
01867 
01868   loadWidget( mFolderListGroup, geometry, folderListMode );
01869   loadWidget( mMIMETreeLocationGroup, reader, mimeTreeLocation );
01870   loadWidget( mMIMETreeModeGroup, reader, mimeTreeMode );
01871   loadWidget( mReaderWindowModeGroup, geometry, readerWindowMode );
01872 }
01873 
01874 void AppearancePage::LayoutTab::installProfile( KConfig * profile ) {
01875   const KConfigGroup reader( profile, "Reader" );
01876   const KConfigGroup geometry( profile, "Geometry" );
01877 
01878   loadProfile( mFolderListGroup, geometry, folderListMode );
01879   loadProfile( mMIMETreeLocationGroup, reader, mimeTreeLocation );
01880   loadProfile( mMIMETreeModeGroup, reader, mimeTreeMode );
01881   loadProfile( mReaderWindowModeGroup, geometry, readerWindowMode );
01882 }
01883 
01884 void AppearancePage::LayoutTab::save() {
01885   KConfigGroup reader( KMKernel::config(), "Reader" );
01886   KConfigGroup geometry( KMKernel::config(), "Geometry" );
01887 
01888   saveButtonGroup( mFolderListGroup, geometry, folderListMode );
01889   saveButtonGroup( mMIMETreeLocationGroup, reader, mimeTreeLocation );
01890   saveButtonGroup( mMIMETreeModeGroup, reader, mimeTreeMode );
01891   saveButtonGroup( mReaderWindowModeGroup, geometry, readerWindowMode );
01892 }
01893 
01894 //
01895 // Appearance Message List
01896 //
01897 
01898 QString AppearancePage::HeadersTab::helpAnchor() const {
01899   return QString::fromLatin1("configure-appearance-headers");
01900 }
01901 
01902 static const struct {
01903   const char * displayName;
01904   DateFormatter::FormatType dateDisplay;
01905 } dateDisplayConfig[] = {
01906   { I18N_NOOP("Sta&ndard format (%1)"), KMime::DateFormatter::CTime },
01907   { I18N_NOOP("Locali&zed format (%1)"), KMime::DateFormatter::Localized },
01908   { I18N_NOOP("Fancy for&mat (%1)"), KMime::DateFormatter::Fancy },
01909   { I18N_NOOP("C&ustom format (Shift+F1 for help):"),
01910     KMime::DateFormatter::Custom }
01911 };
01912 static const int numDateDisplayConfig =
01913   sizeof dateDisplayConfig / sizeof *dateDisplayConfig;
01914 
01915 AppearancePageHeadersTab::AppearancePageHeadersTab( QWidget * parent, const char * name )
01916   : ConfigModuleTab( parent, name ),
01917     mCustomDateFormatEdit( 0 )
01918 {
01919   // tmp. vars:
01920   QButtonGroup * group;
01921   QRadioButton * radio;
01922 
01923   QVBoxLayout * vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
01924 
01925   // "General Options" group:
01926   group = new QVButtonGroup( i18n( "General Options" ), this );
01927   group->layout()->setSpacing( KDialog::spacingHint() );
01928 
01929   mMessageSizeCheck = new QCheckBox( i18n("Display messa&ge sizes"), group );
01930 
01931   mCryptoIconsCheck = new QCheckBox( i18n( "Show crypto &icons" ), group );
01932 
01933   mAttachmentCheck = new QCheckBox( i18n("Show attachment icon"), group );
01934 
01935   mNestedMessagesCheck =
01936     new QCheckBox( i18n("&Threaded message list"), group );
01937 
01938   connect( mMessageSizeCheck, SIGNAL( stateChanged( int ) ),
01939            this, SLOT( slotEmitChanged( void ) ) );
01940   connect( mAttachmentCheck, SIGNAL( stateChanged( int ) ),
01941            this, SLOT( slotEmitChanged( void ) ) );
01942   connect( mCryptoIconsCheck, SIGNAL( stateChanged( int ) ),
01943            this, SLOT( slotEmitChanged( void ) ) );
01944   connect( mNestedMessagesCheck, SIGNAL( stateChanged( int ) ),
01945            this, SLOT( slotEmitChanged( void ) ) );
01946 
01947 
01948   vlay->addWidget( group );
01949 
01950   // "Message Header Threading Options" group:
01951   mNestingPolicy =
01952     new QVButtonGroup( i18n("Threaded Message List Options"), this );
01953   mNestingPolicy->layout()->setSpacing( KDialog::spacingHint() );
01954 
01955   mNestingPolicy->insert(
01956     new QRadioButton( i18n("Always &keep threads open"),
01957                       mNestingPolicy ), 0 );
01958   mNestingPolicy->insert(
01959     new QRadioButton( i18n("Threads default to o&pen"),
01960                       mNestingPolicy ), 1 );
01961   mNestingPolicy->insert(
01962     new QRadioButton( i18n("Threads default to closed"),
01963                       mNestingPolicy ), 2 );
01964   mNestingPolicy->insert(
01965     new QRadioButton( i18n("Open threads that contain ne&w, unread "
01966                            "or important messages and open watched threads."),
01967                       mNestingPolicy ), 3 );
01968 
01969   vlay->addWidget( mNestingPolicy );
01970 
01971   connect( mNestingPolicy, SIGNAL( clicked( int ) ),
01972            this, SLOT( slotEmitChanged( void ) ) );
01973 
01974   // "Date Display" group:
01975   mDateDisplay = new QVButtonGroup( i18n("Date Display"), this );
01976   mDateDisplay->layout()->setSpacing( KDialog::spacingHint() );
01977 
01978   for ( int i = 0 ; i < numDateDisplayConfig ; i++ ) {
01979     QString buttonLabel = i18n(dateDisplayConfig[i].displayName);
01980     if ( buttonLabel.contains("%1") )
01981       buttonLabel = buttonLabel.arg( DateFormatter::formatCurrentDate( dateDisplayConfig[i].dateDisplay ) );
01982     radio = new QRadioButton( buttonLabel, mDateDisplay );
01983     mDateDisplay->insert( radio, i );
01984     if ( dateDisplayConfig[i].dateDisplay == DateFormatter::Custom ) {
01985       mCustomDateFormatEdit = new KLineEdit( mDateDisplay );
01986       mCustomDateFormatEdit->setEnabled( false );
01987       connect( radio, SIGNAL(toggled(bool)),
01988                mCustomDateFormatEdit, SLOT(setEnabled(bool)) );
01989       connect( mCustomDateFormatEdit, SIGNAL(textChanged(const QString&)),
01990                this, SLOT(slotEmitChanged(void)) );
01991       QString customDateWhatsThis =
01992         i18n("<qt><p><strong>These expressions may be used for the date:"
01993              "</strong></p>"
01994              "<ul>"
01995              "<li>d - the day as a number without a leading zero (1-31)</li>"
01996              "<li>dd - the day as a number with a leading zero (01-31)</li>"
01997              "<li>ddd - the abbreviated day name (Mon - Sun)</li>"
01998              "<li>dddd - the long day name (Monday - Sunday)</li>"
01999              "<li>M - the month as a number without a leading zero (1-12)</li>"
02000              "<li>MM - the month as a number with a leading zero (01-12)</li>"
02001              "<li>MMM - the abbreviated month name (Jan - Dec)</li>"
02002              "<li>MMMM - the long month name (January - December)</li>"
02003              "<li>yy - the year as a two digit number (00-99)</li>"
02004              "<li>yyyy - the year as a four digit number (0000-9999)</li>"
02005              "</ul>"
02006              "<p><strong>These expressions may be used for the time:"
02007              "</string></p> "
02008              "<ul>"
02009              "<li>h - the hour without a leading zero (0-23 or 1-12 if AM/PM display)</li>"
02010              "<li>hh - the hour with a leading zero (00-23 or 01-12 if AM/PM display)</li>"
02011              "<li>m - the minutes without a leading zero (0-59)</li>"
02012              "<li>mm - the minutes with a leading zero (00-59)</li>"
02013              "<li>s - the seconds without a leading zero (0-59)</li>"
02014              "<li>ss - the seconds with a leading zero (00-59)</li>"
02015              "<li>z - the milliseconds without leading zeroes (0-999)</li>"
02016              "<li>zzz - the milliseconds with leading zeroes (000-999)</li>"
02017              "<li>AP - switch to AM/PM display. AP will be replaced by either \"AM\" or \"PM\".</li>"
02018              "<li>ap - switch to AM/PM display. ap will be replaced by either \"am\" or \"pm\".</li>"
02019              "<li>Z - time zone in numeric form (-0500)</li>"
02020              "</ul>"
02021              "<p><strong>All other input characters will be ignored."
02022              "</strong></p></qt>");
02023       QWhatsThis::add( mCustomDateFormatEdit, customDateWhatsThis );
02024       QWhatsThis::add( radio, customDateWhatsThis );
02025     }
02026   } // end for loop populating mDateDisplay
02027 
02028   vlay->addWidget( mDateDisplay );
02029   connect( mDateDisplay, SIGNAL( clicked( int ) ),
02030            this, SLOT( slotEmitChanged( void ) ) );
02031 
02032 
02033   vlay->addStretch( 10 ); // spacer
02034 }
02035 
02036 void AppearancePage::HeadersTab::doLoadOther() {
02037   KConfigGroup general( KMKernel::config(), "General" );
02038   KConfigGroup geometry( KMKernel::config(), "Geometry" );
02039 
02040   // "General Options":
02041   mNestedMessagesCheck->setChecked( geometry.readBoolEntry( "nestedMessages", false ) );
02042   mMessageSizeCheck->setChecked( general.readBoolEntry( "showMessageSize", false ) );
02043   mCryptoIconsCheck->setChecked( general.readBoolEntry( "showCryptoIcons", false ) );
02044   mAttachmentCheck->setChecked( general.readBoolEntry( "showAttachmentIcon", true ) );
02045 
02046   // "Message Header Threading Options":
02047   int num = geometry.readNumEntry( "nestingPolicy", 3 );
02048   if ( num < 0 || num > 3 ) num = 3;
02049   mNestingPolicy->setButton( num );
02050 
02051   // "Date Display":
02052   setDateDisplay( general.readNumEntry( "dateFormat", DateFormatter::Fancy ),
02053                   general.readEntry( "customDateFormat" ) );
02054 }
02055 
02056 void AppearancePage::HeadersTab::setDateDisplay( int num, const QString & format ) {
02057   DateFormatter::FormatType dateDisplay =
02058     static_cast<DateFormatter::FormatType>( num );
02059 
02060   // special case: needs text for the line edit:
02061   if ( dateDisplay == DateFormatter::Custom )
02062     mCustomDateFormatEdit->setText( format );
02063 
02064   for ( int i = 0 ; i < numDateDisplayConfig ; i++ )
02065     if ( dateDisplay == dateDisplayConfig[i].dateDisplay ) {
02066       mDateDisplay->setButton( i );
02067       return;
02068     }
02069   // fell through since none found:
02070   mDateDisplay->setButton( numDateDisplayConfig - 2 ); // default
02071 }
02072 
02073 void AppearancePage::HeadersTab::installProfile( KConfig * profile ) {
02074   KConfigGroup general( profile, "General" );
02075   KConfigGroup geometry( profile, "Geometry" );
02076 
02077   if ( geometry.hasKey( "nestedMessages" ) )
02078     mNestedMessagesCheck->setChecked( geometry.readBoolEntry( "nestedMessages" ) );
02079   if ( general.hasKey( "showMessageSize" ) )
02080     mMessageSizeCheck->setChecked( general.readBoolEntry( "showMessageSize" ) );
02081 
02082   if( general.hasKey( "showCryptoIcons" ) )
02083     mCryptoIconsCheck->setChecked( general.readBoolEntry( "showCryptoIcons" ) );
02084   if ( general.hasKey( "showAttachmentIcon" ) )
02085     mAttachmentCheck->setChecked( general.readBoolEntry( "showAttachmentIcon" ) );
02086 
02087   if ( geometry.hasKey( "nestingPolicy" ) ) {
02088     int num = geometry.readNumEntry( "nestingPolicy" );
02089     if ( num < 0 || num > 3 ) num = 3;
02090     mNestingPolicy->setButton( num );
02091   }
02092 
02093   if ( general.hasKey( "dateFormat" ) )
02094     setDateDisplay( general.readNumEntry( "dateFormat" ),
02095                    general.readEntry( "customDateFormat" ) );
02096 }
02097 
02098 void AppearancePage::HeadersTab::save() {
02099   KConfigGroup general( KMKernel::config(), "General" );
02100   KConfigGroup geometry( KMKernel::config(), "Geometry" );
02101 
02102   if ( geometry.readBoolEntry( "nestedMessages", false )
02103        != mNestedMessagesCheck->isChecked() ) {
02104     int result = KMessageBox::warningContinueCancel( this,
02105                    i18n("Changing the global threading setting will override "
02106                         "all folder specific values."),
02107                    QString::null, KStdGuiItem::cont(), "threadOverride" );
02108     if ( result == KMessageBox::Continue ) {
02109       geometry.writeEntry( "nestedMessages", mNestedMessagesCheck->isChecked() );
02110       // remove all threadMessagesOverride keys from all [Folder-*] groups:
02111       QStringList groups = KMKernel::config()->groupList().grep( QRegExp("^Folder-") );
02112       kdDebug(5006) << "groups.count() == " << groups.count() << endl;
02113       for ( QStringList::const_iterator it = groups.begin() ; it != groups.end() ; ++it ) {
02114         KConfigGroup group( KMKernel::config(), *it );
02115         group.deleteEntry( "threadMessagesOverride" );
02116       }
02117     }
02118   }
02119 
02120   geometry.writeEntry( "nestingPolicy",
02121                        mNestingPolicy->id( mNestingPolicy->selected() ) );
02122   general.writeEntry( "showMessageSize", mMessageSizeCheck->isChecked() );
02123   general.writeEntry( "showCryptoIcons", mCryptoIconsCheck->isChecked() );
02124   general.writeEntry( "showAttachmentIcon", mAttachmentCheck->isChecked() );
02125 
02126   int dateDisplayID = mDateDisplay->id( mDateDisplay->selected() );
02127   // check bounds:
02128   assert( dateDisplayID >= 0 ); assert( dateDisplayID < numDateDisplayConfig );
02129   general.writeEntry( "dateFormat",
02130                       dateDisplayConfig[ dateDisplayID ].dateDisplay );
02131   general.writeEntry( "customDateFormat", mCustomDateFormatEdit->text() );
02132 }
02133 
02134 
02135 //
02136 // Message Window
02137 //
02138 
02139 
02140 static const BoolConfigEntry showColorbarMode = {
02141   "Reader", "showColorbar", I18N_NOOP("Show HTML stat&us bar"), false
02142 };
02143 
02144 static const BoolConfigEntry showSpamStatusMode = {
02145   "Reader", "showSpamStatus", I18N_NOOP("Show s&pam status in fancy headers"), true
02146 };
02147 
02148 static const BoolConfigEntry showEmoticons = {
02149   "Reader", "ShowEmoticons", I18N_NOOP("Replace smileys by emoticons"), true
02150 };
02151 
02152 static const BoolConfigEntry shrinkQuotes = {
02153   "Reader", "ShrinkQuotes", I18N_NOOP("Use smaller font for quoted text"), false
02154 };
02155 
02156 static const BoolConfigEntry showExpandQuotesMark= {
02157   "Reader", "ShowExpandQuotesMark", I18N_NOOP("Show expand/collapse quote marks"), false
02158 };
02159 
02160 
02161 QString AppearancePage::ReaderTab::helpAnchor() const {
02162   return QString::fromLatin1("configure-appearance-reader");
02163 }
02164 
02165 AppearancePageReaderTab::AppearancePageReaderTab( QWidget * parent,
02166                                                   const char * name )
02167   : ConfigModuleTab( parent, name )
02168 {
02169   QVBoxLayout *vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
02170 
02171   // "show colorbar" check box:
02172   populateCheckBox( mShowColorbarCheck = new QCheckBox( this ), showColorbarMode );
02173   vlay->addWidget( mShowColorbarCheck );
02174   connect( mShowColorbarCheck, SIGNAL ( stateChanged( int ) ),
02175            this, SLOT( slotEmitChanged() ) );
02176 
02177   // "show spam status" check box;
02178   populateCheckBox( mShowSpamStatusCheck = new QCheckBox( this ), showSpamStatusMode );
02179   vlay->addWidget( mShowSpamStatusCheck );
02180   connect( mShowSpamStatusCheck, SIGNAL ( stateChanged( int ) ),
02181            this, SLOT( slotEmitChanged() ) );
02182 
02183   // "replace smileys by emoticons" check box;
02184   populateCheckBox( mShowEmoticonsCheck = new QCheckBox( this ), showEmoticons );
02185   vlay->addWidget( mShowEmoticonsCheck );
02186   connect( mShowEmoticonsCheck, SIGNAL ( stateChanged( int ) ),
02187            this, SLOT( slotEmitChanged() ) );
02188 
02189   // "Use smaller font for quoted text" check box
02190   mShrinkQuotesCheck = new QCheckBox( i18n( shrinkQuotes.desc ), this,
02191                                       "kcfg_ShrinkQuotes" );
02192   vlay->addWidget( mShrinkQuotesCheck );
02193   connect( mShrinkQuotesCheck, SIGNAL( stateChanged( int ) ),
02194            this, SLOT( slotEmitChanged() ) );
02195 
02196   // "Show expand/collaps quote marks" check box;
02197   QHBoxLayout *hlay= new QHBoxLayout( vlay ); // inherits spacing
02198   populateCheckBox( mShowExpandQuotesMark= new QCheckBox( this ), showExpandQuotesMark);
02199   hlay->addWidget( mShowExpandQuotesMark);
02200   connect( mShowExpandQuotesMark, SIGNAL ( stateChanged( int ) ),
02201            this, SLOT( slotEmitChanged() ) );
02202 
02203   hlay->addStretch( 1 );
02204   mCollapseQuoteLevelSpin = new KIntSpinBox( 0/*min*/,10/*max*/,1/*step*/,
02205       3/*init*/,10/*base*/,this );
02206 
02207   QLabel *label = new QLabel( mCollapseQuoteLevelSpin,
02208            GlobalSettings::self()->collapseQuoteLevelSpinItem()->label(), this );
02209 
02210   hlay->addWidget( label );
02211 
02212   mCollapseQuoteLevelSpin->setEnabled( false ); //since !mShowExpandQuotesMark->isCheckec()
02213   connect(  mCollapseQuoteLevelSpin, SIGNAL( valueChanged( int ) ),
02214       this, SLOT( slotEmitChanged( void ) ) );
02215   hlay->addWidget( mCollapseQuoteLevelSpin);
02216 
02217   connect( mShowExpandQuotesMark, SIGNAL( toggled( bool ) ),
02218       mCollapseQuoteLevelSpin, SLOT( setEnabled( bool ) ) );
02219 
02220   // Fallback Character Encoding
02221   hlay = new QHBoxLayout( vlay ); // inherits spacing
02222   mCharsetCombo = new QComboBox( this );
02223   mCharsetCombo->insertStringList( KMMsgBase::supportedEncodings( false ) );
02224 
02225   connect( mCharsetCombo, SIGNAL( activated( int ) ),
02226            this, SLOT( slotEmitChanged( void ) ) );
02227 
02228   QString fallbackCharsetWhatsThis =
02229     i18n( GlobalSettings::self()->fallbackCharacterEncodingItem()->whatsThis().utf8() );
02230   QWhatsThis::add( mCharsetCombo, fallbackCharsetWhatsThis );
02231 
02232   label = new QLabel( i18n("Fallback ch&aracter encoding:"), this );
02233   label->setBuddy( mCharsetCombo );
02234 
02235   hlay->addWidget( label );
02236   hlay->addWidget( mCharsetCombo );
02237 
02238   // Override Character Encoding
02239   QHBoxLayout *hlay2 = new QHBoxLayout( vlay ); // inherits spacing
02240   mOverrideCharsetCombo = new QComboBox( this );
02241   QStringList encodings = KMMsgBase::supportedEncodings( false );
02242   encodings.prepend( i18n( "Auto" ) );
02243   mOverrideCharsetCombo->insertStringList( encodings );
02244   mOverrideCharsetCombo->setCurrentItem(0);
02245 
02246   connect( mOverrideCharsetCombo, SIGNAL( activated( int ) ),
02247            this, SLOT( slotEmitChanged( void ) ) );
02248 
02249   QString overrideCharsetWhatsThis =
02250     i18n( GlobalSettings::self()->overrideCharacterEncodingItem()->whatsThis().utf8() );
02251   QWhatsThis::add( mOverrideCharsetCombo, overrideCharsetWhatsThis );
02252 
02253   label = new QLabel( i18n("&Override character encoding:"), this );
02254   label->setBuddy( mOverrideCharsetCombo );
02255 
02256   hlay2->addWidget( label );
02257   hlay2->addWidget( mOverrideCharsetCombo );
02258 
02259   vlay->addStretch( 100 ); // spacer
02260 }
02261 
02262 
02263 void AppearancePage::ReaderTab::readCurrentFallbackCodec()
02264 {
02265   QStringList encodings = KMMsgBase::supportedEncodings( false );
02266   QStringList::ConstIterator it( encodings.begin() );
02267   QStringList::ConstIterator end( encodings.end() );
02268   QString currentEncoding = GlobalSettings::self()->fallbackCharacterEncoding();
02269   currentEncoding = currentEncoding.replace( "iso ", "iso-", false );
02271   int i = 0;
02272   int indexOfLatin9 = 0;
02273   bool found = false;
02274   for( ; it != end; ++it)
02275   {
02276     const QString encoding = KGlobal::charsets()->encodingForName(*it);
02277     if ( encoding == "iso-8859-15" )
02278         indexOfLatin9 = i;
02279     if( false && encoding == currentEncoding )
02280     {
02281       mCharsetCombo->setCurrentItem( i );
02282       found = true;
02283       break;
02284     }
02285     i++;
02286   }
02287   if ( !found ) // nothing matched, use latin9
02288     mCharsetCombo->setCurrentItem( indexOfLatin9 );
02289 }
02290 
02291 void AppearancePage::ReaderTab::readCurrentOverrideCodec()
02292 {
02293   const QString &currentOverrideEncoding = GlobalSettings::self()->overrideCharacterEncoding();
02294   if ( currentOverrideEncoding.isEmpty() ) {
02295     mOverrideCharsetCombo->setCurrentItem( 0 );
02296     return;
02297   }
02298   QStringList encodings = KMMsgBase::supportedEncodings( false );
02299   encodings.prepend( i18n( "Auto" ) );
02300   QStringList::Iterator it( encodings.begin() );
02301   QStringList::Iterator end( encodings.end() );
02302   int i = 0;
02303   for( ; it != end; ++it)
02304   {
02305     if( KGlobal::charsets()->encodingForName(*it) == currentOverrideEncoding )
02306     {
02307       mOverrideCharsetCombo->setCurrentItem( i );
02308       break;
02309     }
02310     i++;
02311   }
02312 }
02313 
02314 void AppearancePage::ReaderTab::doLoadFromGlobalSettings()
02315 {
02316   mShowEmoticonsCheck->setChecked( GlobalSettings::self()->showEmoticons() );
02317   mShrinkQuotesCheck->setChecked( GlobalSettings::self()->shrinkQuotes() );
02318   mShowExpandQuotesMark->setChecked( GlobalSettings::self()->showExpandQuotesMark() );
02319   mCollapseQuoteLevelSpin->setValue( GlobalSettings::self()->collapseQuoteLevelSpin() );
02320   readCurrentFallbackCodec();
02321   readCurrentOverrideCodec();
02322 }
02323 
02324 void AppearancePage::ReaderTab::doLoadOther()
02325 {
02326   const KConfigGroup reader( KMKernel::config(), "Reader" );
02327   loadWidget( mShowColorbarCheck, reader, showColorbarMode );
02328   loadWidget( mShowSpamStatusCheck, reader, showSpamStatusMode );
02329 }
02330 
02331 
02332 void AppearancePage::ReaderTab::save() {
02333   KConfigGroup reader( KMKernel::config(), "Reader" );
02334   saveCheckBox( mShowColorbarCheck, reader, showColorbarMode );
02335   saveCheckBox( mShowSpamStatusCheck, reader, showSpamStatusMode );
02336   GlobalSettings::self()->setShowEmoticons( mShowEmoticonsCheck->isChecked() );
02337   GlobalSettings::self()->setShrinkQuotes( mShrinkQuotesCheck->isChecked() );
02338   GlobalSettings::self()->setShowExpandQuotesMark( mShowExpandQuotesMark->isChecked() );
02339 
02340   GlobalSettings::self()->setCollapseQuoteLevelSpin( mCollapseQuoteLevelSpin->value() );
02341   GlobalSettings::self()->setFallbackCharacterEncoding(
02342       KGlobal::charsets()->encodingForName( mCharsetCombo->currentText() ) );
02343   GlobalSettings::self()->setOverrideCharacterEncoding(
02344       mOverrideCharsetCombo->currentItem() == 0 ?
02345         QString() :
02346         KGlobal::charsets()->encodingForName( mOverrideCharsetCombo->currentText() ) );
02347 }
02348 
02349 
02350 void AppearancePage::ReaderTab::installProfile( KConfig * /* profile */ ) {
02351   const KConfigGroup reader( KMKernel::config(), "Reader" );
02352   loadProfile( mShowColorbarCheck, reader, showColorbarMode );
02353   loadProfile( mShowSpamStatusCheck, reader, showSpamStatusMode );
02354   loadProfile( mShowEmoticonsCheck, reader, showEmoticons );
02355   loadProfile( mShrinkQuotesCheck, reader, shrinkQuotes );
02356   loadProfile( mShowExpandQuotesMark, reader, showExpandQuotesMark);
02357 }
02358 
02359 
02360 QString AppearancePage::SystemTrayTab::helpAnchor() const {
02361   return QString::fromLatin1("configure-appearance-systemtray");
02362 }
02363 
02364 AppearancePageSystemTrayTab::AppearancePageSystemTrayTab( QWidget * parent,
02365                                                           const char * name )
02366   : ConfigModuleTab( parent, name )
02367 {
02368   QVBoxLayout * vlay = new QVBoxLayout( this, KDialog::marginHint(),
02369                                         KDialog::spacingHint() );
02370 
02371   // "Enable system tray applet" check box
02372   mSystemTrayCheck = new QCheckBox( i18n("Enable system tray icon"), this );
02373   vlay->addWidget( mSystemTrayCheck );
02374   connect( mSystemTrayCheck, SIGNAL( stateChanged( int ) ),
02375            this, SLOT( slotEmitChanged( void ) ) );
02376 
02377   // System tray modes
02378   mSystemTrayGroup = new QVButtonGroup( i18n("System Tray Mode"), this );
02379   mSystemTrayGroup->layout()->setSpacing( KDialog::spacingHint() );
02380   vlay->addWidget( mSystemTrayGroup );
02381   connect( mSystemTrayGroup, SIGNAL( clicked( int ) ),
02382            this, SLOT( slotEmitChanged( void ) ) );
02383   connect( mSystemTrayCheck, SIGNAL( toggled( bool ) ),
02384            mSystemTrayGroup, SLOT( setEnabled( bool ) ) );
02385 
02386   mSystemTrayGroup->insert( new QRadioButton( i18n("Always show KMail in system tray"), mSystemTrayGroup ),
02387                             GlobalSettings::EnumSystemTrayPolicy::ShowAlways );
02388 
02389   mSystemTrayGroup->insert( new QRadioButton( i18n("Only show KMail in system tray if there are unread messages"), mSystemTrayGroup ),
02390                             GlobalSettings::EnumSystemTrayPolicy::ShowOnUnread );
02391 
02392   vlay->addStretch( 10 ); // spacer
02393 }
02394 
02395 void AppearancePage::SystemTrayTab::doLoadFromGlobalSettings() {
02396   mSystemTrayCheck->setChecked( GlobalSettings::self()->systemTrayEnabled() );
02397   mSystemTrayGroup->setButton( GlobalSettings::self()->systemTrayPolicy() );
02398   mSystemTrayGroup->setEnabled( mSystemTrayCheck->isChecked() );
02399 }
02400 
02401 void AppearancePage::SystemTrayTab::installProfile( KConfig * profile ) {
02402   KConfigGroup general( profile, "General" );
02403 
02404   if ( general.hasKey( "SystemTrayEnabled" ) ) {
02405     mSystemTrayCheck->setChecked( general.readBoolEntry( "SystemTrayEnabled" ) );
02406   }
02407   if ( general.hasKey( "SystemTrayPolicy" ) ) {
02408     mSystemTrayGroup->setButton( general.readNumEntry( "SystemTrayPolicy" ) );
02409   }
02410   mSystemTrayGroup->setEnabled( mSystemTrayCheck->isChecked() );
02411 }
02412 
02413 void AppearancePage::SystemTrayTab::save() {
02414   GlobalSettings::self()->setSystemTrayEnabled( mSystemTrayCheck->isChecked() );
02415   GlobalSettings::self()->setSystemTrayPolicy( mSystemTrayGroup->id( mSystemTrayGroup->selected() ) );
02416 }
02417 
02418 
02419 // *************************************************************
02420 // *                                                           *
02421 // *                      ComposerPage                         *
02422 // *                                                           *
02423 // *************************************************************
02424 
02425 QString ComposerPage::helpAnchor() const {
02426   return QString::fromLatin1("configure-composer");
02427 }
02428 
02429 ComposerPage::ComposerPage( QWidget * parent, const char * name )
02430   : ConfigModuleWithTabs( parent, name )
02431 {
02432   //
02433   // "General" tab:
02434   //
02435   mGeneralTab = new GeneralTab();
02436   addTab( mGeneralTab, i18n("&General") );
02437   addConfig( GlobalSettings::self(), mGeneralTab );
02438 
02439   //
02440   // "Phrases" tab:
02441   //
02442   mPhrasesTab = new PhrasesTab();
02443   addTab( mPhrasesTab, i18n("&Phrases") );
02444 
02445   //
02446   // "Subject" tab:
02447   //
02448   mSubjectTab = new SubjectTab();
02449   addTab( mSubjectTab, i18n("&Subject") );
02450   addConfig( GlobalSettings::self(), mSubjectTab );
02451 
02452   //
02453   // "Charset" tab:
02454   //
02455   mCharsetTab = new CharsetTab();
02456   addTab( mCharsetTab, i18n("Cha&rset") );
02457 
02458   //
02459   // "Headers" tab:
02460   //
02461   mHeadersTab = new HeadersTab();
02462   addTab( mHeadersTab, i18n("H&eaders") );
02463 
02464   //
02465   // "Attachments" tab:
02466   //
02467   mAttachmentsTab = new AttachmentsTab();
02468   addTab( mAttachmentsTab, i18n("Config->Composer->Attachments", "A&ttachments") );
02469   load();
02470 }
02471 
02472 QString ComposerPage::GeneralTab::helpAnchor() const {
02473   return QString::fromLatin1("configure-composer-general");
02474 }
02475 
02476 ComposerPageGeneralTab::ComposerPageGeneralTab( QWidget * parent, const char * name )
02477   : ConfigModuleTab( parent, name )
02478 {
02479   // tmp. vars:
02480   QVBoxLayout *vlay;
02481   QHBoxLayout *hlay;
02482   QGroupBox   *group;
02483   QLabel      *label;
02484   QHBox       *hbox;
02485   QString      msg;
02486 
02487   vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
02488 
02489   // some check buttons...
02490   mAutoAppSignFileCheck = new QCheckBox(
02491            GlobalSettings::self()->autoTextSignatureItem()->label(),
02492            this );
02493   vlay->addWidget( mAutoAppSignFileCheck );
02494   connect( mAutoAppSignFileCheck, SIGNAL( stateChanged(int) ),
02495            this, SLOT( slotEmitChanged( void ) ) );
02496 
02497   mSmartQuoteCheck = new QCheckBox(
02498            GlobalSettings::self()->smartQuoteItem()->label(),
02499            this, "kcfg_SmartQuote" );
02500   vlay->addWidget( mSmartQuoteCheck );
02501   connect( mSmartQuoteCheck, SIGNAL( stateChanged(int) ),
02502            this, SLOT( slotEmitChanged( void ) ) );
02503 
02504   mAutoRequestMDNCheck = new QCheckBox(
02505            GlobalSettings::self()->requestMDNItem()->label(),
02506            this, "kcfg_RequestMDN" );
02507   vlay->addWidget( mAutoRequestMDNCheck );
02508   connect( mAutoRequestMDNCheck, SIGNAL( stateChanged(int) ),
02509            this, SLOT( slotEmitChanged( void ) ) );
02510 
02511   mShowRecentAddressesInComposer = new QCheckBox(
02512            GlobalSettings::self()->showRecentAddressesInComposerItem()->label(),
02513            this, "kcfg_ShowRecentAddressesInComposer" );
02514   vlay->addWidget( mShowRecentAddressesInComposer );
02515   connect( mShowRecentAddressesInComposer, SIGNAL( stateChanged(int) ),
02516            this, SLOT( slotEmitChanged( void ) ) );
02517 
02518   // a checkbox for "word wrap" and a spinbox for the column in
02519   // which to wrap:
02520   hlay = new QHBoxLayout( vlay ); // inherits spacing
02521   mWordWrapCheck = new QCheckBox(
02522            GlobalSettings::self()->wordWrapItem()->label(),
02523            this, "kcfg_WordWrap" );
02524   hlay->addWidget( mWordWrapCheck );
02525   connect( mWordWrapCheck, SIGNAL( stateChanged(int) ),
02526            this, SLOT( slotEmitChanged( void ) ) );
02527 
02528   mWrapColumnSpin = new KIntSpinBox( 30/*min*/, 78/*max*/, 1/*step*/,
02529            78/*init*/, 10 /*base*/, this, "kcfg_LineWrapWidth" );
02530   mWrapColumnSpin->setEnabled( false ); // since !mWordWrapCheck->isChecked()
02531   connect( mWrapColumnSpin, SIGNAL( valueChanged(int) ),
02532            this, SLOT( slotEmitChanged( void ) ) );
02533 
02534   hlay->addWidget( mWrapColumnSpin );
02535   hlay->addStretch( 1 );
02536   // only enable the spinbox if the checkbox is checked:
02537   connect( mWordWrapCheck, SIGNAL(toggled(bool)),
02538            mWrapColumnSpin, SLOT(setEnabled(bool)) );
02539 
02540   hlay = new QHBoxLayout( vlay ); // inherits spacing
02541   mAutoSave = new KIntSpinBox( 0, 60, 1, 1, 10, this, "kcfg_AutosaveInterval" );
02542   label = new QLabel( mAutoSave,
02543            GlobalSettings::self()->autosaveIntervalItem()->label(), this );
02544   hlay->addWidget( label );
02545   hlay->addWidget( mAutoSave );
02546   mAutoSave->setSpecialValueText( i18n("No autosave") );
02547   mAutoSave->setSuffix( i18n(" min") );
02548   hlay->addStretch( 1 );
02549   connect( mAutoSave, SIGNAL( valueChanged(int) ),
02550            this, SLOT( slotEmitChanged( void ) ) );
02551 
02552   hlay = new QHBoxLayout( vlay ); // inherits spacing
02553   QPushButton *completionOrderBtn = new QPushButton( i18n( "Configure Completion Order" ), this );
02554   connect( completionOrderBtn, SIGNAL( clicked() ),
02555            this, SLOT( slotConfigureCompletionOrder() ) );
02556   hlay->addWidget( completionOrderBtn );
02557   hlay->addItem( new QSpacerItem(0, 0) );
02558 
02559   // recent addresses
02560   hlay = new QHBoxLayout( vlay ); // inherits spacing
02561   QPushButton *recentAddressesBtn = new QPushButton( i18n( "Edit Recent Addresses" ), this );
02562   connect( recentAddressesBtn, SIGNAL( clicked() ),
02563            this, SLOT( slotConfigureRecentAddresses() ) );
02564   hlay->addWidget( recentAddressesBtn );
02565   hlay->addItem( new QSpacerItem(0, 0) );
02566 
02567   // The "external editor" group:
02568   group = new QVGroupBox( i18n("External Editor"), this );
02569   group->layout()->setSpacing( KDialog::spacingHint() );
02570 
02571   mExternalEditorCheck = new QCheckBox(
02572            GlobalSettings::self()->useExternalEditorItem()->label(),
02573            group, "kcfg_UseExternalEditor" );
02574   connect( mExternalEditorCheck, SIGNAL( toggled( bool ) ),
02575            this, SLOT( slotEmitChanged( void ) ) );
02576 
02577   hbox = new QHBox( group );
02578   label = new QLabel( GlobalSettings::self()->externalEditorItem()->label(),
02579                    hbox );
02580   mEditorRequester = new KURLRequester( hbox, "kcfg_ExternalEditor" );
02581   connect( mEditorRequester, SIGNAL( urlSelected(const QString&) ),
02582            this, SLOT( slotEmitChanged( void ) ) );
02583   connect( mEditorRequester, SIGNAL( textChanged(const QString&) ),
02584            this, SLOT( slotEmitChanged( void ) ) );
02585 
02586   hbox->setStretchFactor( mEditorRequester, 1 );
02587   label->setBuddy( mEditorRequester );
02588   label->setEnabled( false ); // since !mExternalEditorCheck->isChecked()
02589   // ### FIXME: allow only executables (x-bit when available..)
02590   mEditorRequester->setFilter( "application/x-executable "
02591                                "application/x-shellscript "
02592                                "application/x-desktop" );
02593   mEditorRequester->setEnabled( false ); // !mExternalEditorCheck->isChecked()
02594   connect( mExternalEditorCheck, SIGNAL(toggled(bool)),
02595            label, SLOT(setEnabled(bool)) );
02596   connect( mExternalEditorCheck, SIGNAL(toggled(bool)),
02597            mEditorRequester, SLOT(setEnabled(bool)) );
02598 
02599   label = new QLabel( i18n("<b>%f</b> will be replaced with the "
02600                            "filename to edit."), group );
02601   label->setEnabled( false ); // see above
02602   connect( mExternalEditorCheck, SIGNAL(toggled(bool)),
02603            label, SLOT(setEnabled(bool)) );
02604 
02605   vlay->addWidget( group );
02606   vlay->addStretch( 100 );
02607 }
02608 
02609 void ComposerPage::GeneralTab::doLoadFromGlobalSettings() {
02610   // various check boxes:
02611 
02612   mAutoAppSignFileCheck->setChecked(
02613            GlobalSettings::self()->autoTextSignature()=="auto" );
02614   mSmartQuoteCheck->setChecked( GlobalSettings::self()->smartQuote() );
02615   mAutoRequestMDNCheck->setChecked( GlobalSettings::self()->requestMDN() );
02616   mWordWrapCheck->setChecked( GlobalSettings::self()->wordWrap() );
02617 
02618   mWrapColumnSpin->setValue( GlobalSettings::self()->lineWrapWidth() );
02619   mAutoSave->setValue( GlobalSettings::self()->autosaveInterval() );
02620 
02621   // editor group:
02622   mExternalEditorCheck->setChecked( GlobalSettings::self()->useExternalEditor() );
02623   mEditorRequester->setURL( GlobalSettings::self()->externalEditor() );
02624 }
02625 
02626 void ComposerPage::GeneralTab::installProfile( KConfig * profile ) {
02627   KConfigGroup composer( profile, "Composer" );
02628   KConfigGroup general( profile, "General" );
02629 
02630   if ( composer.hasKey( "signature" ) ) {
02631     bool state = composer.readBoolEntry("signature");
02632     mAutoAppSignFileCheck->setChecked( state );
02633   }
02634   if ( composer.hasKey( "smart-quote" ) )
02635     mSmartQuoteCheck->setChecked( composer.readBoolEntry( "smart-quote" ) );
02636   if ( composer.hasKey( "request-mdn" ) )
02637     mAutoRequestMDNCheck->setChecked( composer.readBoolEntry( "request-mdn" ) );
02638   if ( composer.hasKey( "word-wrap" ) )
02639     mWordWrapCheck->setChecked( composer.readBoolEntry( "word-wrap" ) );
02640   if ( composer.hasKey( "break-at" ) )
02641     mWrapColumnSpin->setValue( composer.readNumEntry( "break-at" ) );
02642   if ( composer.hasKey( "autosave" ) )
02643     mAutoSave->setValue( composer.readNumEntry( "autosave" ) );
02644 
02645   if ( general.hasKey( "use-external-editor" )
02646        && general.hasKey( "external-editor" ) ) {
02647     mExternalEditorCheck->setChecked( general.readBoolEntry( "use-external-editor" ) );
02648     mEditorRequester->setURL( general.readPathEntry( "external-editor" ) );
02649   }
02650 }
02651 
02652 void ComposerPage::GeneralTab::save() {
02653   GlobalSettings::self()->setAutoTextSignature(
02654          mAutoAppSignFileCheck->isChecked() ? "auto" : "manual" );
02655   GlobalSettings::self()->setSmartQuote( mSmartQuoteCheck->isChecked() );
02656   GlobalSettings::self()->setRequestMDN( mAutoRequestMDNCheck->isChecked() );
02657   GlobalSettings::self()->setWordWrap( mWordWrapCheck->isChecked() );
02658 
02659   GlobalSettings::self()->setLineWrapWidth( mWrapColumnSpin->value() );
02660   GlobalSettings::self()->setAutosaveInterval( mAutoSave->value() );
02661 
02662   // editor group:
02663   GlobalSettings::self()->setUseExternalEditor( mExternalEditorCheck->isChecked() );
02664   GlobalSettings::self()->setExternalEditor( mEditorRequester->url() );
02665 }
02666 
02667 void ComposerPage::GeneralTab::slotConfigureRecentAddresses( )
02668 {
02669   KRecentAddress::RecentAddressDialog dlg( this );
02670   dlg.setAddresses( RecentAddresses::self( KMKernel::config() )->addresses() );
02671   if ( dlg.exec() ) {
02672     RecentAddresses::self( KMKernel::config() )->clear();
02673     const QStringList &addrList = dlg.addresses();
02674     QStringList::ConstIterator it;
02675     for ( it = addrList.constBegin(); it != addrList.constEnd(); ++it )
02676       RecentAddresses::self( KMKernel::config() )->add( *it );
02677   }
02678 }
02679 
02680 void ComposerPage::GeneralTab::slotConfigureCompletionOrder( )
02681 {
02682   KPIM::LdapSearch search;
02683   KPIM::CompletionOrderEditor editor( &search, this );
02684   editor.exec();
02685 }
02686 
02687 QString ComposerPage::PhrasesTab::helpAnchor() const {
02688   return QString::fromLatin1("configure-composer-phrases");
02689 }
02690 
02691 ComposerPagePhrasesTab::ComposerPagePhrasesTab( QWidget * parent, const char * name )
02692   : ConfigModuleTab( parent, name )
02693 {
02694   // tmp. vars:
02695   QGridLayout *glay;
02696   QPushButton *button;
02697 
02698   glay = new QGridLayout( this, 7, 3, KDialog::spacingHint() );
02699   glay->setMargin( KDialog::marginHint() );
02700   glay->setColStretch( 1, 1 );
02701   glay->setColStretch( 2, 1 );
02702   glay->setRowStretch( 7, 1 );
02703 
02704   // row 0: help text
02705   glay->addMultiCellWidget( new QLabel( i18n("<qt>The following placeholders are "
02706                                              "supported in the reply phrases:<br>"
02707                                              "<b>%D</b>: date, <b>%S</b>: subject,<br>"
02708                                              "<b>%e</b>: sender's address, <b>%F</b>: sender's name, <b>%f</b>: sender's initials,<br>"
02709                                              "<b>%T</b>: recipient's name, <b>%t</b>: recipient's name and address,<br>"
02710                                              "<b>%C</b>: carbon copy names, <b>%c</b>: carbon copy names and addresses,<br>"
02711                                              "<b>%%</b>: percent sign, <b>%_</b>: space, "
02712                                              "<b>%L</b>: linebreak</qt>"), this ),
02713                             0, 0, 0, 2 ); // row 0; cols 0..2
02714 
02715   // row 1: label and language combo box:
02716   mPhraseLanguageCombo = new LanguageComboBox( false, this );
02717   glay->addWidget( new QLabel( mPhraseLanguageCombo,
02718                                i18n("Lang&uage:"), this ), 1, 0 );
02719   glay->addMultiCellWidget( mPhraseLanguageCombo, 1, 1, 1, 2 );
02720   connect( mPhraseLanguageCombo, SIGNAL(activated(const QString&)),
02721            this, SLOT(slotLanguageChanged(const QString&)) );
02722 
02723   // row 2: "add..." and "remove" push buttons:
02724   button = new QPushButton( i18n("A&dd..."), this );
02725   button->setAutoDefault( false );
02726   glay->addWidget( button, 2, 1 );
02727   mRemoveButton = new QPushButton( i18n("Re&move"), this );
02728   mRemoveButton->setAutoDefault( false );
02729   mRemoveButton->setEnabled( false ); // combo doesn't contain anything...
02730   glay->addWidget( mRemoveButton, 2, 2 );
02731   connect( button, SIGNAL(clicked()),
02732            this, SLOT(slotNewLanguage()) );
02733   connect( mRemoveButton, SIGNAL(clicked()),
02734            this, SLOT(slotRemoveLanguage()) );
02735 
02736   // row 3: "reply to sender" line edit and label:
02737   mPhraseReplyEdit = new KLineEdit( this );
02738   connect( mPhraseReplyEdit, SIGNAL( textChanged( const QString& ) ),
02739            this, SLOT( slotEmitChanged( void ) ) );
02740   glay->addWidget( new QLabel( mPhraseReplyEdit,
02741                                i18n("Reply to se&nder:"), this ), 3, 0 );
02742   glay->addMultiCellWidget( mPhraseReplyEdit, 3, 3, 1, 2 ); // cols 1..2
02743 
02744   // row 4: "reply to all" line edit and label:
02745   mPhraseReplyAllEdit = new KLineEdit( this );
02746   connect( mPhraseReplyAllEdit, SIGNAL( textChanged( const QString& ) ),
02747            this, SLOT( slotEmitChanged( void ) ) );
02748   glay->addWidget( new QLabel( mPhraseReplyAllEdit,
02749                                i18n("Repl&y to all:"), this ), 4, 0 );
02750   glay->addMultiCellWidget( mPhraseReplyAllEdit, 4, 4, 1, 2 ); // cols 1..2
02751 
02752   // row 5: "forward" line edit and label:
02753   mPhraseForwardEdit = new KLineEdit( this );
02754   connect( mPhraseForwardEdit, SIGNAL( textChanged( const QString& ) ),
02755            this, SLOT( slotEmitChanged( void ) ) );
02756   glay->addWidget( new QLabel( mPhraseForwardEdit,
02757                                i18n("&Forward:"), this ), 5, 0 );
02758   glay->addMultiCellWidget( mPhraseForwardEdit, 5, 5, 1, 2 ); // cols 1..2
02759 
02760   // row 6: "quote indicator" line edit and label:
02761   mPhraseIndentPrefixEdit = new KLineEdit( this );
02762   connect( mPhraseIndentPrefixEdit, SIGNAL( textChanged( const QString& ) ),
02763            this, SLOT( slotEmitChanged( void ) ) );
02764   glay->addWidget( new QLabel( mPhraseIndentPrefixEdit,
02765                                i18n("&Quote indicator:"), this ), 6, 0 );
02766   glay->addMultiCellWidget( mPhraseIndentPrefixEdit, 6, 6, 1, 2 );
02767 
02768   // row 7: spacer
02769 }
02770 
02771 
02772 void ComposerPage::PhrasesTab::setLanguageItemInformation( int index ) {
02773   assert( 0 <= index && index < (int)mLanguageList.count() );
02774 
02775   LanguageItem &l = *mLanguageList.at( index );
02776 
02777   mPhraseReplyEdit->setText( l.mReply );
02778   mPhraseReplyAllEdit->setText( l.mReplyAll );
02779   mPhraseForwardEdit->setText( l.mForward );
02780   mPhraseIndentPrefixEdit->setText( l.mIndentPrefix );
02781 }
02782 
02783 void ComposerPage::PhrasesTab::saveActiveLanguageItem() {
02784   int index = mActiveLanguageItem;
02785   if (index == -1) return;
02786   assert( 0 <= index && index < (int)mLanguageList.count() );
02787 
02788   LanguageItem &l = *mLanguageList.at( index );
02789 
02790   l.mReply = mPhraseReplyEdit->text();
02791   l.mReplyAll = mPhraseReplyAllEdit->text();
02792   l.mForward = mPhraseForwardEdit->text();
02793   l.mIndentPrefix = mPhraseIndentPrefixEdit->text();
02794 }
02795 
02796 void ComposerPage::PhrasesTab::slotNewLanguage()
02797 {
02798   NewLanguageDialog dialog( mLanguageList, parentWidget(), "New", true );
02799   if ( dialog.exec() == QDialog::Accepted ) slotAddNewLanguage( dialog.language() );
02800 }
02801 
02802 void ComposerPage::PhrasesTab::slotAddNewLanguage( const QString& lang )
02803 {
02804   mPhraseLanguageCombo->setCurrentItem(
02805     mPhraseLanguageCombo->insertLanguage( lang ) );
02806   KLocale locale("kmail");
02807   locale.setLanguage( lang );
02808   mLanguageList.append(
02809      LanguageItem( lang,
02810                    locale.translate("On %D, you wrote:"),
02811                    locale.translate("On %D, %F wrote:"),
02812                    locale.translate("Forwarded Message"),
02813                    locale.translate(">%_") ) );
02814   mRemoveButton->setEnabled( true );
02815   slotLanguageChanged( QString::null );
02816 }
02817 
02818 void ComposerPage::PhrasesTab::slotRemoveLanguage()
02819 {
02820   assert( mPhraseLanguageCombo->count() > 1 );
02821   int index = mPhraseLanguageCombo->currentItem();
02822   assert( 0 <= index && index < (int)mLanguageList.count() );
02823 
02824   // remove current item from internal list and combobox:
02825   mLanguageList.remove( mLanguageList.at( index ) );
02826   mPhraseLanguageCombo->removeItem( index );
02827 
02828   if ( index >= (int)mLanguageList.count() ) index--;
02829 
02830   mActiveLanguageItem = index;
02831   setLanguageItemInformation( index );
02832   mRemoveButton->setEnabled( mLanguageList.count() > 1 );
02833   emit changed( true );
02834 }
02835 
02836 void ComposerPage::PhrasesTab::slotLanguageChanged( const QString& )
02837 {
02838   int index = mPhraseLanguageCombo->currentItem();
02839   assert( index < (int)mLanguageList.count() );
02840   saveActiveLanguageItem();
02841   mActiveLanguageItem = index;
02842   setLanguageItemInformation( index );
02843   emit changed( true );
02844 }
02845 
02846 
02847 void ComposerPage::PhrasesTab::doLoadFromGlobalSettings() {
02848   mLanguageList.clear();
02849   mPhraseLanguageCombo->clear();
02850   mActiveLanguageItem = -1;
02851 
02852   int numLang = GlobalSettings::self()->replyLanguagesCount();
02853   int currentNr = GlobalSettings::self()->replyCurrentLanguage();
02854 
02855   // build mLanguageList and mPhraseLanguageCombo:
02856   for ( int i = 0 ; i < numLang ; i++ ) {
02857     ReplyPhrases replyPhrases( QString::number(i) );
02858     replyPhrases.readConfig();
02859     QString lang = replyPhrases.language();
02860     mLanguageList.append(
02861          LanguageItem( lang,
02862                        replyPhrases.phraseReplySender(),
02863                        replyPhrases.phraseReplyAll(),
02864                        replyPhrases.phraseForward(),
02865                        replyPhrases.indentPrefix() ) );
02866     mPhraseLanguageCombo->insertLanguage( lang );
02867   }
02868 
02869   if ( currentNr >= numLang || currentNr < 0 )
02870     currentNr = 0;
02871 
02872   if ( numLang == 0 ) {
02873     slotAddNewLanguage( KGlobal::locale()->language() );
02874   }
02875 
02876   mPhraseLanguageCombo->setCurrentItem( currentNr );
02877   mActiveLanguageItem = currentNr;
02878   setLanguageItemInformation( currentNr );
02879   mRemoveButton->setEnabled( mLanguageList.count() > 1 );
02880 }
02881 
02882 void ComposerPage::PhrasesTab::save() {
02883   GlobalSettings::self()->setReplyLanguagesCount( mLanguageList.count() );
02884   GlobalSettings::self()->setReplyCurrentLanguage( mPhraseLanguageCombo->currentItem() );
02885 
02886   saveActiveLanguageItem();
02887   LanguageItemList::Iterator it = mLanguageList.begin();
02888   for ( int i = 0 ; it != mLanguageList.end() ; ++it, ++i ) {
02889     ReplyPhrases replyPhrases( QString::number(i) );
02890     replyPhrases.setLanguage( (*it).mLanguage );
02891     replyPhrases.setPhraseReplySender( (*it).mReply );
02892     replyPhrases.setPhraseReplyAll( (*it).mReplyAll );
02893     replyPhrases.setPhraseForward( (*it).mForward );
02894     replyPhrases.setIndentPrefix( (*it).mIndentPrefix );
02895     replyPhrases.writeConfig();
02896   }
02897 }
02898 
02899 QString ComposerPage::SubjectTab::helpAnchor() const {
02900   return QString::fromLatin1("configure-composer-subject");
02901 }
02902 
02903 ComposerPageSubjectTab::ComposerPageSubjectTab( QWidget * parent, const char * name )
02904   : ConfigModuleTab( parent, name )
02905 {
02906   // tmp. vars:
02907   QVBoxLayout *vlay;
02908   QGroupBox   *group;
02909   QLabel      *label;
02910 
02911 
02912   vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
02913 
02914   group = new QVGroupBox( i18n("Repl&y Subject Prefixes"), this );
02915   group->layout()->setSpacing( KDialog::spacingHint() );
02916 
02917   // row 0: help text:
02918   label = new QLabel( i18n("Recognize any sequence of the following prefixes\n"
02919                            "(entries are case-insensitive regular expressions):"), group );
02920   label->setAlignment( AlignLeft|WordBreak );
02921 
02922   // row 1, string list editor:
02923   SimpleStringListEditor::ButtonCode buttonCode =
02924     static_cast<SimpleStringListEditor::ButtonCode>( SimpleStringListEditor::Add | SimpleStringListEditor::Remove | SimpleStringListEditor::Modify );
02925   mReplyListEditor =
02926     new SimpleStringListEditor( group, 0, buttonCode,
02927                                 i18n("A&dd..."), i18n("Re&move"),
02928                                 i18n("Mod&ify..."),
02929                                 i18n("Enter new reply prefix:") );
02930   connect( mReplyListEditor, SIGNAL( changed( void ) ),
02931            this, SLOT( slotEmitChanged( void ) ) );
02932 
02933   // row 2: "replace [...]" check box:
02934   mReplaceReplyPrefixCheck = new QCheckBox(
02935      GlobalSettings::self()->replaceReplyPrefixItem()->label(),
02936      group, "kcfg_ReplaceReplyPrefix" );
02937   connect( mReplaceReplyPrefixCheck, SIGNAL( stateChanged( int ) ),
02938            this, SLOT( slotEmitChanged( void ) ) );
02939 
02940   vlay->addWidget( group );
02941 
02942 
02943   group = new QVGroupBox( i18n("For&ward Subject Prefixes"), this );
02944   group->layout()->setSpacing( KDialog::marginHint() );
02945 
02946   // row 0: help text:
02947   label= new QLabel( i18n("Recognize any sequence of the following prefixes\n"
02948                           "(entries are case-insensitive regular expressions):"), group );
02949   label->setAlignment( AlignLeft|WordBreak );
02950 
02951   // row 1: string list editor
02952   mForwardListEditor =
02953     new SimpleStringListEditor( group, 0, buttonCode,
02954                                 i18n("Add..."),
02955                                 i18n("Remo&ve"),
02956                                 i18n("Modify..."),
02957                                 i18n("Enter new forward prefix:") );
02958   connect( mForwardListEditor, SIGNAL( changed( void ) ),
02959            this, SLOT( slotEmitChanged( void ) ) );
02960 
02961   // row 3: "replace [...]" check box:
02962   mReplaceForwardPrefixCheck = new QCheckBox(
02963        GlobalSettings::self()->replaceForwardPrefixItem()->label(),
02964        group, "kcfg_ReplaceForwardPrefix" );
02965   connect( mReplaceForwardPrefixCheck, SIGNAL( stateChanged( int ) ),
02966            this, SLOT( slotEmitChanged( void ) ) );
02967 
02968   vlay->addWidget( group );
02969 }
02970 
02971 void ComposerPage::SubjectTab::doLoadFromGlobalSettings() {
02972   mReplyListEditor->setStringList( GlobalSettings::self()->replyPrefixes() );
02973   mReplaceReplyPrefixCheck->setChecked( GlobalSettings::self()->replaceReplyPrefix() );
02974   mForwardListEditor->setStringList( GlobalSettings::self()->forwardPrefixes() );
02975   mReplaceForwardPrefixCheck->setChecked( GlobalSettings::self()->replaceForwardPrefix() );
02976 }
02977 
02978 void ComposerPage::SubjectTab::save() {
02979   GlobalSettings::self()->setReplyPrefixes( mReplyListEditor->stringList() );
02980   GlobalSettings::self()->setForwardPrefixes( mForwardListEditor->stringList() );
02981 }
02982 
02983 QString ComposerPage::CharsetTab::helpAnchor() const {
02984   return QString::fromLatin1("configure-composer-charset");
02985 }
02986 
02987 ComposerPageCharsetTab::ComposerPageCharsetTab( QWidget * parent, const char * name )
02988   : ConfigModuleTab( parent, name )
02989 {
02990   // tmp. vars:
02991   QVBoxLayout *vlay;
02992   QLabel      *label;
02993 
02994   vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
02995 
02996   label = new QLabel( i18n("This list is checked for every outgoing message "
02997                            "from the top to the bottom for a charset that "
02998                            "contains all required characters."), this );
02999   label->setAlignment( WordBreak);
03000   vlay->addWidget( label );
03001 
03002   mCharsetListEditor =
03003     new SimpleStringListEditor( this, 0, SimpleStringListEditor::All,
03004                                 i18n("A&dd..."), i18n("Remo&ve"),
03005                                 i18n("&Modify..."), i18n("Enter charset:") );
03006   connect( mCharsetListEditor, SIGNAL( changed( void ) ),
03007            this, SLOT( slotEmitChanged( void ) ) );
03008 
03009   vlay->addWidget( mCharsetListEditor, 1 );
03010 
03011   mKeepReplyCharsetCheck = new QCheckBox( i18n("&Keep original charset when "
03012                                                 "replying or forwarding (if "
03013                                                 "possible)"), this );
03014   connect( mKeepReplyCharsetCheck, SIGNAL ( stateChanged( int ) ),
03015            this, SLOT( slotEmitChanged( void ) ) );
03016   vlay->addWidget( mKeepReplyCharsetCheck );
03017 
03018   connect( mCharsetListEditor, SIGNAL(aboutToAdd(QString&)),
03019            this, SLOT(slotVerifyCharset(QString&)) );
03020 }
03021 
03022 void ComposerPage::CharsetTab::slotVerifyCharset( QString & charset ) {
03023   if ( charset.isEmpty() ) return;
03024 
03025   // KCharsets::codecForName("us-ascii") returns "iso-8859-1" (cf. Bug #49812)
03026   // therefore we have to treat this case specially
03027   if ( charset.lower() == QString::fromLatin1("us-ascii") ) {
03028     charset = QString::fromLatin1("us-ascii");
03029     return;
03030   }
03031 
03032   if ( charset.lower() == QString::fromLatin1("locale") ) {
03033     charset =  QString::fromLatin1("%1 (locale)")
03034       .arg( QCString( kmkernel->networkCodec()->mimeName() ).lower() );
03035     return;
03036   }
03037 
03038   bool ok = false;
03039   QTextCodec *codec = KGlobal::charsets()->codecForName( charset, ok );
03040   if ( ok && codec ) {
03041     charset = QString::fromLatin1( codec->mimeName() ).lower();
03042     return;
03043   }
03044 
03045   KMessageBox::sorry( this, i18n("This charset is not supported.") );
03046   charset = QString::null;
03047 }
03048 
03049 void ComposerPage::CharsetTab::doLoadOther() {
03050   KConfigGroup composer( KMKernel::config(), "Composer" );
03051 
03052   QStringList charsets = composer.readListEntry( "pref-charsets" );
03053   for ( QStringList::Iterator it = charsets.begin() ;
03054         it != charsets.end() ; ++it )
03055     if ( (*it) == QString::fromLatin1("locale") ) {
03056       QCString cset = kmkernel->networkCodec()->mimeName();
03057       KPIM::kAsciiToLower( cset.data() );
03058       (*it) = QString("%1 (locale)").arg( cset );
03059     }
03060 
03061   mCharsetListEditor->setStringList( charsets );
03062   mKeepReplyCharsetCheck->setChecked( !composer.readBoolEntry( "force-reply-charset", false ) );
03063 }
03064 
03065 void ComposerPage::CharsetTab::save() {
03066   KConfigGroup composer( KMKernel::config(), "Composer" );
03067 
03068   QStringList charsetList = mCharsetListEditor->stringList();
03069   QStringList::Iterator it = charsetList.begin();
03070   for ( ; it != charsetList.end() ; ++it )
03071     if ( (*it).endsWith("(locale)") )
03072       (*it) = "locale";
03073   composer.writeEntry( "pref-charsets", charsetList );
03074   composer.writeEntry( "force-reply-charset",
03075                        !mKeepReplyCharsetCheck->isChecked() );
03076 }
03077 
03078 QString ComposerPage::HeadersTab::helpAnchor() const {
03079   return QString::fromLatin1("configure-composer-headers");
03080 }
03081 
03082 ComposerPageHeadersTab::ComposerPageHeadersTab( QWidget * parent, const char * name )
03083   : ConfigModuleTab( parent, name )
03084 {
03085   // tmp. vars:
03086   QVBoxLayout *vlay;
03087   QHBoxLayout *hlay;
03088   QGridLayout *glay;
03089   QLabel      *label;
03090   QPushButton *button;
03091 
03092   vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
03093 
03094   // "Use custom Message-Id suffix" checkbox:
03095   mCreateOwnMessageIdCheck =
03096     new QCheckBox( i18n("&Use custom message-id suffix"), this );
03097   connect( mCreateOwnMessageIdCheck, SIGNAL ( stateChanged( int ) ),
03098            this, SLOT( slotEmitChanged( void ) ) );
03099   vlay->addWidget( mCreateOwnMessageIdCheck );
03100 
03101   // "Message-Id suffix" line edit and label:
03102   hlay = new QHBoxLayout( vlay ); // inherits spacing
03103   mMessageIdSuffixEdit = new KLineEdit( this );
03104   // only ASCII letters, digits, plus, minus and dots are allowed
03105   mMessageIdSuffixValidator =
03106     new QRegExpValidator( QRegExp( "[a-zA-Z0-9+-]+(?:\\.[a-zA-Z0-9+-]+)*" ), this );
03107   mMessageIdSuffixEdit->setValidator( mMessageIdSuffixValidator );
03108   label = new QLabel( mMessageIdSuffixEdit,
03109                       i18n("Custom message-&id suffix:"), this );
03110   label->setEnabled( false ); // since !mCreateOwnMessageIdCheck->isChecked()
03111   mMessageIdSuffixEdit->setEnabled( false );
03112   hlay->addWidget( label );
03113   hlay->addWidget( mMessageIdSuffixEdit, 1 );
03114   connect( mCreateOwnMessageIdCheck, SIGNAL(toggled(bool) ),
03115            label, SLOT(setEnabled(bool)) );
03116   connect( mCreateOwnMessageIdCheck, SIGNAL(toggled(bool) ),
03117            mMessageIdSuffixEdit, SLOT(setEnabled(bool)) );
03118   connect( mMessageIdSuffixEdit, SIGNAL( textChanged( const QString& ) ),
03119            this, SLOT( slotEmitChanged( void ) ) );
03120 
03121   // horizontal rule and "custom header fields" label:
03122   vlay->addWidget( new KSeparator( KSeparator::HLine, this ) );
03123   vlay->addWidget( new QLabel( i18n("Define custom mime header fields:"), this) );
03124 
03125   // "custom header fields" listbox:
03126   glay = new QGridLayout( vlay, 5, 3 ); // inherits spacing
03127   glay->setRowStretch( 2, 1 );
03128   glay->setColStretch( 1, 1 );
03129   mTagList = new ListView( this, "tagList" );
03130   mTagList->addColumn( i18n("Name") );
03131   mTagList->addColumn( i18n("Value") );
03132   mTagList->setAllColumnsShowFocus( true );
03133   mTagList->setSorting( -1 );
03134   connect( mTagList, SIGNAL(selectionChanged()),
03135            this, SLOT(slotMimeHeaderSelectionChanged()) );
03136   glay->addMultiCellWidget( mTagList, 0, 2, 0, 1 );
03137 
03138   // "new" and "remove" buttons:
03139   button = new QPushButton( i18n("Ne&w"), this );
03140   connect( button, SIGNAL(clicked()), this, SLOT(slotNewMimeHeader()) );
03141   button->setAutoDefault( false );
03142   glay->addWidget( button, 0, 2 );
03143   mRemoveHeaderButton = new QPushButton( i18n("Re&move"), this );
03144   connect( mRemoveHeaderButton, SIGNAL(clicked()),
03145            this, SLOT(slotRemoveMimeHeader()) );
03146   button->setAutoDefault( false );
03147   glay->addWidget( mRemoveHeaderButton, 1, 2 );
03148 
03149   // "name" and "value" line edits and labels:
03150   mTagNameEdit = new KLineEdit( this );
03151   mTagNameEdit->setEnabled( false );
03152   mTagNameLabel = new QLabel( mTagNameEdit, i18n("&Name:"), this );
03153   mTagNameLabel->setEnabled( false );
03154   glay->addWidget( mTagNameLabel, 3, 0 );
03155   glay->addWidget( mTagNameEdit, 3, 1 );
03156   connect( mTagNameEdit, SIGNAL(textChanged(const QString&)),
03157            this, SLOT(slotMimeHeaderNameChanged(const QString&)) );
03158 
03159   mTagValueEdit = new KLineEdit( this );
03160   mTagValueEdit->setEnabled( false );
03161   mTagValueLabel = new QLabel( mTagValueEdit, i18n("&Value:"), this );
03162   mTagValueLabel->setEnabled( false );
03163   glay->addWidget( mTagValueLabel, 4, 0 );
03164   glay->addWidget( mTagValueEdit, 4, 1 );
03165   connect( mTagValueEdit, SIGNAL(textChanged(const QString&)),
03166            this, SLOT(slotMimeHeaderValueChanged(const QString&)) );
03167 }
03168 
03169 void ComposerPage::HeadersTab::slotMimeHeaderSelectionChanged()
03170 {
03171   QListViewItem * item = mTagList->selectedItem();
03172 
03173   if ( item ) {
03174     mTagNameEdit->setText( item->text( 0 ) );
03175     mTagValueEdit->setText( item->text( 1 ) );
03176   } else {
03177     mTagNameEdit->clear();
03178     mTagValueEdit->clear();
03179   }
03180   mRemoveHeaderButton->setEnabled( item );
03181   mTagNameEdit->setEnabled( item );
03182   mTagValueEdit->setEnabled( item );
03183   mTagNameLabel->setEnabled( item );
03184   mTagValueLabel->setEnabled( item );
03185 }
03186 
03187 
03188 void ComposerPage::HeadersTab::slotMimeHeaderNameChanged( const QString & text ) {
03189   // is called on ::setup(), when clearing the line edits. So be
03190   // prepared to not find a selection:
03191   QListViewItem * item = mTagList->selectedItem();
03192   if ( item )
03193     item->setText( 0, text );
03194   emit changed( true );
03195 }
03196 
03197 
03198 void ComposerPage::HeadersTab::slotMimeHeaderValueChanged( const QString & text ) {
03199   // is called on ::setup(), when clearing the line edits. So be
03200   // prepared to not find a selection:
03201   QListViewItem * item = mTagList->selectedItem();
03202   if ( item )
03203     item->setText( 1, text );
03204   emit changed( true );
03205 }
03206 
03207 
03208 void ComposerPage::HeadersTab::slotNewMimeHeader()
03209 {
03210   QListViewItem *listItem = new QListViewItem( mTagList );
03211   mTagList->setCurrentItem( listItem );
03212   mTagList->setSelected( listItem, true );
03213   emit changed( true );
03214 }
03215 
03216 
03217 void ComposerPage::HeadersTab::slotRemoveMimeHeader()
03218 {
03219   // calling this w/o selection is a programming error:
03220   QListViewItem * item = mTagList->selectedItem();
03221   if ( !item ) {
03222     kdDebug(5006) << "==================================================\n"
03223                   << "Error: Remove button was pressed although no custom header was selected\n"
03224                   << "==================================================\n";
03225     return;
03226   }
03227 
03228   QListViewItem * below = item->nextSibling();
03229   delete item;
03230 
03231   if ( below )
03232     mTagList->setSelected( below, true );
03233   else if ( mTagList->lastItem() )
03234     mTagList->setSelected( mTagList->lastItem(), true );
03235   emit changed( true );
03236 }
03237 
03238 void ComposerPage::HeadersTab::doLoadOther() {
03239   KConfigGroup general( KMKernel::config(), "General" );
03240 
03241   QString suffix = general.readEntry( "myMessageIdSuffix" );
03242   mMessageIdSuffixEdit->setText( suffix );
03243   bool state = ( !suffix.isEmpty() &&
03244             general.readBoolEntry( "useCustomMessageIdSuffix", false ) );
03245   mCreateOwnMessageIdCheck->setChecked( state );
03246 
03247   mTagList->clear();
03248   mTagNameEdit->clear();
03249   mTagValueEdit->clear();
03250 
03251   QListViewItem * item = 0;
03252 
03253   int count = general.readNumEntry( "mime-header-count", 0 );
03254   for( int i = 0 ; i < count ; i++ ) {
03255     KConfigGroup config( KMKernel::config(),
03256                          QCString("Mime #") + QCString().setNum(i) );
03257     QString name  = config.readEntry( "name" );
03258     QString value = config.readEntry( "value" );
03259     if( !name.isEmpty() )
03260       item = new QListViewItem( mTagList, item, name, value );
03261   }
03262   if ( mTagList->childCount() ) {
03263     mTagList->setCurrentItem( mTagList->firstChild() );
03264     mTagList->setSelected( mTagList->firstChild(), true );
03265   }
03266   else {
03267     // disable the "Remove" button
03268     mRemoveHeaderButton->setEnabled( false );
03269   }
03270 }
03271 
03272 void ComposerPage::HeadersTab::save() {
03273   KConfigGroup general( KMKernel::config(), "General" );
03274 
03275   general.writeEntry( "useCustomMessageIdSuffix",
03276                       mCreateOwnMessageIdCheck->isChecked() );
03277   general.writeEntry( "myMessageIdSuffix",
03278                       mMessageIdSuffixEdit->text() );
03279 
03280   int numValidEntries = 0;
03281   QListViewItem * item = mTagList->firstChild();
03282   for ( ; item ; item = item->itemBelow() )
03283     if( !item->text(0).isEmpty() ) {
03284       KConfigGroup config( KMKernel::config(), QCString("Mime #")
03285                              + QCString().setNum( numValidEntries ) );
03286       config.writeEntry( "name",  item->text( 0 ) );
03287       config.writeEntry( "value", item->text( 1 ) );
03288       numValidEntries++;
03289     }
03290   general.writeEntry( "mime-header-count", numValidEntries );
03291 }
03292 
03293 QString ComposerPage::AttachmentsTab::helpAnchor() const {
03294   return QString::fromLatin1("configure-composer-attachments");
03295 }
03296 
03297 ComposerPageAttachmentsTab::ComposerPageAttachmentsTab( QWidget * parent,
03298                                                         const char * name )
03299   : ConfigModuleTab( parent, name ) {
03300   // tmp. vars:
03301   QVBoxLayout *vlay;
03302   QLabel      *label;
03303 
03304   vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
03305 
03306   // "Outlook compatible attachment naming" check box
03307   mOutlookCompatibleCheck =
03308     new QCheckBox( i18n( "Outlook-compatible attachment naming" ), this );
03309   mOutlookCompatibleCheck->setChecked( false );
03310   QToolTip::add( mOutlookCompatibleCheck, i18n(
03311     "Turn this option on to make Outlook(tm) understand attachment names "
03312     "containing non-English characters" ) );
03313   connect( mOutlookCompatibleCheck, SIGNAL( stateChanged( int ) ),
03314            this, SLOT( slotEmitChanged( void ) ) );
03315   connect( mOutlookCompatibleCheck, SIGNAL( clicked() ),
03316            this, SLOT( slotOutlookCompatibleClicked() ) );
03317   vlay->addWidget( mOutlookCompatibleCheck );
03318   vlay->addSpacing( 5 );
03319 
03320   // "Enable detection of missing attachments" check box
03321   mMissingAttachmentDetectionCheck =
03322     new QCheckBox( i18n("E&nable detection of missing attachments"), this );
03323   mMissingAttachmentDetectionCheck->setChecked( true );
03324   connect( mMissingAttachmentDetectionCheck, SIGNAL( stateChanged( int ) ),
03325            this, SLOT( slotEmitChanged( void ) ) );
03326   vlay->addWidget( mMissingAttachmentDetectionCheck );
03327 
03328   // "Attachment key words" label and string list editor
03329   label = new QLabel( i18n("Recognize any of the following key words as "
03330                            "intention to attach a file:"), this );
03331   label->setAlignment( AlignLeft|WordBreak );
03332   vlay->addWidget( label );
03333 
03334   SimpleStringListEditor::ButtonCode buttonCode =
03335     static_cast<SimpleStringListEditor::ButtonCode>( SimpleStringListEditor::Add | SimpleStringListEditor::Remove | SimpleStringListEditor::Modify );
03336   mAttachWordsListEditor =
03337     new SimpleStringListEditor( this, 0, buttonCode,
03338                                 i18n("A&dd..."), i18n("Re&move"),
03339                                 i18n("Mod&ify..."),
03340                                 i18n("Enter new key word:") );
03341   connect( mAttachWordsListEditor, SIGNAL( changed( void ) ),
03342            this, SLOT( slotEmitChanged( void ) ) );
03343   vlay->addWidget( mAttachWordsListEditor );
03344 
03345   connect( mMissingAttachmentDetectionCheck, SIGNAL(toggled(bool) ),
03346            label, SLOT(setEnabled(bool)) );
03347   connect( mMissingAttachmentDetectionCheck, SIGNAL(toggled(bool) ),
03348            mAttachWordsListEditor, SLOT(setEnabled(bool)) );
03349 }
03350 
03351 void ComposerPage::AttachmentsTab::doLoadOther() {
03352   KConfigGroup composer( KMKernel::config(), "Composer" );
03353 
03354   mOutlookCompatibleCheck->setChecked(
03355     composer.readBoolEntry( "outlook-compatible-attachments", false ) );
03356   mMissingAttachmentDetectionCheck->setChecked(
03357     composer.readBoolEntry( "showForgottenAttachmentWarning", true ) );
03358   QStringList attachWordsList =
03359     composer.readListEntry( "attachment-keywords" );
03360   if ( attachWordsList.isEmpty() ) {
03361     // default value
03362     attachWordsList << QString::fromLatin1("attachment")
03363                     << QString::fromLatin1("attached");
03364     if ( QString::fromLatin1("attachment") != i18n("attachment") )
03365       attachWordsList << i18n("attachment");
03366     if ( QString::fromLatin1("attached") != i18n("attached") )
03367       attachWordsList << i18n("attached");
03368   }
03369 
03370   mAttachWordsListEditor->setStringList( attachWordsList );
03371 }
03372 
03373 void ComposerPage::AttachmentsTab::save() {
03374   KConfigGroup composer( KMKernel::config(), "Composer" );
03375   composer.writeEntry( "outlook-compatible-attachments",
03376                        mOutlookCompatibleCheck->isChecked() );
03377   composer.writeEntry( "showForgottenAttachmentWarning",
03378                        mMissingAttachmentDetectionCheck->isChecked() );
03379   composer.writeEntry( "attachment-keywords",
03380                        mAttachWordsListEditor->stringList() );
03381 }
03382 
03383 void ComposerPageAttachmentsTab::slotOutlookCompatibleClicked()
03384 {
03385   if (mOutlookCompatibleCheck->isChecked()) {
03386     KMessageBox::information(0,i18n("You have chosen to "
03387     "encode attachment names containing non-English characters in a way that "
03388     "is understood by Outlook(tm) and other mail clients that do not "
03389     "support standard-compliant encoded attachment names.\n"
03390     "Note that KMail may create non-standard compliant messages, "
03391     "and consequently it is possible that your messages will not be "
03392     "understood by standard-compliant mail clients; so, unless you have no "
03393     "other choice, you should not enable this option." ) );
03394   }
03395 }
03396 
03397 // *************************************************************
03398 // *                                                           *
03399 // *                      SecurityPage                         *
03400 // *                                                           *
03401 // *************************************************************
03402 QString SecurityPage::helpAnchor() const {
03403   return QString::fromLatin1("configure-security");
03404 }
03405 
03406 SecurityPage::SecurityPage( QWidget * parent, const char * name )
03407   : ConfigModuleWithTabs( parent, name )
03408 {
03409   //
03410   // "Reading" tab:
03411   //
03412   mGeneralTab = new GeneralTab(); //  @TODO: rename
03413   addTab( mGeneralTab, i18n("&Reading") );
03414 
03415   //
03416   // "Composing" tab:
03417   //
03418   mComposerCryptoTab = new ComposerCryptoTab();
03419   addTab( mComposerCryptoTab, i18n("Composing") );
03420 
03421   //
03422   // "Warnings" tab:
03423   //
03424   mWarningTab = new WarningTab();
03425   addTab( mWarningTab, i18n("Warnings") );
03426 
03427   //
03428   // "S/MIME Validation" tab:
03429   //
03430   mSMimeTab = new SMimeTab();
03431   addTab( mSMimeTab, i18n("S/MIME &Validation") );
03432 
03433   //
03434   // "Crypto Backends" tab:
03435   //
03436   mCryptPlugTab = new CryptPlugTab();
03437   addTab( mCryptPlugTab, i18n("Crypto Backe&nds") );
03438   load();
03439 }
03440 
03441 
03442 void SecurityPage::installProfile( KConfig * profile ) {
03443   mGeneralTab->installProfile( profile );
03444   mComposerCryptoTab->installProfile( profile );
03445   mWarningTab->installProfile( profile );
03446   mSMimeTab->installProfile( profile );
03447 }
03448 
03449 QString SecurityPage::GeneralTab::helpAnchor() const {
03450   return QString::fromLatin1("configure-security-reading");
03451 }
03452 
03453 SecurityPageGeneralTab::SecurityPageGeneralTab( QWidget * parent, const char * name )
03454   : ConfigModuleTab ( parent, name )
03455 {
03456   // tmp. vars:
03457   QVBoxLayout  *vlay;
03458   QHBox        *hbox;
03459   QGroupBox    *group;
03460   QRadioButton *radio;
03461   KActiveLabel *label;
03462   QWidget      *w;
03463   QString       msg;
03464 
03465   vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
03466 
03467   // QWhat'sThis texts
03468   QString htmlWhatsThis = i18n( "<qt><p>Messages sometimes come in both formats. "
03469               "This option controls whether you want the HTML part or the plain "
03470               "text part to be displayed.</p>"
03471               "<p>Displaying the HTML part makes the message look better, "
03472               "but at the same time increases the risk of security holes "
03473               "being exploited.</p>"
03474               "<p>Displaying the plain text part loses much of the message's "
03475               "formatting, but makes it almost <em>impossible</em> "
03476               "to exploit security holes in the HTML renderer (Konqueror).</p>"
03477               "<p>The option below guards against one common misuse of HTML "
03478               "messages, but it cannot guard against security issues that were "
03479               "not known at the time this version of KMail was written.</p>"
03480               "<p>It is therefore advisable to <em>not</em> prefer HTML to "
03481               "plain text.</p>"
03482               "<p><b>Note:</b> You can set this option on a per-folder basis "
03483               "from the <i>Folder</i> menu of KMail's main window.</p></qt>" );
03484 
03485   QString externalWhatsThis = i18n( "<qt><p>Some mail advertisements are in HTML "
03486               "and contain references to, for example, images that the advertisers"
03487               " employ to find out that you have read their message "
03488               "(&quot;web bugs&quot;).</p>"
03489               "<p>There is no valid reason to load images off the Internet like "
03490               "this, since the sender can always attach the required images "
03491               "directly to the message.</p>"
03492               "<p>To guard from such a misuse of the HTML displaying feature "
03493               "of KMail, this option is <em>disabled</em> by default.</p>"
03494               "<p>However, if you wish to, for example, view images in HTML "
03495               "messages that were not attached to it, you can enable this "
03496               "option, but you should be aware of the possible problem.</p></qt>" );
03497 
03498   QString receiptWhatsThis = i18n( "<qt><h3>Message Disposition "
03499               "Notification Policy</h3>"
03500               "<p>MDNs are a generalization of what is commonly called <b>read "
03501               "receipt</b>. The message author requests a disposition "
03502               "notification to be sent and the receiver's mail program "
03503               "generates a reply from which the author can learn what "
03504               "happened to his message. Common disposition types include "
03505               "<b>displayed</b> (i.e. read), <b>deleted</b> and <b>dispatched</b> "
03506               "(e.g. forwarded).</p>"
03507               "<p>The following options are available to control KMail's "
03508               "sending of MDNs:</p>"
03509               "<ul>"
03510               "<li><em>Ignore</em>: Ignores any request for disposition "
03511               "notifications. No MDN will ever be sent automatically "
03512               "(recommended).</li>"
03513               "<li><em>Ask</em>: Answers requests only after asking the user "
03514               "for permission. This way, you can send MDNs for selected "
03515               "messages while denying or ignoring them for others.</li>"
03516               "<li><em>Deny</em>: Always sends a <b>denied</b> notification. This "
03517               "is only <em>slightly</em> better than always sending MDNs. "
03518               "The author will still know that the messages has been acted "
03519               "upon, he just cannot tell whether it was deleted or read etc.</li>"
03520               "<li><em>Always send</em>: Always sends the requested "
03521               "disposition notification. That means that the author of the "
03522               "message gets to know when the message was acted upon and, "
03523               "in addition, what happened to it (displayed, deleted, "
03524               "etc.). This option is strongly discouraged, but since it "
03525               "makes much sense e.g. for customer relationship management, "
03526               "it has been made available.</li>"
03527               "</ul></qt>" );
03528 
03529 
03530   // "HTML Messages" group box:
03531   group = new QVGroupBox( i18n( "HTML Messages" ), this );
03532   group->layout()->setSpacing( KDialog::spacingHint() );
03533 
03534   mHtmlMailCheck = new QCheckBox( i18n("Prefer H&TML to plain text"), group );
03535   QWhatsThis::add( mHtmlMailCheck, htmlWhatsThis );
03536   connect( mHtmlMailCheck, SIGNAL( stateChanged( int ) ),
03537            this, SLOT( slotEmitChanged( void ) ) );
03538   mExternalReferences = new QCheckBox( i18n("Allow messages to load e&xternal "
03539                                             "references from the Internet" ), group );
03540   QWhatsThis::add( mExternalReferences, externalWhatsThis );
03541   connect( mExternalReferences, SIGNAL( stateChanged( int ) ),
03542            this, SLOT( slotEmitChanged( void ) ) );
03543   label = new KActiveLabel( i18n("<b>WARNING:</b> Allowing HTML in email may "
03544                            "increase the risk that your system will be "
03545                            "compromised by present and anticipated security "
03546                            "exploits. <a href=\"whatsthis:%1\">More about "
03547                            "HTML mails...</a> <a href=\"whatsthis:%2\">More "
03548                            "about external references...</a>")
03549                            .arg(htmlWhatsThis).arg(externalWhatsThis),
03550                            group );
03551 
03552   vlay->addWidget( group );
03553 
03554   // "Message Disposition Notification" groupbox:
03555   group = new QVGroupBox( i18n("Message Disposition Notifications"), this );
03556   group->layout()->setSpacing( KDialog::spacingHint() );
03557 
03558 
03559   // "ignore", "ask", "deny", "always send" radiobutton line:
03560   mMDNGroup = new QButtonGroup( group );
03561   mMDNGroup->hide();
03562   connect( mMDNGroup, SIGNAL( clicked( int ) ),
03563            this, SLOT( slotEmitChanged( void ) ) );
03564   hbox = new QHBox( group );
03565   hbox->setSpacing( KDialog::spacingHint() );
03566 
03567   (void)new QLabel( i18n("Send policy:"), hbox );
03568 
03569   radio = new QRadioButton( i18n("&Ignore"), hbox );
03570   mMDNGroup->insert( radio );
03571 
03572   radio = new QRadioButton( i18n("As&k"), hbox );
03573   mMDNGroup->insert( radio );
03574 
03575   radio = new QRadioButton( i18n("&Deny"), hbox );
03576   mMDNGroup->insert( radio );
03577 
03578   radio = new QRadioButton( i18n("Al&ways send"), hbox );
03579   mMDNGroup->insert( radio );
03580 
03581   for ( int i = 0 ; i < mMDNGroup->count() ; ++i )
03582       QWhatsThis::add( mMDNGroup->find( i ), receiptWhatsThis );
03583 
03584   w = new QWidget( hbox ); // spacer
03585   hbox->setStretchFactor( w, 1 );
03586 
03587   // "Original Message quote" radiobutton line:
03588   mOrigQuoteGroup = new QButtonGroup( group );
03589   mOrigQuoteGroup->hide();
03590   connect( mOrigQuoteGroup, SIGNAL( clicked( int ) ),
03591            this, SLOT( slotEmitChanged( void ) ) );
03592 
03593   hbox = new QHBox( group );
03594   hbox->setSpacing( KDialog::spacingHint() );
03595 
03596   (void)new QLabel( i18n("Quote original message:"), hbox );
03597 
03598   radio = new QRadioButton( i18n("Nothin&g"), hbox );
03599   mOrigQuoteGroup->insert( radio );
03600 
03601   radio = new QRadioButton( i18n("&Full message"), hbox );
03602   mOrigQuoteGroup->insert( radio );
03603 
03604   radio = new QRadioButton( i18n("Onl&y headers"), hbox );
03605   mOrigQuoteGroup->insert( radio );
03606 
03607   w = new QWidget( hbox );
03608   hbox->setStretchFactor( w, 1 );
03609 
03610   mNoMDNsWhenEncryptedCheck = new QCheckBox( i18n("Do not send MDNs in response to encrypted messages"), group );
03611   connect( mNoMDNsWhenEncryptedCheck, SIGNAL(toggled(bool)), SLOT(slotEmitChanged()) );
03612 
03613   // Warning label:
03614   label = new KActiveLabel( i18n("<b>WARNING:</b> Unconditionally returning "
03615                            "confirmations undermines your privacy. "
03616                            "<a href=\"whatsthis:%1\">More...</a>")
03617                              .arg(receiptWhatsThis),
03618                            group );
03619 
03620   vlay->addWidget( group );
03621 
03622   // "Attached keys" group box:
03623   group = new QVGroupBox( i18n( "Certificate && Key Bundle Attachments" ), this );
03624   group->layout()->setSpacing( KDialog::spacingHint() );
03625 
03626   mAutomaticallyImportAttachedKeysCheck = new QCheckBox( i18n("Automatically import keys and certificates"), group );
03627   connect( mAutomaticallyImportAttachedKeysCheck, SIGNAL(toggled(bool)), SLOT(slotEmitChanged()) );
03628 
03629   vlay->addWidget( group );
03630 
03631 
03632 
03633   vlay->addStretch( 10 ); // spacer
03634 }
03635 
03636 void SecurityPage::GeneralTab::doLoadOther() {
03637   const KConfigGroup reader( KMKernel::config(), "Reader" );
03638 
03639   mHtmlMailCheck->setChecked( reader.readBoolEntry( "htmlMail", false ) );
03640   mExternalReferences->setChecked( reader.readBoolEntry( "htmlLoadExternal", false ) );
03641   mAutomaticallyImportAttachedKeysCheck->setChecked( reader.readBoolEntry( "AutoImportKeys", false ) );
03642 
03643   const KConfigGroup mdn( KMKernel::config(), "MDN" );
03644 
03645   int num = mdn.readNumEntry( "default-policy", 0 );
03646   if ( num < 0 || num >= mMDNGroup->count() ) num = 0;
03647   mMDNGroup->setButton( num );
03648   num = mdn.readNumEntry( "quote-message", 0 );
03649   if ( num < 0 || num >= mOrigQuoteGroup->count() ) num = 0;
03650   mOrigQuoteGroup->setButton( num );
03651   mNoMDNsWhenEncryptedCheck->setChecked(mdn.readBoolEntry( "not-send-when-encrypted", true ));
03652 }
03653 
03654 void SecurityPage::GeneralTab::installProfile( KConfig * profile ) {
03655   const KConfigGroup reader( profile, "Reader" );
03656   const KConfigGroup mdn( profile, "MDN" );
03657 
03658   if ( reader.hasKey( "htmlMail" ) )
03659     mHtmlMailCheck->setChecked( reader.readBoolEntry( "htmlMail" ) );
03660   if ( reader.hasKey( "htmlLoadExternal" ) )
03661     mExternalReferences->setChecked( reader.readBoolEntry( "htmlLoadExternal" ) );
03662   if ( reader.hasKey( "AutoImportKeys" ) )
03663     mAutomaticallyImportAttachedKeysCheck->setChecked( reader.readBoolEntry( "AutoImportKeys" ) );
03664 
03665   if ( mdn.hasKey( "default-policy" ) ) {
03666       int num = mdn.readNumEntry( "default-policy" );
03667       if ( num < 0 || num >= mMDNGroup->count() ) num = 0;
03668       mMDNGroup->setButton( num );
03669   }
03670   if ( mdn.hasKey( "quote-message" ) ) {
03671       int num = mdn.readNumEntry( "quote-message" );
03672       if ( num < 0 || num >= mOrigQuoteGroup->count() ) num = 0;
03673       mOrigQuoteGroup->setButton( num );
03674   }
03675   if ( mdn.hasKey( "not-send-when-encrypted" ) )
03676       mNoMDNsWhenEncryptedCheck->setChecked(mdn.readBoolEntry( "not-send-when-encrypted" ));
03677 }
03678 
03679 void SecurityPage::GeneralTab::save() {
03680   KConfigGroup reader( KMKernel::config(), "Reader" );
03681   KConfigGroup mdn( KMKernel::config(), "MDN" );
03682 
03683   if (reader.readBoolEntry( "htmlMail", false ) != mHtmlMailCheck->isChecked())
03684   {
03685     if (KMessageBox::warningContinueCancel(this, i18n("Changing the global "
03686       "HTML setting will override all folder specific values."), QString::null,
03687       KStdGuiItem::cont(), "htmlMailOverride") == KMessageBox::Continue)
03688     {
03689       reader.writeEntry( "htmlMail", mHtmlMailCheck->isChecked() );
03690       QStringList names;
03691       QValueList<QGuardedPtr<KMFolder> > folders;
03692       kmkernel->folderMgr()->createFolderList(&names, &folders);
03693       kmkernel->imapFolderMgr()->createFolderList(&names, &folders);
03694       kmkernel->dimapFolderMgr()->createFolderList(&names, &folders);
03695       kmkernel->searchFolderMgr()->createFolderList(&names, &folders);
03696       for (QValueList<QGuardedPtr<KMFolder> >::iterator it = folders.begin();
03697         it != folders.end(); ++it)
03698       {
03699         if (*it)
03700         {
03701           KConfigGroupSaver saver(KMKernel::config(),
03702             "Folder-" + (*it)->idString());
03703           KMKernel::config()->writeEntry("htmlMailOverride", false);
03704         }
03705       }
03706     }
03707   }
03708   reader.writeEntry( "htmlLoadExternal", mExternalReferences->isChecked() );
03709   reader.writeEntry( "AutoImportKeys", mAutomaticallyImportAttachedKeysCheck->isChecked() );
03710   mdn.writeEntry( "default-policy", mMDNGroup->id( mMDNGroup->selected() ) );
03711   mdn.writeEntry( "quote-message", mOrigQuoteGroup->id( mOrigQuoteGroup->selected() ) );
03712   mdn.writeEntry( "not-send-when-encrypted", mNoMDNsWhenEncryptedCheck->isChecked() );
03713 }
03714 
03715 
03716 QString SecurityPage::ComposerCryptoTab::helpAnchor() const {
03717   return QString::fromLatin1("configure-security-composing");
03718 }
03719 
03720 SecurityPageComposerCryptoTab::SecurityPageComposerCryptoTab( QWidget * parent, const char * name )
03721   : ConfigModuleTab ( parent, name )
03722 {
03723   // the margins are inside mWidget itself
03724   QVBoxLayout* vlay = new QVBoxLayout( this, 0, 0 );
03725 
03726   mWidget = new ComposerCryptoConfiguration( this );
03727   connect( mWidget->mAutoSignature, SIGNAL( toggled(bool) ), this, SLOT( slotEmitChanged() ) );
03728   connect( mWidget->mEncToSelf, SIGNAL( toggled(bool) ), this, SLOT( slotEmitChanged() ) );
03729   connect( mWidget->mShowEncryptionResult, SIGNAL( toggled(bool) ), this, SLOT( slotEmitChanged() ) );
03730   connect( mWidget->mShowKeyApprovalDlg, SIGNAL( toggled(bool) ), this, SLOT( slotEmitChanged() ) );
03731   connect( mWidget->mAutoEncrypt, SIGNAL( toggled(bool) ), this, SLOT( slotEmitChanged() ) );
03732   connect( mWidget->mNeverEncryptWhenSavingInDrafts, SIGNAL( toggled(bool) ), this, SLOT( slotEmitChanged() ) );
03733   connect( mWidget->mStoreEncrypted, SIGNAL( toggled(bool) ), this, SLOT( slotEmitChanged() ) );
03734   vlay->addWidget( mWidget );
03735 }
03736 
03737 void SecurityPage::ComposerCryptoTab::doLoadOther() {
03738   const KConfigGroup composer( KMKernel::config(), "Composer" );
03739 
03740   // If you change default values, sync messagecomposer.cpp too
03741 
03742   mWidget->mAutoSignature->setChecked( composer.readBoolEntry( "pgp-auto-sign", false ) );
03743 
03744   mWidget->mEncToSelf->setChecked( composer.readBoolEntry( "crypto-encrypt-to-self", true ) );
03745   mWidget->mShowEncryptionResult->setChecked( false ); //composer.readBoolEntry( "crypto-show-encryption-result", true ) );
03746   mWidget->mShowEncryptionResult->hide();
03747   mWidget->mShowKeyApprovalDlg->setChecked( composer.readBoolEntry( "crypto-show-keys-for-approval", true ) );
03748 
03749   mWidget->mAutoEncrypt->setChecked( composer.readBoolEntry( "pgp-auto-encrypt", false ) );
03750   mWidget->mNeverEncryptWhenSavingInDrafts->setChecked( composer.readBoolEntry( "never-encrypt-drafts", true ) );
03751 
03752   mWidget->mStoreEncrypted->setChecked( composer.readBoolEntry( "crypto-store-encrypted", true ) );
03753 }
03754 
03755 void SecurityPage::ComposerCryptoTab::installProfile( KConfig * profile ) {
03756   const KConfigGroup composer( profile, "Composer" );
03757 
03758   if ( composer.hasKey( "pgp-auto-sign" ) )
03759     mWidget->mAutoSignature->setChecked( composer.readBoolEntry( "pgp-auto-sign" ) );
03760 
03761   if ( composer.hasKey( "crypto-encrypt-to-self" ) )
03762     mWidget->mEncToSelf->setChecked( composer.readBoolEntry( "crypto-encrypt-to-self" ) );
03763   if ( composer.hasKey( "crypto-show-encryption-result" ) )
03764     mWidget->mShowEncryptionResult->setChecked( composer.readBoolEntry( "crypto-show-encryption-result" ) );
03765   if ( composer.hasKey( "crypto-show-keys-for-approval" ) )
03766     mWidget->mShowKeyApprovalDlg->setChecked( composer.readBoolEntry( "crypto-show-keys-for-approval" ) );
03767   if ( composer.hasKey( "pgp-auto-encrypt" ) )
03768     mWidget->mAutoEncrypt->setChecked( composer.readBoolEntry( "pgp-auto-encrypt" ) );
03769   if ( composer.hasKey( "never-encrypt-drafts" ) )
03770     mWidget->mNeverEncryptWhenSavingInDrafts->setChecked( composer.readBoolEntry( "never-encrypt-drafts" ) );
03771 
03772   if ( composer.hasKey( "crypto-store-encrypted" ) )
03773     mWidget->mStoreEncrypted->setChecked( composer.readBoolEntry( "crypto-store-encrypted" ) );
03774 }
03775 
03776 void SecurityPage::ComposerCryptoTab::save() {
03777   KConfigGroup composer( KMKernel::config(), "Composer" );
03778 
03779   composer.writeEntry( "pgp-auto-sign", mWidget->mAutoSignature->isChecked() );
03780 
03781   composer.writeEntry( "crypto-encrypt-to-self", mWidget->mEncToSelf->isChecked() );
03782   composer.writeEntry( "crypto-show-encryption-result", mWidget->mShowEncryptionResult->isChecked() );
03783   composer.writeEntry( "crypto-show-keys-for-approval", mWidget->mShowKeyApprovalDlg->isChecked() );
03784 
03785   composer.writeEntry( "pgp-auto-encrypt", mWidget->mAutoEncrypt->isChecked() );
03786   composer.writeEntry( "never-encrypt-drafts", mWidget->mNeverEncryptWhenSavingInDrafts->isChecked() );
03787 
03788   composer.writeEntry( "crypto-store-encrypted", mWidget->mStoreEncrypted->isChecked() );
03789 }
03790 
03791 QString SecurityPage::WarningTab::helpAnchor() const {
03792   return QString::fromLatin1("configure-security-warnings");
03793 }
03794 
03795 SecurityPageWarningTab::SecurityPageWarningTab( QWidget * parent, const char * name )
03796   : ConfigModuleTab( parent, name )
03797 {
03798   // the margins are inside mWidget itself
03799   QVBoxLayout* vlay = new QVBoxLayout( this, 0, 0 );
03800 
03801   mWidget = new WarningConfiguration( this );
03802   vlay->addWidget( mWidget );
03803 
03804   connect( mWidget->warnGroupBox, SIGNAL(toggled(bool)), SLOT(slotEmitChanged()) );
03805   connect( mWidget->mWarnUnsigned, SIGNAL(toggled(bool)), SLOT(slotEmitChanged()) );
03806   connect( mWidget->warnUnencryptedCB, SIGNAL(toggled(bool)), SLOT(slotEmitChanged()) );
03807   connect( mWidget->warnReceiverNotInCertificateCB, SIGNAL(toggled(bool)), SLOT(slotEmitChanged()) );
03808   connect( mWidget->mWarnSignKeyExpiresSB, SIGNAL( valueChanged( int ) ), SLOT( slotEmitChanged() ) );
03809   connect( mWidget->mWarnSignChainCertExpiresSB, SIGNAL( valueChanged( int ) ), SLOT( slotEmitChanged() ) );
03810   connect( mWidget->mWarnSignRootCertExpiresSB, SIGNAL( valueChanged( int ) ), SLOT( slotEmitChanged() ) );
03811 
03812   connect( mWidget->mWarnEncrKeyExpiresSB, SIGNAL( valueChanged( int ) ), SLOT( slotEmitChanged() ) );
03813   connect( mWidget->mWarnEncrChainCertExpiresSB, SIGNAL( valueChanged( int ) ), SLOT( slotEmitChanged() ) );
03814   connect( mWidget->mWarnEncrRootCertExpiresSB, SIGNAL( valueChanged( int ) ), SLOT( slotEmitChanged() ) );
03815 
03816   connect( mWidget->enableAllWarningsPB, SIGNAL(clicked()),
03817            SLOT(slotReenableAllWarningsClicked()) );
03818 }
03819 
03820 void SecurityPage::WarningTab::doLoadOther() {
03821   const KConfigGroup composer( KMKernel::config(), "Composer" );
03822 
03823   mWidget->warnUnencryptedCB->setChecked( composer.readBoolEntry( "crypto-warning-unencrypted", false ) );
03824   mWidget->mWarnUnsigned->setChecked( composer.readBoolEntry( "crypto-warning-unsigned", false ) );
03825   mWidget->warnReceiverNotInCertificateCB->setChecked( composer.readBoolEntry( "crypto-warn-recv-not-in-cert", true ) );
03826 
03827   // The "-int" part of the key name is because there used to be a separate boolean
03828   // config entry for enabling/disabling. This is done with the single bool value now.
03829   mWidget->warnGroupBox->setChecked( composer.readBoolEntry( "crypto-warn-when-near-expire", true ) );
03830 
03831   mWidget->mWarnSignKeyExpiresSB->setValue( composer.readNumEntry( "crypto-warn-sign-key-near-expire-int", 14 ) );
03832   mWidget->mWarnSignChainCertExpiresSB->setValue( composer.readNumEntry( "crypto-warn-sign-chaincert-near-expire-int", 14 ) );
03833   mWidget->mWarnSignRootCertExpiresSB->setValue( composer.readNumEntry( "crypto-warn-sign-root-near-expire-int", 14 ) );
03834 
03835   mWidget->mWarnEncrKeyExpiresSB->setValue( composer.readNumEntry( "crypto-warn-encr-key-near-expire-int", 14 ) );
03836   mWidget->mWarnEncrChainCertExpiresSB->setValue( composer.readNumEntry( "crypto-warn-encr-chaincert-near-expire-int", 14 ) );
03837   mWidget->mWarnEncrRootCertExpiresSB->setValue( composer.readNumEntry( "crypto-warn-encr-root-near-expire-int", 14 ) );
03838 
03839   mWidget->enableAllWarningsPB->setEnabled( true );
03840 }
03841 
03842 void SecurityPage::WarningTab::installProfile( KConfig * profile ) {
03843   const KConfigGroup composer( profile, "Composer" );
03844 
03845   if ( composer.hasKey( "crypto-warning-unencrypted" ) )
03846     mWidget->warnUnencryptedCB->setChecked( composer.readBoolEntry( "crypto-warning-unencrypted" ) );
03847   if ( composer.hasKey( "crypto-warning-unsigned" ) )
03848     mWidget->mWarnUnsigned->setChecked( composer.readBoolEntry( "crypto-warning-unsigned" ) );
03849   if ( composer.hasKey( "crypto-warn-recv-not-in-cert" ) )
03850     mWidget->warnReceiverNotInCertificateCB->setChecked( composer.readBoolEntry( "crypto-warn-recv-not-in-cert" ) );
03851 
03852   if ( composer.hasKey( "crypto-warn-when-near-expire" ) )
03853     mWidget->warnGroupBox->setChecked( composer.readBoolEntry( "crypto-warn-when-near-expire" ) );
03854 
03855   if ( composer.hasKey( "crypto-warn-sign-key-near-expire-int" ) )
03856     mWidget->mWarnSignKeyExpiresSB->setValue( composer.readNumEntry( "crypto-warn-sign-key-near-expire-int" ) );
03857   if ( composer.hasKey( "crypto-warn-sign-chaincert-near-expire-int" ) )
03858     mWidget->mWarnSignChainCertExpiresSB->setValue( composer.readNumEntry( "crypto-warn-sign-chaincert-near-expire-int" ) );
03859   if ( composer.hasKey( "crypto-warn-sign-root-near-expire-int" ) )
03860     mWidget->mWarnSignRootCertExpiresSB->setValue( composer.readNumEntry( "crypto-warn-sign-root-near-expire-int" ) );
03861 
03862   if ( composer.hasKey( "crypto-warn-encr-key-near-expire-int" ) )
03863     mWidget->mWarnEncrKeyExpiresSB->setValue( composer.readNumEntry( "crypto-warn-encr-key-near-expire-int" ) );
03864   if ( composer.hasKey( "crypto-warn-encr-chaincert-near-expire-int" ) )
03865     mWidget->mWarnEncrChainCertExpiresSB->setValue( composer.readNumEntry( "crypto-warn-encr-chaincert-near-expire-int" ) );
03866   if ( composer.hasKey( "crypto-warn-encr-root-near-expire-int" ) )
03867     mWidget->mWarnEncrRootCertExpiresSB->setValue( composer.readNumEntry( "crypto-warn-encr-root-near-expire-int" ) );
03868 }
03869 
03870 void SecurityPage::WarningTab::save() {
03871   KConfigGroup composer( KMKernel::config(), "Composer" );
03872 
03873   composer.writeEntry( "crypto-warn-recv-not-in-cert", mWidget->warnReceiverNotInCertificateCB->isChecked() );
03874   composer.writeEntry( "crypto-warning-unencrypted", mWidget->warnUnencryptedCB->isChecked() );
03875   composer.writeEntry( "crypto-warning-unsigned", mWidget->mWarnUnsigned->isChecked() );
03876 
03877   composer.writeEntry( "crypto-warn-when-near-expire", mWidget->warnGroupBox->isChecked() );
03878   composer.writeEntry( "crypto-warn-sign-key-near-expire-int",
03879                        mWidget->mWarnSignKeyExpiresSB->value() );
03880   composer.writeEntry( "crypto-warn-sign-chaincert-near-expire-int",
03881                        mWidget->mWarnSignChainCertExpiresSB->value() );
03882   composer.writeEntry( "crypto-warn-sign-root-near-expire-int",
03883                        mWidget->mWarnSignRootCertExpiresSB->value() );
03884 
03885   composer.writeEntry( "crypto-warn-encr-key-near-expire-int",
03886                        mWidget->mWarnEncrKeyExpiresSB->value() );
03887   composer.writeEntry( "crypto-warn-encr-chaincert-near-expire-int",
03888                        mWidget->mWarnEncrChainCertExpiresSB->value() );
03889   composer.writeEntry( "crypto-warn-encr-root-near-expire-int",
03890                        mWidget->mWarnEncrRootCertExpiresSB->value() );
03891 }
03892 
03893 void SecurityPage::WarningTab::slotReenableAllWarningsClicked() {
03894   KMessageBox::enableAllMessages();
03895   mWidget->enableAllWarningsPB->setEnabled( false );
03896 }
03897 
03899 
03900 QString SecurityPage::SMimeTab::helpAnchor() const {
03901   return QString::fromLatin1("configure-security-smime-validation");
03902 }
03903 
03904 SecurityPageSMimeTab::SecurityPageSMimeTab( QWidget * parent, const char * name )
03905   : ConfigModuleTab( parent, name )
03906 {
03907   // the margins are inside mWidget itself
03908   QVBoxLayout* vlay = new QVBoxLayout( this, 0, 0 );
03909 
03910   mWidget = new SMimeConfiguration( this );
03911   vlay->addWidget( mWidget );
03912 
03913   // Button-group for exclusive radiobuttons
03914   QButtonGroup* bg = new QButtonGroup( mWidget );
03915   bg->hide();
03916   bg->insert( mWidget->CRLRB );
03917   bg->insert( mWidget->OCSPRB );
03918 
03919   // Settings for the keyrequester custom widget
03920   mWidget->OCSPResponderSignature->setAllowedKeys(
03921      Kleo::KeySelectionDialog::SMIMEKeys
03922      | Kleo::KeySelectionDialog::TrustedKeys
03923      | Kleo::KeySelectionDialog::ValidKeys
03924      | Kleo::KeySelectionDialog::SigningKeys
03925      | Kleo::KeySelectionDialog::PublicKeys );
03926   mWidget->OCSPResponderSignature->setMultipleKeysEnabled( false );
03927 
03928   mConfig = Kleo::CryptoBackendFactory::instance()->config();
03929 
03930   connect( mWidget->CRLRB, SIGNAL( toggled( bool ) ), this, SLOT( slotEmitChanged() ) );
03931   connect( mWidget->OCSPRB, SIGNAL( toggled( bool ) ), this, SLOT( slotEmitChanged() ) );
03932   connect( mWidget->OCSPResponderURL, SIGNAL( textChanged( const QString& ) ), this, SLOT( slotEmitChanged() ) );
03933   connect( mWidget->OCSPResponderSignature, SIGNAL( changed() ), this, SLOT( slotEmitChanged() ) );
03934   connect( mWidget->doNotCheckCertPolicyCB, SIGNAL( toggled( bool ) ), this, SLOT( slotEmitChanged() ) );
03935   connect( mWidget->neverConsultCB, SIGNAL( toggled( bool ) ), this, SLOT( slotEmitChanged() ) );
03936   connect( mWidget->fetchMissingCB, SIGNAL( toggled( bool ) ), this, SLOT( slotEmitChanged() ) );
03937 
03938   connect( mWidget->ignoreServiceURLCB, SIGNAL( toggled( bool ) ), this, SLOT( slotEmitChanged() ) );
03939   connect( mWidget->ignoreHTTPDPCB, SIGNAL( toggled( bool ) ), this, SLOT( slotEmitChanged() ) );
03940   connect( mWidget->disableHTTPCB, SIGNAL( toggled( bool ) ), this, SLOT( slotEmitChanged() ) );
03941   connect( mWidget->honorHTTPProxyRB, SIGNAL( toggled( bool ) ), this, SLOT( slotEmitChanged() ) );
03942   connect( mWidget->useCustomHTTPProxyRB, SIGNAL( toggled( bool ) ), this, SLOT( slotEmitChanged() ) );
03943   connect( mWidget->customHTTPProxy, SIGNAL( textChanged( const QString& ) ), this, SLOT( slotEmitChanged() ) );
03944   connect( mWidget->ignoreLDAPDPCB, SIGNAL( toggled( bool ) ), this, SLOT( slotEmitChanged() ) );
03945   connect( mWidget->disableLDAPCB, SIGNAL( toggled( bool ) ), this, SLOT( slotEmitChanged() ) );
03946   connect( mWidget->customLDAPProxy, SIGNAL( textChanged( const QString& ) ), this, SLOT( slotEmitChanged() ) );
03947 
03948   connect( mWidget->disableHTTPCB, SIGNAL( toggled( bool ) ),
03949            this, SLOT( slotUpdateHTTPActions() ) );
03950   connect( mWidget->ignoreHTTPDPCB, SIGNAL( toggled( bool ) ),
03951            this, SLOT( slotUpdateHTTPActions() ) );
03952 
03953   // Button-group for exclusive radiobuttons
03954   QButtonGroup* bgHTTPProxy = new QButtonGroup( mWidget );
03955   bgHTTPProxy->hide();
03956   bgHTTPProxy->insert( mWidget->honorHTTPProxyRB );
03957   bgHTTPProxy->insert( mWidget->useCustomHTTPProxyRB );
03958 
03959   if ( !connectDCOPSignal( 0, "KPIM::CryptoConfig", "changed()",
03960                            "load()", false ) )
03961     kdError(5650) << "SecurityPageSMimeTab: connection to CryptoConfig's changed() failed" << endl;
03962 
03963 }
03964 
03965 SecurityPageSMimeTab::~SecurityPageSMimeTab()
03966 {
03967 }
03968 
03969 static void disableDirmngrWidget( QWidget* w ) {
03970   w->setEnabled( false );
03971   QWhatsThis::remove( w );
03972   QWhatsThis::add( w, i18n( "This option requires dirmngr >= 0.9.0" ) );
03973 }
03974 
03975 static void initializeDirmngrCheckbox( QCheckBox* cb, Kleo::CryptoConfigEntry* entry ) {
03976   if ( entry )
03977     cb->setChecked( entry->boolValue() );
03978   else
03979     disableDirmngrWidget( cb );
03980 }
03981 
03982 struct SMIMECryptoConfigEntries {
03983   SMIMECryptoConfigEntries( Kleo::CryptoConfig* config )
03984     : mConfig( config ) {
03985 
03986     // Checkboxes
03987     mCheckUsingOCSPConfigEntry = configEntry( "gpgsm", "Security", "enable-ocsp", Kleo::CryptoConfigEntry::ArgType_None, false );
03988     mEnableOCSPsendingConfigEntry = configEntry( "dirmngr", "OCSP", "allow-ocsp", Kleo::CryptoConfigEntry::ArgType_None, false );
03989     mDoNotCheckCertPolicyConfigEntry = configEntry( "gpgsm", "Security", "disable-policy-checks", Kleo::CryptoConfigEntry::ArgType_None, false );
03990     mNeverConsultConfigEntry = configEntry( "gpgsm", "Security", "disable-crl-checks", Kleo::CryptoConfigEntry::ArgType_None, false );
03991     mFetchMissingConfigEntry = configEntry( "gpgsm", "Security", "auto-issuer-key-retrieve", Kleo::CryptoConfigEntry::ArgType_None, false );
03992     // dirmngr-0.9.0 options
03993     mIgnoreServiceURLEntry = configEntry( "dirmngr", "OCSP", "ignore-ocsp-service-url", Kleo::CryptoConfigEntry::ArgType_None, false );
03994     mIgnoreHTTPDPEntry = configEntry( "dirmngr", "HTTP", "ignore-http-dp", Kleo::CryptoConfigEntry::ArgType_None, false );
03995     mDisableHTTPEntry = configEntry( "dirmngr", "HTTP", "disable-http", Kleo::CryptoConfigEntry::ArgType_None, false );
03996     mHonorHTTPProxy = configEntry( "dirmngr", "HTTP", "honor-http-proxy", Kleo::CryptoConfigEntry::ArgType_None, false );
03997 
03998     mIgnoreLDAPDPEntry = configEntry( "dirmngr", "LDAP", "ignore-ldap-dp", Kleo::CryptoConfigEntry::ArgType_None, false );
03999     mDisableLDAPEntry = configEntry( "dirmngr", "LDAP", "disable-ldap", Kleo::CryptoConfigEntry::ArgType_None, false );
04000     // Other widgets
04001     mOCSPResponderURLConfigEntry = configEntry( "dirmngr", "OCSP", "ocsp-responder", Kleo::CryptoConfigEntry::ArgType_String, false );
04002     mOCSPResponderSignature = configEntry( "dirmngr", "OCSP", "ocsp-signer", Kleo::CryptoConfigEntry::ArgType_String, false );
04003     mCustomHTTPProxy = configEntry( "dirmngr", "HTTP", "http-proxy", Kleo::CryptoConfigEntry::ArgType_String, false );
04004     mCustomLDAPProxy = configEntry( "dirmngr", "LDAP", "ldap-proxy", Kleo::CryptoConfigEntry::ArgType_String, false );
04005   }
04006 
04007   Kleo::CryptoConfigEntry* configEntry( const char* componentName,
04008                                         const char* groupName,
04009                                         const char* entryName,
04010                                         int argType,
04011                                         bool isList );
04012 
04013   // Checkboxes
04014   Kleo::CryptoConfigEntry* mCheckUsingOCSPConfigEntry;
04015   Kleo::CryptoConfigEntry* mEnableOCSPsendingConfigEntry;
04016   Kleo::CryptoConfigEntry* mDoNotCheckCertPolicyConfigEntry;
04017   Kleo::CryptoConfigEntry* mNeverConsultConfigEntry;
04018   Kleo::CryptoConfigEntry* mFetchMissingConfigEntry;
04019   Kleo::CryptoConfigEntry* mIgnoreServiceURLEntry;
04020   Kleo::CryptoConfigEntry* mIgnoreHTTPDPEntry;
04021   Kleo::CryptoConfigEntry* mDisableHTTPEntry;
04022   Kleo::CryptoConfigEntry* mHonorHTTPProxy;
04023   Kleo::CryptoConfigEntry* mIgnoreLDAPDPEntry;
04024   Kleo::CryptoConfigEntry* mDisableLDAPEntry;
04025   // Other widgets
04026   Kleo::CryptoConfigEntry* mOCSPResponderURLConfigEntry;
04027   Kleo::CryptoConfigEntry* mOCSPResponderSignature;
04028   Kleo::CryptoConfigEntry* mCustomHTTPProxy;
04029   Kleo::CryptoConfigEntry* mCustomLDAPProxy;
04030 
04031   Kleo::CryptoConfig* mConfig;
04032 };
04033 
04034 void SecurityPage::SMimeTab::doLoadOther() {
04035   if ( !mConfig ) {
04036     setEnabled( false );
04037     return;
04038   }
04039 
04040   // Force re-parsing gpgconf data, in case e.g. kleopatra or "configure backend" was used
04041   // (which ends up calling us via dcop)
04042   mConfig->clear();
04043 
04044   // Create config entries
04045   // Don't keep them around, they'll get deleted by clear(), which could be
04046   // done by the "configure backend" button even before we save().
04047   SMIMECryptoConfigEntries e( mConfig );
04048 
04049   // Initialize GUI items from the config entries
04050 
04051   if ( e.mCheckUsingOCSPConfigEntry ) {
04052     bool b = e.mCheckUsingOCSPConfigEntry->boolValue();
04053     mWidget->OCSPRB->setChecked( b );
04054     mWidget->CRLRB->setChecked( !b );
04055     mWidget->OCSPGroupBox->setEnabled( b );
04056   } else {
04057     mWidget->OCSPGroupBox->setEnabled( false );
04058   }
04059   if ( e.mDoNotCheckCertPolicyConfigEntry )
04060     mWidget->doNotCheckCertPolicyCB->setChecked( e.mDoNotCheckCertPolicyConfigEntry->boolValue() );
04061   if ( e.mNeverConsultConfigEntry )
04062     mWidget->neverConsultCB->setChecked( e.mNeverConsultConfigEntry->boolValue() );
04063   if ( e.mFetchMissingConfigEntry )
04064     mWidget->fetchMissingCB->setChecked( e.mFetchMissingConfigEntry->boolValue() );
04065 
04066   if ( e.mOCSPResponderURLConfigEntry )
04067     mWidget->OCSPResponderURL->setText( e.mOCSPResponderURLConfigEntry->stringValue() );
04068   if ( e.mOCSPResponderSignature ) {
04069     mWidget->OCSPResponderSignature->setFingerprint( e.mOCSPResponderSignature->stringValue() );
04070   }
04071 
04072   // dirmngr-0.9.0 options
04073   initializeDirmngrCheckbox( mWidget->ignoreServiceURLCB, e.mIgnoreServiceURLEntry );
04074   initializeDirmngrCheckbox( mWidget->ignoreHTTPDPCB, e.mIgnoreHTTPDPEntry );
04075   initializeDirmngrCheckbox( mWidget->disableHTTPCB, e.mDisableHTTPEntry );
04076   initializeDirmngrCheckbox( mWidget->ignoreLDAPDPCB, e.mIgnoreLDAPDPEntry );
04077   initializeDirmngrCheckbox( mWidget->disableLDAPCB, e.mDisableLDAPEntry );
04078   if ( e.mCustomHTTPProxy ) {
04079     QString systemProxy = QString::fromLocal8Bit( getenv( "http_proxy" ) );
04080     if ( systemProxy.isEmpty() )
04081       systemProxy = i18n( "no proxy" );
04082     mWidget->systemHTTPProxy->setText( i18n( "(Current system setting: %1)" ).arg( systemProxy ) );
04083     bool honor = e.mHonorHTTPProxy && e.mHonorHTTPProxy->boolValue();
04084     mWidget->honorHTTPProxyRB->setChecked( honor );
04085     mWidget->useCustomHTTPProxyRB->setChecked( !honor );
04086     mWidget->customHTTPProxy->setText( e.mCustomHTTPProxy->stringValue() );
04087   } else {
04088     disableDirmngrWidget( mWidget->honorHTTPProxyRB );
04089     disableDirmngrWidget( mWidget->useCustomHTTPProxyRB );
04090     disableDirmngrWidget( mWidget->systemHTTPProxy );
04091     disableDirmngrWidget( mWidget->customHTTPProxy );
04092   }
04093   if ( e.mCustomLDAPProxy )
04094     mWidget->customLDAPProxy->setText( e.mCustomLDAPProxy->stringValue() );
04095   else {
04096     disableDirmngrWidget( mWidget->customLDAPProxy );
04097     disableDirmngrWidget( mWidget->customLDAPLabel );
04098   }
04099   slotUpdateHTTPActions();
04100 }
04101 
04102 void SecurityPage::SMimeTab::slotUpdateHTTPActions() {
04103   mWidget->ignoreHTTPDPCB->setEnabled( !mWidget->disableHTTPCB->isChecked() );
04104 
04105   // The proxy settings only make sense when "Ignore HTTP CRL DPs of certificate" is checked.
04106   bool enableProxySettings = !mWidget->disableHTTPCB->isChecked()
04107                           && mWidget->ignoreHTTPDPCB->isChecked();
04108   mWidget->systemHTTPProxy->setEnabled( enableProxySettings );
04109   mWidget->useCustomHTTPProxyRB->setEnabled( enableProxySettings );
04110   mWidget->honorHTTPProxyRB->setEnabled( enableProxySettings );
04111   mWidget->customHTTPProxy->setEnabled( enableProxySettings );
04112 }
04113 
04114 void SecurityPage::SMimeTab::installProfile( KConfig * ) {
04115 }
04116 
04117 static void saveCheckBoxToKleoEntry( QCheckBox* cb, Kleo::CryptoConfigEntry* entry ) {
04118   const bool b = cb->isChecked();
04119   if ( entry && entry->boolValue() != b )
04120     entry->setBoolValue( b );
04121 }
04122 
04123 void SecurityPage::SMimeTab::save() {
04124   if ( !mConfig ) {
04125     return;
04126   }
04127   // Create config entries
04128   // Don't keep them around, they'll get deleted by clear(), which could be done by the
04129   // "configure backend" button.
04130   SMIMECryptoConfigEntries e( mConfig );
04131 
04132   bool b = mWidget->OCSPRB->isChecked();
04133   if ( e.mCheckUsingOCSPConfigEntry && e.mCheckUsingOCSPConfigEntry->boolValue() != b )
04134     e.mCheckUsingOCSPConfigEntry->setBoolValue( b );
04135   // Set allow-ocsp together with enable-ocsp
04136   if ( e.mEnableOCSPsendingConfigEntry && e.mEnableOCSPsendingConfigEntry->boolValue() != b )
04137     e.mEnableOCSPsendingConfigEntry->setBoolValue( b );
04138 
04139   saveCheckBoxToKleoEntry( mWidget->doNotCheckCertPolicyCB, e.mDoNotCheckCertPolicyConfigEntry );
04140   saveCheckBoxToKleoEntry( mWidget->neverConsultCB, e.mNeverConsultConfigEntry );
04141   saveCheckBoxToKleoEntry( mWidget->fetchMissingCB, e.mFetchMissingConfigEntry );
04142 
04143   QString txt = mWidget->OCSPResponderURL->text();
04144   if ( e.mOCSPResponderURLConfigEntry && e.mOCSPResponderURLConfigEntry->stringValue() != txt )
04145     e.mOCSPResponderURLConfigEntry->setStringValue( txt );
04146 
04147   txt = mWidget->OCSPResponderSignature->fingerprint();
04148   if ( e.mOCSPResponderSignature && e.mOCSPResponderSignature->stringValue() != txt ) {
04149     e.mOCSPResponderSignature->setStringValue( txt );
04150   }
04151 
04152   //dirmngr-0.9.0 options
04153   saveCheckBoxToKleoEntry( mWidget->ignoreServiceURLCB, e.mIgnoreServiceURLEntry );
04154   saveCheckBoxToKleoEntry( mWidget->ignoreHTTPDPCB, e.mIgnoreHTTPDPEntry );
04155   saveCheckBoxToKleoEntry( mWidget->disableHTTPCB, e.mDisableHTTPEntry );
04156   saveCheckBoxToKleoEntry( mWidget->ignoreLDAPDPCB, e.mIgnoreLDAPDPEntry );
04157   saveCheckBoxToKleoEntry( mWidget->disableLDAPCB, e.mDisableLDAPEntry );
04158   if ( e.mCustomHTTPProxy ) {
04159     const bool honor = mWidget->honorHTTPProxyRB->isChecked();
04160     if ( e.mHonorHTTPProxy && e.mHonorHTTPProxy->boolValue() != honor )
04161         e.mHonorHTTPProxy->setBoolValue( honor );
04162 
04163     QString chosenProxy = mWidget->customHTTPProxy->text();
04164     if ( chosenProxy != e.mCustomHTTPProxy->stringValue() )
04165       e.mCustomHTTPProxy->setStringValue( chosenProxy );
04166   }
04167   txt = mWidget->customLDAPProxy->text();
04168   if ( e.mCustomLDAPProxy && e.mCustomLDAPProxy->stringValue() != txt )
04169     e.mCustomLDAPProxy->setStringValue( mWidget->customLDAPProxy->text() );
04170 
04171   mConfig->sync( true );
04172 }
04173 
04174 bool SecurityPageSMimeTab::process(const QCString &fun, const QByteArray &data, QCString& replyType, QByteArray &replyData)
04175 {
04176     if ( fun == "load()" ) {
04177         replyType = "void";
04178         load();
04179     } else {
04180         return DCOPObject::process( fun, data, replyType, replyData );
04181     }
04182     return true;
04183 }
04184 
04185 QCStringList SecurityPageSMimeTab::interfaces()
04186 {
04187   QCStringList ifaces = DCOPObject::interfaces();
04188   ifaces += "SecurityPageSMimeTab";
04189   return ifaces;
04190 }
04191 
04192 QCStringList SecurityPageSMimeTab::functions()
04193 {
04194   // Hide our slot, just because it's simpler to do so.
04195   return DCOPObject::functions();
04196 }
04197 
04198 Kleo::CryptoConfigEntry* SMIMECryptoConfigEntries::configEntry( const char* componentName,
04199                                                                 const char* groupName,
04200                                                                 const char* entryName,
04201                                                                 int /*Kleo::CryptoConfigEntry::ArgType*/ argType,
04202                                                                 bool isList )
04203 {
04204     Kleo::CryptoConfigEntry* entry = mConfig->entry( componentName, groupName, entryName );
04205     if ( !entry ) {
04206         kdWarning(5006) << QString( "Backend error: gpgconf doesn't seem to know the entry for %1/%2/%3" ).arg( componentName, groupName, entryName ) << endl;
04207         return 0;
04208     }
04209     if( entry->argType() != argType || entry->isList() != isList ) {
04210         kdWarning(5006) << QString( "Backend error: gpgconf has wrong type for %1/%2/%3: %4 %5" ).arg( componentName, groupName, entryName ).arg( entry->argType() ).arg( entry->isList() ) << endl;
04211         return 0;
04212     }
04213     return entry;
04214 }
04215 
04217 
04218 QString SecurityPage::CryptPlugTab::helpAnchor() const {
04219   return QString::fromLatin1("configure-security-crypto-backends");
04220 }
04221 
04222 SecurityPageCryptPlugTab::SecurityPageCryptPlugTab( QWidget * parent, const char * name )
04223   : ConfigModuleTab( parent, name )
04224 {
04225   QVBoxLayout * vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
04226 
04227   mBackendConfig = Kleo::CryptoBackendFactory::instance()->configWidget( this, "mBackendConfig" );
04228   connect( mBackendConfig, SIGNAL( changed( bool ) ), this, SIGNAL( changed( bool ) ) );
04229 
04230   vlay->addWidget( mBackendConfig );
04231 }
04232 
04233 SecurityPageCryptPlugTab::~SecurityPageCryptPlugTab()
04234 {
04235 
04236 }
04237 
04238 void SecurityPage::CryptPlugTab::doLoadOther() {
04239   mBackendConfig->load();
04240 }
04241 
04242 void SecurityPage::CryptPlugTab::save() {
04243   mBackendConfig->save();
04244 }
04245 
04246 // *************************************************************
04247 // *                                                           *
04248 // *                        MiscPage                           *
04249 // *                                                           *
04250 // *************************************************************
04251 QString MiscPage::helpAnchor() const {
04252   return QString::fromLatin1("configure-misc");
04253 }
04254 
04255 MiscPage::MiscPage( QWidget * parent, const char * name )
04256   : ConfigModuleWithTabs( parent, name )
04257 {
04258   mFolderTab = new FolderTab();
04259   addTab( mFolderTab, i18n("&Folders") );
04260 
04261   mGroupwareTab = new GroupwareTab();
04262   addTab( mGroupwareTab, i18n("&Groupware") );
04263   load();
04264 }
04265 
04266 QString MiscPage::FolderTab::helpAnchor() const {
04267   return QString::fromLatin1("configure-misc-folders");
04268 }
04269 
04270 MiscPageFolderTab::MiscPageFolderTab( QWidget * parent, const char * name )
04271   : ConfigModuleTab( parent, name )
04272 {
04273   // temp. vars:
04274   QVBoxLayout *vlay;
04275   QHBoxLayout *hlay;
04276   QLabel      *label;
04277 
04278   vlay = new QVBoxLayout( this, KDialog::marginHint(), KDialog::spacingHint() );
04279 
04280   // "confirm before emptying folder" check box: stretch 0
04281   mEmptyFolderConfirmCheck =
04282     new QCheckBox( i18n("Corresponds to Folder->Move All Messages to Trash",
04283                         "Ask for co&nfirmation before moving all messages to "
04284                         "trash"),
04285                    this );
04286   vlay->addWidget( mEmptyFolderConfirmCheck );
04287   connect( mEmptyFolderConfirmCheck, SIGNAL( stateChanged( int ) ),
04288            this, SLOT( slotEmitChanged( void ) ) );
04289   mExcludeImportantFromExpiry =
04290     new QCheckBox( i18n("E&xclude important messages from expiry"), this );
04291   vlay->addWidget( mExcludeImportantFromExpiry );
04292   connect( mExcludeImportantFromExpiry, SIGNAL( stateChanged( int ) ),
04293            this, SLOT( slotEmitChanged( void ) ) );
04294 
04295   // "when trying to find unread messages" combo + label: stretch 0
04296   hlay = new QHBoxLayout( vlay ); // inherits spacing
04297   mLoopOnGotoUnread = new QComboBox( false, this );
04298   label = new QLabel( mLoopOnGotoUnread,
04299            i18n("to be continued with \"do not loop\", \"loop in current folder\", "
04300                 "and \"loop in all folders\".",
04301                 "When trying to find unread messages:"), this );
04302   mLoopOnGotoUnread->insertStringList( QStringList()
04303       << i18n("continuation of \"When trying to find unread messages:\"",
04304               "Do not Loop")
04305       << i18n("continuation of \"When trying to find unread messages:\"",
04306               "Loop in Current Folder")
04307       << i18n("continuation of \"When trying to find unread messages:\"",
04308               "Loop in All Folders"));
04309   hlay->addWidget( label );
04310   hlay->addWidget( mLoopOnGotoUnread, 1 );
04311   connect( mLoopOnGotoUnread, SIGNAL( activated( int ) ),
04312            this, SLOT( slotEmitChanged( void ) ) );
04313 
04314   // when entering a folder
04315   hlay = new QHBoxLayout( vlay ); // inherits spacing
04316   mActionEnterFolder = new QComboBox( false, this );
04317   label = new QLabel( mActionEnterFolder,
04318            i18n("to be continued with \"jump to first new message\", "
04319                 "\"jump to first unread or new message\","
04320                 "and \"jump to last selected message\".",
04321                 "When entering a folder:"), this );
04322   mActionEnterFolder->insertStringList( QStringList()
04323       << i18n("continuation of \"When entering a folder:\"",
04324               "Jump to First New Message")
04325       << i18n("continuation of \"When entering a folder:\"",
04326               "Jump to First Unread or New Message")
04327       << i18n("continuation of \"When entering a folder:\"",
04328               "Jump to Last Selected Message"));
04329   hlay->addWidget( label );
04330   hlay->addWidget( mActionEnterFolder, 1 );
04331   connect( mActionEnterFolder, SIGNAL( activated( int ) ),
04332            this, SLOT( slotEmitChanged( void ) ) );
04333 
04334   hlay = new QHBoxLayout( vlay ); // inherits spacing
04335   mDelayedMarkAsRead = new QCheckBox( i18n("Mar&k selected message as read after"), this );
04336   hlay->addWidget( mDelayedMarkAsRead );
04337   mDelayedMarkTime = new KIntSpinBox( 0 /*min*/, 60 /*max*/, 1/*step*/,
04338                                       0 /*init*/, 10 /*base*/, this);
04339   mDelayedMarkTime->setSuffix( i18n(" sec") );
04340   mDelayedMarkTime->setEnabled( false ); // since mDelayedMarkAsREad is off
04341   hlay->addWidget( mDelayedMarkTime );
04342   hlay->addStretch( 1 );
04343   connect( mDelayedMarkTime, SIGNAL( valueChanged( int ) ),
04344            this, SLOT( slotEmitChanged( void ) ) );
04345   connect( mDelayedMarkAsRead, SIGNAL(toggled(bool)),
04346            mDelayedMarkTime, SLOT(setEnabled(bool)));
04347   connect( mDelayedMarkAsRead, SIGNAL(toggled(bool)),
04348            this , SLOT(slotEmitChanged( void )));
04349 
04350   // "show popup after Drag'n'Drop" checkbox: stretch 0
04351   mShowPopupAfterDnD =
04352     new QCheckBox( i18n("Ask for action after &dragging messages to another folder"), this );
04353   vlay->addWidget( mShowPopupAfterDnD );
04354   connect( mShowPopupAfterDnD, SIGNAL( stateChanged( int ) ),
04355            this, SLOT( slotEmitChanged( void ) ) );
04356 
04357   // "default mailbox format" combo + label: stretch 0
04358   hlay = new QHBoxLayout( vlay ); // inherits spacing
04359   mMailboxPrefCombo = new QComboBox( false, this );
04360   label = new QLabel( mMailboxPrefCombo,
04361                       i18n("to be continued with \"flat files\" and "
04362                            "\"directories\", resp.",
04363                            "By default, &message folders on disk are:"), this );
04364   mMailboxPrefCombo->insertStringList( QStringList()
04365           << i18n("continuation of \"By default, &message folders on disk are\"",
04366                   "Flat Files (\"mbox\" format)")
04367           << i18n("continuation of \"By default, &message folders on disk are\"",
04368                   "Directories (\"maildir\" format)") );
04369   hlay->addWidget( label );
04370   hlay->addWidget( mMailboxPrefCombo, 1 );
04371   connect( mMailboxPrefCombo, SIGNAL( activated( int ) ),
04372            this, SLOT( slotEmitChanged( void ) ) );
04373 
04374   // "On startup..." option:
04375   hlay = new QHBoxLayout( vlay ); // inherits spacing
04376   mOnStartupOpenFolder = new FolderRequester( this,
04377       kmkernel->getKMMainWidget()->folderTree() );
04378   label = new QLabel( mOnStartupOpenFolder,
04379                       i18n("Open this folder on startup:"), this );
04380   hlay->addWidget( label );
04381   hlay->addWidget( mOnStartupOpenFolder, 1 );
04382   connect( mOnStartupOpenFolder, SIGNAL( folderChanged( KMFolder* ) ),
04383            this, SLOT( slotEmitChanged( void ) ) );
04384 
04385   // "Empty &trash on program exit" option:
04386   mEmptyTrashCheck = new QCheckBox( i18n("Empty local &trash folder on program exit"),
04387                                     this );
04388   vlay->addWidget( mEmptyTrashCheck );
04389   connect( mEmptyTrashCheck, SIGNAL( stateChanged( int ) ),
04390            this, SLOT( slotEmitChanged( void ) ) );
04391 
04392 #ifdef HAVE_INDEXLIB
04393   // indexing enabled option:
04394   mIndexingEnabled = new QCheckBox( i18n("Enable full text &indexing"), this );
04395   vlay->addWidget( mIndexingEnabled );
04396   connect( mIndexingEnabled, SIGNAL( stateChanged( int ) ),
04397            this, SLOT( slotEmitChanged( void ) ) );
04398 #endif
04399 
04400 
04401 
04402   vlay->addStretch( 1 );
04403 
04404   // and now: add QWhatsThis:
04405   QString msg = i18n( "what's this help",
04406                       "<qt><p>This selects which mailbox format will be "
04407                       "the default for local folders:</p>"
04408                       "<p><b>mbox:</b> KMail's mail "
04409                       "folders are represented by a single file each. "
04410                       "Individual messages are separated from each other by a "
04411                       "line starting with \"From \". This saves space on "
04412                       "disk, but may be less robust, e.g. when moving messages "
04413                       "between folders.</p>"
04414                       "<p><b>maildir:</b> KMail's mail folders are "
04415                       "represented by real folders on disk. Individual messages "
04416                       "are separate files. This may waste a bit of space on "
04417                       "disk, but should be more robust, e.g. when moving "
04418                       "messages between folders.</p></qt>");
04419   QWhatsThis::add( mMailboxPrefCombo, msg );
04420   QWhatsThis::add( label, msg );
04421   // @TODO: Till, move into .kcgc file
04422   msg = i18n( "what's this help",
04423             "<qt><p>When jumping to the next unread message, it may occur "
04424             "that no more unread messages are below the current message.</p>"
04425             "<p><b>Do not loop:</b> The search will stop at the last message in "
04426             "the current folder.</p>"
04427             "<p><b>Loop in current folder:</b> The search will continue at the "
04428             "top of the message list, but not go to another folder.</p>"
04429             "<p><b>Loop in all folders:</b> The search will continue at the top of "
04430             "the message list. If no unread messages are found it will then continue "
04431             "to the next folder.</p>"
04432             "<p>Similarly, when searching for the previous unread message, "
04433             "the search will start from the bottom of the message list and continue to "
04434             "the previous folder depending on which option is selected.</p></qt>" );
04435   QWhatsThis::add( mLoopOnGotoUnread, msg );
04436 
04437 #ifdef HAVE_INDEXLIB
04438  // this is probably overly pessimistic
04439   msg = i18n( "what's this help",
04440           "<qt><p>Full text indexing allows very fast searches on the content "
04441           "of your messages. When enabled, the search dialog will work very fast. "
04442           "Also, the search tool bar will select messages based on content.</p>"
04443           "<p>It takes up a certain amount of disk space "
04444           "(about half the disk space for the messages).</p>"
04445           "<p>After enabling, the index will need to be built, but you can continue to use KMail "
04446           "while this operation is running.</p>"
04447           "</qt>"
04448         );
04449 
04450   QWhatsThis::add( mIndexingEnabled, msg );
04451 #endif
04452 }
04453 
04454 void MiscPage::FolderTab::doLoadFromGlobalSettings() {
04455   mExcludeImportantFromExpiry->setChecked( GlobalSettings::self()->excludeImportantMailFromExpiry() );
04456   // default = "Loop in current folder"
04457   mLoopOnGotoUnread->setCurrentItem( GlobalSettings::self()->loopOnGotoUnread() );
04458   mActionEnterFolder->setCurrentItem( GlobalSettings::self()->actionEnterFolder() );
04459   mDelayedMarkAsRead->setChecked( GlobalSettings::self()->delayedMarkAsRead() );
04460   mDelayedMarkTime->setValue( GlobalSettings::self()->delayedMarkTime() );
04461   mShowPopupAfterDnD->setChecked( GlobalSettings::self()->showPopupAfterDnD() );
04462 }
04463 
04464 void MiscPage::FolderTab::doLoadOther() {
04465   KConfigGroup general( KMKernel::config(), "General" );
04466 
04467   mEmptyTrashCheck->setChecked( general.readBoolEntry( "empty-trash-on-exit", true ) );
04468   mOnStartupOpenFolder->setFolder( general.readEntry( "startupFolder",
04469                                                   kmkernel->inboxFolder()->idString() ) );
04470   mEmptyFolderConfirmCheck->setChecked( general.readBoolEntry( "confirm-before-empty", true ) );
04471 
04472   int num = general.readNumEntry("default-mailbox-format", 1 );
04473   if ( num < 0 || num > 1 ) num = 1;
04474   mMailboxPrefCombo->setCurrentItem( num );
04475 
04476 #ifdef HAVE_INDEXLIB
04477   mIndexingEnabled->setChecked( kmkernel->msgIndex() && kmkernel->msgIndex()->isEnabled() );
04478 #endif
04479 }
04480 
04481 void MiscPage::FolderTab::save() {
04482   KConfigGroup general( KMKernel::config(), "General" );
04483 
04484   general.writeEntry( "empty-trash-on-exit", mEmptyTrashCheck->isChecked() );
04485   general.writeEntry( "confirm-before-empty", mEmptyFolderConfirmCheck->isChecked() );
04486   general.writeEntry( "default-mailbox-format", mMailboxPrefCombo->currentItem() );
04487   general.writeEntry( "startupFolder", mOnStartupOpenFolder->folder() ?
04488                                   mOnStartupOpenFolder->folder()->idString() : QString::null );
04489 
04490   GlobalSettings::self()->setDelayedMarkAsRead( mDelayedMarkAsRead->isChecked() );
04491   GlobalSettings::self()->setDelayedMarkTime( mDelayedMarkTime->value() );
04492   GlobalSettings::self()->setActionEnterFolder( mActionEnterFolder->currentItem() );
04493   GlobalSettings::self()->setLoopOnGotoUnread( mLoopOnGotoUnread->currentItem() );
04494   GlobalSettings::self()->setShowPopupAfterDnD( mShowPopupAfterDnD->isChecked() );
04495   GlobalSettings::self()->setExcludeImportantMailFromExpiry(
04496         mExcludeImportantFromExpiry->isChecked() );
04497 #ifdef HAVE_INDEXLIB
04498   if ( kmkernel->msgIndex() ) kmkernel->msgIndex()->setEnabled( mIndexingEnabled->isChecked() );
04499 #endif
04500 }
04501 
04502 QString MiscPage::GroupwareTab::helpAnchor() const {
04503   return QString::fromLatin1("configure-misc-groupware");
04504 }
04505 
04506 MiscPageGroupwareTab::MiscPageGroupwareTab( QWidget* parent, const char* name )
04507   : ConfigModuleTab( parent, name )
04508 {
04509   QBoxLayout* vlay = new QVBoxLayout( this, KDialog::marginHint(),
04510                                       KDialog::spacingHint() );
04511   vlay->setAutoAdd( true );
04512 
04513   // IMAP resource setup
04514   QVGroupBox* b1 = new QVGroupBox( i18n("&IMAP Resource Folder Options"),
04515                                    this );
04516 
04517   mEnableImapResCB =
04518     new QCheckBox( i18n("&Enable IMAP resource functionality"), b1 );
04519   QToolTip::add( mEnableImapResCB,  i18n( "This enables the IMAP storage for "
04520                                           "the Kontact applications" ) );
04521   QWhatsThis::add( mEnableImapResCB,
04522         i18n( GlobalSettings::self()->theIMAPResourceEnabledItem()->whatsThis().utf8() ) );
04523   connect( mEnableImapResCB, SIGNAL( stateChanged( int ) ),
04524            this, SLOT( slotEmitChanged( void ) ) );
04525 
04526   mBox = new QWidget( b1 );
04527   QGridLayout* grid = new QGridLayout( mBox, 4, 2, 0, KDialog::spacingHint() );
04528   grid->setColStretch( 1, 1 );
04529   connect( mEnableImapResCB, SIGNAL( toggled(bool) ),
04530            mBox, SLOT( setEnabled(bool) ) );
04531 
04532   QLabel* storageFormatLA = new QLabel( i18n("&Format used for the groupware folders:"),
04533                                         mBox );
04534   QString toolTip = i18n( "Choose the format to use to store the contents of the groupware folders." );
04535   QString whatsThis = i18n( GlobalSettings::self()
04536         ->theIMAPResourceStorageFormatItem()->whatsThis().utf8() );
04537   grid->addWidget( storageFormatLA, 0, 0 );
04538   QToolTip::add( storageFormatLA, toolTip );
04539   QWhatsThis::add( storageFormatLA, whatsThis );
04540   mStorageFormatCombo = new QComboBox( false, mBox );
04541   storageFormatLA->setBuddy( mStorageFormatCombo );
04542   QStringList formatLst;
04543   formatLst << i18n("Standard (Ical / Vcard)") << i18n("Kolab (XML)");
04544   mStorageFormatCombo->insertStringList( formatLst );
04545   grid->addWidget( mStorageFormatCombo, 0, 1 );
04546   QToolTip::add( mStorageFormatCombo, toolTip );
04547   QWhatsThis::add( mStorageFormatCombo, whatsThis );
04548   connect( mStorageFormatCombo, SIGNAL( activated( int ) ),
04549            this, SLOT( slotStorageFormatChanged( int ) ) );
04550 
04551   QLabel* languageLA = new QLabel( i18n("&Language of the groupware folders:"),
04552                                    mBox );
04553 
04554   toolTip = i18n( "Set the language of the folder names" );
04555   whatsThis = i18n( GlobalSettings::self()
04556         ->theIMAPResourceFolderLanguageItem()->whatsThis().utf8() );
04557   grid->addWidget( languageLA, 1, 0 );
04558   QToolTip::add( languageLA, toolTip );
04559   QWhatsThis::add( languageLA, whatsThis );
04560   mLanguageCombo = new QComboBox( false, mBox );
04561   languageLA->setBuddy( mLanguageCombo );
04562   QStringList lst;
04563   lst << i18n("English") << i18n("German") << i18n("French") << i18n("Dutch");
04564   mLanguageCombo->insertStringList( lst );
04565   grid->addWidget( mLanguageCombo, 1, 1 );
04566   QToolTip::add( mLanguageCombo, toolTip );
04567   QWhatsThis::add( mLanguageCombo, whatsThis );
04568   connect( mLanguageCombo, SIGNAL( activated( int ) ),
04569            this, SLOT( slotEmitChanged( void ) ) );
04570 
04571   mFolderComboLabel = new QLabel( mBox ); // text depends on storage format
04572   toolTip = i18n( "Set the parent of the resource folders" );
04573   whatsThis = i18n( GlobalSettings::self()->theIMAPResourceFolderParentItem()->whatsThis().utf8() );
04574   QToolTip::add( mFolderComboLabel, toolTip );
04575   QWhatsThis::add( mFolderComboLabel, whatsThis );
04576   grid->addWidget( mFolderComboLabel, 2, 0 );
04577 
04578   mFolderComboStack = new QWidgetStack( mBox );
04579   grid->addWidget( mFolderComboStack, 2, 1 );
04580 
04581   // First possibility in the widgetstack: a combo showing the list of all folders
04582   // This is used with the ical/vcard storage
04583   mFolderCombo = new FolderRequester( mBox,
04584       kmkernel->getKMMainWidget()->folderTree() );
04585   mFolderComboStack->addWidget( mFolderCombo, 0 );
04586   QToolTip::add( mFolderCombo, toolTip );
04587   QWhatsThis::add( mFolderCombo, whatsThis );
04588   connect( mFolderCombo, SIGNAL( folderChanged( KMFolder* ) ),
04589            this, SLOT( slotEmitChanged() ) );
04590 
04591   // Second possibility in the widgetstack: a combo showing the list of accounts
04592   // This is used with the kolab xml storage since the groupware folders
04593   // are always under the inbox.
04594   mAccountCombo = new KMail::AccountComboBox( mBox );
04595   mFolderComboStack->addWidget( mAccountCombo, 1 );
04596   QToolTip::add( mAccountCombo, toolTip );
04597   QWhatsThis::add( mAccountCombo, whatsThis );
04598   connect( mAccountCombo, SIGNAL( activated( int ) ),
04599            this, SLOT( slotEmitChanged() ) );
04600 
04601   mHideGroupwareFolders = new QCheckBox( i18n( "&Hide groupware folders" ),
04602                                          mBox, "HideGroupwareFoldersBox" );
04603   grid->addMultiCellWidget( mHideGroupwareFolders, 3, 3, 0, 1 );
04604   QToolTip::add( mHideGroupwareFolders,
04605                  i18n( "When this is checked, you will not see the IMAP "
04606                        "resource folders in the folder tree." ) );
04607   QWhatsThis::add( mHideGroupwareFolders, i18n( GlobalSettings::self()
04608            ->hideGroupwareFoldersItem()->whatsThis().utf8() ) );
04609   connect( mHideGroupwareFolders, SIGNAL( toggled( bool ) ),
04610            this, SLOT( slotEmitChanged() ) );
04611 
04612   // Groupware functionality compatibility setup
04613   b1 = new QVGroupBox( i18n("Groupware Compatibility && Legacy Options"), this );
04614 
04615   gBox = new QVBox( b1 );
04616 #if 0
04617   // Currently believed to be disused.
04618   mEnableGwCB = new QCheckBox( i18n("&Enable groupware functionality"), b1 );
04619   gBox->setSpacing( KDialog::spacingHint() );
04620   connect( mEnableGwCB, SIGNAL( toggled(bool) ),
04621            gBox, SLOT( setEnabled(bool) ) );
04622   connect( mEnableGwCB, SIGNAL( stateChanged( int ) ),
04623            this, SLOT( slotEmitChanged( void ) ) );
04624 #endif
04625   mEnableGwCB = 0;
04626   mLegacyMangleFromTo = new QCheckBox( i18n( "Mangle From:/To: headers in replies to invitations" ), gBox );
04627   QToolTip::add( mLegacyMangleFromTo, i18n( "Turn this option on in order to make Outlook(tm) understand your answers to invitation replies" ) );
04628   QWhatsThis::add( mLegacyMangleFromTo, i18n( GlobalSettings::self()->
04629            legacyMangleFromToHeadersItem()->whatsThis().utf8() ) );
04630   connect( mLegacyMangleFromTo, SIGNAL( stateChanged( int ) ),
04631            this, SLOT( slotEmitChanged( void ) ) );
04632   mLegacyBodyInvites = new QCheckBox( i18n( "Send invitations in the mail body" ), gBox );
04633   QToolTip::add( mLegacyBodyInvites, i18n( "Turn this option on in order to make Outlook(tm) understand your answers to invitations" ) );
04634   QWhatsThis::add( mLegacyMangleFromTo, i18n( GlobalSettings::self()->
04635            legacyBodyInvitesItem()->whatsThis().utf8() ) );
04636   connect( mLegacyBodyInvites, SIGNAL( toggled( bool ) ),
04637            this, SLOT( slotLegacyBodyInvitesToggled( bool ) ) );
04638   connect( mLegacyBodyInvites, SIGNAL( stateChanged( int ) ),
04639            this, SLOT( slotEmitChanged( void ) ) );
04640   mAutomaticSending = new QCheckBox( i18n( "Automatic invitation sending" ), gBox );
04641   QToolTip::add( mAutomaticSending, i18n( "When this is on, the user will not see the mail composer window. Invitation mails are sent automatically" ) );
04642   QWhatsThis::add( mAutomaticSending, i18n( GlobalSettings::self()->
04643            automaticSendingItem()->whatsThis().utf8() ) );
04644   connect( mAutomaticSending, SIGNAL( stateChanged( int ) ),
04645            this, SLOT( slotEmitChanged( void ) ) );
04646 
04647   // Open space padding at the end
04648   new QLabel( this );
04649 }
04650 
04651 void MiscPageGroupwareTab::slotLegacyBodyInvitesToggled( bool on )
04652 {
04653   if ( on ) {
04654     QString txt = i18n( "<qt>Invitations are normally sent as attachments to "
04655                         "a mail. This switch changes the invitation mails to "
04656                         "be sent in the text of the mail instead; this is "
04657                         "necessary to send invitations and replies to "
04658                         "Microsoft Outlook.<br>But, when you do this, you no "
04659                         "longer get descriptive text that mail programs "
04660                         "can read; so, to people who have email programs "
04661                         "that do not understand the invitations, the "
04662                         "resulting messages look very odd.<br>People that have email "
04663                         "programs that do understand invitations will still "
04664                         "be able to work with this.</qt>" );
04665     KMessageBox::information( this, txt, QString::null,
04666                               "LegacyBodyInvitesWarning" );
04667   }
04668   // Invitations in the body are autosent in any case (no point in editing raw ICAL)
04669   // So the autosend option is only available if invitations are sent as attachment.
04670   mAutomaticSending->setEnabled( !mLegacyBodyInvites->isChecked() );
04671 }
04672 
04673 void MiscPage::GroupwareTab::doLoadFromGlobalSettings() {
04674   // Read the groupware config
04675   if ( mEnableGwCB ) {
04676     mEnableGwCB->setChecked( GlobalSettings::self()->groupwareEnabled() );
04677     gBox->setEnabled( mEnableGwCB->isChecked() );
04678   }
04679   mLegacyMangleFromTo->setChecked( GlobalSettings::self()->legacyMangleFromToHeaders() );
04680   mLegacyBodyInvites->blockSignals( true );
04681   mLegacyBodyInvites->setChecked( GlobalSettings::self()->legacyBodyInvites() );
04682   mLegacyBodyInvites->blockSignals( false );
04683   mAutomaticSending->setChecked( GlobalSettings::self()->automaticSending() );
04684   mAutomaticSending->setEnabled( !mLegacyBodyInvites->isChecked() );
04685 
04686   // Read the IMAP resource config
04687   mEnableImapResCB->setChecked( GlobalSettings::self()->theIMAPResourceEnabled() );
04688   mBox->setEnabled( mEnableImapResCB->isChecked() );
04689 
04690   mHideGroupwareFolders->setChecked( GlobalSettings::self()->hideGroupwareFolders() );
04691   int i = GlobalSettings::self()->theIMAPResourceFolderLanguage();
04692   mLanguageCombo->setCurrentItem(i);
04693   i = GlobalSettings::self()->theIMAPResourceStorageFormat();
04694   mStorageFormatCombo->setCurrentItem(i);
04695   slotStorageFormatChanged( i );
04696 
04697   QString folderId( GlobalSettings::self()->theIMAPResourceFolderParent() );
04698   if( !folderId.isNull() && kmkernel->findFolderById( folderId ) ) {
04699     mFolderCombo->setFolder( folderId );
04700   } else {
04701     // Folder was deleted, we have to choose a new one
04702     mFolderCombo->setFolder( i18n( "<Choose a Folder>" ) );
04703   }
04704 
04705   KMAccount* selectedAccount = 0;
04706   int accountId = GlobalSettings::self()->theIMAPResourceAccount();
04707   if ( accountId )
04708     selectedAccount = kmkernel->acctMgr()->find( accountId );
04709   else {
04710     // Fallback: iterate over accounts to select folderId if found (as an inbox folder)
04711       for( KMAccount *a = kmkernel->acctMgr()->first(); a!=0;
04712          a = kmkernel->acctMgr()->next() ) {
04713       if( a->folder() && a->folder()->child() ) {
04714         // Look inside that folder for an INBOX
04715         KMFolderNode *node;
04716         for (node = a->folder()->child()->first(); node; node = a->folder()->child()->next())
04717           if (!node->isDir() && node->name() == "INBOX") break;
04718 
04719         if ( node && static_cast<KMFolder*>(node)->idString() == folderId ) {
04720           selectedAccount = a;
04721           break;
04722         }
04723       }
04724     }
04725   }
04726   if ( selectedAccount )
04727     mAccountCombo->setCurrentAccount( selectedAccount );
04728   else if ( GlobalSettings::self()->theIMAPResourceStorageFormat() == 1 )
04729     kdDebug(5006) << "Folder " << folderId << " not found as an account's inbox" << endl;
04730 }
04731 
04732 void MiscPage::GroupwareTab::save() {
04733   // Write the groupware config
04734   if ( mEnableGwCB )
04735     GlobalSettings::self()->setGroupwareEnabled( mEnableGwCB->isChecked() );
04736   GlobalSettings::self()->setLegacyMangleFromToHeaders( mLegacyMangleFromTo->isChecked() );
04737   GlobalSettings::self()->setLegacyBodyInvites( mLegacyBodyInvites->isChecked() );
04738   GlobalSettings::self()->setAutomaticSending( mAutomaticSending->isChecked() );
04739 
04740   int format = mStorageFormatCombo->currentItem();
04741   GlobalSettings::self()->setTheIMAPResourceStorageFormat( format );
04742 
04743   // Write the IMAP resource config
04744   GlobalSettings::self()->setHideGroupwareFolders( mHideGroupwareFolders->isChecked() );
04745 
04746   // If there is a leftover folder in the foldercombo, getFolder can
04747   // return 0. In that case we really don't have it enabled
04748   QString folderId;
04749   if (  format == 0 ) {
04750     KMFolder* folder = mFolderCombo->folder();
04751     if (  folder )
04752       folderId = folder->idString();
04753   } else {
04754     // Inbox folder of the selected account
04755     KMAccount* acct = mAccountCombo->currentAccount();
04756     if (  acct ) {
04757       folderId = QString( ".%1.directory/INBOX" ).arg( acct->id() );
04758       GlobalSettings::self()->setTheIMAPResourceAccount( acct->id() );
04759     }
04760   }
04761 
04762   bool enabled = mEnableImapResCB->isChecked() && !folderId.isEmpty();
04763   GlobalSettings::self()->setTheIMAPResourceEnabled( enabled );
04764   GlobalSettings::self()->setTheIMAPResourceFolderLanguage( mLanguageCombo->currentItem() );
04765   GlobalSettings::self()->setTheIMAPResourceFolderParent( folderId );
04766 }
04767 
04768 void MiscPage::GroupwareTab::slotStorageFormatChanged( int format )
04769 {
04770   mLanguageCombo->setEnabled( format == 0 ); // only ical/vcard needs the language hack
04771   mFolderComboStack->raiseWidget( format );
04772   if ( format == 0 ) {
04773     mFolderComboLabel->setText( i18n("&Resource folders are subfolders of:") );
04774     mFolderComboLabel->setBuddy( mFolderCombo );
04775   } else {
04776     mFolderComboLabel->setText( i18n("&Resource folders are in account:") );
04777     mFolderComboLabel->setBuddy( mAccountCombo );
04778   }
04779   slotEmitChanged();
04780 }
04781 
04782 
04783 // *************************************************************
04784 // *                                                           *
04785 // *                     AccountUpdater                        *
04786 // *                                                           *
04787 // *************************************************************
04788 AccountUpdater::AccountUpdater(ImapAccountBase *account)
04789     : QObject()
04790 {
04791   mAccount = account;
04792 }
04793 
04794 void AccountUpdater::update()
04795 {
04796   connect( mAccount, SIGNAL( connectionResult(int, const QString&) ),
04797           this, SLOT( namespacesFetched() ) );
04798   mAccount->makeConnection();
04799 }
04800 
04801 void AccountUpdater::namespacesFetched()
04802 {
04803   mAccount->setCheckingMail( true );
04804   mAccount->processNewMail( false );
04805   deleteLater();
04806 }
04807 
04808 #undef DIM
04809 
04810 //----------------------------
04811 #include "configuredialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys