Akonadi::Monitor Class

class Akonadi::Monitor

Monitors an item or collection for changes. More...

Header: #include <Akonadi/Monitor>
CMake: find_package(KPim6 REQUIRED COMPONENTS AkonadiCore)
target_link_libraries(mytarget PRIVATE KPim6::AkonadiCore)
Inherits: QObject
Inherited By:

Akonadi::ChangeRecorder

Public Functions

Monitor(QObject *parent = nullptr)
virtual ~Monitor() override
Akonadi::CollectionFetchScope &collectionFetchScope()
Akonadi::Collection::List collectionsMonitored() const
void fetchChangedOnly(bool enable)
void fetchCollection(bool enable)
void fetchCollectionStatistics(bool enable)
void ignoreSession(Akonadi::Session *session)
bool isAllMonitored() const
Akonadi::ItemFetchScope &itemFetchScope()
QList<Akonadi::Item::Id> itemsMonitoredEx() const
QStringList mimeTypesMonitored() const
int numItemsMonitored() const
int numMimeTypesMonitored() const
int numResourcesMonitored() const
QList<QByteArray> resourcesMonitored() const
Akonadi::Session *session() const
void setAllMonitored(bool monitored = true)
void setCollectionFetchScope(const Akonadi::CollectionFetchScope &fetchScope)
void setCollectionMonitored(const Akonadi::Collection &collection, bool monitored = true)
void setCollectionMoveTranslationEnabled(bool enabled)
void setItemFetchScope(const Akonadi::ItemFetchScope &fetchScope)
void setItemMonitored(const Akonadi::Item &item, bool monitored = true)
void setMimeTypeMonitored(const QString &mimetype, bool monitored = true)
void setResourceMonitored(const QByteArray &resource, bool monitored = true)
void setSession(Akonadi::Session *session)
void setTagFetchScope(const Akonadi::TagFetchScope &fetchScope)
void setTagMonitored(const Akonadi::Tag &tag, bool monitored = true)
void setTypeMonitored(Akonadi::Monitor::Type type, bool monitored = true)
Akonadi::TagFetchScope &tagFetchScope()
QList<Akonadi::Tag::Id> tagsMonitored() const
QList<Akonadi::Monitor::Type> typesMonitored() const

Signals

void allMonitored(bool monitored)
void collectionAdded(const Akonadi::Collection &collection, const Akonadi::Collection &parent)
void collectionChanged(const Akonadi::Collection &collection)
void collectionChanged(const Akonadi::Collection &collection, const QSet<QByteArray> &attributeNames)
void collectionMonitored(const Akonadi::Collection &collection, bool monitored)
void collectionMoved(const Akonadi::Collection &collection, const Akonadi::Collection &source, const Akonadi::Collection &destination)
void collectionRemoved(const Akonadi::Collection &collection)
void collectionStatisticsChanged(Akonadi::Collection::Id id, const Akonadi::CollectionStatistics &statistics)
void collectionSubscribed(const Akonadi::Collection &collection, const Akonadi::Collection &parent)
void collectionUnsubscribed(const Akonadi::Collection &collection)
void debugNotification(const Akonadi::ChangeNotification &notification)
void itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection)
void itemChanged(const Akonadi::Item &item, const QSet<QByteArray> &partIdentifiers)
void itemLinked(const Akonadi::Item &item, const Akonadi::Collection &collection)
void itemMonitored(const Akonadi::Item &item, bool monitored)
void itemMoved(const Akonadi::Item &item, const Akonadi::Collection &collectionSource, const Akonadi::Collection &collectionDestination)
void itemRemoved(const Akonadi::Item &item)
void itemUnlinked(const Akonadi::Item &item, const Akonadi::Collection &collection)
void itemsFlagsChanged(const Akonadi::Item::List &items, const QSet<QByteArray> &addedFlags, const QSet<QByteArray> &removedFlags)
void itemsLinked(const Akonadi::Item::List &items, const Akonadi::Collection &collection)
void itemsMoved(const Akonadi::Item::List &items, const Akonadi::Collection &collectionSource, const Akonadi::Collection &collectionDestination)
void itemsRemoved(const Akonadi::Item::List &items)
void itemsTagsChanged(const Akonadi::Item::List &items, const QSet<Akonadi::Tag> &addedTags, const QSet<Akonadi::Tag> &removedTags)
void itemsUnlinked(const Akonadi::Item::List &items, const Akonadi::Collection &collection)
void mimeTypeMonitored(const QString &mimeType, bool monitored)
void notificationSubscriberAdded(const Akonadi::NotificationSubscriber &subscriber)
void notificationSubscriberChanged(const Akonadi::NotificationSubscriber &subscriber)
void notificationSubscriberRemoved(const Akonadi::NotificationSubscriber &subscriber)
void resourceMonitored(const QByteArray &identifier, bool monitored)
void tagAdded(const Akonadi::Tag &tag)
void tagChanged(const Akonadi::Tag &tag)
void tagMonitored(const Akonadi::Tag &tag, bool monitored)
void tagRemoved(const Akonadi::Tag &tag)
void typeMonitored(const Akonadi::Monitor::Type type, bool monitored)

