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

akonadi

  • akonadi
entity.h
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 #ifndef AKONADI_ENTITY_H
21 #define AKONADI_ENTITY_H
22 
23 #include "akonadi_export.h"
24 
25 namespace Akonadi {
26 class Entity;
27 }
28 
29 AKONADI_EXPORT uint qHash( const Akonadi::Entity& );
30 
31 #include <akonadi/attribute.h>
32 
33 #include <KDE/KDebug>
34 
35 #include <QtCore/QHash>
36 #include <QtCore/QSharedDataPointer>
37 
38 #define AKONADI_DECLARE_PRIVATE( Class ) \
39  Class##Private* d_func(); \
40  const Class##Private* d_func() const; \
41  friend class Class##Private;
42 
43 namespace Akonadi {
44 
45 class Collection;
46 class EntityPrivate;
47 
58 class AKONADI_EXPORT Entity
59 {
60  public:
64  typedef qint64 Id;
65 
69  void setId( Id identifier );
70 
74  Id id() const;
75 
79  void setRemoteId( const QString& id );
80 
84  QString remoteId() const;
85 
95  void setRemoteRevision( const QString& revision );
96 
103  QString remoteRevision() const;
104 
108  bool isValid() const;
109 
114  bool operator==( const Entity &other ) const;
115 
120  bool operator!=( const Entity &other ) const;
121 
126  Entity& operator=( const Entity &other );
127 
133  bool operator<( const Entity &other ) const;
134 
141  Collection parentCollection() const;
142 
149  Collection& parentCollection();
150 
160  void setParentCollection( const Collection &parent );
161 
172  void addAttribute( Attribute *attribute );
173 
177  void removeAttribute( const QByteArray &name );
178 
183  bool hasAttribute( const QByteArray &name ) const;
184 
188  Attribute::List attributes() const;
189 
193  void clearAttributes();
194 
198  Attribute* attribute( const QByteArray &name ) const;
199 
203  enum CreateOption {
204  AddIfMissing
205  };
206 
214  template <typename T> inline T* attribute( CreateOption option )
215  {
216  Q_UNUSED( option );
217 
218  const T dummy;
219  if ( hasAttribute( dummy.type() ) ) {
220  T* attr = dynamic_cast<T*>( attribute( dummy.type() ) );
221  if ( attr ) {
222  return attr;
223  }
224  kWarning( 5250 ) << "Found attribute of unknown type" << dummy.type()
225  << ". Did you forget to call AttributeFactory::registerAttribute()?";
226  }
227 
228  T* attr = new T();
229  addAttribute( attr );
230  return attr;
231  }
232 
236  template <typename T> inline T* attribute() const
237  {
238  const T dummy;
239  if ( hasAttribute( dummy.type() ) ) {
240  T* attr = dynamic_cast<T*>( attribute( dummy.type() ) );
241  if ( attr )
242  return attr;
243  kWarning( 5250 ) << "Found attribute of unknown type" << dummy.type()
244  << ". Did you forget to call AttributeFactory::registerAttribute()?";
245  }
246 
247  return 0;
248  }
249 
253  template <typename T> inline void removeAttribute()
254  {
255  const T dummy;
256  removeAttribute( dummy.type() );
257  }
258 
262  template <typename T> inline bool hasAttribute() const
263  {
264  const T dummy;
265  return hasAttribute( dummy.type() );
266  }
267 
268  protected:
272  Entity( const Entity &other );
273 
277  ~Entity();
278 
279  //@cond PRIVATE
280  Entity( EntityPrivate *dd );
281  QSharedDataPointer<EntityPrivate> d_ptr;
282  //@endcond
283 
284  AKONADI_DECLARE_PRIVATE( Entity )
285 };
286 
287 }
288 
289 #endif
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
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:236
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:138
Akonadi::Entity::attribute
T * attribute(CreateOption option)
Returns the attribute of the requested type.
Definition: entity.h:214
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::CreateOption
CreateOption
Describes the options that can be passed to access attributes.
Definition: entity.h:203
Akonadi::Entity::hasAttribute
bool hasAttribute() const
Returns whether the entity has an attribute of the requested type.
Definition: entity.h:262
Akonadi::EntityPrivate
Definition: entity_p.h:39
Akonadi::Entity::removeAttribute
void removeAttribute()
Removes and deletes the attribute of the requested type.
Definition: entity.h:253
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:03:17 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.11.3 API Reference

Skip menu "kdepimlibs-4.11.3 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