aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHartmut Riesenbeck <[email protected]>2016-05-09 22:49:10 +0200
committerHartmut Riesenbeck <[email protected]>2016-05-29 17:45:21 +0200
commitf766452408cc64a75b8782e499a6a8c4f64b3ba2 (patch)
tree637c069700d071fec755684db7f250c39945cae5
parent7d5741b0668a4b246529bc7c6f333a67b5afa92f (diff)
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
-rw-r--r--src/practice/imagecache.cpp17
-rw-r--r--src/practice/imagecache.h4
-rw-r--r--src/practice/themedbackgroundrenderer.cpp2
3 files changed, 18 insertions, 5 deletions
diff --git a/src/practice/imagecache.cpp b/src/practice/imagecache.cpp
index 9d01395..929ab76 100644
--- a/src/practice/imagecache.cpp
+++ b/src/practice/imagecache.cpp
@@ -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();
}
+
diff --git a/src/practice/imagecache.h b/src/practice/imagecache.h
index 26afb8a..ffd4163 100644
--- a/src/practice/imagecache.h
+++ b/src/practice/imagecache.h
@@ -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();
diff --git a/src/practice/themedbackgroundrenderer.cpp b/src/practice/themedbackgroundrenderer.cpp
index 7623d69..a2d4eaf 100644
--- a/src/practice/themedbackgroundrenderer.cpp
+++ b/src/practice/themedbackgroundrenderer.cpp
@@ -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);