diff options
author | Tobias Markmann <tm@ayena.de> | 2016-09-05 12:34:41 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-09-05 12:34:41 (GMT) |
commit | dfee5070225e9f2d5e0612cb65ce504b0700d0b9 (patch) | |
tree | 4caafd527475838ba6fddaca8aa8691dd0b6f44c /Swift | |
parent | a898a381b41d88195f8d54817766d1ac296c9fc4 (diff) | |
download | swift-dfee5070225e9f2d5e0612cb65ce504b0700d0b9.zip swift-dfee5070225e9f2d5e0612cb65ce504b0700d0b9.tar.bz2 |
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
Diffstat (limited to 'Swift')
-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; |