kmail Library API Documentation

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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 } 00044 00045 void SieveConfig::writeConfig( KConfigBase & config ) const { 00046 config.writeEntry( "sieve-support", managesieveSupported() ); 00047 config.writeEntry( "sieve-reuse-config", reuseConfig() ); 00048 config.writeEntry( "sieve-port", port() ); 00049 config.writeEntry( "sieve-alternate-url", mAlternateURL.url() ); 00050 } 00051 00052 00053 SieveConfigEditor::SieveConfigEditor( QWidget * parent, const char * name ) 00054 : QWidget( parent, name ) 00055 { 00056 // tmp. vars: 00057 int row = -1; 00058 QLabel * label; 00059 00060 QGridLayout * glay = new QGridLayout( this, 5, 2, 0, KDialog::spacingHint() ); 00061 glay->setRowStretch( 4, 1 ); 00062 glay->setColStretch( 1, 1 ); 00063 00064 00065 // "Server supports sieve" checkbox: 00066 ++row; 00067 mManagesieveCheck = new QCheckBox( i18n("&Server supports Sieve"), this ); 00068 glay->addMultiCellWidget( mManagesieveCheck, row, row, 0, 1 ); 00069 00070 connect( mManagesieveCheck, SIGNAL(toggled(bool)), SLOT(slotEnableWidgets()) ); 00071 00072 // "reuse host and login config" checkbox: 00073 ++row; 00074 mSameConfigCheck = new QCheckBox( i18n("&Reuse host and login configuration"), this ); 00075 mSameConfigCheck->setChecked( true ); 00076 mSameConfigCheck->setEnabled( false ); 00077 glay->addMultiCellWidget( mSameConfigCheck, row, row, 0, 1 ); 00078 00079 connect( mSameConfigCheck, SIGNAL(toggled(bool)), SLOT(slotEnableWidgets()) ); 00080 00081 // "Managesieve port" spinbox and label: 00082 ++row; 00083 mPortSpin = new KIntSpinBox( 1, USHRT_MAX, 1, 2000, 10, this ); 00084 mPortSpin->setEnabled( false ); 00085 label = new QLabel( mPortSpin, i18n("Managesieve &port:"), this ); 00086 glay->addWidget( label, row, 0 ); 00087 glay->addWidget( mPortSpin, row, 1 ); 00088 00089 // "Alternate URL" lineedit and label: 00090 ++row; 00091 mAlternateURLEdit = new KLineEdit( this ); 00092 mAlternateURLEdit->setEnabled( false ); 00093 glay->addWidget( new QLabel( mAlternateURLEdit, i18n("&Alternate URL:"), this ), row, 0 ); 00094 glay->addWidget( mAlternateURLEdit, row, 1 ); 00095 00096 // row 4 is spacer 00097 00098 } 00099 00100 void SieveConfigEditor::slotEnableWidgets() { 00101 bool haveSieve = mManagesieveCheck->isChecked(); 00102 bool reuseConfig = mSameConfigCheck->isChecked(); 00103 00104 mSameConfigCheck->setEnabled( haveSieve ); 00105 mPortSpin->setEnabled( haveSieve && reuseConfig ); 00106 mAlternateURLEdit->setEnabled( haveSieve && !reuseConfig ); 00107 } 00108 00109 bool SieveConfigEditor::managesieveSupported() const { 00110 return mManagesieveCheck->isChecked(); 00111 } 00112 00113 void SieveConfigEditor::setManagesieveSupported( bool enable ) { 00114 mManagesieveCheck->setChecked( enable ); 00115 } 00116 00117 bool SieveConfigEditor::reuseConfig() const { 00118 return mSameConfigCheck->isChecked(); 00119 } 00120 00121 void SieveConfigEditor::setReuseConfig( bool reuse ) { 00122 mSameConfigCheck->setChecked( reuse ); 00123 } 00124 00125 unsigned short SieveConfigEditor::port() const { 00126 return static_cast<unsigned short>( mPortSpin->value() ); 00127 } 00128 00129 void SieveConfigEditor::setPort( unsigned short port ) { 00130 mPortSpin->setValue( port ); 00131 } 00132 00133 KURL SieveConfigEditor::alternateURL() const { 00134 KURL url ( mAlternateURLEdit->text() ); 00135 if ( !url.isValid() ) 00136 return KURL(); 00137 00138 if ( url.hasPass() ) 00139 url.setPass( QString::null ); 00140 00141 return url; 00142 } 00143 00144 void SieveConfigEditor::setAlternateURL( const KURL & url ) { 00145 mAlternateURLEdit->setText( url.url() ); 00146 } 00147 00148 void SieveConfigEditor::setConfig( const SieveConfig & config ) { 00149 setManagesieveSupported( config.managesieveSupported() ); 00150 setReuseConfig( config.reuseConfig() ); 00151 setPort( config.port() ); 00152 setAlternateURL( config.alternateURL() ); 00153 } 00154 00155 } // namespace KMail 00156 00157 #include "sieveconfig.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:51 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003