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

akonadi

attributefactory.cpp
00001 /*
00002     Copyright (c) 2007 - 2008 Volker Krause <vkrause@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "attributefactory.h"
00021 
00022 #include "collectionquotaattribute.h"
00023 #include "collectionrightsattribute_p.h"
00024 #include "entitydisplayattribute.h"
00025 #include "entityhiddenattribute.h"
00026 #include "indexpolicyattribute.h"
00027 #include "persistentsearchattribute.h"
00028 #include "entitydeletedattribute.h"
00029 
00030 #include <KGlobal>
00031 
00032 #include <QtCore/QHash>
00033 
00034 using namespace Akonadi;
00035 
00036 namespace Akonadi {
00037 namespace Internal {
00038 
00042 class DefaultAttribute : public Attribute
00043 {
00044   public:
00045     explicit DefaultAttribute( const QByteArray &type, const QByteArray &value = QByteArray() ) :
00046       mType( type ),
00047       mValue( value )
00048     {}
00049 
00050     QByteArray type() const { return mType; }
00051     Attribute* clone() const
00052     {
00053       return new DefaultAttribute( mType, mValue );
00054     }
00055 
00056     QByteArray serialized() const { return mValue; }
00057     void deserialize( const QByteArray &data ) { mValue = data; }
00058 
00059   private:
00060     QByteArray mType, mValue;
00061 };
00062 
00066 class StaticAttributeFactory : public AttributeFactory
00067 {
00068   public:
00069     StaticAttributeFactory() : AttributeFactory(), initialized( false ) {}
00070     void init() {
00071       if ( initialized )
00072         return;
00073       initialized = true;
00074 
00075       // Register built-in attributes
00076       AttributeFactory::registerAttribute<CollectionQuotaAttribute>();
00077       AttributeFactory::registerAttribute<CollectionRightsAttribute>();
00078       AttributeFactory::registerAttribute<EntityDisplayAttribute>();
00079       AttributeFactory::registerAttribute<EntityHiddenAttribute>();
00080       AttributeFactory::registerAttribute<IndexPolicyAttribute>();
00081       AttributeFactory::registerAttribute<PersistentSearchAttribute>();
00082       AttributeFactory::registerAttribute<EntityDeletedAttribute>();
00083     }
00084     bool initialized;
00085 };
00086 
00087 K_GLOBAL_STATIC( StaticAttributeFactory, s_attributeInstance )
00088 
00089 }
00090 
00091 using Akonadi::Internal::s_attributeInstance;
00092 
00096 class AttributeFactory::Private
00097 {
00098   public:
00099     QHash<QByteArray, Attribute*> attributes;
00100 };
00101 
00102 
00103 AttributeFactory* AttributeFactory::self()
00104 {
00105   s_attributeInstance->init();
00106   return s_attributeInstance;
00107 }
00108 
00109 AttributeFactory::AttributeFactory()
00110   : d( new Private )
00111 {
00112 }
00113 
00114 AttributeFactory::~ AttributeFactory()
00115 {
00116   qDeleteAll( d->attributes );
00117   delete d;
00118 }
00119 
00120 void AttributeFactory::registerAttribute(Attribute *attr)
00121 {
00122   Q_ASSERT( attr );
00123   Q_ASSERT( !attr->type().contains(' ') && !attr->type().contains('\'') && !attr->type().contains('"') );
00124   QHash<QByteArray, Attribute*>::Iterator it = d->attributes.find( attr->type() );
00125   if ( it != d->attributes.end() ) {
00126     delete *it;
00127     d->attributes.erase( it );
00128   }
00129   d->attributes.insert( attr->type(), attr );
00130 }
00131 
00132 Attribute* AttributeFactory::createAttribute(const QByteArray &type)
00133 {
00134   Attribute* attr = self()->d->attributes.value( type );
00135   if ( attr )
00136     return attr->clone();
00137   return new Internal::DefaultAttribute( type );
00138 }
00139 
00140 }
00141 
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu Aug 2 2012 15:25:17 by doxygen 1.7.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.8.5 API Reference

Skip menu "kdepimlibs-4.8.5 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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