From 507a6f02a03808555455b3e024c5baf8f0cece1d Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Mon, 25 Feb 2008 11:24:37 +0000 Subject: [PATCH] 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 --- dataengine.cpp | 39 +++++++++++++++++---------------------- dataengine.h | 13 +++++-------- dataenginemanager.cpp | 5 +---- 3 files changed, 23 insertions(+), 34 deletions(-) diff --git a/dataengine.cpp b/dataengine.cpp index d93c5a0d0..db912dd41 100644 --- a/dataengine.cpp +++ b/dataengine.cpp @@ -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; } } diff --git a/dataengine.h b/dataengine.h index 2132529b5..786cdffe8 100644 --- a/dataengine.h +++ b/dataengine.h @@ -24,7 +24,8 @@ #include #include -#include +#include +#include #include #include @@ -64,11 +65,12 @@ class PLASMA_EXPORT DataEngine : public QObject typedef QHash 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 **/ diff --git a/dataenginemanager.cpp b/dataenginemanager.cpp index e200d6e27..02ad0d634 100644 --- a/dataenginemanager.cpp +++ b/dataenginemanager.cpp @@ -130,7 +130,7 @@ Plasma::DataEngine* DataEngineManager::loadDataEngine(const QString& name) if (language.isEmpty()) { engine = offers.first()->createInstance(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; }