contactgroupexpandjob.h 3.22 KB
Newer Older
Tobias Koenig's avatar
Tobias Koenig committed
1
/*
Tobias Koenig's avatar
Tobias Koenig committed
2 3
    This file is part of Akonadi Contact.

Tobias Koenig's avatar
Tobias Koenig committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
    Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#ifndef AKONADI_CONTACTGROUPEXPANDJOB_H
#define AKONADI_CONTACTGROUPEXPANDJOB_H

#include "akonadi-contact_export.h"

Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
27 28
#include <kcontacts/addressee.h>
#include <kcontacts/contactgroup.h>
Tobias Koenig's avatar
Tobias Koenig committed
29 30
#include <kjob.h>

Laurent Montel's avatar
Laurent Montel committed
31 32
namespace Akonadi
{
Tobias Koenig's avatar
Tobias Koenig committed
33 34 35 36

/**
 * @short Job that expands a ContactGroup to a list of contacts.
 *
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
37 38 39
 * This job takes a KContacts::ContactGroup object or a name of a contact group and
 * expands it to a list of KContacts::Addressee objects by creating temporary KContacts::Addressee objects
 * for the KContacts::ContactGroup::Data objects of the group and fetching the
Tobias Koenig's avatar
Tobias Koenig committed
40
 * complete contacts from the Akonadi storage for the
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
41
 * KContacts::ContactGroup::ContactReferences of the group.
Tobias Koenig's avatar
Tobias Koenig committed
42 43 44
 *
 * @code
 *
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
45
 * const KContacts::ContactGroup group = ...;
Tobias Koenig's avatar
Tobias Koenig committed
46 47
 *
 * Akonadi::ContactGroupExpandJob *job = new Akonadi::ContactGroupExpandJob( group );
Guy Maurel's avatar
Guy Maurel committed
48
 * connect( job, SIGNAL(result(KJob*)), this, SLOT(expandResult(KJob*)) );
Tom Albers's avatar
Tom Albers committed
49
 * job->start();
Tobias Koenig's avatar
Tobias Koenig committed
50 51 52 53 54 55
 *
 * ...
 *
 * MyClass::expandResult( KJob *job )
 * {
 *   Akonadi::ContactGroupExpandJob *expandJob = qobject_cast<Akonadi::ContactGroupExpandJob*>( job );
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
56
 *   const KContacts::Addressee::List contacts = expandJob->contacts();
Tobias Koenig's avatar
Tobias Koenig committed
57 58 59 60 61 62
 *   // do something with the contacts
 * }
 *
 * @endcode
 *
 * @author Tobias Koenig <tokoe@kde.org>
Tobias Koenig's avatar
Tobias Koenig committed
63
 * @since 4.4
Tobias Koenig's avatar
Tobias Koenig committed
64 65 66
 */
class AKONADI_CONTACT_EXPORT ContactGroupExpandJob : public KJob
{
Guy Maurel's avatar
Guy Maurel committed
67
    Q_OBJECT
Tobias Koenig's avatar
Tobias Koenig committed
68

Guy Maurel's avatar
Guy Maurel committed
69
public:
Tobias Koenig's avatar
Tobias Koenig committed
70 71 72 73 74 75
    /**
     * Creates a new contact group expand job.
     *
     * @param group The contact group to expand.
     * @param parent The parent object.
     */
Laurent Montel's avatar
Laurent Montel committed
76
    explicit ContactGroupExpandJob(const KContacts::ContactGroup &group, QObject *parent = nullptr);
Tobias Koenig's avatar
Tobias Koenig committed
77

78 79 80 81 82 83 84 85
    /**
     * Creates a new contact group expand job.
     *
     * @param name The name of the contact group to expand.
     * @param parent The parent object.
     *
     * @since 4.5
     */
Laurent Montel's avatar
Laurent Montel committed
86
    explicit ContactGroupExpandJob(const QString &name, QObject *parent = nullptr);
87

Tobias Koenig's avatar
Tobias Koenig committed
88 89 90 91 92 93 94 95
    /**
     * Destroys the contact group expand job.
     */
    ~ContactGroupExpandJob();

    /**
     * Returns the list of contacts.
     */
Aleix Pol Gonzalez's avatar
Aleix Pol Gonzalez committed
96
    KContacts::Addressee::List contacts() const;
Tobias Koenig's avatar
Tobias Koenig committed
97 98 99 100

    /**
     * Starts the expand job.
     */
101
    void start() override;
Tobias Koenig's avatar
Tobias Koenig committed
102

Guy Maurel's avatar
Guy Maurel committed
103
private:
Tobias Koenig's avatar
Tobias Koenig committed
104 105
    //@cond PRIVATE
    class Private;
Guy Maurel's avatar
Guy Maurel committed
106
    Private *const d;
Tobias Koenig's avatar
Tobias Koenig committed
107

Christian Mollekopf's avatar
Christian Mollekopf committed
108
    Q_PRIVATE_SLOT(d, void resolveGroup())
Guy Maurel's avatar
Guy Maurel committed
109 110
    Q_PRIVATE_SLOT(d, void fetchResult(KJob *))
    Q_PRIVATE_SLOT(d, void searchResult(KJob *))
Tobias Koenig's avatar
Tobias Koenig committed
111 112 113 114 115 116
    //@endcond
};

}

#endif