1/*
2 Copyright (c) 2014 Christian Mollekopf <mollekopf@kolabsys.com>
3
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.
8
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.
13
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.
18*/
19
20#ifndef AKONADI_TAGFETCHJOB_H
21#define AKONADI_TAGFETCHJOB_H
22
23#include <akonadi/job.h>
24#include <akonadi/tag.h>
25
26namespace Akonadi {
27
28class TagFetchScope;
29class TagFetchJobPrivate;
30
31/**
32 * @short Job that fetches tags from the Akonadi storage.
33 *
34 * This class is used to fetch tags from the Akonadi storage.
35 *
36 * If you want to fetch all items with given tag, use ItemFetchJob and the
37 * ItemFetchJob(const Tag &tag, QObject *parent = 0) constructor (since 4.14)
38 *
39 * @since 4.13
40 */
41class AKONADI_EXPORT TagFetchJob : public Job
42{
43 Q_OBJECT
44
45public:
46 /**
47 * Constructs a new tag fetch job that retrieves all tags stored in Akonadi.
48 *
49 * @param parent The parent object.
50 */
51 explicit TagFetchJob(QObject *parent = 0);
52
53 /**
54 * Constructs a new tag fetch job that retrieves the specified tag.
55 * If the tag has a uid set, this is used to identify the tag on the Akonadi
56 * server. If only a remote identifier is available, that is used. However
57 * as remote identifiers are internal to resources, it's necessary to set
58 * the resource context (see ResourceSelectJob).
59 *
60 * @param tag The tag to fetch.
61 * @param parent The parent object.
62 */
63 explicit TagFetchJob(const Tag &tag, QObject *parent = 0);
64
65 /**
66 * Constructs a new tag fetch job that retrieves specified tags.
67 * If the tags have a uid set, this is used to identify the tags on the Akonadi
68 * server. If only a remote identifier is available, that is used. However
69 * as remote identifiers are internal to resources, it's necessary to set
70 * the resource context (see ResourceSelectJob).
71 *
72 * @param tags Tags to fetch.
73 * @param parent The parent object.
74 */
75 explicit TagFetchJob(const Tag::List &tags, QObject *parent = 0);
76
77 /**
78 * Convenience ctor equivalent to ItemFetchJob(const Item::List &items, QObject *parent = 0)
79 *
80 * @param ids UIDs of tags to fetch.
81 * @param parent The parent object.
82 */
83 explicit TagFetchJob(const QList<Tag::Id> &ids, QObject *parent = 0);
84
85 /**
86 * Sets the tag fetch scope.
87 *
88 * The TagFetchScope controls how much of an tags's data is fetched
89 * from the server.
90 *
91 * @param fetchScope The new fetch scope for tag fetch operations.
92 * @see fetchScope()
93 */
94 void setFetchScope(const TagFetchScope &fetchScope);
95
96 /**
97 * Returns the tag fetch scope.
98 *
99 * Since this returns a reference it can be used to conveniently modify the
100 * current scope in-place, i.e. by calling a method on the returned reference
101 * without storing it in a local variable. See the TagFetchScope documentation
102 * for an example.
103 *
104 * @return a reference to the current tag fetch scope
105 *
106 * @see setFetchScope() for replacing the current tag fetch scope
107 */
108 TagFetchScope &fetchScope();
109
110 /**
111 * Returns the fetched tags after the job has been completed.
112 */
113 Tag::List tags() const;
114
115Q_SIGNALS:
116 /**
117 * This signal is emitted whenever new tags have been fetched completely.
118 *
119 * @param items The fetched tags.
120 */
121 void tagsReceived(const Akonadi::Tag::List &tags);
122
123protected:
124 virtual void doStart();
125 virtual void doHandleResponse(const QByteArray &tag, const QByteArray &data);
126
127private:
128 Q_DECLARE_PRIVATE(TagFetchJob)
129
130 //@cond PRIVATE
131 Q_PRIVATE_SLOT(d_func(), void timeout())
132 //@endcond
133};
134
135}
136
137#endif
138