AusweisApp2
Lade ...
Suche ...
Keine Treffer
FileDestination.h
gehe zur Dokumentation dieser Datei
1/*
2 * \brief Little helper that will abstract pathes of underlying systems
3 *
4 * \copyright Copyright (c) 2014-2022 Governikus GmbH & Co. KG, Germany
5 */
6
7#pragma once
8
9#include <QCoreApplication>
10#include <QDebug>
11#include <QFile>
12#include <QLibraryInfo>
13#include <QStandardPaths>
14#include <QStringBuilder>
15#include <QtGlobal>
16
17namespace governikus
18{
19
21{
22 Q_DISABLE_COPY(FileDestination)
23
24 private:
25 FileDestination() = delete;
26 ~FileDestination() = delete;
27
28 static QString getPath()
29 {
30#if defined(Q_OS_ANDROID)
31 return QStringLiteral("assets:");
32
33#elif defined(Q_OS_MACOS)
34 const auto& path = QCoreApplication::applicationDirPath() + QStringLiteral("/../Resources");
35
36 #if !defined(QT_NO_DEBUG)
37 if (!QFile::exists(path))
38 {
39 return QCoreApplication::applicationDirPath();
40 }
41 #endif
42
43 return path;
44
45#else
46 return QCoreApplication::applicationDirPath();
47
48#endif
49 }
50
51 public:
52 static QString getPath(const QString& pFilename,
53 QStandardPaths::LocateOption pOption = QStandardPaths::LocateFile,
54 QStandardPaths::StandardLocation pStandard = QStandardPaths::AppDataLocation)
55 {
56#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) || (defined(Q_OS_BSD4) && !defined(Q_OS_MACOS) && !defined(Q_OS_IOS))
57#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
58 if (pFilename.compare(QStringLiteral("translations")) == 0)
59 {
60 return QLibraryInfo::location(QLibraryInfo::TranslationsPath);
61 }
62#endif
63
64 if (const auto& match = QStandardPaths::locate(pStandard, pFilename, pOption); !match.isNull())
65 {
66 return match;
67 }
68
69 qDebug() << pFilename << "not found in following destinations |" << pOption;
70 const auto defaultLocations = QStandardPaths::standardLocations(pStandard);
71 for (const auto& location : defaultLocations)
72 {
73 qDebug() << location;
74 }
75#else
76 Q_UNUSED(pOption)
77 Q_UNUSED(pStandard)
78#endif
79
80 return getPath() % QLatin1Char('/') % pFilename;
81 }
82
83
84};
85
86} // namespace governikus
Definition: FileDestination.h:21
static QString getPath(const QString &pFilename, QStandardPaths::LocateOption pOption=QStandardPaths::LocateFile, QStandardPaths::StandardLocation pStandard=QStandardPaths::AppDataLocation)
Definition: FileDestination.h:52
A simple template renderer.
Definition: ActivationContext.h:15