Detailed Description

The Monitor emits signals if some of these objects are changed or removed or new ones are added to the Akonadi storage.

There are various ways to filter these notifications. There are three types of filter evaluation: - (-) removal-only filter, ie. if the filter matches the notification is dropped, if not filter evaluation continues with the next one - (+) pass-exit filter, ie. if the filter matches the notification is delivered, if not evaluation is continued - (f) final filter, ie. evaluation ends here if the corresponding filter criteria is set, the notification is delivered depending on the result, evaluation is only continued if no filter criteria is defined

The following filter are available, listed in evaluation order: (1) ignored sessions (-) (2) monitor everything (+) (3a) resource and mimetype filters (f) (items only) (3b) resource filters (f) (collections only) (4) item is monitored (+) (5) collection is monitored (+)

Optionally, the changed objects can be fetched automatically from the server. To enable this, see itemFetchScope() and collectionFetchScope().

Note that as a consequence of rule 3a, it is not possible to monitor (more than zero resources OR more than zero mimetypes) AND more than zero collections.

\todoDistinguish between monitoring collection properties and collection content. \todo Special case for collection content counts changed

Author: Volker Krause <vkrause@kde.org>

Member Function Documentation

[explicit] Monitor::Monitor(QObject *parent = nullptr)

Creates a new monitor.

parent The parent object.

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

Destroys the monitor.

[signal] void Monitor::allMonitored(bool monitored)

This signal is emitted if the Monitor starts or stops monitoring everything. monitored Whether everything is now being monitored or not.

See also setAllMonitored().

[signal] void Monitor::collectionAdded(const Akonadi::Collection &collection, const Akonadi::Collection &parent)

This signal is emitted if a new collection has been added to a monitored collection in the Akonadi storage.

collection The new collection. parent The parent collection.

[signal] void Monitor::collectionChanged(const Akonadi::Collection &collection)

This signal is emitted if a monitored collection has been changed (properties or content).

collection The changed collection.

Note: This signal is overloaded. To connect to this signal:

 // Connect using qOverload:
 connect(monitor, qOverload(&Monitor::collectionChanged),
         receiver, &ReceiverClass::slot);

 // Or using a lambda:
 connect(monitor, qOverload(&Monitor::collectionChanged),
         this, [](const Akonadi::Collection &collection) { /* handle collectionChanged */ });
For more examples and approaches, see connecting to overloaded signals.

[signal] void Monitor::collectionChanged(const Akonadi::Collection &collection, const QSet<QByteArray> &attributeNames)

This signal is emitted if a monitored collection has been changed (properties or attributes).

collection The changed collection. attributeNames The names of the collection attributes that have been changed.

Note: This signal is overloaded. To connect to this signal:

 // Connect using qOverload:
 connect(monitor, qOverload &>(&Monitor::collectionChanged),
         receiver, &ReceiverClass::slot);

 // Or using a lambda:
 connect(monitor, qOverload &>(&Monitor::collectionChanged),
         this, [](const Akonadi::Collection &collection, const QSet &attributeNames) { /* handle collectionChanged */ });
For more examples and approaches, see connecting to overloaded signals.

Akonadi::CollectionFetchScope &Monitor::collectionFetchScope()

Returns the collection 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 CollectionFetchScope documentation for an example.

Returns a reference to the current collection fetch scope

See also setCollectionFetchScope(), for, replacing, the, current, collection, fetch, and scope.

[signal] void Monitor::collectionMonitored(const Akonadi::Collection &collection, bool monitored)

This signal is emitted if the Monitor starts or stops monitoring collection explicitly. collection The collection monitored Whether the collection is now being monitored or not.

See also setCollectionMonitored().

[signal] void Monitor::collectionMoved(const Akonadi::Collection &collection, const Akonadi::Collection &source, const Akonadi::Collection &destination)

This signals is emitted if a monitored collection has been moved.

collection The moved collection. source The previous parent collection. destination The new parent collection.

[signal] void Monitor::collectionRemoved(const Akonadi::Collection &collection)

