backport 1145339: no error box spam
[kdepim.git] / kaddressbook / recursiveitemfetchjob.h
blob49cf51038cba125c469573b983e75ab95fcf7869
1 /*
2 Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
20 #ifndef AKONADI_RECURSIVEITEMFETCHJOB_H
21 #define AKONADI_RECURSIVEITEMFETCHJOB_H
23 #include <akonadi/item.h>
24 #include <kjob.h>
26 namespace Akonadi {
28 class Collection;
29 class ItemFetchScope;
31 /**
32 * @short Job that fetches all items of a collection recursive.
34 * This job takes a collection as argument and returns a list of
35 * all items that are part of the passed collection and its child
36 * collections. The parts of the items that shall be fetched can
37 * by specified via an ItemFetchScope.
39 * Example:
41 * @code
43 * // Assume the following Akonadi storage tree structure:
44 * //
45 * // Root Collection
46 * // |
47 * // +- Contacts
48 * // | |
49 * // | +- Private
50 * // | |
51 * // | `- Business
52 * // |
53 * // `- Events
54 * //
55 * // Collection 'Contacts' has the ID 15, then the following code
56 * // returns all items from 'Contacts', 'Private' and 'Business'.
58 * const Akonadi::Collection contactsCollection( 15 );
60 * Akonadi::RecursiveItemFetchJob *job = new Akonadi::RecursiveItemFetchJob( contactsCollection );
61 * job->fetchScope().fetchFullPayload();
62 * connect( job, SIGNAL( result( KJob* ) ), this, SLOT( fetchResult( KJob* ) ) );
64 * job->start();
66 * ...
68 * MyClass::fetchResult( KJob *job )
69 * {
70 * Akonadi::RecursiveItemFetchJob *fetchJob = qobject_cast<Akonadi::RecursiveItemFetchJob*>( job );
71 * const Akonadi::Item::List items = fetchJob->items();
72 * // do something with the items
73 * }
75 * @endcode
77 * @author Tobias Koenig <tokoe@kde.org>
79 class RecursiveItemFetchJob : public KJob
81 Q_OBJECT
83 public:
84 /**
85 * Creates a new recursive item fetch job.
87 * @param collection The collection that shall be fetched recursive.
88 * @param parent The parent object.
90 explicit RecursiveItemFetchJob( const Akonadi::Collection &collection, QObject *parent = 0 );
92 /**
93 * Destroys the recursive item fetch job.
95 ~RecursiveItemFetchJob();
97 /**
98 * Sets the item fetch scope.
100 * The ItemFetchScope controls how much of an item's data is fetched
101 * from the server, e.g. whether to fetch the full item payload or
102 * only meta data.
104 * @param fetchScope The new scope for item fetch operations.
106 * @see fetchScope()
108 void setFetchScope( const Akonadi::ItemFetchScope &fetchScope );
111 * Returns the item fetch scope.
113 * Since this returns a reference it can be used to conveniently modify the
114 * current scope in-place, i.e. by calling a method on the returned reference
115 * without storing it in a local variable. See the ItemFetchScope documentation
116 * for an example.
118 * @return a reference to the current item fetch scope
120 * @see setFetchScope() for replacing the current item fetch scope
122 Akonadi::ItemFetchScope &fetchScope();
125 * Returns the list of fetched items.
127 Akonadi::Item::List items() const;
130 * Starts the recursive item fetch job.
132 virtual void start();
134 private:
135 //@cond PRIVATE
136 class Private;
137 Private* const d;
139 Q_PRIVATE_SLOT( d, void collectionFetchResult( KJob* ) )
140 Q_PRIVATE_SLOT( d, void itemFetchResult( KJob* ) )
141 //@endcond
146 #endif