kmail

sieveconfig.cpp
1/*
2 sieveconfig.cpp
3
4 KMail, the KDE mail client.
5 Copyright (c) 2002 Marc Mutz <mutz@kde.org>
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License,
9 version 2.0, as published by the Free Software Foundation.
10 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software Foundation,
12 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
13*/
14
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
19#include "sieveconfig.h"
20
21#include <knuminput.h>
22#include <tdelocale.h>
23#include <kdialog.h>
24#include <tdeconfigbase.h>
25
26#include <tqlayout.h>
27#include <tqcheckbox.h>
28#include <tqlabel.h>
29#include <klineedit.h>
30
31
32namespace KMail {
33
34 void SieveConfig::readConfig( const TDEConfigBase & config ) {
35 mManagesieveSupported = config.readBoolEntry( "sieve-support", false );
36 mReuseConfig = config.readBoolEntry( "sieve-reuse-config", true );
37
38 int port = config.readNumEntry( "sieve-port", 2000 );
39 if ( port < 1 || port > USHRT_MAX ) port = 2000;
40 mPort = static_cast<unsigned short>( port );
41
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";
46 }
47
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 );
54 }
55
56 SieveConfigEditor::SieveConfigEditor( TQWidget * parent, const char * name )
57 : TQWidget( parent, name )
58 {
59 // tmp. vars:
60 int row = -1;
61 TQLabel * label;
62
63 TQGridLayout * glay = new TQGridLayout( this, 5, 2, 0, KDialog::spacingHint() );
64 glay->setRowStretch( 4, 1 );
65 glay->setColStretch( 1, 1 );
66
67
68 // "Server supports sieve" checkbox:
69 ++row;
70 mManagesieveCheck = new TQCheckBox( i18n("&Server supports Sieve"), this );
71 glay->addMultiCellWidget( mManagesieveCheck, row, row, 0, 1 );
72
73 connect( mManagesieveCheck, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotEnableWidgets()) );
74
75 // "reuse host and login config" checkbox:
76 ++row;
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 );
81
82 connect( mSameConfigCheck, TQ_SIGNAL(toggled(bool)), TQ_SLOT(slotEnableWidgets()) );
83
84 // "Managesieve port" spinbox and label:
85 ++row;
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 );
91
92 // "Alternate URL" lineedit and label:
93 ++row;
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 );
98
99 // row 4 is spacer
100
101 }
102
103 void SieveConfigEditor::slotEnableWidgets() {
104 bool haveSieve = mManagesieveCheck->isChecked();
105 bool reuseConfig = mSameConfigCheck->isChecked();
106
107 mSameConfigCheck->setEnabled( haveSieve );
108 mPortSpin->setEnabled( haveSieve && reuseConfig );
109 mAlternateURLEdit->setEnabled( haveSieve && !reuseConfig );
110 }
111
112 bool SieveConfigEditor::managesieveSupported() const {
113 return mManagesieveCheck->isChecked();
114 }
115
116 void SieveConfigEditor::setManagesieveSupported( bool enable ) {
117 mManagesieveCheck->setChecked( enable );
118 }
119
120 bool SieveConfigEditor::reuseConfig() const {
121 return mSameConfigCheck->isChecked();
122 }
123
124 void SieveConfigEditor::setReuseConfig( bool reuse ) {
125 mSameConfigCheck->setChecked( reuse );
126 }
127
128 unsigned short SieveConfigEditor::port() const {
129 return static_cast<unsigned short>( mPortSpin->value() );
130 }
131
132 void SieveConfigEditor::setPort( unsigned short port ) {
133 mPortSpin->setValue( port );
134 }
135
136 KURL SieveConfigEditor::alternateURL() const {
137 KURL url ( mAlternateURLEdit->text() );
138 if ( !url.isValid() )
139 return KURL();
140
141 if ( url.hasPass() )
142 url.setPass( TQString() );
143
144 return url;
145 }
146
147 void SieveConfigEditor::setAlternateURL( const KURL & url ) {
148 mAlternateURLEdit->setText( url.url() );
149 }
150
151
152 TQString SieveConfigEditor::vacationFileName() const {
153 return mVacationFileName;
154 }
155
156 void SieveConfigEditor::setVacationFileName( const TQString& name ) {
157 mVacationFileName = name;
158 }
159
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() );
166 }
167
168} // namespace KMail
169
170#include "sieveconfig.moc"
folderdiaquotatab.h
Definition: aboutdata.cpp:40