• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • Akonadi
  • ItemSerializerPlugin
Public Member Functions | Static Public Member Functions | List of all members
Akonadi::ItemSerializerPlugin Class Referenceabstract

#include <itemserializerplugin.h>

Inheritance diagram for Akonadi::ItemSerializerPlugin:
Inheritance graph
[legend]

Public Member Functions

virtual ~ItemSerializerPlugin ()
 
virtual bool deserialize (Item &item, const QByteArray &label, QIODevice &data, int version)=0
 
virtual QSet< QByteArray > parts (const Item &item) const
 
virtual void serialize (const Item &item, const QByteArray &label, QIODevice &data, int &version)=0
 

Static Public Member Functions

static void overridePluginLookup (QObject *plugin)
 

Detailed Description

The base class for item type serializer plugins.

Serializer plugins convert between the payload of Akonadi::Item objects and a textual or binary representation of the actual content data. This allows to easily add support for new types to Akonadi.

The following example shows how to implement a serializer plugin for a new data type PimNote.

The PimNote data structure:

typedef struct {
QString author;
QDateTime dateTime;
QString text;
} PimNote;

The serializer plugin code:

#include <QtCore/qplugin.h>
class SerializerPluginPimNote : public QObject, public Akonadi::ItemSerializerPlugin
{
Q_OBJECT
Q_INTERFACES( Akonadi::ItemSerializerPlugin )
public:
bool deserialize( Akonadi::Item& item, const QByteArray& label, QIODevice& data, int version )
{
// we don't handle versions in this example
Q_UNUSED( version );
// we work only on full payload
if ( label != Akonadi::Item::FullPayload )
return false;
QDataStream stream( &data );
PimNote note;
stream >> note.author;
stream >> note.dateTime;
stream >> note.text;
item.setPayload<PimNote>( note );
return true;
}
void serialize( const Akonadi::Item& item, const QByteArray& label, QIODevice& data, int &version )
{
// we don't handle versions in this example
Q_UNUSED( version );
if ( label != Akonadi::Item::FullPayload || !item.hasPayload<PimNote>() )
return;
QDataStream stream( &data );
PimNote note = item.payload<PimNote>();
stream << note.author;
stream << note.dateTime;
stream << note.text;
}
};
Q_EXPORT_PLUGIN2( akonadi_serializer_pimnote, SerializerPluginPimNote )

The desktop file:

[Misc]
Name=Pim Note Serializer
Comment=An Akonadi serializer plugin for note objects
[Plugin]
Type=application/x-pimnote
X-KDE-Library=akonadi_serializer_pimnote
Author
Till Adam adam@.nosp@m.kde..nosp@m.org, Volker Krause vkrau.nosp@m.se@k.nosp@m.de.or.nosp@m.g

Definition at line 119 of file itemserializerplugin.h.

Constructor & Destructor Documentation

ItemSerializerPlugin::~ItemSerializerPlugin ( )
virtual

Destroys the item serializer plugin.

Definition at line 29 of file itemserializerplugin.cpp.

Member Function Documentation

virtual bool Akonadi::ItemSerializerPlugin::deserialize ( Item &  item,
const QByteArray &  label,
QIODevice &  data,
int  version 
)
pure virtual

Converts serialized item data provided in data into payload for item.

Parameters
itemThe item to which the payload should be added. It is guaranteed to have a mime type matching one of the supported mime types of this plugin. However it might contain a unsuited payload added manually by the application developer. Verifying the payload type in case a payload is already available is recommended therefore.
labelThe part identifier of the part to deserialize. label might be an unsupported item part, return false if this is the case.
dataA QIODevice providing access to the serialized data. The QIODevice is opened in read-only mode and positioned at the beginning. The QIODevice is guaranteed to be valid.
versionThe version of the data format as set by the user in serialize() or 0 (default).
Returns
false if the specified part is not supported by this plugin, true if the part could be de-serialized successfully.

Implemented in Akonadi::StdStringItemSerializerPlugin, and Akonadi::DefaultItemSerializerPlugin.

void ItemSerializerPlugin::overridePluginLookup ( QObject *  plugin)
static

Override the plugin-lookup with plugin.

After calling this each lookup will always return plugin. This is useful to inject a special plugin for testing purposes. To reset the plugin, set to 0.

Since
4.12

Definition at line 42 of file itemserializerplugin.cpp.

QSet< QByteArray > ItemSerializerPlugin::parts ( const Item &  item) const
virtual

Returns a list of available parts for the given item payload.

The default implementation returns Item::FullPayload if a payload is set.

Parameters
itemThe item.

Definition at line 33 of file itemserializerplugin.cpp.

virtual void Akonadi::ItemSerializerPlugin::serialize ( const Item &  item,
const QByteArray &  label,
QIODevice &  data,
int &  version 
)
pure virtual

Convert the payload object provided in item into its serialzed form into data.

Parameters
itemThe item which contains the payload. It is guaranteed to have a mimetype matching one of the supported mimetypes of this plugin as well as the existence of a payload object. However it might contain an unsupported payload added manually by the application developer. Verifying the payload type is recommended therefore.
labelThe part identifier of the part to serialize. label will be one of the item parts returned by parts().
dataThe QIODevice where the serialized data should be written to. The QIODevice is opened in write-only mode and positioned at the beginning. The QIODevice is guaranteed to be valid.
versionThe version of the data format. Can be set by the user to handle different versions.

Implemented in Akonadi::StdStringItemSerializerPlugin, and Akonadi::DefaultItemSerializerPlugin.


The documentation for this class was generated from the following files:
  • itemserializerplugin.h
  • itemserializerplugin.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:29 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal