Framework for looking up contacts directly in nepomuk in addition to going through...
[kdepim.git] / mailcommon / redirectdialog.cpp
bloba46cc2ae4575333894b986f9ef14aed9d45f54cf
1 /*
2 Copyright (c) 2003 Andreas Gungl <a.gungl@gmx.de>
4 This program 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 This program 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
26 your version.
29 #include "redirectdialog.h"
30 #include "mailkernel.h"
32 #include <messagecomposer/composerlineedit.h>
34 #include <messageviewer/autoqpointer.h>
36 #include <Akonadi/Contact/EmailAddressSelectionDialog>
38 #include <KPIMUtils/Email>
40 #include <KIconLoader>
41 #include <KLocale>
42 #include <KMessageBox>
43 #include <KVBox>
45 #include <QFrame>
46 #include <QLabel>
47 #include <QPushButton>
48 #include <QTreeView>
50 using namespace MailCommon;
52 class RedirectDialog::Private
54 public:
55 Private( RedirectDialog *qq, RedirectDialog::SendMode mode )
56 : q( qq ), mSendMode( mode )
60 void slotUser1();
61 void slotUser2();
62 void slotAddressSelection();
63 void slotAddressChanged( const QString & );
65 RedirectDialog *q;
66 QLabel *mLabelTo;
67 MessageComposer::ComposerLineEdit *mEditTo;
68 QPushButton *mBtnTo;
70 QString mResentTo;
71 RedirectDialog::SendMode mSendMode;
74 void RedirectDialog::Private::slotUser1()
76 mSendMode = RedirectDialog::SendNow;
77 q->accept();
80 void RedirectDialog::Private::slotUser2()
82 mSendMode = RedirectDialog::SendLater;
83 q->accept();
86 void RedirectDialog::Private::slotAddressSelection()
88 MessageViewer::AutoQPointer<Akonadi::EmailAddressSelectionDialog> dlg(
89 new Akonadi::EmailAddressSelectionDialog( q ) );
91 dlg->view()->view()->setSelectionMode( QAbstractItemView::MultiSelection );
93 mResentTo = mEditTo->text();
95 if ( dlg->exec() != KDialog::Rejected && dlg ) {
96 QStringList addresses;
97 foreach ( const Akonadi::EmailAddressSelection &selection, dlg->selectedAddresses() ) {
98 addresses << selection.quotedEmail();
101 if ( !mResentTo.isEmpty() ) {
102 addresses.prepend( mResentTo );
105 mEditTo->setText( addresses.join( ", " ) );
106 mEditTo->setModified( true );
110 void RedirectDialog::Private::slotAddressChanged( const QString &text )
112 q->enableButton( KDialog::User1, !text.isEmpty() );
113 q->enableButton( KDialog::User2, !text.isEmpty() );
116 RedirectDialog::RedirectDialog( SendMode mode, QWidget *parent )
117 : KDialog( parent ), d( new Private( this, mode ) )
119 setCaption( i18n( "Redirect Message" ) );
120 setButtons( User1 | User2 | Cancel );
121 setDefaultButton( mode == SendNow ? User1 : User2 );
123 QFrame *vbox = new KVBox( this );
124 setMainWidget( vbox );
125 d->mLabelTo = new QLabel( i18n( "Select the recipient &addresses "
126 "to redirect to:" ), vbox );
128 KHBox *hbox = new KHBox( vbox );
129 hbox->setSpacing( 4 );
130 d->mEditTo = new MessageComposer::ComposerLineEdit( true, hbox );
131 d->mEditTo->setObjectName( "toLine" );
132 d->mEditTo->setRecentAddressConfig( KernelIf->config().data() );
133 d->mEditTo->setMinimumWidth( 300 );
135 d->mBtnTo = new QPushButton( QString(), hbox );
136 d->mBtnTo->setObjectName( "toBtn" );
137 d->mBtnTo->setIcon( KIcon( "help-contents" ) );
138 d->mBtnTo->setIconSize( QSize( KIconLoader::SizeSmall, KIconLoader::SizeSmall ) );
139 d->mBtnTo->setMinimumSize( d->mBtnTo->sizeHint() * 1.2 );
140 d->mBtnTo->setToolTip( i18n( "Use the Address-Selection Dialog" ) );
141 d->mBtnTo->setWhatsThis( i18n( "This button opens a separate dialog "
142 "where you can select recipients out "
143 "of all available addresses." ) );
145 connect( d->mBtnTo, SIGNAL(clicked()), SLOT(slotAddressSelection()) );
147 connect( d->mEditTo, SIGNAL(textChanged(QString)), SLOT(slotAddressChanged(QString)) );
148 d->mLabelTo->setBuddy( d->mBtnTo );
149 d->mEditTo->setFocus();
151 setButtonGuiItem( User1, KGuiItem( i18n( "&Send Now" ), "mail-send" ) );
152 setButtonGuiItem( User2, KGuiItem( i18n( "Send &Later" ), "mail-queue" ) );
153 connect( this, SIGNAL(user1Clicked()), this, SLOT(slotUser1()) );
154 connect( this, SIGNAL(user2Clicked()), this, SLOT(slotUser2()) );
155 enableButton( User1, false );
156 enableButton( User2, false );
159 RedirectDialog::~RedirectDialog()
161 delete d;
164 QString RedirectDialog::to() const
166 return d->mResentTo;
169 RedirectDialog::SendMode RedirectDialog::sendMode() const
171 return d->mSendMode;
174 void RedirectDialog::accept()
176 d->mResentTo = d->mEditTo->text();
177 if ( d->mResentTo.isEmpty() ) {
178 KMessageBox::sorry(
179 this,
180 i18n( "You cannot redirect the message without an address." ),
181 i18n( "Empty Redirection Address" ) );
182 } else {
183 done( Ok );
187 #include "redirectdialog.moc"