2
0

astandardpaths.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. *openPilotLog - A FOSS Pilot Logbook Application
  3. *Copyright (C) 2020-2021 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 "src/testing/adebug.h"
  21. #include <QStandardPaths>
  22. #include <QString>
  23. #include <QMap>
  24. #include <QDir>
  25. /*!
  26. * \brief The AStandardAppPaths class encapsulates a static QMap holding
  27. * the standard paths of the application.
  28. */
  29. class AStandardPaths{
  30. public:
  31. enum Directories {
  32. Database,
  33. Templates,
  34. Backup
  35. };
  36. private:
  37. static QMap<Directories, QDir> directories;
  38. /*!
  39. * \brief Ensures the standard app directories exists and creates
  40. * them if neccessary.
  41. */
  42. static bool scan_directories();
  43. public:
  44. /*!
  45. * \brief Creates and verifies a static map of the standard paths used in the app.
  46. */
  47. static bool setup();
  48. /*!
  49. * \brief Returns the QDir for the standard directory referenced
  50. * by the Directories enum 'loc'
  51. */
  52. static const QDir &directory(Directories location);
  53. /*!
  54. * \brief Returns a string of the absolute path to directory location concatenated with filename
  55. */
  56. static const QString asChildOfDir(Directories location, const QString& filename);
  57. /*!
  58. * \brief returns the static map of all standard directories
  59. * \return static const QMap<Directories, QDir>
  60. */
  61. static const QMap<Directories, QDir> &allDirectories();
  62. };
  63. #endif // ASTANDARDPATHS_H