diff options
-rw-r--r-- | Swift/QtUI/QtScaledAvatarCache.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Swift/QtUI/QtScaledAvatarCache.cpp b/Swift/QtUI/QtScaledAvatarCache.cpp index a0baa62..8c37dac 100644 --- a/Swift/QtUI/QtScaledAvatarCache.cpp +++ b/Swift/QtUI/QtScaledAvatarCache.cpp @@ -20,6 +20,11 @@ namespace Swift { +namespace { + // This number needs to be incremented whenever the avatar scaling procedure changes. + const int QT_SCALED_AVATAR_CACHE_VERSION = 1; +} + QtScaledAvatarCache::QtScaledAvatarCache(int size) : size(size) { } @@ -46,12 +51,13 @@ static QPixmap cropToBiggestCenteredSquare(const QPixmap& input) { QString QtScaledAvatarCache::getScaledAvatarPath(const QString& path) { QFileInfo avatarFile(path); if (avatarFile.exists()) { - if (!avatarFile.dir().exists(QString::number(size))) { - if (!avatarFile.dir().mkdir(QString::number(size))) { - return path; - } + QString cacheSubPath = QString("ScaledAvatarCacheV%1/%2").arg(QString::number(QT_SCALED_AVATAR_CACHE_VERSION), QString::number(size)); + if (!avatarFile.dir().mkpath(cacheSubPath)) { + SWIFT_LOG(error) << "avatarFile.dir(): " << Q2PSTRING(avatarFile.dir().absolutePath()) << std::endl; + SWIFT_LOG(error) << "Failed creating cache folder: " << Q2PSTRING(cacheSubPath) << std::endl; + return path; } - QDir targetDir(avatarFile.dir().absoluteFilePath(QString::number(size))); + QDir targetDir(avatarFile.dir().absoluteFilePath(cacheSubPath)); QString targetFile = targetDir.absoluteFilePath(avatarFile.baseName()); if (!QFileInfo(targetFile).exists()) { QPixmap avatarPixmap; @@ -69,7 +75,7 @@ QString QtScaledAvatarCache::getScaledAvatarPath(const QString& path) { return path; } } else { - SWIFT_LOG(debug) << "Failed to load " << Q2PSTRING(path) << std::endl; + SWIFT_LOG(warning) << "Failed to load " << Q2PSTRING(path) << std::endl; } } return targetFile; |