Commit f7664524 authored by Hartmut Riesenbeck's avatar Hartmut Riesenbeck

Fix theme cache path handling

When path to theme cache file does not exitst (e.g. after a fresh
installation) it is not created automatically which caused the
following error to be shown on stderr while reading and writing:

"QIODevice::read (QFile, "/path/to/theme/cache/startpagethemecache.bin"
): device not open"

Automatic creation of theme cache path is added. Location of cache file
is moved to QStandardPaths::CacheLocation.

REVIEW: 127881
parent 7d5741b0
......@@ -14,6 +14,7 @@
#include "imagecache.h"
#include <QFileInfo>
#include <QDir>
#include <QDataStream>
#include <QDebug>
......@@ -57,10 +58,23 @@ QImage ImageCache::getImage(const QString& id)
return m_images.value(id);
}
void ImageCache::setSaveFilename(const QString &filename)
{
m_saveFilename = filename;
QDir fileDir = QFileInfo(filename).absoluteDir();
if (!fileDir.exists() && !fileDir.mkpath(QStringLiteral("."))) {
qWarning() << QStringLiteral("Couldn't create image cache path: ") << fileDir.absolutePath();
}
}
void ImageCache::openCache()
{
QFile file(m_saveFilename);
file.open(QIODevice::ReadOnly);
if (!file.open(QIODevice::ReadOnly)) {
// If cache is used for the first time it's normal to fail here,
// because cache file doesn't exist at this time.
return;
}
QDataStream stream(&file);
// check identifier
QString temp;
......@@ -112,3 +126,4 @@ QDebug Practice::operator<<(QDebug dbg, const ImageCache &c)
dbg.nospace() << "\n\ttotal pixel count: " << pixels << " (approx. " << double(pixels) * 4 / 1024 / 1024 << " MiB)";
return dbg.space();
}
......@@ -39,9 +39,7 @@ public:
return m_images.isEmpty();
}
void setSaveFilename(const QString& filename) {
m_saveFilename = filename;
}
void setSaveFilename(const QString &filename);
void openCache();
void saveCache();
......
......@@ -29,7 +29,7 @@ ThemedBackgroundRenderer::ThemedBackgroundRenderer(QObject* parent, const QStrin
: QObject(parent), m_haveCache(true), m_queuedRequest(false), m_isFastScaledRender(true)
{
m_theme = new KGameTheme();
m_cache.setSaveFilename(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + '/' + cacheFilename);
m_cache.setSaveFilename(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + '/' + cacheFilename);
m_timer.setSingleShot(true);
m_timer.setInterval(1000);
connect(&m_timer, &QTimer::timeout, this, &ThemedBackgroundRenderer::updateBackgroundTimeout);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment