File indexing completed on 2024-11-24 04:39:26
0001 /* 0002 This file is part of Akonadi Contact. 0003 0004 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #pragma once 0010 0011 #include "akonadi-contact-core_export.h" 0012 0013 #include <KContacts/Addressee> 0014 #include <KContacts/ContactGroup> 0015 #include <KJob> 0016 0017 #include <memory> 0018 0019 namespace Akonadi 0020 { 0021 class ContactGroupExpandJobPrivate; 0022 0023 /** 0024 * @short Job that expands a ContactGroup to a list of contacts. 0025 * 0026 * This job takes a KContacts::ContactGroup object or a name of a contact group and 0027 * expands it to a list of KContacts::Addressee objects by creating temporary KContacts::Addressee objects 0028 * for the KContacts::ContactGroup::Data objects of the group and fetching the 0029 * complete contacts from the Akonadi storage for the 0030 * KContacts::ContactGroup::ContactReferences of the group. 0031 * 0032 * @code 0033 * 0034 * const KContacts::ContactGroup group = ...; 0035 * 0036 * Akonadi::ContactGroupExpandJob *job = new Akonadi::ContactGroupExpandJob( group ); 0037 * connect( job, SIGNAL(result(KJob*)), this, SLOT(expandResult(KJob*)) ); 0038 * job->start(); 0039 * 0040 * ... 0041 * 0042 * MyClass::expandResult( KJob *job ) 0043 * { 0044 * Akonadi::ContactGroupExpandJob *expandJob = qobject_cast<Akonadi::ContactGroupExpandJob*>( job ); 0045 * const KContacts::Addressee::List contacts = expandJob->contacts(); 0046 * // do something with the contacts 0047 * } 0048 * 0049 * @endcode 0050 * 0051 * @author Tobias Koenig <tokoe@kde.org> 0052 * @since 4.4 0053 */ 0054 class AKONADI_CONTACT_CORE_EXPORT ContactGroupExpandJob : public KJob 0055 { 0056 Q_OBJECT 0057 0058 public: 0059 /** 0060 * Creates a new contact group expand job. 0061 * 0062 * @param group The contact group to expand. 0063 * @param parent The parent object. 0064 */ 0065 explicit ContactGroupExpandJob(const KContacts::ContactGroup &group, QObject *parent = nullptr); 0066 0067 /** 0068 * Creates a new contact group expand job. 0069 * 0070 * @param name The name of the contact group to expand. 0071 * @param parent The parent object. 0072 * 0073 * @since 4.5 0074 */ 0075 explicit ContactGroupExpandJob(const QString &name, QObject *parent = nullptr); 0076 0077 /** 0078 * Destroys the contact group expand job. 0079 */ 0080 ~ContactGroupExpandJob() override; 0081 0082 /** 0083 * Returns the list of contacts. 0084 */ 0085 [[nodiscard]] KContacts::Addressee::List contacts() const; 0086 0087 /** 0088 * Starts the expand job. 0089 */ 0090 void start() override; 0091 0092 private: 0093 //@cond PRIVATE 0094 friend class ContactGroupExpandJobPrivate; 0095 std::unique_ptr<ContactGroupExpandJobPrivate> const d; 0096 0097 // Already use with QMetaObject::invokeMethod 0098 Q_PRIVATE_SLOT(d, void resolveGroup()) 0099 //@endcond 0100 }; 0101 }