19 #include "sieveconfig.h"
21 #include <knuminput.h>
22 #include <tdelocale.h>
24 #include <tdeconfigbase.h>
27 #include <tqcheckbox.h>
29 #include <klineedit.h>
34 void SieveConfig::readConfig(
const TDEConfigBase & config ) {
35 mManagesieveSupported = config.readBoolEntry(
"sieve-support",
false );
36 mReuseConfig = config.readBoolEntry(
"sieve-reuse-config",
true );
38 int port = config.readNumEntry(
"sieve-port", 2000 );
39 if ( port < 1 || port > USHRT_MAX ) port = 2000;
40 mPort =
static_cast<unsigned short>( port );
42 mAlternateURL = config.readEntry(
"sieve-alternate-url" );
43 mVacationFileName = config.readEntry(
"sieve-vacation-filename",
"kmail-vacation.siv" );
44 if ( mVacationFileName.isEmpty() )
45 mVacationFileName =
"kmail-vacation.siv";
48 void SieveConfig::writeConfig( TDEConfigBase & config )
const {
49 config.writeEntry(
"sieve-support", managesieveSupported() );
50 config.writeEntry(
"sieve-reuse-config", reuseConfig() );
51 config.writeEntry(
"sieve-port", port() );
52 config.writeEntry(
"sieve-alternate-url", mAlternateURL.url() );
53 config.writeEntry(
"sieve-vacation-filename", mVacationFileName );
56 SieveConfigEditor::SieveConfigEditor( TQWidget * parent,
const char * name )
57 : TQWidget( parent, name )
63 TQGridLayout * glay =
new TQGridLayout(
this, 5, 2, 0, KDialog::spacingHint() );
64 glay->setRowStretch( 4, 1 );
65 glay->setColStretch( 1, 1 );
70 mManagesieveCheck =
new TQCheckBox( i18n(
"&Server supports Sieve"),
this );
71 glay->addMultiCellWidget( mManagesieveCheck, row, row, 0, 1 );
73 connect( mManagesieveCheck, TQ_SIGNAL(toggled(
bool)), TQ_SLOT(slotEnableWidgets()) );
77 mSameConfigCheck =
new TQCheckBox( i18n(
"&Reuse host and login configuration"),
this );
78 mSameConfigCheck->setChecked(
true );
79 mSameConfigCheck->setEnabled(
false );
80 glay->addMultiCellWidget( mSameConfigCheck, row, row, 0, 1 );
82 connect( mSameConfigCheck, TQ_SIGNAL(toggled(
bool)), TQ_SLOT(slotEnableWidgets()) );
86 mPortSpin =
new KIntSpinBox( 1, USHRT_MAX, 1, 2000, 10,
this );
87 mPortSpin->setEnabled(
false );
88 label =
new TQLabel( mPortSpin, i18n(
"Managesieve &port:"),
this );
89 glay->addWidget( label, row, 0 );
90 glay->addWidget( mPortSpin, row, 1 );
94 mAlternateURLEdit =
new KLineEdit(
this );
95 mAlternateURLEdit->setEnabled(
false );
96 glay->addWidget(
new TQLabel( mAlternateURLEdit, i18n(
"&Alternate URL:"),
this ), row, 0 );
97 glay->addWidget( mAlternateURLEdit, row, 1 );
103 void SieveConfigEditor::slotEnableWidgets() {
104 bool haveSieve = mManagesieveCheck->isChecked();
105 bool reuseConfig = mSameConfigCheck->isChecked();
107 mSameConfigCheck->setEnabled( haveSieve );
108 mPortSpin->setEnabled( haveSieve && reuseConfig );
109 mAlternateURLEdit->setEnabled( haveSieve && !reuseConfig );
112 bool SieveConfigEditor::managesieveSupported()
const {
113 return mManagesieveCheck->isChecked();
116 void SieveConfigEditor::setManagesieveSupported(
bool enable ) {
117 mManagesieveCheck->setChecked( enable );
120 bool SieveConfigEditor::reuseConfig()
const {
121 return mSameConfigCheck->isChecked();
124 void SieveConfigEditor::setReuseConfig(
bool reuse ) {
125 mSameConfigCheck->setChecked( reuse );
128 unsigned short SieveConfigEditor::port()
const {
129 return static_cast<unsigned short>( mPortSpin->value() );
132 void SieveConfigEditor::setPort(
unsigned short port ) {
133 mPortSpin->setValue( port );
136 KURL SieveConfigEditor::alternateURL()
const {
137 KURL url ( mAlternateURLEdit->text() );
138 if ( !url.isValid() )
142 url.setPass( TQString() );
147 void SieveConfigEditor::setAlternateURL(
const KURL & url ) {
148 mAlternateURLEdit->setText( url.url() );
152 TQString SieveConfigEditor::vacationFileName()
const {
153 return mVacationFileName;
156 void SieveConfigEditor::setVacationFileName(
const TQString& name ) {
157 mVacationFileName = name;
160 void SieveConfigEditor::setConfig(
const SieveConfig & config ) {
161 setManagesieveSupported( config.managesieveSupported() );
162 setReuseConfig( config.reuseConfig() );
163 setPort( config.port() );
164 setAlternateURL( config.alternateURL() );
165 setVacationFileName( config.vacationFileName() );
170 #include "sieveconfig.moc"