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

akonadi

  • akonadi
attributefactory.cpp
1 /*
2  Copyright (c) 2007 - 2008 Volker Krause <vkrause@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 "attributefactory.h"
21 
22 #include "collectionquotaattribute.h"
23 #include "collectionrightsattribute_p.h"
24 #include "entitydisplayattribute.h"
25 #include "entityhiddenattribute.h"
26 #include "indexpolicyattribute.h"
27 #include "persistentsearchattribute.h"
28 #include "entitydeletedattribute.h"
29 #include "tagattribute.h"
30 #include "entityannotationsattribute.h"
31 
32 #include <KGlobal>
33 
34 #include <QtCore/QHash>
35 
36 using namespace Akonadi;
37 
38 namespace Akonadi {
39 namespace Internal {
40 
44 class DefaultAttribute : public Attribute
45 {
46  public:
47  explicit DefaultAttribute( const QByteArray &type, const QByteArray &value = QByteArray() ) :
48  mType( type ),
49  mValue( value )
50  {}
51 
52  QByteArray type() const { return mType; }
53  Attribute* clone() const
54  {
55  return new DefaultAttribute( mType, mValue );
56  }
57 
58  QByteArray serialized() const { return mValue; }
59  void deserialize( const QByteArray &data ) { mValue = data; }
60 
61  private:
62  QByteArray mType, mValue;
63 };
64 
68 class StaticAttributeFactory : public AttributeFactory
69 {
70  public:
71  StaticAttributeFactory() : AttributeFactory(), initialized( false ) {}
72  void init() {
73  if ( initialized ) {
74  return;
75  }
76  initialized = true;
77 
78  // Register built-in attributes
79  AttributeFactory::registerAttribute<CollectionQuotaAttribute>();
80  AttributeFactory::registerAttribute<CollectionRightsAttribute>();
81  AttributeFactory::registerAttribute<EntityDisplayAttribute>();
82  AttributeFactory::registerAttribute<EntityHiddenAttribute>();
83  AttributeFactory::registerAttribute<IndexPolicyAttribute>();
84  AttributeFactory::registerAttribute<PersistentSearchAttribute>();
85  AttributeFactory::registerAttribute<EntityDeletedAttribute>();
86  AttributeFactory::registerAttribute<EntityAnnotationsAttribute>();
87  AttributeFactory::registerAttribute<TagAttribute>();
88  }
89  bool initialized;
90 };
91 
92 K_GLOBAL_STATIC( StaticAttributeFactory, s_attributeInstance )
93 
94 }
95 
96 using Akonadi::Internal::s_attributeInstance;
97 
101 class AttributeFactory::Private
102 {
103  public:
104  QHash<QByteArray, Attribute*> attributes;
105 };
106 
107 AttributeFactory* AttributeFactory::self()
108 {
109  s_attributeInstance->init();
110  return s_attributeInstance;
111 }
112 
113 AttributeFactory::AttributeFactory()
114  : d( new Private )
115 {
116 }
117 
118 AttributeFactory::~ AttributeFactory()
119 {
120  qDeleteAll( d->attributes );
121  delete d;
122 }
123 
124 void AttributeFactory::registerAttribute(Attribute *attr)
125 {
126  Q_ASSERT( attr );
127  Q_ASSERT( !attr->type().contains( ' ' ) && !attr->type().contains( '\'' ) && !attr->type().contains( '"' ) );
128  QHash<QByteArray, Attribute*>::Iterator it = d->attributes.find( attr->type() );
129  if ( it != d->attributes.end() ) {
130  delete *it;
131  d->attributes.erase( it );
132  }
133  d->attributes.insert( attr->type(), attr );
134 }
135 
136 Attribute* AttributeFactory::createAttribute(const QByteArray &type)
137 {
138  Attribute *attr = self()->d->attributes.value( type );
139  if ( attr ) {
140  return attr->clone();
141  }
142  return new Internal::DefaultAttribute( type );
143 }
144 
145 }
146 
Akonadi::AttributeFactory
Provides the functionality of registering and creating arbitrary entity attributes.
Definition: attributefactory.h:48
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:138
Akonadi::AttributeFactory::registerAttribute
static void registerAttribute()
Registers a custom attribute of type T.
Definition: attributefactory.h:59
Akonadi::AttributeFactory::createAttribute
static Attribute * createAttribute(const QByteArray &type)
Creates an entity attribute object of the given type.
Definition: attributefactory.cpp:136
Akonadi::Attribute::clone
virtual Attribute * clone() const =0
Creates a copy of this attribute.
Akonadi::Attribute::type
virtual QByteArray type() const =0
Returns the type of the attribute.
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