1.1.55
by Jonathan Thomas
Import upstream version 4.5.80 |
1 |
/*
|
2 |
This file is part of akonadiresources.
|
|
3 |
||
4 |
Copyright (c) 2006 Till Adam <adam@kde.org>
|
|
5 |
Copyright (c) 2007 Volker Krause <vkrause@kde.org>
|
|
6 |
||
7 |
This library is free software; you can redistribute it and/or modify it
|
|
8 |
under the terms of the GNU Library General Public License as published by
|
|
9 |
the Free Software Foundation; either version 2 of the License, or (at your
|
|
10 |
option) any later version.
|
|
11 |
||
12 |
This library is distributed in the hope that it will be useful, but WITHOUT
|
|
13 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
|
|
15 |
License for more details.
|
|
16 |
||
17 |
You should have received a copy of the GNU Library General Public License
|
|
18 |
along with this library; see the file COPYING.LIB. If not, write to the
|
|
19 |
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
20 |
02110-1301, USA.
|
|
21 |
*/
|
|
22 |
||
23 |
#ifndef AKONADI_AGENTFACTORY_H
|
|
24 |
#define AKONADI_AGENTFACTORY_H
|
|
25 |
||
26 |
#include "akonadi_export.h" |
|
27 |
#include "agentbase.h" |
|
28 |
||
29 |
#include <QtCore/QObject> |
|
1.1.56
by Jonathan Kolberg
Import upstream version 4.5.85a |
30 |
#include <QtCore/QtPlugin> |
1.1.55
by Jonathan Thomas
Import upstream version 4.5.80 |
31 |
|
32 |
namespace Akonadi { |
|
33 |
||
34 |
class AgentFactoryBasePrivate; |
|
1.1.79
by Jonathan Thomas
Import upstream version 4.8.80a |
35 |
|
1.1.55
by Jonathan Thomas
Import upstream version 4.5.80 |
36 |
/**
|
37 |
* @short A factory base class for in-process agents.
|
|
38 |
*
|
|
39 |
* @see AKONADI_AGENT_FACTORY()
|
|
40 |
* @internal
|
|
41 |
* @since 4.6
|
|
42 |
*/
|
|
43 |
class AKONADI_EXPORT AgentFactoryBase : public QObject |
|
44 |
{
|
|
45 |
Q_OBJECT
|
|
46 |
||
47 |
public: |
|
48 |
/**
|
|
49 |
* Creates a new agent factory.
|
|
50 |
* Executed in the main thread, performs KDE infrastructure setup.
|
|
51 |
*
|
|
52 |
* @param catalogName The translation catalog of this resource.
|
|
53 |
* @param parent The parent object.
|
|
54 |
*/
|
|
55 |
explicit AgentFactoryBase( const char *catalogName, QObject *parent = 0 ); |
|
56 |
||
1.1.79
by Jonathan Thomas
Import upstream version 4.8.80a |
57 |
virtual ~AgentFactoryBase(); |
58 |
||
1.1.55
by Jonathan Thomas
Import upstream version 4.5.80 |
59 |
public Q_SLOTS: |
60 |
/**
|
|
61 |
* Creates a new agent instace with the given identifier.
|
|
62 |
*/
|
|
63 |
virtual QObject* createInstance( const QString &identifier ) const = 0; |
|
64 |
||
65 |
protected: |
|
66 |
void createComponentData( const QString &identifier ) const; |
|
67 |
||
68 |
private: |
|
69 |
AgentFactoryBasePrivate* const d; |
|
70 |
};
|
|
71 |
||
72 |
/**
|
|
73 |
* @short A factory for in-process agents.
|
|
74 |
*
|
|
75 |
* @see AKONADI_AGENT_FACTORY()
|
|
76 |
* @internal
|
|
77 |
* @since 4.6
|
|
78 |
*/
|
|
79 |
template <typename T> |
|
80 |
class AgentFactory : public AgentFactoryBase |
|
81 |
{
|
|
82 |
public: |
|
83 |
/** reimplemented */
|
|
84 |
explicit AgentFactory( const char *catalogName, QObject *parent = 0 ) |
|
85 |
: AgentFactoryBase( catalogName, parent ) |
|
86 |
{
|
|
87 |
}
|
|
88 |
||
89 |
QObject* createInstance( const QString &identifier ) const |
|
90 |
{
|
|
91 |
createComponentData( identifier ); |
|
92 |
T* instance = new T( identifier ); |
|
93 |
||
94 |
// check if T also inherits AgentBase::Observer and
|
|
95 |
// if it does, automatically register it on itself
|
|
96 |
Akonadi::AgentBase::Observer *observer = dynamic_cast<Akonadi::AgentBase::Observer*>( instance ); |
|
97 |
if ( observer != 0 ) |
|
98 |
instance->registerObserver( observer ); |
|
99 |
||
100 |
return instance; |
|
101 |
}
|
|
102 |
};
|
|
1.1.79
by Jonathan Thomas
Import upstream version 4.8.80a |
103 |
|
1.1.55
by Jonathan Thomas
Import upstream version 4.5.80 |
104 |
}
|
105 |
||
106 |
#ifndef AKONADI_AGENT_FACTORY
|
|
107 |
/**
|
|
108 |
* Macro to create an agent factory for in-process agents.
|
|
109 |
*
|
|
110 |
* @param agentClass class name of the agent type this factory should create.
|
|
111 |
* @param catalogName name of the translation catalog of this agent type.
|
|
112 |
* @since 4.6
|
|
113 |
*/
|
|
114 |
#define AKONADI_AGENT_FACTORY( agentClass, catalogName ) \
|
|
115 |
class agentClass ## Factory : public Akonadi::AgentFactory< agentClass > \
|
|
116 |
{ \
|
|
117 |
public: \
|
|
118 |
explicit agentClass ## Factory( QObject * parent = 0 ) : Akonadi::AgentFactory< agentClass >( # catalogName, parent ) {\
|
|
119 |
setObjectName(# catalogName );\
|
|
120 |
} \
|
|
121 |
}; \
|
|
122 |
Q_EXPORT_PLUGIN2( catalogName, agentClass ## Factory )
|
|
123 |
||
124 |
#endif
|
|
125 |
||
126 |
#endif
|