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

akonadi

  • 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 
54 Entity::Entity( const Entity &other )
55 {
56  assignEntityPrivate( d_ptr, other.d_ptr );
57 }
58 
59 Entity::Entity( EntityPrivate *dd )
60  : d_ptr( dd )
61 {
62 }
63 
64 Entity::~Entity()
65 {
66 }
67 
68 void Entity::setId( Id id )
69 {
70  d_ptr->mId = id;
71 }
72 
73 Entity::Id Entity::id() const
74 {
75  return d_ptr->mId;
76 }
77 
78 void Entity::setRemoteId( const QString& id )
79 {
80  d_ptr->mRemoteId = id;
81 }
82 
83 QString Entity::remoteId() const
84 {
85  return d_ptr->mRemoteId;
86 }
87 
88 void Entity::setRemoteRevision( const QString& revision )
89 {
90  d_ptr->mRemoteRevision = revision;
91 }
92 
93 QString Entity::remoteRevision() const
94 {
95  return d_ptr->mRemoteRevision;
96 }
97 
98 bool Entity::isValid() const
99 {
100  return ( d_ptr->mId >= 0 );
101 }
102 
103 bool Entity::operator==( const Entity &other ) const
104 {
105  return ( d_ptr->mId == other.d_ptr->mId );
106 }
107 
108 bool Akonadi::Entity::operator!=(const Entity & other) const
109 {
110  return d_ptr->mId != other.d_ptr->mId;
111 }
112 
113 Entity& Entity ::operator=( const Entity &other )
114 {
115  if ( this != &other ) {
116  assignEntityPrivate( d_ptr, other.d_ptr );
117  }
118 
119  return *this;
120 }
121 
122 bool Akonadi::Entity::operator<( const Entity & other ) const
123 {
124  return d_ptr->mId < other.d_ptr->mId;
125 }
126 
127 void Entity::addAttribute(Attribute * attr)
128 {
129  if ( d_ptr->mAttributes.contains( attr->type() ) ) {
130  Attribute *existing = d_ptr->mAttributes.value( attr->type() );
131  if ( attr == existing ) {
132  return;
133  }
134  d_ptr->mAttributes.remove( attr->type() );
135  delete existing;
136  }
137  d_ptr->mAttributes.insert( attr->type(), attr );
138  d_ptr->mDeletedAttributes.remove( attr->type() );
139 }
140 
141 void Entity::removeAttribute( const QByteArray &type )
142 {
143  d_ptr->mDeletedAttributes.insert( type );
144  delete d_ptr->mAttributes.take( type );
145 }
146 
147 bool Entity::hasAttribute(const QByteArray & type) const
148 {
149  return d_ptr->mAttributes.contains( type );
150 }
151 
152 Attribute::List Entity::attributes() const
153 {
154  return d_ptr->mAttributes.values();
155 }
156 
157 void Akonadi::Entity::clearAttributes()
158 {
159  foreach ( Attribute *attr, d_ptr->mAttributes ) {
160  d_ptr->mDeletedAttributes.insert( attr->type() );
161  delete attr;
162  }
163  d_ptr->mAttributes.clear();
164 }
165 
166 Attribute * Entity::attribute(const QByteArray & type) const
167 {
168  if ( d_ptr->mAttributes.contains( type ) ) {
169  return d_ptr->mAttributes.value( type );
170  }
171  return 0;
172 }
173 
174 uint qHash( const Akonadi::Entity &entity )
175 {
176  return qHash( entity.id() );
177 }
178 
179 Collection& Entity::parentCollection()
180 {
181  if ( !d_ptr->mParent ) {
182  d_ptr->mParent = new Collection();
183  }
184  return *( d_ptr->mParent );
185 }
186 
187 Collection Entity::parentCollection() const
188 {
189  if ( !d_ptr->mParent ) {
190  return *( s_defaultParentCollection );
191  } else {
192  return *( d_ptr->mParent );
193  }
194 }
195 
196 void Entity::setParentCollection( const Collection &parent )
197 {
198  delete d_ptr->mParent;
199  d_ptr->mParent = new Collection( parent );
200 }
201 
202 AKONADI_DEFINE_PRIVATE( Entity )
Akonadi::Entity::operator<
bool operator<(const Entity &other) const
Definition: entity.cpp:122
Akonadi::Entity::Entity
Entity(const Entity &other)
Creates an entity from an other entity.
Definition: entity.cpp:54
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:78
Akonadi::Entity::Id
qint64 Id
Describes the unique id type.
Definition: entity.h:64
Akonadi::Entity::attribute
T * attribute() const
Returns the attribute of the requested type or 0 if it is not available.
Definition: entity.h:235
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:68
Akonadi::Entity::setParentCollection
void setParentCollection(const Collection &parent)
Set the parent collection of this object.
Definition: entity.cpp:196
Akonadi::Entity::parentCollection
Collection parentCollection() const
Returns the parent collection of this object.
Definition: entity.cpp:187
Akonadi::Entity::setRemoteRevision
void setRemoteRevision(const QString &revision)
Sets the remote revision of the entity.
Definition: entity.cpp:88
Akonadi::Entity::addAttribute
void addAttribute(Attribute *attribute)
Adds an attribute to the entity.
Definition: entity.cpp:127
Akonadi::Entity::remoteId
QString remoteId() const
Returns the remote id of the entity.
Definition: entity.cpp:83
Akonadi::Entity::remoteRevision
QString remoteRevision() const
Returns the remote revision of the entity.
Definition: entity.cpp:93
Akonadi::Entity::~Entity
~Entity()
Destroys the entity.
Definition: entity.cpp:64
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:73
Akonadi::Entity
The base class for Item and Collection.
Definition: entity.h:58
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:113
Akonadi::Entity::hasAttribute
bool hasAttribute() const
Returns whether the entity has an attribute of the requested type.
Definition: entity.h:261
Akonadi::Entity::operator==
bool operator==(const Entity &other) const
Returns whether the entity&#39;s id equals the id of the other entity.
Definition: entity.cpp:103
Akonadi::EntityPrivate
Definition: entity_p.h:39
Akonadi::Entity::clearAttributes
void clearAttributes()
Removes and deletes all attributes of the entity.
Definition: entity.cpp:157
Akonadi::Entity::removeAttribute
void removeAttribute()
Removes and deletes the attribute of the requested type.
Definition: entity.h:252
Akonadi::Entity::isValid
bool isValid() const
Returns whether the entity is valid.
Definition: entity.cpp:98
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:152
Akonadi::Entity::operator!=
bool operator!=(const Entity &other) const
Returns whether the entity&#39;s id does not equal the id of the other entity.
Definition: entity.cpp:108
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Wed Nov 25 2015 21:42:12 by doxygen 1.8.5 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-4.10.5 API Reference

Skip menu "kdepimlibs-4.10.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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