00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 void setId( Id identifier );
00070
00074 Id id() const;
00075
00079 void setRemoteId( const QString& id );
00080
00084 QString remoteId() const;
00085
00095 void setRemoteRevision( const QString& revision );
00096
00103 QString remoteRevision() const;
00104
00108 bool isValid() const;
00109
00114 bool operator==( const Entity &other ) const;
00115
00120 bool operator!=( const Entity &other ) const;
00121
00125 Entity& operator=( const Entity &other );
00126
00133 Collection parentCollection() const;
00134
00141 Collection& parentCollection();
00142
00152 void setParentCollection( const Collection &parent );
00153
00164 void addAttribute( Attribute *attribute );
00165
00169 void removeAttribute( const QByteArray &name );
00170
00175 bool hasAttribute( const QByteArray &name ) const;
00176
00180 Attribute::List attributes() const;
00181
00185 void clearAttributes();
00186
00190 Attribute* attribute( const QByteArray &name ) const;
00191
00195 enum CreateOption
00196 {
00197 AddIfMissing
00198 };
00199
00207 template <typename T> inline T* attribute( CreateOption option )
00208 {
00209 Q_UNUSED( option );
00210
00211 const T dummy;
00212 if ( hasAttribute( dummy.type() ) ) {
00213 T* attr = dynamic_cast<T*>( attribute( dummy.type() ) );
00214 if ( attr )
00215 return attr;
00216 kWarning( 5250 ) << "Found attribute of unknown type" << dummy.type()
00217 << ". Did you forget to call AttributeFactory::registerAttribute()?";
00218 }
00219
00220 T* attr = new T();
00221 addAttribute( attr );
00222 return attr;
00223 }
00224
00228 template <typename T> inline T* attribute() const
00229 {
00230 const T dummy;
00231 if ( hasAttribute( dummy.type() ) ) {
00232 T* attr = dynamic_cast<T*>( attribute( dummy.type() ) );
00233 if ( attr )
00234 return attr;
00235 kWarning( 5250 ) << "Found attribute of unknown type" << dummy.type()
00236 << ". Did you forget to call AttributeFactory::registerAttribute()?";
00237 }
00238
00239 return 0;
00240 }
00241
00245 template <typename T> inline void removeAttribute()
00246 {
00247 const T dummy;
00248 removeAttribute( dummy.type() );
00249 }
00250
00254 template <typename T> inline bool hasAttribute() const
00255 {
00256 const T dummy;
00257 return hasAttribute( dummy.type() );
00258 }
00259
00260 protected:
00264 Entity( const Entity &other );
00265
00269 ~Entity();
00270
00271
00272 Entity( EntityPrivate *dd );
00273 QSharedDataPointer<EntityPrivate> d_ptr;
00274
00275
00276 AKONADI_DECLARE_PRIVATE( Entity )
00277 };
00278
00279 }
00280
00281 #endif