Akonadi::Item
#include <item.h>
Public Types | |
enum | CreateOption { AddIfMissing , DontCreate } |
using | Flag = QByteArray |
using | Flags = QSet<QByteArray> |
using | Id = qint64 |
using | List = QList<Item> |
enum | UrlType { UrlShort = 0 , UrlWithMimeType = 1 } |
Public Member Functions | |
Item () | |
Item (const Item &other) | |
Item (const QString &mimeType) | |
Item (Id id) | |
Item (Item &&) noexcept | |
~Item () | |
void | addAttribute (Attribute *attribute) |
void | apply (const Item &other) |
template<typename T > | |
const T * | attribute () const |
Attribute * | attribute (const QByteArray &name) |
const Attribute * | attribute (const QByteArray &name) const |
template<typename T > | |
T * | attribute (CreateOption option=DontCreate) |
Attribute::List | attributes () const |
QList< int > | availablePayloadMetaTypeIds () const |
QSet< QByteArray > | availablePayloadParts () const |
QSet< QByteArray > | cachedPayloadParts () const |
void | clearAttributes () |
void | clearFlag (const QByteArray &name) |
void | clearFlags () |
void | clearPayload () |
void | clearTag (const Tag &tag) |
void | clearTags () |
Flags | flags () const |
QString | gid () const |
template<typename T > | |
bool | hasAttribute () const |
bool | hasAttribute (const QByteArray &name) const |
bool | hasFlag (const QByteArray &name) const |
bool | hasPayload () const |
template<typename T > | |
bool | hasPayload () const |
bool | hasTag (const Tag &tag) const |
Id | id () const |
bool | isValid () const |
QSet< QByteArray > | loadedPayloadParts () const |
QString | mimeType () const |
QDateTime | modificationTime () const |
bool | operator!= (const Item &other) const |
bool | operator< (const Item &other) const |
Item & | operator= (const Item &other) |
bool | operator== (const Item &other) const |
Collection & | parentCollection () |
Collection | parentCollection () const |
template<typename T > | |
T | payload () const |
QByteArray | payloadData () const |
QString | payloadPath () const |
QString | remoteId () const |
QString | remoteRevision () const |
template<typename T > | |
void | removeAttribute () |
void | removeAttribute (const QByteArray &name) |
int | revision () const |
void | setCachedPayloadParts (const QSet< QByteArray > &cachedParts) |
void | setFlag (const QByteArray &name) |
void | setFlags (const Flags &flags) |
void | setGid (const QString &gid) |
void | setId (Id identifier) |
void | setMimeType (const QString &mimeType) |
void | setModificationTime (const QDateTime &datetime) |
void | setParentCollection (const Collection &parent) |
template<typename T > | |
void | setPayload (const T &p) |
template<typename T > | |
void | setPayload (T *p) |
void | setPayloadFromData (const QByteArray &data) |
void | setPayloadPath (const QString &filePath) |
void | setRemoteId (const QString &id) |
void | setRemoteRevision (const QString &revision) |
void | setRevision (int revision) |
void | setSize (qint64 size) |
void | setTag (const Tag &tag) |
void | setTags (const Tag::List &list) |
void | setVirtualReferences (const Collection::List &collections) |
qint64 | size () const |
Collection::Id | storageCollectionId () const |
Tag::List | tags () const |
QUrl | url (UrlType type=UrlShort) const |
Collection::List | virtualReferences () const |
Static Public Member Functions | |
static Item | fromUrl (const QUrl &url) |
Static Public Attributes | |
static const char | FullPayload [] = "RFC822" |
Detailed Description
Represents a PIM item stored in Akonadi storage.
A PIM item consists of one or more parts, allowing a fine-grained access on its content where needed (eg. mail envelope, mail body and attachments).
There is also a namespace (prefix) for special parts which are local to Akonadi. These parts, prefixed by "akonadi-", will never be fetched in the resource. They are useful for local extensions like agents which might want to add meta data to items in order to handle them but the meta data should not be stored back to the resource.
This class is implicitly shared.
Payload
This class contains, beside some type-agnostic information (flags, revision), zero or more payload objects representing its actual data. Which objects these actually are depends on the mimetype of the item and the corresponding serializer plugin(s).
Technically the only restriction on payload objects is that they have to be copyable. For safety reasons, pointer payloads are forbidden as well though, as the ownership would not be clear. In this case, usage of a shared pointer is recommended (such as QSharedPointer or std::shared_ptr).
Using a shared pointer is also required in case the payload is a polymorphic type. For supported shared pointer types implicit casting is provided when possible.
When using a value-based class as payload, it is recommended to use one that does support implicit sharing as setting and retrieving a payload as well as copying an Akonadi::Item object imply copying of the payload object.
Since KDE 4.6, Item supports multiple payload types per mime type, and will automatically convert between them using the serialiser plugins (which is slow). It also supports mixing shared pointer types, e.g. inserting a std::shared_ptr<Foo> and extracting a QSharedPointer<Foo>. Since the two shared pointer types cannot share ownership of the same object, the payload class T
needs to provide a clone()
method with the usual signature, ie.
If the class that does not have a clone()
method, asking for an incompatible shared pointer will throw a PayloadException.
Since using different shared pointer types and different payload types for the same mimetype incurs slow conversions (between payload types) and cloning (between shared pointer types), as well as manifold memory usage (results of conversions are cached inside the Item, and only destroyed when a new payload is set by the user of the class), you want to restrict yourself to just one type and one shared pointer type. This mechanism was mainly introduced for backwards compatibility (e.g., putting in a std::shared_ptr<KCal::Incidence> and extracting a QSharedPointer<KCalCore::Incidence>), so it is not optimized for performance.
The availability of a payload of a specific type can be checked using hasPayload(), payloads can be retrieved by using payload() and set by using setPayload(). Refer to the documentation of those methods for more details.
Member Typedef Documentation
◆ Flag
using Akonadi::Item::Flag = QByteArray |
◆ Flags
using Akonadi::Item::Flags = QSet<QByteArray> |
◆ Id
using Akonadi::Item::Id = qint64 |
◆ List
using Akonadi::Item::List = QList<Item> |
Member Enumeration Documentation
◆ CreateOption
◆ UrlType
Constructor & Destructor Documentation
◆ Item() [1/5]
◆ Item() [2/5]
|
explicit |
◆ Item() [3/5]
|
explicit |
◆ Item() [4/5]
|
default |
Creates a new item from an other
item.
◆ Item() [5/5]
|
noexcept |
Move constructor.
◆ ~Item()
|
default |
Destroys the item.
Member Function Documentation
◆ addAttribute()
void Item::addAttribute | ( | Attribute * | attribute | ) |
◆ apply()
void Item::apply | ( | const Item & | other | ) |
Applies the parts of Item other
to this item.
Any parts or attributes available in other, will be applied to this item, and the payload parts of other will be inserted into this item, overwriting any existing parts with the same part name.
If there is an ItemSerialzerPluginV2 for the type, the merge method in that plugin is used to perform the merge. If only an ItemSerialzerPlugin class is found, or the merge method of the -V2 plugin is not implemented, the merge is performed with multiple deserializations of the payload.
- Parameters
-
other the item to get values from
- Since
- 4.4
◆ attribute() [1/3]
|
inline |
◆ attribute() [2/3]
Attribute * Akonadi::Item::attribute | ( | const QByteArray & | name | ) |
Returns the attribute of the given type name
if available, 0 otherwise.
◆ attribute() [3/3]
|
inline |
◆ attributes()
Attribute::List Item::attributes | ( | ) | const |
Returns a list of all attributes of the item.
- Warning
- Do not modify the attributes returned from this method, the change will not be reflected when updating the Item through ItemModifyJob.
◆ availablePayloadMetaTypeIds()
QList< int > Item::availablePayloadMetaTypeIds | ( | ) | const |
◆ availablePayloadParts()
QSet< QByteArray > Item::availablePayloadParts | ( | ) | const |
Returns the parts available for this item.
The returned set refers to parts available on the akonadi server or remotely, but does not include the loadedPayloadParts() of this item.
- Since
- 4.4
◆ cachedPayloadParts()
QSet< QByteArray > Item::cachedPayloadParts | ( | ) | const |
Returns the parts available for this item in the cache.
The list might be a subset of the actual parts in cache, as it contains only the requested parts. See
- See also
- ItemFetchJob and
- ItemFetchScope
The returned set refers to parts available on the akonadi server.
- Since
- 4.11
◆ clearAttributes()
void Item::clearAttributes | ( | ) |
◆ clearFlag()
void Item::clearFlag | ( | const QByteArray & | name | ) |
◆ clearFlags()
◆ clearPayload()
void Item::clearPayload | ( | ) |
Marks that the payload shall be cleared from the cache when this item is passed to an ItemModifyJob the next time.
This will trigger a refetch of the payload from the backend when the item is accessed afterwards. Only resources should have a need for this functionality.
- Since
- 4.5
◆ clearTag()
◆ clearTags()
◆ flags()
Item::Flags Item::flags | ( | ) | const |
◆ fromUrl()
◆ gid()
QString Item::gid | ( | ) | const |
◆ hasAttribute() [1/2]
|
inline |
◆ hasAttribute() [2/2]
bool Akonadi::Item::hasAttribute | ( | const QByteArray & | name | ) | const |
Returns true
if the item has an attribute of the given type name
, false otherwise.
◆ hasFlag()
bool Item::hasFlag | ( | const QByteArray & | name | ) | const |
◆ hasPayload() [1/2]
bool Akonadi::Item::hasPayload | ( | ) | const |
Returns whether the item has a payload object.
◆ hasPayload() [2/2]
bool Item::hasPayload | ( | ) | const |
Returns whether the item has a payload of type T
.
This method will only return true
if either you requested the exact same payload type that was put in or the payload uses a supported shared pointer type (currently QSharedPointer and std::shared_ptr), and is castable to the requested type. For this to work there needs to be a specialization of Akonadi::super_trait of the used classes.
Trying to retrieve a pointer type will fail to compile.
◆ hasTag()
◆ id()
Item::Id Item::id | ( | ) | const |
◆ isValid()
bool Item::isValid | ( | ) | const |
◆ loadedPayloadParts()
QSet< QByteArray > Item::loadedPayloadParts | ( | ) | const |
◆ mimeType()
QString Item::mimeType | ( | ) | const |
◆ modificationTime()
QDateTime Item::modificationTime | ( | ) | const |
◆ operator!=()
bool Item::operator!= | ( | const Item & | other | ) | const |
◆ operator<()
bool Item::operator< | ( | const Item & | other | ) | const |
◆ operator=()
◆ operator==()
bool Item::operator== | ( | const Item & | other | ) | const |
◆ parentCollection() [1/2]
Collection & Item::parentCollection | ( | ) |
◆ parentCollection() [2/2]
Collection Item::parentCollection | ( | ) | const |
◆ payload()
T Item::payload | ( | ) | const |
Returns the payload object of this PIM item.
This method will only succeed if either you requested the exact same payload type that was put in or the payload uses a supported shared pointer type (currently QSharedPointer and std::shared_ptr), and is castable to the requested type. For this to work there needs to be a specialization of Akonadi::super_trait of the used classes.
If a mismatching or non-castable payload type is requested, an Akonadi::PayloadException is thrown. Therefore it is generally recommended to guard calls to payload() with a corresponding hasPayload() call.
Trying to retrieve a pointer type will fail to compile.
◆ payloadData()
QByteArray Item::payloadData | ( | ) | const |
◆ payloadPath()
QString Item::payloadPath | ( | ) | const |
Returns path to the payload file set by setPayloadPath()
If payload was set via setPayload() or setPayloadFromData() then this method will return a null string.
◆ remoteId()
QString Item::remoteId | ( | ) | const |
◆ remoteRevision()
QString Item::remoteRevision | ( | ) | const |
◆ removeAttribute() [1/2]
|
inline |
◆ removeAttribute() [2/2]
void Akonadi::Item::removeAttribute | ( | const QByteArray & | name | ) |
Removes and deletes the attribute of the given type name
.
◆ revision()
int Item::revision | ( | ) | const |
◆ setCachedPayloadParts()
void Item::setCachedPayloadParts | ( | const QSet< QByteArray > & | cachedParts | ) |
◆ setFlag()
void Item::setFlag | ( | const QByteArray & | name | ) |
◆ setFlags()
void Item::setFlags | ( | const Flags & | flags | ) |
◆ setGid()
void Item::setGid | ( | const QString & | gid | ) |
◆ setId()
void Item::setId | ( | Item::Id | identifier | ) |
◆ setMimeType()
void Item::setMimeType | ( | const QString & | mimeType | ) |
◆ setModificationTime()
void Item::setModificationTime | ( | const QDateTime & | datetime | ) |
◆ setParentCollection()
void Item::setParentCollection | ( | const 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.
- Parameters
-
parent The parent collection.
- Since
- 4.4
◆ setPayload() [1/2]
void Item::setPayload | ( | const T & | p | ) |
Sets the payload object of this PIM item.
- Parameters
-
p The payload object. Must be copyable and must not be a pointer, will cause a compilation failure otherwise. Using a type that can be copied fast (such as implicitly shared classes) is recommended. If the payload type is polymorphic and you intend to set and retrieve payload objects with mismatching but castable types, make sure to use a supported shared pointer implementation (currently QSharedPointer and std::shared_ptr) and make sure there is a specialization of Akonadi::super_trait for your class.
◆ setPayload() [2/2]
void Akonadi::Item::setPayload | ( | T * | p | ) |
◆ setPayloadFromData()
void Item::setPayloadFromData | ( | const QByteArray & | data | ) |
◆ setPayloadPath()
void Item::setPayloadPath | ( | const QString & | filePath | ) |
Sets a path to a file with full payload.
This method can only be used by Resources and should not be used by Akonadi clients. Clients should use setPayload() instead.
Akonadi will not duplicate content of the file in its database but will instead directly refer to this file. This means that the file must be persistent (don't use this method with a temporary files), and the Akonadi resource that owns the storage is responsible for updating the file path if the file is changed, moved or removed.
The payload can still be accessed via payload() methods.
- See also
- setPayload(), setPayloadFromData()
- Since
- 5.6
◆ setRemoteId()
void Item::setRemoteId | ( | const QString & | id | ) |
◆ setRemoteRevision()
void Item::setRemoteRevision | ( | const QString & | revision | ) |
Sets the remote revision
of the item.
- Parameters
-
revision the item'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.
- Since
- 4.5
◆ setRevision()
void Item::setRevision | ( | int | revision | ) |
◆ setSize()
void Item::setSize | ( | qint64 | size | ) |
◆ setTag()
◆ setTags()
◆ setVirtualReferences()
void Item::setVirtualReferences | ( | const Collection::List & | collections | ) |
◆ size()
qint64 Item::size | ( | ) | const |
◆ storageCollectionId()
Collection::Id Item::storageCollectionId | ( | ) | const |
Returns the unique identifier of the collection this item is stored in.
There is only a single such collection, although the item can be linked into arbitrary many virtual collections. Calling this method makes sense only after running an ItemFetchJob on the item.
- Returns
- the collection ID if it is known, -1 otherwise.
- Since
- 4.3
◆ tags()
◆ url()
◆ virtualReferences()
Collection::List Item::virtualReferences | ( | ) | const |
Lists virtual collections that this item is linked to.
- Note
- This value is populated only when this item was retrieved by ItemFetchJob with fetchVirtualReferences set to true in ItemFetchScope, otherwise this list is always empty.
- Since
- 4.14
Member Data Documentation
◆ FullPayload
|
static |
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.