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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 
30 #include <KGlobal>
31 
32 #include <QtCore/QHash>
33 
34 using namespace Akonadi;
35 
36 namespace Akonadi {
37 namespace Internal {
38 
42 class DefaultAttribute : public Attribute
43 {
44  public:
45  explicit DefaultAttribute( const QByteArray &type, const QByteArray &value = QByteArray() ) :
46  mType( type ),
47  mValue( value )
48  {}
49 
50  QByteArray type() const { return mType; }
51  Attribute* clone() const
52  {
53  return new DefaultAttribute( mType, mValue );
54  }
55 
56  QByteArray serialized() const { return mValue; }
57  void deserialize( const QByteArray &data ) { mValue = data; }
58 
59  private:
60  QByteArray mType, mValue;
61 };
62 
66 class StaticAttributeFactory : public AttributeFactory
67 {
68  public:
69  StaticAttributeFactory() : AttributeFactory(), initialized( false ) {}
70  void init() {
71  if ( initialized ) {
72  return;
73  }
74  initialized = true;
75 
76  // Register built-in attributes
77  AttributeFactory::registerAttribute<CollectionQuotaAttribute>();
78  AttributeFactory::registerAttribute<CollectionRightsAttribute>();
79  AttributeFactory::registerAttribute<EntityDisplayAttribute>();
80  AttributeFactory::registerAttribute<EntityHiddenAttribute>();
81  AttributeFactory::registerAttribute<IndexPolicyAttribute>();
82  AttributeFactory::registerAttribute<PersistentSearchAttribute>();
83  AttributeFactory::registerAttribute<EntityDeletedAttribute>();
84  }
85  bool initialized;
86 };
87 
88 K_GLOBAL_STATIC( StaticAttributeFactory, s_attributeInstance )
89 
90 }
91 
92 using Akonadi::Internal::s_attributeInstance;
93 
97 class AttributeFactory::Private
98 {
99  public:
100  QHash<QByteArray, Attribute*> attributes;
101 };
102 
103 AttributeFactory* AttributeFactory::self()
104 {
105  s_attributeInstance->init();
106  return s_attributeInstance;
107 }
108 
109 AttributeFactory::AttributeFactory()
110  : d( new Private )
111 {
112 }
113 
114 AttributeFactory::~ AttributeFactory()
115 {
116  qDeleteAll( d->attributes );
117  delete d;
118 }
119 
120 void AttributeFactory::registerAttribute(Attribute *attr)
121 {
122  Q_ASSERT( attr );
123  Q_ASSERT( !attr->type().contains( ' ' ) && !attr->type().contains( '\'' ) && !attr->type().contains( '"' ) );
124  QHash<QByteArray, Attribute*>::Iterator it = d->attributes.find( attr->type() );
125  if ( it != d->attributes.end() ) {
126  delete *it;
127  d->attributes.erase( it );
128  }
129  d->attributes.insert( attr->type(), attr );
130 }
131 
132 Attribute* AttributeFactory::createAttribute(const QByteArray &type)
133 {
134  Attribute *attr = self()->d->attributes.value( type );
135  if ( attr ) {
136  return attr->clone();
137  }
138  return new Internal::DefaultAttribute( type );
139 }
140 
141 }
142 
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:132
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 Tue Oct 14 2014 23:00:26 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
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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