akonadi
entity.cpp
00001 /* 00002 Copyright (c) 2008 Tobias Koenig <tokoe@kde.org> 00003 00004 This library is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU Library General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or (at your 00007 option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, but WITHOUT 00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to the 00016 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00017 02110-1301, USA. 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 )