akonadi
#include <item.h>

Public Types | |
typedef QByteArray | Flag |
typedef QSet< QByteArray > | Flags |
typedef QList< Item > | List |
enum | UrlType { UrlShort = 0, UrlWithMimeType = 1 } |
![]() | |
enum | CreateOption { AddIfMissing } |
typedef qint64 | Id |
Public Member Functions | |
Item () | |
Item (Id id) | |
Item (const QString &mimeType) | |
Item (const Item &other) | |
~Item () | |
template<typename T > | |
void | addToLegacyMapping (const QString &mimeType) |
void | apply (const Item &other) |
QVector< int > | availablePayloadMetaTypeIds () const |
QSet< QByteArray > | availablePayloadParts () const |
void | clearFlag (const QByteArray &name) |
void | clearFlags () |
void | clearPayload () |
Flags | flags () const |
bool | hasFlag (const QByteArray &name) const |
bool | hasPayload () const |
template<typename T > | |
bool | hasPayload () const |
QSet< QByteArray > | loadedPayloadParts () const |
QString | mimeType () const |
QDateTime | modificationTime () const |
template<typename T > | |
T | payload () const |
QByteArray | payloadData () const |
int | revision () const |
void | setFlag (const QByteArray &name) |
void | setFlags (const Flags &flags) |
void | setMimeType (const QString &mimeType) |
void | setModificationTime (const QDateTime &datetime) |
template<typename T > | |
void | setPayload (const T &p) |
template<typename T > | |
void | setPayload (T *p) |
template<typename T > | |
void | setPayload (std::auto_ptr< T > p) |
void | setPayloadFromData (const QByteArray &data) |
void | setRevision (int revision) |
void | setSize (qint64 size) |
qint64 | size () const |
Entity::Id | storageCollectionId () const |
KUrl | url (UrlType type=UrlShort) const |
![]() | |
void | addAttribute (Attribute *attribute) |
Attribute * | attribute (const QByteArray &name) const |
template<typename T > | |
T * | attribute (CreateOption option) |
template<typename T > | |
T * | attribute () const |
Attribute::List | attributes () const |
void | clearAttributes () |
bool | hasAttribute (const QByteArray &name) const |
template<typename T > | |
bool | hasAttribute () const |
Id | id () const |
bool | isValid () const |
bool | operator!= (const Entity &other) const |
bool | operator< (const Entity &other) const |
Entity & | operator= (const Entity &other) |
bool | operator== (const Entity &other) const |
Collection | parentCollection () const |
Collection & | parentCollection () |
QString | remoteId () const |
QString | remoteRevision () const |
void | removeAttribute (const QByteArray &name) |
template<typename T > | |
void | removeAttribute () |
void | setId (Id identifier) |
void | setParentCollection (const Collection &parent) |
void | setRemoteId (const QString &id) |
void | setRemoteRevision (const QString &revision) |
Static Public Member Functions | |
template<typename T > | |
static void | addToLegacyMapping (const QString &mimeType) |
static Item | fromUrl (const KUrl &url) |
Static Public Attributes | |
static const char * | FullPayload = "RFC822" |
Additional Inherited Members | |
![]() | |
Entity (const Entity &other) | |
~Entity () | |
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 boost::shared_ptr or QSharedPointer).
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 boost::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 boost::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
typedef QByteArray Akonadi::Item::Flag |
typedef QSet<QByteArray> Akonadi::Item::Flags |
typedef QList<Item> Akonadi::Item::List |
Member Enumeration Documentation
Constructor & Destructor Documentation
|
explicit |
|
explicit |
Item::Item | ( | const Item & | other | ) |
Member Function Documentation
|
static |
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.
- Since
- 4.4
QVector< int > Item::availablePayloadMetaTypeIds | ( | ) | const |
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
void Item::clearFlag | ( | const QByteArray & | name | ) |
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
Item::Flags Item::flags | ( | ) | const |
|
static |
bool Item::hasFlag | ( | const QByteArray & | name | ) | const |
bool Akonadi::Item::hasPayload | ( | ) | const |
bool Akonadi::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 boost::shared_ptr and QSharedPointer), 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.
QSet< QByteArray > Item::loadedPayloadParts | ( | ) | const |
QString Item::mimeType | ( | ) | const |
QDateTime Item::modificationTime | ( | ) | const |
T Akonadi::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 boost::shared_ptr and QSharedPointer), 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.
QByteArray Item::payloadData | ( | ) | const |
int Item::revision | ( | ) | const |
void Item::setFlag | ( | const QByteArray & | name | ) |
void Item::setFlags | ( | const Flags & | flags | ) |
void Item::setMimeType | ( | const QString & | mimeType | ) |
void Item::setModificationTime | ( | const QDateTime & | datetime | ) |
void Akonadi::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 boost::shared_ptr and QSharedPointer) and make sure there is a specialization of Akonadi::super_trait for your class.
void Item::setPayloadFromData | ( | const QByteArray & | data | ) |
void Item::setRevision | ( | int | revision | ) |
void Item::setSize | ( | qint64 | size | ) |
qint64 Item::size | ( | ) | const |
Entity::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
Member Data Documentation
|
static |
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:49 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.