introduce setDefaultService(serviceName) and createDefaultService(QObject*). allows the dataengine (inheritor) to specify which service should probably be used. so applet users don't have to know those things if it's just 1

svn path=/trunk/KDE/kdelibs/; revision=1126712
This commit is contained in:
Shaun Reich 2010-05-14 17:41:40 +00:00
parent bdf9ddee65
commit a5da2705a9
3 changed files with 42 additions and 1 deletions

View File

@ -440,6 +440,18 @@ QString DataEngine::pluginName() const
return d->dataEngineDescription.pluginName();
}
void DataEngine::setDefaultService(const QString &serviceName)
{
d->serviceName = serviceName;
}
Service* DataEngine::createDefaultService(QObject *parent)
{
QVariantList args;
args << QVariant::fromValue<DataEngine*>(this);
return Service::load(d->serviceName, args, parent);
}
void DataEnginePrivate::publish(AnnouncementMethods methods, const QString &name)
{
if (!publishedService) {

View File

@ -234,6 +234,17 @@ NoAlignment) const;
*/
QString pluginName() const;
/**
* Initializes and returns a new service from the name that was set with setDefaultService.
* (service name is set internally). Sends a DataEngine* to the created service via the QVariantList.
* Note that you have to dispose of the Service* manually if you do not pass a valid parent.
* @see setDefaultService
* @param the parent of the object, if any, for the returned service
* @return the newly created service
* @since 4.5
*/
Q_INVOKABLE Service* createDefaultService(QObject *parent = 0);
Q_SIGNALS:
/**
* Emitted when a new data source is created
@ -426,6 +437,22 @@ NoAlignment) const;
**/
void setIcon(const QString &icon);
/**
* Should be set if there will be 1 main service.
* This saves any users of this DataEngine from having to know the service name to load.
* It is not created until createDefaultService is called.
*
* @code
* DataEngine *engine = dataEngine("foo");
* Service *service = engine->createDefaultService(this);
* @endcode
*
* @see createDefaultService
* @param serviceName the name of the service to load (plugin name)
* @since 4.5
*/
void setDefaultService(const QString &serviceName);
protected Q_SLOTS:
/**
* Call this method when you call setData directly on a DataContainer instead
@ -479,5 +506,6 @@ K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
K_EXPORT_PLUGIN(factory("plasma_engine_" #libname)) \
K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
#endif // multiple inclusion guard
Q_DECLARE_METATYPE(Plasma::DataEngine*)
#endif // multiple inclusion guard

View File

@ -93,6 +93,7 @@ class DataEnginePrivate
bool valid;
DataEngineScript *script;
QString engineName;
QString serviceName;
Package *package;
Service *publishedService;
};