port improve cache file dropping to plasma-framework
this ports revision c03052935b082 on kdelibs improve cache file dropping * fix regression: version the image cache file name * version the svg elements * drop old svg elements files * respond to changes at runtime by watching the theme's metadata.desktop for changes * move creation of the svg elements file into ThemePrivate::useCache() REVIEW:115397
This commit is contained in:
parent
3647ee36ef
commit
517403096d
@ -129,22 +129,46 @@ KConfigGroup &ThemePrivate::config()
|
|||||||
|
|
||||||
bool ThemePrivate::useCache()
|
bool ThemePrivate::useCache()
|
||||||
{
|
{
|
||||||
|
bool cachesTooOld = false;
|
||||||
|
|
||||||
if (cacheTheme && !pixmapCache) {
|
if (cacheTheme && !pixmapCache) {
|
||||||
if (cacheSize == 0) {
|
if (cacheSize == 0) {
|
||||||
ThemeConfig config;
|
ThemeConfig config;
|
||||||
cacheSize = config.themeCacheKb();
|
cacheSize = config.themeCacheKb();
|
||||||
}
|
}
|
||||||
const bool isRegularTheme = themeName != systemColorsTheme;
|
const bool isRegularTheme = themeName != systemColorsTheme;
|
||||||
const QString cacheFile = "plasma_theme_" + themeName;
|
QString cacheFile = "plasma_theme_" + themeName;
|
||||||
|
|
||||||
|
// clear any cached values from the previous theme cache
|
||||||
|
themeVersion.clear();
|
||||||
|
|
||||||
|
if (!themeMetadataPath.isEmpty()) {
|
||||||
|
KDirWatch::self()->removeFile(themeMetadataPath);
|
||||||
|
}
|
||||||
|
themeMetadataPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1Literal("desktoptheme/") % themeName % QLatin1Literal("/metadata.desktop"));
|
||||||
|
|
||||||
|
|
||||||
if (isRegularTheme) {
|
if (isRegularTheme) {
|
||||||
const QString cacheFileBase = cacheFile + "*.kcache";
|
const QString cacheFileBase = cacheFile + "*.kcache";
|
||||||
|
|
||||||
const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "desktoptheme/" + themeName + "/metadata.desktop");
|
|
||||||
QString currentCacheFileName;
|
QString currentCacheFileName;
|
||||||
if (!path.isEmpty()) {
|
if (!themeMetadataPath.isEmpty()) {
|
||||||
const KPluginInfo pluginInfo(path);
|
// now we record the theme version, if we can
|
||||||
currentCacheFileName = cacheFile + "_v" + pluginInfo.version() + ".kcache";
|
const KPluginInfo pluginInfo(themeMetadataPath);
|
||||||
|
themeVersion = pluginInfo.version();
|
||||||
|
if (!themeVersion.isEmpty()) {
|
||||||
|
cacheFile += "_v" + themeVersion;
|
||||||
|
currentCacheFileName = cacheFile + ".kcache";
|
||||||
|
}
|
||||||
|
|
||||||
|
// watch the metadata file for changes at runtime
|
||||||
|
KDirWatch::self()->addFile(themeMetadataPath);
|
||||||
|
QObject::connect(KDirWatch::self(), SIGNAL(created(QString)),
|
||||||
|
this, SLOT(settingsFileChanged(QString)),
|
||||||
|
Qt::UniqueConnection);
|
||||||
|
QObject::connect(KDirWatch::self(), SIGNAL(dirty(QString)),
|
||||||
|
this, SLOT(settingsFileChanged(QString)),
|
||||||
|
Qt::UniqueConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// now we check for, and remove if necessary, old caches
|
// now we check for, and remove if necessary, old caches
|
||||||
@ -157,19 +181,48 @@ bool ThemePrivate::useCache()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pixmapCache = new KImageCache(cacheFile, cacheSize * 1024);
|
// now we do a sanity check: if the metadata.desktop file is newer than the cache, drop the cache
|
||||||
// now we do a sanity check: if the metadata.desktop file is newer than the cache, drop
|
if (isRegularTheme && !themeMetadataPath.isEmpty()) {
|
||||||
// the cache
|
// now we check to see if the theme metadata file itself is newer than the pixmap cache
|
||||||
if (isRegularTheme) {
|
// this is done before creating the pixmapCache object since that can change the mtime
|
||||||
|
// on the cache file
|
||||||
|
|
||||||
// FIXME: when using the system colors, if they change while the application is not running
|
// FIXME: when using the system colors, if they change while the application is not running
|
||||||
// the cache should be dropped; we need a way to detect system color change when the
|
// the cache should be dropped; we need a way to detect system color change when the
|
||||||
// application is not running.
|
// application is not running.
|
||||||
const QFile f(cacheFile);
|
// check for expired cache
|
||||||
const QFileInfo fileInfo(f);
|
const QString cacheFilePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + '/' + cacheFile;
|
||||||
if (fileInfo.lastModified().toTime_t() > uint(pixmapCache->lastModifiedTime().toTime_t())) {
|
if (!cacheFilePath.isEmpty()) {
|
||||||
discardCache(PixmapCache | SvgElementsCache);
|
const QFileInfo cacheFileInfo(cacheFilePath);
|
||||||
|
const QFileInfo metadataFileInfo(themeMetadataPath);
|
||||||
|
cachesTooOld = cacheFileInfo.lastModified().toTime_t() > metadataFileInfo.lastModified().toTime_t();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ThemeConfig config;
|
||||||
|
pixmapCache = new KImageCache(cacheFile, config.themeCacheKb() * 1024);
|
||||||
|
|
||||||
|
if (cachesTooOld) {
|
||||||
|
discardCache(PixmapCache | SvgElementsCache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cacheTheme && !svgElementsCache) {
|
||||||
|
const QString svgElementsFileNameBase = "plasma-svgelements-" + themeName;
|
||||||
|
QString svgElementsFileName = svgElementsFileNameBase;
|
||||||
|
if (!themeVersion.isEmpty()) {
|
||||||
|
svgElementsFileName += "_v" + themeVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now we check for (and remove) old caches
|
||||||
|
foreach (const QString &file, QStandardPaths::locateAll(QStandardPaths::CacheLocation, svgElementsFileNameBase + "*")) {
|
||||||
|
if (cachesTooOld || !file.endsWith(svgElementsFileName)) {
|
||||||
|
QFile::remove(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString svgElementsFile = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + '/' + svgElementsFileName;
|
||||||
|
svgElementsCache = KSharedConfig::openConfig(svgElementsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cacheTheme;
|
return cacheTheme;
|
||||||
@ -246,14 +299,7 @@ void ThemePrivate::discardCache(CacheTypes caches)
|
|||||||
discoveries.clear();
|
discoveries.clear();
|
||||||
invalidElements.clear();
|
invalidElements.clear();
|
||||||
|
|
||||||
if (svgElementsCache) {
|
svgElementsCache = 0;
|
||||||
QFile f(svgElementsCache->name());
|
|
||||||
svgElementsCache = 0;
|
|
||||||
f.remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
const QString svgElementsFile = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1Char('/') + "plasma-svgelements-" + themeName;
|
|
||||||
svgElementsCache = KSharedConfig::openConfig(svgElementsFile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +434,12 @@ const QString ThemePrivate::svgStyleSheet()
|
|||||||
void ThemePrivate::settingsFileChanged(const QString &file)
|
void ThemePrivate::settingsFileChanged(const QString &file)
|
||||||
{
|
{
|
||||||
qDebug() << "settingsFile: " << file;
|
qDebug() << "settingsFile: " << file;
|
||||||
if (file.endsWith(themeRcFile)) {
|
if (file == themeMetadataPath) {
|
||||||
|
const KPluginInfo pluginInfo(themeMetadataPath);
|
||||||
|
if (themeVersion != pluginInfo.version()) {
|
||||||
|
scheduleThemeChangeNotification(SvgElementsCache);
|
||||||
|
}
|
||||||
|
} else if (file.endsWith(themeRcFile)) {
|
||||||
config().config()->reparseConfiguration();
|
config().config()->reparseConfiguration();
|
||||||
settingsChanged();
|
settingsChanged();
|
||||||
}
|
}
|
||||||
|
@ -135,6 +135,8 @@ public:
|
|||||||
QTimer *updateNotificationTimer;
|
QTimer *updateNotificationTimer;
|
||||||
unsigned cacheSize;
|
unsigned cacheSize;
|
||||||
CacheTypes cachesToDiscard;
|
CacheTypes cachesToDiscard;
|
||||||
|
QString themeVersion;
|
||||||
|
QString themeMetadataPath;
|
||||||
|
|
||||||
bool locolor : 1;
|
bool locolor : 1;
|
||||||
bool compositingActive : 1;
|
bool compositingActive : 1;
|
||||||
|
@ -348,7 +348,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->svgElementsCache) {
|
if (!d->useCache()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,7 +381,7 @@ 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) {
|
if (!d->useCache()) {
|
||||||
return QStringList();
|
return QStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,7 +404,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->svgElementsCache) {
|
if (!d->useCache()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,7 +427,7 @@ void Theme::insertIntoRectsCache(const QString& image, const QString &element, c
|
|||||||
|
|
||||||
void Theme::invalidateRectsCache(const QString& image)
|
void Theme::invalidateRectsCache(const QString& image)
|
||||||
{
|
{
|
||||||
if (d->svgElementsCache) {
|
if (d->useCache()) {
|
||||||
KConfigGroup imageGroup(d->svgElementsCache, image);
|
KConfigGroup imageGroup(d->svgElementsCache, image);
|
||||||
imageGroup.deleteGroup();
|
imageGroup.deleteGroup();
|
||||||
}
|
}
|
||||||
@ -439,7 +439,7 @@ 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()) {
|
||||||
if (!d->svgElementsCache) {
|
if (d->useCache()) {
|
||||||
KConfigGroup imageGroup(d->svgElementsCache, it.key());
|
KConfigGroup imageGroup(d->svgElementsCache, it.key());
|
||||||
imageGroup.writeEntry("invalidElements", it.value().toList());
|
imageGroup.writeEntry("invalidElements", it.value().toList());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user