You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
3.2 KiB
92 lines
3.2 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
11 years ago
|
* Copyright (C) 2003 Harald Fernengel <harry@kdevelop.org>
|
||
|
* Copyright (C) 2004 Alexander Dymo <adymo@kdevelop.org>
|
||
15 years ago
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Library General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Library General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Library General Public License
|
||
|
* along with this library; see the file COPYING.LIB. If not, write to
|
||
15 years ago
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
15 years ago
|
*/
|
||
|
#include <kgenericfactory.h>
|
||
12 years ago
|
#include <tdeaboutdata.h>
|
||
15 years ago
|
|
||
|
/**
|
||
11 years ago
|
@file tdevgenericfactory.h
|
||
15 years ago
|
KDevelop generic plugin factory.
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
This class provides a generic implementation of a KLibFactory for
|
||
13 years ago
|
use with TDevelop plugins.
|
||
15 years ago
|
Usually it is convenient to use K_EXPORT_COMPONENT_FACTORY macro
|
||
13 years ago
|
to create factories for TDevelop plugins. For example, for DummyPlugin
|
||
15 years ago
|
the factory can be created (in dummyplugin.cpp file) as:
|
||
|
@code
|
||
11 years ago
|
typedef TDevGenericFactory<DummyPlugin> DummyPluginFactory;
|
||
|
K_EXPORT_COMPONENT_FACTORY(libtdevdummyplugin, DummyPluginFactory( data ) )
|
||
15 years ago
|
@endcode
|
||
|
Data should be a const static object. This way it complies with the requirements
|
||
11 years ago
|
for data objecs of TDevGenericFactory constructor.
|
||
15 years ago
|
|
||
|
<b>Important:</b><br>
|
||
12 years ago
|
There is no need to create @ref TDEAboutData objects. It is more useful to create
|
||
11 years ago
|
a static const @ref TDevPluginInfo object which can be used also in the constructor
|
||
15 years ago
|
of a plugin.
|
||
|
|
||
|
For example, dummyplugin.cpp file could contain:
|
||
|
@code
|
||
11 years ago
|
#include <tdevplugininfo.h>
|
||
15 years ago
|
|
||
11 years ago
|
static const TDevPluginInfo data("KDevDummyPlugin");
|
||
|
typedef TDevGenericFactory<DummyPlugin> DummyPluginFactory;
|
||
|
K_EXPORT_COMPONENT_FACTORY(libtdevdummyplugin, DummyPluginFactory( data ) )
|
||
15 years ago
|
|
||
14 years ago
|
DummyPlugin::DummyPlugin(TQObject *parent, const char *name, const TQStringList & )
|
||
11 years ago
|
:TDevPlugin(&data, parent, name)
|
||
15 years ago
|
{
|
||
|
}
|
||
|
@endcode
|
||
|
|
||
11 years ago
|
In the example above the duplication of information is avoided as same @ref TDevPluginInfo
|
||
|
objects are used for plugin and for plugin factory. This is possible because @ref TDevPluginInfo
|
||
|
class has an operator to cast @ref TDevPluginInfo to @ref TDEAboutData.
|
||
15 years ago
|
*/
|
||
15 years ago
|
template <class T, class ParentType = TQObject>
|
||
11 years ago
|
class TDevGenericFactory: public KGenericFactory<T, ParentType>
|
||
15 years ago
|
{
|
||
|
public:
|
||
|
/**Constructor.
|
||
12 years ago
|
@param data A reference to TDEAboutData with an information about the plugin.
|
||
15 years ago
|
Data should have:
|
||
|
- plugin name as an application name;
|
||
|
- untranslated plugin generic name as a product name;
|
||
|
- license type number.
|
||
|
.
|
||
|
data object should live as long as factory lives.*/
|
||
11 years ago
|
TDevGenericFactory(TDEAboutData *data)
|
||
15 years ago
|
:KGenericFactory<T, ParentType>(data->appName()), aboutData(data)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
/**Creates an instance.*/
|
||
12 years ago
|
TDEInstance *createInstance()
|
||
15 years ago
|
{
|
||
12 years ago
|
return new TDEInstance(aboutData);
|
||
15 years ago
|
}
|
||
|
|
||
|
private:
|
||
12 years ago
|
TDEAboutData *aboutData;
|
||
15 years ago
|
|
||
|
};
|
||
|
|