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 ~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
00100 void setRemoteRevision( const QString& revision );
00101
00108 QString remoteRevision() const;
00109
00113 bool isValid() const;
00114
00119 bool operator==( const Entity &other ) const;
00120
00125 bool operator!=( const Entity &other ) const;
00126
00130 Entity& operator=( const Entity &other );
00131
00138 Collection parentCollection() const;
00139
00146 Collection& parentCollection();
00147
00157 void setParentCollection( const Collection &parent );
00158
00169 void addAttribute( Attribute *attribute );
00170
00174 void removeAttribute( const QByteArray &name );
00175
00180 bool hasAttribute( const QByteArray &name ) const;
00181
00185 Attribute::List attributes() const;
00186
00190 void clearAttributes();
00191
00195 Attribute* attribute( const QByteArray &name ) const;
00196
00200 enum CreateOption
00201 {
00202 AddIfMissing
00203 };
00204
00212 template <typename T> inline T* attribute( CreateOption option )
00213 {
00214 Q_UNUSED( option );
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 T* attr = new T();
00226 addAttribute( attr );
00227 return attr;
00228 }
00229
00233 template <typename T> inline T* attribute() const
00234 {
00235 const T dummy;
00236 if ( hasAttribute( dummy.type() ) ) {
00237 T* attr = dynamic_cast<T*>( attribute( dummy.type() ) );
00238 if ( attr )
00239 return attr;
00240 kWarning( 5250 ) << "Found attribute of unknown type" << dummy.type()
00241 << ". Did you forget to call AttributeFactory::registerAttribute()?";
00242 }
00243
00244 return 0;
00245 }
00246
00250 template <typename T> inline void removeAttribute()
00251 {
00252 const T dummy;
00253 removeAttribute( dummy.type() );
00254 }
00255
00259 template <typename T> inline bool hasAttribute() const
00260 {
00261 const T dummy;
00262 return hasAttribute( dummy.type() );
00263 }
00264
00265 protected:
00269 Entity( const Entity &other );
00270
00271
00272 Entity( EntityPrivate *dd );
00273 QSharedDataPointer<EntityPrivate> d_ptr;
00274
00275
00276 AKONADI_DECLARE_PRIVATE( Entity )
00277 };
00278
00279 }
00280
00281 #endif