aboutsummaryrefslogtreecommitdiff
path: root/src/corelib/core/msystemdirectories.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/core/msystemdirectories.cpp')
-rw-r--r--src/corelib/core/msystemdirectories.cpp53
1 files changed, 53 insertions, 0 deletions
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;
+}