resourceselectjob_p.h 3.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
    Copyright (c) 2009 Volker Krause <vkrause@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.
*/

20 21
#ifndef AKONADI_RESOURCESELECTJOB_P_H
#define AKONADI_RESOURCESELECTJOB_P_H
22

23
#include "akonadicore_export.h"
Daniel Vrátil's avatar
Daniel Vrátil committed
24
#include "job.h"
25

Laurent Montel's avatar
Laurent Montel committed
26 27
namespace Akonadi
{
28 29 30 31

class ResourceSelectJobPrivate;

/**
32 33 34 35 36 37 38 39
 * @internal
 *
 * @short Job that selects a resource context for remote identifier based operations.
 *
 * This job selects a resource context that is used whenever remote identifier
 * based operations ( e.g. fetch items or collections by remote identifier ) are
 * executed.
 *
40 41 42 43 44 45 46 47 48
 * Example:
 *
 * @code
 *
 * using namespace Akonadi;
 *
 * // Find out the akonadi id of the item with the remote id 'd1627013c6d5a2e7bb58c12560c27047'
 * // that is stored in the resource with identifier 'my_mail_resource'
 *
49
 * Session *m_resourceSession = new Session( "resourceSession" );
50 51 52
 *
 * ResourceSelectJob *job = new ResourceSelectJob( "my_mail_resource", resourceSession );
 *
Guy Maurel's avatar
Guy Maurel committed
53
 * connect( job, SIGNAL(result(KJob*)), SLOT(resourceSelected(KJob*)) );
54 55 56 57 58 59 60
 * ...
 *
 * void resourceSelected( KJob *job )
 * {
 *   if ( job->error() )
 *     return;
 *
61 62 63
 *   Item item;
 *   item.setRemoteIdentifier( "d1627013c6d5a2e7bb58c12560c27047" );
 *
64
 *   ItemFetchJob *fetchJob = new ItemFetchJob( item, m_resourceSession );
Guy Maurel's avatar
Guy Maurel committed
65
 *   connect( fetchJob, SIGNAL(result(KJob*)), SLOT(itemFetched(KJob*)) );
66 67 68 69 70 71
 * }
 *
 * void itemFetched( KJob *job )
 * {
 *   if ( job->error() )
 *     return;
72
 *
73
 *   const Item item = job->items().at(0);
74 75 76 77 78 79
 *
 *   qDebug() << "Remote id" << item.remoteId() << "has akonadi id" << item.id();
 * }
 *
 * @endcode
 *
80 81
 * @author Volker Krause <vkrause@kde.org>
 */
82
class AKONADICORE_EXPORT ResourceSelectJob : public Job
83
{
Guy Maurel's avatar
Guy Maurel committed
84 85
    Q_OBJECT
public:
86
    /**
87 88 89
     * Selects the specified resource for all following remote identifier
     * based operations in the same session.
     *
90 91
     * @param identifier The resource identifier, or any empty string to reset
     *                   the selection.
92 93
     * @param parent The parent object.
     */
Laurent Montel's avatar
Laurent Montel committed
94
    explicit ResourceSelectJob(const QString &identifier, QObject *parent = nullptr);
95

Guy Maurel's avatar
Guy Maurel committed
96
protected:
Laurent Montel's avatar
Laurent Montel committed
97
    void doStart() Q_DECL_OVERRIDE;
98
    bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) Q_DECL_OVERRIDE;
99

Guy Maurel's avatar
Guy Maurel committed
100
private:
101
    //@cond PRIVATE
Guy Maurel's avatar
Guy Maurel committed
102
    Q_DECLARE_PRIVATE(ResourceSelectJob)
103
    //@endcond PRIVATE
104 105 106 107 108
};

}

#endif