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