• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • akonadi
entity.cpp
1 /*
2  Copyright (c) 2008 Tobias Koenig <tokoe@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "entity.h"
21 #include "entity_p.h"
22 #include "collection.h"
23 
24 #include <kglobal.h>
25 
26 using namespace Akonadi;
27 
28 K_GLOBAL_STATIC( Akonadi::Collection, s_defaultParentCollection )
29 
30 
33 static void assignEntityPrivate( QSharedDataPointer<EntityPrivate> &one, const QSharedDataPointer<EntityPrivate> &other )
34 {
35  // We can't simply do one = other here, we have to use a temp.
36  // Otherwise ProtocolHelperTest::testParentCollectionAfterCollectionParsing()
37  // will break.
38  //
39  // The reason are assignments like
40  // col = col.parentCollection()
41  //
42  // Here, parentCollection() actually returns a reference to a pointer owned
43  // by col. So when col (or rather, it's private class) is deleted, the pointer
44  // to the parent collection and therefore the reference becomes invalid.
45  //
46  // With a single-line assignment here, the parent collection would be deleted
47  // before it is assigned, and therefore the resulting object would point to
48  // uninitalized memory.
49  QSharedDataPointer<EntityPrivate> temp = other;
50  one = temp;
51 }
52 
53 Entity::Entity( const Entity &other )
54 {
55  assignEntityPrivate( d_ptr, other.d_ptr );
56 }
57 
58 Entity::Entity( EntityPrivate *dd )
59  : d_ptr( dd )
60 {
61 }
62 
63 Entity::~Entity()
64 {
65 }
66 
67 void Entity::setId( Id id )
68 {
69  d_ptr->mId = id;
70 }
71 
72 Entity::Id Entity::id() const
73 {
74  return d_ptr->mId;
75 }
76 
77 void Entity::setRemoteId( const QString& id )
78 {
79  d_ptr->mRemoteId = id;
80 }
81 
82 QString Entity::remoteId() const
83 {
84  return d_ptr->mRemoteId;
85 }
86 
87 void Entity::setRemoteRevision( const QString& revision )
88 {
89  d_ptr->mRemoteRevision = revision;
90 }
91 
92 QString Entity::remoteRevision() const
93 {
94  return d_ptr->mRemoteRevision;
95 }
96 
97 bool Entity::isValid() const
98 {
99  return ( d_ptr->mId >= 0 );
100 }
101 
102 bool Entity::operator==( const Entity &other ) const
103 {
104  return ( d_ptr->mId == other.d_ptr->mId );
105 }
106 
107 bool Akonadi::Entity::operator!=(const Entity & other) const
108 {
109  return d_ptr->mId != other.d_ptr->mId;
110 }
111 
112 Entity& Entity ::operator=( const Entity &other )
113 {
114  if ( this != &other ) {
115  assignEntityPrivate( d_ptr, other.d_ptr );
116  }
117 
118  return *this;
119 }
120 
121 bool Akonadi::Entity::operator<( const Entity & other ) const
122 {
123  return d_ptr->mId < other.d_ptr->mId;
124 }
125 
126 void Entity::addAttribute(Attribute * attr)
127 {
128  if ( d_ptr->mAttributes.contains( attr->type() ) ) {
129  Attribute *existing = d_ptr->mAttributes.value( attr->type() );
130  if ( attr == existing ) {
131  return;
132  }
133  d_ptr->mAttributes.remove( attr->type() );
134  delete existing;
135  }
136  d_ptr->mAttributes.insert( attr->type(), attr );
137  d_ptr->mDeletedAttributes.remove( attr->type() );
138 }
139 
140 void Entity::removeAttribute( const QByteArray &type )
141 {
142  d_ptr->mDeletedAttributes.insert( type );
143  delete d_ptr->mAttributes.take( type );
144 }
145 
146 bool Entity::hasAttribute(const QByteArray & type) const
147 {
148  return d_ptr->mAttributes.contains( type );
149 }
150 
151 Attribute::List Entity::attributes() const
152 {
153  return d_ptr->mAttributes.values();
154 }
155 
156 void Akonadi::Entity::clearAttributes()
157 {
158  foreach ( Attribute *attr, d_ptr->mAttributes ) {
159  d_ptr->mDeletedAttributes.insert( attr->type() );
160  delete attr;
161  }
162  d_ptr->mAttributes.clear();
163 }
164 
165 Attribute * Entity::attribute(const QByteArray & type) const
166 {
167  if ( d_ptr->mAttributes.contains( type ) ) {
168  return d_ptr->mAttributes.value( type );
169  }
170  return 0;
171 }
172 
173 uint qHash( const Akonadi::Entity &entity )
174 {
175  return qHash( entity.id() );
176 }
177 
178 Collection& Entity::parentCollection()
179 {
180  if ( !d_ptr->mParent ) {
181  d_ptr->mParent = new Collection();
182  }
183  return *( d_ptr->mParent );
184 }
185 
186 Collection Entity::parentCollection() const
187 {
188  if ( !d_ptr->mParent ) {
189  return *( s_defaultParentCollection );
190  } else {
191  return *( d_ptr->mParent );
192  }
193 }
194 
195 void Entity::setParentCollection( const Collection &parent )
196 {
197  delete d_ptr->mParent;
198  d_ptr->mParent = new Collection( parent );
199 }
200 
201 AKONADI_DEFINE_PRIVATE( Entity )
Akonadi::Entity::operator<
bool operator<(const Entity &other) const
Definition: entity.cpp:121
Akonadi::Entity::Entity
Entity(const Entity &other)
Creates an entity from an other entity.
Definition: entity.cpp:53
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Entity::setRemoteId
void setRemoteId(const QString &id)
Sets the remote id of the entity.
Definition: entity.cpp:77
Akonadi::Entity::Id
qint64 Id
Describes the unique id type.
Definition: entity.h:65
Akonadi::Entity::attribute
T * attribute() const
Returns the attribute of the requested type or 0 if it is not available.
Definition: entity.h:237
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:138
Akonadi::Entity::setId
void setId(Id identifier)
Sets the unique identifier of the entity.
Definition: entity.cpp:67
Akonadi::Entity::setParentCollection
void setParentCollection(const Collection &parent)
Set the parent collection of this object.
Definition: entity.cpp:195
Akonadi::Entity::parentCollection
Collection parentCollection() const
Returns the parent collection of this object.
Definition: entity.cpp:186
Akonadi::Entity::setRemoteRevision
void setRemoteRevision(const QString &revision)
Sets the remote revision of the entity.
Definition: entity.cpp:87
Akonadi::Entity::addAttribute
void addAttribute(Attribute *attribute)
Adds an attribute to the entity.
Definition: entity.cpp:126
Akonadi::Entity::remoteId
QString remoteId() const
Returns the remote id of the entity.
Definition: entity.cpp:82
Akonadi::Entity::remoteRevision
QString remoteRevision() const
Returns the remote revision of the entity.
Definition: entity.cpp:92
Akonadi::Entity::~Entity
~Entity()
Destroys the entity.
Definition: entity.cpp:63
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
Akonadi::Entity
The base class for Item and Collection.
Definition: entity.h:59
Akonadi::Attribute::List
QList< Attribute * > List
Describes a list of attributes.
Definition: attribute.h:144
Akonadi::Entity::operator=
Entity & operator=(const Entity &other)
Assigns the other to this entity and returns a reference to this entity.
Definition: entity.cpp:112
Akonadi::Entity::hasAttribute
bool hasAttribute() const
Returns whether the entity has an attribute of the requested type.
Definition: entity.h:263
Akonadi::Entity::operator==
bool operator==(const Entity &other) const
Returns whether the entity's id equals the id of the other entity.
Definition: entity.cpp:102
Akonadi::EntityPrivate
Definition: entity_p.h:39
Akonadi::Entity::clearAttributes
void clearAttributes()
Removes and deletes all attributes of the entity.
Definition: entity.cpp:156
Akonadi::Entity::removeAttribute
void removeAttribute()
Removes and deletes the attribute of the requested type.
Definition: entity.h:254
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:97
Akonadi::Attribute::type
virtual QByteArray type() const =0
Returns the type of the attribute.
Akonadi::Entity::attributes
Attribute::List attributes() const
Returns a list of all attributes of the entity.
Definition: entity.cpp:151
Akonadi::Entity::operator!=
bool operator!=(const Entity &other) const
Returns whether the entity's id does not equal the id of the other entity.
Definition: entity.cpp:107
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal