22 #include "collection.h"
26 using namespace Akonadi;
28 K_GLOBAL_STATIC( Akonadi::Collection, s_defaultParentCollection )
33 static
void assignEntityPrivate( QSharedDataPointer<EntityPrivate> &one, const QSharedDataPointer<EntityPrivate> &other )
49 QSharedDataPointer<EntityPrivate> temp = other;
54 Entity::Entity(
const Entity &other )
56 assignEntityPrivate( d_ptr, other.d_ptr );
68 void Entity::setId(
Id id )
78 void Entity::setRemoteId(
const QString&
id )
80 d_ptr->mRemoteId = id;
83 QString Entity::remoteId()
const
85 return d_ptr->mRemoteId;
88 void Entity::setRemoteRevision(
const QString& revision )
90 d_ptr->mRemoteRevision = revision;
93 QString Entity::remoteRevision()
const
95 return d_ptr->mRemoteRevision;
98 bool Entity::isValid()
const
100 return ( d_ptr->mId >= 0 );
103 bool Entity::operator==(
const Entity &other )
const
105 return ( d_ptr->mId == other.d_ptr->mId );
110 return d_ptr->mId != other.d_ptr->mId;
115 if (
this != &other ) {
116 assignEntityPrivate( d_ptr, other.d_ptr );
124 return d_ptr->mId < other.d_ptr->mId;
129 if ( d_ptr->mAttributes.contains( attr->
type() ) ) {
130 Attribute *existing = d_ptr->mAttributes.value( attr->
type() );
131 if ( attr == existing ) {
134 d_ptr->mAttributes.remove( attr->
type() );
137 d_ptr->mAttributes.insert( attr->
type(), attr );
138 d_ptr->mDeletedAttributes.remove( attr->
type() );
141 void Entity::removeAttribute(
const QByteArray &type )
143 d_ptr->mDeletedAttributes.insert( type );
144 delete d_ptr->mAttributes.take( type );
147 bool Entity::hasAttribute(
const QByteArray & type)
const
149 return d_ptr->mAttributes.contains( type );
154 return d_ptr->mAttributes.values();
159 foreach (
Attribute *attr, d_ptr->mAttributes ) {
160 d_ptr->mDeletedAttributes.insert( attr->
type() );
163 d_ptr->mAttributes.clear();
166 Attribute * Entity::attribute(
const QByteArray & type)
const
168 if ( d_ptr->mAttributes.contains( type ) )
169 return d_ptr->mAttributes.value( type );
173 uint qHash(
const Akonadi::Entity &entity )
175 return qHash( entity.id() );
180 if ( !d_ptr->mParent )
182 return *(d_ptr->mParent);
187 if ( !d_ptr->mParent )
188 return *(s_defaultParentCollection);
190 return *(d_ptr->mParent);
195 delete d_ptr->mParent;
199 AKONADI_DEFINE_PRIVATE(
Entity )