kmail

accountdialog.cpp

Go to the documentation of this file.
00001 /*
00002  *   kmail: KDE mail client
00003  *   This file: Copyright (C) 2000 Espen Sand, espen@kde.org
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with this program; if not, write to the Free Software
00017  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  */
00020 #include <config.h>
00021 
00022 #include "accountdialog.h"
00023 
00024 #include <qbuttongroup.h>
00025 #include <qcheckbox.h>
00026 #include <qlayout.h>
00027 #include <qtabwidget.h>
00028 #include <qradiobutton.h>
00029 #include <qvalidator.h>
00030 #include <qlabel.h>
00031 #include <qpushbutton.h>
00032 #include <qwhatsthis.h>
00033 #include <qhbox.h>
00034 #include <qcombobox.h>
00035 #include <qheader.h>
00036 #include <qtoolbutton.h>
00037 #include <qgrid.h>
00038 
00039 #include <kfiledialog.h>
00040 #include <klocale.h>
00041 #include <kdebug.h>
00042 #include <kmessagebox.h>
00043 #include <knuminput.h>
00044 #include <kseparator.h>
00045 #include <kapplication.h>
00046 #include <kmessagebox.h>
00047 #include <kprotocolinfo.h>
00048 #include <kiconloader.h>
00049 #include <kpopupmenu.h>
00050 
00051 #include <netdb.h>
00052 #include <netinet/in.h>
00053 
00054 #include "sieveconfig.h"
00055 #include "kmacctmaildir.h"
00056 #include "kmacctlocal.h"
00057 #include "accountmanager.h"
00058 #include "popaccount.h"
00059 #include "kmacctimap.h"
00060 #include "kmacctcachedimap.h"
00061 #include "kmfoldermgr.h"
00062 #include "kmservertest.h"
00063 #include "protocols.h"
00064 #include "folderrequester.h"
00065 #include "kmmainwidget.h"
00066 #include "kmfolder.h"
00067 #include <libkpimidentities/identitymanager.h>
00068 #include <libkpimidentities/identitycombo.h>
00069 #include <libkpimidentities/identity.h>
00070 #include "globalsettings.h"
00071 
00072 #include <cassert>
00073 #include <stdlib.h>
00074 
00075 #ifdef HAVE_PATHS_H
00076 #include <paths.h>  /* defines _PATH_MAILDIR */
00077 #endif
00078 
00079 #ifndef _PATH_MAILDIR
00080 #define _PATH_MAILDIR "/var/spool/mail"
00081 #endif
00082 
00083 namespace KMail {
00084 
00085 class ProcmailRCParser
00086 {
00087 public:
00088   ProcmailRCParser(QString fileName = QString::null);
00089   ~ProcmailRCParser();
00090 
00091   QStringList getLockFilesList() const { return mLockFiles; }
00092   QStringList getSpoolFilesList() const { return mSpoolFiles; }
00093 
00094 protected:
00095   void processGlobalLock(const QString&);
00096   void processLocalLock(const QString&);
00097   void processVariableSetting(const QString&, int);
00098   QString expandVars(const QString&);
00099 
00100   QFile mProcmailrc;
00101   QTextStream *mStream;
00102   QStringList mLockFiles;
00103   QStringList mSpoolFiles;
00104   QAsciiDict<QString> mVars;
00105 };
00106 
00107 ProcmailRCParser::ProcmailRCParser(QString fname)
00108   : mProcmailrc(fname),
00109     mStream(new QTextStream(&mProcmailrc))
00110 {
00111   mVars.setAutoDelete(true);
00112 
00113   // predefined
00114   mVars.insert( "HOME", new QString( QDir::homeDirPath() ) );
00115 
00116   if( !fname || fname.isEmpty() ) {
00117     fname = QDir::homeDirPath() + "/.procmailrc";
00118     mProcmailrc.setName(fname);
00119   }
00120 
00121   QRegExp lockFileGlobal("^LOCKFILE=", true);
00122   QRegExp lockFileLocal("^:0", true);
00123 
00124   if(  mProcmailrc.open(IO_ReadOnly) ) {
00125 
00126     QString s;
00127 
00128     while( !mStream->eof() ) {
00129 
00130       s = mStream->readLine().stripWhiteSpace();
00131 
00132       if(  s[0] == '#' ) continue; // skip comments
00133 
00134       int commentPos = -1;
00135 
00136       if( (commentPos = s.find('#')) > -1 ) {
00137         // get rid of trailing comment
00138         s.truncate(commentPos);
00139         s = s.stripWhiteSpace();
00140       }
00141 
00142       if(  lockFileGlobal.search(s) != -1 ) {
00143         processGlobalLock(s);
00144       } else if( lockFileLocal.search(s) != -1 ) {
00145         processLocalLock(s);
00146       } else if( int i = s.find('=') ) {
00147         processVariableSetting(s,i);
00148       }
00149     }
00150 
00151   }
00152   QString default_Location = getenv("MAIL");
00153 
00154   if (default_Location.isNull()) {
00155     default_Location = _PATH_MAILDIR;
00156     default_Location += '/';
00157     default_Location += getenv("USER");
00158   }
00159   if ( !mSpoolFiles.contains(default_Location) )
00160     mSpoolFiles << default_Location;
00161 
00162   default_Location = default_Location + ".lock";
00163   if ( !mLockFiles.contains(default_Location) )
00164     mLockFiles << default_Location;
00165 }
00166 
00167 ProcmailRCParser::~ProcmailRCParser()
00168 {
00169   delete mStream;
00170 }
00171 
00172 void
00173 ProcmailRCParser::processGlobalLock(const QString &s)
00174 {
00175   QString val = expandVars(s.mid(s.find('=') + 1).stripWhiteSpace());
00176   if ( !mLockFiles.contains(val) )
00177     mLockFiles << val;
00178 }
00179 
00180 void
00181 ProcmailRCParser::processLocalLock(const QString &s)
00182 {
00183   QString val;
00184   int colonPos = s.findRev(':');
00185 
00186   if (colonPos > 0) { // we don't care about the leading one
00187     val = s.mid(colonPos + 1).stripWhiteSpace();
00188 
00189     if ( val.length() ) {
00190       // user specified a lockfile, so process it
00191       //
00192       val = expandVars(val);
00193       if( val[0] != '/' && mVars.find("MAILDIR") )
00194         val.insert(0, *(mVars["MAILDIR"]) + '/');
00195     } // else we'll deduce the lockfile name one we
00196     // get the spoolfile name
00197   }
00198 
00199   // parse until we find the spoolfile
00200   QString line, prevLine;
00201   do {
00202     prevLine = line;
00203     line = mStream->readLine().stripWhiteSpace();
00204   } while ( !mStream->eof() && (line[0] == '*' ||
00205                                 prevLine[prevLine.length() - 1] == '\\' ));
00206 
00207   if( line[0] != '!' && line[0] != '|' &&  line[0] != '{' ) {
00208     // this is a filename, expand it
00209     //
00210     line =  line.stripWhiteSpace();
00211     line = expandVars(line);
00212 
00213     // prepend default MAILDIR if needed
00214     if( line[0] != '/' && mVars.find("MAILDIR") )
00215       line.insert(0, *(mVars["MAILDIR"]) + '/');
00216 
00217     // now we have the spoolfile name
00218     if ( !mSpoolFiles.contains(line) )
00219       mSpoolFiles << line;
00220 
00221     if( colonPos > 0 && (!val || val.isEmpty()) ) {
00222       // there is a local lockfile, but the user didn't
00223       // specify the name so compute it from the spoolfile's name
00224       val = line;
00225 
00226       // append lock extension
00227       if( mVars.find("LOCKEXT") )
00228         val += *(mVars["LOCKEXT"]);
00229       else
00230         val += ".lock";
00231     }
00232 
00233     if ( !val.isNull() && !mLockFiles.contains(val) ) {
00234       mLockFiles << val;
00235     }
00236   }
00237 
00238 }
00239 
00240 void
00241 ProcmailRCParser::processVariableSetting(const QString &s, int eqPos)
00242 {
00243   if( eqPos == -1) return;
00244 
00245   QString varName = s.left(eqPos),
00246     varValue = expandVars(s.mid(eqPos + 1).stripWhiteSpace());
00247 
00248   mVars.insert(varName.latin1(), new QString(varValue));
00249 }
00250 
00251 QString
00252 ProcmailRCParser::expandVars(const QString &s)
00253 {
00254   if( s.isEmpty()) return s;
00255 
00256   QString expS = s;
00257 
00258   QAsciiDictIterator<QString> it( mVars ); // iterator for dict
00259 
00260   while ( it.current() ) {
00261     expS.replace(QString::fromLatin1("$") + it.currentKey(), *it.current());
00262     ++it;
00263   }
00264 
00265   return expS;
00266 }
00267 
00268 
00269 
00270 AccountDialog::AccountDialog( const QString & caption, KMAccount *account,
00271                   QWidget *parent, const char *name, bool modal )
00272   : KDialogBase( parent, name, modal, caption, Ok|Cancel|Help, Ok, true ),
00273     mAccount( account ),
00274     mServerTest( 0 ),
00275     mCurCapa( AllCapa ),
00276     mCapaNormal( AllCapa ),
00277     mCapaSSL( AllCapa ),
00278     mCapaTLS( AllCapa ),
00279     mSieveConfigEditor( 0 )
00280 {
00281   mValidator = new QRegExpValidator( QRegExp( "[A-Za-z0-9-_:.]*" ), 0 );
00282   setHelp("receiving-mail");
00283 
00284   QString accountType = mAccount->type();
00285 
00286   if( accountType == "local" )
00287   {
00288     makeLocalAccountPage();
00289   }
00290   else if( accountType == "maildir" )
00291   {
00292     makeMaildirAccountPage();
00293   }
00294   else if( accountType == "pop" )
00295   {
00296     makePopAccountPage();
00297   }
00298   else if( accountType == "imap" )
00299   {
00300     makeImapAccountPage();
00301   }
00302   else if( accountType == "cachedimap" )
00303   {
00304     makeImapAccountPage(true);
00305   }
00306   else
00307   {
00308     QString msg = i18n( "Account type is not supported." );
00309     KMessageBox::information( topLevelWidget(),msg,i18n("Configure Account") );
00310     return;
00311   }
00312 
00313   setupSettings();
00314 }
00315 
00316 AccountDialog::~AccountDialog()
00317 {
00318   delete mValidator;
00319   mValidator = 0;
00320   delete mServerTest;
00321   mServerTest = 0;
00322 }
00323 
00324 void AccountDialog::makeLocalAccountPage()
00325 {
00326   ProcmailRCParser procmailrcParser;
00327   QFrame *page = makeMainWidget();
00328   QGridLayout *topLayout = new QGridLayout( page, 12, 3, 0, spacingHint() );
00329   topLayout->addColSpacing( 1, fontMetrics().maxWidth()*15 );
00330   topLayout->setRowStretch( 11, 10 );
00331   topLayout->setColStretch( 1, 10 );
00332 
00333   mLocal.titleLabel = new QLabel( i18n("Account Type: Local Account"), page );
00334   topLayout->addMultiCellWidget( mLocal.titleLabel, 0, 0, 0, 2 );
00335   QFont titleFont( mLocal.titleLabel->font() );
00336   titleFont.setBold( true );
00337   mLocal.titleLabel->setFont( titleFont );
00338   KSeparator *hline = new KSeparator( KSeparator::HLine, page);
00339   topLayout->addMultiCellWidget( hline, 1, 1, 0, 2 );
00340 
00341   QLabel *label = new QLabel( i18n("Account &name:"), page );
00342   topLayout->addWidget( label, 2, 0 );
00343   mLocal.nameEdit = new KLineEdit( page );
00344   label->setBuddy( mLocal.nameEdit );
00345   topLayout->addWidget( mLocal.nameEdit, 2, 1 );
00346 
00347   label = new QLabel( i18n("File &location:"), page );
00348   topLayout->addWidget( label, 3, 0 );
00349   mLocal.locationEdit = new QComboBox( true, page );
00350   label->setBuddy( mLocal.locationEdit );
00351   topLayout->addWidget( mLocal.locationEdit, 3, 1 );
00352   mLocal.locationEdit->insertStringList(procmailrcParser.getSpoolFilesList());
00353 
00354   QPushButton *choose = new QPushButton( i18n("Choo&se..."), page );
00355   choose->setAutoDefault( false );
00356   connect( choose, SIGNAL(clicked()), this, SLOT(slotLocationChooser()) );
00357   topLayout->addWidget( choose, 3, 2 );
00358 
00359   QButtonGroup *group = new QButtonGroup(i18n("Locking Method"), page );
00360   group->setColumnLayout(0, Qt::Horizontal);
00361   group->layout()->setSpacing( 0 );
00362   group->layout()->setMargin( 0 );
00363   QGridLayout *groupLayout = new QGridLayout( group->layout() );
00364   groupLayout->setAlignment( Qt::AlignTop );
00365   groupLayout->setSpacing( 6 );
00366   groupLayout->setMargin( 11 );
00367 
00368   mLocal.lockProcmail = new QRadioButton( i18n("Procmail loc&kfile:"), group);
00369   groupLayout->addWidget(mLocal.lockProcmail, 0, 0);
00370 
00371   mLocal.procmailLockFileName = new QComboBox( true, group );
00372   groupLayout->addWidget(mLocal.procmailLockFileName, 0, 1);
00373   mLocal.procmailLockFileName->insertStringList(procmailrcParser.getLockFilesList());
00374   mLocal.procmailLockFileName->setEnabled(false);
00375 
00376   QObject::connect(mLocal.lockProcmail, SIGNAL(toggled(bool)),
00377                    mLocal.procmailLockFileName, SLOT(setEnabled(bool)));
00378 
00379   mLocal.lockMutt = new QRadioButton(
00380     i18n("&Mutt dotlock"), group);
00381   groupLayout->addWidget(mLocal.lockMutt, 1, 0);
00382 
00383   mLocal.lockMuttPriv = new QRadioButton(
00384     i18n("M&utt dotlock privileged"), group);
00385   groupLayout->addWidget(mLocal.lockMuttPriv, 2, 0);
00386 
00387   mLocal.lockFcntl = new QRadioButton(
00388     i18n("&FCNTL"), group);
00389   groupLayout->addWidget(mLocal.lockFcntl, 3, 0);
00390 
00391   mLocal.lockNone = new QRadioButton(
00392     i18n("Non&e (use with care)"), group);
00393   groupLayout->addWidget(mLocal.lockNone, 4, 0);
00394 
00395   topLayout->addMultiCellWidget( group, 4, 4, 0, 2 );
00396 
00397 #if 0
00398   QHBox* resourceHB = new QHBox( page );
00399   resourceHB->setSpacing( 11 );
00400   mLocal.resourceCheck =
00401       new QCheckBox( i18n( "Account for semiautomatic resource handling" ), resourceHB );
00402   mLocal.resourceClearButton =
00403       new QPushButton( i18n( "Clear" ), resourceHB );
00404   QWhatsThis::add( mLocal.resourceClearButton,
00405                    i18n( "Delete all allocations for the resource represented by this account." ) );
00406   mLocal.resourceClearButton->setEnabled( false );
00407   connect( mLocal.resourceCheck, SIGNAL( toggled(bool) ),
00408            mLocal.resourceClearButton, SLOT( setEnabled(bool) ) );
00409   connect( mLocal.resourceClearButton, SIGNAL( clicked() ),
00410            this, SLOT( slotClearResourceAllocations() ) );
00411   mLocal.resourceClearPastButton =
00412       new QPushButton( i18n( "Clear Past" ), resourceHB );
00413   mLocal.resourceClearPastButton->setEnabled( false );
00414   connect( mLocal.resourceCheck, SIGNAL( toggled(bool) ),
00415            mLocal.resourceClearPastButton, SLOT( setEnabled(bool) ) );
00416   QWhatsThis::add( mLocal.resourceClearPastButton,
00417                    i18n( "Delete all outdated allocations for the resource represented by this account." ) );
00418   connect( mLocal.resourceClearPastButton, SIGNAL( clicked() ),
00419            this, SLOT( slotClearPastResourceAllocations() ) );
00420   topLayout->addMultiCellWidget( resourceHB, 5, 5, 0, 2 );
00421 #endif
00422 
00423   mLocal.includeInCheck =
00424     new QCheckBox( i18n("Include in m&anual mail check"),
00425                    page );
00426   topLayout->addMultiCellWidget( mLocal.includeInCheck, 5, 5, 0, 2 );
00427 
00428   mLocal.intervalCheck =
00429     new QCheckBox( i18n("Enable &interval mail checking"), page );
00430   topLayout->addMultiCellWidget( mLocal.intervalCheck, 6, 6, 0, 2 );
00431   connect( mLocal.intervalCheck, SIGNAL(toggled(bool)),
00432        this, SLOT(slotEnableLocalInterval(bool)) );
00433   mLocal.intervalLabel = new QLabel( i18n("Check inter&val:"), page );
00434   topLayout->addWidget( mLocal.intervalLabel, 7, 0 );
00435   mLocal.intervalSpin = new KIntNumInput( page );
00436   mLocal.intervalLabel->setBuddy( mLocal.intervalSpin );
00437   mLocal.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(), 10000, 1, false );
00438   mLocal.intervalSpin->setSuffix( i18n(" min") );
00439   mLocal.intervalSpin->setValue( defaultmailcheckintervalmin );
00440   topLayout->addWidget( mLocal.intervalSpin, 7, 1 );
00441 
00442   label = new QLabel( i18n("&Destination folder:"), page );
00443   topLayout->addWidget( label, 8, 0 );
00444   mLocal.folderCombo = new QComboBox( false, page );
00445   label->setBuddy( mLocal.folderCombo );
00446   topLayout->addWidget( mLocal.folderCombo, 8, 1 );
00447 
00448   label = new QLabel( i18n("&Pre-command:"), page );
00449   topLayout->addWidget( label, 9, 0 );
00450   mLocal.precommand = new KLineEdit( page );
00451   label->setBuddy( mLocal.precommand );
00452   topLayout->addWidget( mLocal.precommand, 9, 1 );
00453 
00454   mLocal.identityLabel = new QLabel( i18n("Identity:"), page );
00455   topLayout->addWidget( mLocal.identityLabel, 10, 0 );
00456   mLocal.identityCombo = new KPIM::IdentityCombo(kmkernel->identityManager(), page );
00457   mLocal.identityLabel->setBuddy( mLocal.identityCombo );
00458   topLayout->addWidget( mLocal.identityCombo, 10, 1 );
00459 
00460   connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()));
00461 }
00462 
00463 void AccountDialog::makeMaildirAccountPage()
00464 {
00465   ProcmailRCParser procmailrcParser;
00466 
00467   QFrame *page = makeMainWidget();
00468   QGridLayout *topLayout = new QGridLayout( page, 11, 3, 0, spacingHint() );
00469   topLayout->addColSpacing( 1, fontMetrics().maxWidth()*15 );
00470   topLayout->setRowStretch( 11, 10 );
00471   topLayout->setColStretch( 1, 10 );
00472 
00473   mMaildir.titleLabel = new QLabel( i18n("Account Type: Maildir Account"), page );
00474   topLayout->addMultiCellWidget( mMaildir.titleLabel, 0, 0, 0, 2 );
00475   QFont titleFont( mMaildir.titleLabel->font() );
00476   titleFont.setBold( true );
00477   mMaildir.titleLabel->setFont( titleFont );
00478   QFrame *hline = new QFrame( page );
00479   hline->setFrameStyle( QFrame::Sunken | QFrame::HLine );
00480   topLayout->addMultiCellWidget( hline, 1, 1, 0, 2 );
00481 
00482   mMaildir.nameEdit = new KLineEdit( page );
00483   topLayout->addWidget( mMaildir.nameEdit, 2, 1 );
00484   QLabel *label = new QLabel( mMaildir.nameEdit, i18n("Account &name:"), page );
00485   topLayout->addWidget( label, 2, 0 );
00486 
00487   mMaildir.locationEdit = new QComboBox( true, page );
00488   topLayout->addWidget( mMaildir.locationEdit, 3, 1 );
00489   mMaildir.locationEdit->insertStringList(procmailrcParser.getSpoolFilesList());
00490   label = new QLabel( mMaildir.locationEdit, i18n("Folder &location:"), page );
00491   topLayout->addWidget( label, 3, 0 );
00492 
00493   QPushButton *choose = new QPushButton( i18n("Choo&se..."), page );
00494   choose->setAutoDefault( false );
00495   connect( choose, SIGNAL(clicked()), this, SLOT(slotMaildirChooser()) );
00496   topLayout->addWidget( choose, 3, 2 );
00497 
00498 #if 0
00499   QHBox* resourceHB = new QHBox( page );
00500   resourceHB->setSpacing( 11 );
00501   mMaildir.resourceCheck =
00502       new QCheckBox( i18n( "Account for semiautomatic resource handling" ), resourceHB );
00503   mMaildir.resourceClearButton =
00504       new QPushButton( i18n( "Clear" ), resourceHB );
00505   mMaildir.resourceClearButton->setEnabled( false );
00506   connect( mMaildir.resourceCheck, SIGNAL( toggled(bool) ),
00507            mMaildir.resourceClearButton, SLOT( setEnabled(bool) ) );
00508   QWhatsThis::add( mMaildir.resourceClearButton,
00509                    i18n( "Delete all allocations for the resource represented by this account." ) );
00510   connect( mMaildir.resourceClearButton, SIGNAL( clicked() ),
00511            this, SLOT( slotClearResourceAllocations() ) );
00512   mMaildir.resourceClearPastButton =
00513       new QPushButton( i18n( "Clear Past" ), resourceHB );
00514   mMaildir.resourceClearPastButton->setEnabled( false );
00515   connect( mMaildir.resourceCheck, SIGNAL( toggled(bool) ),
00516            mMaildir.resourceClearPastButton, SLOT( setEnabled(bool) ) );
00517   QWhatsThis::add( mMaildir.resourceClearPastButton,
00518                    i18n( "Delete all outdated allocations for the resource represented by this account." ) );
00519   connect( mMaildir.resourceClearPastButton, SIGNAL( clicked() ),
00520            this, SLOT( slotClearPastResourceAllocations() ) );
00521   topLayout->addMultiCellWidget( resourceHB, 4, 4, 0, 2 );
00522 #endif
00523 
00524   mMaildir.includeInCheck =
00525     new QCheckBox( i18n("Include in &manual mail check"), page );
00526   topLayout->addMultiCellWidget( mMaildir.includeInCheck, 4, 4, 0, 2 );
00527 
00528   mMaildir.intervalCheck =
00529     new QCheckBox( i18n("Enable &interval mail checking"), page );
00530   topLayout->addMultiCellWidget( mMaildir.intervalCheck, 5, 5, 0, 2 );
00531   connect( mMaildir.intervalCheck, SIGNAL(toggled(bool)),
00532        this, SLOT(slotEnableMaildirInterval(bool)) );
00533   mMaildir.intervalLabel = new QLabel( i18n("Check inter&val:"), page );
00534   topLayout->addWidget( mMaildir.intervalLabel, 6, 0 );
00535   mMaildir.intervalSpin = new KIntNumInput( page );
00536   mMaildir.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(), 10000, 1, false );
00537   mMaildir.intervalSpin->setSuffix( i18n(" min") );
00538   mMaildir.intervalSpin->setValue( defaultmailcheckintervalmin );
00539   mMaildir.intervalLabel->setBuddy( mMaildir.intervalSpin );
00540   topLayout->addWidget( mMaildir.intervalSpin, 6, 1 );
00541 
00542   mMaildir.folderCombo = new QComboBox( false, page );
00543   topLayout->addWidget( mMaildir.folderCombo, 7, 1 );
00544   label = new QLabel( mMaildir.folderCombo,
00545               i18n("&Destination folder:"), page );
00546   topLayout->addWidget( label, 7, 0 );
00547 
00548   mMaildir.precommand = new KLineEdit( page );
00549   topLayout->addWidget( mMaildir.precommand, 8, 1 );
00550   label = new QLabel( mMaildir.precommand, i18n("&Pre-command:"), page );
00551   topLayout->addWidget( label, 8, 0 );
00552 
00553 
00554   mMaildir.identityLabel = new QLabel( i18n("Identity:"), page );
00555   topLayout->addWidget( mMaildir.identityLabel, 9, 0 );
00556   mMaildir.identityCombo = new KPIM::IdentityCombo(kmkernel->identityManager(), page );
00557   mMaildir.identityLabel->setBuddy( mMaildir.identityCombo );
00558   topLayout->addWidget( mMaildir.identityCombo, 9, 1 );
00559 
00560   connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()));
00561 }
00562 
00563 
00564 void AccountDialog::makePopAccountPage()
00565 {
00566   QFrame *page = makeMainWidget();
00567   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00568 
00569   mPop.titleLabel = new QLabel( page );
00570   mPop.titleLabel->setText( i18n("Account Type: POP Account") );
00571   QFont titleFont( mPop.titleLabel->font() );
00572   titleFont.setBold( true );
00573   mPop.titleLabel->setFont( titleFont );
00574   topLayout->addWidget( mPop.titleLabel );
00575   KSeparator *hline = new KSeparator( KSeparator::HLine, page);
00576   topLayout->addWidget( hline );
00577 
00578   QTabWidget *tabWidget = new QTabWidget(page);
00579   topLayout->addWidget( tabWidget );
00580 
00581   QWidget *page1 = new QWidget( tabWidget );
00582   tabWidget->addTab( page1, i18n("&General") );
00583 
00584   QGridLayout *grid = new QGridLayout( page1, 16, 2, marginHint(), spacingHint() );
00585   grid->addColSpacing( 1, fontMetrics().maxWidth()*15 );
00586   grid->setRowStretch( 15, 10 );
00587   grid->setColStretch( 1, 10 );
00588 
00589   QLabel *label = new QLabel( i18n("Account &name:"), page1 );
00590   grid->addWidget( label, 0, 0 );
00591   mPop.nameEdit = new KLineEdit( page1 );
00592   label->setBuddy( mPop.nameEdit );
00593   grid->addWidget( mPop.nameEdit, 0, 1 );
00594 
00595   label = new QLabel( i18n("&Login:"), page1 );
00596   QWhatsThis::add( label, i18n("Your Internet Service Provider gave you a <em>user name</em> which is used to authenticate you with their servers. It usually is the first part of your email address (the part before <em>@</em>).") );
00597   grid->addWidget( label, 1, 0 );
00598   mPop.loginEdit = new KLineEdit( page1 );
00599   label->setBuddy( mPop.loginEdit );
00600   grid->addWidget( mPop.loginEdit, 1, 1 );
00601 
00602   label = new QLabel( i18n("P&assword:"), page1 );
00603   grid->addWidget( label, 2, 0 );
00604   mPop.passwordEdit = new KLineEdit( page1 );
00605   mPop.passwordEdit->setEchoMode( QLineEdit::Password );
00606   label->setBuddy( mPop.passwordEdit );
00607   grid->addWidget( mPop.passwordEdit, 2, 1 );
00608 
00609   label = new QLabel( i18n("Ho&st:"), page1 );
00610   grid->addWidget( label, 3, 0 );
00611   mPop.hostEdit = new KLineEdit( page1 );
00612   // only letters, digits, '-', '.', ':' (IPv6) and '_' (for Windows
00613   // compatibility) are allowed
00614   mPop.hostEdit->setValidator(mValidator);
00615   label->setBuddy( mPop.hostEdit );
00616   grid->addWidget( mPop.hostEdit, 3, 1 );
00617 
00618   label = new QLabel( i18n("&Port:"), page1 );
00619   grid->addWidget( label, 4, 0 );
00620   mPop.portEdit = new KLineEdit( page1 );
00621   mPop.portEdit->setValidator( new QIntValidator(this) );
00622   label->setBuddy( mPop.portEdit );
00623   grid->addWidget( mPop.portEdit, 4, 1 );
00624 
00625   mPop.storePasswordCheck =
00626     new QCheckBox( i18n("Sto&re POP password"), page1 );
00627   QWhatsThis::add( mPop.storePasswordCheck,
00628                    i18n("Check this option to have KMail store "
00629                    "the password.\nIf KWallet is available "
00630                    "the password will be stored there which is considered "
00631                    "safe.\nHowever, if KWallet is not available, "
00632                    "the password will be stored in KMail's configuration "
00633                    "file. The password is stored in an "
00634                    "obfuscated format, but should not be "
00635                    "considered secure from decryption efforts "
00636                    "if access to the configuration file is obtained.") );
00637   grid->addMultiCellWidget( mPop.storePasswordCheck, 5, 5, 0, 1 );
00638 
00639   mPop.leaveOnServerCheck =
00640     new QCheckBox( i18n("Lea&ve fetched messages on the server"), page1 );
00641   connect( mPop.leaveOnServerCheck, SIGNAL( clicked() ),
00642            this, SLOT( slotLeaveOnServerClicked() ) );
00643   grid->addMultiCellWidget( mPop.leaveOnServerCheck, 6, 6, 0, 1 );
00644   QHBox *afterDaysBox = new QHBox( page1 );
00645   afterDaysBox->setSpacing( KDialog::spacingHint() );
00646   mPop.leaveOnServerDaysCheck =
00647     new QCheckBox( i18n("Leave messages on the server for"), afterDaysBox );
00648   connect( mPop.leaveOnServerDaysCheck, SIGNAL( toggled(bool) ),
00649            this, SLOT( slotEnableLeaveOnServerDays(bool)) );
00650   mPop.leaveOnServerDaysSpin = new KIntNumInput( afterDaysBox );
00651   mPop.leaveOnServerDaysSpin->setRange( 1, 365, 1, false );
00652   connect( mPop.leaveOnServerDaysSpin, SIGNAL(valueChanged(int)),
00653            SLOT(slotLeaveOnServerDaysChanged(int)));
00654   mPop.leaveOnServerDaysSpin->setValue( 1 );
00655   afterDaysBox->setStretchFactor( mPop.leaveOnServerDaysSpin, 1 );
00656   grid->addMultiCellWidget( afterDaysBox, 7, 7, 0, 1 );
00657   QHBox *leaveOnServerCountBox = new QHBox( page1 );
00658   leaveOnServerCountBox->setSpacing( KDialog::spacingHint() );
00659   mPop.leaveOnServerCountCheck =
00660     new QCheckBox( i18n("Keep only the last"), leaveOnServerCountBox );
00661   connect( mPop.leaveOnServerCountCheck, SIGNAL( toggled(bool) ),
00662            this, SLOT( slotEnableLeaveOnServerCount(bool)) );
00663   mPop.leaveOnServerCountSpin = new KIntNumInput( leaveOnServerCountBox );
00664   mPop.leaveOnServerCountSpin->setRange( 1, 999999, 1, false );
00665   connect( mPop.leaveOnServerCountSpin, SIGNAL(valueChanged(int)),
00666            SLOT(slotLeaveOnServerCountChanged(int)));
00667   mPop.leaveOnServerCountSpin->setValue( 100 );
00668   grid->addMultiCellWidget( leaveOnServerCountBox, 8, 8, 0, 1 );
00669   QHBox *leaveOnServerSizeBox = new QHBox( page1 );
00670   leaveOnServerSizeBox->setSpacing( KDialog::spacingHint() );
00671   mPop.leaveOnServerSizeCheck =
00672     new QCheckBox( i18n("Keep only the last"), leaveOnServerSizeBox );
00673   connect( mPop.leaveOnServerSizeCheck, SIGNAL( toggled(bool) ),
00674            this, SLOT( slotEnableLeaveOnServerSize(bool)) );
00675   mPop.leaveOnServerSizeSpin = new KIntNumInput( leaveOnServerSizeBox );
00676   mPop.leaveOnServerSizeSpin->setRange( 1, 999999, 1, false );
00677   mPop.leaveOnServerSizeSpin->setSuffix( i18n(" MB") );
00678   mPop.leaveOnServerSizeSpin->setValue( 10 );
00679   grid->addMultiCellWidget( leaveOnServerSizeBox, 9, 9, 0, 1 );
00680 #if 0
00681   QHBox *resourceHB = new QHBox( page1 );
00682   resourceHB->setSpacing( 11 );
00683   mPop.resourceCheck =
00684       new QCheckBox( i18n( "Account for semiautomatic resource handling" ), resourceHB );
00685   mPop.resourceClearButton =
00686       new QPushButton( i18n( "Clear" ), resourceHB );
00687   mPop.resourceClearButton->setEnabled( false );
00688   connect( mPop.resourceCheck, SIGNAL( toggled(bool) ),
00689            mPop.resourceClearButton, SLOT( setEnabled(bool) ) );
00690   QWhatsThis::add( mPop.resourceClearButton,
00691                    i18n( "Delete all allocations for the resource represented by this account." ) );
00692   connect( mPop.resourceClearButton, SIGNAL( clicked() ),
00693            this, SLOT( slotClearResourceAllocations() ) );
00694   mPop.resourceClearPastButton =
00695       new QPushButton( i18n( "Clear Past" ), resourceHB );
00696   mPop.resourceClearPastButton->setEnabled( false );
00697   connect( mPop.resourceCheck, SIGNAL( toggled(bool) ),
00698            mPop.resourceClearPastButton, SLOT( setEnabled(bool) ) );
00699   QWhatsThis::add( mPop.resourceClearPastButton,
00700                    i18n( "Delete all outdated allocations for the resource represented by this account." ) );
00701   connect( mPop.resourceClearPastButton, SIGNAL( clicked() ),
00702            this, SLOT( slotClearPastResourceAllocations() ) );
00703   grid->addMultiCellWidget( resourceHB, 10, 10, 0, 2 );
00704 #endif
00705 
00706   mPop.includeInCheck =
00707     new QCheckBox( i18n("Include in man&ual mail check"), page1 );
00708   grid->addMultiCellWidget( mPop.includeInCheck, 10, 10, 0, 1 );
00709 
00710   QHBox * hbox = new QHBox( page1 );
00711   hbox->setSpacing( KDialog::spacingHint() );
00712   mPop.filterOnServerCheck =
00713     new QCheckBox( i18n("&Filter messages if they are greater than"), hbox );
00714   mPop.filterOnServerSizeSpin = new KIntNumInput ( hbox );
00715   mPop.filterOnServerSizeSpin->setEnabled( false );
00716   hbox->setStretchFactor( mPop.filterOnServerSizeSpin, 1 );
00717   mPop.filterOnServerSizeSpin->setRange( 1, 10000000, 100, false );
00718   connect(mPop.filterOnServerSizeSpin, SIGNAL(valueChanged(int)),
00719           SLOT(slotFilterOnServerSizeChanged(int)));
00720   mPop.filterOnServerSizeSpin->setValue( 50000 );
00721   grid->addMultiCellWidget( hbox, 11, 11, 0, 1 );
00722   connect( mPop.filterOnServerCheck, SIGNAL(toggled(bool)),
00723        mPop.filterOnServerSizeSpin, SLOT(setEnabled(bool)) );
00724   connect( mPop.filterOnServerCheck, SIGNAL( clicked() ),
00725            this, SLOT( slotFilterOnServerClicked() ) );
00726   QString msg = i18n("If you select this option, POP Filters will be used to "
00727              "decide what to do with messages. You can then select "
00728              "to download, delete or keep them on the server." );
00729   QWhatsThis::add( mPop.filterOnServerCheck, msg );
00730   QWhatsThis::add( mPop.filterOnServerSizeSpin, msg );
00731 
00732   mPop.intervalCheck =
00733     new QCheckBox( i18n("Enable &interval mail checking"), page1 );
00734   grid->addMultiCellWidget( mPop.intervalCheck, 12, 12, 0, 1 );
00735   connect( mPop.intervalCheck, SIGNAL(toggled(bool)),
00736        this, SLOT(slotEnablePopInterval(bool)) );
00737   mPop.intervalLabel = new QLabel( i18n("Chec&k interval:"), page1 );
00738   grid->addWidget( mPop.intervalLabel, 13, 0 );
00739   mPop.intervalSpin = new KIntNumInput( page1 );
00740   mPop.intervalSpin->setRange( GlobalSettings::self()->minimumCheckInterval(), 10000, 1, false );
00741   mPop.intervalSpin->setSuffix( i18n(" min") );
00742   mPop.intervalSpin->setValue( defaultmailcheckintervalmin );
00743   mPop.intervalLabel->setBuddy( mPop.intervalSpin );
00744   grid->addWidget( mPop.intervalSpin, 13, 1 );
00745 
00746   label = new QLabel( i18n("Des&tination folder:"), page1 );
00747   grid->addWidget( label, 14, 0 );
00748   mPop.folderCombo = new QComboBox( false, page1 );
00749   label->setBuddy( mPop.folderCombo );
00750   grid->addWidget( mPop.folderCombo, 14, 1 );
00751 
00752   label = new QLabel( i18n("Pre-com&mand:"), page1 );
00753   grid->addWidget( label, 15, 0 );
00754   mPop.precommand = new KLineEdit( page1 );
00755   label->setBuddy(mPop.precommand);
00756   grid->addWidget( mPop.precommand, 15, 1 );
00757 
00758   mPop.identityLabel = new QLabel( i18n("Identity:"), page1 );
00759   grid->addWidget( mPop.identityLabel, 16, 0 );
00760   mPop.identityCombo = new KPIM::IdentityCombo(kmkernel->identityManager(), page1 );
00761   mPop.identityLabel->setBuddy( mPop.identityCombo );
00762   grid->addWidget( mPop.identityCombo, 16, 1 );
00763 
00764   QWidget *page2 = new QWidget( tabWidget );
00765   tabWidget->addTab( page2, i18n("&Extras") );
00766   QVBoxLayout *vlay = new QVBoxLayout( page2, marginHint(), spacingHint() );
00767 
00768   vlay->addSpacing( KDialog::spacingHint() );
00769 
00770   QHBoxLayout *buttonLay = new QHBoxLayout( vlay );
00771   mPop.checkCapabilities =
00772     new QPushButton( i18n("Check &What the Server Supports"), page2 );
00773   connect(mPop.checkCapabilities, SIGNAL(clicked()),
00774     SLOT(slotCheckPopCapabilities()));
00775   buttonLay->addStretch();
00776   buttonLay->addWidget( mPop.checkCapabilities );
00777   buttonLay->addStretch();
00778 
00779   vlay->addSpacing( KDialog::spacingHint() );
00780 
00781   mPop.encryptionGroup = new QButtonGroup( 1, Qt::Horizontal,
00782     i18n("Encryption"), page2 );
00783   mPop.encryptionNone =
00784     new QRadioButton( i18n("&None"), mPop.encryptionGroup );
00785   mPop.encryptionSSL =
00786     new QRadioButton( i18n("Use &SSL for secure mail download"),
00787     mPop.encryptionGroup );
00788   mPop.encryptionTLS =
00789     new QRadioButton( i18n("Use &TLS for secure mail download"),
00790     mPop.encryptionGroup );
00791   connect(mPop.encryptionGroup, SIGNAL(clicked(int)),
00792     SLOT(slotPopEncryptionChanged(int)));
00793   vlay->addWidget( mPop.encryptionGroup );
00794 
00795   mPop.authGroup = new QButtonGroup( 1, Qt::Horizontal,
00796     i18n("Authentication Method"), page2 );
00797   mPop.authUser = new QRadioButton( i18n("Clear te&xt") , mPop.authGroup,
00798                                     "auth clear text" );
00799   mPop.authLogin = new QRadioButton( i18n("Please translate this "
00800     "authentication method only if you have a good reason", "&LOGIN"),
00801     mPop.authGroup, "auth login" );
00802   mPop.authPlain = new QRadioButton( i18n("Please translate this "
00803     "authentication method only if you have a good reason", "&PLAIN"),
00804     mPop.authGroup, "auth plain"  );
00805   mPop.authCRAM_MD5 = new QRadioButton( i18n("CRAM-MD&5"), mPop.authGroup, "auth cram-md5" );
00806   mPop.authDigestMd5 = new QRadioButton( i18n("&DIGEST-MD5"), mPop.authGroup, "auth digest-md5" );
00807   mPop.authNTLM = new QRadioButton( i18n("&NTLM"), mPop.authGroup, "auth ntlm" );
00808   mPop.authGSSAPI = new QRadioButton( i18n("&GSSAPI"), mPop.authGroup, "auth gssapi" );
00809   if ( KProtocolInfo::capabilities("pop3").contains("SASL") == 0 )
00810   {
00811     mPop.authNTLM->hide();
00812     mPop.authGSSAPI->hide();
00813   }
00814   mPop.authAPOP = new QRadioButton( i18n("&APOP"), mPop.authGroup, "auth apop" );
00815 
00816   vlay->addWidget( mPop.authGroup );
00817 
00818   mPop.usePipeliningCheck =
00819     new QCheckBox( i18n("&Use pipelining for faster mail download"), page2 );
00820   connect(mPop.usePipeliningCheck, SIGNAL(clicked()),
00821     SLOT(slotPipeliningClicked()));
00822   vlay->addWidget( mPop.usePipeliningCheck );
00823 
00824   vlay->addStretch();
00825 
00826   connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()));
00827 }
00828 
00829 
00830 void AccountDialog::makeImapAccountPage( bool connected )
00831 {
00832   QFrame *page = makeMainWidget();
00833   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00834 
00835   mImap.titleLabel = new QLabel( page );
00836   if( connected )
00837     mImap.titleLabel->setText( i18n("Account Type: Disconnected IMAP Account") );
00838   else
00839     mImap.titleLabel->setText( i18n("Account Type: IMAP Account") );
00840   QFont titleFont( mImap.titleLabel->font() );
00841   titleFont.setBold( true );
00842   mImap.titleLabel->setFont( titleFont );
00843   topLayout->addWidget( mImap.titleLabel );
00844   KSeparator *hline = new KSeparator( KSeparator::HLine, page);
00845   topLayout->addWidget( hline );
00846 
00847   QTabWidget *tabWidget = new QTabWidget(page);
00848   topLayout->addWidget( tabWidget );
00849 
00850   QWidget *page1 = new QWidget( tabWidget );
00851   tabWidget->addTab( page1, i18n("&General") );
00852 
00853   int row = -1;
00854   QGridLayout *grid = new QGridLayout( page1, 16, 2, marginHint(), spacingHint() );
00855   grid->addColSpacing( 1, fontMetrics().maxWidth()*16 );
00856 
00857   ++row;
00858   QLabel *label = new QLabel( i18n("Account &name:"), page1 );
00859   grid->addWidget( label, row, 0 );
00860   mImap.nameEdit = new KLineEdit( page1 );
00861   label->setBuddy( mImap.nameEdit );
00862   grid->addWidget( mImap.nameEdit, row, 1 );
00863 
00864   ++row;
00865   label = new QLabel( i18n("&Login:"), page1 );
00866   QWhatsThis::add( label, i18n("Your Internet Service Provider gave you a <em>user name</em> which is used to authenticate you with their servers. It usually is the first part of your email address (the part before <em>@</em>).") );
00867   grid->addWidget( label, row, 0 );
00868   mImap.loginEdit = new KLineEdit( page1 );
00869   label->setBuddy( mImap.loginEdit );
00870   grid->addWidget( mImap.loginEdit, row, 1 );
00871 
00872   ++row;
00873   label = new QLabel( i18n("P&assword:"), page1 );
00874   grid->addWidget( label, row, 0 );
00875   mImap.passwordEdit = new KLineEdit( page1 );
00876   mImap.passwordEdit->setEchoMode( QLineEdit::Password );
00877   label->setBuddy( mImap.passwordEdit );
00878   grid->addWidget( mImap.passwordEdit, row, 1 );
00879 
00880   ++row;
00881   label = new QLabel( i18n("Ho&st:"), page1 );
00882   grid->addWidget( label, row, 0 );
00883   mImap.hostEdit = new KLineEdit( page1 );
00884   // only letters, digits, '-', '.', ':' (IPv6) and '_' (for Windows
00885   // compatibility) are allowed
00886   mImap.hostEdit->setValidator(mValidator);
00887   label->setBuddy( mImap.hostEdit );
00888   grid->addWidget( mImap.hostEdit, row, 1 );
00889 
00890   ++row;
00891   label = new QLabel( i18n("&Port:"), page1 );
00892   grid->addWidget( label, row, 0 );
00893   mImap.portEdit = new KLineEdit( page1 );
00894   mImap.portEdit->setValidator( new QIntValidator(this) );
00895   label->setBuddy( mImap.portEdit );
00896   grid->addWidget( mImap.portEdit, row, 1 );
00897 
00898   // namespace list
00899   ++row;
00900   QHBox* box = new QHBox( page1 );
00901   label = new QLabel( i18n("Namespaces:"), box );
00902   QWhatsThis::add( label, i18n( "Here you see the different namespaces that your IMAP server supports."
00903         "Each namespace represents a prefix that separates groups of folders."
00904         "Namespaces allow KMail for example to display your personal folders and shared folders in one account." ) );
00905   // button to reload
00906   QToolButton* button = new QToolButton( box );
00907   button->setAutoRaise(true);
00908   button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
00909   button->setFixedSize( 22, 22 );
00910   button->setIconSet(
00911       KGlobal::iconLoader()->loadIconSet( "reload", KIcon::Small, 0 ) );
00912   connect( button, SIGNAL(clicked()), this, SLOT(slotReloadNamespaces()) );
00913   QWhatsThis::add( button,
00914       i18n("Reload the namespaces from the server. This overwrites any changes.") );
00915   grid->addWidget( box, row, 0 );
00916 
00917   // grid with label, namespace list and edit button
00918   QGrid* listbox = new QGrid( 3, page1 );
00919   label = new QLabel( i18n("Personal"), listbox );
00920   QWhatsThis::add( label, i18n( "Personal namespaces include your personal folders." ) );
00921   mImap.personalNS = new KLineEdit( listbox );
00922   mImap.personalNS->setReadOnly( true );
00923   mImap.editPNS = new QToolButton( listbox );
00924   mImap.editPNS->setIconSet(
00925       KGlobal::iconLoader()->loadIconSet( "edit", KIcon::Small, 0 ) );
00926   mImap.editPNS->setAutoRaise( true );
00927   mImap.editPNS->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
00928   mImap.editPNS->setFixedSize( 22, 22 );
00929   connect( mImap.editPNS, SIGNAL(clicked()), this, SLOT(slotEditPersonalNamespace()) );
00930 
00931   label = new QLabel( i18n("Other Users"), listbox );
00932   QWhatsThis::add( label, i18n( "These namespaces include the folders of other users." ) );
00933   mImap.otherUsersNS = new KLineEdit( listbox );
00934   mImap.otherUsersNS->setReadOnly( true );
00935   mImap.editONS = new QToolButton( listbox );
00936   mImap.editONS->setIconSet(
00937       KGlobal::iconLoader()->loadIconSet( "edit", KIcon::Small, 0 ) );
00938   mImap.editONS->setAutoRaise( true );
00939   mImap.editONS->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
00940   mImap.editONS->setFixedSize( 22, 22 );
00941   connect( mImap.editONS, SIGNAL(clicked()), this, SLOT(slotEditOtherUsersNamespace()) );
00942 
00943   label = new QLabel( i18n("Shared"), listbox );
00944   QWhatsThis::add( label, i18n( "These namespaces include the shared folders." ) );
00945   mImap.sharedNS = new KLineEdit( listbox );
00946   mImap.sharedNS->setReadOnly( true );
00947   mImap.editSNS = new QToolButton( listbox );
00948   mImap.editSNS->setIconSet(
00949       KGlobal::iconLoader()->loadIconSet( "edit", KIcon::Small, 0 ) );
00950   mImap.editSNS->setAutoRaise( true );
00951   mImap.editSNS->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
00952   mImap.editSNS->setFixedSize( 22, 22 );
00953   connect( mImap.editSNS, SIGNAL(clicked()), this, SLOT(slotEditSharedNamespace()) );
00954 
00955   label->setBuddy( listbox );
00956   grid->addWidget( listbox, row, 1 );
00957 
00958   ++row;
00959   mImap.storePasswordCheck =
00960     new QCheckBox( i18n("Sto&re IMAP password"), page1 );
00961   QWhatsThis::add( mImap.storePasswordCheck,
00962                    i18n("Check this option to have KMail store "
00963                    "the password.\nIf KWallet is available "
00964                    "the password will be stored there which is considered "
00965                    "safe.\nHowever, if KWallet is not available, "
00966                    "the password will be stored in KMail's configuration "
00967                    "file. The password is stored in an "
00968                    "obfuscated format, but should not be "
00969                    "considered secure from decryption efforts "
00970                    "if access to the configuration file is obtained.") );
00971   grid->addMultiCellWidget( mImap.storePasswordCheck, row, row, 0, 1 );
00972 
00973   if( !connected ) {
00974     ++row;
00975     mImap.autoExpungeCheck =
00976       new QCheckBox( i18n("Automaticall&y compact folders (expunges deleted messages)"), page1);
00977     grid->addMultiCellWidget( mImap.autoExpungeCheck, row, row, 0, 1 );
00978   }
00979 
00980   ++row;
00981   mImap.hiddenFoldersCheck = new QCheckBox( i18n("Sho&w hidden folders"), page1);
00982   grid->addMultiCellWidget( mImap.hiddenFoldersCheck, row, row, 0, 1 );
00983 
00984 
00985   ++row;
00986   mImap.subscribedFoldersCheck = new QCheckBox(
00987     i18n("Show only s&ubscribed folders"), page1);
00988   grid->addMultiCellWidget( mImap.subscribedFoldersCheck, row, row, 0, 1 );
00989 
00990   ++row;
00991   mImap.locallySubscribedFoldersCheck = new QCheckBox(
00992     i18n("Show only &locally subscribed folders"), page1);
00993   grid->addMultiCellWidget( mImap.locallySubscribedFoldersCheck, row, row, 0, 1 );
00994 
00995   if ( !connected ) {
00996     // not implemented for disconnected yet
00997     ++row;
00998     mImap.loadOnDemandCheck = new QCheckBox(
00999         i18n("Load attach&ments on demand"), page1);
01000     QWhatsThis::add( mImap.loadOnDemandCheck,
01001         i18n("Activate this to load attachments not automatically when you select the email but only when you click on the attachment. This way also big emails are shown instantly.") );
01002     grid->addMultiCellWidget( mImap.loadOnDemandCheck, row, row, 0, 1 );
01003   }
01004 
01005   if ( !connected ) {
01006     // not implemented for disconnected yet
01007     ++row;
01008     mImap.listOnlyOpenCheck = new QCheckBox(
01009         i18n("List only open folders"), page1);
01010     QWhatsThis::add( mImap.listOnlyOpenCheck,
01011         i18n("Only folders that are open (expanded) in the folder tree are checked for subfolders. Use this if there are many folders on the server.") );
01012     grid->addMultiCellWidget( mImap.listOnlyOpenCheck, row, row, 0, 1 );
01013   }
01014 
01015 #if 0
01016   ++row;
01017   QHBox* resourceHB = new QHBox( page1 );
01018   resourceHB->setSpacing( 11 );
01019   mImap.resourceCheck =
01020       new QCheckBox( i18n( "Account for semiautomatic resource handling" ), resourceHB );
01021   mImap.resourceClearButton =
01022       new QPushButton( i18n( "Clear" ), resourceHB );
01023   mImap.resourceClearButton->setEnabled( false );
01024   connect( mImap.resourceCheck, SIGNAL( toggled(bool) ),
01025            mImap.resourceClearButton, SLOT( setEnabled(bool) ) );
01026   QWhatsThis::add( mImap.resourceClearButton,
01027                    i18n( "Delete all allocations for the resource represented by this account." ) );
01028   connect( mImap.resourceClearButton, SIGNAL( clicked() ),
01029            this, SLOT( slotClearResourceAllocations() ) );
01030   mImap.resourceClearPastButton =
01031       new QPushButton( i18n( "Clear Past" ), resourceHB );
01032   mImap.resourceClearPastButton->setEnabled( false );
01033   connect( mImap.resourceCheck, SIGNAL( toggled(bool) ),
01034            mImap.resourceClearPastButton, SLOT( setEnabled(bool) ) );
01035   QWhatsThis::add( mImap.resourceClearPastButton,
01036                    i18n( "Delete all outdated allocations for the resource represented by this account." ) );
01037   connect( mImap.resourceClearPastButton, SIGNAL( clicked() ),
01038            this, SLOT( slotClearPastResourceAllocations() ) );
01039   grid->addMultiCellWidget( resourceHB, row, row, 0, 2 );
01040 #endif
01041 
01042   ++row;
01043   mImap.includeInCheck =
01044     new QCheckBox( i18n("Include in manual mail chec&k"), page1 );
01045   grid->addMultiCellWidget( mImap.includeInCheck, row, row, 0, 1 );
01046 
01047   ++row;
01048   mImap.intervalCheck =
01049     new QCheckBox( i18n("Enable &interval mail checking"), page1 );
01050   grid->addMultiCellWidget( mImap.intervalCheck, row, row, 0, 2 );
01051   connect( mImap.intervalCheck, SIGNAL(toggled(bool)),
01052        this, SLOT(slotEnableImapInterval(bool)) );
01053   ++row;
01054   mImap.intervalLabel = new QLabel( i18n("Check inter&val:"), page1 );
01055   grid->addWidget( mImap.intervalLabel, row, 0 );
01056   mImap.intervalSpin = new KIntNumInput( page1 );
01057   mImap.intervalSpin->setRange( GlobalSettings::minimumCheckInterval(), 60, 1, false );
01058   mImap.intervalSpin->setValue( defaultmailcheckintervalmin );
01059   mImap.intervalSpin->setSuffix( i18n( " min" ) );
01060   mImap.intervalLabel->setBuddy( mImap.intervalSpin );
01061   grid->addWidget( mImap.intervalSpin, row, 1 );
01062 
01063   ++row;
01064   label = new QLabel( i18n("&Trash folder:"), page1 );
01065   grid->addWidget( label, row, 0 );
01066   mImap.trashCombo = new FolderRequester( page1,
01067       kmkernel->getKMMainWidget()->folderTree() );
01068   mImap.trashCombo->setShowOutbox( false );
01069   label->setBuddy( mImap.trashCombo );
01070   grid->addWidget( mImap.trashCombo, row, 1 );
01071 
01072   ++row;
01073   mImap.identityLabel = new QLabel( i18n("Identity:"), page1 );
01074   grid->addWidget( mImap.identityLabel, row, 0 );
01075   mImap.identityCombo = new KPIM::IdentityCombo(kmkernel->identityManager(), page1 );
01076   mImap.identityLabel->setBuddy( mImap.identityCombo );
01077   grid->addWidget( mImap.identityCombo, row, 1 );
01078 
01079   QWidget *page2 = new QWidget( tabWidget );
01080   tabWidget->addTab( page2, i18n("S&ecurity") );
01081   QVBoxLayout *vlay = new QVBoxLayout( page2, marginHint(), spacingHint() );
01082 
01083   vlay->addSpacing( KDialog::spacingHint() );
01084 
01085   QHBoxLayout *buttonLay = new QHBoxLayout( vlay );
01086   mImap.checkCapabilities =
01087     new QPushButton( i18n("Check &What the Server Supports"), page2 );
01088   connect(mImap.checkCapabilities, SIGNAL(clicked()),
01089     SLOT(slotCheckImapCapabilities()));
01090   buttonLay->addStretch();
01091   buttonLay->addWidget( mImap.checkCapabilities );
01092   buttonLay->addStretch();
01093 
01094   vlay->addSpacing( KDialog::spacingHint() );
01095 
01096   mImap.encryptionGroup = new QButtonGroup( 1, Qt::Horizontal,
01097     i18n("Encryption"), page2 );
01098   mImap.encryptionNone =
01099     new QRadioButton( i18n("&None"), mImap.encryptionGroup );
01100   mImap.encryptionSSL =
01101     new QRadioButton( i18n("Use &SSL for secure mail download"),
01102     mImap.encryptionGroup );
01103   mImap.encryptionTLS =
01104     new QRadioButton( i18n("Use &TLS for secure mail download"),
01105     mImap.encryptionGroup );
01106   connect(mImap.encryptionGroup, SIGNAL(clicked(int)),
01107     SLOT(slotImapEncryptionChanged(int)));
01108   vlay->addWidget( mImap.encryptionGroup );
01109 
01110   mImap.authGroup = new QButtonGroup( 1, Qt::Horizontal,
01111     i18n("Authentication Method"), page2 );
01112   mImap.authUser = new QRadioButton( i18n("Clear te&xt"), mImap.authGroup );
01113   mImap.authLogin = new QRadioButton( i18n("Please translate this "
01114     "authentication method only if you have a good reason", "&LOGIN"),
01115     mImap.authGroup );
01116   mImap.authPlain = new QRadioButton( i18n("Please translate this "
01117     "authentication method only if you have a good reason", "&PLAIN"),
01118      mImap.authGroup );
01119   mImap.authCramMd5 = new QRadioButton( i18n("CRAM-MD&5"), mImap.authGroup );
01120   mImap.authDigestMd5 = new QRadioButton( i18n("&DIGEST-MD5"), mImap.authGroup );
01121   mImap.authNTLM = new QRadioButton( i18n("&NTLM"), mImap.authGroup );
01122   mImap.authGSSAPI = new QRadioButton( i18n("&GSSAPI"), mImap.authGroup );
01123   mImap.authAnonymous = new QRadioButton( i18n("&Anonymous"), mImap.authGroup );
01124   vlay->addWidget( mImap.authGroup );
01125 
01126   vlay->addStretch();
01127 
01128   // TODO (marc/bo): Test this
01129   mSieveConfigEditor = new SieveConfigEditor( tabWidget );
01130   mSieveConfigEditor->layout()->setMargin( KDialog::marginHint() );
01131   tabWidget->addTab( mSieveConfigEditor, i18n("&Filtering") );
01132 
01133   connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()));
01134 }
01135 
01136 
01137 void AccountDialog::setupSettings()
01138 {
01139   QComboBox *folderCombo = 0;
01140   int interval = mAccount->checkInterval();
01141 
01142   QString accountType = mAccount->type();
01143   if( accountType == "local" )
01144   {
01145     ProcmailRCParser procmailrcParser;
01146     KMAcctLocal *acctLocal = dynamic_cast<KMAcctLocal*>(mAccount);
01147 
01148     if ( acctLocal->location().isEmpty() )
01149         acctLocal->setLocation( procmailrcParser.getSpoolFilesList().first() );
01150     else
01151         mLocal.locationEdit->insertItem( acctLocal->location() );
01152 
01153     if ( acctLocal->procmailLockFileName().isEmpty() )
01154         acctLocal->setProcmailLockFileName( procmailrcParser.getLockFilesList().first() );
01155     else
01156         mLocal.procmailLockFileName->insertItem( acctLocal->procmailLockFileName() );
01157 
01158     mLocal.nameEdit->setText( mAccount->name() );
01159     mLocal.nameEdit->setFocus();
01160     mLocal.locationEdit->setEditText( acctLocal->location() );
01161     if (acctLocal->lockType() == mutt_dotlock)
01162       mLocal.lockMutt->setChecked(true);
01163     else if (acctLocal->lockType() == mutt_dotlock_privileged)
01164       mLocal.lockMuttPriv->setChecked(true);
01165     else if (acctLocal->lockType() == procmail_lockfile) {
01166       mLocal.lockProcmail->setChecked(true);
01167       mLocal.procmailLockFileName->setEditText(acctLocal->procmailLockFileName());
01168     } else if (acctLocal->lockType() == FCNTL)
01169       mLocal.lockFcntl->setChecked(true);
01170     else if (acctLocal->lockType() == lock_none)
01171       mLocal.lockNone->setChecked(true);
01172 
01173     if ( interval <= 0 ) mLocal.intervalSpin->setValue( defaultmailcheckintervalmin );
01174     else mLocal.intervalSpin->setValue( interval );
01175     mLocal.intervalCheck->setChecked( interval >= 1 );
01176 #if 0
01177     mLocal.resourceCheck->setChecked( mAccount->resource() );
01178 #endif
01179     mLocal.includeInCheck->setChecked( !mAccount->checkExclude() );
01180     mLocal.precommand->setText( mAccount->precommand() );
01181 
01182     slotEnableLocalInterval( interval >= 1 );
01183     folderCombo = mLocal.folderCombo;
01184     mLocal.identityCombo-> setCurrentIdentity( mAccount->identityId() );
01185   }
01186   else if( accountType == "pop" )
01187   {
01188     PopAccount &ap = *(PopAccount*)mAccount;
01189     mPop.nameEdit->setText( mAccount->name() );
01190     mPop.nameEdit->setFocus();
01191     mPop.loginEdit->setText( ap.login() );
01192     mPop.passwordEdit->setText( ap.passwd());
01193     mPop.hostEdit->setText( ap.host() );
01194     mPop.portEdit->setText( QString("%1").arg( ap.port() ) );
01195     mPop.usePipeliningCheck->setChecked( ap.usePipelining() );
01196     mPop.storePasswordCheck->setChecked( ap.storePasswd() );
01197     mPop.leaveOnServerCheck->setChecked( ap.leaveOnServer() );
01198     mPop.leaveOnServerDaysCheck->setEnabled( ap.leaveOnServer() );
01199     mPop.leaveOnServerDaysCheck->setChecked( ap.leaveOnServerDays() >= 1 );
01200     mPop.leaveOnServerDaysSpin->setValue( ap.leaveOnServerDays() >= 1 ?
01201                                             ap.leaveOnServerDays() : 7 );
01202     mPop.leaveOnServerCountCheck->setEnabled( ap.leaveOnServer() );
01203     mPop.leaveOnServerCountCheck->setChecked( ap.leaveOnServerCount() >= 1 );
01204     mPop.leaveOnServerCountSpin->setValue( ap.leaveOnServerCount() >= 1 ?
01205                                             ap.leaveOnServerCount() : 100 );
01206     mPop.leaveOnServerSizeCheck->setEnabled( ap.leaveOnServer() );
01207     mPop.leaveOnServerSizeCheck->setChecked( ap.leaveOnServerSize() >= 1 );
01208     mPop.leaveOnServerSizeSpin->setValue( ap.leaveOnServerSize() >= 1 ?
01209                                             ap.leaveOnServerSize() : 10 );
01210     mPop.filterOnServerCheck->setChecked( ap.filterOnServer() );
01211     mPop.filterOnServerSizeSpin->setValue( ap.filterOnServerCheckSize() );
01212     mPop.intervalCheck->setChecked( interval >= 1 );
01213     if ( interval <= 0 ) mPop.intervalSpin->setValue( defaultmailcheckintervalmin );
01214     else mPop.intervalSpin->setValue( interval );
01215 #if 0
01216     mPop.resourceCheck->setChecked( mAccount->resource() );
01217 #endif
01218     mPop.includeInCheck->setChecked( !mAccount->checkExclude() );
01219     mPop.precommand->setText( ap.precommand() );
01220     mPop.identityCombo-> setCurrentIdentity( mAccount->identityId() );
01221     if (ap.useSSL())
01222       mPop.encryptionSSL->setChecked( true );
01223     else if (ap.useTLS())
01224       mPop.encryptionTLS->setChecked( true );
01225     else mPop.encryptionNone->setChecked( true );
01226     if (ap.auth() == "LOGIN")
01227       mPop.authLogin->setChecked( true );
01228     else if (ap.auth() == "PLAIN")
01229       mPop.authPlain->setChecked( true );
01230     else if (ap.auth() == "CRAM-MD5")
01231       mPop.authCRAM_MD5->setChecked( true );
01232     else if (ap.auth() == "DIGEST-MD5")
01233       mPop.authDigestMd5->setChecked( true );
01234     else if (ap.auth() == "NTLM")
01235       mPop.authNTLM->setChecked( true );
01236     else if (ap.auth() == "GSSAPI")
01237       mPop.authGSSAPI->setChecked( true );
01238     else if (ap.auth() == "APOP")
01239       mPop.authAPOP->setChecked( true );
01240     else mPop.authUser->setChecked( true );
01241 
01242     slotEnableLeaveOnServerDays( mPop.leaveOnServerDaysCheck->isEnabled() ?
01243                                    ap.leaveOnServerDays() >= 1 : 0);
01244     slotEnableLeaveOnServerCount( mPop.leaveOnServerCountCheck->isEnabled() ?
01245                                     ap.leaveOnServerCount() >= 1 : 0);
01246     slotEnableLeaveOnServerSize( mPop.leaveOnServerSizeCheck->isEnabled() ?
01247                                     ap.leaveOnServerSize() >= 1 : 0);
01248     slotEnablePopInterval( interval >= 1 );
01249     folderCombo = mPop.folderCombo;
01250   }
01251   else if( accountType == "imap" )
01252   {
01253     KMAcctImap &ai = *(KMAcctImap*)mAccount;
01254     mImap.nameEdit->setText( mAccount->name() );
01255     mImap.nameEdit->setFocus();
01256     mImap.loginEdit->setText( ai.login() );
01257     mImap.passwordEdit->setText( ai.passwd());
01258     mImap.hostEdit->setText( ai.host() );
01259     mImap.portEdit->setText( QString("%1").arg( ai.port() ) );
01260     mImap.autoExpungeCheck->setChecked( ai.autoExpunge() );
01261     mImap.hiddenFoldersCheck->setChecked( ai.hiddenFolders() );
01262     mImap.subscribedFoldersCheck->setChecked( ai.onlySubscribedFolders() );
01263     mImap.locallySubscribedFoldersCheck->setChecked( ai.onlyLocallySubscribedFolders() );
01264     mImap.loadOnDemandCheck->setChecked( ai.loadOnDemand() );
01265     mImap.listOnlyOpenCheck->setChecked( ai.listOnlyOpenFolders() );
01266     mImap.storePasswordCheck->setChecked( ai.storePasswd() );
01267 #if 0
01268     mImap.resourceCheck->setChecked( ai.resource() );
01269 #endif
01270     mImap.includeInCheck->setChecked( !ai.checkExclude() );
01271     mImap.intervalCheck->setChecked( interval >= 1 );
01272     if ( interval <= 0 ) mImap.intervalSpin->setValue( defaultmailcheckintervalmin );
01273     else mImap.intervalSpin->setValue( interval );
01274     QString trashfolder = ai.trash();
01275     if (trashfolder.isEmpty())
01276       trashfolder = kmkernel->trashFolder()->idString();
01277     mImap.trashCombo->setFolder( trashfolder );
01278     slotEnableImapInterval( interval >= 1 );
01279     mImap.identityCombo-> setCurrentIdentity( mAccount->identityId() );
01280     //mImap.identityCombo->insertStringList( kmkernel->identityManager()->shadowIdentities() );
01281     if (ai.useSSL())
01282       mImap.encryptionSSL->setChecked( true );
01283     else if (ai.useTLS())
01284       mImap.encryptionTLS->setChecked( true );
01285     else mImap.encryptionNone->setChecked( true );
01286     if (ai.auth() == "CRAM-MD5")
01287       mImap.authCramMd5->setChecked( true );
01288     else if (ai.auth() == "DIGEST-MD5")
01289       mImap.authDigestMd5->setChecked( true );
01290     else if (ai.auth() == "NTLM")
01291       mImap.authNTLM->setChecked( true );
01292     else if (ai.auth() == "GSSAPI")
01293       mImap.authGSSAPI->setChecked( true );
01294     else if (ai.auth() == "ANONYMOUS")
01295       mImap.authAnonymous->setChecked( true );
01296     else if (ai.auth() == "PLAIN")
01297       mImap.authPlain->setChecked( true );
01298     else if (ai.auth() == "LOGIN")
01299       mImap.authLogin->setChecked( true );
01300     else mImap.authUser->setChecked( true );
01301     if ( mSieveConfigEditor )
01302       mSieveConfigEditor->setConfig( ai.sieveConfig() );
01303   }
01304   else if( accountType == "cachedimap" )
01305   {
01306     KMAcctCachedImap &ai = *(KMAcctCachedImap*)mAccount;
01307     mImap.nameEdit->setText( mAccount->name() );
01308     mImap.nameEdit->setFocus();
01309     mImap.loginEdit->setText( ai.login() );
01310     mImap.passwordEdit->setText( ai.passwd());
01311     mImap.hostEdit->setText( ai.host() );
01312     mImap.portEdit->setText( QString("%1").arg( ai.port() ) );
01313 #if 0
01314     mImap.resourceCheck->setChecked( ai.resource() );
01315 #endif
01316     mImap.hiddenFoldersCheck->setChecked( ai.hiddenFolders() );
01317     mImap.subscribedFoldersCheck->setChecked( ai.onlySubscribedFolders() );
01318     mImap.locallySubscribedFoldersCheck->setChecked( ai.onlyLocallySubscribedFolders() );
01319     mImap.storePasswordCheck->setChecked( ai.storePasswd() );
01320     mImap.intervalCheck->setChecked( interval >= 1 );
01321     if ( interval <= 0 ) mImap.intervalSpin->setValue( defaultmailcheckintervalmin );
01322     else mImap.intervalSpin->setValue( interval );
01323     mImap.includeInCheck->setChecked( !ai.checkExclude() );
01324     QString trashfolder = ai.trash();
01325     if (trashfolder.isEmpty())
01326       trashfolder = kmkernel->trashFolder()->idString();
01327     mImap.trashCombo->setFolder( trashfolder );
01328     slotEnableImapInterval( interval >= 1 );
01329     mImap.identityCombo-> setCurrentIdentity( mAccount->identityId() );
01330     //mImap.identityCombo->insertStringList( kmkernel->identityManager()->shadowIdentities() );
01331     if (ai.useSSL())
01332       mImap.encryptionSSL->setChecked( true );
01333     else if (ai.useTLS())
01334       mImap.encryptionTLS->setChecked( true );
01335     else mImap.encryptionNone->setChecked( true );
01336     if (ai.auth() == "CRAM-MD5")
01337       mImap.authCramMd5->setChecked( true );
01338     else if (ai.auth() == "DIGEST-MD5")
01339       mImap.authDigestMd5->setChecked( true );
01340     else if (ai.auth() == "GSSAPI")
01341       mImap.authGSSAPI->setChecked( true );
01342     else if (ai.auth() == "NTLM")
01343       mImap.authNTLM->setChecked( true );
01344     else if (ai.auth() == "ANONYMOUS")
01345       mImap.authAnonymous->setChecked( true );
01346     else if (ai.auth() == "PLAIN")
01347       mImap.authPlain->setChecked( true );
01348     else if (ai.auth() == "LOGIN")
01349       mImap.authLogin->setChecked( true );
01350     else mImap.authUser->setChecked( true );
01351     if ( mSieveConfigEditor )
01352       mSieveConfigEditor->setConfig( ai.sieveConfig() );
01353   }
01354   else if( accountType == "maildir" )
01355   {
01356     KMAcctMaildir *acctMaildir = dynamic_cast<KMAcctMaildir*>(mAccount);
01357 
01358     mMaildir.nameEdit->setText( mAccount->name() );
01359     mMaildir.nameEdit->setFocus();
01360     mMaildir.locationEdit->setEditText( acctMaildir->location() );
01361 
01362     if ( interval <= 0 ) mMaildir.intervalSpin->setValue( defaultmailcheckintervalmin );
01363     else mMaildir.intervalSpin->setValue( interval );
01364     mMaildir.intervalCheck->setChecked( interval >= 1 );
01365 #if 0
01366     mMaildir.resourceCheck->setChecked( mAccount->resource() );
01367 #endif
01368     mMaildir.includeInCheck->setChecked( !mAccount->checkExclude() );
01369     mMaildir.precommand->setText( mAccount->precommand() );
01370     mMaildir.identityCombo-> setCurrentIdentity( mAccount->identityId() );
01371     slotEnableMaildirInterval( interval >= 1 );
01372     folderCombo = mMaildir.folderCombo;
01373   }
01374   else // Unknown account type
01375     return;
01376 
01377   if ( accountType == "imap" || accountType == "cachedimap" )
01378   {
01379     // settings for imap in general
01380     ImapAccountBase &ai = *(ImapAccountBase*)mAccount;
01381     // namespaces
01382     if ( ( ai.namespaces().isEmpty() || ai.namespaceToDelimiter().isEmpty() ) &&
01383          !ai.login().isEmpty() && !ai.passwd().isEmpty() && !ai.host().isEmpty() )
01384     {
01385       slotReloadNamespaces();
01386     } else {
01387       slotSetupNamespaces( ai.namespacesWithDelimiter() );
01388     }
01389   }
01390 
01391   if (!folderCombo) return;
01392 
01393   KMFolderDir *fdir = (KMFolderDir*)&kmkernel->folderMgr()->dir();
01394   KMFolder *acctFolder = mAccount->folder();
01395   if( acctFolder == 0 )
01396   {
01397     acctFolder = (KMFolder*)fdir->first();
01398   }
01399   if( acctFolder == 0 )
01400   {
01401     folderCombo->insertItem( i18n("<none>") );
01402   }
01403   else
01404   {
01405     uint i = 0;
01406     int curIndex = -1;
01407     kmkernel->folderMgr()->createI18nFolderList(&mFolderNames, &mFolderList);
01408     while (i < mFolderNames.count())
01409     {
01410       QValueList<QGuardedPtr<KMFolder> >::Iterator it = mFolderList.at(i);
01411       KMFolder *folder = *it;
01412       if (folder->isSystemFolder())
01413       {
01414         mFolderList.remove(it);
01415         mFolderNames.remove(mFolderNames.at(i));
01416       } else {
01417         if (folder == acctFolder) curIndex = i;
01418         i++;
01419       }
01420     }
01421     mFolderNames.prepend(i18n("inbox"));
01422     mFolderList.prepend(kmkernel->inboxFolder());
01423     folderCombo->insertStringList(mFolderNames);
01424     folderCombo->setCurrentItem(curIndex + 1);
01425 
01426     // -sanders hack for startup users. Must investigate this properly
01427     if (folderCombo->count() == 0)
01428       folderCombo->insertItem( i18n("inbox") );
01429   }
01430 }
01431 
01432 void AccountDialog::slotLeaveOnServerClicked()
01433 {
01434   bool state = mPop.leaveOnServerCheck->isChecked();
01435   mPop.leaveOnServerDaysCheck->setEnabled( state );
01436   mPop.leaveOnServerCountCheck->setEnabled( state );
01437   mPop.leaveOnServerSizeCheck->setEnabled( state );
01438   if ( state ) {
01439     if ( mPop.leaveOnServerDaysCheck->isChecked() ) {
01440       slotEnableLeaveOnServerDays( state );
01441     }
01442     if ( mPop.leaveOnServerCountCheck->isChecked() ) {
01443       slotEnableLeaveOnServerCount( state );
01444     }
01445     if ( mPop.leaveOnServerSizeCheck->isChecked() ) {
01446       slotEnableLeaveOnServerSize( state );
01447     }
01448   } else {
01449     slotEnableLeaveOnServerDays( state );
01450     slotEnableLeaveOnServerCount( state );
01451     slotEnableLeaveOnServerSize( state );
01452   }
01453   if ( !( mCurCapa & UIDL ) && mPop.leaveOnServerCheck->isChecked() ) {
01454     KMessageBox::information( topLevelWidget(),
01455                               i18n("The server does not seem to support unique "
01456                                    "message numbers, but this is a "
01457                                    "requirement for leaving messages on the "
01458                                    "server.\n"
01459                                    "Since some servers do not correctly "
01460                                    "announce their capabilities you still "
01461                                    "have the possibility to turn leaving "
01462                                    "fetched messages on the server on.") );
01463   }
01464 }
01465 
01466 void AccountDialog::slotFilterOnServerClicked()
01467 {
01468   if ( !( mCurCapa & TOP ) && mPop.filterOnServerCheck->isChecked() ) {
01469     KMessageBox::information( topLevelWidget(),
01470                               i18n("The server does not seem to support "
01471                                    "fetching message headers, but this is a "
01472                                    "requirement for filtering messages on the "
01473                                    "server.\n"
01474                                    "Since some servers do not correctly "
01475                                    "announce their capabilities you still "
01476                                    "have the possibility to turn filtering "
01477                                    "messages on the server on.") );
01478   }
01479 }
01480 
01481 void AccountDialog::slotPipeliningClicked()
01482 {
01483   if (mPop.usePipeliningCheck->isChecked())
01484     KMessageBox::information( topLevelWidget(),
01485       i18n("Please note that this feature can cause some POP3 servers "
01486       "that do not support pipelining to send corrupted mail;\n"
01487       "this is configurable, though, because some servers support pipelining "
01488       "but do not announce their capabilities. To check whether your POP3 server "
01489       "announces pipelining support use the \"Check What the Server "
01490       "Supports\" button at the bottom of the dialog;\n"
01491       "if your server does not announce it, but you want more speed, then "
01492       "you should do some testing first by sending yourself a batch "
01493       "of mail and downloading it."), QString::null,
01494       "pipelining");
01495 }
01496 
01497 
01498 void AccountDialog::slotPopEncryptionChanged(int id)
01499 {
01500   kdDebug(5006) << "slotPopEncryptionChanged( " << id << " )" << endl;
01501   // adjust port
01502   if ( id == SSL || mPop.portEdit->text() == "995" )
01503     mPop.portEdit->setText( ( id == SSL ) ? "995" : "110" );
01504 
01505   // switch supported auth methods
01506   mCurCapa = ( id == TLS ) ? mCapaTLS
01507                            : ( id == SSL ) ? mCapaSSL
01508                                            : mCapaNormal;
01509   enablePopFeatures( mCurCapa );
01510   const QButton *old = mPop.authGroup->selected();
01511   if ( !old->isEnabled() )
01512     checkHighest( mPop.authGroup );
01513 }
01514 
01515 
01516 void AccountDialog::slotImapEncryptionChanged(int id)
01517 {
01518   kdDebug(5006) << "slotImapEncryptionChanged( " << id << " )" << endl;
01519   // adjust port
01520   if ( id == SSL || mImap.portEdit->text() == "993" )
01521     mImap.portEdit->setText( ( id == SSL ) ? "993" : "143" );
01522 
01523   // switch supported auth methods
01524   int authMethods = ( id == TLS ) ? mCapaTLS
01525                                   : ( id == SSL ) ? mCapaSSL
01526                                                   : mCapaNormal;
01527   enableImapAuthMethods( authMethods );
01528   QButton *old = mImap.authGroup->selected();
01529   if ( !old->isEnabled() )
01530     checkHighest( mImap.authGroup );
01531 }
01532 
01533 
01534 void AccountDialog::slotCheckPopCapabilities()
01535 {
01536   if ( mPop.hostEdit->text().isEmpty() || mPop.portEdit->text().isEmpty() )
01537   {
01538      KMessageBox::sorry( this, i18n( "Please specify a server and port on "
01539               "the General tab first." ) );
01540      return;
01541   }
01542   delete mServerTest;
01543   mServerTest = new KMServerTest(POP_PROTOCOL, mPop.hostEdit->text(),
01544     mPop.portEdit->text().toInt());
01545   connect( mServerTest, SIGNAL( capabilities( const QStringList &,
01546                                               const QStringList & ) ),
01547            this, SLOT( slotPopCapabilities( const QStringList &,
01548                                             const QStringList & ) ) );
01549   mPop.checkCapabilities->setEnabled(false);
01550 }
01551 
01552 
01553 void AccountDialog::slotCheckImapCapabilities()
01554 {
01555   if ( mImap.hostEdit->text().isEmpty() || mImap.portEdit->text().isEmpty() )
01556   {
01557      KMessageBox::sorry( this, i18n( "Please specify a server and port on "
01558               "the General tab first." ) );
01559      return;
01560   }
01561   delete mServerTest;
01562   mServerTest = new KMServerTest(IMAP_PROTOCOL, mImap.hostEdit->text(),
01563     mImap.portEdit->text().toInt());
01564   connect( mServerTest, SIGNAL( capabilities( const QStringList &,
01565                                               const QStringList & ) ),
01566            this, SLOT( slotImapCapabilities( const QStringList &,
01567                                              const QStringList & ) ) );
01568   mImap.checkCapabilities->setEnabled(false);
01569 }
01570 
01571 
01572 unsigned int AccountDialog::popCapabilitiesFromStringList( const QStringList & l )
01573 {
01574   unsigned int capa = 0;
01575   kdDebug( 5006 ) << k_funcinfo << l << endl;
01576   for ( QStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
01577     QString cur = (*it).upper();
01578     if ( cur == "PLAIN" )
01579       capa |= Plain;
01580     else if ( cur == "LOGIN" )
01581       capa |= Login;
01582     else if ( cur == "CRAM-MD5" )
01583       capa |= CRAM_MD5;
01584     else if ( cur == "DIGEST-MD5" )
01585       capa |= Digest_MD5;
01586     else if ( cur == "NTLM" )
01587       capa |= NTLM;
01588     else if ( cur == "GSSAPI" )
01589       capa |= GSSAPI;
01590     else if ( cur == "APOP" )
01591       capa |= APOP;
01592     else if ( cur == "PIPELINING" )
01593       capa |= Pipelining;
01594     else if ( cur == "TOP" )
01595       capa |= TOP;
01596     else if ( cur == "UIDL" )
01597       capa |= UIDL;
01598     else if ( cur == "STLS" )
01599       capa |= STLS;
01600   }
01601   return capa;
01602 }
01603 
01604 
01605 void AccountDialog::slotPopCapabilities( const QStringList & capaNormal,
01606                                          const QStringList & capaSSL )
01607 {
01608   mPop.checkCapabilities->setEnabled( true );
01609   mCapaNormal = popCapabilitiesFromStringList( capaNormal );
01610   if ( mCapaNormal & STLS )
01611     mCapaTLS = mCapaNormal;
01612   else
01613     mCapaTLS = 0;
01614   mCapaSSL = popCapabilitiesFromStringList( capaSSL );
01615   kdDebug(5006) << "mCapaNormal = " << mCapaNormal
01616                 << "; mCapaSSL = " << mCapaSSL
01617                 << "; mCapaTLS = " << mCapaTLS << endl;
01618   mPop.encryptionNone->setEnabled( !capaNormal.isEmpty() );
01619   mPop.encryptionSSL->setEnabled( !capaSSL.isEmpty() );
01620   mPop.encryptionTLS->setEnabled( mCapaTLS != 0 );
01621   checkHighest( mPop.encryptionGroup );
01622   delete mServerTest;
01623   mServerTest = 0;
01624 }
01625 
01626 
01627 void AccountDialog::enablePopFeatures( unsigned int capa )
01628 {
01629   kdDebug(5006) << "enablePopFeatures( " << capa << " )" << endl;
01630   mPop.authPlain->setEnabled( capa & Plain );
01631   mPop.authLogin->setEnabled( capa & Login );
01632   mPop.authCRAM_MD5->setEnabled( capa & CRAM_MD5 );
01633   mPop.authDigestMd5->setEnabled( capa & Digest_MD5 );
01634   mPop.authNTLM->setEnabled( capa & NTLM );
01635   mPop.authGSSAPI->setEnabled( capa & GSSAPI );
01636   mPop.authAPOP->setEnabled( capa & APOP );
01637   if ( !( capa & Pipelining ) && mPop.usePipeliningCheck->isChecked() ) {
01638     mPop.usePipeliningCheck->setChecked( false );
01639     KMessageBox::information( topLevelWidget(),
01640                               i18n("The server does not seem to support "
01641                                    "pipelining; therefore, this option has "
01642                                    "been disabled.\n"
01643                                    "Since some servers do not correctly "
01644                                    "announce their capabilities you still "
01645                                    "have the possibility to turn pipelining "
01646                                    "on. But please note that this feature can "
01647                                    "cause some POP servers that do not "
01648                                    "support pipelining to send corrupt "
01649                                    "messages. So before using this feature "
01650                                    "with important mail you should first "
01651                                    "test it by sending yourself a larger "
01652                                    "number of test messages which you all "
01653                                    "download in one go from the POP "
01654                                    "server.") );
01655   }
01656   if ( !( capa & UIDL ) && mPop.leaveOnServerCheck->isChecked() ) {
01657     mPop.leaveOnServerCheck->setChecked( false );
01658     KMessageBox::information( topLevelWidget(),
01659                               i18n("The server does not seem to support unique "
01660                                    "message numbers, but this is a "
01661                                    "requirement for leaving messages on the "
01662                                    "server; therefore, this option has been "
01663                                    "disabled.\n"
01664                                    "Since some servers do not correctly "
01665                                    "announce their capabilities you still "
01666                                    "have the possibility to turn leaving "
01667                                    "fetched messages on the server on.") );
01668   }
01669   if ( !( capa & TOP ) && mPop.filterOnServerCheck->isChecked() ) {
01670     mPop.filterOnServerCheck->setChecked( false );
01671     KMessageBox::information( topLevelWidget(),
01672                               i18n("The server does not seem to support "
01673                                    "fetching message headers, but this is a "
01674                                    "requirement for filtering messages on the "
01675                                    "server; therefore, this option has been "
01676                                    "disabled.\n"
01677                                    "Since some servers do not correctly "
01678                                    "announce their capabilities you still "
01679                                    "have the possibility to turn filtering "
01680                                    "messages on the server on.") );
01681   }
01682 }
01683 
01684 
01685 unsigned int AccountDialog::imapCapabilitiesFromStringList( const QStringList & l )
01686 {
01687   unsigned int capa = 0;
01688   for ( QStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
01689     QString cur = (*it).upper();
01690     if ( cur == "AUTH=PLAIN" )
01691       capa |= Plain;
01692     else if ( cur == "AUTH=LOGIN" )
01693       capa |= Login;
01694     else if ( cur == "AUTH=CRAM-MD5" )
01695       capa |= CRAM_MD5;
01696     else if ( cur == "AUTH=DIGEST-MD5" )
01697       capa |= Digest_MD5;
01698     else if ( cur == "AUTH=NTLM" )
01699       capa |= NTLM;
01700     else if ( cur == "AUTH=GSSAPI" )
01701       capa |= GSSAPI;
01702     else if ( cur == "AUTH=ANONYMOUS" )
01703       capa |= Anonymous;
01704     else if ( cur == "STARTTLS" )
01705       capa |= STARTTLS;
01706   }
01707   return capa;
01708 }
01709 
01710 
01711 void AccountDialog::slotImapCapabilities( const QStringList & capaNormal,
01712                                           const QStringList & capaSSL )
01713 {
01714   mImap.checkCapabilities->setEnabled( true );
01715   mCapaNormal = imapCapabilitiesFromStringList( capaNormal );
01716   if ( mCapaNormal & STARTTLS )
01717     mCapaTLS = mCapaNormal;
01718   else
01719     mCapaTLS = 0;
01720   mCapaSSL = imapCapabilitiesFromStringList( capaSSL );
01721   kdDebug(5006) << "mCapaNormal = " << mCapaNormal
01722                 << "; mCapaSSL = " << mCapaSSL
01723                 << "; mCapaTLS = " << mCapaTLS << endl;
01724   mImap.encryptionNone->setEnabled( !capaNormal.isEmpty() );
01725   mImap.encryptionSSL->setEnabled( !capaSSL.isEmpty() );
01726   mImap.encryptionTLS->setEnabled( mCapaTLS != 0 );
01727   checkHighest( mImap.encryptionGroup );
01728   delete mServerTest;
01729   mServerTest = 0;
01730 }
01731 
01732 void AccountDialog::slotLeaveOnServerDaysChanged ( int value )
01733 {
01734   mPop.leaveOnServerDaysSpin->setSuffix( i18n(" day", " days", value) );
01735 }
01736 
01737 
01738 void AccountDialog::slotLeaveOnServerCountChanged ( int value )
01739 {
01740   mPop.leaveOnServerCountSpin->setSuffix( i18n(" message", " messages", value) );
01741 }
01742 
01743 
01744 void AccountDialog::slotFilterOnServerSizeChanged ( int value )
01745 {
01746   mPop.filterOnServerSizeSpin->setSuffix( i18n(" byte", " bytes", value) );
01747 }
01748 
01749 
01750 void AccountDialog::enableImapAuthMethods( unsigned int capa )
01751 {
01752   kdDebug(5006) << "enableImapAuthMethods( " << capa << " )" << endl;
01753   mImap.authPlain->setEnabled( capa & Plain );
01754   mImap.authLogin->setEnabled( capa & Login );
01755   mImap.authCramMd5->setEnabled( capa & CRAM_MD5 );
01756   mImap.authDigestMd5->setEnabled( capa & Digest_MD5 );
01757   mImap.authNTLM->setEnabled( capa & NTLM );
01758   mImap.authGSSAPI->setEnabled( capa & GSSAPI );
01759   mImap.authAnonymous->setEnabled( capa & Anonymous );
01760 }
01761 
01762 
01763 void AccountDialog::checkHighest( QButtonGroup *btnGroup )
01764 {
01765   kdDebug(5006) << "checkHighest( " << btnGroup << " )" << endl;
01766   for ( int i = btnGroup->count() - 1; i >= 0 ; --i ) {
01767     QButton * btn = btnGroup->find( i );
01768     if ( btn && btn->isEnabled() ) {
01769       btn->animateClick();
01770       return;
01771     }
01772   }
01773 }
01774 
01775 
01776 void AccountDialog::slotOk()
01777 {
01778   saveSettings();
01779   accept();
01780 }
01781 
01782 
01783 void AccountDialog::saveSettings()
01784 {
01785   QString accountType = mAccount->type();
01786   if( accountType == "local" )
01787   {
01788     KMAcctLocal *acctLocal = dynamic_cast<KMAcctLocal*>(mAccount);
01789 
01790     if (acctLocal) {
01791       mAccount->setName( mLocal.nameEdit->text() );
01792       acctLocal->setLocation( mLocal.locationEdit->currentText() );
01793       if (mLocal.lockMutt->isChecked())
01794         acctLocal->setLockType(mutt_dotlock);
01795       else if (mLocal.lockMuttPriv->isChecked())
01796         acctLocal->setLockType(mutt_dotlock_privileged);
01797       else if (mLocal.lockProcmail->isChecked()) {
01798         acctLocal->setLockType(procmail_lockfile);
01799         acctLocal->setProcmailLockFileName(mLocal.procmailLockFileName->currentText());
01800       }
01801       else if (mLocal.lockNone->isChecked())
01802         acctLocal->setLockType(lock_none);
01803       else acctLocal->setLockType(FCNTL);
01804     }
01805 
01806     mAccount->setCheckInterval( mLocal.intervalCheck->isChecked() ?
01807                  mLocal.intervalSpin->value() : 0 );
01808 #if 0
01809     mAccount->setResource( mLocal.resourceCheck->isChecked() );
01810 #endif
01811     mAccount->setCheckExclude( !mLocal.includeInCheck->isChecked() );
01812 
01813     mAccount->setPrecommand( mLocal.precommand->text() );
01814 
01815     mAccount->setFolder( *mFolderList.at(mLocal.folderCombo->currentItem()) );
01816 
01817     mAccount->setIdentityId( mLocal.identityCombo->currentIdentity() );
01818 
01819   }
01820   else if( accountType == "pop" )
01821   {
01822     mAccount->setName( mPop.nameEdit->text() );
01823     mAccount->setCheckInterval( mPop.intervalCheck->isChecked() ?
01824                  mPop.intervalSpin->value() : 0 );
01825 #if 0
01826     mAccount->setResource( mPop.resourceCheck->isChecked() );
01827 #endif
01828     mAccount->setCheckExclude( !mPop.includeInCheck->isChecked() );
01829 
01830     mAccount->setFolder( *mFolderList.at(mPop.folderCombo->currentItem()) );
01831 
01832     mAccount->setIdentityId( mPop.identityCombo->currentIdentity() );
01833 
01834     initAccountForConnect();
01835     PopAccount &epa = *(PopAccount*)mAccount;
01836     epa.setUsePipelining( mPop.usePipeliningCheck->isChecked() );
01837     epa.setLeaveOnServer( mPop.leaveOnServerCheck->isChecked() );
01838     epa.setLeaveOnServerDays( mPop.leaveOnServerCheck->isChecked() ?
01839                               ( mPop.leaveOnServerDaysCheck->isChecked() ?
01840                                 mPop.leaveOnServerDaysSpin->value() : -1 ) : 0);
01841     epa.setLeaveOnServerCount( mPop.leaveOnServerCheck->isChecked() ?
01842                                ( mPop.leaveOnServerCountCheck->isChecked() ?
01843                                  mPop.leaveOnServerCountSpin->value() : -1 ) : 0 );
01844     epa.setLeaveOnServerSize( mPop.leaveOnServerCheck->isChecked() ?
01845                               ( mPop.leaveOnServerSizeCheck->isChecked() ?
01846                                 mPop.leaveOnServerSizeSpin->value() : -1 ) : 0 );
01847     epa.setFilterOnServer( mPop.filterOnServerCheck->isChecked() );
01848     epa.setFilterOnServerCheckSize (mPop.filterOnServerSizeSpin->value() );
01849     epa.setPrecommand( mPop.precommand->text() );
01850 
01851   }
01852   else if( accountType == "imap" )
01853   {
01854     mAccount->setName( mImap.nameEdit->text() );
01855     mAccount->setCheckInterval( mImap.intervalCheck->isChecked() ?
01856                                 mImap.intervalSpin->value() : 0 );
01857     mAccount->setIdentityId( mImap.identityCombo->currentIdentity() );
01858 
01859 #if 0
01860     mAccount->setResource( mImap.resourceCheck->isChecked() );
01861 #endif
01862     mAccount->setCheckExclude( !mImap.includeInCheck->isChecked() );
01863     mAccount->setFolder( kmkernel->imapFolderMgr()->findById(mAccount->id()) );
01864 
01865     initAccountForConnect();
01866     KMAcctImap &epa = *(KMAcctImap*)mAccount;
01867     epa.setAutoExpunge( mImap.autoExpungeCheck->isChecked() );
01868     epa.setHiddenFolders( mImap.hiddenFoldersCheck->isChecked() );
01869     epa.setOnlySubscribedFolders( mImap.subscribedFoldersCheck->isChecked() );
01870     epa.setOnlyLocallySubscribedFolders( mImap.locallySubscribedFoldersCheck->isChecked() );
01871     epa.setLoadOnDemand( mImap.loadOnDemandCheck->isChecked() );
01872     epa.setListOnlyOpenFolders( mImap.listOnlyOpenCheck->isChecked() );
01873     KMFolder *t = mImap.trashCombo->folder();
01874     if ( t )
01875       epa.setTrash( mImap.trashCombo->folder()->idString() );
01876     else
01877       epa.setTrash( kmkernel->trashFolder()->idString() );
01878 #if 0
01879     epa.setResource( mImap.resourceCheck->isChecked() );
01880 #endif
01881     epa.setCheckExclude( !mImap.includeInCheck->isChecked() );
01882     if ( mSieveConfigEditor )
01883       epa.setSieveConfig( mSieveConfigEditor->config() );
01884   }
01885   else if( accountType == "cachedimap" )
01886   {
01887     mAccount->setName( mImap.nameEdit->text() );
01888     mAccount->setCheckInterval( mImap.intervalCheck->isChecked() ?
01889                                 mImap.intervalSpin->value() : 0 );
01890     mAccount->setIdentityId( mImap.identityCombo->currentIdentity() );
01891 
01892 #if 0
01893     mAccount->setResource( mImap.resourceCheck->isChecked() );
01894 #endif
01895     mAccount->setCheckExclude( !mImap.includeInCheck->isChecked() );
01896     //mAccount->setFolder( NULL );
01897     mAccount->setFolder( kmkernel->dimapFolderMgr()->findById(mAccount->id()) );
01898     //kdDebug(5006) << "account for folder " << mAccount->folder()->name() << endl;
01899 
01900     initAccountForConnect();
01901     KMAcctCachedImap &epa = *(KMAcctCachedImap*)mAccount;
01902     epa.setHiddenFolders( mImap.hiddenFoldersCheck->isChecked() );
01903     epa.setOnlySubscribedFolders( mImap.subscribedFoldersCheck->isChecked() );
01904     epa.setOnlyLocallySubscribedFolders( mImap.locallySubscribedFoldersCheck->isChecked() );
01905     epa.setStorePasswd( mImap.storePasswordCheck->isChecked() );
01906     epa.setPasswd( mImap.passwordEdit->text(), epa.storePasswd() );
01907     KMFolder *t = mImap.trashCombo->folder();
01908     if ( t )
01909       epa.setTrash( mImap.trashCombo->folder()->idString() );
01910     else
01911       epa.setTrash( kmkernel->trashFolder()->idString() );
01912 #if 0
01913     epa.setResource( mImap.resourceCheck->isChecked() );
01914 #endif
01915     epa.setCheckExclude( !mImap.includeInCheck->isChecked() );
01916     if ( mSieveConfigEditor )
01917       epa.setSieveConfig( mSieveConfigEditor->config() );
01918   }
01919   else if( accountType == "maildir" )
01920   {
01921     KMAcctMaildir *acctMaildir = dynamic_cast<KMAcctMaildir*>(mAccount);
01922 
01923     if (acctMaildir) {
01924         mAccount->setName( mMaildir.nameEdit->text() );
01925         acctMaildir->setLocation( mMaildir.locationEdit->currentText() );
01926 
01927         KMFolder *targetFolder = *mFolderList.at(mMaildir.folderCombo->currentItem());
01928         if ( targetFolder->location()  == acctMaildir->location() ) {
01929             /*
01930                Prevent data loss if the user sets the destination folder to be the same as the
01931                source account maildir folder by setting the target folder to the inbox.
01932                ### FIXME post 3.2: show dialog and let the user chose another target folder
01933             */
01934             targetFolder = kmkernel->inboxFolder();
01935         }
01936         mAccount->setFolder( targetFolder );
01937     }
01938     mAccount->setCheckInterval( mMaildir.intervalCheck->isChecked() ?
01939                  mMaildir.intervalSpin->value() : 0 );
01940 #if 0
01941     mAccount->setResource( mMaildir.resourceCheck->isChecked() );
01942 #endif
01943     mAccount->setCheckExclude( !mMaildir.includeInCheck->isChecked() );
01944 
01945     mAccount->setPrecommand( mMaildir.precommand->text() );
01946 
01947     mAccount->setIdentityId( mMaildir.identityCombo->currentIdentity() );
01948   }
01949 
01950   if ( accountType == "imap" || accountType == "cachedimap" )
01951   {
01952     // settings for imap in general
01953     ImapAccountBase &ai = *(ImapAccountBase*)mAccount;
01954     // namespace
01955     ImapAccountBase::nsMap map;
01956     ImapAccountBase::namespaceDelim delimMap;
01957     ImapAccountBase::nsDelimMap::Iterator it;
01958     ImapAccountBase::namespaceDelim::Iterator it2;
01959     for ( it = mImap.nsMap.begin(); it != mImap.nsMap.end(); ++it ) {
01960       QStringList list;
01961       for ( it2 = it.data().begin(); it2 != it.data().end(); ++it2 ) {
01962         list << it2.key();
01963         delimMap[it2.key()] = it2.data();
01964       }
01965       map[it.key()] = list;
01966     }
01967     ai.setNamespaces( map );
01968     ai.setNamespaceToDelimiter( delimMap );
01969   }
01970 
01971   kmkernel->acctMgr()->writeConfig( true );
01972   // get the new account and register the new destination folder
01973   // this is the target folder for local or pop accounts and the root folder
01974   // of the account for (d)imap
01975   KMAccount* newAcct = kmkernel->acctMgr()->find(mAccount->id());
01976   if (newAcct)
01977   {
01978     if( accountType == "local" ) {
01979       newAcct->setFolder( *mFolderList.at(mLocal.folderCombo->currentItem()), true );
01980     } else if ( accountType == "pop" ) {
01981       newAcct->setFolder( *mFolderList.at(mPop.folderCombo->currentItem()), true );
01982     } else if ( accountType == "maildir" ) {
01983       newAcct->setFolder( *mFolderList.at(mMaildir.folderCombo->currentItem()), true );
01984     } else if ( accountType == "imap" ) {
01985       newAcct->setFolder( kmkernel->imapFolderMgr()->findById(mAccount->id()), true );
01986     } else if ( accountType == "cachedimap" ) {
01987       newAcct->setFolder( kmkernel->dimapFolderMgr()->findById(mAccount->id()), true );
01988     }
01989   }
01990 }
01991 
01992 
01993 void AccountDialog::slotLocationChooser()
01994 {
01995   static QString directory( "/" );
01996 
01997   KFileDialog dialog( directory, QString::null, this, 0, true );
01998   dialog.setCaption( i18n("Choose Location") );
01999 
02000   bool result = dialog.exec();
02001   if( result == false )
02002   {
02003     return;
02004   }
02005 
02006   KURL url = dialog.selectedURL();
02007   if( url.isEmpty() )
02008   {
02009     return;
02010   }
02011   if( url.isLocalFile() == false )
02012   {
02013     KMessageBox::sorry( 0, i18n( "Only local files are currently supported." ) );
02014     return;
02015   }
02016 
02017   mLocal.locationEdit->setEditText( url.path() );
02018   directory = url.directory();
02019 }
02020 
02021 void AccountDialog::slotMaildirChooser()
02022 {
02023   static QString directory( "/" );
02024 
02025   QString dir = KFileDialog::getExistingDirectory(directory, this, i18n("Choose Location"));
02026 
02027   if( dir.isEmpty() )
02028     return;
02029 
02030   mMaildir.locationEdit->setEditText( dir );
02031   directory = dir;
02032 }
02033 
02034 void AccountDialog::slotEnableLeaveOnServerDays( bool state )
02035 {
02036   if ( state && !mPop.leaveOnServerDaysCheck->isEnabled()) return;
02037   mPop.leaveOnServerDaysSpin->setEnabled( state );
02038 }
02039 
02040 void AccountDialog::slotEnableLeaveOnServerCount( bool state )
02041 {
02042   if ( state && !mPop.leaveOnServerCountCheck->isEnabled()) return;
02043   mPop.leaveOnServerCountSpin->setEnabled( state );
02044   return;
02045 }
02046 
02047 void AccountDialog::slotEnableLeaveOnServerSize( bool state )
02048 {
02049   if ( state && !mPop.leaveOnServerSizeCheck->isEnabled()) return;
02050   mPop.leaveOnServerSizeSpin->setEnabled( state );
02051   return;
02052 }
02053 
02054 void AccountDialog::slotEnablePopInterval( bool state )
02055 {
02056   mPop.intervalSpin->setEnabled( state );
02057   mPop.intervalLabel->setEnabled( state );
02058 }
02059 
02060 void AccountDialog::slotEnableImapInterval( bool state )
02061 {
02062   mImap.intervalSpin->setEnabled( state );
02063   mImap.intervalLabel->setEnabled( state );
02064 }
02065 
02066 void AccountDialog::slotEnableLocalInterval( bool state )
02067 {
02068   mLocal.intervalSpin->setEnabled( state );
02069   mLocal.intervalLabel->setEnabled( state );
02070 }
02071 
02072 void AccountDialog::slotEnableMaildirInterval( bool state )
02073 {
02074   mMaildir.intervalSpin->setEnabled( state );
02075   mMaildir.intervalLabel->setEnabled( state );
02076 }
02077 
02078 void AccountDialog::slotFontChanged( void )
02079 {
02080   QString accountType = mAccount->type();
02081   if( accountType == "local" )
02082   {
02083     QFont titleFont( mLocal.titleLabel->font() );
02084     titleFont.setBold( true );
02085     mLocal.titleLabel->setFont(titleFont);
02086   }
02087   else if( accountType == "pop" )
02088   {
02089     QFont titleFont( mPop.titleLabel->font() );
02090     titleFont.setBold( true );
02091     mPop.titleLabel->setFont(titleFont);
02092   }
02093   else if( accountType == "imap" )
02094   {
02095     QFont titleFont( mImap.titleLabel->font() );
02096     titleFont.setBold( true );
02097     mImap.titleLabel->setFont(titleFont);
02098   }
02099 }
02100 
02101 #if 0
02102 void AccountDialog::slotClearResourceAllocations()
02103 {
02104     mAccount->clearIntervals();
02105 }
02106 
02107 
02108 void AccountDialog::slotClearPastResourceAllocations()
02109 {
02110     mAccount->clearOldIntervals();
02111 }
02112 #endif
02113 
02114 void AccountDialog::slotReloadNamespaces()
02115 {
02116   if ( mAccount->type() == "imap" || mAccount->type() == "cachedimap" )
02117   {
02118     initAccountForConnect();
02119     mImap.personalNS->setText( i18n("Fetching Namespaces...") );
02120     mImap.otherUsersNS->setText( QString::null );
02121     mImap.sharedNS->setText( QString::null );
02122     ImapAccountBase* ai = static_cast<ImapAccountBase*>( mAccount );
02123     connect( ai, SIGNAL( namespacesFetched( const ImapAccountBase::nsDelimMap& ) ),
02124         this, SLOT( slotSetupNamespaces( const ImapAccountBase::nsDelimMap& ) ) );
02125     connect( ai, SIGNAL( connectionResult(int, const QString&) ),
02126           this, SLOT( slotConnectionResult(int, const QString&) ) );
02127     ai->getNamespaces();
02128   }
02129 }
02130 
02131 void AccountDialog::slotConnectionResult( int errorCode, const QString& )
02132 {
02133   if ( errorCode > 0 ) {
02134     ImapAccountBase* ai = static_cast<ImapAccountBase*>( mAccount );
02135     disconnect( ai, SIGNAL( namespacesFetched( const ImapAccountBase::nsDelimMap& ) ),
02136         this, SLOT( slotSetupNamespaces( const ImapAccountBase::nsDelimMap& ) ) );
02137     disconnect( ai, SIGNAL( connectionResult(int, const QString&) ),
02138           this, SLOT( slotConnectionResult(int, const QString&) ) );
02139     mImap.personalNS->setText( QString::null );
02140   }
02141 }
02142 
02143 void AccountDialog::slotSetupNamespaces( const ImapAccountBase::nsDelimMap& map )
02144 {
02145   disconnect( this, SLOT( slotSetupNamespaces( const ImapAccountBase::nsDelimMap& ) ) );
02146   mImap.personalNS->setText( QString::null );
02147   mImap.otherUsersNS->setText( QString::null );
02148   mImap.sharedNS->setText( QString::null );
02149   mImap.nsMap = map;
02150 
02151   ImapAccountBase::namespaceDelim ns = map[ImapAccountBase::PersonalNS];
02152   ImapAccountBase::namespaceDelim::ConstIterator it;
02153   if ( !ns.isEmpty() ) {
02154     mImap.personalNS->setText( namespaceListToString( ns.keys() ) );
02155     mImap.editPNS->setEnabled( true );
02156   } else {
02157     mImap.editPNS->setEnabled( false );
02158   }
02159   ns = map[ImapAccountBase::OtherUsersNS];
02160   if ( !ns.isEmpty() ) {
02161     mImap.otherUsersNS->setText( namespaceListToString( ns.keys() ) );
02162     mImap.editONS->setEnabled( true );
02163   } else {
02164     mImap.editONS->setEnabled( false );
02165   }
02166   ns = map[ImapAccountBase::SharedNS];
02167   if ( !ns.isEmpty() ) {
02168     mImap.sharedNS->setText( namespaceListToString( ns.keys() ) );
02169     mImap.editSNS->setEnabled( true );
02170   } else {
02171     mImap.editSNS->setEnabled( false );
02172   }
02173 }
02174 
02175 const QString AccountDialog::namespaceListToString( const QStringList& list )
02176 {
02177   QStringList myList = list;
02178   for ( QStringList::Iterator it = myList.begin(); it != myList.end(); ++it ) {
02179     if ( (*it).isEmpty() ) {
02180       (*it) = "<" + i18n("Empty") + ">";
02181     }
02182   }
02183   return myList.join(",");
02184 }
02185 
02186 void AccountDialog::initAccountForConnect()
02187 {
02188   QString type = mAccount->type();
02189   if ( type == "local" )
02190     return;
02191 
02192   NetworkAccount &na = *(NetworkAccount*)mAccount;
02193 
02194   if ( type == "pop" ) {
02195     na.setHost( mPop.hostEdit->text().stripWhiteSpace() );
02196     na.setPort( mPop.portEdit->text().toInt() );
02197     na.setLogin( mPop.loginEdit->text().stripWhiteSpace() );
02198     na.setStorePasswd( mPop.storePasswordCheck->isChecked() );
02199     na.setPasswd( mPop.passwordEdit->text(), na.storePasswd() );
02200     na.setUseSSL( mPop.encryptionSSL->isChecked() );
02201     na.setUseTLS( mPop.encryptionTLS->isChecked() );
02202     if (mPop.authUser->isChecked())
02203       na.setAuth("USER");
02204     else if (mPop.authLogin->isChecked())
02205       na.setAuth("LOGIN");
02206     else if (mPop.authPlain->isChecked())
02207       na.setAuth("PLAIN");
02208     else if (mPop.authCRAM_MD5->isChecked())
02209       na.setAuth("CRAM-MD5");
02210     else if (mPop.authDigestMd5->isChecked())
02211       na.setAuth("DIGEST-MD5");
02212     else if (mPop.authNTLM->isChecked())
02213       na.setAuth("NTLM");
02214     else if (mPop.authGSSAPI->isChecked())
02215       na.setAuth("GSSAPI");
02216     else if (mPop.authAPOP->isChecked())
02217       na.setAuth("APOP");
02218     else na.setAuth("AUTO");
02219   }
02220   else if ( type == "imap" || type == "cachedimap" ) {
02221     na.setHost( mImap.hostEdit->text().stripWhiteSpace() );
02222     na.setPort( mImap.portEdit->text().toInt() );
02223     na.setLogin( mImap.loginEdit->text().stripWhiteSpace() );
02224     na.setStorePasswd( mImap.storePasswordCheck->isChecked() );
02225     na.setPasswd( mImap.passwordEdit->text(), na.storePasswd() );
02226     na.setUseSSL( mImap.encryptionSSL->isChecked() );
02227     na.setUseTLS( mImap.encryptionTLS->isChecked() );
02228     if (mImap.authCramMd5->isChecked())
02229       na.setAuth("CRAM-MD5");
02230     else if (mImap.authDigestMd5->isChecked())
02231       na.setAuth("DIGEST-MD5");
02232     else if (mImap.authNTLM->isChecked())
02233       na.setAuth("NTLM");
02234     else if (mImap.authGSSAPI->isChecked())
02235       na.setAuth("GSSAPI");
02236     else if (mImap.authAnonymous->isChecked())
02237       na.setAuth("ANONYMOUS");
02238     else if (mImap.authLogin->isChecked())
02239       na.setAuth("LOGIN");
02240     else if (mImap.authPlain->isChecked())
02241       na.setAuth("PLAIN");
02242     else na.setAuth("*");
02243   }
02244 }
02245 
02246 void AccountDialog::slotEditPersonalNamespace()
02247 {
02248   NamespaceEditDialog dialog( this, ImapAccountBase::PersonalNS, &mImap.nsMap );
02249   if ( dialog.exec() == QDialog::Accepted ) {
02250     slotSetupNamespaces( mImap.nsMap );
02251   }
02252 }
02253 
02254 void AccountDialog::slotEditOtherUsersNamespace()
02255 {
02256   NamespaceEditDialog dialog( this, ImapAccountBase::OtherUsersNS, &mImap.nsMap );
02257   if ( dialog.exec() == QDialog::Accepted ) {
02258     slotSetupNamespaces( mImap.nsMap );
02259   }
02260 }
02261 
02262 void AccountDialog::slotEditSharedNamespace()
02263 {
02264   NamespaceEditDialog dialog( this, ImapAccountBase::SharedNS, &mImap.nsMap );
02265   if ( dialog.exec() == QDialog::Accepted ) {
02266     slotSetupNamespaces( mImap.nsMap );
02267   }
02268 }
02269 
02270 NamespaceLineEdit::NamespaceLineEdit( QWidget* parent )
02271   : KLineEdit( parent )
02272 {
02273 }
02274 
02275 void NamespaceLineEdit::setText( const QString& text )
02276 {
02277   mLastText = text;
02278   KLineEdit::setText( text );
02279 }
02280 
02281 NamespaceEditDialog::NamespaceEditDialog( QWidget *parent,
02282     ImapAccountBase::imapNamespace type, ImapAccountBase::nsDelimMap* map )
02283   : KDialogBase( parent, "edit_namespace", false, QString::null,
02284       Ok|Cancel, Ok, true ), mType( type ), mNamespaceMap( map )
02285 {
02286   QVBox *page = makeVBoxMainWidget();
02287 
02288   QString ns;
02289   if ( mType == ImapAccountBase::PersonalNS ) {
02290     ns = i18n("Personal");
02291   } else if ( mType == ImapAccountBase::OtherUsersNS ) {
02292     ns = i18n("Other Users");
02293   } else {
02294     ns = i18n("Shared");
02295   }
02296   setCaption( i18n("Edit Namespace '%1'").arg(ns) );
02297   QGrid* grid = new QGrid( 2, page );
02298 
02299   mBg = new QButtonGroup( 0 );
02300   connect( mBg, SIGNAL( clicked(int) ), this, SLOT( slotRemoveEntry(int) ) );
02301   mDelimMap = mNamespaceMap->find( mType ).data();
02302   ImapAccountBase::namespaceDelim::Iterator it;
02303   for ( it = mDelimMap.begin(); it != mDelimMap.end(); ++it ) {
02304     NamespaceLineEdit* edit = new NamespaceLineEdit( grid );
02305     edit->setText( it.key() );
02306     QToolButton* button = new QToolButton( grid );
02307     button->setIconSet(
02308       KGlobal::iconLoader()->loadIconSet( "editdelete", KIcon::Small, 0 ) );
02309     button->setAutoRaise( true );
02310     button->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
02311     button->setFixedSize( 22, 22 );
02312     mLineEditMap[ mBg->insert( button ) ] = edit;
02313   }
02314 }
02315 
02316 void NamespaceEditDialog::slotRemoveEntry( int id )
02317 {
02318   if ( mLineEditMap.contains( id ) ) {
02319     // delete the lineedit and remove namespace from map
02320     NamespaceLineEdit* edit = mLineEditMap[id];
02321     mDelimMap.remove( edit->text() );
02322     if ( edit->isModified() ) {
02323       mDelimMap.remove( edit->lastText() );
02324     }
02325     mLineEditMap.remove( id );
02326     delete edit;
02327   }
02328   if ( mBg->find( id ) ) {
02329     // delete the button
02330     delete mBg->find( id );
02331   }
02332   adjustSize();
02333 }
02334 
02335 void NamespaceEditDialog::slotOk()
02336 {
02337   QMap<int, NamespaceLineEdit*>::Iterator it;
02338   for ( it = mLineEditMap.begin(); it != mLineEditMap.end(); ++it ) {
02339     NamespaceLineEdit* edit = it.data();
02340     if ( edit->isModified() ) {
02341       // register delimiter for new namespace
02342       mDelimMap[edit->text()] = mDelimMap[edit->lastText()];
02343       mDelimMap.remove( edit->lastText() );
02344     }
02345   }
02346   mNamespaceMap->replace( mType, mDelimMap );
02347   KDialogBase::slotOk();
02348 }
02349 
02350 } // namespace KMail
02351 
02352 #include "accountdialog.moc"