kmail

sieveconfig.cpp

00001 /*  -*- c++ -*-
00002     sieveconfig.cpp
00003 
00004     KMail, the KDE mail client.
00005     Copyright (c) 2002 Marc Mutz <mutz@kde.org>
00006 
00007     This program is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU General Public License,
00009     version 2.0, as published by the Free Software Foundation.
00010     You should have received a copy of the GNU General Public License
00011     along with this program; if not, write to the Free Software Foundation,
00012     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
00013 */
00014 
00015 #ifdef HAVE_CONFIG_H
00016 #include <config.h>
00017 #endif
00018 
00019 #include "sieveconfig.h"
00020 
00021 #include <knuminput.h>
00022 #include <klocale.h>
00023 #include <kdialog.h>
00024 #include <kconfigbase.h>
00025 
00026 #include <qlayout.h>
00027 #include <qcheckbox.h>
00028 #include <qlabel.h>
00029 #include <klineedit.h>
00030 
00031 
00032 namespace KMail {
00033 
00034   void SieveConfig::readConfig( const KConfigBase & config ) {
00035     mManagesieveSupported = config.readBoolEntry( "sieve-support", false );
00036     mReuseConfig = config.readBoolEntry( "sieve-reuse-config", true );
00037 
00038     int port = config.readNumEntry( "sieve-port", 2000 );
00039     if ( port < 1 || port > USHRT_MAX ) port = 2000;
00040     mPort = static_cast<unsigned short>( port );
00041 
00042     mAlternateURL = config.readEntry( "sieve-alternate-url" );
00043     mVacationFileName = config.readEntry( "sieve-vacation-filename", "kmail-vacation.siv" );
00044   }
00045 
00046   void SieveConfig::writeConfig( KConfigBase & config ) const {
00047     config.writeEntry( "sieve-support", managesieveSupported() );
00048     config.writeEntry( "sieve-reuse-config", reuseConfig() );
00049     config.writeEntry( "sieve-port", port() );
00050     config.writeEntry( "sieve-alternate-url", mAlternateURL.url() );
00051     config.writeEntry( "sieve-vacation-filename", mVacationFileName );
00052   }
00053 
00054   SieveConfigEditor::SieveConfigEditor( QWidget * parent, const char * name )
00055     : QWidget( parent, name )
00056   {
00057     // tmp. vars:
00058     int row = -1;
00059     QLabel * label;
00060 
00061     QGridLayout * glay = new QGridLayout( this, 5, 2, 0, KDialog::spacingHint() );
00062     glay->setRowStretch( 4, 1 );
00063     glay->setColStretch( 1, 1 );
00064 
00065 
00066     // "Server supports sieve" checkbox:
00067     ++row;
00068     mManagesieveCheck = new QCheckBox( i18n("&Server supports Sieve"), this );
00069     glay->addMultiCellWidget( mManagesieveCheck, row, row, 0, 1 );
00070 
00071     connect( mManagesieveCheck, SIGNAL(toggled(bool)), SLOT(slotEnableWidgets()) );
00072 
00073     // "reuse host and login config" checkbox:
00074     ++row;
00075     mSameConfigCheck = new QCheckBox( i18n("&Reuse host and login configuration"), this );
00076     mSameConfigCheck->setChecked( true );
00077     mSameConfigCheck->setEnabled( false );
00078     glay->addMultiCellWidget( mSameConfigCheck, row, row, 0, 1 );
00079 
00080     connect( mSameConfigCheck, SIGNAL(toggled(bool)), SLOT(slotEnableWidgets()) );
00081 
00082     // "Managesieve port" spinbox and label:
00083     ++row;
00084     mPortSpin = new KIntSpinBox( 1, USHRT_MAX, 1, 2000, 10, this );
00085     mPortSpin->setEnabled( false );
00086     label = new QLabel( mPortSpin, i18n("Managesieve &port:"), this );
00087     glay->addWidget( label, row, 0 );
00088     glay->addWidget( mPortSpin, row, 1 );
00089 
00090     // "Alternate URL" lineedit and label:
00091     ++row;
00092     mAlternateURLEdit = new KLineEdit( this );
00093     mAlternateURLEdit->setEnabled( false );
00094     glay->addWidget( new QLabel( mAlternateURLEdit, i18n("&Alternate URL:"), this ), row, 0 );
00095     glay->addWidget( mAlternateURLEdit, row, 1 );
00096 
00097     // row 4 is spacer
00098 
00099   }
00100 
00101   void SieveConfigEditor::slotEnableWidgets() {
00102     bool haveSieve = mManagesieveCheck->isChecked();
00103     bool reuseConfig = mSameConfigCheck->isChecked();
00104 
00105     mSameConfigCheck->setEnabled( haveSieve );
00106     mPortSpin->setEnabled( haveSieve && reuseConfig );
00107     mAlternateURLEdit->setEnabled( haveSieve && !reuseConfig );
00108   }
00109 
00110   bool SieveConfigEditor::managesieveSupported() const {
00111     return mManagesieveCheck->isChecked();
00112   }
00113 
00114   void SieveConfigEditor::setManagesieveSupported( bool enable ) {
00115     mManagesieveCheck->setChecked( enable );
00116   }
00117 
00118   bool SieveConfigEditor::reuseConfig() const {
00119     return mSameConfigCheck->isChecked();
00120   }
00121 
00122   void SieveConfigEditor::setReuseConfig( bool reuse ) {
00123     mSameConfigCheck->setChecked( reuse );
00124   }
00125 
00126   unsigned short SieveConfigEditor::port() const {
00127     return static_cast<unsigned short>( mPortSpin->value() );
00128   }
00129 
00130   void SieveConfigEditor::setPort( unsigned short port ) {
00131     mPortSpin->setValue( port );
00132   }
00133 
00134   KURL SieveConfigEditor::alternateURL() const {
00135     KURL url ( mAlternateURLEdit->text() );
00136     if ( !url.isValid() )
00137       return KURL();
00138 
00139     if ( url.hasPass() )
00140       url.setPass( QString::null );
00141 
00142     return url;
00143   }
00144 
00145   void SieveConfigEditor::setAlternateURL( const KURL & url ) {
00146     mAlternateURLEdit->setText( url.url() );
00147   }
00148 
00149 
00150   QString SieveConfigEditor::vacationFileName() const {
00151       return mVacationFileName;
00152   }
00153 
00154   void SieveConfigEditor::setVacationFileName( const QString& name ) {
00155     mVacationFileName = name;
00156   }
00157 
00158   void SieveConfigEditor::setConfig( const SieveConfig & config ) {
00159     setManagesieveSupported( config.managesieveSupported() );
00160     setReuseConfig( config.reuseConfig() );
00161     setPort( config.port() );
00162     setAlternateURL( config.alternateURL() );
00163     setVacationFileName( config.vacationFileName() );
00164   }
00165 
00166 } // namespace KMail
00167 
00168 #include "sieveconfig.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys