Akonadi::ItemFetchJob Class
class Akonadi::ItemFetchJobJob that fetches items from the Akonadi storage. More...
| Header: | #include <Akonadi/ItemFetchJob> |
| CMake: | find_package(KPim6 REQUIRED COMPONENTS AkonadiCore)target_link_libraries(mytarget PRIVATE KPim6::AkonadiCore) |
| Inherits: | Akonadi::Job |
Public Functions
| ItemFetchJob(const Akonadi::Collection &collection, QObject *parent = nullptr) | |
| ItemFetchJob(const Akonadi::Tag &tag, QObject *parent = nullptr) | |
| ItemFetchJob(const QList<Akonadi::Item::Id> &items, QObject *parent = nullptr) | |
| virtual | ~ItemFetchJob() override |
| void | clearItems() |
| int | count() const |
| Akonadi::ItemFetchJob::DeliveryOptions | deliveryOptions() const |
| Akonadi::ItemFetchScope & | fetchScope() |
| Akonadi::Item::List | items() const |
| void | setDeliveryOption(Akonadi::ItemFetchJob::DeliveryOptions options) |
| void | setFetchScope(const Akonadi::ItemFetchScope &fetchScope) |
| void | setLimit(int limit, int start, Qt::SortOrder order = Qt::DescendingOrder) |
Signals
| void | itemsReceived(const Akonadi::Item::List &items) |
Detailed Description
This class is used to fetch items from the Akonadi storage. Which parts of the items (e.g. headers only, attachments or all) can be specified by the ItemFetchScope.
Note that ItemFetchJob does not refresh the Akonadi storage from the backend; this is unnecessary due to the fact that backend updates automatically trigger an update to the Akonadi database whenever they occur (unless the resource is offline).
Note that items can not be created in the root collection (Collection::root()) and therefore can not be fetched from there either. That is - an item fetch in the root collection will yield an empty list.
Example:
// Fetch all items with full payload from a collection const Collection collection = getCollection(); Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob(collection); connect(job, &KJob::result, this, &MyClass::jobFinished); job->fetchScope().fetchFullPayload(); ... MyClass::jobFinished(KJob *job) { if (job->error()) { qDebug() << "Error occurred"; return; } Akonadi::ItemFetchJob *fetchJob = qobject_cast<Akonadi::ItemFetchJob*>(job); const Akonadi::Item::List items = fetchJob->items(); for (const Akonadi::Item &item : items) { qDebug() << "Item ID:" << item.id(); } }
Author: Volker Krause <vkrause@kde.org>
Member Function Documentation
[explicit] ItemFetchJob::ItemFetchJob(const Akonadi::Collection &collection, QObject *parent = nullptr)
Creates a new item fetch job that retrieves all items inside the given collection.
collection The parent collection to fetch all items from. parent The parent object.
[explicit] ItemFetchJob::ItemFetchJob(const Akonadi::Tag &tag, QObject *parent = nullptr)
Creates a new item fetch job that retrieves all items tagged with specified tag.
tag The tag to fetch all items from. parent The parent object.
[explicit] ItemFetchJob::ItemFetchJob(const QList<Akonadi::Item::Id> &items, QObject *parent = nullptr)
Convenience ctor equivalent to ItemFetchJob(const Item::List &items, QObject *parent = nullptr)
[override virtual noexcept] ItemFetchJob::~ItemFetchJob()
Destroys the item fetch job.
void ItemFetchJob::clearItems()
Save memory by clearing the fetched items.
int ItemFetchJob::count() const
Returns the total number of retrieved items. This works also without the ItemGetter DeliveryOption.
Akonadi::ItemFetchJob::DeliveryOptions ItemFetchJob::deliveryOptions() const
Returns the delivery options
Akonadi::ItemFetchScope &ItemFetchJob::fetchScope()
Returns the item fetch scope.
Since this returns a reference it can be used to conveniently modify the current scope in-place, i.e. by calling a method on the returned reference without storing it in a local variable. See the ItemFetchScope documentation for an example.
Returns a reference to the current item fetch scope
See also setFetchScope(), for, replacing, the, current, item, fetch, and scope.
Akonadi::Item::List ItemFetchJob::items() const
Returns the fetched items.
This returns an empty list when not using the ItemGetter DeliveryOption.
Note: The items are invalid before the result(KJob*) signal has been emitted or if an error occurred.
[signal] void ItemFetchJob::itemsReceived(const Akonadi::Item::List &items)
This signal is emitted whenever new items have been fetched completely.
Note: This is an optimization; instead of waiting for the end of the job and calling items(), you can connect to this signal and get the items incrementally.
items The fetched items.
void ItemFetchJob::setDeliveryOption(Akonadi::ItemFetchJob::DeliveryOptions options)
Sets the mechanisms by which the items should be fetched
void ItemFetchJob::setFetchScope(const Akonadi::ItemFetchScope &fetchScope)
Sets the item fetch scope.
The ItemFetchScope controls how much of an item's data is fetched from the server, e.g. whether to fetch the full item payload or only meta data.
fetchScope The new scope for item fetch operations.
See also fetchScope().
void ItemFetchJob::setLimit(int limit, int start, Qt::SortOrder order = Qt::DescendingOrder)
Sets the limit of fetched items.
limit the maximum number of items to retrieve. The default value for limit is -1, indicating no limit. start specifies the offset of the first item to retrieve. order specifies whether items will be fetched starting with the highest or lowest ID of the item.