00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifdef HAVE_CONFIG_H
00016 #include <config.h>
00017 #endif
00018
00019 #include "vacationdialog.h"
00020
00021 #include <kmime_header_parsing.h>
00022 using KMime::Types::AddrSpecList;
00023 using KMime::Types::AddressList;
00024 using KMime::Types::MailboxList;
00025 using KMime::HeaderParsing::parseAddressList;
00026
00027 #include <knuminput.h>
00028 #include <klocale.h>
00029 #include <kdebug.h>
00030 #include <kwin.h>
00031 #include <kapplication.h>
00032
00033 #include <qlayout.h>
00034 #include <qlabel.h>
00035 #include <qcheckbox.h>
00036 #include <qlineedit.h>
00037 #include <qtextedit.h>
00038 #include <qvalidator.h>
00039
00040 namespace KMail {
00041
00042 VacationDialog::VacationDialog( const QString & caption, QWidget * parent,
00043 const char * name, bool modal )
00044 : KDialogBase( Plain, caption, Ok|Cancel|Default, Ok, parent, name, modal )
00045 {
00046 KWin::setIcons( winId(), kapp->icon(), kapp->miniIcon() );
00047
00048 static const int rows = 7;
00049 int row = -1;
00050
00051 QGridLayout * glay = new QGridLayout( plainPage(), rows, 2, 0, spacingHint() );
00052 glay->setColStretch( 1, 1 );
00053
00054
00055 ++row;
00056 glay->addMultiCellWidget( new QLabel( i18n("Configure vacation "
00057 "notifications to be sent:"),
00058 plainPage() ), row, row, 0, 1 );
00059
00060
00061 ++row;
00062 mActiveCheck = new QCheckBox( i18n("&Activate vacation notifications"), plainPage() );
00063 glay->addMultiCellWidget( mActiveCheck, row, row, 0, 1 );
00064
00065
00066 ++row;
00067 glay->setRowStretch( row, 1 );
00068 mTextEdit = new QTextEdit( plainPage(), "mTextEdit" );
00069 mTextEdit->setTextFormat( QTextEdit::PlainText );
00070 glay->addMultiCellWidget( mTextEdit, row, row, 0, 1 );
00071
00072
00073 ++row;
00074 mIntervalSpin = new KIntSpinBox( 1, 356, 1, 7, 10, plainPage(), "mIntervalSpin" );
00075 connect(mIntervalSpin, SIGNAL( valueChanged( int )), SLOT( slotIntervalSpinChanged( int ) ) );
00076 glay->addWidget( new QLabel( mIntervalSpin, i18n("&Resend notification only after:"), plainPage() ), row, 0 );
00077 glay->addWidget( mIntervalSpin, row, 1 );
00078
00079
00080 ++row;
00081 mMailAliasesEdit = new QLineEdit( plainPage(), "mMailAliasesEdit" );
00082 glay->addWidget( new QLabel( mMailAliasesEdit, i18n("&Send responses for these addresses:"), plainPage() ), row, 0 );
00083 glay->addWidget( mMailAliasesEdit, row, 1 );
00084
00085
00086 ++row;
00087 mSpamCheck = new QCheckBox( i18n("Do not send vacation replies to spam messages"), plainPage(), "mSpamCheck" );
00088 mSpamCheck->setChecked( true );
00089 glay->addMultiCellWidget( mSpamCheck, row, row, 0, 1 );
00090
00091
00092 ++row;
00093 mDomainCheck = new QCheckBox( i18n("Only react to mail coming from domain"), plainPage(), "mDomainCheck" );
00094 mDomainCheck->setChecked( false );
00095 mDomainEdit = new QLineEdit( plainPage(), "mDomainEdit" );
00096 mDomainEdit->setEnabled( false );
00097 mDomainEdit->setValidator( new QRegExpValidator( QRegExp( "[a-zA-Z0-9+-]+(?:\\.[a-zA-Z0-9+-]+)*" ), mDomainEdit ) );
00098 glay->addWidget( mDomainCheck, row, 0 );
00099 glay->addWidget( mDomainEdit, row, 1 );
00100 connect( mDomainCheck, SIGNAL(toggled(bool)),
00101 mDomainEdit, SLOT(setEnabled(bool)) );
00102
00103 Q_ASSERT( row == rows - 1 );
00104 }
00105
00106 VacationDialog::~VacationDialog() {
00107 kdDebug(5006) << "~VacationDialog()" << endl;
00108 }
00109
00110 bool VacationDialog::activateVacation() const {
00111 return mActiveCheck->isChecked();
00112 }
00113
00114 void VacationDialog::setActivateVacation( bool activate ) {
00115 mActiveCheck->setChecked( activate );
00116 }
00117
00118 QString VacationDialog::messageText() const {
00119 return mTextEdit->text().stripWhiteSpace();
00120 }
00121
00122 void VacationDialog::setMessageText( const QString & text ) {
00123 mTextEdit->setText( text );
00124 const int height = ( mTextEdit->fontMetrics().lineSpacing() + 1 ) * 11;
00125 mTextEdit->setMinimumHeight( height );
00126 }
00127
00128 int VacationDialog::notificationInterval() const {
00129 return mIntervalSpin->value();
00130 }
00131
00132 void VacationDialog::setNotificationInterval( int days ) {
00133 mIntervalSpin->setValue( days );
00134 }
00135
00136 AddrSpecList VacationDialog::mailAliases() const {
00137 QCString text = mMailAliasesEdit->text().latin1();
00138 AddressList al;
00139 const char * s = text.begin();
00140 parseAddressList( s, text.end(), al );
00141
00142 AddrSpecList asl;
00143 for ( AddressList::const_iterator it = al.begin() ; it != al.end() ; ++it ) {
00144 const MailboxList & mbl = (*it).mailboxList;
00145 for ( MailboxList::const_iterator jt = mbl.begin() ; jt != mbl.end() ; ++jt )
00146 asl.push_back( (*jt).addrSpec );
00147 }
00148 return asl;
00149 }
00150
00151 void VacationDialog::setMailAliases( const AddrSpecList & aliases ) {
00152 QStringList sl;
00153 for ( AddrSpecList::const_iterator it = aliases.begin() ; it != aliases.end() ; ++it )
00154 sl.push_back( (*it).asString() );
00155 mMailAliasesEdit->setText( sl.join(", ") );
00156 }
00157
00158 void VacationDialog::setMailAliases( const QString & aliases ) {
00159 mMailAliasesEdit->setText( aliases );
00160 }
00161
00162 void VacationDialog::slotIntervalSpinChanged ( int value ) {
00163 mIntervalSpin->setSuffix( i18n(" day", " days", value) );
00164 }
00165
00166 QString VacationDialog::domainName() const {
00167 return mDomainCheck->isChecked() ? mDomainEdit->text() : QString::null ;
00168 }
00169
00170 void VacationDialog::setDomainName( const QString & domain ) {
00171 mDomainEdit->setText( domain );
00172 if ( !domain.isEmpty() )
00173 mDomainCheck->setChecked( true );
00174 }
00175
00176 bool VacationDialog::sendForSpam() const {
00177 return !mSpamCheck->isChecked();
00178 }
00179
00180 void VacationDialog::setSendForSpam( bool enable ) {
00181 mSpamCheck->setChecked( !enable );
00182 }
00183
00184
00185
00186 void KMail::VacationDialog::enableDomainAndSendForSpam( bool enable ) {
00187 mDomainCheck->setEnabled( enable );
00188 mDomainEdit->setEnabled( enable );
00189 mSpamCheck->setEnabled( enable );
00190 }
00191
00192
00193 }
00194
00195 #include "vacationdialog.moc"