2
0

astandardpaths.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2022 Felix Turowsky
  4. *
  5. *This program is free software: you can redistribute it and/or modify
  6. *it under the terms of the GNU General Public License as published by
  7. *the Free Software Foundation, either version 3 of the License, or
  8. *(at your option) any later version.
  9. *
  10. *This program is distributed in the hope that it will be useful,
  11. *but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. *GNU General Public License for more details.
  14. *
  15. *You should have received a copy of the GNU General Public License
  16. *along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. #ifndef ASTANDARDPATHS_H
  19. #define ASTANDARDPATHS_H
  20. #include <QStandardPaths>
  21. #include <QString>
  22. #include <QHash>
  23. #include <QDir>
  24. /*!
  25. * \brief The AStandardAppPaths class encapsulates a static QHash holding
  26. * the standard paths of the application.
  27. */
  28. class AStandardPaths{
  29. public:
  30. enum Directories {
  31. Database,
  32. Templates,
  33. Backup,
  34. Log,
  35. JSON
  36. };
  37. private:
  38. static QHash<Directories, QDir> directories;
  39. /*!
  40. * \brief Ensures the standard app directories exists and creates
  41. * them if neccessary.
  42. */
  43. static bool scan_directories();
  44. public:
  45. /*!
  46. * \brief Creates and verifies a static map of the standard paths used in the app.
  47. */
  48. static bool setup();
  49. /*!
  50. * \brief Returns the QDir for the standard directory referenced
  51. * by the Directories enum 'loc'
  52. */
  53. static const QDir &directory(Directories location);
  54. /*!
  55. * \brief Returns a string of the absolute path to directory location concatenated with filename
  56. */
  57. static const QString asChildOfDir(Directories location, const QString& filename);
  58. /*!
  59. * \brief returns the static map of all standard directories
  60. * \return static const QHash<Directories, QDir>
  61. */
  62. static const QHash<Directories, QDir> &allDirectories();
  63. };
  64. #endif // ASTANDARDPATHS_H