KDE 4.5 PyKDE API Reference
  • KDE's Python API
  • Overview
  • PyKDE Home
  • Sitemap
  • Contact Us
 

ItemSerializerPlugin Class Reference

from PyKDE4.akonadi import *

Subclasses: Akonadi.ItemSerializerPluginV2
Namespace: Akonadi

Detailed Description

Abstract class:
This class can be used as a base class for new classes, but can not be instantiated directly.

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>


Methods

bool deserialize (self, Akonadi.Item item, QByteArray label, QIODevice data, int version)
QSet parts (self, Akonadi.Item item)
 serialize (self, Akonadi.Item item, QByteArray label, QIODevice data, int version)

Method Documentation

bool deserialize (  self,
Akonadi.Item  item,
QByteArray  label,
QIODevice  data,
int  version
)
Abstract method:
This method is abstract and can be overridden but not called directly.

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.

QSet parts (  self,
Akonadi.Item  item
)

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.

serialize (  self,
Akonadi.Item  item,
QByteArray  label,
QIODevice  data,
int  version
)
Abstract method:
This method is abstract and can be overridden but not called directly.

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.

  • Full Index

Modules

  • akonadi
  • dnssd
  • kdecore
  • kdeui
  • khtml
  • kio
  • knewstuff
  • kparts
  • kutils
  • nepomuk
  • phonon
  • plasma
  • polkitqt
  • solid
  • soprano
This documentation is maintained by Simon Edwards.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal