kmail

redirectdialog.cpp

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 <tqvbox.h>
00046 #include <tqhbox.h>
00047 #include <tqtooltip.h>
00048 #include <tqwhatsthis.h>
00049 #include <tqlabel.h>
00050 #include <tqpushbutton.h>
00051 #include <tqstringlist.h>
00052 
00053 using namespace KMail;
00054 
00055 RedirectDialog::RedirectDialog( TQWidget *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   TQVBox *vbox = makeVBoxMainWidget();
00061   mLabelTo = new TQLabel( i18n( "Select the recipient &addresses "
00062                                "to redirect to:" ), vbox );
00063 
00064   TQHBox *hbox = new TQHBox( vbox );
00065   hbox->setSpacing(4);
00066   mEditTo = new KMLineEdit( true, hbox, "toLine" );
00067   mEditTo->setMinimumWidth( 300 );
00068 
00069   mBtnTo = new TQPushButton( TQString::null, hbox, "toBtn" );
00070   mBtnTo->setPixmap( BarIcon( "contents", KIcon::SizeSmall ) );
00071   mBtnTo->setMinimumSize( mBtnTo->sizeHint() * 1.2 );
00072   TQToolTip::add( mBtnTo, i18n("Use the Address-Selection Dialog") );
00073   TQWhatsThis::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, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddrBook()) );
00078 
00079   connect( mEditTo, TQT_SIGNAL( textChanged ( const TQString & ) ), TQT_SLOT( slotEmailChanged( const TQString & ) ) );
00080   mLabelTo->setBuddy( mBtnTo );
00081   mEditTo->setFocus();
00082 
00083   setButtonGuiItem( User1, KGuiItem( i18n("&Send Now"), "mail_send" ) );
00084   setButtonGuiItem( User2, KGuiItem( i18n("Send &Later"), "queue" ) );
00085   enableButton( User1, false );
00086   enableButton( User2, false );
00087 }
00088 
00089 
00090 void RedirectDialog::slotEmailChanged( const TQString & text )
00091 {
00092   enableButton( User1, !text.isEmpty() );
00093   enableButton( User2, !text.isEmpty() );
00094 }
00095 
00096 //-----------------------------------------------------------------------------
00097 void RedirectDialog::slotUser1()
00098 {
00099   mImmediate = true;
00100   accept();
00101 }
00102 
00103 //-----------------------------------------------------------------------------
00104 void RedirectDialog::slotUser2()
00105 {
00106   mImmediate = false;
00107   accept();
00108 }
00109 
00110 //-----------------------------------------------------------------------------
00111 void RedirectDialog::accept()
00112 {
00113   mResentTo = mEditTo->text();
00114   if ( mResentTo.isEmpty() ) {
00115     KMessageBox::sorry( this,
00116         i18n("You cannot redirect the message without an address."),
00117         i18n("Empty Redirection Address") );
00118   }
00119   else done( Ok );
00120 }
00121 
00122 
00123 //-----------------------------------------------------------------------------
00124 void RedirectDialog::slotAddrBook()
00125 {
00126   AddressesDialog dlg( this );
00127 
00128   mResentTo = mEditTo->text();
00129   if ( !mResentTo.isEmpty() ) {
00130       TQStringList lst = KPIM::splitEmailAddrList( mResentTo );
00131       dlg.setSelectedTo( lst );
00132   }
00133 
00134   dlg.setRecentAddresses(
00135       RecentAddresses::self( KMKernel::config() )->kabcAddresses() );
00136 
00137   // Make it impossible to specify Cc or Bcc addresses as we support
00138   // only the Redirect-To header!
00139   dlg.setShowCC( false );
00140   dlg.setShowBCC( false );
00141 
00142   if (dlg.exec()==TQDialog::Rejected) return;
00143 
00144   mEditTo->setText( dlg.to().join(", ") );
00145   mEditTo->setEdited( true );
00146 }
00147 
00148 
00149 #include "redirectdialog.moc"