Use correct on-disk pixmap cache

svn path=/trunk/KDE/kdelibs/; revision=1206190
This commit is contained in:
Manuel Mommertz 2010-12-13 20:14:52 +00:00
parent e04e91e9ad
commit 0594bd9d85

View File

@ -62,6 +62,14 @@ enum styles {
SVGSTYLE SVGSTYLE
}; };
enum CacheType {
NoCache = 0,
PixmapCache = 1,
SvgElementsCache = 2
};
Q_DECLARE_FLAGS(CacheTypes, CacheType)
Q_DECLARE_OPERATORS_FOR_FLAGS(CacheTypes)
class ThemePrivate class ThemePrivate
{ {
public: public:
@ -132,7 +140,7 @@ public:
QString findInTheme(const QString &image, const QString &theme) const; QString findInTheme(const QString &image, const QString &theme) const;
void compositingChanged(); void compositingChanged();
void discardCache(const QString &oldThemeName = QString(), bool keepSvgElementsCache = false); void discardCache(CacheTypes caches);
void scheduledCacheUpdate(); void scheduledCacheUpdate();
void colorsChanged(); void colorsChanged();
bool useCache(); bool useCache();
@ -196,6 +204,17 @@ bool ThemePrivate::useCache()
if (cacheTheme && !pixmapCache) { if (cacheTheme && !pixmapCache) {
ThemeConfig config; ThemeConfig config;
pixmapCache = new KImageCache("plasma_theme_" + themeName, config.themeCacheKb() * 1024); pixmapCache = new KImageCache("plasma_theme_" + themeName, config.themeCacheKb() * 1024);
if (themeName != systemColorsTheme) {
//check for expired cache
// 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
// application is not running.
QFile f(KStandardDirs::locate("data", "desktoptheme/" + themeName + "/metadata.desktop"));
QFileInfo info(f);
if (info.lastModified().toTime_t() > pixmapCache->lastModifiedTime()) {
pixmapCache->clear();
}
}
} }
return cacheTheme; return cacheTheme;
@ -241,40 +260,38 @@ void ThemePrivate::compositingChanged()
if (compositingActive != nowCompositingActive) { if (compositingActive != nowCompositingActive) {
compositingActive = nowCompositingActive; compositingActive = nowCompositingActive;
discardCache(); discardCache(PixmapCache | SvgElementsCache);
emit q->themeChanged(); emit q->themeChanged();
} }
#endif #endif
} }
void ThemePrivate::discardCache(const QString &oldThemeName, bool keepSvgElementsCache) void ThemePrivate::discardCache(CacheTypes caches)
{ {
if (oldThemeName.isEmpty()) { if (caches & PixmapCache) {
if (pixmapCache) { if (pixmapCache) {
pixmapCache->clear(); pixmapCache->clear();
} }
} else { } else {
// This deletes the object but keeps the on-disk cache for later use
delete pixmapCache; delete pixmapCache;
pixmapCache = 0; pixmapCache = 0;
KSharedDataCache::deleteCache("plasma_theme_" + oldThemeName);
} }
cachedStyleSheets.clear(); cachedStyleSheets.clear();
invalidElements.clear(); invalidElements.clear();
pixmapsToCache.clear(); pixmapsToCache.clear();
saveTimer->stop(); saveTimer->stop();
if (keepSvgElementsCache) { if (caches & SvgElementsCache) {
return; if (svgElementsCache) {
} QFile f(svgElementsCache->name());
svgElementsCache = 0;
f.remove();
}
if (svgElementsCache) { const QString svgElementsFile = KStandardDirs::locateLocal("cache", "plasma-svgelements-" + themeName);
QFile f(svgElementsCache->name()); svgElementsCache = KSharedConfig::openConfig(svgElementsFile);
svgElementsCache = 0;
f.remove();
} }
const QString svgElementsFile = KStandardDirs::locateLocal("cache", "plasma-svgelements-" + themeName);
svgElementsCache = KSharedConfig::openConfig(svgElementsFile);
} }
void ThemePrivate::scheduledCacheUpdate() void ThemePrivate::scheduledCacheUpdate()
@ -292,7 +309,7 @@ void ThemePrivate::scheduledCacheUpdate()
void ThemePrivate::colorsChanged() void ThemePrivate::colorsChanged()
{ {
discardCache(QString(), true); discardCache(PixmapCache);
colorScheme = KColorScheme(QPalette::Active, KColorScheme::Window, colors); colorScheme = KColorScheme(QPalette::Active, KColorScheme::Window, colors);
buttonColorScheme = KColorScheme(QPalette::Active, KColorScheme::Button, colors); buttonColorScheme = KColorScheme(QPalette::Active, KColorScheme::Button, colors);
viewColorScheme = KColorScheme(QPalette::Active, KColorScheme::View, colors); viewColorScheme = KColorScheme(QPalette::Active, KColorScheme::View, colors);
@ -553,8 +570,6 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
return; return;
} }
const QString oldThemeName = themeName;
themeName = theme; themeName = theme;
// load the color scheme config // load the color scheme config
@ -562,7 +577,6 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
: QString(); : QString();
//kDebug() << "we're going for..." << colorsFile << "*******************"; //kDebug() << "we're going for..." << colorsFile << "*******************";
bool expireCache = false;
// load the wallpaper settings, if any // load the wallpaper settings, if any
if (realTheme) { if (realTheme) {
@ -603,17 +617,6 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
processAnimationSettings(theme, &metadata); processAnimationSettings(theme, &metadata);
processWallpaperSettings(&metadata); processWallpaperSettings(&metadata);
} }
//check for expired cache
// 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
// application is not running.
QFile f(metadataPath);
QFileInfo info(f);
if (useCache() && info.lastModified().toTime_t() > pixmapCache->lastModifiedTime()) {
expireCache = true;
}
} }
if (colorsFile.isEmpty()) { if (colorsFile.isEmpty()) {
@ -642,12 +645,7 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
cg.sync(); cg.sync();
} }
if (expireCache) { discardCache(SvgElementsCache);
discardCache(oldThemeName);
} else {
QString svgElementsFile = KStandardDirs::locateLocal("cache", QLatin1Literal("plasma-svgelements-") % themeName);
svgElementsCache = KSharedConfig::openConfig(svgElementsFile);
}
invalidElements.clear(); invalidElements.clear();
emit q->themeChanged(); emit q->themeChanged();