This signal is emitted if a monitored collection has been removed from the Akonadi storage.

collection The removed collection.

[signal] void Monitor::collectionStatisticsChanged(Akonadi::Collection::Id id, const Akonadi::CollectionStatistics &statistics)

This signal is emitted if the statistics information of a monitored collection has changed.

id The collection identifier of the changed collection. statistics The updated collection statistics, invalid if automatic fetching of statistics changes is disabled.

[signal] void Monitor::collectionSubscribed(const Akonadi::Collection &collection, const Akonadi::Collection &parent)

This signal is emitted if a collection has been subscribed to by the user. It will be emitted even for unmonitored collections as the check for whether to monitor it has not been applied yet.

collection The subscribed collection parent The parent collection of the subscribed collection.

[signal] void Monitor::collectionUnsubscribed(const Akonadi::Collection &collection)

This signal is emitted if a user unsubscribes from a collection.

collection The unsubscribed collection

Akonadi::Collection::List Monitor::collectionsMonitored() const

Returns the list of collections being monitored.

[signal] void Monitor::debugNotification(const Akonadi::ChangeNotification &notification)

This signal is emitted when Notifications are monitored and the server emits any change notification.

Note: Getting introspection into all change notifications only makes sense if you want to globally debug Notifications. There is no reason to use this in regular applications.

void Monitor::fetchChangedOnly(bool enable)

Instructs the monitor to fetch only those parts that were changed and were requested in the fetch scope.

This is taken in account only for item modifications. Example usage:

 monitor->itemFetchScope().fetchFullPayload( true );
 monitor->fetchChangedOnly(true);

In the example if an item was changed, but its payload was not, the full payload will not be retrieved. If the item's payload was changed, the monitor retrieves the changed payload as well.

The default is to fetch everything requested.

enable \ true to enable the feature, \ false means everything that was requested will be fetched.

void Monitor::fetchCollection(bool enable)

Enables automatic fetching of changed collections from the Akonadi storage.

enable \ true enables automatic fetching, \ false disables automatic fetching.

void Monitor::fetchCollectionStatistics(bool enable)

Enables automatic fetching of changed collection statistics information from the Akonadi storage.

enable \ true to enables automatic fetching, \ false disables automatic fetching.

void Monitor::ignoreSession(Akonadi::Session *session)

Ignores all change notifications caused by the given session. This overrides all other settings on this session.

session The session you want to ignore.

bool Monitor::isAllMonitored() const

Returns true if everything is being monitored.

[signal] void Monitor::itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection)

This signal is emitted if an item has been added to a monitored collection in the Akonadi storage.

item The new item. collection The collection the item has been added to.

[signal] void Monitor::itemChanged(const Akonadi::Item &item, const QSet<QByteArray> &partIdentifiers)

This signal is emitted if a monitored item has changed, e.g. item parts have been modified.

item The changed item. partIdentifiers The identifiers of the item parts that has been changed.

Akonadi::ItemFetchScope &Monitor::itemFetchScope()

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 setItemFetchScope(), for, replacing, the, current, item, fetch, and scope.

[signal] void Monitor::itemLinked(const Akonadi::Item &item, const Akonadi::Collection &collection)

This signal is emitted if a reference to an item is added to a virtual collection. item The linked item. collection The collection the item is linked to.

[signal] void Monitor::itemMonitored(const Akonadi::Item &item, bool monitored)

This signal is emitted if the Monitor starts or stops monitoring item explicitly. item The item monitored Whether the item is now being monitored or not.

See also setItemMonitored().

[signal] void Monitor::itemMoved(const Akonadi::Item &item, const Akonadi::Collection &collectionSource, const Akonadi::Collection &collectionDestination)

This signal is emitted if a monitored item has been moved between two collections

item The moved item. collectionSource The collection the item has been moved from. collectionDestination The collection the item has been moved to.

[signal] void Monitor::itemRemoved(const Akonadi::Item &item)

This signal is emitted if - a monitored item has been removed from the Akonadi storage or - a item has been removed from a monitored collection.

item The removed item.

[signal] void Monitor::itemUnlinked(const Akonadi::Item &item, const Akonadi::Collection &collection)

This signal is emitted if a reference to an item is removed from a virtual collection. item The unlinked item. collection The collection the item is unlinked from.

[signal] void Monitor::itemsFlagsChanged(const Akonadi::Item::List &items, const QSet<QByteArray> &addedFlags, const QSet<QByteArray> &removedFlags)

This signal is emitted if flags of monitored items have changed.

items Items that were changed addedFlags Flags that have been added to each item in items removedFlags Flags that have been removed from each item in items

