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
This commit is contained in:
Aaron J. Seigo 2009-08-02 18:24:20 +00:00
parent bb659e280c
commit b684273624
2 changed files with 24 additions and 1 deletions

View File

@ -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<QGraphicsWidget*>(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<QWidget *, QString> associatedWidgets;
QMultiHash<QGraphicsWidget *, QString> associatedGraphicsWidgets;

View File

@ -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;