improved discardCache function
- if the theme changed recreate the cache - if the theme is the same just clear it - on colorscheme change keep svgElementsCache as element names and sizes are unchanged svn path=/trunk/KDE/kdelibs/; revision=1173948
This commit is contained in:
parent
a74c0a9706
commit
404c4b310d
39
theme.cpp
39
theme.cpp
@ -125,7 +125,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();
|
void discardCache(const QString &oldThemeName = QString(), bool keepSvgElementsCache = false);
|
||||||
void scheduledCacheUpdate();
|
void scheduledCacheUpdate();
|
||||||
void colorsChanged();
|
void colorsChanged();
|
||||||
bool useCache();
|
bool useCache();
|
||||||
@ -235,21 +235,32 @@ void ThemePrivate::compositingChanged()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThemePrivate::discardCache()
|
void ThemePrivate::discardCache(const QString &oldThemeName, bool keepSvgElementsCache)
|
||||||
{
|
{
|
||||||
KSharedDataCache::deleteCache("plasma_theme_" + themeName);
|
if (oldThemeName.isEmpty()) {
|
||||||
delete pixmapCache;
|
if (pixmapCache) {
|
||||||
pixmapCache = 0;
|
pixmapCache->clear();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delete pixmapCache;
|
||||||
|
pixmapCache = 0;
|
||||||
|
KSharedDataCache::deleteCache("plasma_theme_" + oldThemeName);
|
||||||
|
}
|
||||||
invalidElements.clear();
|
invalidElements.clear();
|
||||||
pixmapsToCache.clear();
|
pixmapsToCache.clear();
|
||||||
saveTimer->stop();
|
saveTimer->stop();
|
||||||
|
|
||||||
const QString svgElementsFile = KStandardDirs::locateLocal("cache", "plasma-svgelements-" + themeName);
|
if (keepSvgElementsCache) {
|
||||||
if (!svgElementsFile.isEmpty()) {
|
return;
|
||||||
QFile f(svgElementsFile);
|
}
|
||||||
|
|
||||||
|
if (svgElementsCache) {
|
||||||
|
QFile f(svgElementsCache->name());
|
||||||
|
svgElementsCache = 0;
|
||||||
f.remove();
|
f.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString svgElementsFile = KStandardDirs::locateLocal("cache", "plasma-svgelements-" + themeName);
|
||||||
svgElementsCache = KSharedConfig::openConfig(svgElementsFile);
|
svgElementsCache = KSharedConfig::openConfig(svgElementsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +279,7 @@ void ThemePrivate::scheduledCacheUpdate()
|
|||||||
|
|
||||||
void ThemePrivate::colorsChanged()
|
void ThemePrivate::colorsChanged()
|
||||||
{
|
{
|
||||||
discardCache();
|
discardCache(QString(), true);
|
||||||
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);
|
||||||
@ -488,14 +499,12 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
|
|||||||
theme = ThemePrivate::defaultTheme;
|
theme = ThemePrivate::defaultTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check again as ThemePrivate::defaultTheme might be empty
|
||||||
if (themeName == theme) {
|
if (themeName == theme) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//discard the old theme cache
|
const QString oldThemeName = themeName;
|
||||||
if (!themeName.isEmpty() && pixmapCache) {
|
|
||||||
discardCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
themeName = theme;
|
themeName = theme;
|
||||||
|
|
||||||
@ -573,8 +582,8 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
|
|||||||
QFile f(metadataPath);
|
QFile f(metadataPath);
|
||||||
QFileInfo info(f);
|
QFileInfo info(f);
|
||||||
|
|
||||||
if (useCache() && info.lastModified().toTime_t() > pixmapCache->lastModifiedTime()) {
|
if (useCache() && (!oldThemeName.isEmpty() || info.lastModified().toTime_t() > pixmapCache->lastModifiedTime())) {
|
||||||
discardCache();
|
discardCache(oldThemeName);
|
||||||
} else {
|
} else {
|
||||||
QString svgElementsFile = KStandardDirs::locateLocal("cache", "plasma-svgelements-" + themeName);
|
QString svgElementsFile = KStandardDirs::locateLocal("cache", "plasma-svgelements-" + themeName);
|
||||||
svgElementsCache = KSharedConfig::openConfig(svgElementsFile);
|
svgElementsCache = KSharedConfig::openConfig(svgElementsFile);
|
||||||
|
Loading…
Reference in New Issue
Block a user