diff options
author | Armin Berres <armin.berres@basyskom.de> | 2011-01-07 12:51:51 +0100 |
---|---|---|
committer | Armin Berres <armin.berres@basyskom.de> | 2011-01-18 15:21:43 +0100 |
commit | ca8539bd7166a1de92ea7cf0bd6c013136bf3a01 (patch) | |
tree | a853d492b1ff0645cdf751c1a3d36f618c737c8e /src/corelib | |
parent | badc94d6742f46e68c3f7e5ee7ab81c0632a4db7 (diff) |
Changes: make sure we have a writable cache directory
RevBy: Stanislav Ionascu, Holger Schröder
Details:
So far we were always trying to save our cache files in /var/cache/meegotouch.
This had various side effects on non-linux platforms and also on linux
platforms with missing access rights to this directory.
We now fallback to the cache directory specified by QDesktopServices
if needed.
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/core/core.pri | 2 | ||||
-rw-r--r-- | src/corelib/core/msystemdirectories.cpp | 53 | ||||
-rw-r--r-- | src/corelib/core/msystemdirectories.h | 35 | ||||
-rw-r--r-- | src/corelib/style/mstylesheetparser.cpp | 7 | ||||
-rw-r--r-- | src/corelib/theme/mimagedirectory.cpp | 4 | ||||
-rw-r--r-- | src/corelib/theme/mlogicalvalues.cpp | 15 | ||||
-rw-r--r-- | src/corelib/theme/mthemedaemon.cpp | 34 |
7 files changed, 98 insertions, 52 deletions
diff --git a/src/corelib/core/core.pri b/src/corelib/core/core.pri index 441d666f..7a047ad1 100644 --- a/src/corelib/core/core.pri +++ b/src/corelib/core/core.pri @@ -41,6 +41,7 @@ PRIVATE_HEADERS += \ $$CORE_SRC_DIR/mgraphicssystemhelper.h \ $$CORE_SRC_DIR/mdynamicpropertywatcher.h \ $$CORE_SRC_DIR/mmetatypes.h \ + $$CORE_SRC_DIR/msystemdirectories.h \ contains(DEFINES, HAVE_DBUS) { PUBLIC_HEADERS += \ @@ -81,6 +82,7 @@ SOURCES += \ $$CORE_SRC_DIR/mgraphicssystemhelper.cpp \ $$CORE_SRC_DIR/mdynamicpropertywatcher.cpp \ $$CORE_SRC_DIR/mdebug.cpp \ + $$CORE_SRC_DIR/msystemdirectories.cpp \ contains(DEFINES, HAVE_DBUS) { SOURCES += \ diff --git a/src/corelib/core/msystemdirectories.cpp b/src/corelib/core/msystemdirectories.cpp new file mode 100644 index 00000000..6f9f0b2e --- /dev/null +++ b/src/corelib/core/msystemdirectories.cpp @@ -0,0 +1,53 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of libmeegotouch. +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation +** and appearing in the file LICENSE.LGPL included in the packaging +** of this file. +** +****************************************************************************/ + +#include "msystemdirectories.h" +#include "qdebug.h" + +#include <QString> +#include <QDesktopServices> +#include <QDir> +#include <QFileInfo> + +#include <cstdlib> + + +QString MSystemDirectories::cacheDirectory() +{ + static QString cacheDir; + if (cacheDir.isEmpty()) { + // first check if we can write to CACHEDIR + cacheDir = CACHEDIR "/"; + QDir().mkpath(cacheDir); + QFileInfo cacheDirInfo(cacheDir); + if (!(cacheDirInfo.isWritable() && cacheDirInfo.isDir())) + { + // now we try a standard cache location + cacheDir = QDesktopServices::storageLocation(QDesktopServices::CacheLocation) + QDir::separator() + QLatin1String("meegotouch") + QDir::separator(); + QDir().mkpath(cacheDir); + cacheDirInfo.setFile(cacheDir); + if (!cacheDirInfo.isWritable() && cacheDirInfo.isDir()) { + qCritical() << "No writable cache directory found. Make sure that either" << QString(CACHEDIR) << "or" << cacheDir << "are writable."; + exit(EXIT_FAILURE); + } + } + } + + return cacheDir; +} diff --git a/src/corelib/core/msystemdirectories.h b/src/corelib/core/msystemdirectories.h new file mode 100644 index 00000000..004a0214 --- /dev/null +++ b/src/corelib/core/msystemdirectories.h @@ -0,0 +1,35 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of libmeegotouch. +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation +** and appearing in the file LICENSE.LGPL included in the packaging +** of this file. +** +****************************************************************************/ + +#ifndef MSYSTEMDIRECTORIES_H +#define MSYSTEMDIRECTORIES_H + +class QString; + +class MSystemDirectories +{ +public: + /** + * Returns a cache directory which can be used to store library + * specific cache files. + */ + static QString cacheDirectory(); +}; + +#endif diff --git a/src/corelib/style/mstylesheetparser.cpp b/src/corelib/style/mstylesheetparser.cpp index e474fd10..f8abb2da 100644 --- a/src/corelib/style/mstylesheetparser.cpp +++ b/src/corelib/style/mstylesheetparser.cpp @@ -22,6 +22,7 @@ #include "mclassfactory.h" #include "mstylesheetattribute.h" #include "mlogicalvalues.h" +#include "msystemdirectories.h" #include <QFile> #include <QTextStream> @@ -954,11 +955,7 @@ MStyleSheetParser::MStyleSheetParser(const MLogicalValues *logicalValues) : { Q_D(MStyleSheetParser); d->privateFileInfo = 0; -#ifdef Q_WS_X11 - d->binaryDirectory = QString(CACHEDIR) + "/css/"; -#else - d->binaryDirectory = QDir::tempPath() + QDir::separator(); -#endif + d->binaryDirectory = MSystemDirectories::cacheDirectory() + QLatin1String("css") + QDir::separator(); d->binaryFileMode = true; setSyntaxMode(StrictSyntax); diff --git a/src/corelib/theme/mimagedirectory.cpp b/src/corelib/theme/mimagedirectory.cpp index 339f4357..b0c3a2f7 100644 --- a/src/corelib/theme/mimagedirectory.cpp +++ b/src/corelib/theme/mimagedirectory.cpp @@ -278,7 +278,7 @@ QString ImageResource::createCacheFilename(const QSize& size) cacheKey.replace(QLatin1Char('/'), QLatin1String("_.")); cacheKey += '(' + QString::number(size.width()) + QLatin1Char(',') + QString::number(size.height()) + QLatin1Char(')'); - return MThemeDaemon::systemThemeCacheDirectory() + QLatin1String("images/") + cacheKey; + return MThemeDaemon::systemThemeCacheDirectory() + QLatin1String("images") + QDir::separator() + cacheKey; } bool ImageResource::shouldBeCached() @@ -683,7 +683,7 @@ QString MThemeImagesDirectory::createIdCacheFilename(const QString &filePath) co QString filePathEncoded(filePath); filePathEncoded.replace(QLatin1Char('_'), QLatin1String("__")); filePathEncoded.replace(QLatin1Char('/'), QLatin1String("_.")); - return MThemeDaemon::systemThemeCacheDirectory() + QLatin1String("ids/") + filePathEncoded; + return MThemeDaemon::systemThemeCacheDirectory() + QLatin1String("ids") + QDir::separator() + filePathEncoded; } MImageDirectory::MImageDirectory(const QString &path, M::RecursionMode recursionMode) diff --git a/src/corelib/theme/mlogicalvalues.cpp b/src/corelib/theme/mlogicalvalues.cpp index 381dbb1d..dd3ed229 100644 --- a/src/corelib/theme/mlogicalvalues.cpp +++ b/src/corelib/theme/mlogicalvalues.cpp @@ -21,6 +21,7 @@ #include "mlogicalvalues_p.h" #include "mstylesheetattribute.h" #include "mdebug.h" +#include "msystemdirectories.h" #include <QDir> #include <QFile> @@ -176,19 +177,7 @@ bool MLogicalValuesPrivate::saveToBinaryCache(const QFileInfo &fileInfo, const G } QString MLogicalValuesPrivate::createBinaryFilename(const QFileInfo &fileInfo) const { - QString binaryDirectory; -#ifdef Q_OS_WIN - QDir appDir(QCoreApplication::applicationDirPath()); - appDir.cdUp(); - - binaryDirectory = appDir.absolutePath() - + QDir::separator() + "var" - + QDir::separator() + "cache" - + QDir::separator() + "meegotouch" - + QDir::separator() + "logicalvalues"; -#else - binaryDirectory = QString(CACHEDIR) + "/logicalValues/"; -#endif + QString binaryDirectory = MSystemDirectories::cacheDirectory() + QLatin1String("logicalValues") + QDir::separator(); QString binaryFilename(binaryDirectory); QString absoluteFilePathEncoded(fileInfo.absoluteFilePath()); diff --git a/src/corelib/theme/mthemedaemon.cpp b/src/corelib/theme/mthemedaemon.cpp index 3bfbe3d8..abdaae26 100644 --- a/src/corelib/theme/mthemedaemon.cpp +++ b/src/corelib/theme/mthemedaemon.cpp @@ -35,6 +35,7 @@ #include "mimagedirectory.h" #include "mthemedaemonprotocol.h" #include "mpixmaphandle.h" +#include "msystemdirectories.h" using namespace M::MThemeDaemonProtocol; @@ -79,38 +80,7 @@ QString MThemeDaemon::systemThemeDirectory() QString MThemeDaemon::systemThemeCacheDirectory() { - static QString cacheDir; - if (cacheDir.isEmpty()) { - // first check if we can write to CACHEDIR -#ifdef Q_OS_WIN - QDir appDir(QCoreApplication::applicationDirPath()); - - appDir.cdUp(); - - cacheDir = appDir.absolutePath() - + QDir::separator() + "var" - + QDir::separator() + "cache" - + QDir::separator() + "meegotouch"; -#else - cacheDir = CACHEDIR; -#endif - QDir().mkpath(cacheDir); - QFile testFile(cacheDir + QDir::separator() + "permission_test_file"); - if (!testFile.open(QFile::WriteOnly)) { - // now we try a standard cache location - cacheDir = QDesktopServices::storageLocation(QDesktopServices::CacheLocation) - + QDir::separator() + QLatin1String("meegotouch"); - QDir().mkpath(cacheDir); - testFile.setFileName(cacheDir + QDir::separator() + "permission_test_file"); - if (!testFile.open(QFile::WriteOnly)) { - exit(EXIT_FAILURE); - } - } - testFile.remove(); - testFile.close(); - } - - return cacheDir + QDir::separator() + QLatin1String("themedaemon"); + return MSystemDirectories::cacheDirectory() + QLatin1String("themedaemon") + QDir::separator(); } void MThemeDaemon::addClient(MThemeDaemonClient *client) |