akonadi
entity.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "entity.h"
00021 #include "entity_p.h"
00022
00023 using namespace Akonadi;
00024
00025 Entity::Entity( const Entity &other )
00026 : d_ptr( other.d_ptr )
00027 {
00028 }
00029
00030 Entity::Entity( EntityPrivate *dd )
00031 : d_ptr( dd )
00032 {
00033 }
00034
00035 Entity::~Entity()
00036 {
00037 }
00038
00039 void Entity::setId( Id id )
00040 {
00041 d_ptr->mId = id;
00042 }
00043
00044 Entity::Id Entity::id() const
00045 {
00046 return d_ptr->mId;
00047 }
00048
00049 void Entity::setRemoteId( const QString& id )
00050 {
00051 d_ptr->mRemoteId = id;
00052 }
00053
00054 QString Entity::remoteId() const
00055 {
00056 return d_ptr->mRemoteId;
00057 }
00058
00059 bool Entity::isValid() const
00060 {
00061 return ( d_ptr->mId >= 0 );
00062 }
00063
00064 bool Entity::operator==( const Entity &other ) const
00065 {
00066 return ( d_ptr->mId == other.d_ptr->mId );
00067 }
00068
00069 bool Akonadi::Entity::operator!=(const Entity & other) const
00070 {
00071 return d_ptr->mId != other.d_ptr->mId;
00072 }
00073
00074 Entity& Entity ::operator=( const Entity &other )
00075 {
00076 if ( this != &other )
00077 d_ptr = other.d_ptr;
00078
00079 return *this;
00080 }
00081
00082 void Entity::addAttribute(Attribute * attr)
00083 {
00084 if ( d_ptr->mAttributes.contains( attr->type() ) )
00085 delete d_ptr->mAttributes.take( attr->type() );
00086 d_ptr->mAttributes.insert( attr->type(), attr );
00087 d_ptr->mDeletedAttributes.remove( attr->type() );
00088 }
00089
00090 void Entity::removeAttribute( const QByteArray &type )
00091 {
00092 if ( d_ptr->mAttributes.contains( type ) ) {
00093 d_ptr->mDeletedAttributes.insert( type );
00094 delete d_ptr->mAttributes.take( type );
00095 }
00096 }
00097
00098 bool Entity::hasAttribute(const QByteArray & type) const
00099 {
00100 return d_ptr->mAttributes.contains( type );
00101 }
00102
00103 Attribute::List Entity::attributes() const
00104 {
00105 return d_ptr->mAttributes.values();
00106 }
00107
00108 void Akonadi::Entity::clearAttributes()
00109 {
00110 foreach ( Attribute *attr, d_ptr->mAttributes ) {
00111 d_ptr->mDeletedAttributes.insert( attr->type() );
00112 delete attr;
00113 }
00114 d_ptr->mAttributes.clear();
00115 }
00116
00117 Attribute * Entity::attribute(const QByteArray & type) const
00118 {
00119 if ( d_ptr->mAttributes.contains( type ) )
00120 return d_ptr->mAttributes.value( type );
00121 return 0;
00122 }
00123
00124 uint qHash( const Akonadi::Entity &entity )
00125 {
00126 return qHash( entity.id() );
00127 }
00128
00129 AKONADI_DEFINE_PRIVATE( Entity )