|  | @@ -1,22 +1,43 @@
 | 
	
		
			
				|  |  | +/*
 | 
	
		
			
				|  |  | + *openPilot Log - A FOSS Pilot Logbook Application
 | 
	
		
			
				|  |  | + *Copyright (C) 2020  Felix Turowsky
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + *This program is free software: you can redistribute it and/or modify
 | 
	
		
			
				|  |  | + *it under the terms of the GNU General Public License as published by
 | 
	
		
			
				|  |  | + *the Free Software Foundation, either version 3 of the License, or
 | 
	
		
			
				|  |  | + *(at your option) any later version.
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + *This program is distributed in the hope that it will be useful,
 | 
	
		
			
				|  |  | + *but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
	
		
			
				|  |  | + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
	
		
			
				|  |  | + *GNU General Public License for more details.
 | 
	
		
			
				|  |  | + *
 | 
	
		
			
				|  |  | + *You should have received a copy of the GNU General Public License
 | 
	
		
			
				|  |  | + *along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  |  #include "src/classes/astandardpaths.h"
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  QMap<AStandardPaths::Directories, QDir> AStandardPaths::directories;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -void AStandardPaths::setup()
 | 
	
		
			
				|  |  | +bool AStandardPaths::setup()
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  |      auto data_location = QStandardPaths::AppDataLocation;
 | 
	
		
			
				|  |  | -    directories = { // [F]: Dir could be ambiguous since it is very similar to QDir
 | 
	
		
			
				|  |  | -        {Database, QDir(QStandardPaths::writableLocation(data_location) + '/')},
 | 
	
		
			
				|  |  | -        {Templates, QDir(QStandardPaths::writableLocation(data_location)).filePath(
 | 
	
		
			
				|  |  | -         QStringLiteral("templates/"))},
 | 
	
		
			
				|  |  | -        {Backup, QDir(QStandardPaths::writableLocation(data_location)).filePath(
 | 
	
		
			
				|  |  | -         QStringLiteral("backup/"))}
 | 
	
		
			
				|  |  | +    directories = {
 | 
	
		
			
				|  |  | +        {Database, QDir(QStandardPaths::writableLocation(data_location))},
 | 
	
		
			
				|  |  | +        {Templates, QDir(QStandardPaths::writableLocation(data_location)
 | 
	
		
			
				|  |  | +         + QStringLiteral("/templates"))},
 | 
	
		
			
				|  |  | +        {Backup, QDir(QStandardPaths::writableLocation(data_location)
 | 
	
		
			
				|  |  | +         + QStringLiteral("/backup"))}
 | 
	
		
			
				|  |  |      };
 | 
	
		
			
				|  |  | +    if (scan_directories())
 | 
	
		
			
				|  |  | +        return true;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    return false;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -const QDir& AStandardPaths::directory(Directories loc)
 | 
	
		
			
				|  |  | +const QDir& AStandardPaths::directory(Directories location)
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  | -    return directories[loc];
 | 
	
		
			
				|  |  | +    return directories[location];
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  const QMap<AStandardPaths::Directories, QDir>& AStandardPaths::allDirectories()
 | 
	
	
		
			
				|  | @@ -24,11 +45,11 @@ const QMap<AStandardPaths::Directories, QDir>& AStandardPaths::allDirectories()
 | 
	
		
			
				|  |  |      return directories;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -bool AStandardPaths::scan_dirs()
 | 
	
		
			
				|  |  | +bool AStandardPaths::scan_directories()
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  |      for(const auto& dir : directories){
 | 
	
		
			
				|  |  |          if(!dir.exists()) {
 | 
	
		
			
				|  |  | -            DEB << dir << "Does not exist. Creating: " << dir.absolutePath();
 | 
	
		
			
				|  |  | +            DEB << dir << "Does not exist. Creating:" << dir.absolutePath();
 | 
	
		
			
				|  |  |              if (!dir.mkpath(dir.absolutePath()))
 | 
	
		
			
				|  |  |                  return false;
 | 
	
		
			
				|  |  |          }
 |