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 <tdelocale.h>
00029 #include <kdebug.h>
00030 #include <twin.h>
00031 #include <tdeapplication.h>
00032 
00033 #include <tqlayout.h>
00034 #include <tqlabel.h>
00035 #include <tqcheckbox.h>
00036 #include <tqlineedit.h>
00037 #include <tqtextedit.h>
00038 #include <tqvalidator.h>
00039 
00040 namespace KMail {
00041 
00042   VacationDialog::VacationDialog( const TQString & caption, TQWidget * 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     TQGridLayout * glay = new TQGridLayout( plainPage(), rows, 2, 0, spacingHint() );
00052     glay->setColStretch( 1, 1 );
00053 
00054     // explanation label:
00055     ++row;
00056     glay->addMultiCellWidget( new TQLabel( i18n("Configure vacation "
00057                            "notifications to be sent:"),
00058                       plainPage() ), row, row, 0, 1 );
00059 
00060     // Activate checkbox:
00061     ++row;
00062     mActiveCheck = new TQCheckBox( 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 TQTextEdit( plainPage(), "mTextEdit" );
00069     mTextEdit->setTextFormat( TQTextEdit::PlainText );
00070     glay->addMultiCellWidget( mTextEdit, row, row, 0, 1 );
00071 
00072     // "Resent only after" spinbox and label:
00073     ++row;
00074     int defDayInterval = 7; //default day interval
00075     mIntervalSpin = new KIntSpinBox( 1, 356, 1, defDayInterval, 10, plainPage(), "mIntervalSpin" );
00076     mIntervalSpin->setSuffix( i18n(" day", " days", defDayInterval) );
00077     connect(mIntervalSpin, TQT_SIGNAL( valueChanged( int )), TQT_SLOT( slotIntervalSpinChanged( int ) ) );
00078     glay->addWidget( new TQLabel( mIntervalSpin, i18n("&Resend notification only after:"), plainPage() ), row, 0 );
00079     glay->addWidget( mIntervalSpin, row, 1 );
00080 
00081     // "Send responses for these addresses" lineedit and label:
00082     ++row;
00083     mMailAliasesEdit = new TQLineEdit( plainPage(), "mMailAliasesEdit" );
00084     glay->addWidget( new TQLabel( mMailAliasesEdit, i18n("&Send responses for these addresses:"), plainPage() ), row, 0 );
00085     glay->addWidget( mMailAliasesEdit, row, 1 );
00086 
00087     // "Send responses also to SPAM mail" checkbox:
00088     ++row;
00089     mSpamCheck = new TQCheckBox( i18n("Do not send vacation replies to spam messages"), plainPage(), "mSpamCheck" );
00090     mSpamCheck->setChecked( true );
00091     glay->addMultiCellWidget( mSpamCheck, row, row, 0, 1 );
00092 
00093     //  domain checkbox and linedit:
00094     ++row;
00095     mDomainCheck = new TQCheckBox( i18n("Only react to mail coming from domain"), plainPage(), "mDomainCheck" );
00096     mDomainCheck->setChecked( false );
00097     mDomainEdit = new TQLineEdit( plainPage(), "mDomainEdit" );
00098     mDomainEdit->setEnabled( false );
00099     mDomainEdit->setValidator( new TQRegExpValidator( TQRegExp( "[a-zA-Z0-9+-]+(?:\\.[a-zA-Z0-9+-]+)*" ), TQT_TQOBJECT(mDomainEdit) ) );
00100     glay->addWidget( mDomainCheck, row, 0 );
00101     glay->addWidget( mDomainEdit, row, 1 );
00102     connect( mDomainCheck, TQT_SIGNAL(toggled(bool)),
00103              mDomainEdit, TQT_SLOT(setEnabled(bool)) );
00104 
00105     Q_ASSERT( row == rows - 1 );
00106   }
00107 
00108   VacationDialog::~VacationDialog() {
00109     kdDebug(5006) << "~VacationDialog()" << endl;
00110   }
00111 
00112   bool VacationDialog::activateVacation() const {
00113     return mActiveCheck->isChecked();
00114   }
00115 
00116   void VacationDialog::setActivateVacation( bool activate ) {
00117     mActiveCheck->setChecked( activate );
00118   }
00119 
00120   TQString VacationDialog::messageText() const {
00121     return mTextEdit->text().stripWhiteSpace();
00122   }
00123 
00124   void VacationDialog::setMessageText( const TQString & text ) {
00125     mTextEdit->setText( text );
00126     const int height = ( mTextEdit->fontMetrics().lineSpacing() + 1 ) * 11;
00127     mTextEdit->setMinimumHeight( height );
00128   }
00129 
00130   int VacationDialog::notificationInterval() const {
00131     return mIntervalSpin->value();
00132   }
00133 
00134   void VacationDialog::setNotificationInterval( int days ) {
00135     mIntervalSpin->setValue( days );
00136   }
00137 
00138   AddrSpecList VacationDialog::mailAliases() const {
00139     TQCString text = mMailAliasesEdit->text().latin1(); // ### IMAA: !ok
00140     AddressList al;
00141     const char * s = text.begin();
00142     parseAddressList( s, text.end(), al );
00143 
00144     AddrSpecList asl;
00145     for ( AddressList::const_iterator it = al.begin() ; it != al.end() ; ++it ) {
00146       const MailboxList & mbl = (*it).mailboxList;
00147       for ( MailboxList::const_iterator jt = mbl.begin() ; jt != mbl.end() ; ++jt )
00148     asl.push_back( (*jt).addrSpec );
00149     }
00150     return asl;
00151   }
00152 
00153   void VacationDialog::setMailAliases( const AddrSpecList & aliases ) {
00154     TQStringList sl;
00155     for ( AddrSpecList::const_iterator it = aliases.begin() ; it != aliases.end() ; ++it )
00156       sl.push_back( (*it).asString() );
00157     mMailAliasesEdit->setText( sl.join(", ") );
00158   }
00159 
00160   void VacationDialog::setMailAliases( const TQString & aliases ) {
00161     mMailAliasesEdit->setText( aliases );
00162   }
00163 
00164   void VacationDialog::slotIntervalSpinChanged ( int value ) {
00165     mIntervalSpin->setSuffix( i18n(" day", " days", value) );
00166   }
00167 
00168   TQString VacationDialog::domainName() const {
00169     return mDomainCheck->isChecked() ? mDomainEdit->text() : TQString() ;
00170   }
00171 
00172   void VacationDialog::setDomainName( const TQString & domain ) {
00173     if ( !domain.isEmpty() ) {
00174       mDomainEdit->setText( domain );
00175       mDomainCheck->setChecked( true );
00176     }
00177   }
00178 
00179   bool VacationDialog::domainCheck() const
00180   {
00181     return mDomainCheck->isChecked();
00182   }
00183 
00184   void VacationDialog::setDomainCheck( bool check )
00185   {
00186     mDomainCheck->setChecked( check );
00187   }
00188 
00189   bool VacationDialog::sendForSpam() const
00190   {
00191     return !mSpamCheck->isChecked();
00192   }
00193 
00194   void VacationDialog::setSendForSpam( bool enable )
00195   {
00196     mSpamCheck->setChecked( !enable );
00197   }
00198 
00199   /* virtual*/
00200   void KMail::VacationDialog::enableDomainAndSendForSpam( bool enable )
00201   {
00202     mDomainCheck->setEnabled( enable );
00203     mDomainEdit->setEnabled( enable && mDomainCheck->isChecked() );
00204     mSpamCheck->setEnabled( enable );
00205   }
00206 
00207 } // namespace KMail
00208 
00209 #include "vacationdialog.moc"