Deprecate a lastModified timestamp of 0 in Theme::findInCache

lastModified is used to track whether a file is outdated. Having a 0
here means we (in the old code) use the cached version. This causes
problems when the on-disk file has changed, as we have no way of
informing callers that they should regenerate the cache entry. To avoid
this, using a lastModified of 0 now warns and will always return false
(to indicate it is not cached). Unfortunately we can't simply drop the
default parameter of 0 since there is no source-compatible way of doing
that.

CCBUG: 426674
This commit is contained in:
Arjen Hiemstra 2020-09-22 14:41:26 +02:00
parent c0ebacfa68
commit 54e12fcda0
2 changed files with 25 additions and 13 deletions

View File

@ -282,23 +282,31 @@ bool Theme::useGlobalSettings() const
bool Theme::findInCache(const QString &key, QPixmap &pix, unsigned int lastModified)
{
if (lastModified != 0 && d->useCache() && lastModified > uint(d->pixmapCache->lastModifiedTime().toSecsSinceEpoch())) {
//TODO KF6: Make lastModified non-optional.
if (lastModified == 0) {
qCWarning(LOG_PLASMA) << "findInCache with a lastModified timestamp of 0 is deprecated";
return false;
}
if (d->useCache()) {
const QString id = d->keysToCache.value(key);
const auto it = d->pixmapsToCache.constFind(id);
if (it != d->pixmapsToCache.constEnd()) {
pix = *it;
return !pix.isNull();
}
if (!d->useCache()) {
return false;
}
QPixmap temp;
if (d->pixmapCache->findPixmap(key, &temp) && !temp.isNull()) {
pix = temp;
return true;
}
if (lastModified > uint(d->pixmapCache->lastModifiedTime().toSecsSinceEpoch())) {
return false;
}
const QString id = d->keysToCache.value(key);
const auto it = d->pixmapsToCache.constFind(id);
if (it != d->pixmapsToCache.constEnd()) {
pix = *it;
return !pix.isNull();
}
QPixmap temp;
if (d->pixmapCache->findPixmap(key, &temp) && !temp.isNull()) {
pix = temp;
return true;
}
return false;

View File

@ -220,6 +220,10 @@ public:
* @param lastModified if non-zero, the time stamp is also checked on the file,
* and must be newer than the timestamp to be loaded
*
* @note Since KF 5.75, a lastModified value of 0 is deprecated. If used, it
* will now always return false. Use a proper file timestamp instead
* so modification can be properly tracked.
*
* @return true when pixmap was found and loaded from cache, false otherwise
* @since 4.3
**/