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/contact/contactgroupexpandjob.h>
13 #include <akonadi/contact/contactgroupsearchjob.h>
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 
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 
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 }
DistributionListExpandJob(const QString &name, QObject *parent=nullptr)
Creates a new distribution list expand job.
QString addresses() const
Returns the email addresses of the list members.
void emitResult()
void reserve(int alloc)
void setError(int errorCode)
QString join(const QString &separator) const const
bool isEmpty() const
Returns whether the list of email addresses is empty.
void setErrorText(const QString &errorText)
KContacts::Addressee::List contacts() const
bool isEmpty() const const
KContacts::ContactGroup::List contactGroups() const
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
AddresseeList List
~DistributionListExpandJob() override
Destroys the distribution list expand job.
void result(KJob *job)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
T qobject_cast(QObject *object)
QString errorText() const
int error() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Nov 28 2021 23:05:43 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.