protect usage of svg element cache config

this needs to be thoroughly checked over and tested before backporting;
seems this fixes some occassional crashes users are running into.
CCMAIL:notmart@gmail.com
This commit is contained in:
Aaron Seigo 2011-01-30 13:47:29 -08:00
parent 74b55d7ca5
commit d83bb2a72c

View File

@ -223,7 +223,7 @@ bool ThemePrivate::useCache()
// application is not running. // application is not running.
QFile f(KStandardDirs::locate("data", "desktoptheme/" + themeName + "/metadata.desktop")); QFile f(KStandardDirs::locate("data", "desktoptheme/" + themeName + "/metadata.desktop"));
QFileInfo info(f); QFileInfo info(f);
if (info.lastModified().toTime_t() > pixmapCache->lastModifiedTime()) { if (info.lastModified().toTime_t() > uint(pixmapCache->lastModifiedTime())) {
pixmapCache->clear(); pixmapCache->clear();
} }
} }
@ -280,20 +280,22 @@ void ThemePrivate::compositingChanged()
void ThemePrivate::discardCache(CacheTypes caches) void ThemePrivate::discardCache(CacheTypes caches)
{ {
if (caches & PixmapCache) { if (caches & PixmapCache) {
if (pixmapCache) { pixmapsToCache.clear();
pixmapCache->clear(); saveTimer->stop();
} if (pixmapCache) {
pixmapCache->clear();
}
} else { } else {
// This deletes the object but keeps the on-disk cache for later use // This deletes the object but keeps the on-disk cache for later use
delete pixmapCache; delete pixmapCache;
pixmapCache = 0; pixmapCache = 0;
} }
cachedStyleSheets.clear(); cachedStyleSheets.clear();
invalidElements.clear();
pixmapsToCache.clear();
saveTimer->stop();
if (caches & SvgElementsCache) { if (caches & SvgElementsCache) {
invalidElements.clear();
if (svgElementsCache) { if (svgElementsCache) {
QFile f(svgElementsCache->name()); QFile f(svgElementsCache->name());
svgElementsCache = 0; svgElementsCache = 0;
@ -465,13 +467,16 @@ Theme::Theme(const QString &themeName, QObject *parent)
Theme::~Theme() Theme::~Theme()
{ {
QHashIterator<QString, QSet<QString> > it(d->invalidElements); if (d->svgElementsCache) {
while (it.hasNext()) { QHashIterator<QString, QSet<QString> > it(d->invalidElements);
it.next(); while (it.hasNext()) {
KConfigGroup imageGroup(d->svgElementsCache, it.key()); it.next();
imageGroup.writeEntry("invalidElements", it.value().toList()); //FIXME: add QSet support to KConfig KConfigGroup imageGroup(d->svgElementsCache, it.key());
imageGroup.writeEntry("invalidElements", it.value().toList()); //FIXME: add QSet support to KConfig
}
} }
d->onAppExitCleanup();
delete d; delete d;
} }
@ -665,7 +670,6 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
discardCache(SvgElementsCache); discardCache(SvgElementsCache);
invalidElements.clear();
emit q->themeChanged(); emit q->themeChanged();
} }
@ -923,7 +927,7 @@ bool Theme::findInCache(const QString &key, QPixmap &pix)
// BIC FIXME: Should be merged with the other findInCache method above when we break BC // BIC FIXME: Should be merged with the other findInCache method above when we break BC
bool Theme::findInCache(const QString &key, QPixmap &pix, unsigned int lastModified) bool Theme::findInCache(const QString &key, QPixmap &pix, unsigned int lastModified)
{ {
if (d->useCache() && lastModified > d->pixmapCache->lastModifiedTime()) { if (d->useCache() && lastModified > uint(d->pixmapCache->lastModifiedTime())) {
return false; return false;
} }
@ -954,7 +958,7 @@ void Theme::insertIntoCache(const QString& key, const QPixmap& pix, const QStrin
bool Theme::findInRectsCache(const QString &image, const QString &element, QRectF &rect) const bool Theme::findInRectsCache(const QString &image, const QString &element, QRectF &rect) const
{ {
if (!d->pixmapCache) { if (!d->svgElementsCache) {
return false; return false;
} }
@ -987,6 +991,10 @@ bool Theme::findInRectsCache(const QString &image, const QString &element, QRect
QStringList Theme::listCachedRectKeys(const QString &image) const QStringList Theme::listCachedRectKeys(const QString &image) const
{ {
if (!d->svgElementsCache) {
return QStringList();
}
KConfigGroup imageGroup(d->svgElementsCache, image); KConfigGroup imageGroup(d->svgElementsCache, image);
QStringList keys = imageGroup.keyList(); QStringList keys = imageGroup.keyList();
@ -1006,7 +1014,7 @@ QStringList Theme::listCachedRectKeys(const QString &image) const
void Theme::insertIntoRectsCache(const QString& image, const QString &element, const QRectF &rect) void Theme::insertIntoRectsCache(const QString& image, const QString &element, const QRectF &rect)
{ {
if (!d->pixmapCache) { if (!d->svgElementsCache) {
return; return;
} }
@ -1029,18 +1037,23 @@ void Theme::insertIntoRectsCache(const QString& image, const QString &element, c
void Theme::invalidateRectsCache(const QString& image) void Theme::invalidateRectsCache(const QString& image)
{ {
KConfigGroup imageGroup(d->svgElementsCache, image); if (d->svgElementsCache) {
imageGroup.deleteGroup(); KConfigGroup imageGroup(d->svgElementsCache, image);
imageGroup.deleteGroup();
}
releaseRectsCache(image); d->invalidElements.remove(image);
} }
void Theme::releaseRectsCache(const QString &image) void Theme::releaseRectsCache(const QString &image)
{ {
QHash<QString, QSet<QString> >::iterator it = d->invalidElements.find(image); QHash<QString, QSet<QString> >::iterator it = d->invalidElements.find(image);
if (it != d->invalidElements.end()) { if (it != d->invalidElements.end()) {
KConfigGroup imageGroup(d->svgElementsCache, it.key()); if (!d->svgElementsCache) {
imageGroup.writeEntry("invalidElements", it.value().toList()); KConfigGroup imageGroup(d->svgElementsCache, it.key());
imageGroup.writeEntry("invalidElements", it.value().toList());
}
d->invalidElements.erase(it); d->invalidElements.erase(it);
} }
} }