Create picture cache directory if needed

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2015-03-17 12:09:03 +01:00 committed by Dirk Hohndel
parent e0490f3055
commit 002cfa0663

View file

@ -65,7 +65,11 @@ void ImageDownloader::saveImage(QNetworkReply *reply)
QByteArray imageData = reply->readAll();
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(imageData);
QFile imageFile(QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first().append("/").append(hash.result().toHex()));
QString path = QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first();
QDir dir(path);
if (!dir.exists())
dir.mkpath(path);
QFile imageFile(path.append("/").append(hash.result().toHex()));
if (imageFile.open(QIODevice::WriteOnly)) {
QDataStream stream(&imageFile);
stream.writeRawData(imageData.data(), imageData.length());