Messagelib

distributionlistexpandjob.cpp
1 /*
2  * This file is part of KMail.
3  *
4  * SPDX-FileCopyrightText: 2010 KDAB
5  * SPDX-FileContributor: Tobias Koenig <[email protected]>
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #include "distributionlistexpandjob.h"
11 
12 #include <Akonadi/ContactGroupExpandJob>
13 #include <Akonadi/ContactGroupSearchJob>
14 
15 using namespace MessageComposer;
16 
18  : KJob(parent)
19  , mListName(name)
20 {
21 }
22 
24 
26 {
27  auto job = new Akonadi::ContactGroupSearchJob(this);
28  job->setQuery(Akonadi::ContactGroupSearchJob::Name, mListName);
29  connect(job, &KJob::result, this, &DistributionListExpandJob::slotSearchDone);
30 }
31 
33 {
34  return mEmailAddresses.join(QLatin1String(", "));
35 }
36 
38 {
39  return mIsEmpty;
40 }
41 
42 void DistributionListExpandJob::slotSearchDone(KJob *job)
43 {
44  if (job->error()) {
45  setError(job->error());
46  setErrorText(job->errorText());
47  emitResult();
48  return;
49  }
50 
51  const Akonadi::ContactGroupSearchJob *searchJob = qobject_cast<Akonadi::ContactGroupSearchJob *>(job);
52 
53  const KContacts::ContactGroup::List groups = searchJob->contactGroups();
54  if (groups.isEmpty()) {
55  emitResult();
56  return;
57  }
58 
59  auto expandJob = new Akonadi::ContactGroupExpandJob(groups.first());
60  connect(expandJob, &KJob::result, this, &DistributionListExpandJob::slotExpansionDone);
61  expandJob->start();
62 }
63 
64 void DistributionListExpandJob::slotExpansionDone(KJob *job)
65 {
66  if (job->error()) {
67  setError(job->error());
68  setErrorText(job->errorText());
69  emitResult();
70  return;
71  }
72 
73  const Akonadi::ContactGroupExpandJob *expandJob = qobject_cast<Akonadi::ContactGroupExpandJob *>(job);
74 
75  const KContacts::Addressee::List contacts = expandJob->contacts();
76  mEmailAddresses.reserve(contacts.count());
77  for (const KContacts::Addressee &contact : contacts) {
78  mEmailAddresses << contact.fullEmail();
79  }
80 
81  mIsEmpty = mEmailAddresses.isEmpty();
82 
83  emitResult();
84 }
QString addresses() const
Returns the email addresses of the list members.
bool isEmpty() const const
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
void setErrorText(const QString &errorText)
void result(KJob *job)
T & first()
KContacts::Addressee::List contacts() const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void reserve(int alloc)
QString errorText() const
bool isEmpty() const const
QString join(const QString &separator) const const
~DistributionListExpandJob() override
Destroys the distribution list expand job.
KContacts::ContactGroup::List contactGroups() const
AddresseeList List
bool isEmpty() const
Returns whether the list of email addresses is empty.
void emitResult()
int error() const
void setError(int errorCode)
DistributionListExpandJob(const QString &name, QObject *parent=nullptr)
Creates a new distribution list expand job.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed May 25 2022 03:55:39 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.