kmail

vacationdialog.cpp

00001 /*  -*- c++ -*-
00002     vacationdialog.cpp
00003 
00004     KMail, the KDE mail client.
00005     Copyright (c) 2002 Marc Mutz <mutz@kde.org>
00006 
00007     This program is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU General Public License,
00009     version 2.0, as published by the Free Software Foundation.
00010     You should have received a copy of the GNU General Public License
00011     along with this program; if not, write to the Free Software Foundation,
00012     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
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     // explanation label:
00055     ++row;
00056     glay->addMultiCellWidget( new QLabel( i18n("Configure vacation "
00057                            "notifications to be sent:"),
00058                       plainPage() ), row, row, 0, 1 );
00059 
00060     // Activate checkbox:
00061     ++row;
00062     mActiveCheck = new QCheckBox( i18n("&Activate vacation notifications"), plainPage() );
00063     glay->addMultiCellWidget( mActiveCheck, row, row, 0, 1 );
00064 
00065     // Message text edit:
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     // "Resent only after" spinbox and label:
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     // "Send responses for these addresses" lineedit and label:
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     // "Send responses also to SPAM mail" checkbox:
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     //  domain checkbox and linedit:
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   }
00125 
00126   int VacationDialog::notificationInterval() const {
00127     return mIntervalSpin->value();
00128   }
00129 
00130   void VacationDialog::setNotificationInterval( int days ) {
00131     mIntervalSpin->setValue( days );
00132   }
00133 
00134   AddrSpecList VacationDialog::mailAliases() const {
00135     QCString text = mMailAliasesEdit->text().latin1(); // ### IMAA: !ok
00136     AddressList al;
00137     const char * s = text.begin();
00138     parseAddressList( s, text.end(), al );
00139 
00140     AddrSpecList asl;
00141     for ( AddressList::const_iterator it = al.begin() ; it != al.end() ; ++it ) {
00142       const MailboxList & mbl = (*it).mailboxList;
00143       for ( MailboxList::const_iterator jt = mbl.begin() ; jt != mbl.end() ; ++jt )
00144     asl.push_back( (*jt).addrSpec );
00145     }
00146     return asl;
00147   }
00148 
00149   void VacationDialog::setMailAliases( const AddrSpecList & aliases ) {
00150     QStringList sl;
00151     for ( AddrSpecList::const_iterator it = aliases.begin() ; it != aliases.end() ; ++it )
00152       sl.push_back( (*it).asString() );
00153     mMailAliasesEdit->setText( sl.join(", ") );
00154   }
00155 
00156   void VacationDialog::setMailAliases( const QString & aliases ) {
00157     mMailAliasesEdit->setText( aliases );
00158   }
00159 
00160   void VacationDialog::slotIntervalSpinChanged ( int value ) {
00161     mIntervalSpin->setSuffix( i18n(" day", " days", value) );
00162   }
00163  
00164   QString VacationDialog::domainName() const {
00165     return mDomainCheck->isChecked() ? mDomainEdit->text() : QString::null ;
00166   }
00167 
00168   void VacationDialog::setDomainName( const QString & domain ) {
00169     mDomainEdit->setText( domain );
00170     if ( !domain.isEmpty() )
00171       mDomainCheck->setChecked( true );
00172   }
00173 
00174   bool VacationDialog::sendForSpam() const {
00175     return !mSpamCheck->isChecked();
00176   }
00177 
00178   void VacationDialog::setSendForSpam( bool enable ) {
00179     mSpamCheck->setChecked( !enable );
00180   }
00181 
00182 
00183   /* virtual*/ 
00184   void KMail::VacationDialog::enableDomainAndSendForSpam( bool enable ) {
00185       mDomainCheck->setEnabled( enable );
00186       mDomainEdit->setEnabled( enable );
00187       mSpamCheck->setEnabled( enable );
00188   }
00189 
00190 
00191 } // namespace KMail
00192 
00193 #include "vacationdialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys