Fix confusing checkbox text due to class reuse
[kdepim.git] / kmail / addressvalidationjob.cpp
blob328c15c810349d3c5cc66d45861cb2a072f15806
1 /*
2 * This file is part of KMail.
4 * Copyright (c) 2010 KDAB
6 * Author: Tobias Koenig <tokoe@kde.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "addressvalidationjob.h"
24 #include <messagecomposer/aliasesexpandjob.h>
25 using MessageComposer::AliasesExpandJob;
27 #include "messagecomposersettings.h"
29 #include <klocale.h>
30 #include <kmessagebox.h>
32 #include <KPIMUtils/Email>
34 #include <messagecore/stringutil.h>
36 class AddressValidationJob::Private
38 public:
39 Private( AddressValidationJob *qq, const QString &emailAddresses, QWidget *parentWidget )
40 : q( qq ), mEmailAddresses( emailAddresses ), mIsValid( false ), mParentWidget( parentWidget )
44 void slotAliasExpansionDone( KJob* );
46 AddressValidationJob *q;
47 QString mEmailAddresses;
48 bool mIsValid;
49 QWidget *mParentWidget;
52 void AddressValidationJob::Private::slotAliasExpansionDone( KJob *job )
54 if ( job->error() ) {
55 q->setError( job->error() );
56 q->setErrorText( job->errorText() );
57 mIsValid = false;
58 q->emitResult();
59 return;
62 const AliasesExpandJob *expandJob = qobject_cast<AliasesExpandJob*>( job );
63 const QStringList emptyDistributionLists = expandJob->emptyDistributionLists();
65 QString brokenAddress;
67 const KPIMUtils::EmailParseResult errorCode = KPIMUtils::isValidAddressList( expandJob->addresses(), brokenAddress );
68 if ( !emptyDistributionLists.isEmpty() ) {
69 const QString errorMsg = i18n( "Distribution list \"%1\" is empty, it cannot be used.",
70 emptyDistributionLists.join( ", " ) );
71 KMessageBox::sorry( mParentWidget, errorMsg, i18n( "Invalid Email Address" ) );
72 mIsValid = false;
73 } else {
74 if ( !( errorCode == KPIMUtils::AddressOk ||
75 errorCode == KPIMUtils::AddressEmpty ) ) {
76 const QString errorMsg( "<qt><p><b>" + brokenAddress +
77 "</b></p><p>" +
78 KPIMUtils::emailParseResultToString( errorCode ) +
79 "</p></qt>" );
80 KMessageBox::sorry( mParentWidget, errorMsg, i18n( "Invalid Email Address" ) );
81 mIsValid = false;
85 mIsValid = true;
87 q->emitResult();
90 AddressValidationJob::AddressValidationJob( const QString &emailAddresses, QWidget *parentWidget, QObject *parent )
91 : KJob( parent ), d( new Private( this, emailAddresses, parentWidget ) )
95 AddressValidationJob::~AddressValidationJob()
97 delete d;
100 void AddressValidationJob::start()
102 AliasesExpandJob *job = new AliasesExpandJob( d->mEmailAddresses, MessageComposer::MessageComposerSettings::defaultDomain(), this );
103 connect( job, SIGNAL( result( KJob* ) ), SLOT( slotAliasExpansionDone( KJob* ) ) );
104 job->start();
108 bool AddressValidationJob::isValid() const
110 return d->mIsValid;
113 #include "addressvalidationjob.moc"