rearrange the initialization code of the engines a bit, moving more out of the manager class, and calling init immediately. applets shouldn't be connecting to them in their ctor, so this should have minimal (or even zero) effect on start up while ensuring that init gets called first no matter what

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=779042
This commit is contained in:
Aaron J. Seigo 2008-02-25 11:24:37 +00:00
parent bc5accafd2
commit 507a6f02a0
3 changed files with 23 additions and 34 deletions

View File

@ -40,18 +40,26 @@ class DataEngine::Private
public:
Private(DataEngine* e, KService::Ptr service)
: engine(e),
ref(0),
ref(-1), // first ref
updateTimerId(0),
minUpdateInterval(-1),
limit(0),
valid(true),
script(0),
dataEngineDescription(service)
script(0)
{
updateTimer = new QTimer(engine);
updateTimer->setSingleShot(true);
updateTimestamp.start();
if (!service) {
return;
}
engineName = service->property("X-Plasma-EngineName").toString();
e->setObjectName(engineName);
icon = service->icon();
KPluginInfo dataEngineDescription(service);
if (dataEngineDescription.isValid()) {
QString language = dataEngineDescription.property("X-Plasma-Language").toString();
@ -185,18 +193,16 @@ class DataEngine::Private
uint limit;
bool valid;
DataEngineScript* script;
KPluginInfo dataEngineDescription;
QString engineName;
};
DataEngine::DataEngine(QObject* parent, const QString& serviceId)
DataEngine::DataEngine(QObject* parent, KService::Ptr service)
: QObject(parent),
d(new Private(this, KService::serviceByStorageId(serviceId)))
d(new Private(this, service))
{
connect(d->updateTimer, SIGNAL(timeout()), this, SLOT(checkForUpdates()));
//FIXME: we should delay this call; to when is the question.
//Update DataEngine::init() api docu when fixed
QTimer::singleShot(0, this, SLOT(startInit()));
init();
}
DataEngine::DataEngine(QObject* parent, const QVariantList& args)
@ -204,9 +210,7 @@ DataEngine::DataEngine(QObject* parent, const QVariantList& args)
d(new Private(this, KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString())))
{
connect(d->updateTimer, SIGNAL(timeout()), this, SLOT(checkForUpdates()));
//FIXME: we should delay this call; to when is the question.
//Update DataEngine::init() api docu when fixed
QTimer::singleShot(0, this, SLOT(startInit()));
init();
}
DataEngine::~DataEngine()
@ -271,11 +275,6 @@ DataEngine::Data DataEngine::query(const QString& source) const
return data;
}
void DataEngine::startInit()
{
init();
}
void DataEngine::internalUpdateSource(DataContainer* source)
{
if (d->minUpdateInterval > 0 &&
@ -529,11 +528,7 @@ void DataEngine::checkForUpdates()
QString DataEngine::engineName() const
{
if (!d->dataEngineDescription.isValid()) {
return QString();
}
return d->dataEngineDescription.property("X-Plasma-EngineName").toString();
return d->engineName;
}
}

View File

@ -24,7 +24,8 @@
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <kgenericfactory.h>
#include <KGenericFactory>
#include <KService>
#include <plasma/plasma_export.h>
#include <plasma/plasma.h>
@ -64,11 +65,12 @@ class PLASMA_EXPORT DataEngine : public QObject
typedef QHash<QString, DataContainer*> SourceDict;
/**
* Default constructor.
* Constructor.
*
* @param parent The parent object.
* @param service pointer to the service that describes the engine
**/
explicit DataEngine(QObject* parent = 0, const QString& serviceId = QString());
explicit DataEngine(QObject* parent = 0, KService::Ptr service = KService::Ptr(0));
DataEngine(QObject* parent, const QVariantList& args);
virtual ~DataEngine();
@ -395,11 +397,6 @@ class PLASMA_EXPORT DataEngine : public QObject
**/
void removeSource(const QString& source);
/**
* @internal
**/
void startInit();
/**
* @internal
**/

View File

@ -130,7 +130,7 @@ Plasma::DataEngine* DataEngineManager::loadDataEngine(const QString& name)
if (language.isEmpty()) {
engine = offers.first()->createInstance<Plasma::DataEngine>(0, allArgs, &error);
} else {
engine = new DataEngine(0, offers.first()->storageId());
engine = new DataEngine(0, offers.first());
}
}
@ -139,9 +139,6 @@ Plasma::DataEngine* DataEngineManager::loadDataEngine(const QString& name)
return d->nullEngine();
}
engine->ref();
engine->setObjectName(offers.first()->name());
engine->setIcon(offers.first()->icon());
d->engines[name] = engine;
return engine;
}