Big-Ugly Style Update (#278)
* Bulk replaced tabs with spaces * Bulk removed trailing whitespace from lines * Replaced c-style comments with c++-style comments in file banners * Replace nested namespace definitions with single concise definitions (C++17), this keeps the indentation more manageable * Cleanup ordering and spacing of include directives * Bulk renaming of header file extensions from '.h' to '.hpp'. * Update CODING-STYLE.md * Update target_compile_features from cxx_std_11 to cxx_std_20. * Refresh .clang-format file. Still needs a lot of tweaking.
This commit is contained in:
+100
-102
@@ -1,124 +1,122 @@
|
||||
/* FileUtil.cpp
|
||||
*
|
||||
* Copyright (C) 2015 Jaye Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt 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.
|
||||
*
|
||||
* gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
// FileUtil.cpp
|
||||
//
|
||||
// Copyright (C) 2015 Jaye Evins <evins@snaught.com>
|
||||
//
|
||||
// This file is part of gLabels-qt.
|
||||
//
|
||||
// gLabels-qt 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.
|
||||
//
|
||||
// gLabels-qt 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 gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
|
||||
#include "FileUtil.h"
|
||||
|
||||
#include "Config.h"
|
||||
#include "FileUtil.hpp"
|
||||
|
||||
#include "Config.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QStandardPaths>
|
||||
|
||||
|
||||
namespace glabels
|
||||
namespace glabels::model
|
||||
{
|
||||
namespace model
|
||||
{
|
||||
|
||||
QString FileUtil::addExtension( const QString& rawFilename, const QString& extension )
|
||||
{
|
||||
if ( rawFilename.endsWith( extension ) )
|
||||
{
|
||||
return rawFilename;
|
||||
}
|
||||
QString FileUtil::addExtension( const QString& rawFilename, const QString& extension )
|
||||
{
|
||||
if ( rawFilename.endsWith( extension ) )
|
||||
{
|
||||
return rawFilename;
|
||||
}
|
||||
|
||||
return rawFilename + extension;
|
||||
}
|
||||
return rawFilename + extension;
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::systemTemplatesDir()
|
||||
{
|
||||
QDir dir;
|
||||
QDir FileUtil::systemTemplatesDir()
|
||||
{
|
||||
QDir dir;
|
||||
|
||||
// First, try finding templates directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
// First, try finding templates directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_SOURCE_DIR ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_SOURCE_DIR ) && dir.cd( "templates" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
qFatal( "Cannot locate system template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
qFatal( "Cannot locate system template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::manualUserTemplatesDir()
|
||||
{
|
||||
// Location for manually created user-defined templates
|
||||
QDir dir( QStandardPaths::writableLocation(QStandardPaths::HomeLocation) );
|
||||
dir.mkpath( ".glabels" );
|
||||
dir.cd( ".glabels" );
|
||||
QDir FileUtil::manualUserTemplatesDir()
|
||||
{
|
||||
// Location for manually created user-defined templates
|
||||
QDir dir( QStandardPaths::writableLocation(QStandardPaths::HomeLocation) );
|
||||
dir.mkpath( ".glabels" );
|
||||
dir.cd( ".glabels" );
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::userTemplatesDir()
|
||||
{
|
||||
// Location for user-defined templates created using TemplateDesigner
|
||||
QDir dir( QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) );
|
||||
dir.mkpath( "." );
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::translationsDir()
|
||||
{
|
||||
QDir dir;
|
||||
|
||||
// First, try finding translations directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "translations" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_BUILD_DIR ) && dir.cd( "translations" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
qFatal( "Cannot locate system template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
QString FileUtil::makeRelativeIfInDir( const QDir& dir,
|
||||
const QString& filename )
|
||||
{
|
||||
QString relativeFilePath = dir.relativeFilePath( filename ); // Note: directory separators canonicalized to slash by Qt path methods
|
||||
if ( !relativeFilePath.startsWith( "../" ) )
|
||||
{
|
||||
return relativeFilePath;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
QDir FileUtil::userTemplatesDir()
|
||||
{
|
||||
// Location for user-defined templates created using TemplateDesigner
|
||||
QDir dir( QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) );
|
||||
dir.mkpath( "." );
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
|
||||
QDir FileUtil::translationsDir()
|
||||
{
|
||||
QDir dir;
|
||||
|
||||
// First, try finding translations directory relative to application path
|
||||
dir.cd( QApplication::applicationDirPath() );
|
||||
if ( (dir.dirName() == "bin") &&
|
||||
dir.cdUp() && dir.cd( "share" ) && dir.cd( "glabels-qt" ) && dir.cd( "translations" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Next, try running out of the source directory.
|
||||
if ( dir.cd( Config::PROJECT_BUILD_DIR ) && dir.cd( "translations" ) )
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
|
||||
qFatal( "Cannot locate system template directory!" );
|
||||
return QDir("/");
|
||||
}
|
||||
|
||||
|
||||
QString FileUtil::makeRelativeIfInDir( const QDir& dir,
|
||||
const QString& filename )
|
||||
{
|
||||
QString relativeFilePath = dir.relativeFilePath( filename ); // Note: directory separators canonicalized to slash by Qt path methods
|
||||
if ( !relativeFilePath.startsWith( "../" ) )
|
||||
{
|
||||
return relativeFilePath;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user