00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef AKONADI_AGENTFACTORY_H
00024 #define AKONADI_AGENTFACTORY_H
00025
00026 #include "akonadi_export.h"
00027 #include "agentbase.h"
00028
00029 #include <QtCore/QObject>
00030 #include <QtCore/QtPlugin>
00031
00032 namespace Akonadi {
00033
00034 class AgentFactoryBasePrivate;
00035
00043 class AKONADI_EXPORT AgentFactoryBase : public QObject
00044 {
00045 Q_OBJECT
00046
00047 public:
00055 explicit AgentFactoryBase( const char *catalogName, QObject *parent = 0 );
00056
00057 public Q_SLOTS:
00061 virtual QObject* createInstance( const QString &identifier ) const = 0;
00062
00063 protected:
00064 void createComponentData( const QString &identifier ) const;
00065
00066 private:
00067 AgentFactoryBasePrivate* const d;
00068 };
00069
00077 template <typename T>
00078 class AgentFactory : public AgentFactoryBase
00079 {
00080 public:
00082 explicit AgentFactory( const char *catalogName, QObject *parent = 0 )
00083 : AgentFactoryBase( catalogName, parent )
00084 {
00085 }
00086
00087 QObject* createInstance( const QString &identifier ) const
00088 {
00089 createComponentData( identifier );
00090 T* instance = new T( identifier );
00091
00092
00093
00094 Akonadi::AgentBase::Observer *observer = dynamic_cast<Akonadi::AgentBase::Observer*>( instance );
00095 if ( observer != 0 )
00096 instance->registerObserver( observer );
00097
00098 return instance;
00099 }
00100 };
00101
00102 }
00103
00104 #ifndef AKONADI_AGENT_FACTORY
00105
00112 #define AKONADI_AGENT_FACTORY( agentClass, catalogName ) \
00113 class agentClass ## Factory : public Akonadi::AgentFactory< agentClass > \
00114 { \
00115 public: \
00116 explicit agentClass ## Factory( QObject * parent = 0 ) : Akonadi::AgentFactory< agentClass >( # catalogName, parent ) {\
00117 setObjectName(# catalogName );\
00118 } \
00119 }; \
00120 Q_EXPORT_PLUGIN2( catalogName, agentClass ## Factory )
00121
00122 #endif
00123
00124 #endif