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 
00039 namespace KMail {
00040 
00041   VacationDialog::VacationDialog( const QString & caption, QWidget * parent,
00042                   const char * name, bool modal )
00043     : KDialogBase( Plain, caption, Ok|Cancel|Default, Ok, parent, name, modal )
00044   {
00045     KWin::setIcons( winId(), kapp->icon(), kapp->miniIcon() );
00046 
00047     static const int rows = 4;
00048     int row = -1;
00049 
00050     QGridLayout * glay = new QGridLayout( plainPage(), rows, 2, 0, spacingHint() );
00051     glay->setColStretch( 1, 1 );
00052 
00053     // explanation label:
00054     ++row;
00055     glay->addMultiCellWidget( new QLabel( i18n("Configure vacation "
00056                            "notifications to be sent:"),
00057                       plainPage() ), row, row, 0, 1 );
00058 
00059     // Activate checkbox:
00060     ++row;
00061     mActiveCheck = new QCheckBox( i18n("&Activate vacation notifications"), plainPage() );
00062     glay->addMultiCellWidget( mActiveCheck, row, row, 0, 1 );
00063 
00064     // Message text edit:
00065     ++row;
00066     glay->setRowStretch( row, 1 );
00067     mTextEdit = new QTextEdit( plainPage(), "mTextEdit" );
00068     mTextEdit->setTextFormat( QTextEdit::PlainText );
00069     glay->addMultiCellWidget( mTextEdit, row, row, 0, 1 );
00070 
00071     // "Resent only after" spinbox and label:
00072     ++row;
00073     mIntervalSpin = new KIntSpinBox( 1, 356, 1, 7, 10, plainPage(), "mIntervalSpin" );
00074     connect(mIntervalSpin, SIGNAL( valueChanged( int )), SLOT( slotIntervalSpinChanged( int ) ) );
00075     glay->addWidget( new QLabel( mIntervalSpin, i18n("&Resend notification only after:"), plainPage() ), row, 0 );
00076     glay->addWidget( mIntervalSpin, row, 1 );
00077 
00078     // "Send responses for these addresses" lineedit and label:
00079     ++row;
00080     mMailAliasesEdit = new QLineEdit( plainPage(), "mMailAliasesEdit" );
00081     glay->addWidget( new QLabel( mMailAliasesEdit, i18n("&Send responses for these addresses:"), plainPage() ), row, 0 );
00082     glay->addWidget( mMailAliasesEdit, row, 1 );
00083 
00084     // row 5 is for stretch.
00085     Q_ASSERT( row == rows - 1 );
00086   }
00087 
00088   VacationDialog::~VacationDialog() {
00089     kdDebug(5006) << "~VacationDialog()" << endl;
00090   }
00091 
00092   bool VacationDialog::activateVacation() const {
00093     return mActiveCheck->isChecked();
00094   }
00095 
00096   void VacationDialog::setActivateVacation( bool activate ) {
00097     mActiveCheck->setChecked( activate );
00098   }
00099 
00100   QString VacationDialog::messageText() const {
00101     return mTextEdit->text().stripWhiteSpace();
00102   }
00103 
00104   void VacationDialog::setMessageText( const QString & text ) {
00105     mTextEdit->setText( text );
00106   }
00107 
00108   int VacationDialog::notificationInterval() const {
00109     return mIntervalSpin->value();
00110   }
00111 
00112   void VacationDialog::setNotificationInterval( int days ) {
00113     mIntervalSpin->setValue( days );
00114   }
00115 
00116   AddrSpecList VacationDialog::mailAliases() const {
00117     QCString text = mMailAliasesEdit->text().latin1(); // ### IMAA: !ok
00118     AddressList al;
00119     const char * s = text.begin();
00120     parseAddressList( s, text.end(), al );
00121 
00122     AddrSpecList asl;
00123     for ( AddressList::const_iterator it = al.begin() ; it != al.end() ; ++it ) {
00124       const MailboxList & mbl = (*it).mailboxList;
00125       for ( MailboxList::const_iterator jt = mbl.begin() ; jt != mbl.end() ; ++jt )
00126     asl.push_back( (*jt).addrSpec );
00127     }
00128     return asl;
00129   }
00130 
00131   void VacationDialog::setMailAliases( const AddrSpecList & aliases ) {
00132     QStringList sl;
00133     for ( AddrSpecList::const_iterator it = aliases.begin() ; it != aliases.end() ; ++it )
00134       sl.push_back( (*it).asString() );
00135     mMailAliasesEdit->setText( sl.join(", ") );
00136   }
00137 
00138   void VacationDialog::setMailAliases( const QString & aliases ) {
00139     mMailAliasesEdit->setText( aliases );
00140   }
00141 
00142   void VacationDialog::slotIntervalSpinChanged ( int value ) {
00143     mIntervalSpin->setSuffix( i18n(" day", " days", value) );
00144   }
00145 
00146 } // namespace KMail
00147 
00148 #include "vacationdialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys