kmail Library API Documentation

vacationdialog.cpp

00001 /*  -*- c++ -*-
00002     vacationdialog.cpp
00003 
00004     KMail, the KDE mail client.
00005     Copyright (c) 2002 Marc Mutz <mutz@kde.org>
00006     Copyright (c) 2005 Klarälvdalens Datakonsult AB
00007 
00008     KMail is free software; you can redistribute it and/or modify it
00009     under the terms of the GNU General Public License, version 2, as
00010     published by the Free Software Foundation.
00011 
00012     KMail is distributed in the hope that it will be useful, but
00013     WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 */
00032 
00033 #ifdef HAVE_CONFIG_H
00034 #include <config.h>
00035 #endif
00036 
00037 #include "vacationdialog.h"
00038 
00039 #include <kmime_header_parsing.h>
00040 using KMime::Types::AddrSpecList;
00041 using KMime::Types::AddressList;
00042 using KMime::Types::MailboxList;
00043 using KMime::HeaderParsing::parseAddressList;
00044 
00045 #include <knuminput.h>
00046 #include <klocale.h>
00047 #include <kdebug.h>
00048 #include <kwin.h>
00049 #include <kapplication.h>
00050 
00051 #include <qlayout.h>
00052 #include <qlabel.h>
00053 #include <qcheckbox.h>
00054 #include <qlineedit.h>
00055 #include <qtextedit.h>
00056 #include <qvalidator.h>
00057 
00058 namespace KMail {
00059 
00060   VacationDialog::VacationDialog( const QString & caption, QWidget * parent,
00061                   const char * name, bool modal )
00062     : KDialogBase( Plain, caption, Ok|Cancel|Default, Ok, parent, name, modal )
00063   {
00064     KWin::setIcons( winId(), kapp->icon(), kapp->miniIcon() );
00065 
00066     static const int rows = 7;
00067     int row = -1;
00068 
00069     QGridLayout * glay = new QGridLayout( plainPage(), rows, 2, 0, spacingHint() );
00070     glay->setColStretch( 1, 1 );
00071 
00072     // explanation label:
00073     ++row;
00074     glay->addMultiCellWidget( new QLabel( i18n("Configure vacation "
00075                            "notifications to be sent:"),
00076                       plainPage() ), row, row, 0, 1 );
00077 
00078     // Activate checkbox:
00079     ++row;
00080     mActiveCheck = new QCheckBox( i18n("&Activate vacation notifications"), plainPage() );
00081     glay->addMultiCellWidget( mActiveCheck, row, row, 0, 1 );
00082 
00083     // Message text edit:
00084     ++row;
00085     glay->setRowStretch( row, 1 );
00086     mTextEdit = new QTextEdit( plainPage(), "mTextEdit" );
00087     mTextEdit->setTextFormat( QTextEdit::PlainText );
00088     glay->addMultiCellWidget( mTextEdit, row, row, 0, 1 );
00089 
00090     // "Resent only after" spinbox and label:
00091     ++row;
00092     mIntervalSpin = new KIntSpinBox( 1, 356, 1, 7, 10, plainPage(), "mIntervalSpin" );
00093     mIntervalSpin->setSuffix( i18n(" days") );
00094     glay->addWidget( new QLabel( mIntervalSpin, i18n("&Resend notification only after:"), plainPage() ), row, 0 );
00095     glay->addWidget( mIntervalSpin, row, 1 );
00096 
00097     // "Send responses for these addresses" lineedit and label:
00098     ++row;
00099     mMailAliasesEdit = new QLineEdit( plainPage(), "mMailAliasesEdit" );
00100     glay->addWidget( new QLabel( mMailAliasesEdit, i18n("&Send responses for these addresses:"), plainPage() ), row, 0 );
00101     glay->addWidget( mMailAliasesEdit, row, 1 );
00102 
00103     // "Send responses also to SPAM mail" checkbox:
00104     ++row;
00105     mSpamCheck = new QCheckBox( i18n("Do not send vacation replies to spam messages"), plainPage(), "mSpamCheck" );
00106     mSpamCheck->setChecked( true );
00107     glay->addMultiCellWidget( mSpamCheck, row, row, 0, 1 );
00108 
00109     //  domain checkbox and linedit:
00110     ++row;
00111     mDomainCheck = new QCheckBox( i18n("Only react to mail coming from domain"), plainPage(), "mDomainCheck" );
00112     mDomainCheck->setChecked( false );
00113     mDomainEdit = new QLineEdit( plainPage(), "mDomainEdit" );
00114     mDomainEdit->setEnabled( false );
00115     mDomainEdit->setValidator( new QRegExpValidator( QRegExp( "[a-zA-Z0-9+-]+(?:\\.[a-zA-Z0-9+-]+)*" ), mDomainEdit ) );
00116     glay->addWidget( mDomainCheck, row, 0 );
00117     glay->addWidget( mDomainEdit, row, 1 );
00118     connect( mDomainCheck, SIGNAL(toggled(bool)),
00119              mDomainEdit, SLOT(setEnabled(bool)) );
00120 
00121     Q_ASSERT( row == rows - 1 );
00122   }
00123 
00124   VacationDialog::~VacationDialog() {
00125     kdDebug(5006) << "~VacationDialog()" << endl;
00126   }
00127 
00128   bool VacationDialog::activateVacation() const {
00129     return mActiveCheck->isChecked();
00130   }
00131 
00132   void VacationDialog::setActivateVacation( bool activate ) {
00133     mActiveCheck->setChecked( activate );
00134   }
00135 
00136   QString VacationDialog::messageText() const {
00137     return mTextEdit->text().stripWhiteSpace();
00138   }
00139 
00140   void VacationDialog::setMessageText( const QString & text ) {
00141     mTextEdit->setText( text );
00142   }
00143 
00144   int VacationDialog::notificationInterval() const {
00145     return mIntervalSpin->value();
00146   }
00147 
00148   void VacationDialog::setNotificationInterval( int days ) {
00149     mIntervalSpin->setValue( days );
00150   }
00151 
00152   AddrSpecList VacationDialog::mailAliases() const {
00153     QCString text = mMailAliasesEdit->text().latin1(); // ### IMAA: !ok
00154     AddressList al;
00155     const char * s = text.begin();
00156     parseAddressList( s, text.end(), al );
00157 
00158     AddrSpecList asl;
00159     for ( AddressList::const_iterator it = al.begin() ; it != al.end() ; ++it ) {
00160       const MailboxList & mbl = (*it).mailboxList;
00161       for ( MailboxList::const_iterator jt = mbl.begin() ; jt != mbl.end() ; ++jt )
00162     asl.push_back( (*jt).addrSpec );
00163     }
00164     return asl;
00165   }
00166 
00167   void VacationDialog::setMailAliases( const AddrSpecList & aliases ) {
00168     QStringList sl;
00169     for ( AddrSpecList::const_iterator it = aliases.begin() ; it != aliases.end() ; ++it )
00170       sl.push_back( (*it).asString() );
00171     mMailAliasesEdit->setText( sl.join(", ") );
00172   }
00173 
00174   void VacationDialog::setMailAliases( const QString & aliases ) {
00175     mMailAliasesEdit->setText( aliases );
00176   }
00177 
00178   QString VacationDialog::domainName() const {
00179     return mDomainCheck->isChecked() ? mDomainEdit->text() : QString::null ;
00180   }
00181 
00182   void VacationDialog::setDomainName( const QString & domain ) {
00183     mDomainEdit->setText( domain );
00184     if ( !domain.isEmpty() )
00185       mDomainCheck->setChecked( true );
00186   }
00187 
00188   bool VacationDialog::sendForSpam() const {
00189     return !mSpamCheck->isChecked();
00190   }
00191 
00192   void VacationDialog::setSendForSpam( bool enable ) {
00193     mSpamCheck->setChecked( !enable );
00194   }
00195 
00196 
00197   /* virtual*/ 
00198   void KMail::VacationDialog::enableDomainAndSendForSpam( bool enable ) {
00199       mDomainCheck->setEnabled( enable );
00200       mDomainEdit->setEnabled( enable );
00201       mSpamCheck->setEnabled( enable );
00202   }
00203 
00204 } // namespace KMail
00205 
00206 #include "vacationdialog.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Dec 21 14:25:05 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003