From b684273624b8317ea665c598f0aa6193670ad363 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Sun, 2 Aug 2009 18:24:20 +0000 Subject: [PATCH] return a dummy group when we have no description set up; prevents crashes when the operations file is not available BUG:200475 svn path=/trunk/KDE/kdelibs/; revision=1005964 --- private/service_p.h | 17 +++++++++++++++++ service.cpp | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/private/service_p.h b/private/service_p.h index c345f2ac7..8145cbe5e 100644 --- a/private/service_p.h +++ b/private/service_p.h @@ -73,6 +73,7 @@ public: ServicePrivate(Service *service) : q(service), config(0), + dummyConfig(0), tempFile(0) { } @@ -80,6 +81,7 @@ public: ~ServicePrivate() { delete config; + delete dummyConfig; delete tempFile; } @@ -98,10 +100,25 @@ public: associatedGraphicsWidgets.remove(static_cast(obj)); } + KConfigGroup dummyGroup() + { + if (!dummyConfig) { + if (!tempFile) { + tempFile = new KTemporaryFile; + tempFile->open(); + } + + dummyConfig = new KConfig(tempFile->fileName()); + } + + return KConfigGroup(dummyConfig, "DummyGroup"); + } + Service *q; QString destination; QString name; ConfigLoader *config; + KConfig *dummyConfig; KTemporaryFile *tempFile; QMultiHash associatedWidgets; QMultiHash associatedGraphicsWidgets; diff --git a/service.cpp b/service.cpp index fc96913f8..f23e26ed5 100644 --- a/service.cpp +++ b/service.cpp @@ -116,7 +116,7 @@ KConfigGroup Service::operationDescription(const QString &operationName) { if (!d->config) { kDebug() << "No valid operations scheme has been registered"; - return KConfigGroup(); + return d->dummyGroup(); } d->config->writeConfig(); @@ -212,6 +212,9 @@ void Service::setName(const QString &name) delete d->tempFile; d->tempFile = 0; + delete d->dummyConfig; + d->dummyConfig = 0; + registerOperationsScheme(); } @@ -258,6 +261,9 @@ void Service::setOperationsScheme(QIODevice *xml) delete d->config; delete d->tempFile; + delete d->dummyConfig; + d->dummyConfig = 0; + //FIXME: make KSharedConfig and KConfigSkeleton not braindamaged in 4.2 and then get rid of the // temp file object here d->tempFile = new KTemporaryFile;