try harder to avoid creating svg renderers
now is actually possible to obtain a startup with zero svg renderers * svg::isValid will create a renderer only if really nevessary * the rects cache is ensured to be written on disk * fixed the check on the theme metadata age * rect cache is shared between all applications
This commit is contained in:
parent
9d9c72630c
commit
0b10a16113
@ -173,7 +173,7 @@ bool ThemePrivate::useCache()
|
||||
}
|
||||
|
||||
// now we check for, and remove if necessary, old caches
|
||||
foreach (const QString &file, QStandardPaths::locateAll(QStandardPaths::CacheLocation, cacheFileBase)) {
|
||||
foreach (const QString &file, QStandardPaths::locateAll(QStandardPaths::GenericCacheLocation, cacheFileBase)) {
|
||||
if (currentCacheFileName.isEmpty() ||
|
||||
!file.endsWith(currentCacheFileName)) {
|
||||
QFile::remove(file);
|
||||
@ -192,11 +192,11 @@ bool ThemePrivate::useCache()
|
||||
// the cache should be dropped; we need a way to detect system color change when the
|
||||
// application is not running.
|
||||
// check for expired cache
|
||||
const QString cacheFilePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + '/' + cacheFile;
|
||||
const QString cacheFilePath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + '/' + cacheFile + ".kcache";
|
||||
if (!cacheFilePath.isEmpty()) {
|
||||
const QFileInfo cacheFileInfo(cacheFilePath);
|
||||
const QFileInfo metadataFileInfo(themeMetadataPath);
|
||||
cachesTooOld = cacheFileInfo.lastModified().toTime_t() > metadataFileInfo.lastModified().toTime_t();
|
||||
cachesTooOld = cacheFileInfo.lastModified().toTime_t() < metadataFileInfo.lastModified().toTime_t();
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,13 +216,13 @@ bool ThemePrivate::useCache()
|
||||
}
|
||||
|
||||
// now we check for (and remove) old caches
|
||||
foreach (const QString &file, QStandardPaths::locateAll(QStandardPaths::CacheLocation, svgElementsFileNameBase + QLatin1Char('*'))) {
|
||||
foreach (const QString &file, QStandardPaths::locateAll(QStandardPaths::GenericCacheLocation, svgElementsFileNameBase + QLatin1Char('*'))) {
|
||||
if (cachesTooOld || !file.endsWith(svgElementsFileName)) {
|
||||
QFile::remove(file);
|
||||
}
|
||||
}
|
||||
|
||||
const QString svgElementsFile = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + '/' + svgElementsFileName;
|
||||
const QString svgElementsFile = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + '/' + svgElementsFileName;
|
||||
svgElementsCache = KSharedConfig::openConfig(svgElementsFile);
|
||||
}
|
||||
|
||||
@ -668,8 +668,9 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
|
||||
cg.sync();
|
||||
}
|
||||
|
||||
if(emitChanged)
|
||||
if(emitChanged) {
|
||||
scheduleThemeChangeNotification(SvgElementsCache);
|
||||
}
|
||||
}
|
||||
|
||||
bool ThemePrivate::eventFilter(QObject *watched, QEvent *event)
|
||||
|
@ -204,7 +204,8 @@ bool SvgPrivate::setImagePath(const QString &imagePath)
|
||||
|
||||
if (themed) {
|
||||
themePath = actualPath;
|
||||
themeFailed = false;
|
||||
path = actualTheme()->imagePath(themePath);
|
||||
themeFailed = path.isEmpty();
|
||||
QObject::connect(actualTheme(), SIGNAL(themeChanged()), q, SLOT(themeChanged()));
|
||||
} else if (QFile::exists(actualPath)) {
|
||||
QObject::connect(cacheAndColorsTheme(), SIGNAL(themeChanged()), q, SLOT(themeChanged()), Qt::UniqueConnection);
|
||||
@ -220,8 +221,9 @@ bool SvgPrivate::setImagePath(const QString &imagePath)
|
||||
|
||||
// also images with absolute path needs to have a natural size initialized,
|
||||
// even if looks a bit weird using Theme to store non-themed stuff
|
||||
if (themed || QFile::exists(actualPath)) {
|
||||
if ((themed && QFile::exists(path)) || QFile::exists(actualPath)) {
|
||||
QRectF rect;
|
||||
|
||||
if (cacheAndColorsTheme()->findInRectsCache(path, "_Natural", rect)) {
|
||||
naturalSize = rect.size();
|
||||
} else {
|
||||
@ -482,6 +484,10 @@ QRectF SvgPrivate::elementRect(const QString &elementId)
|
||||
}
|
||||
}
|
||||
|
||||
if (path.isEmpty()) {
|
||||
return QRectF();
|
||||
}
|
||||
|
||||
QString id = cacheId(elementId);
|
||||
|
||||
if (localRectCache.contains(id)) {
|
||||
@ -489,7 +495,12 @@ QRectF SvgPrivate::elementRect(const QString &elementId)
|
||||
}
|
||||
|
||||
QRectF rect;
|
||||
if (cacheAndColorsTheme()->findInRectsCache(path, id, rect)) {
|
||||
bool found = cacheAndColorsTheme()->findInRectsCache(path, id, rect);
|
||||
|
||||
//This is a corner case where we are *sure* the element is not valid
|
||||
if (found && rect == QRectF()) {
|
||||
return rect;
|
||||
} else if (found) {
|
||||
localRectCache.insert(id, rect);
|
||||
} else {
|
||||
rect = findAndCacheElementRect(elementId);
|
||||
@ -519,6 +530,7 @@ QRectF SvgPrivate::findAndCacheElementRect(const QString &elementId)
|
||||
elementRect.width() * dx * devicePixelRatio, elementRect.height() * dy * devicePixelRatio);
|
||||
|
||||
cacheAndColorsTheme()->insertIntoRectsCache(path, id, elementRect);
|
||||
|
||||
return elementRect;
|
||||
}
|
||||
|
||||
@ -780,6 +792,16 @@ bool Svg::isValid() const
|
||||
return false;
|
||||
}
|
||||
|
||||
//try very hard to avoid creation of a parser
|
||||
QRectF rect;
|
||||
if (d->cacheAndColorsTheme()->findInRectsCache(d->path, "_Natural", rect)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!QFile::exists(d->path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
d->createRenderer();
|
||||
return d->renderer->isValid();
|
||||
}
|
||||
|
@ -98,6 +98,9 @@ Theme::~Theme()
|
||||
KConfigGroup imageGroup(d->svgElementsCache, it.key());
|
||||
imageGroup.writeEntry("invalidElements", it.value().toList()); //FIXME: add QSet support to KConfig
|
||||
}
|
||||
|
||||
//The application is probably dying, last occasion to write to disk
|
||||
d->svgElementsCache->sync();
|
||||
}
|
||||
|
||||
if (d == ThemePrivate::globalTheme) {
|
||||
|
Loading…
Reference in New Issue
Block a user