From 30dc3caf9b42d42060375a67542b20340862aad1 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 20 Oct 2009 19:15:32 +0000 Subject: [PATCH] * move remotedataengine.h to remotedataengine_p.h as it's private * allow queueing for un-ready remote services * always double check that the RemoteServiceJob is really Ok to send; things like operation being ready may have changed, for instance svn path=/trunk/KDE/kdelibs/; revision=1038181 --- applet.cpp | 4 +- private/dataengineconsumer.cpp | 2 +- private/dataengineconsumer_p.h | 2 +- private/remotedataengine.cpp | 4 +- ...emotedataengine.h => remotedataengine_p.h} | 0 private/remoteservicejob.cpp | 25 +++++++++- private/remoteservicejob_p.h | 5 ++ service.cpp | 47 ++++++++++++++----- service.h | 8 ++++ servicejob.h | 1 + 10 files changed, 79 insertions(+), 19 deletions(-) rename private/{remotedataengine.h => remotedataengine_p.h} (100%) diff --git a/applet.cpp b/applet.cpp index 054c9d9c8..a321278b0 100644 --- a/applet.cpp +++ b/applet.cpp @@ -93,6 +93,7 @@ #include "wallpaper.h" #include "paintutils.h" +#include "private/associatedapplicationmanager_p.h" #include "private/authorizationmanager_p.h" #include "private/containment_p.h" #include "private/extenderapplet_p.h" @@ -100,10 +101,9 @@ #include "private/packages_p.h" #include "private/plasmoidservice.h" #include "private/popupapplet_p.h" +#include "private/remotedataengine_p.h" #include "private/service_p.h" -#include "private/remotedataengine.h" #include "private/internaltoolbox_p.h" -#include "private/associatedapplicationmanager_p.h" #include "ui_publish.h" #include "config-plasma.h" diff --git a/private/dataengineconsumer.cpp b/private/dataengineconsumer.cpp index 0a6faa90c..d6b937eaa 100644 --- a/private/dataengineconsumer.cpp +++ b/private/dataengineconsumer.cpp @@ -26,7 +26,7 @@ #include #include "plasma/dataenginemanager.h" -#include "plasma/private/remotedataengine.h" +#include "plasma/private/remotedataengine_p.h" #include namespace Plasma diff --git a/private/dataengineconsumer_p.h b/private/dataengineconsumer_p.h index 37f09c240..d3c7808c3 100644 --- a/private/dataengineconsumer_p.h +++ b/private/dataengineconsumer_p.h @@ -27,13 +27,13 @@ #include #include "plasma/dataenginemanager.h" -#include "plasma/private/remotedataengine.h" #include namespace Plasma { class DataEngineConsumer; +class RemoteDataEngine; class ServiceMonitor : public QObject { diff --git a/private/remotedataengine.cpp b/private/remotedataengine.cpp index fcbcfc18b..e3e7ff303 100644 --- a/private/remotedataengine.cpp +++ b/private/remotedataengine.cpp @@ -16,7 +16,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "remotedataengine.h" +#include "remotedataengine_p.h" #include "remoteservice_p.h" @@ -232,5 +232,5 @@ void RemoteDataEngine::updateSources() } -#include "remotedataengine.moc" +#include "remotedataengine_p.moc" diff --git a/private/remotedataengine.h b/private/remotedataengine_p.h similarity index 100% rename from private/remotedataengine.h rename to private/remotedataengine_p.h diff --git a/private/remoteservicejob.cpp b/private/remoteservicejob.cpp index eccd0a5f1..78605569c 100644 --- a/private/remoteservicejob.cpp +++ b/private/remoteservicejob.cpp @@ -18,6 +18,7 @@ #include "remoteservicejob_p.h" +#include #include #include @@ -31,6 +32,7 @@ #include "../remote/authorizationmanager.h" #include "authorizationmanager_p.h" #include "remoteservice_p.h" +#include "servicejob_p.h" #include "joliemessagehelper_p.h" #include @@ -46,10 +48,17 @@ RemoteServiceJob::RemoteServiceJob(KUrl location, : ServiceJob(destination, operation, parameters, parent), m_token(initialToken), m_location(location), - m_service(parent) + m_service(parent), + m_delayedDesc(0) { } +RemoteServiceJob::~RemoteServiceJob() +{ + delete m_delayedDesc; + m_delayedDesc = 0; +} + void RemoteServiceJob::start() { QTimer::singleShot(30000, this, SLOT(timeout())); @@ -94,11 +103,22 @@ void RemoteServiceJob::start() this, SLOT(callCompleted(Jolie::PendingCallWatcher*))); } +void RemoteServiceJob::setDelayedDescription(const KConfigGroup &desc) +{ + if (!m_delayedDesc) { + m_delayedDesc = new KConfigGroup(desc); + } else { + *m_delayedDesc = desc; + } +} + void RemoteServiceJob::checkValidity() { if (!m_service->isOperationEnabled(operationName())) { setError(-1); setErrorText(i18n("Job no longer valid, operation is not enabled!")); + } else if (m_delayedDesc) { + d->parameters = m_service->parametersFromDescription(*m_delayedDesc); } else { KConfigGroup description = m_service->operationDescription(operationName()); QMapIterator param(parameters()); @@ -111,6 +131,9 @@ void RemoteServiceJob::checkValidity() } } } + + delete m_delayedDesc; + m_delayedDesc = 0; } void RemoteServiceJob::callCompleted(Jolie::PendingCallWatcher *watcher) diff --git a/private/remoteservicejob_p.h b/private/remoteservicejob_p.h index 8535a6c5f..7baad6fcf 100644 --- a/private/remoteservicejob_p.h +++ b/private/remoteservicejob_p.h @@ -24,6 +24,8 @@ #include "../servicejob.h" +class KConfigGroup; + namespace Jolie { class PendingCallWatcher; @@ -45,8 +47,10 @@ class RemoteServiceJob : public Plasma::ServiceJob QMap& parameters, QByteArray initialToken, RemoteService *parent); + ~RemoteServiceJob(); void start(); + void setDelayedDescription(const KConfigGroup &desc); private Q_SLOTS: void callCompleted(Jolie::PendingCallWatcher *watcher); @@ -58,6 +62,7 @@ class RemoteServiceJob : public Plasma::ServiceJob QByteArray m_token; KUrl m_location; RemoteService *m_service; + KConfigGroup *m_delayedDesc; }; } // namespace Plasma diff --git a/service.cpp b/service.cpp index bd8fd1304..4eb38e1d6 100644 --- a/service.cpp +++ b/service.cpp @@ -19,7 +19,6 @@ #include "service.h" #include "private/authorizationmanager_p.h" -#include "private/remoteservice_p.h" #include "private/service_p.h" #include "private/serviceprovider_p.h" @@ -40,6 +39,8 @@ #include "configloader.h" #include "version.h" #include "private/configloader_p.h" +#include "private/remoteservice_p.h" +#include "private/remoteservicejob_p.h" namespace Plasma { @@ -224,27 +225,49 @@ KConfigGroup Service::operationDescription(const QString &operationName) return params; } +QMap Service::parametersFromDescription(const KConfigGroup &description) +{ + QMap params; + + if (!d->config || !description.isValid()) { + return params; + } + + const QString op = description.name(); + foreach (const QString &key, description.keyList()) { + KConfigSkeletonItem *item = d->config->findItem(op, key); + if (item) { + params.insert(key, description.readEntry(key, item->property())); + } + } + + return params; +} + ServiceJob *Service::startOperationCall(const KConfigGroup &description, QObject *parent) { // TODO: nested groups? ServiceJob *job = 0; - QString op = description.isValid() ? description.name() : QString(); + const QString op = description.isValid() ? description.name() : QString(); - if (!d->config) { + RemoteService *rs = qobject_cast(this); + if (!op.isEmpty() && rs && !rs->isReady()) { + // if we have an operation, but a non-ready remote service, just let it through + kDebug() << "Remote service is not ready; queueing operation"; + QMap params; + job = createJob(op, params); + RemoteServiceJob *rsj = qobject_cast(job); + if (rsj) { + rsj->setDelayedDescription(description); + } + } else if (!d->config) { kDebug() << "No valid operations scheme has been registered"; } else if (!op.isEmpty() && d->config->hasGroup(op)) { if (d->disabledOperations.contains(op)) { kDebug() << "Operation" << op << "is disabled"; } else { - QMap params; - foreach (const QString &key, description.keyList()) { - KConfigSkeletonItem *item = d->config->findItem(op, key); - if (item) { - params.insert(key, description.readEntry(key, item->property())); - } - } - - job = createJob(description.name(), params); + QMap params = parametersFromDescription(description); + job = createJob(op, params); } } else { kDebug() << "Not a valid group!"; diff --git a/service.h b/service.h index 7bb91bf65..2beceb620 100644 --- a/service.h +++ b/service.h @@ -192,6 +192,13 @@ public: */ Q_INVOKABLE void disassociateWidget(QGraphicsWidget *widget); + /** + * @return a parameter map for the given description + * @arg description the configuration values to turn into the parameter map + * @since 4.4 + */ + Q_INVOKABLE QMap parametersFromDescription(const KConfigGroup &description); + Q_SIGNALS: /** * Emitted when a job associated with this Service completes its task @@ -275,6 +282,7 @@ private: friend class GetSource; friend class PackagePrivate; friend class ServiceProvider; + friend class RemoveService; }; } // namespace Plasma diff --git a/servicejob.h b/servicejob.h index 268b0cfd2..e8f752ffa 100644 --- a/servicejob.h +++ b/servicejob.h @@ -123,6 +123,7 @@ private: ServiceJobPrivate * const d; friend class ServiceProvider; + friend class RemoteServiceJob; }; } // namespace Plasma