Add image caching && update libqmatrixclient.

This commit is contained in:
Black Hat 2018-08-27 19:29:50 +08:00
parent cb2f7daa17
commit 3fa14d3c4b
2 changed files with 13 additions and 1 deletions

@ -1 +1 @@
Subproject commit 4e45218924babe6708fe2128574a3cf6341fe3c6 Subproject commit d9ff200ff62fb7f5b6b51082dc3979d5454a1bec

View File

@ -1,6 +1,8 @@
#include "imageprovider.h" #include "imageprovider.h"
#include <QFile>
#include <QMetaObject> #include <QMetaObject>
#include <QStandardPaths>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtCore/QWaitCondition> #include <QtCore/QWaitCondition>
@ -30,6 +32,14 @@ QImage ImageProvider::requestImage(const QString& id, QSize* pSize,
QUrl mxcUri{id}; QUrl mxcUri{id};
QUrl tempfilePath = QUrl::fromLocalFile(
QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/" +
mxcUri.fileName() + "-" + QString::number(requestedSize.width()) +
"x" + QString::number(requestedSize.height()) + ".png");
QImage cachedImage;
if (cachedImage.load(tempfilePath.toLocalFile())) return cachedImage;
MediaThumbnailJob* job = nullptr; MediaThumbnailJob* job = nullptr;
QReadLocker locker(&m_lock); QReadLocker locker(&m_lock);
@ -63,5 +73,7 @@ QImage ImageProvider::requestImage(const QString& id, QSize* pSize,
if (pSize != nullptr) *pSize = result.size(); if (pSize != nullptr) *pSize = result.size();
result.save(tempfilePath.toLocalFile());
return result; return result;
} }