2 Copyright (c) 2003 Andreas Gungl <a.gungl@gmx.de>
4 KMail is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License, version 2, as
6 published by the Free Software Foundation.
8 KMail is distributed in the hope that it will be useful, but
9 WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 In addition, as a special exception, the copyright holders give
18 permission to link the code of this program with any edition of
19 the Qt library by Trolltech AS, Norway (or with modified versions
20 of Qt that use the same license as Qt), and distribute linked
21 combinations including the two. You must obey the GNU General
22 Public License in all respects for all of the code used other than
23 Qt. If you modify this file, you may extend this exception to
24 your version of the file, but you are not obligated to do so. If
25 you do not wish to do so, delete this exception statement from
29 #include "redirectdialog.h"
31 #include "mailkernel.h"
33 #include <akonadi/contact/emailaddressselectiondialog.h>
34 #include <kpimutils/email.h>
35 #include <messagecomposer/composerlineedit.h>
36 #include <messageviewer/autoqpointer.h>
38 #include <kiconloader.h>
40 #include <kmessagebox.h>
43 #include <QtCore/QStringList>
44 #include <QtGui/QFrame>
45 #include <QtGui/QLabel>
46 #include <QtGui/QPushButton>
47 #include <QtGui/QTreeView>
49 using namespace MailCommon
;
51 class RedirectDialog::Private
54 Private( RedirectDialog
*qq
, RedirectDialog::SendMode mode
)
55 : q( qq
), mSendMode( mode
)
61 void slotAddressSelection();
62 void slotAddressChanged( const QString
& );
66 MessageComposer::ComposerLineEdit
*mEditTo
;
70 RedirectDialog::SendMode mSendMode
;
73 void RedirectDialog::Private::slotUser1()
75 mSendMode
= RedirectDialog::SendNow
;
79 void RedirectDialog::Private::slotUser2()
81 mSendMode
= RedirectDialog::SendLater
;
85 void RedirectDialog::Private::slotAddressSelection()
87 MessageViewer::AutoQPointer
<Akonadi::EmailAddressSelectionDialog
> dlg( new Akonadi::EmailAddressSelectionDialog( q
) );
88 dlg
->view()->view()->setSelectionMode( QAbstractItemView::MultiSelection
);
90 mResentTo
= mEditTo
->text();
92 if ( dlg
->exec() != KDialog::Rejected
&& dlg
) {
93 QStringList addresses
;
94 foreach ( const Akonadi::EmailAddressSelection
&selection
, dlg
->selectedAddresses() )
95 addresses
<< selection
.quotedEmail();
97 if ( !mResentTo
.isEmpty() )
98 addresses
.prepend( mResentTo
);
100 mEditTo
->setText( addresses
.join( ", " ) );
101 mEditTo
->setModified( true );
105 void RedirectDialog::Private::slotAddressChanged( const QString
&text
)
107 q
->enableButton( KDialog::User1
, !text
.isEmpty() );
108 q
->enableButton( KDialog::User2
, !text
.isEmpty() );
112 RedirectDialog::RedirectDialog( SendMode mode
, QWidget
*parent
)
113 : KDialog( parent
), d( new Private( this, mode
) )
115 setCaption( i18n( "Redirect Message" ) );
116 setButtons( User1
| User2
| Cancel
);
117 setDefaultButton( mode
== SendNow
? User1
: User2
);
119 QFrame
*vbox
= new KVBox( this );
120 setMainWidget( vbox
);
121 d
->mLabelTo
= new QLabel( i18n( "Select the recipient &addresses "
122 "to redirect to:" ), vbox
);
124 KHBox
*hbox
= new KHBox( vbox
);
125 hbox
->setSpacing( 4 );
126 d
->mEditTo
= new MessageComposer::ComposerLineEdit( true, hbox
);
127 d
->mEditTo
->setObjectName( "toLine" );
128 d
->mEditTo
->setRecentAddressConfig( KernelIf
->config().data() );
129 d
->mEditTo
->setMinimumWidth( 300 );
131 d
->mBtnTo
= new QPushButton( QString(), hbox
);
132 d
->mBtnTo
->setObjectName( "toBtn" );
133 d
->mBtnTo
->setIcon( KIcon( "help-contents" ) );
134 d
->mBtnTo
->setIconSize( QSize( KIconLoader::SizeSmall
, KIconLoader::SizeSmall
) );
135 d
->mBtnTo
->setMinimumSize( d
->mBtnTo
->sizeHint() * 1.2 );
136 d
->mBtnTo
->setToolTip( i18n( "Use the Address-Selection Dialog" ) );
137 d
->mBtnTo
->setWhatsThis( i18n( "This button opens a separate dialog "
138 "where you can select recipients out "
139 "of all available addresses." ) );
141 connect( d
->mBtnTo
, SIGNAL(clicked()), SLOT(slotAddressSelection()) );
143 connect( d
->mEditTo
, SIGNAL(textChanged(QString
)), SLOT(slotAddressChanged(QString
)) );
144 d
->mLabelTo
->setBuddy( d
->mBtnTo
);
145 d
->mEditTo
->setFocus();
147 setButtonGuiItem( User1
, KGuiItem( i18n( "&Send Now" ), "mail-send" ) );
148 setButtonGuiItem( User2
, KGuiItem( i18n( "Send &Later" ), "mail-queue" ) );
149 connect( this, SIGNAL(user1Clicked()), this, SLOT(slotUser1()) );
150 connect( this, SIGNAL(user2Clicked()), this, SLOT(slotUser2()) );
151 enableButton( User1
, false );
152 enableButton( User2
, false );
155 RedirectDialog::~RedirectDialog()
160 QString
RedirectDialog::to() const
165 RedirectDialog::SendMode
RedirectDialog::sendMode() const
170 void RedirectDialog::accept()
172 d
->mResentTo
= d
->mEditTo
->text();
173 if ( d
->mResentTo
.isEmpty() ) {
174 KMessageBox::sorry( this, i18n( "You cannot redirect the message without an address." ),
175 i18n( "Empty Redirection Address" ) );
181 #include "redirectdialog.moc"