fix errors found while translating
[kdepim.git] / kmail / vacationdialog.cpp
blob5194631a39aa4e51fa65eb2d53644998069e3be5
1 /* -*- c++ -*-
2 vacationdialog.cpp
4 KMail, the KDE mail client.
5 Copyright (c) 2002 Marc Mutz <mutz@kde.org>
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
16 #include "vacationdialog.h"
18 #include <kmime/kmime_header_parsing.h>
20 using KMime::Types::AddrSpecList;
21 using KMime::Types::AddressList;
22 using KMime::Types::MailboxList;
23 using KMime::HeaderParsing::parseAddressList;
25 #include <knuminput.h>
26 #include <klocale.h>
27 #include <kdebug.h>
28 #include <kwindowsystem.h>
29 #include <kiconloader.h>
30 #include <klineedit.h>
31 #include <ktextedit.h>
33 #include <QGridLayout>
34 #include <QApplication>
35 #include <QByteArray>
36 #include <QLayout>
37 #include <QLabel>
38 #include <QCheckBox>
39 #include <QValidator>
41 namespace KMail {
43 VacationDialog::VacationDialog( const QString & caption, QWidget * parent,
44 const char * name, bool modal )
45 : KDialog( parent )
47 setCaption( caption );
48 setObjectName( name );
49 setButtons( Ok|Cancel|Default );
50 setDefaultButton( Ok );
51 setModal( modal );
52 QFrame *frame = new QFrame( this );
53 setMainWidget( frame );
54 KWindowSystem::setIcons( winId(), qApp->windowIcon().pixmap(IconSize(KIconLoader::Desktop),IconSize(KIconLoader::Desktop)), qApp->windowIcon().pixmap(IconSize(KIconLoader::Small),IconSize(KIconLoader::Small)) );
55 static const int rows = 7;
56 int row = -1;
58 QGridLayout * glay = new QGridLayout( frame );
59 glay->setSpacing( spacingHint() );
60 glay->setMargin( 0 );
61 glay->setColumnStretch( 1, 1 );
63 // explanation label:
64 ++row;
65 glay->addWidget( new QLabel( i18n("Configure vacation "
66 "notifications to be sent:"),
67 frame ), row, 0, 1, 2 );
69 // Activate checkbox:
70 ++row;
71 mActiveCheck = new QCheckBox( i18n("&Activate vacation notifications"), frame );
72 glay->addWidget( mActiveCheck, row, 0, 1, 2 );
74 // Message text edit:
75 ++row;
76 glay->setRowStretch( row, 1 );
77 mTextEdit = new KTextEdit( frame );
78 mTextEdit->setObjectName( "mTextEdit" );
79 mTextEdit->setAcceptRichText( false );
80 glay->addWidget( mTextEdit, row, 0, 1, 2 );
82 // "Resent only after" spinbox and label:
83 ++row;
84 mIntervalSpin = new KIntSpinBox( 1, 356, 1, 7, frame );
85 mIntervalSpin->setObjectName( "mIntervalSpin" );
86 connect(mIntervalSpin, SIGNAL( valueChanged( int )), SLOT( slotIntervalSpinChanged( int ) ) );
87 QLabel *label = new QLabel( i18n("&Resend notification only after:"), frame );
88 label->setBuddy( mIntervalSpin );
89 glay->addWidget( label, row, 0 );
90 glay->addWidget( mIntervalSpin, row, 1 );
92 // "Send responses for these addresses" lineedit and label:
93 ++row;
94 mMailAliasesEdit = new KLineEdit( frame );
95 mMailAliasesEdit->setObjectName( "mMailAliasesEdit" );
96 mMailAliasesEdit->setClearButtonShown( true );
97 QLabel *tmpLabel = new QLabel( i18n("&Send responses for these addresses:"), frame );
98 tmpLabel->setBuddy( mMailAliasesEdit );
99 glay->addWidget( tmpLabel, row, 0 );
100 glay->addWidget( mMailAliasesEdit, row, 1 );
102 // "Send responses also to SPAM mail" checkbox:
103 ++row;
104 mSpamCheck = new QCheckBox( i18n("Do not send vacation replies to spam messages"), frame );
105 mSpamCheck->setObjectName( "mSpamCheck" );
106 mSpamCheck->setChecked( true );
107 glay->addWidget( mSpamCheck, row, 0, 1, 2 );
109 // domain checkbox and linedit:
110 ++row;
111 mDomainCheck = new QCheckBox( i18n("Only react to mail coming from domain"), frame );
112 mDomainCheck->setObjectName( "mDomainCheck" );
113 mDomainCheck->setChecked( false );
114 mDomainEdit = new KLineEdit( frame );
115 mDomainEdit->setObjectName( "mDomainEdit" );
116 mDomainEdit->setClearButtonShown( true );
117 mDomainEdit->setEnabled( false );
118 mDomainEdit->setValidator( new QRegExpValidator( QRegExp( "[a-zA-Z0-9+-]+(?:\\.[a-zA-Z0-9+-]+)*" ), mDomainEdit ) );
119 glay->addWidget( mDomainCheck, row, 0 );
120 glay->addWidget( mDomainEdit, row, 1 );
121 connect( mDomainCheck, SIGNAL(toggled(bool)),
122 mDomainEdit, SLOT(setEnabled(bool)) );
124 Q_ASSERT( row == rows - 1 );
127 VacationDialog::~VacationDialog() {
128 kDebug(5006) <<"~VacationDialog()";
131 bool VacationDialog::activateVacation() const {
132 return mActiveCheck->isChecked();
135 void VacationDialog::setActivateVacation( bool activate ) {
136 mActiveCheck->setChecked( activate );
139 QString VacationDialog::messageText() const {
140 return mTextEdit->toPlainText().trimmed();
143 void VacationDialog::setMessageText( const QString & text ) {
144 mTextEdit->setText( text );
145 const int height = ( mTextEdit->fontMetrics().lineSpacing() + 1 ) * 11;
146 mTextEdit->setMinimumHeight( height );
149 int VacationDialog::notificationInterval() const {
150 return mIntervalSpin->value();
153 void VacationDialog::setNotificationInterval( int days ) {
154 mIntervalSpin->setValue( days );
157 AddrSpecList VacationDialog::mailAliases() const {
158 QByteArray text = mMailAliasesEdit->text().toLatin1(); // ### IMAA: !ok
159 AddressList al;
160 const char * s = text.begin();
161 parseAddressList( s, text.end(), al );
163 AddrSpecList asl;
164 for ( AddressList::const_iterator it = al.begin() ; it != al.end() ; ++it ) {
165 const MailboxList & mbl = (*it).mailboxList;
166 for ( MailboxList::const_iterator jt = mbl.begin() ; jt != mbl.end() ; ++jt )
167 asl.push_back( (*jt).addrSpec() );
169 return asl;
172 void VacationDialog::setMailAliases( const AddrSpecList & aliases ) {
173 QStringList sl;
174 for ( AddrSpecList::const_iterator it = aliases.begin() ; it != aliases.end() ; ++it )
175 sl.push_back( (*it).asString() );
176 mMailAliasesEdit->setText( sl.join(", ") );
179 void VacationDialog::setMailAliases( const QString & aliases ) {
180 mMailAliasesEdit->setText( aliases );
183 void VacationDialog::slotIntervalSpinChanged ( int value ) {
184 mIntervalSpin->setSuffix( i18np(" day", " days", value) );
187 QString VacationDialog::domainName() const {
188 return mDomainCheck->isChecked() ? mDomainEdit->text() : QString() ;
191 void VacationDialog::setDomainName( const QString & domain ) {
192 mDomainEdit->setText( domain );
193 if ( !domain.isEmpty() )
194 mDomainCheck->setChecked( true );
197 bool VacationDialog::sendForSpam() const {
198 return !mSpamCheck->isChecked();
201 void VacationDialog::setSendForSpam( bool enable ) {
202 mSpamCheck->setChecked( !enable );
206 /* virtual*/
207 void KMail::VacationDialog::enableDomainAndSendForSpam( bool enable ) {
208 mDomainCheck->setEnabled( enable );
209 mDomainEdit->setEnabled( enable );
210 mSpamCheck->setEnabled( enable );
214 } // namespace KMail
216 #include "vacationdialog.moc"