• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi

  • Akonadi
  • Akonadi::ItemSerializerPlugin
Public Member Functions

Akonadi::ItemSerializerPlugin Class Reference

The base class for item type serializer plugins. More...

#include <itemserializerplugin.h>

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

List of all members.

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

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@kde.org>, Volker Krause <vkrause@kde.org>

Definition at line 120 of file itemserializerplugin.h.


Constructor & Destructor Documentation

virtual Akonadi::ItemSerializerPlugin::~ItemSerializerPlugin (  )  [virtual]

Destroys the item serializer plugin.


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:
item The 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.
label The part identifier of the part to deserialize. label might be an unsupported item part, return false if this is the case.
data A 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.
version The 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::DefaultItemSerializerPlugin.

virtual QSet<QByteArray> Akonadi::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:
item The item.
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:
item The 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.
label The part identifier of the part to serialize. label will be one of the item parts returned by parts().
data The 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.
version The version of the data format. Can be set by the user to handle different versions.

Implemented in Akonadi::DefaultItemSerializerPlugin.


The documentation for this class was generated from the following file:
  • itemserializerplugin.h

akonadi

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal