lazy create the config loader on demand, reset when appropriate

This commit is contained in:
Aaron Seigo 2013-02-26 14:48:39 +01:00
parent 7ab77c4e6d
commit 9478edaa05
2 changed files with 16 additions and 11 deletions

View File

@ -277,6 +277,18 @@ bool Applet::destroyed() const
ConfigLoader *Applet::configScheme() const
{
if (!d->configLoader) {
const QString xmlPath = d->package? d->package->filePath("mainconfigxml") : QString();
KConfigGroup cfg = config();
if (xmlPath.isEmpty()) {
d->configLoader = new ConfigLoader(&cfg, 0);
} else {
QFile file(xmlPath);
d->configLoader = new ConfigLoader(&cfg, &file);
QObject::connect(d->configLoader, SIGNAL(configChanged()), this, SLOT(propagateConfigChanged()));
}
}
return d->configLoader;
}
@ -669,7 +681,7 @@ void Applet::showConfigurationInterface()
KDesktopFile df(d->package->path() + "/metadata.desktop");
const QStringList kcmPlugins = df.desktopGroup().readEntry("X-Plasma-ConfigPlugins", QStringList());
if (!uiFile.isEmpty() || !kcmPlugins.isEmpty()) {
KConfigSkeleton *configLoader = d->configLoader ? d->configLoader : new KConfigSkeleton(0);
KConfigSkeleton *configLoader = configScheme() ? d->configLoader : new KConfigSkeleton(0);
dialog = new AppletConfigDialog(0, d->configDialogId(), configLoader);
if (!d->configLoader) {

View File

@ -356,8 +356,6 @@ void AppletPrivate::setIsContainment(bool nowIsContainment, bool forceUpdate)
void AppletPrivate::setupPackage()
{
if (!package) {
delete configLoader;
configLoader = 0;
return;
}
@ -372,14 +370,6 @@ void AppletPrivate::setupPackage()
KLocalizedString::insertCatalog(appletDescription.pluginName());
}
const QString xmlPath = package->filePath("mainconfigxml");
if (!xmlPath.isEmpty()) {
QFile file(xmlPath);
KConfigGroup config = q->config();
configLoader = new ConfigLoader(&config, &file);
QObject::connect(configLoader, SIGNAL(configChanged()), q, SLOT(propagateConfigChanged()));
}
if (!package->filePath("mainconfigui").isEmpty()) {
q->setHasConfigurationInterface(true);
}
@ -462,6 +452,9 @@ KConfigGroup *AppletPrivate::mainConfigGroup()
mainConfig = new KConfigGroup(&appletConfig, QString::number(appletId));
}
if (configLoader) {
configLoader->setSharedConfig(KSharedConfig::openConfig(mainConfig->config()->name()));
}
return mainConfig;
}