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

akonadi

Akonadi::Attribute

Akonadi::Attribute Class Reference

Provides interface for custom attributes for Entity. More...

#include <attribute.h>

Inheritance diagram for Akonadi::Attribute:
Akonadi::EntityDisplayAttribute Akonadi::MessageThreadingAttribute

List of all members.

Public Types

typedef QList< Attribute * > List

Public Member Functions

virtual Attribute * clone () const =0
virtual void deserialize (const QByteArray &data)=0
virtual QByteArray serialized () const =0
virtual QByteArray type () const =0
virtual ~Attribute ()

Detailed Description

Provides interface for custom attributes for Entity.

This class is an interface for custom attributes, that can be stored in an entity. Attributes should be meta data, e.g. ACLs, quotas etc. that are not part of the entities' data itself.

To provide custom attributes, you have to subclass from this interface and reimplement the pure virtual methods.

 class SecrecyAttribute : public Akonadi::Attribute
 {
    public:
      enum Secrecy
      {
        Public,
        Private,
        Confidential
      };

      SecrecyAttribute( Secrecy secrecy = Public )
        : mSecrecy( secrecy )
      {
      }

      void setSecrecy( Secrecy secrecy )
      {
        mSecrecy = secrecy;
      }

      Secrecy secrecy() const
      {
        return mSecrecy;
      }

      virtual QByteArray type() const
      {
        return "secrecy";
      }

      virtual Attribute* clone() const
      {
        return new SecrecyAttribute( mSecrecy );
      }

      virtual QByteArray serialized() const
      {
        switch ( mSecrecy ) {
          case Public: return "public"; break;
          case Private: return "private"; break;
          case Confidential: return "confidential"; break;
        }
      }

      virtual void deserialize( const QByteArray &data )
      {
        if ( data == "public" )
          mSecrecy = Public;
        else if ( data == "private" )
          mSecrecy = Private;
        else if ( data == "confidential" )
          mSecrecy = Confidential;
      }
 }

Additionally, you need to register your attribute with Akonadi::AttributeFactory for automatic deserialization during retrieving of collecitons or items:

 AttributeFactory::registerAttribute<SecrecyAttribute>();

Third party attributes need to be registered once by each application that uses them. So the above snippet needs to be in the resource that adds the attribute, and each application that uses the resource. This may be simplified in the future.

The custom attributes can be used in the following way:

 Akonadi::Item item( "text/directory" );
 SecrecyAttribute* attr = item.attribute<SecrecyAttribute>( Item::AddIfMissing );
 attr->setSecrecy( SecrecyAttribute::Confidential );

and

 Akonadi::Item item = ...

 if ( item.hasAttribute<SecrecyAttribute>() ) {
   SecrecyAttribute *attr = item.attribute<SecrecyAttribute>();

   SecrecyAttribute::Secrecy secrecy = attr->secrecy();
   ...
 }
Author:
Volker Krause <vkrause@kde.org>

Definition at line 135 of file attribute.h.


Member Typedef Documentation

typedef QList<Attribute*> Akonadi::Attribute::List

Describes a list of attributes.

Definition at line 141 of file attribute.h.


Constructor & Destructor Documentation

Attribute::~Attribute (  )  [virtual]

Destroys this attribute.

Definition at line 24 of file attribute.cpp.


Member Function Documentation

virtual Attribute* Akonadi::Attribute::clone (  )  const [pure virtual]

Creates a copy of this attribute.

Implemented in Akonadi::EntityDisplayAttribute, and Akonadi::MessageThreadingAttribute.

virtual void Akonadi::Attribute::deserialize ( const QByteArray &  data  )  [pure virtual]

Sets the data of this attribute, using the same encoding as returned by toByteArray().

Parameters:
data The encoded attribute data.

Implemented in Akonadi::EntityDisplayAttribute, and Akonadi::MessageThreadingAttribute.

virtual QByteArray Akonadi::Attribute::serialized (  )  const [pure virtual]

Returns a QByteArray representation of the attribute which will be storaged.

This can be raw binary data, no encoding needs to be applied.

Implemented in Akonadi::EntityDisplayAttribute, and Akonadi::MessageThreadingAttribute.

virtual QByteArray Akonadi::Attribute::type (  )  const [pure virtual]

Returns the type of the attribute.

Implemented in Akonadi::EntityDisplayAttribute, and Akonadi::MessageThreadingAttribute.


The documentation for this class was generated from the following files:
  • attribute.h
  • attribute.cpp

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
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.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