[signal] void Monitor::itemsLinked(const Akonadi::Item::List &items, const Akonadi::Collection &collection)

This signal is emitted if a reference to multiple items is added to a virtual collection

items The linked items collection The collections the items are linked to

QList<Akonadi::Item::Id> Monitor::itemsMonitoredEx() const

Returns the set of items being monitored.

Faster version (at least on 32-bit systems) of itemsMonitored().

[signal] void Monitor::itemsMoved(const Akonadi::Item::List &items, const Akonadi::Collection &collectionSource, const Akonadi::Collection &collectionDestination)

This is signal is emitted when multiple monitored items have been moved between two collections

items Moved items collectionSource The collection the items have been moved from. collectionDestination The collection the items have been moved to.

[signal] void Monitor::itemsRemoved(const Akonadi::Item::List &items)

This signal is emitted if monitored items have been removed from Akonadi storage of items have been removed from a monitored collection.

items Removed items

[signal] void Monitor::itemsTagsChanged(const Akonadi::Item::List &items, const QSet<Akonadi::Tag> &addedTags, const QSet<Akonadi::Tag> &removedTags)

This signal is emitted if tags of monitored items have changed.

items Items that were changed addedTags Tags that have been added to each item in items. removedTags Tags that have been removed from each item in items

[signal] void Monitor::itemsUnlinked(const Akonadi::Item::List &items, const Akonadi::Collection &collection)

This signal is emitted if a reference to items is removed from a virtual collection

items The unlinked items collection The collections the items are unlinked from

[signal] void Monitor::mimeTypeMonitored(const QString &mimeType, bool monitored)

This signal is emitted if the Monitor starts or stops monitoring mimeType explicitly. mimeType The mimeType. monitored Whether the mimeType is now being monitored or not.

See also setMimeTypeMonitored().

QStringList Monitor::mimeTypesMonitored() const

Returns the set of mimetypes being monitored.

[signal] void Monitor::notificationSubscriberAdded(const Akonadi::NotificationSubscriber &subscriber)

This signal is emitted when Subscribers are monitored and a new subscriber subscribers to the server.

subscriber The new subscriber

Note: Monitoring for subscribers and listening to this signal only makes sense if you want to globally debug Monitors. There is no reason to use this in regular applications.

[signal] void Monitor::notificationSubscriberChanged(const Akonadi::NotificationSubscriber &subscriber)

This signal is emitted when Subscribers are monitored and an existing subscriber changes its subscription.

subscriber The changed subscriber

Note: Monitoring for subscribers and listening to this signal only makes sense if you want to globally debug Monitors. There is no reason to use this in regular applications.

[signal] void Monitor::notificationSubscriberRemoved(const Akonadi::NotificationSubscriber &subscriber)

This signal is emitted when Subscribers are monitored and an existing subscriber unsubscribes from the server.

subscriber The removed subscriber

Note: Monitoring for subscribers and listening to this signal only makes sense if you want to globally debug Monitors. There is no reason to use this in regular applications.

int Monitor::numItemsMonitored() const

Returns the number of items being monitored. Optimization.

int Monitor::numMimeTypesMonitored() const

Returns the number of mimetypes being monitored. Optimization.

int Monitor::numResourcesMonitored() const

Returns the number of resources being monitored. Optimization.

[signal] void Monitor::resourceMonitored(const QByteArray &identifier, bool monitored)

This signal is emitted if the Monitor starts or stops monitoring the resource with the identifier identifier explicitly. identifier The identifier of the resource. monitored Whether the resource is now being monitored or not.

See also setResourceMonitored().

QList<QByteArray> Monitor::resourcesMonitored() const

Returns the set of identifiers for resources being monitored.

Akonadi::Session *Monitor::session() const

Returns the Session used by the monitor to communicate with Akonadi.

See also setSession().

void Monitor::setAllMonitored(bool monitored = true)

Sets whether all items shall be monitored. monitored sets all items as monitored if set as \ true Note that if a session is being ignored, this takes precedence over setAllMonitored() on that session.

See also allMonitored().

void Monitor::setCollectionFetchScope(const Akonadi::CollectionFetchScope &fetchScope)

Sets the collection fetch scope.

Controls which collections are monitored and how much of a collection's data is fetched from the server.

fetchScope The new scope for collection fetch operations.

See also collectionFetchScope().

void Monitor::setCollectionMonitored(const Akonadi::Collection &collection, bool monitored = true)

Sets whether the specified collection shall be monitored for changes. If monitoring is turned on for the collection, all notifications for items in that collection will be emitted, and its child collections will also be monitored. Note that move notifications will be emitted if either one of the collections involved is being monitored.

