AusweisApp2
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-2020 Governikus GmbH & Co. KG, Germany
5  */
6 
7 #pragma once
8 
9 #include <QCoreApplication>
10 #include <QDebug>
11 #include <QStandardPaths>
12 #include <QStringBuilder>
13 
14 namespace governikus
15 {
16 
18 {
19  private:
20  FileDestination() = delete;
21  ~FileDestination() = delete;
22  Q_DISABLE_COPY(FileDestination)
23 
24  static QString getPath()
25  {
26  #if defined(Q_OS_ANDROID)
27  return QStringLiteral("assets:");
28 
29  #elif defined(Q_OS_MACOS) && defined(QT_NO_DEBUG)
30  return QCoreApplication::applicationDirPath() + QStringLiteral("/../Resources");
31 
32  #else
33  return QCoreApplication::applicationDirPath();
34 
35  #endif
36  }
37 
38  public:
39  static QString getPath(const QString& pFilename,
40  QStandardPaths::LocateOption pOption = QStandardPaths::LocateFile,
41  QStandardPaths::StandardLocation pStandard = QStandardPaths::AppDataLocation)
42  {
43  #if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) || (defined(Q_OS_BSD4) && !defined(Q_OS_MACOS) && !defined(Q_OS_IOS))
44  const auto match = QStandardPaths::locate(pStandard, pFilename, pOption);
45  if (!match.isNull())
46  {
47  return match;
48  }
49 
50  qDebug() << pFilename << "not found in following destinations |" << pOption;
51  const auto defaultLocations = QStandardPaths::standardLocations(pStandard);
52  for (const auto& location : defaultLocations)
53  {
54  qDebug() << location;
55  }
56  #else
57  Q_UNUSED(pOption)
58  Q_UNUSED(pStandard)
59  #endif
60 
61  return getPath() % QLatin1Char('/') % pFilename;
62  }
63 
64 
65 };
66 
67 } // namespace governikus
static QString getPath(const QString &pFilename, QStandardPaths::LocateOption pOption=QStandardPaths::LocateFile, QStandardPaths::StandardLocation pStandard=QStandardPaths::AppDataLocation)
Definition: FileDestination.h:39
Implementation of ActivationContext for Intent based activation on Android systems.
Definition: ActivationContext.h:14
Definition: FileDestination.h:17