Akonadi::ItemSync Class

class Akonadi::ItemSync

Syncs between items known to a client (usually a resource) and the Akonadi storage. More...

Header: #include <Akonadi/ItemSync>
CMake: find_package(KPim6 REQUIRED COMPONENTS AkonadiCore)
target_link_libraries(mytarget PRIVATE KPim6::AkonadiCore)
Inherits: Akonadi::Job

Public Types

enum TransactionMode { SingleTransaction, MultipleTransactions, NoTransaction }

Public Functions

ItemSync(const Akonadi::Collection &collection, const QDateTime &timestamp = {}, QObject *parent = nullptr)
virtual ~ItemSync() override
int batchSize() const
void deliveryDone()
Akonadi::ItemSync::MergeMode mergeMode() const
void rollback()
void setBatchSize(int)
void setDisableAutomaticDeliveryDone(bool disable)
void setFullSyncItems(const Akonadi::Item::List &items)
void setIncrementalSyncItems(const Akonadi::Item::List &changedItems, const Akonadi::Item::List &removedItems)
void setMergeMode(Akonadi::ItemSync::MergeMode mergeMode)
void setStreamingEnabled(bool enable)
void setTotalItems(int amount)
void setTransactionMode(Akonadi::ItemSync::TransactionMode mode)

Signals

void readyForNextBatch(int remainingBatchSize)

Detailed Description

Remote Id must only be set by the resource storing the item, other clients should leave it empty, since the resource responsible for the target collection will be notified about the addition and then create a suitable remote Id.

There are two different forms of ItemSync usage: - Full-Sync: meaning the client provides all valid items, i.e. any item not part of the list but currently stored in Akonadi will be removed - Incremental-Sync: meaning the client provides two lists, one for items which are new or modified and one for items which should be removed. Any item not part of either list but currently stored in Akonadi will not be changed.

Note: This is provided for convenience to implement "save all" like behavior, however it is strongly recommended to use single item jobs whenever possible, e.g. ItemCreateJob, ItemModifyJob and ItemDeleteJob

Author: Tobias Koenig <tokoe@kde.org>

Member Type Documentation

enum ItemSync::TransactionMode

Transaction mode used by ItemSync.

Member Function Documentation

[explicit] ItemSync::ItemSync(const Akonadi::Collection &collection, const QDateTime &timestamp = {}, QObject *parent = nullptr)

* Creates a new item synchronizer. * * collection The collection we are syncing. * timestamp Optional timestamp of itemsync start. Will be used to detect local changes that happen while the ItemSync is running. * parent The parent object.

[override virtual noexcept] ItemSync::~ItemSync()

Destroys the item synchronizer.

int ItemSync::batchSize() const

Minimum number of items required to start processing in streaming mode. When MultipleTransactions is used, one transaction per batch will be created.

See also setBatchSize().

void ItemSync::deliveryDone()

Notify ItemSync that all remote items have been delivered. Only call this in streaming mode.

Akonadi::ItemSync::MergeMode ItemSync::mergeMode() const

Returns current merge mode

See also setMergeMode().

[signal] void ItemSync::readyForNextBatch(int remainingBatchSize)

Signals the resource that new items can be delivered. remainingBatchSize the number of items required to complete the batch (typically the same as batchSize())

void ItemSync::rollback()

Aborts the sync process and rolls back all not yet committed transactions. Use this if an external error occurred during the sync process (such as the user canceling it).

void ItemSync::setBatchSize(int)

Set the batch size.

The default is 10.

Note: You must call this method before starting the sync, changes afterwards lead to undefined results.

See also batchSize().

void ItemSync::setDisableAutomaticDeliveryDone(bool disable)

Disables the automatic completion of the item sync, based on the number of delivered items.

This ensures that the item sync only finishes once deliveryDone() is called, while still making it possible to use the progress reporting of the ItemSync.

Note: You must call this method before starting the sync, changes afterwards lead to undefined results.

See also setTotalItems.

void ItemSync::setFullSyncItems(const Akonadi::Item::List &items)

Sets the full item list for the collection.

Usually the result of a full item listing.

Warning: If the client using this is a resource, all items must have a valid remote identifier.

items A list of items.

void ItemSync::setIncrementalSyncItems(const Akonadi::Item::List &changedItems, const Akonadi::Item::List &removedItems)

Sets the item lists for incrementally syncing the collection.

Usually the result of an incremental remote item listing.

Warning: If the client using this is a resource, all items must have a valid remote identifier.

changedItems A list of items added or changed by the client. removedItems A list of items deleted by the client.

void ItemSync::setMergeMode(Akonadi::ItemSync::MergeMode mergeMode)

Set what merge method should be used for next ItemSync run

By default ItemSync uses RIDMerge method.

See ItemCreateJob for details on Item merging.

Note: You must call this method before starting the sync, changes afterwards lead to undefined results.

See also mergeMode.

void ItemSync::setStreamingEnabled(bool enable)

Enable item streaming. Item streaming means that the items delivered by setXItems() calls are delivered in chunks and you manually indicate when all items have been delivered by calling deliveryDone(). enable \ true to enable item streaming

void ItemSync::setTotalItems(int amount)

Set the amount of items which you are going to return in total by using the setFullSyncItems()/setIncrementalSyncItems() methods.

Warning: By default the item sync will automatically end once sufficient items have been provided. To disable this use setDisableAutomaticDeliveryDone

amount The amount of items in total.

See also setDisableAutomaticDeliveryDone.

void ItemSync::setTransactionMode(Akonadi::ItemSync::TransactionMode mode)

Set the transaction mode to use for this sync.

Note: You must call this method before starting the sync, changes afterwards lead to undefined results. mode the transaction mode to use