Akonadi::Attribute

Search for usage in LXR

Akonadi::Attribute Class Referenceabstract

#include <attribute.h>

Inheritance diagram for Akonadi::Attribute:

Public Types

using List = QList< Attribute * >
 

Public Member Functions

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

Protected Member Functions

 Attribute (const Attribute &)=default
 

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.

Note that attributes are per user, i.e. when an attribute is added to an entity, it only applies to the current user.

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 collections 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 vkrau[email protected][email protected][email protected]de.or[email protected]g

Definition at line 124 of file attribute.h.

Member Typedef Documentation

◆ List

Describes a list of attributes.

Definition at line 130 of file attribute.h.

Constructor & Destructor Documentation

◆ ~Attribute()

Attribute::~Attribute ( )
virtualdefault

Destroys this attribute.

Member Function Documentation

◆ clone()

◆ deserialize()

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

◆ serialized()

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

◆ type()


The documentation for this class was generated from the following files:
virtual QByteArray type() const =0
Returns the type of the attribute.
Provides interface for custom attributes for Entity.
Definition: attribute.h:124
virtual QByteArray serialized() const =0
Returns a QByteArray representation of the attribute which will be storaged.
virtual Attribute * clone() const =0
Creates a copy of this attribute.
bool hasAttribute(const QByteArray &name) const
Returns true if the item has an attribute of the given type name, false otherwise.
Definition: item.cpp:128
@ AddIfMissing
Creates the attribute if it is missing.
Definition: item.h:311
Attribute * attribute(const QByteArray &name)
Returns the attribute of the given type name if available, 0 otherwise.
Definition: item.cpp:143
virtual void deserialize(const QByteArray &data)=0
Sets the data of this attribute, using the same encoding as returned by toByteArray().
Represents a PIM item stored in Akonadi storage.
Definition: item.h:104
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun May 22 2022 03:51:25 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.