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 <tdelocale.h> 00023 #include <kdialog.h> 00024 #include <tdeconfigbase.h> 00025 00026 #include <tqlayout.h> 00027 #include <tqcheckbox.h> 00028 #include <tqlabel.h> 00029 #include <klineedit.h> 00030 00031 00032 namespace KMail { 00033 00034 void SieveConfig::readConfig( const TDEConfigBase & 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 if ( mVacationFileName.isEmpty() ) 00045 mVacationFileName = "kmail-vacation.siv"; 00046 } 00047 00048 void SieveConfig::writeConfig( TDEConfigBase & config ) const { 00049 config.writeEntry( "sieve-support", managesieveSupported() ); 00050 config.writeEntry( "sieve-reuse-config", reuseConfig() ); 00051 config.writeEntry( "sieve-port", port() ); 00052 config.writeEntry( "sieve-alternate-url", mAlternateURL.url() ); 00053 config.writeEntry( "sieve-vacation-filename", mVacationFileName ); 00054 } 00055 00056 SieveConfigEditor::SieveConfigEditor( TQWidget * parent, const char * name ) 00057 : TQWidget( parent, name ) 00058 { 00059 // tmp. vars: 00060 int row = -1; 00061 TQLabel * label; 00062 00063 TQGridLayout * glay = new TQGridLayout( this, 5, 2, 0, KDialog::spacingHint() ); 00064 glay->setRowStretch( 4, 1 ); 00065 glay->setColStretch( 1, 1 ); 00066 00067 00068 // "Server supports sieve" checkbox: 00069 ++row; 00070 mManagesieveCheck = new TQCheckBox( i18n("&Server supports Sieve"), this ); 00071 glay->addMultiCellWidget( mManagesieveCheck, row, row, 0, 1 ); 00072 00073 connect( mManagesieveCheck, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotEnableWidgets()) ); 00074 00075 // "reuse host and login config" checkbox: 00076 ++row; 00077 mSameConfigCheck = new TQCheckBox( i18n("&Reuse host and login configuration"), this ); 00078 mSameConfigCheck->setChecked( true ); 00079 mSameConfigCheck->setEnabled( false ); 00080 glay->addMultiCellWidget( mSameConfigCheck, row, row, 0, 1 ); 00081 00082 connect( mSameConfigCheck, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotEnableWidgets()) ); 00083 00084 // "Managesieve port" spinbox and label: 00085 ++row; 00086 mPortSpin = new KIntSpinBox( 1, USHRT_MAX, 1, 2000, 10, this ); 00087 mPortSpin->setEnabled( false ); 00088 label = new TQLabel( mPortSpin, i18n("Managesieve &port:"), this ); 00089 glay->addWidget( label, row, 0 ); 00090 glay->addWidget( mPortSpin, row, 1 ); 00091 00092 // "Alternate URL" lineedit and label: 00093 ++row; 00094 mAlternateURLEdit = new KLineEdit( this ); 00095 mAlternateURLEdit->setEnabled( false ); 00096 glay->addWidget( new TQLabel( mAlternateURLEdit, i18n("&Alternate URL:"), this ), row, 0 ); 00097 glay->addWidget( mAlternateURLEdit, row, 1 ); 00098 00099 // row 4 is spacer 00100 00101 } 00102 00103 void SieveConfigEditor::slotEnableWidgets() { 00104 bool haveSieve = mManagesieveCheck->isChecked(); 00105 bool reuseConfig = mSameConfigCheck->isChecked(); 00106 00107 mSameConfigCheck->setEnabled( haveSieve ); 00108 mPortSpin->setEnabled( haveSieve && reuseConfig ); 00109 mAlternateURLEdit->setEnabled( haveSieve && !reuseConfig ); 00110 } 00111 00112 bool SieveConfigEditor::managesieveSupported() const { 00113 return mManagesieveCheck->isChecked(); 00114 } 00115 00116 void SieveConfigEditor::setManagesieveSupported( bool enable ) { 00117 mManagesieveCheck->setChecked( enable ); 00118 } 00119 00120 bool SieveConfigEditor::reuseConfig() const { 00121 return mSameConfigCheck->isChecked(); 00122 } 00123 00124 void SieveConfigEditor::setReuseConfig( bool reuse ) { 00125 mSameConfigCheck->setChecked( reuse ); 00126 } 00127 00128 unsigned short SieveConfigEditor::port() const { 00129 return static_cast<unsigned short>( mPortSpin->value() ); 00130 } 00131 00132 void SieveConfigEditor::setPort( unsigned short port ) { 00133 mPortSpin->setValue( port ); 00134 } 00135 00136 KURL SieveConfigEditor::alternateURL() const { 00137 KURL url ( mAlternateURLEdit->text() ); 00138 if ( !url.isValid() ) 00139 return KURL(); 00140 00141 if ( url.hasPass() ) 00142 url.setPass( TQString() ); 00143 00144 return url; 00145 } 00146 00147 void SieveConfigEditor::setAlternateURL( const KURL & url ) { 00148 mAlternateURLEdit->setText( url.url() ); 00149 } 00150 00151 00152 TQString SieveConfigEditor::vacationFileName() const { 00153 return mVacationFileName; 00154 } 00155 00156 void SieveConfigEditor::setVacationFileName( const TQString& name ) { 00157 mVacationFileName = name; 00158 } 00159 00160 void SieveConfigEditor::setConfig( const SieveConfig & config ) { 00161 setManagesieveSupported( config.managesieveSupported() ); 00162 setReuseConfig( config.reuseConfig() ); 00163 setPort( config.port() ); 00164 setAlternateURL( config.alternateURL() ); 00165 setVacationFileName( config.vacationFileName() ); 00166 } 00167 00168 } // namespace KMail 00169 00170 #include "sieveconfig.moc"