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

akonadi

  • akonadi
attributeentity.h
1 /*
2  Copyright (c) 2014 Christian Mollekopf <mollekopf@kolabsys.com>
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_ATTRIBUTEENTITY_H
21 #define AKONADI_ATTRIBUTEENTITY_H
22 
23 #include <akonadi/job.h>
24 #include <QVector>
25 #include <qsharedpointer.h>
26 #include "attribute.h"
27 #include <kdebug.h>
28 
29 namespace Akonadi {
30 
40 class AKONADI_EXPORT AttributeEntity {
41 public:
42  AttributeEntity();
43 
44  AttributeEntity(const AttributeEntity &other);
45  virtual ~AttributeEntity();
46 
47  //Each subclass must override this to avoid slicing
48  virtual AttributeEntity &operator=(const AttributeEntity &other);
49 
60  void addAttribute( Attribute *attribute );
61 
65  void removeAttribute( const QByteArray &name );
66 
71  bool hasAttribute( const QByteArray &name ) const;
72 
76  Attribute::List attributes() const;
77 
81  void clearAttributes();
82 
86  Attribute* attribute( const QByteArray &name ) const;
87 
91  enum CreateOption {
92  AddIfMissing
93  };
94 
102  template <typename T> inline T* attribute( CreateOption option )
103  {
104  Q_UNUSED( option );
105 
106  const T dummy;
107  if ( hasAttribute( dummy.type() ) ) {
108  T* attr = dynamic_cast<T*>( attribute( dummy.type() ) );
109  if ( attr ) {
110  return attr;
111  }
112  kWarning( 5250 ) << "Found attribute of unknown type" << dummy.type()
113  << ". Did you forget to call AttributeFactory::registerAttribute()?";
114  }
115 
116  T* attr = new T();
117  addAttribute( attr );
118  return attr;
119  }
120 
124  template <typename T> inline T* attribute() const
125  {
126  const T dummy;
127  if ( hasAttribute( dummy.type() ) ) {
128  T* attr = dynamic_cast<T*>( attribute( dummy.type() ) );
129  if ( attr )
130  return attr;
131  kWarning( 5250 ) << "Found attribute of unknown type" << dummy.type()
132  << ". Did you forget to call AttributeFactory::registerAttribute()?";
133  }
134 
135  return 0;
136  }
137 
141  template <typename T> inline void removeAttribute()
142  {
143  const T dummy;
144  removeAttribute( dummy.type() );
145  }
146 
150  template <typename T> inline bool hasAttribute() const
151  {
152  const T dummy;
153  return hasAttribute( dummy.type() );
154  }
155 private:
156  friend class TagModifyJob;
157  QSet<QByteArray> &removedAttributes() const;
158 
159  class Private;
160  QSharedPointer<Private> d_ptr;
161 };
162 
163 }
164 
165 #endif
Akonadi::AttributeEntity::hasAttribute
bool hasAttribute() const
Returns whether the entity has an attribute of the requested type.
Definition: attributeentity.h:150
Akonadi::AttributeEntity::removeAttribute
void removeAttribute()
Removes and deletes the attribute of the requested type.
Definition: attributeentity.h:141
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:138
Akonadi::AttributeEntity
Parent class for entities that can have attributes.
Definition: attributeentity.h:40
Akonadi::AttributeEntity::attribute
T * attribute(CreateOption option)
Returns the attribute of the requested type.
Definition: attributeentity.h:102
Akonadi::AttributeEntity::CreateOption
CreateOption
Describes the options that can be passed to access attributes.
Definition: attributeentity.h:91
Akonadi::Attribute::List
QList< Attribute * > List
Describes a list of attributes.
Definition: attribute.h:144
Akonadi::TagModifyJob
Job that modifies a tag in the Akonadi storage.
Definition: tagmodifyjob.h:34
Akonadi::AttributeEntity::attribute
T * attribute() const
Returns the attribute of the requested type or 0 if it is not available.
Definition: attributeentity.h:124
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Jul 21 2014 08:03:50 by doxygen 1.8.6 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.13.3 API Reference

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