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