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