kmail

redirectdialog.cpp

Go to the documentation of this file.
00001 /*
00002     This file is part of KMail.
00003     Copyright (c) 2003 Andreas Gungl <a.gungl@gmx.de>
00004 
00005     KMail is free software; you can redistribute it and/or modify it
00006     under the terms of the GNU General Public License, version 2, as
00007     published by the Free Software Foundation.
00008 
00009     KMail is distributed in the hope that it will be useful, but
00010     WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017 
00018     In addition, as a special exception, the copyright holders give
00019     permission to link the code of this program with any edition of
00020     the Qt library by Trolltech AS, Norway (or with modified versions
00021     of Qt that use the same license as Qt), and distribute linked
00022     combinations including the two.  You must obey the GNU General
00023     Public License in all respects for all of the code used other than
00024     Qt.  If you modify this file, you may extend this exception to
00025     your version of the file, but you are not obligated to do so.  If
00026     you do not wish to do so, delete this exception statement from
00027     your version.
00028 */
00029 
00030 #include "redirectdialog.h"
00031 
00032 #include "kmkernel.h"
00033 #include "kmlineeditspell.h"
00034 
00035 #include <libemailfunctions/email.h>
00036 #include <addressesdialog.h>
00037 using KPIM::AddressesDialog;
00038 #include "recentaddresses.h"
00039 using KRecentAddress::RecentAddresses;
00040 
00041 #include <kiconloader.h>
00042 #include <klocale.h>
00043 #include <kmessagebox.h>
00044 
00045 #include <qvbox.h>
00046 #include <qhbox.h>
00047 #include <qtooltip.h>
00048 #include <qwhatsthis.h>
00049 #include <qlabel.h>
00050 #include <qpushbutton.h>
00051 #include <qstringlist.h>
00052 
00053 using namespace KMail;
00054 
00055 RedirectDialog::RedirectDialog( QWidget *parent, const char *name,
00056                                 bool modal, bool immediate )
00057   : KDialogBase( parent, name, modal, i18n( "Redirect Message" ),
00058                  User1|User2|Cancel, ( immediate ? User1 : User2 ), false )
00059 {
00060   QVBox *vbox = makeVBoxMainWidget();
00061   mLabelTo = new QLabel( i18n( "Select the recipient &addresses "
00062                                "to redirect to:" ), vbox );
00063 
00064   QHBox *hbox = new QHBox( vbox );
00065   hbox->setSpacing(4);
00066   mEditTo = new KMLineEdit( true, hbox, "toLine" );
00067   mEditTo->setMinimumWidth( 300 );
00068 
00069   mBtnTo = new QPushButton( QString::null, hbox, "toBtn" );
00070   mBtnTo->setPixmap( BarIcon( "contents", KIcon::SizeSmall ) );
00071   mBtnTo->setMinimumSize( mBtnTo->sizeHint() * 1.2 );
00072   QToolTip::add( mBtnTo, i18n("Use the Address-Selection Dialog") );
00073   QWhatsThis::add( mBtnTo, i18n("This button opens a separate dialog "
00074                                  "where you can select recipients out "
00075                                  "of all available addresses." ) );
00076 
00077   connect( mBtnTo, SIGNAL(clicked()), SLOT(slotAddrBook()) );
00078 
00079   mLabelTo->setBuddy( mBtnTo );
00080   mEditTo->setFocus();
00081 
00082   setButtonGuiItem( User1, KGuiItem( i18n("&Send Now"), "mail_send" ) );
00083   setButtonGuiItem( User2, KGuiItem( i18n("Send &Later"), "queue" ) );
00084 }
00085 
00086 
00087 //-----------------------------------------------------------------------------
00088 void RedirectDialog::slotUser1()
00089 {
00090   mImmediate = true;
00091   accept();
00092 }
00093 
00094 //-----------------------------------------------------------------------------
00095 void RedirectDialog::slotUser2()
00096 {
00097   mImmediate = false;
00098   accept();
00099 }
00100 
00101 //-----------------------------------------------------------------------------
00102 void RedirectDialog::accept()
00103 {
00104   mResentTo = mEditTo->text();
00105   if ( mResentTo.isEmpty() ) {
00106     KMessageBox::sorry( this,
00107         i18n("You cannot redirect the message without an address."),
00108         i18n("Empty Redirection Address") );
00109   }
00110   else done( Ok );
00111 }
00112 
00113 
00114 //-----------------------------------------------------------------------------
00115 void RedirectDialog::slotAddrBook()
00116 {
00117   AddressesDialog dlg( this );
00118 
00119   mResentTo = mEditTo->text();
00120   if ( !mResentTo.isEmpty() ) {
00121       QStringList lst = KPIM::splitEmailAddrList( mResentTo );
00122       dlg.setSelectedTo( lst );
00123   }
00124 
00125   dlg.setRecentAddresses(
00126       RecentAddresses::self( KMKernel::config() )->kabcAddresses() );
00127 
00128   // Make it impossible to specify Cc or Bcc addresses as we support
00129   // only the Redirect-To header!
00130   dlg.setShowCC( false );
00131   dlg.setShowBCC( false );
00132 
00133   if (dlg.exec()==QDialog::Rejected) return;
00134 
00135   mEditTo->setText( dlg.to().join(", ") );
00136   mEditTo->setEdited( true );
00137 }
00138 
00139 
00140 #include "redirectdialog.moc"