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