akonadi
agentfactory.h
00001 /* 00002 This file is part of akonadiresources. 00003 00004 Copyright (c) 2006 Till Adam <adam@kde.org> 00005 Copyright (c) 2007 Volker Krause <vkrause@kde.org> 00006 00007 This library is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU Library General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or (at your 00010 option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00015 License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to the 00019 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00020 02110-1301, USA. 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 // check if T also inherits AgentBase::Observer and 00093 // if it does, automatically register it on itself 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
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue May 8 2012 00:00:39 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue May 8 2012 00:00:39 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.