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#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
21 case QStandardPaths::DataLocation:
22#else
24#endif
26 findings = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QDir("kstars").filePath(fileName), options);
27 break;
28
30 findings = QStandardPaths::locate(QStandardPaths::GenericCacheLocation, QDir("kstars").filePath(fileName), options);
31 break;
32
35 findings = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, QDir("kstars").filePath(fileName), options);
36 break;
37
38 default:
39 break;
40 }
41 }
42
43#ifdef ANDROID
44 // If we are running Android, check the reserved-file area
45 if (findings.isEmpty())
46 {
47 QFileInfo const rfile("/data/data/org.kde.kstars.lite/qt-reserved-files/share/kstars/" + fileName);
48 if (rfile.exists())
49 return rfile.filePath();
50 }
51#endif
52
53 return findings;
54}
55
56QStringList KSPaths::locateAll(QStandardPaths::StandardLocation location, const QString &fileName,
58{
59 QStringList findings = QStandardPaths::locateAll(location, fileName, options);
60
61 // If there was no result and we are running a test, if the location contains the app name, retry with installed name
62 if (findings.isEmpty() && QStandardPaths::isTestModeEnabled())
63 {
64 switch(location)
65 {
67 findings = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QDir("kstars").filePath(fileName), options);
68 break;
69
71 findings = QStandardPaths::locateAll(QStandardPaths::GenericCacheLocation, QDir("kstars").filePath(fileName), options);
72 break;
73
75 findings = QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, QDir("kstars").filePath(fileName), options);
76 break;
77
78 default:
79 break;
80 }
81 }
82
83#ifdef ANDROID
84 // If we are running Android, check the reserved-file area
85 if (findings.isEmpty())
86 {
87 QFileInfo const rfile("/data/data/org.kde.kstars.lite/qt-reserved-files/share/kstars/" + fileName);
88 if (rfile.exists())
89 return { rfile.filePath() };
90 }
91#endif
92
93 return findings;
94}
95
96QString KSPaths::writableLocation(QStandardPaths::StandardLocation type)
97{
98 switch (type)
99 {
103 qWarning("Call to writableLocation without an application-based location.");
104 break;
105
106 default:
107 break;
108 }
109
110 //Q_ASSERT_X(type != QStandardPaths::GenericDataLocation, __FUNCTION__, "GenericDataLocation is not writable.");
111 //Q_ASSERT_X(type != QStandardPaths::GenericConfigLocation, __FUNCTION__, "GenericConfigLocation is not writable.");
112 //Q_ASSERT_X(type != QStandardPaths::GenericCacheLocation, __FUNCTION__, "GenericCacheLocation is not writable.");
113
114#ifdef Q_OS_ANDROID
115 // No more writableLocation calls on Generic(Data|Config|Cache)Location anymore in KStars
116#endif
117
118#ifdef Q_OS_WIN
119 // As long as the application name on Windows and Linux is the same, no change here
120#endif
121
123}
bool isEmpty() const const
QString locate(StandardLocation type, const QString &fileName, LocateOptions options)
QStringList locateAll(StandardLocation type, const QString &fileName, LocateOptions options)
QString writableLocation(StandardLocation type)
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.