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 | |
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.
-rw-r--r-- | benchmarks/pt_mstylesheet/pt_mstylesheet.pro | 2 | ||||
-rw-r--r-- | mkspecs/features/meegotouch_defines.prf.in | 2 | ||||
-rw-r--r-- | mthemedaemon/mthemedaemon.pro | 2 | ||||
-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 | ||||
-rw-r--r-- | tests/ft_mstylesheet/ft_mstylesheet.pro | 4 | ||||
-rw-r--r-- | tests/ft_mstylesheetparser/ft_mstylesheetparser.pro | 8 | ||||
-rw-r--r-- | tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.pro | 2 | ||||
-rw-r--r-- | tests/ut_mlogicalvalues/ut_mlogicalvalues.pro | 6 |
14 files changed, 117 insertions, 59 deletions
diff --git a/benchmarks/pt_mstylesheet/pt_mstylesheet.pro b/benchmarks/pt_mstylesheet/pt_mstylesheet.pro index 1755cd7f..b0434097 100644 --- a/benchmarks/pt_mstylesheet/pt_mstylesheet.pro +++ b/benchmarks/pt_mstylesheet/pt_mstylesheet.pro @@ -8,7 +8,9 @@ TARGET = pt_mstylesheet SOURCES += pt_mstylesheet.cpp \ mlogicalvalues.cpp \ mstylesheetattribute.cpp \ + $$MSRCDIR/corelib/core/msystemdirectories.cpp \ HEADERS += pt_mstylesheet.h \ mlogicalvalues.h \ mstylesheetattribute.h \ + $$MSRCDIR/corelib/core/msystemdirectories.h \ diff --git a/mkspecs/features/meegotouch_defines.prf.in b/mkspecs/features/meegotouch_defines.prf.in index 4014b47e..8df5a2c6 100644 --- a/mkspecs/features/meegotouch_defines.prf.in +++ b/mkspecs/features/meegotouch_defines.prf.in @@ -108,7 +108,7 @@ win32 { M_INSTALL_SYSCONF = $$M_PREFIX/etc M_INSTALL_XSESSION = $$M_INSTALL_SYSCONF/X11 M_INSTALL_LOCALSTATE = $$M_PREFIX/var - M_CACHE_DIR = $$M_INSTALL_LOCALSTATE/cache/meegotouch + M_CACHE_DIR = c:/windows/temp/meegotouch M_THEME_PRELOAD_DIR = $$M_INSTALL_LOCALSTATE/lib/meegotouch/theme/preload.d M_THEME_POST_PRELOAD_DIR = $$M_INSTALL_LOCALSTATE/lib/meegotouch/theme/preload.post diff --git a/mthemedaemon/mthemedaemon.pro b/mthemedaemon/mthemedaemon.pro index 7331f0c8..6f30de9a 100644 --- a/mthemedaemon/mthemedaemon.pro +++ b/mthemedaemon/mthemedaemon.pro @@ -42,6 +42,7 @@ SOURCES += main.cpp \ ../src/corelib/theme/mthemedaemonprotocol.cpp \ ../src/corelib/core/mcpumonitor.cpp \ ../src/corelib/core/mgraphicssystemhelper.cpp \ + ../src/corelib/core/msystemdirectories.cpp \ contains(DEFINES, HAVE_GCONF) { PKGCONFIG += gconf-2.0 @@ -61,6 +62,7 @@ HEADERS += \ ../src/corelib/core/mgconfitem.h \ ../src/corelib/core/mcpumonitor.h \ ../src/corelib/core/mgraphicssystemhelper.h \ + ../src/corelib/core/msystemdirectories.h \ keypresswaiter.h \ QMAKE_EXTRA_TARGETS += check 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) diff --git a/tests/ft_mstylesheet/ft_mstylesheet.pro b/tests/ft_mstylesheet/ft_mstylesheet.pro index 78f8a940..e58b49ee 100644 --- a/tests/ft_mstylesheet/ft_mstylesheet.pro +++ b/tests/ft_mstylesheet/ft_mstylesheet.pro @@ -11,7 +11,8 @@ STYLE_HEADERS += testobjectstyle.h testobject2style.h testobject3style.h SOURCES += \ ft_mstylesheet.cpp \ $$MSRCDIR/corelib/theme/mlogicalvalues.cpp \ - $$MSRCDIR/corelib/style/mstylesheetattribute.cpp + $$MSRCDIR/corelib/style/mstylesheetattribute.cpp \ + $$MSRCDIR/corelib/core/msystemdirectories.cpp \ HEADERS += \ ft_mstylesheet.h \ @@ -23,6 +24,7 @@ HEADERS += \ testwidget3.h \ $$MSRCDIR/corelib/theme/mlogicalvalues.h \ $$MSRCDIR/corelib/style/mstylesheetattribute.h \ + $$MSRCDIR/corelib/core/msystemdirectories.cpp \ $$STYLE_HEADERS support_files.files += \ diff --git a/tests/ft_mstylesheetparser/ft_mstylesheetparser.pro b/tests/ft_mstylesheetparser/ft_mstylesheetparser.pro index afe434f6..e635bae1 100644 --- a/tests/ft_mstylesheetparser/ft_mstylesheetparser.pro +++ b/tests/ft_mstylesheetparser/ft_mstylesheetparser.pro @@ -8,13 +8,15 @@ INCLUDEPATH += $$MSRCDIR/corelib/core/ SOURCES += \ ft_mstylesheetparser.cpp \ $$MSRCDIR/corelib/theme/mlogicalvalues.cpp \ - $$MSRCDIR/corelib/style/mstylesheetattribute.cpp + $$MSRCDIR/corelib/style/mstylesheetattribute.cpp \ + $$MSRCDIR/corelib/core/msystemdirectories.cpp \ HEADERS += \ - ft_mstylesheetparser.h \ + ft_mstylesheetparser.h \ $$MSRCDIR/corelib/theme/mlogicalvalues.h \ - $$MSRCDIR/corelib/style/mstylesheetattribute.h + $$MSRCDIR/corelib/style/mstylesheetattribute.h \ + $$MSRCDIR/corelib/core/msystemdirectories.h \ support_files.files += \ *.css \ diff --git a/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.pro b/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.pro index 53b50728..2953f30b 100644 --- a/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.pro +++ b/tests/ut_mlocalthemedaemon/ut_mlocalthemedaemon.pro @@ -20,6 +20,7 @@ SOURCES += \ $$MSRCDIR/corelib/theme/mthemedaemon.cpp \ $$MSRCDIR/corelib/theme/mthemedaemonclient.cpp \ $$MSRCDIR/corelib/theme/mthemedaemonprotocol.cpp \ + $$MSRCDIR/corelib/core/msystemdirectories.cpp \ HEADERS += \ ut_mlocalthemedaemon.h \ @@ -33,5 +34,6 @@ HEADERS += \ $$MSRCDIR/corelib/theme/mthemedaemon.h \ $$MSRCDIR/corelib/theme/mthemedaemonprotocol.h \ $$MSRCDIR/corelib/theme/mthemedaemonclient.h \ + $$MSRCDIR/corelib/core/msystemdirectories.h \ include(../common_bot.pri) diff --git a/tests/ut_mlogicalvalues/ut_mlogicalvalues.pro b/tests/ut_mlogicalvalues/ut_mlogicalvalues.pro index a47f1440..82fa1998 100644 --- a/tests/ut_mlogicalvalues/ut_mlogicalvalues.pro +++ b/tests/ut_mlogicalvalues/ut_mlogicalvalues.pro @@ -8,13 +8,15 @@ INCLUDEPATH += $$MSRCDIR/corelib/core/ SOURCES += \ ut_mlogicalvalues.cpp \ $$MSRCDIR/corelib/theme/mlogicalvalues.cpp \ - $$MSRCDIR/corelib/style/mstylesheetattribute.cpp + $$MSRCDIR/corelib/style/mstylesheetattribute.cpp \ + $$MSRCDIR/corelib/core/msystemdirectories.cpp \ HEADERS += \ ut_mlogicalvalues.h \ $$MSRCDIR/corelib/theme/mlogicalvalues.h \ $$MSRCDIR/corelib/theme/mlogicalvalues_p.h \ - $$MSRCDIR/corelib/style/mstylesheetattribute.h + $$MSRCDIR/corelib/style/mstylesheetattribute.h \ + $$MSRCDIR/corelib/core/msystemdirectories.h \ support_files.files += *.ini |