Note that if a session is being ignored, this takes precedence over setCollectionMonitored() on that session.

collection The collection to monitor. If this collection is Collection::root(), all collections in the Akonadi storage will be monitored. monitored Whether to monitor the collection.

See also collectionMonitored().

void Monitor::setCollectionMoveTranslationEnabled(bool enabled)

Allows to enable/disable collection move translation. If enabled (the default), move notifications are automatically translated into add/remove notifications if the source/destination is outside of the monitored collection hierarchy. enabled enables collection move translation if set as \ true

void Monitor::setItemFetchScope(const Akonadi::ItemFetchScope &fetchScope)

Sets the item fetch scope.

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 itemFetchScope().

void Monitor::setItemMonitored(const Akonadi::Item &item, bool monitored = true)

Sets whether the specified item shall be monitored for changes.

Note that if a session is being ignored, this takes precedence over setItemMonitored() on that session.

item The item to monitor. monitored Whether to monitor the item.

See also itemMonitored().

void Monitor::setMimeTypeMonitored(const QString &mimetype, bool monitored = true)

Sets whether items of the specified mime type shall be monitored for changes. If monitoring is turned on for the mime type, all notifications for items matching that mime type will be emitted, but notifications for collections matching that mime type will only be emitted if this is otherwise specified, for example by setCollectionMonitored().

Note that if a session is being ignored, this takes precedence over setMimeTypeMonitored() on that session.

mimetype The mime type to monitor. monitored Whether to monitor the mime type.

See also mimeTypeMonitored().

void Monitor::setResourceMonitored(const QByteArray &resource, bool monitored = true)

Sets whether the specified resource shall be monitored for changes. If monitoring is turned on for the resource, all notifications for collections and items in that resource will be emitted.

Note that if a session is being ignored, this takes precedence over setResourceMonitored() on that session.

resource The resource identifier. monitored Whether to monitor the resource.

See also resourceMonitored().

void Monitor::setSession(Akonadi::Session *session)

Sets the session used by the Monitor to communicate with the %Akonadi server. If not set, the Akonadi::Session::defaultSession is used. session the session to be set

See also session().

void Monitor::setTagFetchScope(const Akonadi::TagFetchScope &fetchScope)

Sets the tag fetch scope.

Controls how much of an tag's data is fetched from the server.

fetchScope The new scope for tag fetch operations.

See also tagFetchScope().

void Monitor::setTagMonitored(const Akonadi::Tag &tag, bool monitored = true)

Sets whether the specified tag shall be monitored for changes.

Same rules as for item monitoring apply.

tag Tag to monitor. monitored Whether to monitor the tag.

See also tagMonitored().

void Monitor::setTypeMonitored(Akonadi::Monitor::Type type, bool monitored = true)

Sets whether given type (Collection, Item, Tag should be monitored).

By default all types are monitored, but once you change one, you have to explicitly enable all other types you want to monitor.

type Type to monitor. monitored Whether to monitor the type

See also typeMonitored().

[signal] void Monitor::tagAdded(const Akonadi::Tag &tag)

This signal is emitted if a tag has been added to Akonadi storage.

tag The added tag

[signal] void Monitor::tagChanged(const Akonadi::Tag &tag)

This signal is emitted if a monitored tag is changed on the server.

tag The changed tag.

Akonadi::TagFetchScope &Monitor::tagFetchScope()

Returns the tag 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.

Returns a reference to the current tag fetch scope

See also setTagFetchScope(), for, replacing, the, current, tag, fetch, and scope.

[signal] void Monitor::tagMonitored(const Akonadi::Tag &tag, bool monitored)

This signal is emitted if the Monitor starts or stops monitoring tag explicitly. tag The tag. monitored Whether the tag is now being monitored or not.

See also setTagMonitored().

[signal] void Monitor::tagRemoved(const Akonadi::Tag &tag)

This signal is emitted if a monitored tag is removed from the server storage.

The monitor will also emit itemTagsChanged() signal for all monitored items (if any) that were tagged by tag.

tag The removed tag.

QList<Akonadi::Tag::Id> Monitor::tagsMonitored() const

Returns the set of tags being monitored.

[signal] void Monitor::typeMonitored(const Akonadi::Monitor::Type type, bool monitored)

This signal is emitted if the Monitor starts or stops monitoring type explicitly type The type. monitored Whether the type is now being monitored or not.

See also setTypeMonitored().

QList<Akonadi::Monitor::Type> Monitor::typesMonitored() const

Returns the set of types being monitored.