Akonadi::Collection Class
class Akonadi::CollectionRepresents a collection of PIM items. More...
| Header: | #include <Akonadi/Collection> |
| CMake: | find_package(KPim6 REQUIRED COMPONENTS AkonadiCore)target_link_libraries(mytarget PRIVATE KPim6::AkonadiCore) |
Public Types
| enum | CreateOption { AddIfMissing, DontCreate } |
| enum | ListPreference { ListEnabled, ListDisabled, ListDefault } |
| enum | ListPurpose { ListSync, ListDisplay, ListIndex } |
| enum | Right { ReadOnly, CanChangeItem, CanCreateItem, CanDeleteItem, CanChangeCollection, …, AllRights } |
| flags | Rights |
| enum | UrlType { UrlShort, UrlWithName } |
Public Functions
| Collection() | |
| Collection(Akonadi::Collection::Id id) | |
| Collection(const Akonadi::Collection &other) | |
| Collection(Akonadi::Collection &&other) | |
| ~Collection() | |
| void | addAttribute(Akonadi::Attribute *attribute) |
| const T * | attribute() const |
| T * | attribute(Akonadi::Collection::CreateOption option = DontCreate) |
| Akonadi::Attribute * | attribute(const QByteArray &name) |
| Akonadi::Attribute::List | attributes() const |
| Akonadi::CachePolicy | cachePolicy() const |
| void | clearAttributes() |
| QStringList | contentMimeTypes() const |
| QString | displayName() const |
| bool | enabled() const |
| bool | hasAttribute() const |
| bool | hasAttribute(const QByteArray &name) const |
| Akonadi::Collection::Id | id() const |
| bool | isValid() const |
| bool | isVirtual() const |
| QSet<QByteArray> | keepLocalChanges() const |
| Akonadi::Collection::ListPreference | localListPreference(Akonadi::Collection::ListPurpose purpose) const |
| QString | name() const |
| Akonadi::Collection & | parentCollection() |
| Akonadi::Collection | parentCollection() const |
| QString | remoteId() const |
| QString | remoteRevision() const |
| void | removeAttribute() |
| void | removeAttribute(const QByteArray &name) |
| QString | resource() const |
| Akonadi::Collection::Rights | rights() const |
| void | setCachePolicy(const Akonadi::CachePolicy &policy) |
| void | setContentMimeTypes(const QStringList &types) |
| void | setEnabled(bool enabled) |
| void | setId(Akonadi::Collection::Id identifier) |
| void | setKeepLocalChanges(const QSet<QByteArray> &parts) |
| void | setLocalListPreference(Akonadi::Collection::ListPurpose purpose, Akonadi::Collection::ListPreference preference) |
| void | setName(const QString &name) |
| void | setParentCollection(const Akonadi::Collection &parent) |
| void | setRemoteId(const QString &id) |
| void | setRemoteRevision(const QString &revision) |
| void | setResource(const QString &identifier) |
| void | setRights(Akonadi::Collection::Rights rights) |
| void | setShouldList(Akonadi::Collection::ListPurpose purpose, bool shouldList) |
| void | setStatistics(const Akonadi::CollectionStatistics &statistics) |
| void | setVirtual(bool isVirtual) |
| bool | shouldList(Akonadi::Collection::ListPurpose purpose) const |
| Akonadi::CollectionStatistics | statistics() const |
| QUrl | url(Akonadi::Collection::UrlType type = UrlShort) const |
| bool | operator!=(const Akonadi::Collection &other) const |
| Akonadi::Collection & | operator=(const Akonadi::Collection &other) |
| bool | operator==(const Akonadi::Collection &other) const |
Static Public Members
| Akonadi::Collection | fromUrl(const QUrl &url) |
| QString | mimeType() |
| Akonadi::Collection | root() |
| QString | virtualMimeType() |
Detailed Description
This class represents a collection of PIM items, such as a folder on a mail- or groupware-server.
Collections are hierarchical, i.e., they may have a parent collection.
using namespace Akonadi; // fetching all collections recursive, starting at the root collection CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive ); connect(job, &KJob::result, this, &MyClass::fetchFinished); ... MyClass::fetchFinished( KJob *job ) { if ( job->error() ) { qDebug() << "Error occurred"; return; } CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob*>( job ); const Collection::List collections = fetchJob->collections(); for ( const Collection &collection : collections ) { qDebug() << "Name:" << collection.name(); } }
Author: Volker Krause <vkrause@kde.org>
Member Type Documentation
enum Collection::CreateOption
Describes the options that can be passed to access attributes.
enum Collection::ListPreference
Describes the list preference value
enum Collection::ListPurpose
Describes the purpose of the listing
enum Collection::Right
flags Collection::Rights
Describes rights of a collection.
The Rights type is a typedef for QFlags<Right>. It stores an OR combination of Right values.
enum Collection::UrlType
Describes the type of url which is returned in url().
Member Function Documentation
Collection::Collection()
Creates an invalid collection.
[explicit] Collection::Collection(Akonadi::Collection::Id id)
Create a new collection.
id The unique identifier of the collection.
Collection::Collection(const Akonadi::Collection &other)
Creates a collection from an other collection.
[noexcept] Collection::Collection(Akonadi::Collection &&other)
Move constructor.
[noexcept] Collection::~Collection()
Destroys the collection.
void Collection::addAttribute(Akonadi::Attribute *attribute)
Adds an attribute to the collection.
If an attribute of the same type name already exists, it is deleted and replaced with the new one.
attribute The new attribute.
Note: The collection takes the ownership of the attribute.
template <typename T> const T *Collection::attribute() const
Returns the attribute of the requested type or 0 if it is not available.
template <typename T> T *Collection::attribute(Akonadi::Collection::CreateOption option = DontCreate)
Returns the attribute of the requested type. If the collection has no attribute of that type yet, passing AddIfMissing as an argument will create and add it to the entity
option The create options.
Akonadi::Attribute *Collection::attribute(const QByteArray &name)
Returns the attribute of the given type name if available, 0 otherwise.
Akonadi::Attribute::List Collection::attributes() const
Returns a list of all attributes of the collection.
Warning: Do not modify the attributes returned from this method, the change will not be reflected when updating the Collection through CollectionModifyJob.
Akonadi::CachePolicy Collection::cachePolicy() const
Returns the cache policy of the collection.
Note: Getter function for property cachePolicy.
See also setCachePolicy().
void Collection::clearAttributes()
Removes and deletes all attributes of the collection.
QStringList Collection::contentMimeTypes() const
Returns a list of possible content mimetypes, e.g. message/rfc822, x-akonadi/collection for a mail folder that supports sub-folders.
Note: Getter function for property contentMimeTypes.
See also setContentMimeTypes().
QString Collection::displayName() const
Returns the display name (EntityDisplayAttribute::displayName()) if set, and Collection::name() otherwise. For human-readable strings this is preferred over Collection::name().
Note: Getter function for property displayName.
bool Collection::enabled() const
Returns the collection's enabled state.
Note: Getter function for property enabled.
See also setEnabled() and localListPreference.
[static] Akonadi::Collection Collection::fromUrl(const QUrl &url)
Creates a collection from the given url.
template <typename T> bool Collection::hasAttribute() const
Returns whether the collection has an attribute of the requested type.
bool Collection::hasAttribute(const QByteArray &name) const
Returns \ true if the collection has an attribute of the given type name, false otherwise.
Akonadi::Collection::Id Collection::id() const
Returns the unique identifier of the collection.
Note: Getter function for property id.
See also setId().
bool Collection::isValid() const
Returns whether the collection is valid.
Note: Getter function for property isValid.
bool Collection::isVirtual() const
Returns whether the collection is virtual, for example a search collection.
Note: Getter function for property isVirtual.
QSet<QByteArray> Collection::keepLocalChanges() const
Returns what parts are only default values.
See also setKeepLocalChanges().
Akonadi::Collection::ListPreference Collection::localListPreference(Akonadi::Collection::ListPurpose purpose) const
Returns the local list preference for the specified purpose.
See also setLocalListPreference.
[static] QString Collection::mimeType()
Returns the mimetype used for collections.
QString Collection::name() const
Returns the i18n'ed name of the collection.
Note: Getter function for property name.
See also setName().
Akonadi::Collection &Collection::parentCollection()
Returns a reference to the parent collection of this object.
Note: This will of course only return a useful value if it was explicitly retrieved from the Akonadi server.
See also setParentCollection().
Akonadi::Collection Collection::parentCollection() const
Returns the parent collection of this object.
Note: This will of course only return a useful value if it was explicitly retrieved from the Akonadi server.
QString Collection::remoteId() const
Returns the remote id of the collection.
Note: Getter function for property remoteIdd.
See also setRemoteId().
QString Collection::remoteRevision() const
Returns the remote revision of the collection.
Note: This method is supposed to be used by resources only.
Note: Getter function for property remoteRevision.
See also setRemoteRevision().
template <typename T> void Collection::removeAttribute()
Removes and deletes the attribute of the requested type.
void Collection::removeAttribute(const QByteArray &name)
Removes and deletes the attribute of the given type name.
QString Collection::resource() const
Returns the identifier of the resource owning the collection.
Note: Getter function for property resource.
See also setResource().
Akonadi::Collection::Rights Collection::rights() const
Returns the rights the user has on the collection.
Note: Getter function for property rights.
See also setRights().
[static] Akonadi::Collection Collection::root()
Returns the root collection.
void Collection::setCachePolicy(const Akonadi::CachePolicy &policy)
Sets the cache policy of the collection.
See also cachePolicy().
void Collection::setContentMimeTypes(const QStringList &types)
Sets the list of possible content mime types.
Note: Setter function for property contentMimeTypes.
See also contentMimeTypes().
void Collection::setEnabled(bool enabled)
Sets the collection's enabled state.
Use this mechanism to set if a collection should be available to the user or not.
This can be used in conjunction with the local list preference for finer grained control to define if a collection should be included depending on the purpose.
For example: A collection is by default enabled, meaning it is displayed to the user, synchronized by the resource, and indexed by the indexer. A disabled collection on the other hand is not displayed, synchronized or indexed. The local list preference allows to locally override that default value for each purpose individually.
The enabled state can be synchronized by backends. E.g. an imap resource may synchronize this with the subscription state.
Note: Setter function for property enabled.
See also enabled(), setLocalListPreference, and setShouldList.
void Collection::setId(Akonadi::Collection::Id identifier)
Sets the unique identifier of the collection.
Note: Setter function for property id.
See also id().
void Collection::setKeepLocalChanges(const QSet<QByteArray> &parts)
Set during sync to indicate that the provided parts are only default values;
See also keepLocalChanges().
void Collection::setLocalListPreference(Akonadi::Collection::ListPurpose purpose, Akonadi::Collection::ListPreference preference)
Sets the local list preference for the specified purpose.
The local list preference overrides the enabled state unless set to ListDefault. In case of ListDefault the enabled state should be taken as fallback (shouldList() implements this logic).
The default value is ListDefault.
See also localListPreference(), shouldList, and setEnabled.
void Collection::setName(const QString &name)
Sets the i18n'ed name of the collection.
name The new collection name.
Note: Setter function for property name.
See also name().
void Collection::setParentCollection(const Akonadi::Collection &parent)
Set the parent collection of this object.
Note: Calling this method has no immediate effect for the object itself, such as being moved to another collection. It is mainly relevant to provide a context for RID-based operations inside resources. parent The parent collection.
See also parentCollection().
void Collection::setRemoteId(const QString &id)
Sets the remote id of the collection.
Note: Setter function for property remoteIdd.
See also remoteId().
void Collection::setRemoteRevision(const QString &revision)
Sets the remote revision of the collection. revision the collections's remote revision The remote revision can be used by resources to store some revision information of the backend to detect changes there.
Note: This method is supposed to be used by resources only.
Note: Setter function for property remoteRevision.
See also remoteRevision().
void Collection::setResource(const QString &identifier)
Sets the identifier of the resource owning the collection.
Note: Setter function for property resource.
See also resource().
void Collection::setRights(Akonadi::Collection::Rights rights)
Sets the rights the user has on the collection.
Note: Setter function for property rights.
See also rights().
void Collection::setShouldList(Akonadi::Collection::ListPurpose purpose, bool shouldList)
Sets whether the collection should be listed or not for the specified purpose. Takes enabled state and local preference into account.
Use this instead of sestEnabled and setLocalListPreference to automatically set the right setting.
See also shouldList(), setLocalListPreference, and setEnabled.
void Collection::setStatistics(const Akonadi::CollectionStatistics &statistics)
Sets the collection statistics for the collection.
See also statistics().
void Collection::setVirtual(bool isVirtual)
Sets whether the collection is virtual or not. Virtual collections can't be converted to non-virtual and vice versa. isVirtual virtual collection if \ true, otherwise a normal collection
Note: Setter function for property isVirtual.
See also isVirtual().
bool Collection::shouldList(Akonadi::Collection::ListPurpose purpose) const
Returns whether the collection should be listed or not for the specified purpose Takes enabled state and local preference into account.
See also setShouldList(), setLocalListPreference, and setEnabled.
Akonadi::CollectionStatistics Collection::statistics() const
Returns the collection statistics of the collection.
Note: Getter function for property statistics.
See also setStatistics().
QUrl Collection::url(Akonadi::Collection::UrlType type = UrlShort) const
Returns the url of the collection. type the type of url
[static] QString Collection::virtualMimeType()
Returns the mimetype used for virtual collections
bool Collection::operator!=(const Akonadi::Collection &other) const
Returns whether the collection's id does not equal the id of the other collection.
Akonadi::Collection &Collection::operator=(const Akonadi::Collection &other)
Assigns the other to this collection and returns a reference to this collection. other the collection to assign
bool Collection::operator==(const Akonadi::Collection &other) const
Returns whether this collections's id equals the id of the other collection.