• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • 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 "collectionrightsattribute.h"
00023 
00024 #include <KGlobal>
00025 
00026 #include <QtCore/QHash>
00027 
00028 using namespace Akonadi;
00029 
00033 class DefaultAttribute : public Attribute
00034 {
00035   public:
00036     explicit DefaultAttribute( const QByteArray &type, const QByteArray &value = QByteArray() ) :
00037       mType( type ),
00038       mValue( value )
00039     {}
00040 
00041     QByteArray type() const { return mType; }
00042     Attribute* clone() const
00043     {
00044       return new DefaultAttribute( mType, mValue );
00045     }
00046 
00047     QByteArray serialized() const { return mValue; }
00048     void deserialize( const QByteArray &data ) { mValue = data; }
00049 
00050   private:
00051     QByteArray mType, mValue;
00052 };
00053 
00057 class AttributeFactory::Private
00058 {
00059   public:
00060     QHash<QByteArray, Attribute*> attributes;
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<CollectionRightsAttribute>();
00077     }
00078     bool initialized;
00079 };
00080 
00081 K_GLOBAL_STATIC( StaticAttributeFactory, s_attributeInstance )
00082 
00083 
00084 AttributeFactory* AttributeFactory::self()
00085 {
00086   s_attributeInstance->init();
00087   return s_attributeInstance;
00088 }
00089 
00090 AttributeFactory::AttributeFactory()
00091   : d( new Private )
00092 {
00093 }
00094 
00095 AttributeFactory::~ AttributeFactory()
00096 {
00097   qDeleteAll( d->attributes );
00098   delete d;
00099 }
00100 
00101 void AttributeFactory::registerAttribute(Attribute *attr)
00102 {
00103   Q_ASSERT( !d->attributes.contains( attr->type() ) );
00104   d->attributes.insert( attr->type(), attr );
00105 }
00106 
00107 Attribute* AttributeFactory::createAttribute(const QByteArray &type)
00108 {
00109   Attribute* attr = self()->d->attributes.value( type );
00110   if ( attr )
00111     return attr->clone();
00112   return new DefaultAttribute( type );
00113 }

akonadi

Skip menu "akonadi"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.7.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal