Kstars

kspaths.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "auxiliary/kspaths.h"
7#include <QFileInfo>
8#include <QCoreApplication>
9
10QString KSPaths::locate(QStandardPaths::StandardLocation location, const QString &fileName,
12{
13 QString findings = QStandardPaths::locate(location, fileName, options);
14
15 // If there was no result and we are running a test, if the location contains the app name, retry with installed name
16 if (findings.isEmpty() && QStandardPaths::isTestModeEnabled())
17 {
18 switch(location)
19 {
20 case QStandardPaths::DataLocation:
22 findings = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QDir("kstars").filePath(fileName), options);
23 break;
24
26 findings = QStandardPaths::locate(QStandardPaths::GenericCacheLocation, QDir("kstars").filePath(fileName), options);
27 break;
28
30 findings = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, QDir("kstars").filePath(fileName), options);
31 break;
32
33 default:
34 break;
35 }
36 }
37
38#ifdef ANDROID
39 // If we are running Android, check the reserved-file area
40 if (findings.isEmpty())
41 {
42 QFileInfo const rfile("/data/data/org.kde.kstars.lite/qt-reserved-files/share/kstars/" + fileName);
43 if (rfile.exists())
44 return rfile.filePath();
45 }
46#endif
47
48 return findings;
49}
50
51QStringList KSPaths::locateAll(QStandardPaths::StandardLocation location, const QString &fileName,
53{
54 QStringList findings = QStandardPaths::locateAll(location, fileName, options);
55
56 // If there was no result and we are running a test, if the location contains the app name, retry with installed name
57 if (findings.isEmpty() && QStandardPaths::isTestModeEnabled())
58 {
59 switch(location)
60 {
61 case QStandardPaths::DataLocation:
63 findings = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QDir("kstars").filePath(fileName), options);
64 break;
65
67 findings = QStandardPaths::locateAll(QStandardPaths::GenericCacheLocation, QDir("kstars").filePath(fileName), options);
68 break;
69
71 findings = QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, QDir("kstars").filePath(fileName), options);
72 break;
73
74 default:
75 break;
76 }
77 }
78
79#ifdef ANDROID
80 // If we are running Android, check the reserved-file area
81 if (findings.isEmpty())
82 {
83 QFileInfo const rfile("/data/data/org.kde.kstars.lite/qt-reserved-files/share/kstars/" + fileName);
84 if (rfile.exists())
85 return { rfile.filePath() };
86 }
87#endif
88
89 return findings;
90}
91
92QString KSPaths::writableLocation(QStandardPaths::StandardLocation type)
93{
94 switch (type)
95 {
99 qWarning("Call to writableLocation without an application-based location.");
100 break;
101
102 default:
103 break;
104 }
105
106 //Q_ASSERT_X(type != QStandardPaths::GenericDataLocation, __FUNCTION__, "GenericDataLocation is not writable.");
107 //Q_ASSERT_X(type != QStandardPaths::GenericConfigLocation, __FUNCTION__, "GenericConfigLocation is not writable.");
108 //Q_ASSERT_X(type != QStandardPaths::GenericCacheLocation, __FUNCTION__, "GenericCacheLocation is not writable.");
109
110#ifdef Q_OS_ANDROID
111 // No more writableLocation calls on Generic(Data|Config|Cache)Location anymore in KStars
112#endif
113
114#ifdef Q_OS_WIN
115 // As long as the application name on Windows and Linux is the same, no change here
116#endif
117
119}
typedef LocateOptions
QString locate(StandardLocation type, const QString &fileName, LocateOptions options)
QStringList locateAll(StandardLocation type, const QString &fileName, LocateOptions options)
QString writableLocation(StandardLocation type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:01 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.