summaryrefslogtreecommitdiffstats
path: root/kmail/sieveconfig.cpp
blob: a787e06a57d0d75d1f02ab4eb5cd14cf13618866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
    sieveconfig.cpp

    KMail, the KDE mail client.
    Copyright (c) 2002 Marc Mutz <mutz@kde.org>

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License,
    version 2.0, as published by the Free Software Foundation.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "sieveconfig.h"

#include <knuminput.h>
#include <tdelocale.h>
#include <kdialog.h>
#include <tdeconfigbase.h>

#include <tqlayout.h>
#include <tqcheckbox.h>
#include <tqlabel.h>
#include <klineedit.h>


namespace KMail {

  void SieveConfig::readConfig( const TDEConfigBase & config ) {
    mManagesieveSupported = config.readBoolEntry( "sieve-support", false );
    mReuseConfig = config.readBoolEntry( "sieve-reuse-config", true );

    int port = config.readNumEntry( "sieve-port", 2000 );
    if ( port < 1 || port > USHRT_MAX ) port = 2000;
    mPort = static_cast<unsigned short>( port );

    mAlternateURL = config.readEntry( "sieve-alternate-url" );
    mVacationFileName = config.readEntry( "sieve-vacation-filename", "kmail-vacation.siv" );
    if ( mVacationFileName.isEmpty() )
      mVacationFileName = "kmail-vacation.siv";
  }

  void SieveConfig::writeConfig( TDEConfigBase & config ) const {
    config.writeEntry( "sieve-support", managesieveSupported() );
    config.writeEntry( "sieve-reuse-config", reuseConfig() );
    config.writeEntry( "sieve-port", port() );
    config.writeEntry( "sieve-alternate-url", mAlternateURL.url() );
    config.writeEntry( "sieve-vacation-filename", mVacationFileName );
  }

  SieveConfigEditor::SieveConfigEditor( TQWidget * parent, const char * name )
    : TQWidget( parent, name )
  {
    // tmp. vars:
    int row = -1;
    TQLabel * label;

    TQGridLayout * glay = new TQGridLayout( this, 5, 2, 0, KDialog::spacingHint() );
    glay->setRowStretch( 4, 1 );
    glay->setColStretch( 1, 1 );


    // "Server supports sieve" checkbox:
    ++row;
    mManagesieveCheck = new TQCheckBox( i18n("&Server supports Sieve"), this );
    glay->addMultiCellWidget( mManagesieveCheck, row, row, 0, 1 );

    connect( mManagesieveCheck, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotEnableWidgets()) );

    // "reuse host and login config" checkbox:
    ++row;
    mSameConfigCheck = new TQCheckBox( i18n("&Reuse host and login configuration"), this );
    mSameConfigCheck->setChecked( true );
    mSameConfigCheck->setEnabled( false );
    glay->addMultiCellWidget( mSameConfigCheck, row, row, 0, 1 );

    connect( mSameConfigCheck, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotEnableWidgets()) );

    // "Managesieve port" spinbox and label:
    ++row;
    mPortSpin = new KIntSpinBox( 1, USHRT_MAX, 1, 2000, 10, this );
    mPortSpin->setEnabled( false );
    label = new TQLabel( mPortSpin, i18n("Managesieve &port:"), this );
    glay->addWidget( label, row, 0 );
    glay->addWidget( mPortSpin, row, 1 );

    // "Alternate URL" lineedit and label:
    ++row;
    mAlternateURLEdit = new KLineEdit( this );
    mAlternateURLEdit->setEnabled( false );
    glay->addWidget( new TQLabel( mAlternateURLEdit, i18n("&Alternate URL:"), this ), row, 0 );
    glay->addWidget( mAlternateURLEdit, row, 1 );

    // row 4 is spacer

  }

  void SieveConfigEditor::slotEnableWidgets() {
    bool haveSieve = mManagesieveCheck->isChecked();
    bool reuseConfig = mSameConfigCheck->isChecked();

    mSameConfigCheck->setEnabled( haveSieve );
    mPortSpin->setEnabled( haveSieve && reuseConfig );
    mAlternateURLEdit->setEnabled( haveSieve && !reuseConfig );
  }

  bool SieveConfigEditor::managesieveSupported() const {
    return mManagesieveCheck->isChecked();
  }

  void SieveConfigEditor::setManagesieveSupported( bool enable ) {
    mManagesieveCheck->setChecked( enable );
  }

  bool SieveConfigEditor::reuseConfig() const {
    return mSameConfigCheck->isChecked();
  }

  void SieveConfigEditor::setReuseConfig( bool reuse ) {
    mSameConfigCheck->setChecked( reuse );
  }

  unsigned short SieveConfigEditor::port() const {
    return static_cast<unsigned short>( mPortSpin->value() );
  }

  void SieveConfigEditor::setPort( unsigned short port ) {
    mPortSpin->setValue( port );
  }

  KURL SieveConfigEditor::alternateURL() const {
    KURL url ( mAlternateURLEdit->text() );
    if ( !url.isValid() )
      return KURL();

    if ( url.hasPass() )
      url.setPass( TQString() );

    return url;
  }

  void SieveConfigEditor::setAlternateURL( const KURL & url ) {
    mAlternateURLEdit->setText( url.url() );
  }


  TQString SieveConfigEditor::vacationFileName() const {
      return mVacationFileName;
  }

  void SieveConfigEditor::setVacationFileName( const TQString& name ) {
    mVacationFileName = name;
  }

  void SieveConfigEditor::setConfig( const SieveConfig & config ) {
    setManagesieveSupported( config.managesieveSupported() );
    setReuseConfig( config.reuseConfig() );
    setPort( config.port() );
    setAlternateURL( config.alternateURL() );
    setVacationFileName( config.vacationFileName() );
  }

} // namespace KMail

#include "sieveconfig.moc"