• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi

entity.h

00001 /*
00002     Copyright (c) 2008 Tobias Koenig <tokoe@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 #ifndef AKONADI_ENTITY_H
00021 #define AKONADI_ENTITY_H
00022 
00023 #include "akonadi_export.h"
00024 
00025 namespace Akonadi {
00026 class Entity;
00027 }
00028 
00029 AKONADI_EXPORT uint qHash( const Akonadi::Entity& );
00030 
00031 #include <akonadi/attribute.h>
00032 
00033 #include <KDE/KDebug>
00034 
00035 #include <QtCore/QHash>
00036 #include <QtCore/QSharedDataPointer>
00037 
00038 #define AKONADI_DECLARE_PRIVATE( Class ) \
00039     Class##Private* d_func(); \
00040     const Class##Private* d_func() const; \
00041     friend class Class##Private;
00042 
00043 namespace Akonadi {
00044 
00045 class Collection;
00046 class EntityPrivate;
00047 
00058 class AKONADI_EXPORT Entity
00059 {
00060   public:
00064     typedef qint64 Id;
00065 
00069     ~Entity();
00070 
00074     void setId( Id identifier );
00075 
00079     Id id() const;
00080 
00084     void setRemoteId( const QString& id );
00085 
00089     QString remoteId() const;
00090 
00094     bool isValid() const;
00095 
00100     bool operator==( const Entity &other ) const;
00101 
00106     bool operator!=( const Entity &other ) const;
00107 
00111     Entity& operator=( const Entity &other );
00112 
00119     Collection parentCollection() const;
00120 
00127     Collection& parentCollection();
00128 
00138     void setParentCollection( const Collection &parent );
00139 
00150     void addAttribute( Attribute *attribute );
00151 
00155     void removeAttribute( const QByteArray &name );
00156 
00161     bool hasAttribute( const QByteArray &name ) const;
00162 
00166     Attribute::List attributes() const;
00167 
00171     void clearAttributes();
00172 
00176     Attribute* attribute( const QByteArray &name ) const;
00177 
00181     enum CreateOption
00182     {
00183       AddIfMissing    
00184     };
00185 
00193     template <typename T> inline T* attribute( CreateOption option )
00194     {
00195       Q_UNUSED( option );
00196 
00197       const T dummy;
00198       if ( hasAttribute( dummy.type() ) ) {
00199         T* attr = dynamic_cast<T*>( attribute( dummy.type() ) );
00200         if ( attr )
00201           return attr;
00202         kWarning( 5250 ) << "Found attribute of unknown type" << dummy.type()
00203           << ". Did you forget to call AttributeFactory::registerAttribute()?";
00204       }
00205 
00206       T* attr = new T();
00207       addAttribute( attr );
00208       return attr;
00209     }
00210 
00214     template <typename T> inline T* attribute() const
00215     {
00216       const T dummy;
00217       if ( hasAttribute( dummy.type() ) ) {
00218         T* attr = dynamic_cast<T*>( attribute( dummy.type() ) );
00219         if ( attr )
00220           return attr;
00221         kWarning( 5250 ) << "Found attribute of unknown type" << dummy.type()
00222           << ". Did you forget to call AttributeFactory::registerAttribute()?";
00223       }
00224 
00225       return 0;
00226     }
00227 
00231     template <typename T> inline void removeAttribute()
00232     {
00233       const T dummy;
00234       removeAttribute( dummy.type() );
00235     }
00236 
00240     template <typename T> inline bool hasAttribute() const
00241     {
00242       const T dummy;
00243       return hasAttribute( dummy.type() );
00244     }
00245 
00246   protected:
00250     Entity( const Entity &other );
00251 
00252     //@cond PRIVATE
00253     Entity( EntityPrivate *dd );
00254     QSharedDataPointer<EntityPrivate> d_ptr;
00255     //@endcond
00256 
00257     AKONADI_DECLARE_PRIVATE( Entity )
00258 };
00259 
00260 }
00261 
00262 #endif

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
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.2-20100208
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