Messagelib

distributionlistexpandjob.cpp
1/*
2 * This file is part of KMail.
3 *
4 * SPDX-FileCopyrightText: 2010 KDAB
5 * SPDX-FileContributor: Tobias Koenig <tokoe@kde.org>
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
15using 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(QLatin1StringView(", "));
35}
36
38{
39 return mIsEmpty;
40}
41
42void 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
64void 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}
85
86#include "moc_distributionlistexpandjob.cpp"
KContacts::Addressee::List contacts() const
KContacts::ContactGroup::List contactGroups() const
AddresseeList List
void setErrorText(const QString &errorText)
void emitResult()
int error() const
void result(KJob *job)
void setError(int errorCode)
QString errorText() const
bool isEmpty() const
Returns whether the list of email addresses is empty.
~DistributionListExpandJob() override
Destroys the distribution list expand job.
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.
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
T & first()
bool isEmpty() const const
void reserve(qsizetype size)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
QString join(QChar separator) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:24 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.