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 
00055   SieveConfigEditor::SieveConfigEditor( QWidget * parent, const char * name )
00056     : QWidget( parent, name )
00057   {
00058     // tmp. vars:
00059     int row = -1;
00060     QLabel * label;
00061 
00062     QGridLayout * glay = new QGridLayout( this, 5, 2, 0, KDialog::spacingHint() );
00063     glay->setRowStretch( 4, 1 );
00064     glay->setColStretch( 1, 1 );
00065 
00066 
00067     // "Server supports sieve" checkbox:
00068     ++row;
00069     mManagesieveCheck = new QCheckBox( i18n("&Server supports Sieve"), this );
00070     glay->addMultiCellWidget( mManagesieveCheck, row, row, 0, 1 );
00071 
00072     connect( mManagesieveCheck, SIGNAL(toggled(bool)), SLOT(slotEnableWidgets()) );
00073 
00074     // "reuse host and login config" checkbox:
00075     ++row;
00076     mSameConfigCheck = new QCheckBox( i18n("&Reuse host and login configuration"), this );
00077     mSameConfigCheck->setChecked( true );
00078     mSameConfigCheck->setEnabled( false );
00079     glay->addMultiCellWidget( mSameConfigCheck, row, row, 0, 1 );
00080 
00081     connect( mSameConfigCheck, SIGNAL(toggled(bool)), SLOT(slotEnableWidgets()) );
00082 
00083     // "Managesieve port" spinbox and label:
00084     ++row;
00085     mPortSpin = new KIntSpinBox( 1, USHRT_MAX, 1, 2000, 10, this );
00086     mPortSpin->setEnabled( false );
00087     label = new QLabel( mPortSpin, i18n("Managesieve &port:"), this );
00088     glay->addWidget( label, row, 0 );
00089     glay->addWidget( mPortSpin, row, 1 );
00090 
00091     // "Alternate URL" lineedit and label:
00092     ++row;
00093     mAlternateURLEdit = new KLineEdit( this );
00094     mAlternateURLEdit->setEnabled( false );
00095     glay->addWidget( new QLabel( mAlternateURLEdit, i18n("&Alternate URL:"), this ), row, 0 );
00096     glay->addWidget( mAlternateURLEdit, row, 1 );
00097 
00098     // row 4 is spacer
00099 
00100   }
00101 
00102   void SieveConfigEditor::slotEnableWidgets() {
00103     bool haveSieve = mManagesieveCheck->isChecked();
00104     bool reuseConfig = mSameConfigCheck->isChecked();
00105 
00106     mSameConfigCheck->setEnabled( haveSieve );
00107     mPortSpin->setEnabled( haveSieve && reuseConfig );
00108     mAlternateURLEdit->setEnabled( haveSieve && !reuseConfig );
00109   }
00110 
00111   bool SieveConfigEditor::managesieveSupported() const {
00112     return mManagesieveCheck->isChecked();
00113   }
00114 
00115   void SieveConfigEditor::setManagesieveSupported( bool enable ) {
00116     mManagesieveCheck->setChecked( enable );
00117   }
00118 
00119   bool SieveConfigEditor::reuseConfig() const {
00120     return mSameConfigCheck->isChecked();
00121   }
00122 
00123   void SieveConfigEditor::setReuseConfig( bool reuse ) {
00124     mSameConfigCheck->setChecked( reuse );
00125   }
00126 
00127   unsigned short SieveConfigEditor::port() const {
00128     return static_cast<unsigned short>( mPortSpin->value() );
00129   }
00130 
00131   void SieveConfigEditor::setPort( unsigned short port ) {
00132     mPortSpin->setValue( port );
00133   }
00134 
00135   KURL SieveConfigEditor::alternateURL() const {
00136     KURL url ( mAlternateURLEdit->text() );
00137     if ( !url.isValid() )
00138       return KURL();
00139 
00140     if ( url.hasPass() )
00141       url.setPass( QString::null );
00142 
00143     return url;
00144   }
00145 
00146   void SieveConfigEditor::setAlternateURL( const KURL & url ) {
00147     mAlternateURLEdit->setText( url.url() );
00148   }
00149 
00150   void SieveConfigEditor::setConfig( const SieveConfig & config ) {
00151     setManagesieveSupported( config.managesieveSupported() );
00152     setReuseConfig( config.reuseConfig() );
00153     setPort( config.port() );
00154     setAlternateURL( config.alternateURL() );
00155   }
00156 
00157 } // namespace KMail
00158 
00159 #include "sieveconfig.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys