From 6e0e06078b9b141466c2653dea284245b0da6ec8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 05:36:04 -0400 Subject: [PATCH 01/11] [libcalamares] Split out the variant-manipulation bits - We already have utils/ as the filesystem namespace, may as well make clearer what the various parts are. - Adjust CommandList to the moved API. --- src/libcalamares/CMakeLists.txt | 1 + src/libcalamares/utils/CalamaresUtils.cpp | 73 --------------- src/libcalamares/utils/CalamaresUtils.h | 31 ------- src/libcalamares/utils/CommandList.cpp | 3 +- src/libcalamares/utils/Variant.cpp | 107 ++++++++++++++++++++++ src/libcalamares/utils/Variant.h | 62 +++++++++++++ 6 files changed, 172 insertions(+), 105 deletions(-) create mode 100644 src/libcalamares/utils/Variant.cpp create mode 100644 src/libcalamares/utils/Variant.h diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 8baabac9a..2814b02a0 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -27,6 +27,7 @@ set( utilsSources utils/Logger.cpp utils/PluginFactory.cpp utils/Retranslator.cpp + utils/Variant.cpp utils/YamlUtils.cpp ) set( kdsagSources diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index 0ff6810c1..6d8862269 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -388,77 +388,4 @@ crash() *a = 1; } -bool -getBool( const QVariantMap& map, const QString& key, bool d ) -{ - bool result = d; - if ( map.contains( key ) ) - { - auto v = map.value( key ); - if ( v.type() == QVariant::Bool ) - result = v.toBool(); - } - - return result; -} - -QString -getString(const QVariantMap& map, const QString& key) -{ - if ( map.contains( key ) ) - { - auto v = map.value( key ); - if ( v.type() == QVariant::String ) - return v.toString(); - } - return QString(); -} - -int -getInteger( const QVariantMap& map, const QString& key, int d ) -{ - int result = d; - if ( map.contains( key ) ) - { - auto v = map.value( key ); - if ( v.type() == QVariant::Int ) - result = v.toInt(); - } - - return result; -} - -double -getDouble( const QVariantMap& map, const QString& key, double d ) -{ - double result = d; - if ( map.contains( key ) ) - { - auto v = map.value( key ); - if ( v.type() == QVariant::Int ) - result = v.toInt(); - else if ( v.type() == QVariant::Double ) - result = v.toDouble(); - } - - return result; -} - -QVariantMap -getSubMap( const QVariantMap& map, const QString& key, bool& success ) -{ - success = false; - - if ( map.contains( key ) ) - { - auto v = map.value( key ); - if ( v.type() == QVariant::Map ) - { - success = true; - return v.toMap(); - } - } - return QVariantMap(); -} - } diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/CalamaresUtils.h index baf7a12dc..2eb202b2c 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/CalamaresUtils.h @@ -108,37 +108,6 @@ namespace CalamaresUtils * @brief crash makes Calamares crash immediately. */ DLLEXPORT void crash(); - - /** - * Get a bool value from a mapping with a given key; returns the default - * if no value is stored in the map. - */ - DLLEXPORT bool getBool( const QVariantMap& map, const QString& key, bool d ); - - /** - * Get a string value from a mapping; returns empty QString if no value. - */ - DLLEXPORT QString getString( const QVariantMap& map, const QString& key ); - - /** - * Get an integer value from a mapping; returns @p d if no value. - */ - DLLEXPORT int getInteger( const QVariantMap& map, const QString& key, int d ); - - /** - * Get a double value from a mapping (integers are converted); returns @p d if no value. - */ - DLLEXPORT double getDouble( const QVariantMap& map, const QString& key, double d ); - - /** - * Returns a sub-map (i.e. a nested map) from the given mapping with the - * given key. @p success is set to true if the @p key exists - * in @p map and converts to a map, false otherwise. - * - * Returns an empty map if there is no such key or it is not a map-value. - * (e.g. if @p success is false). - */ - DLLEXPORT QVariantMap getSubMap( const QVariantMap& map, const QString& key, bool& success ); } #endif // CALAMARESUTILS_H diff --git a/src/libcalamares/utils/CommandList.cpp b/src/libcalamares/utils/CommandList.cpp index 6a9d68bef..9916c71fe 100644 --- a/src/libcalamares/utils/CommandList.cpp +++ b/src/libcalamares/utils/CommandList.cpp @@ -21,9 +21,10 @@ #include "GlobalStorage.h" #include "JobQueue.h" -#include "utils/CalamaresUtils.h" +// #include "utils/CalamaresUtils.h" #include "utils/CalamaresUtilsSystem.h" #include "utils/Logger.h" +#include "utils/Variant.h" #include #include diff --git a/src/libcalamares/utils/Variant.cpp b/src/libcalamares/utils/Variant.cpp new file mode 100644 index 000000000..f11853916 --- /dev/null +++ b/src/libcalamares/utils/Variant.cpp @@ -0,0 +1,107 @@ +/* === This file is part of Calamares - === + * + * Copyright 2013-2016, Teo Mrnjavac + * Copyright 2018, Adriaan de Groot + * + * Originally from Tomahawk, portions: + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Leo Franchi + * Copyright 2010-2012, Jeff Mitchell + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#include "Variant.h" + +#include "Logger.h" + +#include +#include + +namespace CalamaresUtils +{ +bool +getBool( const QVariantMap& map, const QString& key, bool d ) +{ + bool result = d; + if ( map.contains( key ) ) + { + auto v = map.value( key ); + if ( v.type() == QVariant::Bool ) + result = v.toBool(); + } + + return result; +} + +QString +getString(const QVariantMap& map, const QString& key) +{ + if ( map.contains( key ) ) + { + auto v = map.value( key ); + if ( v.type() == QVariant::String ) + return v.toString(); + } + return QString(); +} + +int +getInteger( const QVariantMap& map, const QString& key, int d ) +{ + int result = d; + if ( map.contains( key ) ) + { + auto v = map.value( key ); + if ( v.type() == QVariant::Int ) + result = v.toInt(); + } + + return result; +} + +double +getDouble( const QVariantMap& map, const QString& key, double d ) +{ + double result = d; + if ( map.contains( key ) ) + { + auto v = map.value( key ); + if ( v.type() == QVariant::Int ) + result = v.toInt(); + else if ( v.type() == QVariant::Double ) + result = v.toDouble(); + } + + return result; +} + +QVariantMap +getSubMap( const QVariantMap& map, const QString& key, bool& success ) +{ + success = false; + + if ( map.contains( key ) ) + { + auto v = map.value( key ); + if ( v.type() == QVariant::Map ) + { + success = true; + return v.toMap(); + } + } + return QVariantMap(); +} + +} diff --git a/src/libcalamares/utils/Variant.h b/src/libcalamares/utils/Variant.h new file mode 100644 index 000000000..e60eccb4e --- /dev/null +++ b/src/libcalamares/utils/Variant.h @@ -0,0 +1,62 @@ +/* === This file is part of Calamares - === + * + * Copyright 2013-2016, Teo Mrnjavac + * Copyright 2018, Adriaan de Groot + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#ifndef UTILS_VARIANT_H +#define UTILS_VARIANT_H + +#include "DllMacro.h" + +#include +#include + +namespace CalamaresUtils +{ + /** + * Get a bool value from a mapping with a given key; returns the default + * if no value is stored in the map. + */ + DLLEXPORT bool getBool( const QVariantMap& map, const QString& key, bool d ); + + /** + * Get a string value from a mapping; returns empty QString if no value. + */ + DLLEXPORT QString getString( const QVariantMap& map, const QString& key ); + + /** + * Get an integer value from a mapping; returns @p d if no value. + */ + DLLEXPORT int getInteger( const QVariantMap& map, const QString& key, int d ); + + /** + * Get a double value from a mapping (integers are converted); returns @p d if no value. + */ + DLLEXPORT double getDouble( const QVariantMap& map, const QString& key, double d ); + + /** + * Returns a sub-map (i.e. a nested map) from the given mapping with the + * given key. @p success is set to true if the @p key exists + * in @p map and converts to a map, false otherwise. + * + * Returns an empty map if there is no such key or it is not a map-value. + * (e.g. if @p success is false). + */ + DLLEXPORT QVariantMap getSubMap( const QVariantMap& map, const QString& key, bool& success ); +} // namespace + +#endif From 090aee91960f77df8f2fa4fdee25cfa6b23fc269 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 05:51:27 -0400 Subject: [PATCH 02/11] Modules: adjust to split-out utils/Variant.h - Most modules only needed the variant support, not the "whole" CalamaresUtils header. - While here improve ordering of headers as well. --- .../contextualprocess/ContextualProcessJob.cpp | 2 +- src/modules/fsresizer/ResizeFSJob.cpp | 2 +- src/modules/license/LicensePage.cpp | 2 +- src/modules/locale/GeoIPJSON.cpp | 2 +- src/modules/locale/LocaleViewStep.cpp | 2 +- src/modules/netinstall/NetInstallViewStep.cpp | 2 +- src/modules/partition/core/PartitionCoreModule.cpp | 3 ++- src/modules/partition/gui/PartitionViewStep.cpp | 11 +++++++---- src/modules/plasmalnf/PlasmaLnfViewStep.cpp | 2 +- src/modules/shellprocess/ShellProcessJob.cpp | 3 +-- src/modules/tracking/TrackingViewStep.cpp | 14 ++++++++------ src/modules/users/UsersViewStep.cpp | 3 ++- 12 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/modules/contextualprocess/ContextualProcessJob.cpp b/src/modules/contextualprocess/ContextualProcessJob.cpp index d79297029..428e54cd5 100644 --- a/src/modules/contextualprocess/ContextualProcessJob.cpp +++ b/src/modules/contextualprocess/ContextualProcessJob.cpp @@ -26,9 +26,9 @@ #include "JobQueue.h" #include "GlobalStorage.h" -#include "utils/CalamaresUtils.h" #include "utils/CommandList.h" #include "utils/Logger.h" +#include "utils/Variant.h" struct ValueCheck : public QPair { diff --git a/src/modules/fsresizer/ResizeFSJob.cpp b/src/modules/fsresizer/ResizeFSJob.cpp index a44815345..c8224a4c4 100644 --- a/src/modules/fsresizer/ResizeFSJob.cpp +++ b/src/modules/fsresizer/ResizeFSJob.cpp @@ -33,9 +33,9 @@ #include "JobQueue.h" #include "GlobalStorage.h" -#include "utils/CalamaresUtils.h" #include "utils/Logger.h" #include "utils/Units.h" +#include "utils/Variant.h" #include "modules/partition/core/PartitionIterator.h" diff --git a/src/modules/license/LicensePage.cpp b/src/modules/license/LicensePage.cpp index f52c68f63..3c241e467 100644 --- a/src/modules/license/LicensePage.cpp +++ b/src/modules/license/LicensePage.cpp @@ -28,11 +28,11 @@ #include "GlobalStorage.h" #include "ViewManager.h" -#include "utils/CalamaresUtils.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" #include "utils/NamedEnum.h" #include "utils/Retranslator.h" +#include "utils/Variant.h" #include #include diff --git a/src/modules/locale/GeoIPJSON.cpp b/src/modules/locale/GeoIPJSON.cpp index d6a309af7..81e0ff0e7 100644 --- a/src/modules/locale/GeoIPJSON.cpp +++ b/src/modules/locale/GeoIPJSON.cpp @@ -19,8 +19,8 @@ #include "GeoIPJSON.h" -#include "utils/CalamaresUtils.h" #include "utils/Logger.h" +#include "utils/Variant.h" #include "utils/YamlUtils.h" #include diff --git a/src/modules/locale/LocaleViewStep.cpp b/src/modules/locale/LocaleViewStep.cpp index b78365dc2..c432f84d6 100644 --- a/src/modules/locale/LocaleViewStep.cpp +++ b/src/modules/locale/LocaleViewStep.cpp @@ -31,9 +31,9 @@ #include "timezonewidget/localeglobal.h" #include "widgets/WaitingWidget.h" -#include "utils/CalamaresUtils.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" +#include "utils/Variant.h" #include "utils/YamlUtils.h" #include diff --git a/src/modules/netinstall/NetInstallViewStep.cpp b/src/modules/netinstall/NetInstallViewStep.cpp index 9964dcec3..fcb76be5a 100644 --- a/src/modules/netinstall/NetInstallViewStep.cpp +++ b/src/modules/netinstall/NetInstallViewStep.cpp @@ -23,8 +23,8 @@ #include "JobQueue.h" #include "GlobalStorage.h" -#include "utils/CalamaresUtils.h" #include "utils/Logger.h" +#include "utils/Variant.h" #include "NetInstallPage.h" diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index e042b23e2..183fdfcac 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -44,7 +44,8 @@ #include "jobs/ResizePartitionJob.h" #include "jobs/ResizeVolumeGroupJob.h" #include "jobs/SetPartitionFlagsJob.h" -#include "utils/CalamaresUtils.h" + +#include "utils/Variant.h" #ifdef DEBUG_PARTITION_LAME #include "JobExample.h" diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 02d289518..2e186b3a8 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -33,16 +33,19 @@ #include "gui/PartitionBarsView.h" #include "gui/PartitionLabelsView.h" +#include "Branding.h" #include "CalamaresVersion.h" +#include "GlobalStorage.h" +#include "Job.h" +#include "JobQueue.h" + #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" #include "utils/NamedEnum.h" #include "utils/Retranslator.h" +#include "utils/Variant.h" #include "widgets/WaitingWidget.h" -#include "GlobalStorage.h" -#include "JobQueue.h" -#include "Job.h" -#include "Branding.h" + #include #include diff --git a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp index 5525f36fc..ec5258c64 100644 --- a/src/modules/plasmalnf/PlasmaLnfViewStep.cpp +++ b/src/modules/plasmalnf/PlasmaLnfViewStep.cpp @@ -21,8 +21,8 @@ #include "PlasmaLnfPage.h" #include "ThemeInfo.h" -#include "utils/CalamaresUtils.h" #include "utils/Logger.h" +#include "utils/Variant.h" #include #include diff --git a/src/modules/shellprocess/ShellProcessJob.cpp b/src/modules/shellprocess/ShellProcessJob.cpp index 19c7bc8f1..d688540ae 100644 --- a/src/modules/shellprocess/ShellProcessJob.cpp +++ b/src/modules/shellprocess/ShellProcessJob.cpp @@ -26,10 +26,9 @@ #include "JobQueue.h" #include "GlobalStorage.h" -#include "utils/CalamaresUtils.h" -#include "utils/CalamaresUtilsSystem.h" #include "utils/CommandList.h" #include "utils/Logger.h" +#include "utils/Variant.h" ShellProcessJob::ShellProcessJob( QObject* parent ) : Calamares::CppJob( parent ) diff --git a/src/modules/tracking/TrackingViewStep.cpp b/src/modules/tracking/TrackingViewStep.cpp index 412156833..cb48b340b 100644 --- a/src/modules/tracking/TrackingViewStep.cpp +++ b/src/modules/tracking/TrackingViewStep.cpp @@ -16,15 +16,17 @@ * along with Calamares. If not, see . */ -#include "JobQueue.h" -#include "GlobalStorage.h" -#include "utils/Logger.h" -#include "utils/CalamaresUtils.h" -#include "utils/CalamaresUtilsSystem.h" +#include "TrackingViewStep.h" #include "TrackingJobs.h" #include "TrackingPage.h" -#include "TrackingViewStep.h" + +#include "JobQueue.h" +#include "GlobalStorage.h" + +#include "utils/Logger.h" +#include "utils/CalamaresUtilsSystem.h" +#include "utils/Variant.h" #include #include diff --git a/src/modules/users/UsersViewStep.cpp b/src/modules/users/UsersViewStep.cpp index 3b1e6a5ad..4582a9e85 100644 --- a/src/modules/users/UsersViewStep.cpp +++ b/src/modules/users/UsersViewStep.cpp @@ -22,8 +22,9 @@ #include "UsersPage.h" -#include "utils/CalamaresUtils.h" +// #include "utils/CalamaresUtils.h" #include "utils/Logger.h" +#include "utils/Variant.h" #include "GlobalStorage.h" #include "JobQueue.h" From f076dd76ad0902fc4d5338f00573625df790352b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 06:04:55 -0400 Subject: [PATCH 03/11] [libcalamares] Rename YamlUtils.h - Since we have the utils/ filesystem namespace, and use CalamaresUtils:: as C++ namespace, simplify naming. --- src/calamares/testmain.cpp | 2 +- src/libcalamares/CMakeLists.txt | 2 +- src/libcalamares/GlobalStorage.cpp | 2 +- src/libcalamares/Settings.cpp | 2 +- src/libcalamares/Tests.cpp | 2 +- src/libcalamares/utils/{YamlUtils.cpp => Yaml.cpp} | 2 +- src/libcalamares/utils/{YamlUtils.h => Yaml.h} | 8 ++++---- src/libcalamaresui/Branding.cpp | 2 +- src/libcalamaresui/modulesystem/Module.cpp | 2 +- src/libcalamaresui/modulesystem/ModuleManager.cpp | 2 +- src/modules/contextualprocess/Tests.cpp | 2 +- src/modules/fsresizer/Tests.cpp | 2 +- src/modules/locale/GeoIPJSON.cpp | 2 +- src/modules/locale/LocaleViewStep.cpp | 2 +- src/modules/netinstall/NetInstallPage.cpp | 2 +- src/modules/netinstall/PackageModel.cpp | 2 +- src/modules/shellprocess/Tests.cpp | 2 +- src/modules/test_conf.cpp | 2 +- 18 files changed, 21 insertions(+), 21 deletions(-) rename src/libcalamares/utils/{YamlUtils.cpp => Yaml.cpp} (99%) rename src/libcalamares/utils/{YamlUtils.h => Yaml.h} (97%) diff --git a/src/calamares/testmain.cpp b/src/calamares/testmain.cpp index 982a9b4c2..11ea9eaca 100644 --- a/src/calamares/testmain.cpp +++ b/src/calamares/testmain.cpp @@ -23,7 +23,7 @@ */ #include "utils/Logger.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include "modulesystem/Module.h" #include "GlobalStorage.h" diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 2814b02a0..bd42ba5c5 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -28,7 +28,7 @@ set( utilsSources utils/PluginFactory.cpp utils/Retranslator.cpp utils/Variant.cpp - utils/YamlUtils.cpp + utils/Yaml.cpp ) set( kdsagSources kdsingleapplicationguard/kdsingleapplicationguard.cpp diff --git a/src/libcalamares/GlobalStorage.cpp b/src/libcalamares/GlobalStorage.cpp index 54331eb3e..73236a311 100644 --- a/src/libcalamares/GlobalStorage.cpp +++ b/src/libcalamares/GlobalStorage.cpp @@ -21,7 +21,7 @@ #include "JobQueue.h" #include "utils/Logger.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include #include diff --git a/src/libcalamares/Settings.cpp b/src/libcalamares/Settings.cpp index 74b99c417..1ba58ccdf 100644 --- a/src/libcalamares/Settings.cpp +++ b/src/libcalamares/Settings.cpp @@ -23,7 +23,7 @@ #include "utils/CalamaresUtils.h" #include "utils/Logger.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include #include diff --git a/src/libcalamares/Tests.cpp b/src/libcalamares/Tests.cpp index e8566887d..615cb51a7 100644 --- a/src/libcalamares/Tests.cpp +++ b/src/libcalamares/Tests.cpp @@ -19,7 +19,7 @@ #include "Tests.h" #include "utils/Logger.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include diff --git a/src/libcalamares/utils/YamlUtils.cpp b/src/libcalamares/utils/Yaml.cpp similarity index 99% rename from src/libcalamares/utils/YamlUtils.cpp rename to src/libcalamares/utils/Yaml.cpp index b60978919..aa7ef6c2e 100644 --- a/src/libcalamares/utils/YamlUtils.cpp +++ b/src/libcalamares/utils/Yaml.cpp @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with Calamares. If not, see . */ -#include "YamlUtils.h" +#include "Yaml.h" #include "utils/Logger.h" diff --git a/src/libcalamares/utils/YamlUtils.h b/src/libcalamares/utils/Yaml.h similarity index 97% rename from src/libcalamares/utils/YamlUtils.h rename to src/libcalamares/utils/Yaml.h index 68268efdf..8755be336 100644 --- a/src/libcalamares/utils/YamlUtils.h +++ b/src/libcalamares/utils/Yaml.h @@ -17,8 +17,8 @@ * along with Calamares. If not, see . */ -#ifndef YAMLUTILS_H -#define YAMLUTILS_H +#ifndef UTILS_YAML_H +#define UTILS_YAML_H #include #include @@ -77,6 +77,6 @@ void explainYamlException( const YAML::Exception& e, const QByteArray& data, con void explainYamlException( const YAML::Exception& e, const QByteArray& data, const QString& label ); void explainYamlException( const YAML::Exception& e, const QByteArray& data ); -} //ns +} // namespace -#endif // YAMLUTILS_H +#endif diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index 22248ae53..e3da98614 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -26,7 +26,7 @@ #include "utils/ImageRegistry.h" #include "utils/Logger.h" #include "utils/NamedEnum.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include #include diff --git a/src/libcalamaresui/modulesystem/Module.cpp b/src/libcalamaresui/modulesystem/Module.cpp index 97833edb2..de2cb79a5 100644 --- a/src/libcalamaresui/modulesystem/Module.cpp +++ b/src/libcalamaresui/modulesystem/Module.cpp @@ -23,7 +23,7 @@ #include "CppJobModule.h" #include "ViewModule.h" #include "utils/CalamaresUtils.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include "utils/Logger.h" #include "Settings.h" #include "CalamaresConfig.h" diff --git a/src/libcalamaresui/modulesystem/ModuleManager.cpp b/src/libcalamaresui/modulesystem/ModuleManager.cpp index d2aa3f5c8..32fe09033 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.cpp +++ b/src/libcalamaresui/modulesystem/ModuleManager.cpp @@ -26,7 +26,7 @@ #include "ViewManager.h" #include "utils/Logger.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include #include diff --git a/src/modules/contextualprocess/Tests.cpp b/src/modules/contextualprocess/Tests.cpp index 055e35c53..51319c220 100644 --- a/src/modules/contextualprocess/Tests.cpp +++ b/src/modules/contextualprocess/Tests.cpp @@ -20,7 +20,7 @@ #include "ContextualProcessJob.h" #include "utils/CommandList.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include diff --git a/src/modules/fsresizer/Tests.cpp b/src/modules/fsresizer/Tests.cpp index 3c204327a..190a1d279 100644 --- a/src/modules/fsresizer/Tests.cpp +++ b/src/modules/fsresizer/Tests.cpp @@ -23,7 +23,7 @@ #include "Settings.h" #include "utils/Logger.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include diff --git a/src/modules/locale/GeoIPJSON.cpp b/src/modules/locale/GeoIPJSON.cpp index 81e0ff0e7..8e5cc2e5c 100644 --- a/src/modules/locale/GeoIPJSON.cpp +++ b/src/modules/locale/GeoIPJSON.cpp @@ -21,7 +21,7 @@ #include "utils/Logger.h" #include "utils/Variant.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include diff --git a/src/modules/locale/LocaleViewStep.cpp b/src/modules/locale/LocaleViewStep.cpp index c432f84d6..d321b8501 100644 --- a/src/modules/locale/LocaleViewStep.cpp +++ b/src/modules/locale/LocaleViewStep.cpp @@ -34,7 +34,7 @@ #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" #include "utils/Variant.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include #include diff --git a/src/modules/netinstall/NetInstallPage.cpp b/src/modules/netinstall/NetInstallPage.cpp index 607251488..dfa94744d 100644 --- a/src/modules/netinstall/NetInstallPage.cpp +++ b/src/modules/netinstall/NetInstallPage.cpp @@ -28,7 +28,7 @@ #include "utils/Logger.h" #include "utils/Retranslator.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include #include diff --git a/src/modules/netinstall/PackageModel.cpp b/src/modules/netinstall/PackageModel.cpp index 588646816..2fde7695e 100644 --- a/src/modules/netinstall/PackageModel.cpp +++ b/src/modules/netinstall/PackageModel.cpp @@ -19,7 +19,7 @@ #include "PackageModel.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" PackageModel::PackageModel( const YAML::Node& data, QObject* parent ) : QAbstractItemModel( parent ), diff --git a/src/modules/shellprocess/Tests.cpp b/src/modules/shellprocess/Tests.cpp index 3672586f0..488f4a7af 100644 --- a/src/modules/shellprocess/Tests.cpp +++ b/src/modules/shellprocess/Tests.cpp @@ -24,7 +24,7 @@ #include "utils/CommandList.h" #include "utils/Logger.h" -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include diff --git a/src/modules/test_conf.cpp b/src/modules/test_conf.cpp index d0746421f..06247bfed 100644 --- a/src/modules/test_conf.cpp +++ b/src/modules/test_conf.cpp @@ -21,7 +21,7 @@ * shipped with each module for correctness -- well, for parseability. */ -#include "utils/YamlUtils.h" +#include "utils/Yaml.h" #include #include From 432b8848ab3fd3237d676eac24508efe2933b9ef Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 06:12:18 -0400 Subject: [PATCH 04/11] [libcalamares] Make #include guards consistent --- src/libcalamares/utils/CalamaresUtils.h | 8 ++++---- src/libcalamares/utils/CalamaresUtilsSystem.h | 8 ++++---- src/libcalamares/utils/CommandList.h | 6 +++--- src/libcalamares/utils/LocaleLabel.h | 12 ++++++------ src/libcalamares/utils/Logger.h | 8 ++++---- src/libcalamares/utils/NamedEnum.h | 5 ++--- src/libcalamares/utils/NamedSuffix.h | 5 ++--- src/libcalamares/utils/PluginFactory.h | 8 ++++---- src/libcalamares/utils/PluginFactory_p.h | 8 ++++---- src/libcalamares/utils/Retranslator.h | 8 ++++---- src/libcalamares/utils/Units.h | 4 ++-- 11 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/CalamaresUtils.h index 2eb202b2c..85661a94b 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/CalamaresUtils.h @@ -22,8 +22,8 @@ * along with Calamares. If not, see . */ -#ifndef CALAMARESUTILS_H -#define CALAMARESUTILS_H +#ifndef UTILS_CALAMARESUTILS_H +#define UTILS_CALAMARESUTILS_H #include "DllMacro.h" @@ -108,6 +108,6 @@ namespace CalamaresUtils * @brief crash makes Calamares crash immediately. */ DLLEXPORT void crash(); -} +} // namespace -#endif // CALAMARESUTILS_H +#endif diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.h b/src/libcalamares/utils/CalamaresUtilsSystem.h index 2b5967591..6809859ee 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.h +++ b/src/libcalamares/utils/CalamaresUtilsSystem.h @@ -16,8 +16,8 @@ * You should have received a copy of the GNU General Public License * along with Calamares. If not, see . */ -#ifndef CALAMARESUTILSSYSTEM_H -#define CALAMARESUTILSSYSTEM_H +#ifndef UTILS_CALAMARESUTILSSYSTEM_H +#define UTILS_CALAMARESUTILSSYSTEM_H #include "DllMacro.h" @@ -235,6 +235,6 @@ private: bool m_doChroot; }; -} +} // namespace -#endif // CALAMARESUTILSSYSTEM_H +#endif diff --git a/src/libcalamares/utils/CommandList.h b/src/libcalamares/utils/CommandList.h index 9faf705f2..3dccdec6a 100644 --- a/src/libcalamares/utils/CommandList.h +++ b/src/libcalamares/utils/CommandList.h @@ -16,8 +16,8 @@ * along with Calamares. If not, see . */ -#ifndef COMMANDLIST_H -#define COMMANDLIST_H +#ifndef UTILS_COMMANDLIST_H +#define UTILS_COMMANDLIST_H #include "Job.h" @@ -110,4 +110,4 @@ private: } ; } // namespace -#endif // COMMANDLIST_H +#endif diff --git a/src/libcalamares/utils/LocaleLabel.h b/src/libcalamares/utils/LocaleLabel.h index d3113c869..b56b29f33 100644 --- a/src/libcalamares/utils/LocaleLabel.h +++ b/src/libcalamares/utils/LocaleLabel.h @@ -17,8 +17,8 @@ * along with Calamares. If not, see . */ -#ifndef LIBCALAMARES_LOCALELABEL_H -#define LIBCALAMARES_LOCALELABEL_H +#ifndef UTILS_LOCALELABEL_H +#define UTILS_LOCALELABEL_H #include #include @@ -41,7 +41,7 @@ public: /** @brief Empty locale. This uses the system-default locale. */ LocaleLabel(); - + /** @brief Construct from a locale name. * * The @p localeName should be one that Qt recognizes, e.g. en_US or ar_EY. @@ -100,7 +100,7 @@ public: protected: void setLabels( const QString& name, LabelFormat format ); - + QLocale m_locale; QString m_localeId; // the locale identifier, e.g. "en_GB" QString m_label; // the native name of the locale @@ -108,6 +108,6 @@ protected: } ; -} // namespace CalamaresUtils +} // namespace -#endif // LIBCALAMARES_LOCALELABEL_H +#endif diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index d7af886b3..4d1534e4b 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -18,8 +18,8 @@ * along with Calamares. If not, see . */ -#ifndef CALAMARES_LOGGER_H -#define CALAMARES_LOGGER_H +#ifndef UTILS_LOGGER_H +#define UTILS_LOGGER_H #include @@ -186,10 +186,10 @@ namespace Logger s << Continuation << it.key().toUtf8().constData() << ':' << ' ' << toString( it.value() ).toUtf8().constData(); return s; } -} +} // namespace #define cDebug Logger::CDebug #define cWarning() Logger::CDebug(Logger::LOGWARNING) #define cError() Logger::CDebug(Logger::LOGERROR) -#endif // CALAMARES_LOGGER_H +#endif diff --git a/src/libcalamares/utils/NamedEnum.h b/src/libcalamares/utils/NamedEnum.h index fd3791e72..5ff62f54c 100644 --- a/src/libcalamares/utils/NamedEnum.h +++ b/src/libcalamares/utils/NamedEnum.h @@ -26,8 +26,8 @@ * in printing integer (underlying) values of an enum. */ -#ifndef LIBCALAMARES_NAMEDENUM_H -#define LIBCALAMARES_NAMEDENUM_H +#ifndef UTILS_NAMEDENUM_H +#define UTILS_NAMEDENUM_H #include @@ -108,5 +108,4 @@ constexpr typename std::underlying_type::type smash( const E e ) return static_cast::type>( e ); } - #endif diff --git a/src/libcalamares/utils/NamedSuffix.h b/src/libcalamares/utils/NamedSuffix.h index d4a0ed4b7..f58277698 100644 --- a/src/libcalamares/utils/NamedSuffix.h +++ b/src/libcalamares/utils/NamedSuffix.h @@ -36,8 +36,8 @@ * } ; */ -#ifndef LIBCALAMARES_NAMEDSUFFIX_H -#define LIBCALAMARES_NAMEDSUFFIX_H +#ifndef UTILS_NAMEDSUFFIX_H +#define UTILS_NAMEDSUFFIX_H #include "NamedEnum.h" @@ -104,5 +104,4 @@ protected: unit_t m_unit; }; - #endif diff --git a/src/libcalamares/utils/PluginFactory.h b/src/libcalamares/utils/PluginFactory.h index 7338d53de..1ab485779 100644 --- a/src/libcalamares/utils/PluginFactory.h +++ b/src/libcalamares/utils/PluginFactory.h @@ -21,8 +21,8 @@ * along with Calamares. If not, see . */ -#ifndef CALAMARESPLUGINFACTORY_H -#define CALAMARESPLUGINFACTORY_H +#ifndef UTILS_PLUGINFACTORY_H +#define UTILS_PLUGINFACTORY_H #include "DllMacro.h" @@ -311,8 +311,8 @@ inline T* PluginFactory::create( const QString& keyword, QObject* parent ) return t; } -} +} // namespace Q_DECLARE_INTERFACE( Calamares::PluginFactory, CalamaresPluginFactory_iid ) -#endif // CALAMARESPLUGINFACTORY_H +#endif diff --git a/src/libcalamares/utils/PluginFactory_p.h b/src/libcalamares/utils/PluginFactory_p.h index ce50e8b46..7a6db217e 100644 --- a/src/libcalamares/utils/PluginFactory_p.h +++ b/src/libcalamares/utils/PluginFactory_p.h @@ -20,8 +20,8 @@ * along with Calamares. If not, see . */ -#ifndef CALAMARESPLUGINFACTORY_P_H -#define CALAMARESPLUGINFACTORY_P_H +#ifndef UTILS_PLUGINFACTORY_P_H +#define UTILS_PLUGINFACTORY_P_H #include "PluginFactory.h" @@ -49,6 +49,6 @@ protected: PluginFactory *q_ptr; }; -} +} // namespace -#endif // CALAMARESPLUGINFACTORY_P_H +#endif diff --git a/src/libcalamares/utils/Retranslator.h b/src/libcalamares/utils/Retranslator.h index 4c719a6bf..af561a9ce 100644 --- a/src/libcalamares/utils/Retranslator.h +++ b/src/libcalamares/utils/Retranslator.h @@ -16,8 +16,8 @@ * along with Calamares. If not, see . */ -#ifndef CALAMARESUTILS_RETRANSLATOR_H -#define CALAMARESUTILS_RETRANSLATOR_H +#ifndef UTILS_RETRANSLATOR_H +#define UTILS_RETRANSLATOR_H #include #include @@ -48,11 +48,11 @@ private: }; -} // namespace CalamaresUtils +} // namespace #define CALAMARES_RETRANSLATE(body) \ CalamaresUtils::Retranslator::attachRetranslator( this, [=] { body } ); #define CALAMARES_RETRANSLATE_WIDGET(widget,body) \ CalamaresUtils::Retranslator::attachRetranslator( widget, [=] { body } ); -#endif // CALAMARESUTILS_RETRANSLATOR_H +#endif diff --git a/src/libcalamares/utils/Units.h b/src/libcalamares/utils/Units.h index 34f80b17f..74c809362 100644 --- a/src/libcalamares/utils/Units.h +++ b/src/libcalamares/utils/Units.h @@ -17,8 +17,8 @@ * along with Calamares. If not, see . */ -#ifndef LIBCALAMARES_UTILS_UNITS_H -#define LIBCALAMARES_UTILS_UNITS_H +#ifndef UTILS_UNITS_H +#define UTILS_UNITS_H #include From 2907b488445dc4fbeccc1b15331614d13b702065 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 06:13:32 -0400 Subject: [PATCH 05/11] [libcalamaresui] Move RESPATH #define to the one place it's used --- src/libcalamares/utils/CalamaresUtils.h | 2 -- src/libcalamaresui/utils/CalamaresUtilsGui.cpp | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/CalamaresUtils.h index 85661a94b..d4f48ec2a 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/CalamaresUtils.h @@ -29,8 +29,6 @@ #include -#define RESPATH ":/data/" - class QDir; class QObject; diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp index cdc3f2ecb..808c805cb 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.cpp +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.cpp @@ -29,6 +29,8 @@ #include #include +#define RESPATH ":/data/" + namespace CalamaresUtils { From 50694ef610fca5abee59a399997234476304e939 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 06:22:24 -0400 Subject: [PATCH 06/11] [libcalamares] Split dirs-functionality into separate file --- src/libcalamares/CMakeLists.txt | 1 + src/libcalamares/utils/CalamaresUtils.cpp | 152 ----------------- src/libcalamares/utils/CalamaresUtils.h | 38 ----- src/libcalamares/utils/Dirs.cpp | 194 ++++++++++++++++++++++ src/libcalamares/utils/Dirs.h | 73 ++++++++ 5 files changed, 268 insertions(+), 190 deletions(-) create mode 100644 src/libcalamares/utils/Dirs.cpp create mode 100644 src/libcalamares/utils/Dirs.h diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index bd42ba5c5..5efd850a9 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -23,6 +23,7 @@ set( utilsSources utils/CalamaresUtils.cpp utils/CalamaresUtilsSystem.cpp utils/CommandList.cpp + utils/Dirs.cpp utils/LocaleLabel.cpp utils/Logger.cpp utils/PluginFactory.cpp diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index 6d8862269..25eceb159 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -41,154 +41,10 @@ using std::cerr; namespace CalamaresUtils { -static QDir s_appDataDir( CMAKE_INSTALL_FULL_DATADIR ); -static QDir s_qmlModulesDir( QString( CMAKE_INSTALL_FULL_DATADIR ) + "/qml" ); -static bool s_isAppDataDirOverridden = false; - static QTranslator* s_brandingTranslator = nullptr; static QTranslator* s_translator = nullptr; static QString s_translatorLocaleName; -static bool s_haveExtraDirs = false; -static QStringList s_extraConfigDirs; -static QStringList s_extraDataDirs; - -static bool -isWritableDir( const QDir& dir ) -{ - // We log with cerr here because we might be looking for the log dir - QString path = dir.absolutePath(); - if ( !dir.exists() ) - { - if ( !dir.mkpath( "." ) ) - { - cerr << "warning: failed to create " << qPrintable( path ) << '\n'; - return false; - } - return true; - } - - QFileInfo info( path ); - if ( !info.isDir() ) - { - cerr << "warning: " << qPrintable( path ) << " is not a dir\n"; - return false; - } - if ( !info.isWritable() ) - { - cerr << "warning: " << qPrintable( path ) << " is not writable\n"; - return false; - } - return true; -} - - -QDir -qmlModulesDir() -{ - return s_qmlModulesDir; -} - - -void -setAppDataDir( const QDir& dir ) -{ - s_appDataDir = dir; - s_isAppDataDirOverridden = true; -} - -/* Split $ENV{@p name} on :, append to @p l, making sure each ends in / */ -static void -mungeEnvironment( QStringList& l, const char* name, const char* defaultDirs ) -{ - static const QString calamaresSubdir = QStringLiteral( "calamares/" ); - - QStringList dirs = QString( qgetenv( name ) ).split( ':' ); - if ( dirs.isEmpty() ) - dirs = QString( defaultDirs ).split( ':' ); - - for ( auto s : dirs ) - { - if ( s.isEmpty() ) - continue; - if ( s.endsWith( '/' ) ) - l << ( s + calamaresSubdir ) << s; - else - l << ( s + '/' + calamaresSubdir ) << ( s + '/' ); - } -} - -void -setXdgDirs() -{ - mungeEnvironment( s_extraConfigDirs, "XDG_CONFIG_DIRS", "/etc/xdg" ); - mungeEnvironment( s_extraDataDirs, "XDG_DATA_DIRS", "/usr/local/share/:/usr/share/" ); - - s_haveExtraDirs = !( s_extraConfigDirs.isEmpty() && s_extraDataDirs.isEmpty() ); -} - -QStringList -extraConfigDirs() -{ - if ( s_haveExtraDirs ) - return s_extraConfigDirs; - return QStringList(); -} - -QStringList -extraDataDirs() -{ - if ( s_haveExtraDirs ) - return s_extraDataDirs; - return QStringList(); -} - -bool -haveExtraDirs() -{ - return s_haveExtraDirs && ( !s_extraConfigDirs.isEmpty() || !s_extraDataDirs.isEmpty() ); -} - -bool -isAppDataDirOverridden() -{ - return s_isAppDataDirOverridden; -} - - -QDir -appDataDir() -{ - return s_appDataDir; -} - - -QDir -systemLibDir() -{ - QDir path( CMAKE_INSTALL_FULL_LIBDIR ); - return path; -} - - -QDir -appLogDir() -{ - QString path = QStandardPaths::writableLocation( QStandardPaths::CacheLocation ); - QDir dir( path ); - if ( isWritableDir( dir ) ) - return dir; - - cerr << "warning: Could not find a standard writable location for log dir, falling back to $HOME\n"; - dir = QDir::home(); - if ( isWritableDir( dir ) ) - return dir; - - cerr << "warning: Found no writable location for log dir, falling back to the temp dir\n"; - return QDir::temp(); -} - - void installTranslator( const QLocale& locale, const QString& brandingTranslationsPrefix, @@ -278,14 +134,6 @@ translatorLocaleName() return s_translatorLocaleName; } - -void -setQmlModulesDir( const QDir& dir ) -{ - s_qmlModulesDir = dir; -} - - QString removeDiacritics( const QString& string ) { diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/CalamaresUtils.h index d4f48ec2a..49abf0cd6 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/CalamaresUtils.h @@ -37,26 +37,6 @@ class QObject; */ namespace CalamaresUtils { - DLLEXPORT QDir qmlModulesDir(); - - /** - * @brief appDataDir returns the directory with common application data. - * Defaults to CMAKE_INSTALL_FULL_DATADIR (usually /usr/share/calamares). - */ - DLLEXPORT QDir appDataDir(); - - /** - * @brief appLogDir returns the directory for Calamares logs. - * Defaults to QStandardPaths::CacheLocation (usually ~/.cache/Calamares). - */ - DLLEXPORT QDir appLogDir(); - - /** - * @brief systemLibDir returns the system's lib directory. - * Defaults to CMAKE_INSTALL_FULL_LIBDIR (usually /usr/lib64 or /usr/lib). - */ - DLLEXPORT QDir systemLibDir(); - /** * @brief installTranslator changes the application language. * @param locale the new locale. @@ -69,24 +49,6 @@ namespace CalamaresUtils DLLEXPORT QString translatorLocaleName(); - /** - * Override app data dir. Only for testing purposes. - */ - DLLEXPORT void setAppDataDir( const QDir& dir ); - DLLEXPORT bool isAppDataDirOverridden(); - - DLLEXPORT void setQmlModulesDir( const QDir& dir ); - - /** @brief Setup extra config and data dirs from the XDG variables. - */ - DLLEXPORT void setXdgDirs(); - /** @brief Are any extra directories configured? */ - DLLEXPORT bool haveExtraDirs(); - /** @brief XDG_CONFIG_DIRS, each guaranteed to end with / */ - DLLEXPORT QStringList extraConfigDirs(); - /** @brief XDG_DATA_DIRS, each guaranteed to end with / */ - DLLEXPORT QStringList extraDataDirs(); - /** * @brief removeDiacritics replaces letters with diacritics and ligatures with * alternative forms and digraphs. diff --git a/src/libcalamares/utils/Dirs.cpp b/src/libcalamares/utils/Dirs.cpp new file mode 100644 index 000000000..1fd309584 --- /dev/null +++ b/src/libcalamares/utils/Dirs.cpp @@ -0,0 +1,194 @@ +/* === This file is part of Calamares - === + * + * Copyright 2013-2016, Teo Mrnjavac + * Copyright 2018, Adriaan de Groot + * + * Originally from Tomahawk, portions: + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Leo Franchi + * Copyright 2010-2012, Jeff Mitchell + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#include "Dirs.h" + +#include "CalamaresConfig.h" +#include "Logger.h" + +#include +#include +#include +#include +#include +#include + +#include + +using std::cerr; + +namespace CalamaresUtils +{ + +static QDir s_appDataDir( CMAKE_INSTALL_FULL_DATADIR ); +static QDir s_qmlModulesDir( QString( CMAKE_INSTALL_FULL_DATADIR ) + "/qml" ); +static bool s_isAppDataDirOverridden = false; + +static bool s_haveExtraDirs = false; +static QStringList s_extraConfigDirs; +static QStringList s_extraDataDirs; + +static bool +isWritableDir( const QDir& dir ) +{ + // We log with cerr here because we might be looking for the log dir + QString path = dir.absolutePath(); + if ( !dir.exists() ) + { + if ( !dir.mkpath( "." ) ) + { + cerr << "warning: failed to create " << qPrintable( path ) << '\n'; + return false; + } + return true; + } + + QFileInfo info( path ); + if ( !info.isDir() ) + { + cerr << "warning: " << qPrintable( path ) << " is not a dir\n"; + return false; + } + if ( !info.isWritable() ) + { + cerr << "warning: " << qPrintable( path ) << " is not writable\n"; + return false; + } + return true; +} + + +QDir +qmlModulesDir() +{ + return s_qmlModulesDir; +} + + +void +setAppDataDir( const QDir& dir ) +{ + s_appDataDir = dir; + s_isAppDataDirOverridden = true; +} + +/* Split $ENV{@p name} on :, append to @p l, making sure each ends in / */ +static void +mungeEnvironment( QStringList& l, const char* name, const char* defaultDirs ) +{ + static const QString calamaresSubdir = QStringLiteral( "calamares/" ); + + QStringList dirs = QString( qgetenv( name ) ).split( ':' ); + if ( dirs.isEmpty() ) + dirs = QString( defaultDirs ).split( ':' ); + + for ( auto s : dirs ) + { + if ( s.isEmpty() ) + continue; + if ( s.endsWith( '/' ) ) + l << ( s + calamaresSubdir ) << s; + else + l << ( s + '/' + calamaresSubdir ) << ( s + '/' ); + } +} + +void +setXdgDirs() +{ + mungeEnvironment( s_extraConfigDirs, "XDG_CONFIG_DIRS", "/etc/xdg" ); + mungeEnvironment( s_extraDataDirs, "XDG_DATA_DIRS", "/usr/local/share/:/usr/share/" ); + + s_haveExtraDirs = !( s_extraConfigDirs.isEmpty() && s_extraDataDirs.isEmpty() ); +} + +QStringList +extraConfigDirs() +{ + if ( s_haveExtraDirs ) + return s_extraConfigDirs; + return QStringList(); +} + +QStringList +extraDataDirs() +{ + if ( s_haveExtraDirs ) + return s_extraDataDirs; + return QStringList(); +} + +bool +haveExtraDirs() +{ + return s_haveExtraDirs && ( !s_extraConfigDirs.isEmpty() || !s_extraDataDirs.isEmpty() ); +} + +bool +isAppDataDirOverridden() +{ + return s_isAppDataDirOverridden; +} + + +QDir +appDataDir() +{ + return s_appDataDir; +} + + +QDir +systemLibDir() +{ + QDir path( CMAKE_INSTALL_FULL_LIBDIR ); + return path; +} + + +QDir +appLogDir() +{ + QString path = QStandardPaths::writableLocation( QStandardPaths::CacheLocation ); + QDir dir( path ); + if ( isWritableDir( dir ) ) + return dir; + + cerr << "warning: Could not find a standard writable location for log dir, falling back to $HOME\n"; + dir = QDir::home(); + if ( isWritableDir( dir ) ) + return dir; + + cerr << "warning: Found no writable location for log dir, falling back to the temp dir\n"; + return QDir::temp(); +} + + +void +setQmlModulesDir( const QDir& dir ) +{ + s_qmlModulesDir = dir; +} + +} // namespace diff --git a/src/libcalamares/utils/Dirs.h b/src/libcalamares/utils/Dirs.h new file mode 100644 index 000000000..5532cb79b --- /dev/null +++ b/src/libcalamares/utils/Dirs.h @@ -0,0 +1,73 @@ +/* === This file is part of Calamares - === + * + * Copyright 2013-2016, Teo Mrnjavac + * Copyright 2018, Adriaan de Groot + * + * Originally from Tomahawk, portions: + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2011, Leo Franchi + * Copyright 2010-2012, Jeff Mitchell + * + * Calamares 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. + * + * Calamares 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 Calamares. If not, see . + */ + +#ifndef UTILS_DIRS_H +#define UTILS_DIRS_H + +#include "DllMacro.h" + +#include + +namespace CalamaresUtils +{ + DLLEXPORT QDir qmlModulesDir(); + + /** + * @brief appDataDir returns the directory with common application data. + * Defaults to CMAKE_INSTALL_FULL_DATADIR (usually /usr/share/calamares). + */ + DLLEXPORT QDir appDataDir(); + + /** + * @brief appLogDir returns the directory for Calamares logs. + * Defaults to QStandardPaths::CacheLocation (usually ~/.cache/Calamares). + */ + DLLEXPORT QDir appLogDir(); + + /** + * @brief systemLibDir returns the system's lib directory. + * Defaults to CMAKE_INSTALL_FULL_LIBDIR (usually /usr/lib64 or /usr/lib). + */ + DLLEXPORT QDir systemLibDir(); + + /** + * Override app data dir. Only for testing purposes. + */ + DLLEXPORT void setAppDataDir( const QDir& dir ); + DLLEXPORT bool isAppDataDirOverridden(); + + DLLEXPORT void setQmlModulesDir( const QDir& dir ); + + /** @brief Setup extra config and data dirs from the XDG variables. + */ + DLLEXPORT void setXdgDirs(); + /** @brief Are any extra directories configured? */ + DLLEXPORT bool haveExtraDirs(); + /** @brief XDG_CONFIG_DIRS, each guaranteed to end with / */ + DLLEXPORT QStringList extraConfigDirs(); + /** @brief XDG_DATA_DIRS, each guaranteed to end with / */ + DLLEXPORT QStringList extraDataDirs(); +} // namespace + +#endif From ac095d9ed0f004e719ae7a3da0f60e399f4887b8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 06:27:31 -0400 Subject: [PATCH 07/11] [libcalamares] [libcalamaresui] [calamares] Adjust to moved Dirs.h --- src/calamares/CalamaresApplication.cpp | 1 + src/calamares/main.cpp | 2 +- src/libcalamares/PythonHelper.cpp | 2 +- src/libcalamares/Settings.cpp | 5 +++-- src/libcalamares/utils/Logger.cpp | 2 +- src/libcalamaresui/ExecutionViewStep.cpp | 4 +++- src/libcalamaresui/modulesystem/Module.cpp | 15 ++++++++------- 7 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 0fd307548..81ec2d160 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -28,6 +28,7 @@ #include "modulesystem/ModuleManager.h" #include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsSystem.h" +#include "utils/Dirs.h" #include "utils/Logger.h" #include "JobQueue.h" #include "Branding.h" diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index e2b5da8bf..5ddda33c6 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -22,7 +22,7 @@ #include "CalamaresConfig.h" #include "kdsingleapplicationguard/kdsingleapplicationguard.h" -#include "utils/CalamaresUtils.h" +#include "utils/Dirs.h" #include "utils/Logger.h" #include "CalamaresConfig.h" diff --git a/src/libcalamares/PythonHelper.cpp b/src/libcalamares/PythonHelper.cpp index d6001055e..3c4d1cca6 100644 --- a/src/libcalamares/PythonHelper.cpp +++ b/src/libcalamares/PythonHelper.cpp @@ -19,7 +19,7 @@ #include "PythonHelper.h" -#include "utils/CalamaresUtils.h" +#include "utils/Dirs.h" #include "utils/Logger.h" #include diff --git a/src/libcalamares/Settings.cpp b/src/libcalamares/Settings.cpp index 1ba58ccdf..0b12d87fb 100644 --- a/src/libcalamares/Settings.cpp +++ b/src/libcalamares/Settings.cpp @@ -21,7 +21,8 @@ #include "Settings.h" -#include "utils/CalamaresUtils.h" +// #include "utils/CalamaresUtils.h" +#include "utils/Dirs.h" #include "utils/Logger.h" #include "utils/Yaml.h" @@ -275,7 +276,7 @@ Settings::disableCancel() const { return m_disableCancel; } - + bool Settings::dontCancel() const { diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index cbe711698..433e01fbb 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -30,7 +30,7 @@ #include #include -#include "utils/CalamaresUtils.h" +#include "utils/Dirs.h" #include "CalamaresVersion.h" #define LOGFILE_SIZE 1024 * 256 diff --git a/src/libcalamaresui/ExecutionViewStep.cpp b/src/libcalamaresui/ExecutionViewStep.cpp index b505102a4..2010bf120 100644 --- a/src/libcalamaresui/ExecutionViewStep.cpp +++ b/src/libcalamaresui/ExecutionViewStep.cpp @@ -26,10 +26,12 @@ #include "modulesystem/Module.h" #include "modulesystem/ModuleManager.h" #include "Settings.h" +#include "ViewManager.h" + #include "utils/CalamaresUtilsGui.h" +#include "utils/Dirs.h" #include "utils/Logger.h" #include "utils/Retranslator.h" -#include "ViewManager.h" #include #include diff --git a/src/libcalamaresui/modulesystem/Module.cpp b/src/libcalamaresui/modulesystem/Module.cpp index de2cb79a5..133ee5438 100644 --- a/src/libcalamaresui/modulesystem/Module.cpp +++ b/src/libcalamaresui/modulesystem/Module.cpp @@ -19,14 +19,15 @@ #include "Module.h" -#include "ProcessJobModule.h" -#include "CppJobModule.h" -#include "ViewModule.h" -#include "utils/CalamaresUtils.h" -#include "utils/Yaml.h" -#include "utils/Logger.h" -#include "Settings.h" #include "CalamaresConfig.h" +#include "CppJobModule.h" +#include "ProcessJobModule.h" +#include "Settings.h" +#include "ViewModule.h" + +#include "utils/Dirs.h" +#include "utils/Logger.h" +#include "utils/Yaml.h" #ifdef WITH_PYTHON #include "PythonJobModule.h" From 66c4445077631147ea6c18c5f3cfae17ac621210 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 06:33:55 -0400 Subject: [PATCH 08/11] [libcalamares] Move translation-related functions to Retranslator.h --- src/calamares/CalamaresApplication.cpp | 1 + src/libcalamares/utils/CalamaresUtils.cpp | 108 ---------------------- src/libcalamares/utils/CalamaresUtils.h | 12 --- src/libcalamares/utils/Retranslator.cpp | 96 +++++++++++++++++++ src/libcalamares/utils/Retranslator.h | 15 +++ 5 files changed, 112 insertions(+), 120 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 81ec2d160..2d5ea41f0 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -30,6 +30,7 @@ #include "utils/CalamaresUtilsSystem.h" #include "utils/Dirs.h" #include "utils/Logger.h" +#include "utils/Retranslator.h" #include "JobQueue.h" #include "Branding.h" #include "Settings.h" diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index 25eceb159..b44be6795 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -24,116 +24,8 @@ #include "CalamaresUtils.h" -#include "CalamaresConfig.h" -#include "Logger.h" - -#include -#include -#include -#include -#include -#include - -#include - -using std::cerr; - namespace CalamaresUtils { - -static QTranslator* s_brandingTranslator = nullptr; -static QTranslator* s_translator = nullptr; -static QString s_translatorLocaleName; - -void -installTranslator( const QLocale& locale, - const QString& brandingTranslationsPrefix, - QObject* parent ) -{ - QString localeName = locale.name(); - localeName.replace( "-", "_" ); - - if ( localeName == "C" ) - localeName = "en"; - - // Special case of sr@latin - // - // See top-level CMakeLists.txt about special cases for translation loading. - if ( locale.language() == QLocale::Language::Serbian && locale.script() == QLocale::Script::LatinScript ) - localeName = QStringLiteral( "sr@latin" ); - - cDebug() << "Looking for translations for" << localeName; - - QTranslator* translator = nullptr; - - // Branding translations - if ( !brandingTranslationsPrefix.isEmpty() ) - { - QString brandingTranslationsDirPath( brandingTranslationsPrefix ); - brandingTranslationsDirPath.truncate( brandingTranslationsPrefix.lastIndexOf( - QDir::separator() ) ); - QDir brandingTranslationsDir( brandingTranslationsDirPath ); - if ( brandingTranslationsDir.exists() ) - { - QString filenameBase( brandingTranslationsPrefix ); - filenameBase.remove( 0, brandingTranslationsPrefix.lastIndexOf( - QDir::separator() ) + 1 ); - translator = new QTranslator( parent ); - if ( translator->load( locale, - filenameBase, - "_", - brandingTranslationsDir.absolutePath() ) ) - { - cDebug() << Logger::SubEntry << "Branding using locale:" << localeName; - } - else - { - cDebug() << Logger::SubEntry << "Branding using default, system locale not found:" << localeName; - translator->load( brandingTranslationsPrefix + "en" ); - } - - if ( s_brandingTranslator ) - { - QCoreApplication::removeTranslator( s_brandingTranslator ); - delete s_brandingTranslator; - } - - QCoreApplication::installTranslator( translator ); - s_brandingTranslator = translator; - } - } - - // Calamares translations - translator = new QTranslator( parent ); - if ( translator->load( QString( ":/lang/calamares_" ) + localeName ) ) - { - cDebug() << Logger::SubEntry << "Calamares using locale:" << localeName; - } - else - { - cDebug() << Logger::SubEntry << "Calamares using default, system locale not found:" << localeName; - translator->load( QString( ":/lang/calamares_en" ) ); - } - - if ( s_translator ) - { - QCoreApplication::removeTranslator( s_translator ); - delete s_translator; - } - - QCoreApplication::installTranslator( translator ); - s_translator = translator; - - s_translatorLocaleName = localeName; -} - - -QString -translatorLocaleName() -{ - return s_translatorLocaleName; -} - QString removeDiacritics( const QString& string ) { diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/CalamaresUtils.h index 49abf0cd6..39d338d5c 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/CalamaresUtils.h @@ -37,18 +37,6 @@ class QObject; */ namespace CalamaresUtils { - /** - * @brief installTranslator changes the application language. - * @param locale the new locale. - * @param brandingTranslationsPrefix the branding path prefix, from Calamares::Branding. - * @param parent the parent QObject. - */ - DLLEXPORT void installTranslator( const QLocale& locale, - const QString& brandingTranslationsPrefix, - QObject* parent ); - - DLLEXPORT QString translatorLocaleName(); - /** * @brief removeDiacritics replaces letters with diacritics and ligatures with * alternative forms and digraphs. diff --git a/src/libcalamares/utils/Retranslator.cpp b/src/libcalamares/utils/Retranslator.cpp index 1cc25fa70..93560f4ae 100644 --- a/src/libcalamares/utils/Retranslator.cpp +++ b/src/libcalamares/utils/Retranslator.cpp @@ -18,11 +18,107 @@ #include "Retranslator.h" +#include "Logger.h" + +#include +#include #include +#include namespace CalamaresUtils { +static QTranslator* s_brandingTranslator = nullptr; +static QTranslator* s_translator = nullptr; +static QString s_translatorLocaleName; +void +installTranslator( const QLocale& locale, + const QString& brandingTranslationsPrefix, + QObject* parent ) +{ + QString localeName = locale.name(); + localeName.replace( "-", "_" ); + + if ( localeName == "C" ) + localeName = "en"; + + // Special case of sr@latin + // + // See top-level CMakeLists.txt about special cases for translation loading. + if ( locale.language() == QLocale::Language::Serbian && locale.script() == QLocale::Script::LatinScript ) + localeName = QStringLiteral( "sr@latin" ); + + cDebug() << "Looking for translations for" << localeName; + + QTranslator* translator = nullptr; + + // Branding translations + if ( !brandingTranslationsPrefix.isEmpty() ) + { + QString brandingTranslationsDirPath( brandingTranslationsPrefix ); + brandingTranslationsDirPath.truncate( brandingTranslationsPrefix.lastIndexOf( + QDir::separator() ) ); + QDir brandingTranslationsDir( brandingTranslationsDirPath ); + if ( brandingTranslationsDir.exists() ) + { + QString filenameBase( brandingTranslationsPrefix ); + filenameBase.remove( 0, brandingTranslationsPrefix.lastIndexOf( + QDir::separator() ) + 1 ); + translator = new QTranslator( parent ); + if ( translator->load( locale, + filenameBase, + "_", + brandingTranslationsDir.absolutePath() ) ) + { + cDebug() << Logger::SubEntry << "Branding using locale:" << localeName; + } + else + { + cDebug() << Logger::SubEntry << "Branding using default, system locale not found:" << localeName; + translator->load( brandingTranslationsPrefix + "en" ); + } + + if ( s_brandingTranslator ) + { + QCoreApplication::removeTranslator( s_brandingTranslator ); + delete s_brandingTranslator; + } + + QCoreApplication::installTranslator( translator ); + s_brandingTranslator = translator; + } + } + + // Calamares translations + translator = new QTranslator( parent ); + if ( translator->load( QString( ":/lang/calamares_" ) + localeName ) ) + { + cDebug() << Logger::SubEntry << "Calamares using locale:" << localeName; + } + else + { + cDebug() << Logger::SubEntry << "Calamares using default, system locale not found:" << localeName; + translator->load( QString( ":/lang/calamares_en" ) ); + } + + if ( s_translator ) + { + QCoreApplication::removeTranslator( s_translator ); + delete s_translator; + } + + QCoreApplication::installTranslator( translator ); + s_translator = translator; + + s_translatorLocaleName = localeName; +} + + +QString +translatorLocaleName() +{ + return s_translatorLocaleName; +} void Retranslator::attachRetranslator( QObject* parent, diff --git a/src/libcalamares/utils/Retranslator.h b/src/libcalamares/utils/Retranslator.h index af561a9ce..e06630630 100644 --- a/src/libcalamares/utils/Retranslator.h +++ b/src/libcalamares/utils/Retranslator.h @@ -19,15 +19,30 @@ #ifndef UTILS_RETRANSLATOR_H #define UTILS_RETRANSLATOR_H +#include "DllMacro.h" + #include #include +#include #include class QEvent; +class QLocale; namespace CalamaresUtils { + /** + * @brief installTranslator changes the application language. + * @param locale the new locale. + * @param brandingTranslationsPrefix the branding path prefix, from Calamares::Branding. + * @param parent the parent QObject. + */ + DLLEXPORT void installTranslator( const QLocale& locale, + const QString& brandingTranslationsPrefix, + QObject* parent ); + + DLLEXPORT QString translatorLocaleName(); class Retranslator : public QObject { From eaba696173f8777917eee7538e6dbd0975ec1456 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 06:38:09 -0400 Subject: [PATCH 09/11] [libcalamares] Move the crash() function to the one place it's used --- src/libcalamares/utils/CalamaresUtils.cpp | 8 -------- src/libcalamares/utils/CalamaresUtils.h | 5 ----- src/libcalamaresui/utils/DebugWindow.cpp | 16 ++++++++++++---- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index b44be6795..0fd72e267 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -120,12 +120,4 @@ obscure( const QString& string ) return result; } - -void -crash() -{ - volatile int* a = nullptr; - *a = 1; -} - } diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/CalamaresUtils.h index 39d338d5c..2387a7005 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/CalamaresUtils.h @@ -51,11 +51,6 @@ namespace CalamaresUtils * @return the obfuscated string. */ DLLEXPORT QString obscure( const QString& string ); - - /** - * @brief crash makes Calamares crash immediately. - */ - DLLEXPORT void crash(); } // namespace #endif diff --git a/src/libcalamaresui/utils/DebugWindow.cpp b/src/libcalamaresui/utils/DebugWindow.cpp index 03f4f6aa8..a9be30411 100644 --- a/src/libcalamaresui/utils/DebugWindow.cpp +++ b/src/libcalamaresui/utils/DebugWindow.cpp @@ -37,6 +37,17 @@ #include #include +/** + * @brief crash makes Calamares crash immediately. + */ +static void +crash() +{ + volatile int* a = nullptr; + *a = 1; +} + + namespace Calamares { DebugWindow::DebugWindow() @@ -172,10 +183,7 @@ DebugWindow::DebugWindow() } } ); - connect( crashButton, &QPushButton::clicked, - this, [] { - CalamaresUtils::crash(); - } ); + connect( crashButton, &QPushButton::clicked, this, [] { ::crash(); } ); CALAMARES_RETRANSLATE( retranslateUi( this ); From 8d0f076591552664f53b736870674eee0ac2e968 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 06:48:01 -0400 Subject: [PATCH 10/11] [libcalamares] Rename CalamaresUtils -> String - The only remaining functions in the file are string-related, so rename to match their purpose. - Drop this include file from most places, since they don't actually use the string functionality at all. --- src/libcalamares/CMakeLists.txt | 2 +- src/libcalamares/PythonJobApi.cpp | 2 +- .../utils/{CalamaresUtils.cpp => String.cpp} | 8 +++++--- .../utils/{CalamaresUtils.h => String.h} | 9 +++------ src/libcalamaresui/Branding.cpp | 1 - src/libcalamaresui/utils/CalamaresUtilsGui.h | 1 - src/libcalamaresui/utils/DebugWindow.cpp | 1 - .../viewpages/PythonQtUtilsWrapper.cpp | 2 +- src/modules/preservefiles/PreserveFiles.cpp | 15 +++++++-------- src/modules/users/UsersPage.cpp | 13 +++++++++---- 10 files changed, 27 insertions(+), 27 deletions(-) rename src/libcalamares/utils/{CalamaresUtils.cpp => String.cpp} (96%) rename src/libcalamares/utils/{CalamaresUtils.h => String.h} (94%) diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 5efd850a9..4aa7c44df 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -20,7 +20,6 @@ set( libSources Settings.cpp ) set( utilsSources - utils/CalamaresUtils.cpp utils/CalamaresUtilsSystem.cpp utils/CommandList.cpp utils/Dirs.cpp @@ -28,6 +27,7 @@ set( utilsSources utils/Logger.cpp utils/PluginFactory.cpp utils/Retranslator.cpp + utils/String.cpp utils/Variant.cpp utils/Yaml.cpp ) diff --git a/src/libcalamares/PythonJobApi.cpp b/src/libcalamares/PythonJobApi.cpp index c94aa34e1..8e8b8b2ab 100644 --- a/src/libcalamares/PythonJobApi.cpp +++ b/src/libcalamares/PythonJobApi.cpp @@ -22,7 +22,7 @@ #include "PythonHelper.h" #include "utils/Logger.h" #include "utils/CalamaresUtilsSystem.h" -#include "utils/CalamaresUtils.h" +#include "utils/String.h" #include "GlobalStorage.h" #include "JobQueue.h" diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/String.cpp similarity index 96% rename from src/libcalamares/utils/CalamaresUtils.cpp rename to src/libcalamares/utils/String.cpp index 0fd72e267..a39ebd8c7 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/String.cpp @@ -22,14 +22,16 @@ * along with Calamares. If not, see . */ -#include "CalamaresUtils.h" +#include "String.h" + +#include namespace CalamaresUtils { QString removeDiacritics( const QString& string ) { - const QString diacriticLetters = QString::fromUtf8( + static const QString diacriticLetters = QString::fromUtf8( "ŠŒŽšœžŸ¥µÀ" "ÁÂÃÄÅÆÇÈÉÊ" "ËÌÍÎÏÐÑÒÓÔ" @@ -46,7 +48,7 @@ removeDiacritics( const QString& string ) "ॹĘꣳŃńŚ" "śŹźŻż" ); - const QStringList noDiacriticLetters = { + static const QStringList noDiacriticLetters = { "S", "OE", "Z", "s", "oe", "z", "Y", "Y", "u", "A", "A", "A", "A", "A", "AA", "AE", "C", "E", "E", "E", "E", "I", "I", "I", "I", "D", "N", "O", "O", "O", diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/String.h similarity index 94% rename from src/libcalamares/utils/CalamaresUtils.h rename to src/libcalamares/utils/String.h index 2387a7005..0a69bcf83 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/String.h @@ -22,15 +22,12 @@ * along with Calamares. If not, see . */ -#ifndef UTILS_CALAMARESUTILS_H -#define UTILS_CALAMARESUTILS_H +#ifndef UTILS_STRING_H +#define UTILS_STRING_H #include "DllMacro.h" -#include - -class QDir; -class QObject; +#include /** * @brief The CalamaresUtils namespace contains utility functions. diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index e3da98614..b7bf4c7aa 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -21,7 +21,6 @@ #include "Branding.h" #include "GlobalStorage.h" -#include "utils/CalamaresUtils.h" #include "utils/CalamaresUtilsGui.h" #include "utils/ImageRegistry.h" #include "utils/Logger.h" diff --git a/src/libcalamaresui/utils/CalamaresUtilsGui.h b/src/libcalamaresui/utils/CalamaresUtilsGui.h index 135a57c43..72430a083 100644 --- a/src/libcalamaresui/utils/CalamaresUtilsGui.h +++ b/src/libcalamaresui/utils/CalamaresUtilsGui.h @@ -20,7 +20,6 @@ #ifndef CALAMARESUTILSGUI_H #define CALAMARESUTILSGUI_H -#include "utils/CalamaresUtils.h" #include "UiDllMacro.h" #include diff --git a/src/libcalamaresui/utils/DebugWindow.cpp b/src/libcalamaresui/utils/DebugWindow.cpp index a9be30411..22986014e 100644 --- a/src/libcalamaresui/utils/DebugWindow.cpp +++ b/src/libcalamaresui/utils/DebugWindow.cpp @@ -17,7 +17,6 @@ */ #include "DebugWindow.h" -#include "utils/CalamaresUtils.h" #include "utils/Retranslator.h" #include "utils/qjsonmodel.h" #include "JobQueue.h" diff --git a/src/libcalamaresui/viewpages/PythonQtUtilsWrapper.cpp b/src/libcalamaresui/viewpages/PythonQtUtilsWrapper.cpp index 6adfaa72f..efb3da2a1 100644 --- a/src/libcalamaresui/viewpages/PythonQtUtilsWrapper.cpp +++ b/src/libcalamaresui/viewpages/PythonQtUtilsWrapper.cpp @@ -19,8 +19,8 @@ #include "PythonQtUtilsWrapper.h" #include "utils/CalamaresUtilsSystem.h" -#include "utils/CalamaresUtils.h" #include "utils/Logger.h" +#include "utils/String.h" #include diff --git a/src/modules/preservefiles/PreserveFiles.cpp b/src/modules/preservefiles/PreserveFiles.cpp index 2c1b85103..96d26274c 100644 --- a/src/modules/preservefiles/PreserveFiles.cpp +++ b/src/modules/preservefiles/PreserveFiles.cpp @@ -24,7 +24,6 @@ #include "JobQueue.h" #include "GlobalStorage.h" -#include "utils/CalamaresUtils.h" #include "utils/CalamaresUtilsSystem.h" #include "utils/CommandList.h" #include "utils/Logger.h" @@ -113,7 +112,7 @@ copy_file( const QString& source, const QString& dest ) sourcef.close(); destf.close(); - + return true; } @@ -151,22 +150,22 @@ Calamares::JobResult PreserveFiles::exec() if ( it.perm.isValid() ) { auto s_p = CalamaresUtils::System::instance(); - + int r; - + r = s_p->targetEnvCall( QStringList{ "chown", it.perm.username(), bare_dest } ); if ( r ) cWarning() << "Could not chown target" << bare_dest; - + r = s_p->targetEnvCall( QStringList{ "chgrp", it.perm.group(), bare_dest } ); if ( r ) cWarning() << "Could not chgrp target" << bare_dest; - + r = s_p->targetEnvCall( QStringList{ "chmod", it.perm.octal(), bare_dest } ); if ( r ) cWarning() << "Could not chmod target" << bare_dest; } - + ++count; } } @@ -195,7 +194,7 @@ void PreserveFiles::setConfigurationMap(const QVariantMap& configurationMap) QString defaultPermissions = configurationMap[ "perm" ].toString(); if ( defaultPermissions.isEmpty() ) defaultPermissions = QStringLiteral( "root:root:0400" ); - + QVariantList l = files.toList(); unsigned int c = 0; for ( const auto& li : l ) diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 834287bcd..62292b76c 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -23,17 +23,22 @@ */ #include "UsersPage.h" + #include "ui_page_usersetup.h" + #include "CreateUserJob.h" #include "SetPasswordJob.h" #include "SetHostNameJob.h" -#include "JobQueue.h" + #include "GlobalStorage.h" -#include "utils/Logger.h" -#include "utils/CalamaresUtilsGui.h" -#include "utils/Retranslator.h" +#include "JobQueue.h" #include "Settings.h" +#include "utils/CalamaresUtilsGui.h" +#include "utils/Logger.h" +#include "utils/Retranslator.h" +#include "utils/String.h" + #include #include #include From 600a18f2f0746d4ffcd9963f44a42a216dc4c331 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 29 Apr 2019 06:55:00 -0400 Subject: [PATCH 11/11] Changes: document utils/ shuffle --- CHANGES | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGES b/CHANGES index 9909c247f..cb4b0a7ce 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,10 @@ website will have to do for older versions. # 3.2.8 (unreleased) # +This is a **source-incompatible** release of Calamares. Include files +have been shuffled around, so third-party C++ modules will need +adjustment to the changed names. + This release contains contributions from (alphabetically by first name): ## Core ## @@ -12,6 +16,11 @@ This release contains contributions from (alphabetically by first name): - *libcalamares* (accidentally) linked with Qt's GUI libraries when PythonQt was found. This led to the odd situation where the non-GUI Calamares library depends on a bunch of GUI libraries. + - *libcalamares* The `utils/` subdirectory has been hugely refactored, + with functionality split out into separate files. C++ modules will + need to have their `#include` names updated. Basically, users of + `utils/CalamaresUtils.h` will need to include the header file for + the functionality that is actually used. ## Modules ##