• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
  • job
addressvalidationjob.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of KMail.
3  *
4  * Copyright (c) 2010 KDAB
5  *
6  * Author: Tobias Koenig <tokoe@kde.org>
7  *
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.
12  *
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.
17  *
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.
21  */
22 
23 #include "addressvalidationjob.h"
24 #include <messagecomposer/job/aliasesexpandjob.h>
25 using MessageComposer::AliasesExpandJob;
26 
27 #include "settings/messagecomposersettings.h"
28 
29 #include <klocale.h>
30 #include <kmessagebox.h>
31 
32 #include <KPIMUtils/Email>
33 
34 
35 class AddressValidationJob::Private
36 {
37 public:
38  Private( AddressValidationJob *qq, const QString &emailAddresses, QWidget *parentWidget )
39  : q( qq ),
40  mEmailAddresses( emailAddresses ),
41  mIsValid( false ),
42  mParentWidget( parentWidget )
43  {
44  }
45 
46  void slotAliasExpansionDone( KJob* );
47 
48  AddressValidationJob *q;
49  QString mEmailAddresses;
50  bool mIsValid;
51  QWidget *mParentWidget;
52 };
53 
54 void AddressValidationJob::Private::slotAliasExpansionDone( KJob *job )
55 {
56  mIsValid = true;
57 
58  if ( job->error() ) {
59  q->setError( job->error() );
60  q->setErrorText( job->errorText() );
61  mIsValid = false;
62  q->emitResult();
63  return;
64  }
65 
66  const AliasesExpandJob *expandJob = qobject_cast<AliasesExpandJob*>( job );
67  const QStringList emptyDistributionLists = expandJob->emptyDistributionLists();
68 
69  QString brokenAddress;
70 
71  const KPIMUtils::EmailParseResult errorCode = KPIMUtils::isValidAddressList( expandJob->addresses(), brokenAddress );
72  if ( !emptyDistributionLists.isEmpty() ) {
73  QString errorMsg;
74  const int numberOfDistributionList( emptyDistributionLists.count() );
75  QString listOfDistributionList;
76  for ( int i = 0; i < numberOfDistributionList; ++i ) {
77  if ( i != 0 )
78  listOfDistributionList.append( QLatin1String(", ") );
79  listOfDistributionList.append( QString::fromLatin1( "\"%1\"" ).arg( emptyDistributionLists.at( i ) ) );
80  }
81  errorMsg = i18np( "Distribution list %2 is empty, it cannot be used.",
82  "Distribution lists %2 are empty, they cannot be used.",
83  numberOfDistributionList, listOfDistributionList );
84  KMessageBox::sorry( mParentWidget, errorMsg, i18n( "Invalid Email Address" ) );
85  mIsValid = false;
86  } else {
87  if ( !( errorCode == KPIMUtils::AddressOk ||
88  errorCode == KPIMUtils::AddressEmpty ) ) {
89  const QString errorMsg( QLatin1String("<qt><p><b>") + brokenAddress +
90  QLatin1String("</b></p><p>") +
91  KPIMUtils::emailParseResultToString( errorCode ) +
92  QLatin1String("</p></qt>") );
93  KMessageBox::sorry( mParentWidget, errorMsg, i18n( "Invalid Email Address" ) );
94  mIsValid = false;
95  }
96  }
97 
98  q->emitResult();
99 }
100 
101 AddressValidationJob::AddressValidationJob( const QString &emailAddresses, QWidget *parentWidget, QObject *parent )
102  : KJob( parent ), d( new Private( this, emailAddresses, parentWidget ) )
103 {
104 }
105 
106 AddressValidationJob::~AddressValidationJob()
107 {
108  delete d;
109 }
110 
111 void AddressValidationJob::start()
112 {
113  AliasesExpandJob *job = new AliasesExpandJob( d->mEmailAddresses, MessageComposer::MessageComposerSettings::defaultDomain(), this );
114  connect( job, SIGNAL(result(KJob*)), SLOT(slotAliasExpansionDone(KJob*)) );
115  job->start();
116 }
117 
118 bool AddressValidationJob::isValid() const
119 {
120  return d->mIsValid;
121 }
122 
123 #include "addressvalidationjob.moc"
AddressValidationJob
Definition: addressvalidationjob.h:28
AddressValidationJob::start
void start()
Definition: addressvalidationjob.cpp:111
QWidget
AddressValidationJob::isValid
bool isValid() const
Definition: addressvalidationjob.cpp:118
AddressValidationJob::~AddressValidationJob
~AddressValidationJob()
Definition: addressvalidationjob.cpp:106
QObject
AddressValidationJob::AddressValidationJob
AddressValidationJob(const QString &emailAddresses, QWidget *parentWidget, QObject *parent=0)
Definition: addressvalidationjob.cpp:101
addressvalidationjob.h
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal