File indexing completed on 2024-05-12 05:25:58
0001 /* 0002 * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) version 3, or any 0008 * later version accepted by the membership of KDE e.V. (or its 0009 * successor approved by the membership of KDE e.V.), which shall 0010 * act as a proxy defined in Section 6 of version 3 of the license. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #include "definitions.h" 0022 0023 #include <QStandardPaths> 0024 #include <QDir> 0025 0026 static bool rereadDataLocation = true; 0027 static bool rereadConfigLocation = true; 0028 static bool rereadTemporaryFileLocation = true; 0029 0030 void Sink::clearLocationCache() 0031 { 0032 rereadDataLocation = true; 0033 rereadConfigLocation = true; 0034 rereadTemporaryFileLocation = true; 0035 } 0036 0037 QString Sink::storageLocation() 0038 { 0039 return dataLocation() + "/storage"; 0040 } 0041 0042 static QString sinkLocation(QStandardPaths::StandardLocation location) 0043 { 0044 return QStandardPaths::writableLocation(location) + "/sink"; 0045 } 0046 0047 QString Sink::dataLocation() 0048 { 0049 static QString location = sinkLocation(QStandardPaths::GenericDataLocation); 0050 //Warning: This is not threadsafe, but clearLocationCache is only ever used in testcode. The initialization above is required to make at least the initialization threadsafe (relies on C++11 threadsafe initialization). 0051 if (rereadDataLocation) { 0052 location = sinkLocation(QStandardPaths::GenericDataLocation); 0053 rereadDataLocation = false; 0054 } 0055 return location; 0056 } 0057 0058 QString Sink::configLocation() 0059 { 0060 static QString location = sinkLocation(QStandardPaths::GenericConfigLocation); 0061 //Warning: This is not threadsafe, but clearLocationCache is only ever used in testcode. The initialization above is required to make at least the initialization threadsafe (relies on C++11 threadsafe initialization). 0062 if (rereadConfigLocation) { 0063 location = sinkLocation(QStandardPaths::GenericConfigLocation); 0064 rereadConfigLocation = false; 0065 } 0066 return location; 0067 } 0068 0069 QString Sink::temporaryFileLocation() 0070 { 0071 static QString location = dataLocation() + "/temporaryFiles"; 0072 static bool dirCreated = false; 0073 //Warning: This is not threadsafe, but clearLocationCache is only ever used in testcode. The initialization above is required to make at least the initialization threadsafe (relies on C++11 threadsafe initialization). 0074 if (rereadTemporaryFileLocation) { 0075 location = dataLocation() + "/temporaryFiles"; 0076 dirCreated = QDir{}.mkpath(location); 0077 rereadTemporaryFileLocation = false; 0078 } 0079 if (!dirCreated && QDir{}.mkpath(location)) { 0080 dirCreated = true; 0081 } 0082 return location; 0083 } 0084 0085 QString Sink::resourceStorageLocation(const QByteArray &resourceInstanceIdentifier) 0086 { 0087 return storageLocation() + "/" + resourceInstanceIdentifier + "/data"; 0088 } 0089 0090 0091 qint64 Sink::latestDatabaseVersion() 0092 { 0093 return 8; 0094 }