kmail Library API Documentation

accountdialog.cpp

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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  *
00019  */
00020 #include <config.h>
00021 
00022 #include "accountdialog.h"
00023 
00024 #include <qbuttongroup.h>
00025 #include <qcheckbox.h>
00026 #include <klineedit.h>
00027 #include <qlayout.h>
00028 #include <qtabwidget.h>
00029 #include <qradiobutton.h>
00030 #include <qvalidator.h>
00031 #include <qlabel.h>
00032 #include <qpushbutton.h>
00033 #include <qwhatsthis.h>
00034 #include <qhbox.h>
00035 
00036 #include <kfiledialog.h>
00037 #include <klocale.h>
00038 #include <kdebug.h>
00039 #include <kmessagebox.h>
00040 #include <knuminput.h>
00041 #include <kseparator.h>
00042 #include <kapplication.h>
00043 #include <kmessagebox.h>
00044 
00045 #include <netdb.h>
00046 #include <netinet/in.h>
00047 
00048 #include "sieveconfig.h"
00049 using KMail::SieveConfig;
00050 using KMail::SieveConfigEditor;
00051 #include "kmacctmaildir.h"
00052 #include "kmacctlocal.h"
00053 #include "kmacctmgr.h"
00054 #include "kmacctexppop.h"
00055 #include "kmacctimap.h"
00056 #include "kmacctcachedimap.h"
00057 #include "kmfoldermgr.h"
00058 #include "kmservertest.h"
00059 #include "protocols.h"
00060 #include "globalsettings.h"
00061 
00062 
00063 #include <cassert>
00064 #include <stdlib.h>
00065 
00066 #ifdef HAVE_PATHS_H
00067 #include <paths.h>  /* defines _PATH_MAILDIR */
00068 #endif
00069 
00070 #ifndef _PATH_MAILDIR
00071 #define _PATH_MAILDIR "/var/spool/mail"
00072 #endif
00073 
00074 class ProcmailRCParser
00075 {
00076 public:
00077   ProcmailRCParser(QString fileName = QString::null);
00078   ~ProcmailRCParser();
00079 
00080   QStringList getLockFilesList() const { return mLockFiles; }
00081   QStringList getSpoolFilesList() const { return mSpoolFiles; }
00082 
00083 protected:
00084   void processGlobalLock(const QString&);
00085   void processLocalLock(const QString&);
00086   void processVariableSetting(const QString&, int);
00087   QString expandVars(const QString&);
00088 
00089   QFile mProcmailrc;
00090   QTextStream *mStream;
00091   QStringList mLockFiles;
00092   QStringList mSpoolFiles;
00093   QAsciiDict<QString> mVars;
00094 };
00095 
00096 ProcmailRCParser::ProcmailRCParser(QString fname)
00097   : mProcmailrc(fname),
00098     mStream(new QTextStream(&mProcmailrc))
00099 {
00100   mVars.setAutoDelete(true);
00101 
00102   // predefined
00103   mVars.insert( "HOME", new QString( QDir::homeDirPath() ) );
00104 
00105   if( !fname || fname.isEmpty() ) {
00106     fname = QDir::homeDirPath() + "/.procmailrc";
00107     mProcmailrc.setName(fname);
00108   }
00109 
00110   QRegExp lockFileGlobal("^LOCKFILE=", true);
00111   QRegExp lockFileLocal("^:0", true);
00112 
00113   if(  mProcmailrc.open(IO_ReadOnly) ) {
00114 
00115     QString s;
00116 
00117     while( !mStream->eof() ) {
00118 
00119       s = mStream->readLine().stripWhiteSpace();
00120 
00121       if(  s[0] == '#' ) continue; // skip comments
00122 
00123       int commentPos = -1;
00124 
00125       if( (commentPos = s.find('#')) > -1 ) {
00126         // get rid of trailing comment
00127         s.truncate(commentPos);
00128         s = s.stripWhiteSpace();
00129       }
00130 
00131       if(  lockFileGlobal.search(s) != -1 ) {
00132         processGlobalLock(s);
00133       } else if( lockFileLocal.search(s) != -1 ) {
00134         processLocalLock(s);
00135       } else if( int i = s.find('=') ) {
00136         processVariableSetting(s,i);
00137       }
00138     }
00139 
00140   }
00141   QString default_Location = getenv("MAIL");
00142 
00143   if (default_Location.isNull()) {
00144     default_Location = _PATH_MAILDIR;
00145     default_Location += '/';
00146     default_Location += getenv("USER");
00147   }
00148   if ( !mSpoolFiles.contains(default_Location) )
00149     mSpoolFiles << default_Location;
00150 
00151   default_Location = default_Location + ".lock";
00152   if ( !mLockFiles.contains(default_Location) )
00153     mLockFiles << default_Location;
00154 }
00155 
00156 ProcmailRCParser::~ProcmailRCParser()
00157 {
00158   delete mStream;
00159 }
00160 
00161 void
00162 ProcmailRCParser::processGlobalLock(const QString &s)
00163 {
00164   QString val = expandVars(s.mid(s.find('=') + 1).stripWhiteSpace());
00165   if ( !mLockFiles.contains(val) )
00166     mLockFiles << val;
00167 }
00168 
00169 void
00170 ProcmailRCParser::processLocalLock(const QString &s)
00171 {
00172   QString val;
00173   int colonPos = s.findRev(':');
00174 
00175   if (colonPos > 0) { // we don't care about the leading one
00176     val = s.mid(colonPos + 1).stripWhiteSpace();
00177 
00178     if ( val.length() ) {
00179       // user specified a lockfile, so process it
00180       //
00181       val = expandVars(val);
00182       if( val[0] != '/' && mVars.find("MAILDIR") )
00183         val.insert(0, *(mVars["MAILDIR"]) + '/');
00184     } // else we'll deduce the lockfile name one we
00185     // get the spoolfile name
00186   }
00187 
00188   // parse until we find the spoolfile
00189   QString line, prevLine;
00190   do {
00191     prevLine = line;
00192     line = mStream->readLine().stripWhiteSpace();
00193   } while ( !mStream->eof() && (line[0] == '*' ||
00194                                 prevLine[prevLine.length() - 1] == '\\' ));
00195 
00196   if( line[0] != '!' && line[0] != '|' &&  line[0] != '{' ) {
00197     // this is a filename, expand it
00198     //
00199     line =  line.stripWhiteSpace();
00200     line = expandVars(line);
00201 
00202     // prepend default MAILDIR if needed
00203     if( line[0] != '/' && mVars.find("MAILDIR") )
00204       line.insert(0, *(mVars["MAILDIR"]) + '/');
00205 
00206     // now we have the spoolfile name
00207     if ( !mSpoolFiles.contains(line) )
00208       mSpoolFiles << line;
00209 
00210     if( colonPos > 0 && (!val || val.isEmpty()) ) {
00211       // there is a local lockfile, but the user didn't
00212       // specify the name so compute it from the spoolfile's name
00213       val = line;
00214 
00215       // append lock extension
00216       if( mVars.find("LOCKEXT") )
00217         val += *(mVars["LOCKEXT"]);
00218       else
00219         val += ".lock";
00220     }
00221 
00222     if ( !val.isNull() && !mLockFiles.contains(val) ) {
00223       mLockFiles << val;
00224     }
00225   }
00226 
00227 }
00228 
00229 void
00230 ProcmailRCParser::processVariableSetting(const QString &s, int eqPos)
00231 {
00232   if( eqPos == -1) return;
00233 
00234   QString varName = s.left(eqPos),
00235     varValue = expandVars(s.mid(eqPos + 1).stripWhiteSpace());
00236 
00237   mVars.insert(varName.latin1(), new QString(varValue));
00238 }
00239 
00240 QString
00241 ProcmailRCParser::expandVars(const QString &s)
00242 {
00243   if( s.isEmpty()) return s;
00244 
00245   QString expS = s;
00246 
00247   QAsciiDictIterator<QString> it( mVars ); // iterator for dict
00248 
00249   while ( it.current() ) {
00250     expS.replace(QString::fromLatin1("$") + it.currentKey(), *it.current());
00251     ++it;
00252   }
00253 
00254   return expS;
00255 }
00256 
00257 
00258 
00259 AccountDialog::AccountDialog( const QString & caption, KMAccount *account,
00260                   QWidget *parent, const char *name, bool modal )
00261   : KDialogBase( parent, name, modal, caption, Ok|Cancel|Help, Ok, true ),
00262     mAccount( account ),
00263     mServerTest( 0 ),
00264     mCurCapa( AllCapa ),
00265     mCapaNormal( AllCapa ),
00266     mCapaSSL( AllCapa ),
00267     mCapaTLS( AllCapa ),
00268     mSieveConfigEditor( 0 )
00269 {
00270   mValidator = new QRegExpValidator( QRegExp( "[A-Za-z0-9-_:.]*" ), 0 );
00271   setHelp("receiving-mail");
00272 
00273   QString accountType = mAccount->type();
00274 
00275   if( accountType == "local" )
00276   {
00277     makeLocalAccountPage();
00278   }
00279   else if( accountType == "maildir" )
00280   {
00281     makeMaildirAccountPage();
00282   }
00283   else if( accountType == "pop" )
00284   {
00285     makePopAccountPage();
00286   }
00287   else if( accountType == "imap" )
00288   {
00289     makeImapAccountPage();
00290   }
00291   else if( accountType == "cachedimap" )
00292   {
00293     makeImapAccountPage(true);
00294   }
00295   else
00296   {
00297     QString msg = i18n( "Account type is not supported." );
00298     KMessageBox::information( topLevelWidget(),msg,i18n("Configure Account") );
00299     return;
00300   }
00301 
00302   setupSettings();
00303 }
00304 
00305 AccountDialog::~AccountDialog()
00306 {
00307   delete mValidator;
00308   mValidator = 0;
00309   delete mServerTest;
00310   mServerTest = 0;
00311 }
00312 
00313 void AccountDialog::makeLocalAccountPage()
00314 {
00315   ProcmailRCParser procmailrcParser;
00316   QFrame *page = makeMainWidget();
00317   QGridLayout *topLayout = new QGridLayout( page, 12, 3, 0, spacingHint() );
00318   topLayout->addColSpacing( 1, fontMetrics().maxWidth()*15 );
00319   topLayout->setRowStretch( 11, 10 );
00320   topLayout->setColStretch( 1, 10 );
00321 
00322   mLocal.titleLabel = new QLabel( i18n("Account Type: Local Account"), page );
00323   topLayout->addMultiCellWidget( mLocal.titleLabel, 0, 0, 0, 2 );
00324   QFont titleFont( mLocal.titleLabel->font() );
00325   titleFont.setBold( true );
00326   mLocal.titleLabel->setFont( titleFont );
00327   KSeparator *hline = new KSeparator( KSeparator::HLine, page);
00328   topLayout->addMultiCellWidget( hline, 1, 1, 0, 2 );
00329 
00330   QLabel *label = new QLabel( i18n("&Name:"), page );
00331   topLayout->addWidget( label, 2, 0 );
00332   mLocal.nameEdit = new KLineEdit( page );
00333   label->setBuddy( mLocal.nameEdit );
00334   topLayout->addWidget( mLocal.nameEdit, 2, 1 );
00335 
00336   label = new QLabel( i18n("&Location:"), page );
00337   topLayout->addWidget( label, 3, 0 );
00338   mLocal.locationEdit = new QComboBox( true, page );
00339   label->setBuddy( mLocal.locationEdit );
00340   topLayout->addWidget( mLocal.locationEdit, 3, 1 );
00341   mLocal.locationEdit->insertStringList(procmailrcParser.getSpoolFilesList());
00342 
00343   QPushButton *choose = new QPushButton( i18n("Choo&se..."), page );
00344   choose->setAutoDefault( false );
00345   connect( choose, SIGNAL(clicked()), this, SLOT(slotLocationChooser()) );
00346   topLayout->addWidget( choose, 3, 2 );
00347 
00348   QButtonGroup *group = new QButtonGroup(i18n("Locking Method"), page );
00349   group->setColumnLayout(0, Qt::Horizontal);
00350   group->layout()->setSpacing( 0 );
00351   group->layout()->setMargin( 0 );
00352   QGridLayout *groupLayout = new QGridLayout( group->layout() );
00353   groupLayout->setAlignment( Qt::AlignTop );
00354   groupLayout->setSpacing( 6 );
00355   groupLayout->setMargin( 11 );
00356 
00357   mLocal.lockProcmail = new QRadioButton( i18n("Procmail loc&kfile:"), group);
00358   groupLayout->addWidget(mLocal.lockProcmail, 0, 0);
00359 
00360   mLocal.procmailLockFileName = new QComboBox( true, group );
00361   groupLayout->addWidget(mLocal.procmailLockFileName, 0, 1);
00362   mLocal.procmailLockFileName->insertStringList(procmailrcParser.getLockFilesList());
00363   mLocal.procmailLockFileName->setEnabled(false);
00364 
00365   QObject::connect(mLocal.lockProcmail, SIGNAL(toggled(bool)),
00366                    mLocal.procmailLockFileName, SLOT(setEnabled(bool)));
00367 
00368   mLocal.lockMutt = new QRadioButton(
00369     i18n("&Mutt dotlock"), group);
00370   groupLayout->addWidget(mLocal.lockMutt, 1, 0);
00371 
00372   mLocal.lockMuttPriv = new QRadioButton(
00373     i18n("M&utt dotlock privileged"), group);
00374   groupLayout->addWidget(mLocal.lockMuttPriv, 2, 0);
00375 
00376   mLocal.lockFcntl = new QRadioButton(
00377     i18n("&FCNTL"), group);
00378   groupLayout->addWidget(mLocal.lockFcntl, 3, 0);
00379 
00380   mLocal.lockNone = new QRadioButton(
00381     i18n("Non&e (use with care)"), group);
00382   groupLayout->addWidget(mLocal.lockNone, 4, 0);
00383 
00384   topLayout->addMultiCellWidget( group, 4, 4, 0, 2 );
00385 
00386 #if 0
00387   QHBox* resourceHB = new QHBox( page );
00388   resourceHB->setSpacing( 11 );
00389   mLocal.resourceCheck =
00390       new QCheckBox( i18n( "Account for semiautomatic resource handling" ), resourceHB );
00391   mLocal.resourceClearButton =
00392       new QPushButton( i18n( "Clear" ), resourceHB );
00393   QWhatsThis::add( mLocal.resourceClearButton,
00394                    i18n( "Delete all allocations for the resource represented by this account." ) );
00395   mLocal.resourceClearButton->setEnabled( false );
00396   connect( mLocal.resourceCheck, SIGNAL( toggled(bool) ),
00397            mLocal.resourceClearButton, SLOT( setEnabled(bool) ) );
00398   connect( mLocal.resourceClearButton, SIGNAL( clicked() ),
00399            this, SLOT( slotClearResourceAllocations() ) );
00400   mLocal.resourceClearPastButton =
00401       new QPushButton( i18n( "Clear Past" ), resourceHB );
00402   mLocal.resourceClearPastButton->setEnabled( false );
00403   connect( mLocal.resourceCheck, SIGNAL( toggled(bool) ),
00404            mLocal.resourceClearPastButton, SLOT( setEnabled(bool) ) );
00405   QWhatsThis::add( mLocal.resourceClearPastButton,
00406                    i18n( "Delete all outdated allocations for the resource represented by this account." ) );
00407   connect( mLocal.resourceClearPastButton, SIGNAL( clicked() ),
00408            this, SLOT( slotClearPastResourceAllocations() ) );
00409   topLayout->addMultiCellWidget( resourceHB, 5, 5, 0, 2 );
00410 #endif
00411 
00412   mLocal.excludeCheck =
00413     new QCheckBox( i18n("E&xclude from \"Check Mail\""), page );
00414   topLayout->addMultiCellWidget( mLocal.excludeCheck, 5, 5, 0, 2 );
00415 
00416   mLocal.intervalCheck =
00417     new QCheckBox( i18n("Enable &interval mail checking"), page );
00418   topLayout->addMultiCellWidget( mLocal.intervalCheck, 6, 6, 0, 2 );
00419   connect( mLocal.intervalCheck, SIGNAL(toggled(bool)),
00420        this, SLOT(slotEnableLocalInterval(bool)) );
00421   mLocal.intervalLabel = new QLabel( i18n("Check inter&val:"), page );
00422   topLayout->addWidget( mLocal.intervalLabel, 7, 0 );
00423   mLocal.intervalSpin = new KIntNumInput( page );
00424   mLocal.intervalLabel->setBuddy( mLocal.intervalSpin );
00425   mLocal.intervalSpin->setRange( 1, 10000, 1, FALSE );
00426   mLocal.intervalSpin->setSuffix( i18n(" min") );
00427   mLocal.intervalSpin->setValue( 1 );
00428   topLayout->addWidget( mLocal.intervalSpin, 7, 1 );
00429 
00430   label = new QLabel( i18n("&Destination folder:"), page );
00431   topLayout->addWidget( label, 8, 0 );
00432   mLocal.folderCombo = new QComboBox( false, page );
00433   label->setBuddy( mLocal.folderCombo );
00434   topLayout->addWidget( mLocal.folderCombo, 8, 1 );
00435 
00436   /* -sanders Probably won't support this way, use filters insteada
00437   label = new QLabel( i18n("Default identity:"), page );
00438   topLayout->addWidget( label, 9, 0 );
00439   mLocal.identityCombo = new QComboBox( false, page );
00440   topLayout->addWidget( mLocal.identityCombo, 9, 1 );
00441   // GS - this was moved inside the commented block 9/30/2000
00442   //      (I think Don missed it?)
00443   label->setEnabled(false);
00444   */
00445 
00446   //mLocal.identityCombo->setEnabled(false);
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   connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()));
00455 }
00456 
00457 void AccountDialog::makeMaildirAccountPage()
00458 {
00459   ProcmailRCParser procmailrcParser;
00460 
00461   QFrame *page = makeMainWidget();
00462   QGridLayout *topLayout = new QGridLayout( page, 11, 3, 0, spacingHint() );
00463   topLayout->addColSpacing( 1, fontMetrics().maxWidth()*15 );
00464   topLayout->setRowStretch( 11, 10 );
00465   topLayout->setColStretch( 1, 10 );
00466 
00467   mMaildir.titleLabel = new QLabel( i18n("Account Type: Maildir Account"), page );
00468   topLayout->addMultiCellWidget( mMaildir.titleLabel, 0, 0, 0, 2 );
00469   QFont titleFont( mMaildir.titleLabel->font() );
00470   titleFont.setBold( true );
00471   mMaildir.titleLabel->setFont( titleFont );
00472   QFrame *hline = new QFrame( page );
00473   hline->setFrameStyle( QFrame::Sunken | QFrame::HLine );
00474   topLayout->addMultiCellWidget( hline, 1, 1, 0, 2 );
00475 
00476   mMaildir.nameEdit = new KLineEdit( page );
00477   topLayout->addWidget( mMaildir.nameEdit, 2, 1 );
00478   QLabel *label = new QLabel( mMaildir.nameEdit, i18n("&Name:"), page );
00479   topLayout->addWidget( label, 2, 0 );
00480 
00481   mMaildir.locationEdit = new QComboBox( true, page );
00482   topLayout->addWidget( mMaildir.locationEdit, 3, 1 );
00483   mMaildir.locationEdit->insertStringList(procmailrcParser.getSpoolFilesList());
00484   label = new QLabel( mMaildir.locationEdit, i18n("&Location:"), page );
00485   topLayout->addWidget( label, 3, 0 );
00486 
00487   QPushButton *choose = new QPushButton( i18n("Choo&se..."), page );
00488   choose->setAutoDefault( false );
00489   connect( choose, SIGNAL(clicked()), this, SLOT(slotMaildirChooser()) );
00490   topLayout->addWidget( choose, 3, 2 );
00491 
00492 #if 0
00493   QHBox* resourceHB = new QHBox( page );
00494   resourceHB->setSpacing( 11 );
00495   mMaildir.resourceCheck =
00496       new QCheckBox( i18n( "Account for semiautomatic resource handling" ), resourceHB );
00497   mMaildir.resourceClearButton =
00498       new QPushButton( i18n( "Clear" ), resourceHB );
00499   mMaildir.resourceClearButton->setEnabled( false );
00500   connect( mMaildir.resourceCheck, SIGNAL( toggled(bool) ),
00501            mMaildir.resourceClearButton, SLOT( setEnabled(bool) ) );
00502   QWhatsThis::add( mMaildir.resourceClearButton,
00503                    i18n( "Delete all allocations for the resource represented by this account." ) );
00504   connect( mMaildir.resourceClearButton, SIGNAL( clicked() ),
00505            this, SLOT( slotClearResourceAllocations() ) );
00506   mMaildir.resourceClearPastButton =
00507       new QPushButton( i18n( "Clear Past" ), resourceHB );
00508   mMaildir.resourceClearPastButton->setEnabled( false );
00509   connect( mMaildir.resourceCheck, SIGNAL( toggled(bool) ),
00510            mMaildir.resourceClearPastButton, SLOT( setEnabled(bool) ) );
00511   QWhatsThis::add( mMaildir.resourceClearPastButton,
00512                    i18n( "Delete all outdated allocations for the resource represented by this account." ) );
00513   connect( mMaildir.resourceClearPastButton, SIGNAL( clicked() ),
00514            this, SLOT( slotClearPastResourceAllocations() ) );
00515   topLayout->addMultiCellWidget( resourceHB, 4, 4, 0, 2 );
00516 #endif
00517 
00518   mMaildir.excludeCheck =
00519     new QCheckBox( i18n("E&xclude from \"Check Mail\""), page );
00520   topLayout->addMultiCellWidget( mMaildir.excludeCheck, 4, 4, 0, 2 );
00521 
00522   mMaildir.intervalCheck =
00523     new QCheckBox( i18n("Enable &interval mail checking"), page );
00524   topLayout->addMultiCellWidget( mMaildir.intervalCheck, 5, 5, 0, 2 );
00525   connect( mMaildir.intervalCheck, SIGNAL(toggled(bool)),
00526        this, SLOT(slotEnableMaildirInterval(bool)) );
00527   mMaildir.intervalLabel = new QLabel( i18n("Check inter&val:"), page );
00528   topLayout->addWidget( mMaildir.intervalLabel, 6, 0 );
00529   mMaildir.intervalSpin = new KIntNumInput( page );
00530   mMaildir.intervalSpin->setRange( 1, 10000, 1, FALSE );
00531   mMaildir.intervalSpin->setSuffix( i18n(" min") );
00532   mMaildir.intervalSpin->setValue( 1 );
00533   mMaildir.intervalLabel->setBuddy( mMaildir.intervalSpin );
00534   topLayout->addWidget( mMaildir.intervalSpin, 6, 1 );
00535 
00536   mMaildir.folderCombo = new QComboBox( false, page );
00537   topLayout->addWidget( mMaildir.folderCombo, 7, 1 );
00538   label = new QLabel( mMaildir.folderCombo,
00539               i18n("&Destination folder:"), page );
00540   topLayout->addWidget( label, 7, 0 );
00541 
00542   mMaildir.precommand = new KLineEdit( page );
00543   topLayout->addWidget( mMaildir.precommand, 8, 1 );
00544   label = new QLabel( mMaildir.precommand, i18n("&Pre-command:"), page );
00545   topLayout->addWidget( label, 8, 0 );
00546 
00547   connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()));
00548 }
00549 
00550 
00551 void AccountDialog::makePopAccountPage()
00552 {
00553   QFrame *page = makeMainWidget();
00554   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00555 
00556   mPop.titleLabel = new QLabel( page );
00557   mPop.titleLabel->setText( i18n("Account Type: POP Account") );
00558   QFont titleFont( mPop.titleLabel->font() );
00559   titleFont.setBold( true );
00560   mPop.titleLabel->setFont( titleFont );
00561   topLayout->addWidget( mPop.titleLabel );
00562   KSeparator *hline = new KSeparator( KSeparator::HLine, page);
00563   topLayout->addWidget( hline );
00564 
00565   QTabWidget *tabWidget = new QTabWidget(page);
00566   topLayout->addWidget( tabWidget );
00567 
00568   QWidget *page1 = new QWidget( tabWidget );
00569   tabWidget->addTab( page1, i18n("&General") );
00570 
00571   QGridLayout *grid = new QGridLayout( page1, 16, 2, marginHint(), spacingHint() );
00572   grid->addColSpacing( 1, fontMetrics().maxWidth()*15 );
00573   grid->setRowStretch( 15, 10 );
00574   grid->setColStretch( 1, 10 );
00575 
00576   QLabel *label = new QLabel( i18n("&Name:"), page1 );
00577   grid->addWidget( label, 0, 0 );
00578   mPop.nameEdit = new KLineEdit( page1 );
00579   label->setBuddy( mPop.nameEdit );
00580   grid->addWidget( mPop.nameEdit, 0, 1 );
00581 
00582   label = new QLabel( i18n("&Login:"), page1 );
00583   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>).") );
00584   grid->addWidget( label, 1, 0 );
00585   mPop.loginEdit = new KLineEdit( page1 );
00586   label->setBuddy( mPop.loginEdit );
00587   grid->addWidget( mPop.loginEdit, 1, 1 );
00588 
00589   label = new QLabel( i18n("P&assword:"), page1 );
00590   grid->addWidget( label, 2, 0 );
00591   mPop.passwordEdit = new KLineEdit( page1 );
00592   mPop.passwordEdit->setEchoMode( QLineEdit::Password );
00593   label->setBuddy( mPop.passwordEdit );
00594   grid->addWidget( mPop.passwordEdit, 2, 1 );
00595 
00596   label = new QLabel( i18n("Ho&st:"), page1 );
00597   grid->addWidget( label, 3, 0 );
00598   mPop.hostEdit = new KLineEdit( page1 );
00599   // only letters, digits, '-', '.', ':' (IPv6) and '_' (for Windows
00600   // compatibility) are allowed
00601   mPop.hostEdit->setValidator(mValidator);
00602   label->setBuddy( mPop.hostEdit );
00603   grid->addWidget( mPop.hostEdit, 3, 1 );
00604 
00605   label = new QLabel( i18n("&Port:"), page1 );
00606   grid->addWidget( label, 4, 0 );
00607   mPop.portEdit = new KLineEdit( page1 );
00608   mPop.portEdit->setValidator( new QIntValidator(this) );
00609   label->setBuddy( mPop.portEdit );
00610   grid->addWidget( mPop.portEdit, 4, 1 );
00611 
00612   mPop.storePasswordCheck =
00613     new QCheckBox( i18n("Sto&re POP password in configuration file"), page1 );
00614   grid->addMultiCellWidget( mPop.storePasswordCheck, 5, 5, 0, 1 );
00615 
00616   mPop.leaveOnServerCheck =
00617     new QCheckBox( i18n("Lea&ve fetched messages on the server"), page1 );
00618   connect( mPop.leaveOnServerCheck, SIGNAL( clicked() ),
00619            this, SLOT( slotLeaveOnServerClicked() ) );
00620   grid->addMultiCellWidget( mPop.leaveOnServerCheck, 6, 6, 0, 1 );
00621 
00622 #if 0
00623   QHBox* resourceHB = new QHBox( page1 );
00624   resourceHB->setSpacing( 11 );
00625   mPop.resourceCheck =
00626       new QCheckBox( i18n( "Account for semiautomatic resource handling" ), resourceHB );
00627   mPop.resourceClearButton =
00628       new QPushButton( i18n( "Clear" ), resourceHB );
00629   mPop.resourceClearButton->setEnabled( false );
00630   connect( mPop.resourceCheck, SIGNAL( toggled(bool) ),
00631            mPop.resourceClearButton, SLOT( setEnabled(bool) ) );
00632   QWhatsThis::add( mPop.resourceClearButton,
00633                    i18n( "Delete all allocations for the resource represented by this account." ) );
00634   connect( mPop.resourceClearButton, SIGNAL( clicked() ),
00635            this, SLOT( slotClearResourceAllocations() ) );
00636   mPop.resourceClearPastButton =
00637       new QPushButton( i18n( "Clear Past" ), resourceHB );
00638   mPop.resourceClearPastButton->setEnabled( false );
00639   connect( mPop.resourceCheck, SIGNAL( toggled(bool) ),
00640            mPop.resourceClearPastButton, SLOT( setEnabled(bool) ) );
00641   QWhatsThis::add( mPop.resourceClearPastButton,
00642                    i18n( "Delete all outdated allocations for the resource represented by this account." ) );
00643   connect( mPop.resourceClearPastButton, SIGNAL( clicked() ),
00644            this, SLOT( slotClearPastResourceAllocations() ) );
00645   grid->addMultiCellWidget( resourceHB, 7, 7, 0, 2 );
00646 #endif
00647 
00648   mPop.excludeCheck =
00649     new QCheckBox( i18n("E&xclude from \"Check Mail\""), page1 );
00650   grid->addMultiCellWidget( mPop.excludeCheck, 7, 7, 0, 1 );
00651 
00652   QHBox * hbox = new QHBox( page1 );
00653   hbox->setSpacing( KDialog::spacingHint() );
00654   mPop.filterOnServerCheck =
00655     new QCheckBox( i18n("&Filter messages if they are greater than"), hbox );
00656   mPop.filterOnServerSizeSpin = new KIntNumInput ( hbox );
00657   mPop.filterOnServerSizeSpin->setEnabled( false );
00658   hbox->setStretchFactor( mPop.filterOnServerSizeSpin, 1 );
00659   mPop.filterOnServerSizeSpin->setRange( 1, 10000000, 100, FALSE );
00660   mPop.filterOnServerSizeSpin->setValue( 50000 );
00661   mPop.filterOnServerSizeSpin->setSuffix( i18n(" byte") );
00662   grid->addMultiCellWidget( hbox, 8, 8, 0, 1 );
00663   connect( mPop.filterOnServerCheck, SIGNAL(toggled(bool)),
00664        mPop.filterOnServerSizeSpin, SLOT(setEnabled(bool)) );
00665   connect( mPop.filterOnServerCheck, SIGNAL( clicked() ),
00666            this, SLOT( slotFilterOnServerClicked() ) );
00667   QString msg = i18n("If you select this option, POP Filters will be used to "
00668              "decide what to do with messages. You can then select "
00669              "to download, delete or keep them on the server." );
00670   QWhatsThis::add( mPop.filterOnServerCheck, msg );
00671   QWhatsThis::add( mPop.filterOnServerSizeSpin, msg );
00672 
00673   mPop.intervalCheck =
00674     new QCheckBox( i18n("Enable &interval mail checking"), page1 );
00675   grid->addMultiCellWidget( mPop.intervalCheck, 9, 9, 0, 1 );
00676   connect( mPop.intervalCheck, SIGNAL(toggled(bool)),
00677        this, SLOT(slotEnablePopInterval(bool)) );
00678   mPop.intervalLabel = new QLabel( i18n("Chec&k interval:"), page1 );
00679   grid->addWidget( mPop.intervalLabel, 10, 0 );
00680   mPop.intervalSpin = new KIntNumInput( page1 );
00681   mPop.intervalSpin->setRange( 1, 10000, 1, FALSE );
00682   mPop.intervalSpin->setSuffix( i18n(" min") );
00683   mPop.intervalSpin->setValue( 1 );
00684   mPop.intervalLabel->setBuddy( mPop.intervalSpin );
00685   grid->addWidget( mPop.intervalSpin, 10, 1 );
00686 
00687   label = new QLabel( i18n("Des&tination folder:"), page1 );
00688   grid->addWidget( label, 11, 0 );
00689   mPop.folderCombo = new QComboBox( false, page1 );
00690   label->setBuddy( mPop.folderCombo );
00691   grid->addWidget( mPop.folderCombo, 11, 1 );
00692 
00693   label = new QLabel( i18n("Precom&mand:"), page1 );
00694   grid->addWidget( label, 12, 0 );
00695   mPop.precommand = new KLineEdit( page1 );
00696   label->setBuddy(mPop.precommand);
00697   grid->addWidget( mPop.precommand, 12, 1 );
00698 
00699   QWidget *page2 = new QWidget( tabWidget );
00700   tabWidget->addTab( page2, i18n("&Extras") );
00701   QVBoxLayout *vlay = new QVBoxLayout( page2, marginHint(), spacingHint() );
00702 
00703   mPop.usePipeliningCheck =
00704     new QCheckBox( i18n("&Use pipelining for faster mail download"), page2 );
00705   connect(mPop.usePipeliningCheck, SIGNAL(clicked()),
00706     SLOT(slotPipeliningClicked()));
00707   vlay->addWidget( mPop.usePipeliningCheck );
00708 
00709   mPop.encryptionGroup = new QButtonGroup( 1, Qt::Horizontal,
00710     i18n("Encryption"), page2 );
00711   mPop.encryptionNone =
00712     new QRadioButton( i18n("&None"), mPop.encryptionGroup );
00713   mPop.encryptionSSL =
00714     new QRadioButton( i18n("Use &SSL for secure mail download"),
00715     mPop.encryptionGroup );
00716   mPop.encryptionTLS =
00717     new QRadioButton( i18n("Use &TLS for secure mail download"),
00718     mPop.encryptionGroup );
00719   connect(mPop.encryptionGroup, SIGNAL(clicked(int)),
00720     SLOT(slotPopEncryptionChanged(int)));
00721   vlay->addWidget( mPop.encryptionGroup );
00722 
00723   mPop.authGroup = new QButtonGroup( 1, Qt::Horizontal,
00724     i18n("Authentication Method"), page2 );
00725   mPop.authUser = new QRadioButton( i18n("Clear te&xt") , mPop.authGroup,
00726                                     "auth clear text" );
00727   mPop.authLogin = new QRadioButton( i18n("Please translate this "
00728     "authentication method only if you have a good reason", "&LOGIN"),
00729     mPop.authGroup, "auth login" );
00730   mPop.authPlain = new QRadioButton( i18n("Please translate this "
00731     "authentication method only if you have a good reason", "&PLAIN"),
00732     mPop.authGroup, "auth plain"  );
00733   mPop.authCRAM_MD5 = new QRadioButton( i18n("CRAM-MD&5"), mPop.authGroup, "auth cram-md5" );
00734   mPop.authDigestMd5 = new QRadioButton( i18n("&DIGEST-MD5"), mPop.authGroup, "auth digest-md5" );
00735   mPop.authAPOP = new QRadioButton( i18n("&APOP"), mPop.authGroup, "auth apop" );
00736   vlay->addWidget( mPop.authGroup );
00737 
00738   vlay->addStretch();
00739 
00740   QHBoxLayout *buttonLay = new QHBoxLayout( vlay );
00741   mPop.checkCapabilities =
00742     new QPushButton( i18n("Check &What the Server Supports"), page2 );
00743   connect(mPop.checkCapabilities, SIGNAL(clicked()),
00744     SLOT(slotCheckPopCapabilities()));
00745   buttonLay->addStretch();
00746   buttonLay->addWidget( mPop.checkCapabilities );
00747 
00748   connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()));
00749 }
00750 
00751 
00752 void AccountDialog::makeImapAccountPage( bool connected )
00753 {
00754   QFrame *page = makeMainWidget();
00755   QVBoxLayout *topLayout = new QVBoxLayout( page, 0, spacingHint() );
00756 
00757   mImap.titleLabel = new QLabel( page );
00758   if( connected )
00759     mImap.titleLabel->setText( i18n("Account Type: Disconnected IMAP Account") );
00760   else
00761     mImap.titleLabel->setText( i18n("Account Type: IMAP Account") );
00762   QFont titleFont( mImap.titleLabel->font() );
00763   titleFont.setBold( true );
00764   mImap.titleLabel->setFont( titleFont );
00765   topLayout->addWidget( mImap.titleLabel );
00766   KSeparator *hline = new KSeparator( KSeparator::HLine, page);
00767   topLayout->addWidget( hline );
00768 
00769   QTabWidget *tabWidget = new QTabWidget(page);
00770   topLayout->addWidget( tabWidget );
00771 
00772   QWidget *page1 = new QWidget( tabWidget );
00773   tabWidget->addTab( page1, i18n("&General") );
00774 
00775   int row = -1;
00776   QGridLayout *grid = new QGridLayout( page1, 15, 2, marginHint(), spacingHint() );
00777   grid->addColSpacing( 1, fontMetrics().maxWidth()*15 );
00778   grid->setRowStretch( 15, 10 );
00779   grid->setColStretch( 1, 10 );
00780 
00781   ++row;
00782   QLabel *label = new QLabel( i18n("&Name:"), page1 );
00783   grid->addWidget( label, row, 0 );
00784   mImap.nameEdit = new KLineEdit( page1 );
00785   label->setBuddy( mImap.nameEdit );
00786   grid->addWidget( mImap.nameEdit, row, 1 );
00787 
00788   ++row;
00789   label = new QLabel( i18n("&Login:"), page1 );
00790   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>).") );
00791   grid->addWidget( label, row, 0 );
00792   mImap.loginEdit = new KLineEdit( page1 );
00793   label->setBuddy( mImap.loginEdit );
00794   grid->addWidget( mImap.loginEdit, row, 1 );
00795 
00796   ++row;
00797   label = new QLabel( i18n("P&assword:"), page1 );
00798   grid->addWidget( label, row, 0 );
00799   mImap.passwordEdit = new KLineEdit( page1 );
00800   mImap.passwordEdit->setEchoMode( QLineEdit::Password );
00801   label->setBuddy( mImap.passwordEdit );
00802   grid->addWidget( mImap.passwordEdit, row, 1 );
00803 
00804   ++row;
00805   label = new QLabel( i18n("Ho&st:"), page1 );
00806   grid->addWidget( label, row, 0 );
00807   mImap.hostEdit = new KLineEdit( page1 );
00808   // only letters, digits, '-', '.', ':' (IPv6) and '_' (for Windows
00809   // compatibility) are allowed
00810   mImap.hostEdit->setValidator(mValidator);
00811   label->setBuddy( mImap.hostEdit );
00812   grid->addWidget( mImap.hostEdit, row, 1 );
00813 
00814   ++row;
00815   label = new QLabel( i18n("&Port:"), page1 );
00816   grid->addWidget( label, row, 0 );
00817   mImap.portEdit = new KLineEdit( page1 );
00818   mImap.portEdit->setValidator( new QIntValidator(this) );
00819   label->setBuddy( mImap.portEdit );
00820   grid->addWidget( mImap.portEdit, row, 1 );
00821 
00822   ++row;
00823   label = new QLabel( i18n("Prefix to fol&ders:"), page1 );
00824   grid->addWidget( label, row, 0 );
00825   mImap.prefixEdit = new KLineEdit( page1 );
00826   label->setBuddy( mImap.prefixEdit );
00827   grid->addWidget( mImap.prefixEdit, row, 1 );
00828 
00829   ++row;
00830   mImap.storePasswordCheck =
00831     new QCheckBox( i18n("Sto&re IMAP password in configuration file"), page1 );
00832   grid->addMultiCellWidget( mImap.storePasswordCheck, row, row, 0, 1 );
00833 
00834   if( !connected ) {
00835     ++row;
00836     mImap.autoExpungeCheck =
00837       new QCheckBox( i18n("Automaticall&y compact folders (expunges deleted messages)"), page1);
00838     grid->addMultiCellWidget( mImap.autoExpungeCheck, row, row, 0, 1 );
00839   }
00840 
00841   ++row;
00842   mImap.hiddenFoldersCheck = new QCheckBox( i18n("Sho&w hidden folders"), page1);
00843   grid->addMultiCellWidget( mImap.hiddenFoldersCheck, row, row, 0, 1 );
00844 
00845   if( connected ) {
00846     ++row;
00847     mImap.progressDialogCheck = new QCheckBox( i18n("Show &progress window"), page1);
00848     grid->addMultiCellWidget( mImap.progressDialogCheck, row, row, 0, 1 );
00849   }
00850 
00851   ++row;
00852   mImap.subscribedFoldersCheck = new QCheckBox(
00853     i18n("Show only s&ubscribed folders"), page1);
00854   grid->addMultiCellWidget( mImap.subscribedFoldersCheck, row, row, 0, 1 );
00855 
00856   ++row;
00857   mImap.locallySubscribedFoldersCheck = new QCheckBox(
00858     i18n("Show only &locally subscribed folders"), page1);
00859   grid->addMultiCellWidget( mImap.locallySubscribedFoldersCheck, row, row, 0, 1 );
00860 
00861   if ( !connected ) {
00862     // not implemented for disconnected yet
00863     ++row;
00864     mImap.loadOnDemandCheck = new QCheckBox(
00865         i18n("Load attach&ments on demand"), page1);
00866     QWhatsThis::add( mImap.loadOnDemandCheck,
00867         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.") );
00868     grid->addMultiCellWidget( mImap.loadOnDemandCheck, row, row, 0, 1 );
00869   }
00870 
00871   if ( !connected ) {
00872     // not implemented for disconnected yet
00873     ++row;
00874     mImap.listOnlyOpenCheck = new QCheckBox(
00875         i18n("List only open folders"), page1);
00876     QWhatsThis::add( mImap.listOnlyOpenCheck,
00877         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.") );
00878     grid->addMultiCellWidget( mImap.listOnlyOpenCheck, row, row, 0, 1 );
00879   }
00880 
00881   ++row;
00882 #if 0
00883   QHBox* resourceHB = new QHBox( page1 );
00884   resourceHB->setSpacing( 11 );
00885   mImap.resourceCheck =
00886       new QCheckBox( i18n( "Account for semiautomatic resource handling" ), resourceHB );
00887   mImap.resourceClearButton =
00888       new QPushButton( i18n( "Clear" ), resourceHB );
00889   mImap.resourceClearButton->setEnabled( false );
00890   connect( mImap.resourceCheck, SIGNAL( toggled(bool) ),
00891            mImap.resourceClearButton, SLOT( setEnabled(bool) ) );
00892   QWhatsThis::add( mImap.resourceClearButton,
00893                    i18n( "Delete all allocations for the resource represented by this account." ) );
00894   connect( mImap.resourceClearButton, SIGNAL( clicked() ),
00895            this, SLOT( slotClearResourceAllocations() ) );
00896   mImap.resourceClearPastButton =
00897       new QPushButton( i18n( "Clear Past" ), resourceHB );
00898   mImap.resourceClearPastButton->setEnabled( false );
00899   connect( mImap.resourceCheck, SIGNAL( toggled(bool) ),
00900            mImap.resourceClearPastButton, SLOT( setEnabled(bool) ) );
00901   QWhatsThis::add( mImap.resourceClearPastButton,
00902                    i18n( "Delete all outdated allocations for the resource represented by this account." ) );
00903   connect( mImap.resourceClearPastButton, SIGNAL( clicked() ),
00904            this, SLOT( slotClearPastResourceAllocations() ) );
00905   grid->addMultiCellWidget( resourceHB, row, row, 0, 2 );
00906 #endif
00907 
00908   ++row;
00909   mImap.excludeCheck =
00910     new QCheckBox( i18n("E&xclude from \"Check Mail\""), page1 );
00911   grid->addMultiCellWidget( mImap.excludeCheck, row, row, 0, 1 );
00912 
00913   ++row;
00914   mImap.intervalCheck =
00915     new QCheckBox( i18n("Enable &interval mail checking"), page1 );
00916   grid->addMultiCellWidget( mImap.intervalCheck, row, row, 0, 2 );
00917   connect( mImap.intervalCheck, SIGNAL(toggled(bool)),
00918        this, SLOT(slotEnableImapInterval(bool)) );
00919   ++row;
00920   mImap.intervalLabel = new QLabel( i18n("Check inter&val:"), page1 );
00921   grid->addWidget( mImap.intervalLabel, row, 0 );
00922   mImap.intervalSpin = new KIntNumInput( page1 );
00923   const int kioskMinimumImapCheckInterval = GlobalSettings::minimumImapCheckInterval();
00924   mImap.intervalSpin->setRange( kioskMinimumImapCheckInterval, 60, 1, FALSE );
00925   mImap.intervalSpin->setValue( 1 );
00926   mImap.intervalSpin->setSuffix( i18n( " min" ) );
00927   mImap.intervalLabel->setBuddy( mImap.intervalSpin );
00928   grid->addWidget( mImap.intervalSpin, row, 1 );
00929 
00930   ++row;
00931   mImap.trashCombo = new KMFolderComboBox( page1 );
00932   mImap.trashCombo->showOutboxFolder( FALSE );
00933   grid->addWidget( mImap.trashCombo, row, 1 );
00934   grid->addWidget( new QLabel( mImap.trashCombo, i18n("&Trash folder:"), page1 ), row, 0 );
00935 
00936   QWidget *page2 = new QWidget( tabWidget );
00937   tabWidget->addTab( page2, i18n("S&ecurity") );
00938   QVBoxLayout *vlay = new QVBoxLayout( page2, marginHint(), spacingHint() );
00939 
00940   mImap.encryptionGroup = new QButtonGroup( 1, Qt::Horizontal,
00941     i18n("Encryption"), page2 );
00942   mImap.encryptionNone =
00943     new QRadioButton( i18n("&None"), mImap.encryptionGroup );
00944   mImap.encryptionSSL =
00945     new QRadioButton( i18n("Use &SSL for secure mail download"),
00946     mImap.encryptionGroup );
00947   mImap.encryptionTLS =
00948     new QRadioButton( i18n("Use &TLS for secure mail download"),
00949     mImap.encryptionGroup );
00950   connect(mImap.encryptionGroup, SIGNAL(clicked(int)),
00951     SLOT(slotImapEncryptionChanged(int)));
00952   vlay->addWidget( mImap.encryptionGroup );
00953 
00954   mImap.authGroup = new QButtonGroup( 1, Qt::Horizontal,
00955     i18n("Authentication Method"), page2 );
00956   mImap.authUser = new QRadioButton( i18n("Clear te&xt"), mImap.authGroup );
00957   mImap.authLogin = new QRadioButton( i18n("Please translate this "
00958     "authentication method only if you have a good reason", "&LOGIN"),
00959     mImap.authGroup );
00960   mImap.authPlain = new QRadioButton( i18n("Please translate this "
00961     "authentication method only if you have a good reason", "&PLAIN"),
00962      mImap.authGroup );
00963   mImap.authCramMd5 = new QRadioButton( i18n("CRAM-MD&5"), mImap.authGroup );
00964   mImap.authDigestMd5 = new QRadioButton( i18n("&DIGEST-MD5"), mImap.authGroup );
00965   mImap.authAnonymous = new QRadioButton( i18n("&Anonymous"), mImap.authGroup );
00966   vlay->addWidget( mImap.authGroup );
00967 
00968   vlay->addStretch();
00969 
00970   QHBoxLayout *buttonLay = new QHBoxLayout( vlay );
00971   mImap.checkCapabilities =
00972     new QPushButton( i18n("Check &What the Server Supports"), page2 );
00973   connect(mImap.checkCapabilities, SIGNAL(clicked()),
00974     SLOT(slotCheckImapCapabilities()));
00975   buttonLay->addStretch();
00976   buttonLay->addWidget( mImap.checkCapabilities );
00977 
00978   // TODO (marc/bo): Test this
00979   mSieveConfigEditor = new SieveConfigEditor( tabWidget );
00980   mSieveConfigEditor->layout()->setMargin( KDialog::marginHint() );
00981   tabWidget->addTab( mSieveConfigEditor, i18n("&Filtering") );
00982 
00983   connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged()));
00984 }
00985 
00986 
00987 void AccountDialog::setupSettings()
00988 {
00989   QComboBox *folderCombo = 0;
00990   int interval = mAccount->checkInterval();
00991 
00992   QString accountType = mAccount->type();
00993   if( accountType == "local" )
00994   {
00995     ProcmailRCParser procmailrcParser;
00996     KMAcctLocal *acctLocal = dynamic_cast<KMAcctLocal*>(mAccount);
00997 
00998     if ( acctLocal->location().isEmpty() )
00999         acctLocal->setLocation( procmailrcParser.getSpoolFilesList().first() );
01000     else
01001         mLocal.locationEdit->insertItem( acctLocal->location() );
01002 
01003     if ( acctLocal->procmailLockFileName().isEmpty() )
01004         acctLocal->setProcmailLockFileName( procmailrcParser.getLockFilesList().first() );
01005     else
01006         mLocal.procmailLockFileName->insertItem( acctLocal->procmailLockFileName() );
01007 
01008     mLocal.nameEdit->setText( mAccount->name() );
01009     mLocal.nameEdit->setFocus();
01010     mLocal.locationEdit->setEditText( acctLocal->location() );
01011     if (acctLocal->lockType() == mutt_dotlock)
01012       mLocal.lockMutt->setChecked(true);
01013     else if (acctLocal->lockType() == mutt_dotlock_privileged)
01014       mLocal.lockMuttPriv->setChecked(true);
01015     else if (acctLocal->lockType() == procmail_lockfile) {
01016       mLocal.lockProcmail->setChecked(true);
01017       mLocal.procmailLockFileName->setEditText(acctLocal->procmailLockFileName());
01018     } else if (acctLocal->lockType() == FCNTL)
01019       mLocal.lockFcntl->setChecked(true);
01020     else if (acctLocal->lockType() == lock_none)
01021       mLocal.lockNone->setChecked(true);
01022 
01023     mLocal.intervalSpin->setValue( QMAX(1, interval) );
01024     mLocal.intervalCheck->setChecked( interval >= 1 );
01025 #if 0
01026     mLocal.resourceCheck->setChecked( mAccount->resource() );
01027 #endif
01028     mLocal.excludeCheck->setChecked( mAccount->checkExclude() );
01029     mLocal.precommand->setText( mAccount->precommand() );
01030 
01031     slotEnableLocalInterval( interval >= 1 );
01032     folderCombo = mLocal.folderCombo;
01033   }
01034   else if( accountType == "pop" )
01035   {
01036     KMAcctExpPop &ap = *(KMAcctExpPop*)mAccount;
01037     mPop.nameEdit->setText( mAccount->name() );
01038     mPop.nameEdit->setFocus();
01039     mPop.loginEdit->setText( ap.login() );
01040     mPop.passwordEdit->setText( ap.passwd());
01041     mPop.hostEdit->setText( ap.host() );
01042     mPop.portEdit->setText( QString("%1").arg( ap.port() ) );
01043     mPop.usePipeliningCheck->setChecked( ap.usePipelining() );
01044     mPop.storePasswordCheck->setChecked( ap.storePasswd() );
01045     mPop.leaveOnServerCheck->setChecked( ap.leaveOnServer() );
01046     mPop.filterOnServerCheck->setChecked( ap.filterOnServer() );
01047     mPop.filterOnServerSizeSpin->setValue( ap.filterOnServerCheckSize() );
01048     mPop.intervalCheck->setChecked( interval >= 1 );
01049     mPop.intervalSpin->setValue( QMAX(1, interval) );
01050 #if 0
01051     mPop.resourceCheck->setChecked( mAccount->resource() );
01052 #endif
01053     mPop.excludeCheck->setChecked( mAccount->checkExclude() );
01054     mPop.precommand->setText( ap.precommand() );
01055     if (ap.useSSL())
01056       mPop.encryptionSSL->setChecked( TRUE );
01057     else if (ap.useTLS())
01058       mPop.encryptionTLS->setChecked( TRUE );
01059     else mPop.encryptionNone->setChecked( TRUE );
01060     if (ap.auth() == "LOGIN")
01061       mPop.authLogin->setChecked( TRUE );
01062     else if (ap.auth() == "PLAIN")
01063       mPop.authPlain->setChecked( TRUE );
01064     else if (ap.auth() == "CRAM-MD5")
01065       mPop.authCRAM_MD5->setChecked( TRUE );
01066     else if (ap.auth() == "DIGEST-MD5")
01067       mPop.authDigestMd5->setChecked( TRUE );
01068     else if (ap.auth() == "APOP")
01069       mPop.authAPOP->setChecked( TRUE );
01070     else mPop.authUser->setChecked( TRUE );
01071 
01072     slotEnablePopInterval( interval >= 1 );
01073     folderCombo = mPop.folderCombo;
01074   }
01075   else if( accountType == "imap" )
01076   {
01077     KMAcctImap &ai = *(KMAcctImap*)mAccount;
01078     mImap.nameEdit->setText( mAccount->name() );
01079     mImap.nameEdit->setFocus();
01080     mImap.loginEdit->setText( ai.login() );
01081     mImap.passwordEdit->setText( ai.passwd());
01082     mImap.hostEdit->setText( ai.host() );
01083     mImap.portEdit->setText( QString("%1").arg( ai.port() ) );
01084     QString prefix = ai.prefix();
01085     if (!prefix.isEmpty() && prefix[0] == '/') prefix = prefix.mid(1);
01086     if (!prefix.isEmpty() && prefix[prefix.length() - 1] == '/')
01087       prefix = prefix.left(prefix.length() - 1);
01088     mImap.prefixEdit->setText( prefix );
01089     mImap.autoExpungeCheck->setChecked( ai.autoExpunge() );
01090     mImap.hiddenFoldersCheck->setChecked( ai.hiddenFolders() );
01091     mImap.subscribedFoldersCheck->setChecked( ai.onlySubscribedFolders() );
01092     mImap.locallySubscribedFoldersCheck->setChecked( ai.onlyLocallySubscribedFolders() );
01093     mImap.loadOnDemandCheck->setChecked( ai.loadOnDemand() );
01094     mImap.listOnlyOpenCheck->setChecked( ai.listOnlyOpenFolders() );
01095     mImap.storePasswordCheck->setChecked( ai.storePasswd() );
01096     mImap.intervalCheck->setChecked( interval >= 1 );
01097     mImap.intervalSpin->setValue( QMAX(1, interval) );
01098 #if 0
01099     mImap.resourceCheck->setChecked( ai.resource() );
01100 #endif
01101     mImap.excludeCheck->setChecked( ai.checkExclude() );
01102     mImap.intervalCheck->setChecked( interval >= 1 );
01103     mImap.intervalSpin->setValue( QMAX(1, interval) );
01104     QString trashfolder = ai.trash();
01105     if (trashfolder.isEmpty())
01106       trashfolder = kmkernel->trashFolder()->idString();
01107     mImap.trashCombo->setFolder( trashfolder );
01108     slotEnableImapInterval( interval >= 1 );
01109     if (ai.useSSL())
01110       mImap.encryptionSSL->setChecked( TRUE );
01111     else if (ai.useTLS())
01112       mImap.encryptionTLS->setChecked( TRUE );
01113     else mImap.encryptionNone->setChecked( TRUE );
01114     if (ai.auth() == "CRAM-MD5")
01115       mImap.authCramMd5->setChecked( TRUE );
01116     else if (ai.auth() == "DIGEST-MD5")
01117       mImap.authDigestMd5->setChecked( TRUE );
01118     else if (ai.auth() == "ANONYMOUS")
01119       mImap.authAnonymous->setChecked( TRUE );
01120     else if (ai.auth() == "PLAIN")
01121       mImap.authPlain->setChecked( TRUE );
01122     else if (ai.auth() == "LOGIN")
01123       mImap.authLogin->setChecked( TRUE );
01124     else mImap.authUser->setChecked( TRUE );
01125     if ( mSieveConfigEditor )
01126       mSieveConfigEditor->setConfig( ai.sieveConfig() );
01127   }
01128   else if( accountType == "cachedimap" )
01129   {
01130     KMAcctCachedImap &ai = *(KMAcctCachedImap*)mAccount;
01131     mImap.nameEdit->setText( mAccount->name() );
01132     mImap.nameEdit->setFocus();
01133     mImap.loginEdit->setText( ai.login() );
01134     mImap.passwordEdit->setText( ai.passwd());
01135     mImap.hostEdit->setText( ai.host() );
01136     mImap.portEdit->setText( QString("%1").arg( ai.port() ) );
01137     QString prefix = ai.prefix();
01138     if (!prefix.isEmpty() && prefix[0] == '/') prefix = prefix.mid(1);
01139     if (!prefix.isEmpty() && prefix[prefix.length() - 1] == '/')
01140       prefix = prefix.left(prefix.length() - 1);
01141     mImap.prefixEdit->setText( prefix );
01142     mImap.progressDialogCheck->setChecked( ai.isProgressDialogEnabled() );
01143 #if 0
01144     mImap.resourceCheck->setChecked( ai.resource() );
01145 #endif
01146     mImap.hiddenFoldersCheck->setChecked( ai.hiddenFolders() );
01147     mImap.subscribedFoldersCheck->setChecked( ai.onlySubscribedFolders() );
01148     mImap.locallySubscribedFoldersCheck->setChecked( ai.onlyLocallySubscribedFolders() );
01149     mImap.storePasswordCheck->setChecked( ai.storePasswd() );
01150     mImap.intervalCheck->setChecked( interval >= 1 );
01151     mImap.intervalSpin->setValue( QMAX(1, interval) );
01152     mImap.excludeCheck->setChecked( ai.checkExclude() );
01153     mImap.intervalCheck->setChecked( interval >= 1 );
01154     mImap.intervalSpin->setValue( QMAX(1, interval) );
01155     QString trashfolder = ai.trash();
01156     if (trashfolder.isEmpty())
01157       trashfolder = kmkernel->trashFolder()->idString();
01158     mImap.trashCombo->setFolder( trashfolder );
01159     slotEnableImapInterval( interval >= 1 );
01160     if (ai.useSSL())
01161       mImap.encryptionSSL->setChecked( TRUE );
01162     else if (ai.useTLS())
01163       mImap.encryptionTLS->setChecked( TRUE );
01164     else mImap.encryptionNone->setChecked( TRUE );
01165     if (ai.auth() == "CRAM-MD5")
01166       mImap.authCramMd5->setChecked( TRUE );
01167     else if (ai.auth() == "DIGEST-MD5")
01168       mImap.authDigestMd5->setChecked( TRUE );
01169     else if (ai.auth() == "ANONYMOUS")
01170       mImap.authAnonymous->setChecked( TRUE );
01171     else if (ai.auth() == "PLAIN")
01172       mImap.authPlain->setChecked( TRUE );
01173     else if (ai.auth() == "LOGIN")
01174       mImap.authLogin->setChecked( TRUE );
01175     else mImap.authUser->setChecked( TRUE );
01176     if ( mSieveConfigEditor )
01177       mSieveConfigEditor->setConfig( ai.sieveConfig() );
01178   }
01179   else if( accountType == "maildir" )
01180   {
01181     KMAcctMaildir *acctMaildir = dynamic_cast<KMAcctMaildir*>(mAccount);
01182 
01183     mMaildir.nameEdit->setText( mAccount->name() );
01184     mMaildir.nameEdit->setFocus();
01185     mMaildir.locationEdit->setEditText( acctMaildir->location() );
01186 
01187     mMaildir.intervalSpin->setValue( QMAX(1, interval) );
01188     mMaildir.intervalCheck->setChecked( interval >= 1 );
01189 #if 0
01190     mMaildir.resourceCheck->setChecked( mAccount->resource() );
01191 #endif
01192     mMaildir.excludeCheck->setChecked( mAccount->checkExclude() );
01193     mMaildir.precommand->setText( mAccount->precommand() );
01194 
01195     slotEnableMaildirInterval( interval >= 1 );
01196     folderCombo = mMaildir.folderCombo;
01197   }
01198   else // Unknown account type
01199     return;
01200 
01201   if (!folderCombo) return;
01202 
01203   KMFolderDir *fdir = (KMFolderDir*)&kmkernel->folderMgr()->dir();
01204   KMFolder *acctFolder = mAccount->folder();
01205   if( acctFolder == 0 )
01206   {
01207     acctFolder = (KMFolder*)fdir->first();
01208   }
01209   if( acctFolder == 0 )
01210   {
01211     folderCombo->insertItem( i18n("<none>") );
01212   }
01213   else
01214   {
01215     uint i = 0;
01216     int curIndex = -1;
01217     kmkernel->folderMgr()->createI18nFolderList(&mFolderNames, &mFolderList);
01218     while (i < mFolderNames.count())
01219     {
01220       QValueList<QGuardedPtr<KMFolder> >::Iterator it = mFolderList.at(i);
01221       KMFolder *folder = *it;
01222       if (folder->isSystemFolder())
01223       {
01224         mFolderList.remove(it);
01225         mFolderNames.remove(mFolderNames.at(i));
01226       } else {
01227         if (folder == acctFolder) curIndex = i;
01228         i++;
01229       }
01230     }
01231     mFolderNames.prepend(i18n("inbox"));
01232     mFolderList.prepend(kmkernel->inboxFolder());
01233     folderCombo->insertStringList(mFolderNames);
01234     folderCombo->setCurrentItem(curIndex + 1);
01235 
01236     // -sanders hack for startup users. Must investigate this properly
01237     if (folderCombo->count() == 0)
01238       folderCombo->insertItem( i18n("inbox") );
01239   }
01240 }
01241 
01242 
01243 void AccountDialog::slotLeaveOnServerClicked()
01244 {
01245   if ( !( mCurCapa & UIDL ) && mPop.leaveOnServerCheck->isChecked() ) {
01246     KMessageBox::information( topLevelWidget(),
01247                               i18n("The server does not seem to support unique "
01248                                    "message numbers, but this is a "
01249                                    "requirement for leaving messages on the "
01250                                    "server.\n"
01251                                    "Since some servers do not correctly "
01252                                    "announce their capabilities you still "
01253                                    "have the possibility to turn leaving "
01254                                    "fetched messages on the server on.") );
01255   }
01256 }
01257 
01258 void AccountDialog::slotFilterOnServerClicked()
01259 {
01260   if ( !( mCurCapa & TOP ) && mPop.filterOnServerCheck->isChecked() ) {
01261     KMessageBox::information( topLevelWidget(),
01262                               i18n("The server does not seem to support "
01263                                    "fetching message headers, but this is a "
01264                                    "requirement for filtering messages on the "
01265                                    "server.\n"
01266                                    "Since some servers do not correctly "
01267                                    "announce their capabilities you still "
01268                                    "have the possibility to turn filtering "
01269                                    "messages on the server on.") );
01270   }
01271 }
01272 
01273 void AccountDialog::slotPipeliningClicked()
01274 {
01275   if (mPop.usePipeliningCheck->isChecked())
01276     KMessageBox::information( topLevelWidget(),
01277       i18n("Please note that this feature can cause some POP3 servers "
01278       "that do not support pipelining to send corrupted mail;\n"
01279       "this is configurable, though, because some servers support pipelining "
01280       "but do not announce their capabilities. To check whether your POP3 server "
01281       "announces pipelining support use the \"Check What the Server "
01282       "Supports\" button at the bottom of the dialog;\n"
01283       "if your server does not announce it, but you want more speed, then "
01284       "you should do some testing first by sending yourself a batch "
01285       "of mail and downloading it."), QString::null,
01286       "pipelining");
01287 }
01288 
01289 
01290 void AccountDialog::slotPopEncryptionChanged(int id)
01291 {
01292   kdDebug(5006) << "slotPopEncryptionChanged( " << id << " )" << endl;
01293   // adjust port
01294   if ( id == SSL || mPop.portEdit->text() == "995" )
01295     mPop.portEdit->setText( ( id == SSL ) ? "995" : "110" );
01296 
01297   // switch supported auth methods
01298   mCurCapa = ( id == TLS ) ? mCapaTLS
01299                            : ( id == SSL ) ? mCapaSSL
01300                                            : mCapaNormal;
01301   enablePopFeatures( mCurCapa );
01302   const QButton *old = mPop.authGroup->selected();
01303   if ( !old->isEnabled() )
01304     checkHighest( mPop.authGroup );
01305 }
01306 
01307 
01308 void AccountDialog::slotImapEncryptionChanged(int id)
01309 {
01310   kdDebug(5006) << "slotImapEncryptionChanged( " << id << " )" << endl;
01311   // adjust port
01312   if ( id == SSL || mImap.portEdit->text() == "993" )
01313     mImap.portEdit->setText( ( id == SSL ) ? "993" : "143" );
01314 
01315   // switch supported auth methods
01316   int authMethods = ( id == TLS ) ? mCapaTLS
01317                                   : ( id == SSL ) ? mCapaSSL
01318                                                   : mCapaNormal;
01319   enableImapAuthMethods( authMethods );
01320   QButton *old = mImap.authGroup->selected();
01321   if ( !old->isEnabled() )
01322     checkHighest( mImap.authGroup );
01323 }
01324 
01325 
01326 void AccountDialog::slotCheckPopCapabilities()
01327 {
01328   if ( mPop.hostEdit->text().isEmpty() || mPop.portEdit->text().isEmpty() )
01329   {
01330      KMessageBox::sorry( this, i18n( "Please specify a server and port on "
01331               "the General tab first." ) );
01332      return;
01333   }
01334   delete mServerTest;
01335   mServerTest = new KMServerTest(POP_PROTOCOL, mPop.hostEdit->text(),
01336     mPop.portEdit->text().toInt());
01337   connect( mServerTest, SIGNAL( capabilities( const QStringList &,
01338                                               const QStringList & ) ),
01339            this, SLOT( slotPopCapabilities( const QStringList &,
01340                                             const QStringList & ) ) );
01341   mPop.checkCapabilities->setEnabled(FALSE);
01342 }
01343 
01344 
01345 void AccountDialog::slotCheckImapCapabilities()
01346 {
01347   if ( mImap.hostEdit->text().isEmpty() || mImap.portEdit->text().isEmpty() )
01348   {
01349      KMessageBox::sorry( this, i18n( "Please specify a server and port on "
01350               "the General tab first." ) );
01351      return;
01352   }
01353   delete mServerTest;
01354   mServerTest = new KMServerTest(IMAP_PROTOCOL, mImap.hostEdit->text(),
01355     mImap.portEdit->text().toInt());
01356   connect( mServerTest, SIGNAL( capabilities( const QStringList &,
01357                                               const QStringList & ) ),
01358            this, SLOT( slotImapCapabilities( const QStringList &,
01359                                              const QStringList & ) ) );
01360   mImap.checkCapabilities->setEnabled(FALSE);
01361 }
01362 
01363 
01364 unsigned int AccountDialog::popCapabilitiesFromStringList( const QStringList & l )
01365 {
01366   unsigned int capa = 0;
01367   for ( QStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
01368     QString cur = (*it).upper();
01369     if ( cur == "PLAIN" )
01370       capa |= Plain;
01371     else if ( cur == "LOGIN" )
01372       capa |= Login;
01373     else if ( cur == "CRAM-MD5" )
01374       capa |= CRAM_MD5;
01375     else if ( cur == "DIGEST-MD5" )
01376       capa |= Digest_MD5;
01377     else if ( cur == "APOP" )
01378       capa |= APOP;
01379     else if ( cur == "PIPELINING" )
01380       capa |= Pipelining;
01381     else if ( cur == "TOP" )
01382       capa |= TOP;
01383     else if ( cur == "UIDL" )
01384       capa |= UIDL;
01385     else if ( cur == "STLS" )
01386       capa |= STLS;
01387   }
01388   return capa;
01389 }
01390 
01391 
01392 void AccountDialog::slotPopCapabilities( const QStringList & capaNormal,
01393                                          const QStringList & capaSSL )
01394 {
01395   mPop.checkCapabilities->setEnabled( true );
01396   mCapaNormal = popCapabilitiesFromStringList( capaNormal );
01397   if ( mCapaNormal & STLS )
01398     mCapaTLS = mCapaNormal;
01399   else
01400     mCapaTLS = 0;
01401   mCapaSSL = popCapabilitiesFromStringList( capaSSL );
01402   kdDebug(5006) << "mCapaNormal = " << mCapaNormal
01403                 << "; mCapaSSL = " << mCapaSSL
01404                 << "; mCapaTLS = " << mCapaTLS << endl;
01405   mPop.encryptionNone->setEnabled( !capaNormal.isEmpty() );
01406   mPop.encryptionSSL->setEnabled( !capaSSL.isEmpty() );
01407   mPop.encryptionTLS->setEnabled( mCapaTLS != 0 );
01408   checkHighest( mPop.encryptionGroup );
01409   delete mServerTest;
01410   mServerTest = 0;
01411 }
01412 
01413 
01414 void AccountDialog::enablePopFeatures( unsigned int capa )
01415 {
01416   kdDebug(5006) << "enablePopFeatures( " << capa << " )" << endl;
01417   mPop.authPlain->setEnabled( capa & Plain );
01418   mPop.authLogin->setEnabled( capa & Login );
01419   mPop.authCRAM_MD5->setEnabled( capa & CRAM_MD5 );
01420   mPop.authDigestMd5->setEnabled( capa & Digest_MD5 );
01421   mPop.authAPOP->setEnabled( capa & APOP );
01422   if ( !( capa & Pipelining ) && mPop.usePipeliningCheck->isChecked() ) {
01423     mPop.usePipeliningCheck->setChecked( false );
01424     KMessageBox::information( topLevelWidget(),
01425                               i18n("The server does not seem to support "
01426                                    "pipelining; therefore, this option has "
01427                                    "been disabled.\n"
01428                                    "Since some servers do not correctly "
01429                                    "announce their capabilities you still "
01430                                    "have the possibility to turn pipelining "
01431                                    "on. But please note that this feature can "
01432                                    "cause some POP servers that do not "
01433                                    "support pipelining to send corrupt "
01434                                    "messages. So before using this feature "
01435                                    "with important mail you should first "
01436                                    "test it by sending yourself a larger "
01437                                    "number of test messages which you all "
01438                                    "download in one go from the POP "
01439                                    "server.") );
01440   }
01441   if ( !( capa & UIDL ) && mPop.leaveOnServerCheck->isChecked() ) {
01442     mPop.leaveOnServerCheck->setChecked( false );
01443     KMessageBox::information( topLevelWidget(),
01444                               i18n("The server does not seem to support unique "
01445                                    "message numbers, but this is a "
01446                                    "requirement for leaving messages on the "
01447                                    "server; therefore, this option has been "
01448                                    "disabled.\n"
01449                                    "Since some servers do not correctly "
01450                                    "announce their capabilities you still "
01451                                    "have the possibility to turn leaving "
01452                                    "fetched messages on the server on.") );
01453   }
01454   if ( !( capa & TOP ) && mPop.filterOnServerCheck->isChecked() ) {
01455     mPop.filterOnServerCheck->setChecked( false );
01456     KMessageBox::information( topLevelWidget(),
01457                               i18n("The server does not seem to support "
01458                                    "fetching message headers, but this is a "
01459                                    "requirement for filtering messages on the "
01460                                    "server; therefore, this option has been "
01461                                    "disabled.\n"
01462                                    "Since some servers do not correctly "
01463                                    "announce their capabilities you still "
01464                                    "have the possibility to turn filtering "
01465                                    "messages on the server on.") );
01466   }
01467 }
01468 
01469 
01470 unsigned int AccountDialog::imapCapabilitiesFromStringList( const QStringList & l )
01471 {
01472   unsigned int capa = 0;
01473   for ( QStringList::const_iterator it = l.begin() ; it != l.end() ; ++it ) {
01474     QString cur = (*it).upper();
01475     if ( cur == "AUTH=PLAIN" )
01476       capa |= Plain;
01477     else if ( cur == "AUTH=LOGIN" )
01478       capa |= Login;
01479     else if ( cur == "AUTH=CRAM-MD5" )
01480       capa |= CRAM_MD5;
01481     else if ( cur == "AUTH=DIGEST-MD5" )
01482       capa |= Digest_MD5;
01483     else if ( cur == "AUTH=ANONYMOUS" )
01484       capa |= Anonymous;
01485     else if ( cur == "STARTTLS" )
01486       capa |= STARTTLS;
01487   }
01488   return capa;
01489 }
01490 
01491 
01492 void AccountDialog::slotImapCapabilities( const QStringList & capaNormal,
01493                                           const QStringList & capaSSL )
01494 {
01495   mImap.checkCapabilities->setEnabled( true );
01496   mCapaNormal = imapCapabilitiesFromStringList( capaNormal );
01497   if ( mCapaNormal & STARTTLS )
01498     mCapaTLS = mCapaNormal;
01499   else
01500     mCapaTLS = 0;
01501   mCapaSSL = imapCapabilitiesFromStringList( capaSSL );
01502   kdDebug(5006) << "mCapaNormal = " << mCapaNormal
01503                 << "; mCapaSSL = " << mCapaSSL
01504                 << "; mCapaTLS = " << mCapaTLS << endl;
01505   mImap.encryptionNone->setEnabled( !capaNormal.isEmpty() );
01506   mImap.encryptionSSL->setEnabled( !capaSSL.isEmpty() );
01507   mImap.encryptionTLS->setEnabled( mCapaTLS != 0 );
01508   checkHighest( mImap.encryptionGroup );
01509   delete mServerTest;
01510   mServerTest = 0;
01511 }
01512 
01513 
01514 void AccountDialog::enableImapAuthMethods( unsigned int capa )
01515 {
01516   kdDebug(5006) << "enableImapAuthMethods( " << capa << " )" << endl;
01517   mImap.authPlain->setEnabled( capa & Plain );
01518   mImap.authLogin->setEnabled( capa & Login );
01519   mImap.authCramMd5->setEnabled( capa & CRAM_MD5 );
01520   mImap.authDigestMd5->setEnabled( capa & Digest_MD5 );
01521   mImap.authAnonymous->setEnabled( capa & Anonymous );
01522 }
01523 
01524 
01525 void AccountDialog::checkHighest( QButtonGroup *btnGroup )
01526 {
01527   kdDebug(5006) << "checkHighest( " << btnGroup << " )" << endl;
01528   for ( int i = btnGroup->count() - 1; i >= 0 ; --i ) {
01529     QButton * btn = btnGroup->find( i );
01530     if ( btn && btn->isEnabled() ) {
01531       btn->animateClick();
01532       return;
01533     }
01534   }
01535 }
01536 
01537 
01538 void AccountDialog::slotOk()
01539 {
01540   saveSettings();
01541   accept();
01542 }
01543 
01544 
01545 void AccountDialog::saveSettings()
01546 {
01547   QString accountType = mAccount->type();
01548   if( accountType == "local" )
01549   {
01550     KMAcctLocal *acctLocal = dynamic_cast<KMAcctLocal*>(mAccount);
01551 
01552     if (acctLocal) {
01553       mAccount->setName( mLocal.nameEdit->text() );
01554       acctLocal->setLocation( mLocal.locationEdit->currentText() );
01555       if (mLocal.lockMutt->isChecked())
01556         acctLocal->setLockType(mutt_dotlock);
01557       else if (mLocal.lockMuttPriv->isChecked())
01558         acctLocal->setLockType(mutt_dotlock_privileged);
01559       else if (mLocal.lockProcmail->isChecked()) {
01560         acctLocal->setLockType(procmail_lockfile);
01561         acctLocal->setProcmailLockFileName(mLocal.procmailLockFileName->currentText());
01562       }
01563       else if (mLocal.lockNone->isChecked())
01564         acctLocal->setLockType(lock_none);
01565       else acctLocal->setLockType(FCNTL);
01566     }
01567 
01568     mAccount->setCheckInterval( mLocal.intervalCheck->isChecked() ?
01569                  mLocal.intervalSpin->value() : 0 );
01570 #if 0
01571     mAccount->setResource( mLocal.resourceCheck->isChecked() );
01572 #endif
01573     mAccount->setCheckExclude( mLocal.excludeCheck->isChecked() );
01574 
01575     mAccount->setPrecommand( mLocal.precommand->text() );
01576 
01577     mAccount->setFolder( *mFolderList.at(mLocal.folderCombo->currentItem()) );
01578 
01579   }
01580   else if( accountType == "pop" )
01581   {
01582     mAccount->setName( mPop.nameEdit->text() );
01583     mAccount->setCheckInterval( mPop.intervalCheck->isChecked() ?
01584                  mPop.intervalSpin->value() : 0 );
01585 #if 0
01586     mAccount->setResource( mPop.resourceCheck->isChecked() );
01587 #endif
01588     mAccount->setCheckExclude( mPop.excludeCheck->isChecked() );
01589 
01590     mAccount->setFolder( *mFolderList.at(mPop.folderCombo->currentItem()) );
01591 
01592     KMAcctExpPop &epa = *(KMAcctExpPop*)mAccount;
01593     epa.setHost( mPop.hostEdit->text().stripWhiteSpace() );
01594     epa.setPort( mPop.portEdit->text().toInt() );
01595     epa.setLogin( mPop.loginEdit->text().stripWhiteSpace() );
01596     epa.setPasswd( mPop.passwordEdit->text(), true );
01597     epa.setUsePipelining( mPop.usePipeliningCheck->isChecked() );
01598     epa.setStorePasswd( mPop.storePasswordCheck->isChecked() );
01599     epa.setPasswd( mPop.passwordEdit->text(), epa.storePasswd() );
01600     epa.setLeaveOnServer( mPop.leaveOnServerCheck->isChecked() );
01601     epa.setFilterOnServer( mPop.filterOnServerCheck->isChecked() );
01602     epa.setFilterOnServerCheckSize (mPop.filterOnServerSizeSpin->value() );
01603     epa.setPrecommand( mPop.precommand->text() );
01604     epa.setUseSSL( mPop.encryptionSSL->isChecked() );
01605     epa.setUseTLS( mPop.encryptionTLS->isChecked() );
01606     if (mPop.authUser->isChecked())
01607       epa.setAuth("USER");
01608     else if (mPop.authLogin->isChecked())
01609       epa.setAuth("LOGIN");
01610     else if (mPop.authPlain->isChecked())
01611       epa.setAuth("PLAIN");
01612     else if (mPop.authCRAM_MD5->isChecked())
01613       epa.setAuth("CRAM-MD5");
01614     else if (mPop.authDigestMd5->isChecked())
01615       epa.setAuth("DIGEST-MD5");
01616     else if (mPop.authAPOP->isChecked())
01617       epa.setAuth("APOP");
01618     else epa.setAuth("AUTO");
01619   }
01620   else if( accountType == "imap" )
01621   {
01622     mAccount->setName( mImap.nameEdit->text() );
01623     mAccount->setCheckInterval( mImap.intervalCheck->isChecked() ?
01624                                 mImap.intervalSpin->value() : 0 );
01625 #if 0
01626     mAccount->setResource( mImap.resourceCheck->isChecked() );
01627 #endif
01628     mAccount->setCheckExclude( mImap.excludeCheck->isChecked() );
01629     mAccount->setFolder( kmkernel->imapFolderMgr()->findById(mAccount->id()) );
01630 
01631     KMAcctImap &epa = *(KMAcctImap*)mAccount;
01632     epa.setHost( mImap.hostEdit->text().stripWhiteSpace() );
01633     epa.setPort( mImap.portEdit->text().toInt() );
01634     QString prefix = "/" + mImap.prefixEdit->text();
01635     if (prefix[prefix.length() - 1] != '/') prefix += "/";
01636     epa.setPrefix( prefix );
01637     epa.setLogin( mImap.loginEdit->text().stripWhiteSpace() );
01638     epa.setAutoExpunge( mImap.autoExpungeCheck->isChecked() );
01639     epa.setHiddenFolders( mImap.hiddenFoldersCheck->isChecked() );
01640     epa.setOnlySubscribedFolders( mImap.subscribedFoldersCheck->isChecked() );
01641     epa.setOnlyLocallySubscribedFolders( mImap.locallySubscribedFoldersCheck->isChecked() );
01642     epa.setLoadOnDemand( mImap.loadOnDemandCheck->isChecked() );
01643     epa.setListOnlyOpenFolders( mImap.listOnlyOpenCheck->isChecked() );
01644     epa.setStorePasswd( mImap.storePasswordCheck->isChecked() );
01645     epa.setPasswd( mImap.passwordEdit->text(), epa.storePasswd() );
01646     KMFolder *t = mImap.trashCombo->getFolder();
01647     if ( t )
01648       epa.setTrash( mImap.trashCombo->getFolder()->idString() );
01649     else
01650       epa.setTrash( kmkernel->trashFolder()->idString() );
01651 #if 0
01652     epa.setResource( mImap.resourceCheck->isChecked() );
01653 #endif
01654     epa.setCheckExclude( mImap.excludeCheck->isChecked() );
01655     epa.setUseSSL( mImap.encryptionSSL->isChecked() );
01656     epa.setUseTLS( mImap.encryptionTLS->isChecked() );
01657     if (mImap.authCramMd5->isChecked())
01658       epa.setAuth("CRAM-MD5");
01659     else if (mImap.authDigestMd5->isChecked())
01660       epa.setAuth("DIGEST-MD5");
01661     else if (mImap.authAnonymous->isChecked())
01662       epa.setAuth("ANONYMOUS");
01663     else if (mImap.authLogin->isChecked())
01664       epa.setAuth("LOGIN");
01665     else if (mImap.authPlain->isChecked())
01666       epa.setAuth("PLAIN");
01667     else epa.setAuth("*");
01668     if ( mSieveConfigEditor )
01669       epa.setSieveConfig( mSieveConfigEditor->config() );
01670   }
01671   else if( accountType == "cachedimap" )
01672   {
01673     mAccount->setName( mImap.nameEdit->text() );
01674     mAccount->setCheckInterval( mImap.intervalCheck->isChecked() ?
01675                                 mImap.intervalSpin->value() : 0 );
01676 #if 0
01677     mAccount->setResource( mImap.resourceCheck->isChecked() );
01678 #endif
01679     mAccount->setCheckExclude( mImap.excludeCheck->isChecked() );
01680     //mAccount->setFolder( NULL );
01681     mAccount->setFolder( kmkernel->dimapFolderMgr()->findById(mAccount->id()) );
01682     kdDebug(5006) << mAccount->name() << endl;
01683     //kdDebug(5006) << "account for folder " << mAccount->folder()->name() << endl;
01684 
01685     KMAcctCachedImap &epa = *(KMAcctCachedImap*)mAccount;
01686     epa.setHost( mImap.hostEdit->text().stripWhiteSpace() );
01687     epa.setPort( mImap.portEdit->text().toInt() );
01688     QString prefix = "/" + mImap.prefixEdit->text();
01689     if (prefix[prefix.length() - 1] != '/') prefix += "/";
01690     epa.setPrefix( prefix );
01691     epa.setLogin( mImap.loginEdit->text().stripWhiteSpace() );
01692     epa.setProgressDialogEnabled( mImap.progressDialogCheck->isChecked() );
01693     epa.setHiddenFolders( mImap.hiddenFoldersCheck->isChecked() );
01694     epa.setOnlySubscribedFolders( mImap.subscribedFoldersCheck->isChecked() );
01695     epa.setOnlyLocallySubscribedFolders( mImap.locallySubscribedFoldersCheck->isChecked() );
01696     epa.setStorePasswd( mImap.storePasswordCheck->isChecked() );
01697     epa.setPasswd( mImap.passwordEdit->text(), epa.storePasswd() );
01698     KMFolder *t = mImap.trashCombo->getFolder();
01699     if ( t )
01700       epa.setTrash( mImap.trashCombo->getFolder()->idString() );
01701     else
01702       epa.setTrash( kmkernel->trashFolder()->idString() );
01703 #if 0
01704     epa.setResource( mImap.resourceCheck->isChecked() );
01705 #endif
01706     epa.setCheckExclude( mImap.excludeCheck->isChecked() );
01707     epa.setUseSSL( mImap.encryptionSSL->isChecked() );
01708     epa.setUseTLS( mImap.encryptionTLS->isChecked() );
01709     if (mImap.authCramMd5->isChecked())
01710       epa.setAuth("CRAM-MD5");
01711     else if (mImap.authDigestMd5->isChecked())
01712       epa.setAuth("DIGEST-MD5");
01713     else if (mImap.authAnonymous->isChecked())
01714       epa.setAuth("ANONYMOUS");
01715     else if (mImap.authLogin->isChecked())
01716       epa.setAuth("LOGIN");
01717     else if (mImap.authPlain->isChecked())
01718       epa.setAuth("PLAIN");
01719     else epa.setAuth("*");
01720     if ( mSieveConfigEditor )
01721       epa.setSieveConfig( mSieveConfigEditor->config() );
01722   }
01723   else if( accountType == "maildir" )
01724   {
01725     KMAcctMaildir *acctMaildir = dynamic_cast<KMAcctMaildir*>(mAccount);
01726 
01727     if (acctMaildir) {
01728         mAccount->setName( mMaildir.nameEdit->text() );
01729         acctMaildir->setLocation( mMaildir.locationEdit->currentText() );
01730 
01731         KMFolder *targetFolder = *mFolderList.at(mMaildir.folderCombo->currentItem());
01732         if ( targetFolder->location()  == acctMaildir->location() ) {
01733             /*
01734                Prevent data loss if the user sets the destination folder to be the same as the
01735                source account maildir folder by setting the target folder to the inbox.
01736                ### FIXME post 3.2: show dialog and let the user chose another target folder
01737             */
01738             targetFolder = kmkernel->inboxFolder();
01739         }
01740         mAccount->setFolder( targetFolder );
01741     }
01742     mAccount->setCheckInterval( mMaildir.intervalCheck->isChecked() ?
01743                  mMaildir.intervalSpin->value() : 0 );
01744 #if 0
01745     mAccount->setResource( mMaildir.resourceCheck->isChecked() );
01746 #endif
01747     mAccount->setCheckExclude( mMaildir.excludeCheck->isChecked() );
01748 
01749     mAccount->setPrecommand( mMaildir.precommand->text() );
01750   }
01751 
01752   kmkernel->acctMgr()->writeConfig(TRUE);
01753 
01754   // get the new account and register the new destination folder
01755   // this is the target folder for local or pop accounts and the root folder
01756   // of the account for (d)imap
01757   KMAccount* newAcct = kmkernel->acctMgr()->find(mAccount->id());
01758   if (newAcct)
01759   {
01760     if( accountType == "local" ) {
01761       newAcct->setFolder( *mFolderList.at(mLocal.folderCombo->currentItem()), true );
01762     } else if ( accountType == "pop" ) {
01763       newAcct->setFolder( *mFolderList.at(mPop.folderCombo->currentItem()), true );
01764     } else if ( accountType == "maildir" ) {
01765       newAcct->setFolder( *mFolderList.at(mMaildir.folderCombo->currentItem()), true );
01766     } else if ( accountType == "imap" ) {
01767       newAcct->setFolder( kmkernel->imapFolderMgr()->findById(mAccount->id()), true );
01768     } else if ( accountType == "cachedimap" ) {
01769       newAcct->setFolder( kmkernel->dimapFolderMgr()->findById(mAccount->id()), true );
01770     }
01771   }
01772 }
01773 
01774 
01775 void AccountDialog::slotLocationChooser()
01776 {
01777   static QString directory( "/" );
01778 
01779   KFileDialog dialog( directory, QString::null, this, 0, true );
01780   dialog.setCaption( i18n("Choose Location") );
01781 
01782   bool result = dialog.exec();
01783   if( result == false )
01784   {
01785     return;
01786   }
01787 
01788   KURL url = dialog.selectedURL();
01789   if( url.isEmpty() )
01790   {
01791     return;
01792   }
01793   if( url.isLocalFile() == false )
01794   {
01795     KMessageBox::sorry( 0, i18n( "Only local files are currently supported." ) );
01796     return;
01797   }
01798 
01799   mLocal.locationEdit->setEditText( url.path() );
01800   directory = url.directory();
01801 }
01802 
01803 void AccountDialog::slotMaildirChooser()
01804 {
01805   static QString directory( "/" );
01806 
01807   QString dir = KFileDialog::getExistingDirectory(directory, this, i18n("Choose Location"));
01808 
01809   if( dir.isEmpty() )
01810     return;
01811 
01812   mMaildir.locationEdit->setEditText( dir );
01813   directory = dir;
01814 }
01815 
01816 
01817 void AccountDialog::slotEnablePopInterval( bool state )
01818 {
01819   mPop.intervalSpin->setEnabled( state );
01820   mPop.intervalLabel->setEnabled( state );
01821 }
01822 
01823 void AccountDialog::slotEnableImapInterval( bool state )
01824 {
01825   mImap.intervalSpin->setEnabled( state );
01826   mImap.intervalLabel->setEnabled( state );
01827 }
01828 
01829 void AccountDialog::slotEnableLocalInterval( bool state )
01830 {
01831   mLocal.intervalSpin->setEnabled( state );
01832   mLocal.intervalLabel->setEnabled( state );
01833 }
01834 
01835 void AccountDialog::slotEnableMaildirInterval( bool state )
01836 {
01837   mMaildir.intervalSpin->setEnabled( state );
01838   mMaildir.intervalLabel->setEnabled( state );
01839 }
01840 
01841 void AccountDialog::slotFontChanged( void )
01842 {
01843   QString accountType = mAccount->type();
01844   if( accountType == "local" )
01845   {
01846     QFont titleFont( mLocal.titleLabel->font() );
01847     titleFont.setBold( true );
01848     mLocal.titleLabel->setFont(titleFont);
01849   }
01850   else if( accountType == "pop" )
01851   {
01852     QFont titleFont( mPop.titleLabel->font() );
01853     titleFont.setBold( true );
01854     mPop.titleLabel->setFont(titleFont);
01855   }
01856   else if( accountType == "imap" )
01857   {
01858     QFont titleFont( mImap.titleLabel->font() );
01859     titleFont.setBold( true );
01860     mImap.titleLabel->setFont(titleFont);
01861   }
01862 }
01863 
01864 
01865 
01866 #if 0
01867 void AccountDialog::slotClearResourceAllocations()
01868 {
01869     mAccount->clearIntervals();
01870 }
01871 
01872 
01873 void AccountDialog::slotClearPastResourceAllocations()
01874 {
01875     mAccount->clearOldIntervals();
01876 }
01877 #endif
01878 
01879 #include "accountdialog.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 2 09:54:55 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003