From dfee5070225e9f2d5e0612cb65ce504b0700d0b9 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Mon, 5 Sep 2016 14:34:41 +0200
Subject: Add simple versioning to QtScaledAvatarCache

The cache for each version is stored in a dedicated directory
that exists next to the raw avatar images.

This allows running different Swift versions which use
different versions of the QtScaledAvatarCache.

Test-Information:

Tested on OS X 10.11.6 with Qt 5.5.1 and Windows 8 with Qt
5.5.1.

Verified that the avatar paths changed to the new versioned
cache path in the web views.

Change-Id: I12cb46c4d6750ae7ad82c719eef290f721d1d131

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;
-- 
cgit v0.10.2-6-g49f6