2
0

astandardpaths.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "src/classes/astandardpaths.h"
  2. QMap<AStandardPaths::Dirs, QString> AStandardPaths::dirs;
  3. void AStandardPaths::setup()
  4. {
  5. auto data_location = QStandardPaths::AppDataLocation;
  6. dirs = { // [G]: potential rename to `dirs`
  7. {Database, QStandardPaths::writableLocation(data_location)},
  8. {Templates, QDir(QStandardPaths::writableLocation(data_location)).filePath("templates")},
  9. {DatabaseBackup, QDir(QStandardPaths::writableLocation(data_location)).filePath("backup")}
  10. };
  11. }
  12. const QString& AStandardPaths::absPathOf(Dirs loc)
  13. {
  14. return dirs[loc];
  15. }
  16. const QMap<AStandardPaths::Dirs, QString>& AStandardPaths::allPaths()
  17. {
  18. return dirs;
  19. }
  20. void AStandardPaths::scan_dirs()
  21. {
  22. for(auto& dir : dirs){
  23. auto d = QDir(dir);
  24. if(!d.exists()) {
  25. d.mkpath(dir);
  26. }
  27. }
  28. }
  29. bool AStandardPaths::validate_dirs()
  30. {
  31. for(auto& dir : dirs){
  32. //DEB << "Validating " << dir;
  33. if(false) // determine path as valid (scan contents and parse for correctness)
  34. return false;
  35. }
  36. return true;
  37. }