kmail

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