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

akonadi

  • sources
  • kde-4.14
  • 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  // Invalid items are the same, no matter what their internal ID is
105  return (!isValid() && !other.isValid()) || (d_ptr->mId == other.d_ptr->mId);
106 }
107 
108 bool Akonadi::Entity::operator!=(const Entity &other) const
109 {
110  return (isValid() || other.isValid()) && (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  Q_ASSERT(attr);
130  Attribute *existing = d_ptr->mAttributes.value(attr->type());
131  if (existing) {
132  if (attr == existing) {
133  return;
134  }
135  d_ptr->mAttributes.remove(attr->type());
136  delete existing;
137  }
138  d_ptr->mAttributes.insert(attr->type(), attr);
139  d_ptr->mDeletedAttributes.remove(attr->type());
140 }
141 
142 void Entity::removeAttribute(const QByteArray &type)
143 {
144  d_ptr->mDeletedAttributes.insert(type);
145  delete d_ptr->mAttributes.take(type);
146 }
147 
148 bool Entity::hasAttribute(const QByteArray &type) const
149 {
150  return d_ptr->mAttributes.contains(type);
151 }
152 
153 Attribute::List Entity::attributes() const
154 {
155  return d_ptr->mAttributes.values();
156 }
157 
158 void Akonadi::Entity::clearAttributes()
159 {
160  foreach (Attribute *attr, d_ptr->mAttributes) {
161  d_ptr->mDeletedAttributes.insert(attr->type());
162  delete attr;
163  }
164  d_ptr->mAttributes.clear();
165 }
166 
167 Attribute *Entity::attribute(const QByteArray &type) const
168 {
169  return d_ptr->mAttributes.value(type);
170 }
171 
172 uint qHash(const Akonadi::Entity &entity)
173 {
174  return qHash(entity.id());
175 }
176 
177 Collection &Entity::parentCollection()
178 {
179  if (!d_ptr->mParent) {
180  d_ptr->mParent = new Collection();
181  }
182  return *(d_ptr->mParent);
183 }
184 
185 Collection Entity::parentCollection() const
186 {
187  if (!d_ptr->mParent) {
188  return *(s_defaultParentCollection);
189  } else {
190  return *(d_ptr->mParent);
191  }
192 }
193 
194 void Entity::setParentCollection(const Collection &parent)
195 {
196  delete d_ptr->mParent;
197  d_ptr->mParent = new Collection(parent);
198 }
199 
200 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:53
QByteArray
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:194
Akonadi::Entity::parentCollection
Collection parentCollection() const
Returns the parent collection of this object.
Definition: entity.cpp:185
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:127
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
QString
QList
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::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:264
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:158
Akonadi::Entity::removeAttribute
void removeAttribute()
Removes and deletes the attribute of the requested type.
Definition: entity.h:255
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:153
QSharedDataPointer
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:108
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:03 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
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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