From 91625c8ba8cf68228f785a45479e02ea1db3a3a1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Feb 2020 13:35:26 +0100 Subject: [PATCH 01/10] [libcalamares] Tidy up boolean options in Settings - The const getters for a single boolean value have moved to the header, for inlining. - Document the getters and what their settings mean. --- src/libcalamares/Settings.cpp | 33 --------------------------------- src/libcalamares/Settings.h | 30 +++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 38 deletions(-) diff --git a/src/libcalamares/Settings.cpp b/src/libcalamares/Settings.cpp index 456956430..668868812 100644 --- a/src/libcalamares/Settings.cpp +++ b/src/libcalamares/Settings.cpp @@ -265,37 +265,4 @@ Settings::brandingComponentName() const return m_brandingComponentName; } - -bool -Settings::showPromptBeforeExecution() const -{ - return m_promptInstall; -} - - -bool -Settings::debugMode() const -{ - return m_debug; -} - -bool -Settings::doChroot() const -{ - return m_doChroot; -} - -bool -Settings::disableCancel() const -{ - return m_disableCancel; -} - -bool -Settings::disableCancelDuringExec() const -{ - return m_disableCancelDuringExec; -} - - } // namespace Calamares diff --git a/src/libcalamares/Settings.h b/src/libcalamares/Settings.h index 4c2f2ed9d..bd980caaa 100644 --- a/src/libcalamares/Settings.h +++ b/src/libcalamares/Settings.h @@ -51,11 +51,31 @@ public: QString brandingComponentName() const; - bool showPromptBeforeExecution() const; + /** @brief Is this a debugging run? + * + * Returns true if Calamares is in debug mode. In debug mode, + * modules and settings are loaded from more locations, to help + * development and debugging. + */ + bool debugMode() const { return m_debug; } - bool debugMode() const; + /** @brief Distinguish "install" from "OEM" modes. + * + * Returns true in "install" mode, which is where actions happen + * in a chroot -- the target system, which exists separately from + * the source system. In "OEM" mode, returns false and most actions + * apply to the *current* (host) system. + */ + bool doChroot() const { return m_doChroot; } - bool doChroot() const; + /** @brief Global setting of prompt-before-install. + * + * Returns true when the configuration is such that the user + * should be prompted one-last-time before any action is taken + * that really affects the machine. + */ + bool showPromptBeforeExecution() const { return m_promptInstall; } + /** @brief Distinguish between "install" and "setup" modes. * * This influences user-visible strings, for instance using the @@ -64,9 +84,9 @@ public: bool isSetupMode() const { return m_isSetupMode; } /** @brief Global setting of disable-cancel: can't cancel ever. */ - bool disableCancel() const; + bool disableCancel() const { return m_disableCancel; } /** @brief Temporary setting of disable-cancel: can't cancel during exec. */ - bool disableCancelDuringExec() const; + bool disableCancelDuringExec() const { return m_disableCancelDuringExec; } private: static Settings* s_instance; From af862336a862717dad0ee8e65dc9a0041ffde3b2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Feb 2020 13:49:44 +0100 Subject: [PATCH 02/10] [calamares] Initialize settings before QML --- src/calamares/CalamaresApplication.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 1584b11fa..e435dd6ef 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -75,13 +75,13 @@ CalamaresApplication::init() setQuitOnLastWindowClosed( false ); - initQmlPath(); initSettings(); + initQmlPath(); initBranding(); setWindowIcon( QIcon( Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductIcon ) ) ); - cDebug() << "STARTUP: initQmlPath, initSettings, initBranding done"; + cDebug() << "STARTUP: initSettings, initQmlPath, initBranding done"; initModuleManager(); //also shows main window From ea8adc3de71a4bd38f7f4cf1eab9a83fa7269f2d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Feb 2020 14:04:52 +0100 Subject: [PATCH 03/10] [calamares] Simplify return from main --- src/calamares/main.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index caf1f6cfd..2a49b4806 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -116,11 +116,10 @@ main( int argc, char* argv[] ) handle_args( a ); KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances ); - int returnCode = 0; if ( guard.isPrimaryInstance() ) { a.init(); - returnCode = a.exec(); + return a.exec(); } else { @@ -135,7 +134,6 @@ main( int argc, char* argv[] ) { qDebug() << " " << i.isValid() << i.pid() << i.arguments(); } + return 69; // EX_UNAVAILABLE on FreeBSD } - - return returnCode; } From f233cac7a17d39038839a12d8223db85c4808f90 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Feb 2020 14:23:55 +0100 Subject: [PATCH 04/10] [calamares] Refactor debug-logging settings --- src/calamares/main.cpp | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index 2a49b4806..e451cf8cc 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -35,6 +35,21 @@ #include #include +static unsigned int +debug_level( QCommandLineParser& parser, QCommandLineOption& levelOption ) +{ + bool ok = true; + int l = parser.value( levelOption ).toInt( &ok ); + if ( !ok || ( l < 0 ) ) + { + return Logger::LOGVERBOSE; + } + else + { + return static_cast< unsigned int >( l ); // l >= 0 + } +} + static void handle_args( CalamaresApplication& a ) { @@ -59,25 +74,7 @@ handle_args( CalamaresApplication& a ) parser.process( a ); a.setDebug( parser.isSet( debugOption ) ); - if ( parser.isSet( debugOption ) ) - { - Logger::setupLogLevel( Logger::LOGVERBOSE ); - } - else if ( parser.isSet( debugLevelOption ) ) - { - bool ok = true; - int l = parser.value( debugLevelOption ).toInt( &ok ); - unsigned int dlevel = 0; - if ( !ok || ( l < 0 ) ) - { - dlevel = Logger::LOGVERBOSE; - } - else - { - dlevel = static_cast< unsigned int >( l ); // l >= 0 - } - Logger::setupLogLevel( dlevel ); - } + Logger::setupLogLevel( a.isDebug() ? Logger::LOGVERBOSE : debug_level( parser, debugLevelOption ) ); if ( parser.isSet( configOption ) ) { CalamaresUtils::setAppDataDir( QDir( parser.value( configOption ) ) ); @@ -115,7 +112,6 @@ main( int argc, char* argv[] ) handle_args( a ); KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances ); - if ( guard.isPrimaryInstance() ) { a.init(); From 50b6801d35abf01d63534f8baf9b52c98089d533 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Feb 2020 14:33:42 +0100 Subject: [PATCH 05/10] [calamares] Install translator after loading settings - means that also the *initial* translation can take settings into account, like -d loading local translations. --- src/calamares/CalamaresApplication.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index e435dd6ef..a1daa4df2 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -59,8 +59,6 @@ CalamaresApplication::CalamaresApplication( int& argc, char* argv[] ) setApplicationName( QStringLiteral( CALAMARES_APPLICATION_NAME ) ); setApplicationVersion( QStringLiteral( CALAMARES_VERSION ) ); - CalamaresUtils::installTranslator( QLocale::system(), QString(), this ); - QFont f = font(); CalamaresUtils::setDefaultFontSize( f.pointSize() ); } @@ -73,12 +71,13 @@ CalamaresApplication::init() cDebug() << "Calamares version:" << CALAMARES_VERSION; cDebug() << " languages:" << QString( CALAMARES_TRANSLATION_LANGUAGES ).replace( ";", ", " ); - setQuitOnLastWindowClosed( false ); - initSettings(); initQmlPath(); initBranding(); + CalamaresUtils::installTranslator( QLocale::system(), QString(), this ); + + setQuitOnLastWindowClosed( false ); setWindowIcon( QIcon( Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductIcon ) ) ); cDebug() << "STARTUP: initSettings, initQmlPath, initBranding done"; From db80a34aca14fdb710588a6cc1ccb3c4d5aad2d6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Feb 2020 16:09:35 +0100 Subject: [PATCH 06/10] [calamares] Remove intermediate debug-settings - There's a multi-stage setup for debug-mode, where the application object also knows that debugging is set. Remove it. - Break debug mode (because now the settings don't get debug-mode set). - Refactor so that parameter handing is only done if this Calamares is the unique (first) Calamares. --- src/calamares/CalamaresApplication.cpp | 21 ++++++--------------- src/calamares/CalamaresApplication.h | 12 ------------ src/calamares/main.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index a1daa4df2..1ce8f5eaa 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -42,12 +42,17 @@ #include #include +/// @brief Convenience for "are the settings in debug mode" +static bool +isDebug() +{ + return Calamares::Settings::instance() && Calamares::Settings::instance()->debugMode(); +} CalamaresApplication::CalamaresApplication( int& argc, char* argv[] ) : QApplication( argc, argv ) , m_mainwindow( nullptr ) , m_moduleManager( nullptr ) - , m_debugMode( false ) { // Setting the organization name makes the default cache // directory -- where Calamares stores logs, for instance -- @@ -102,20 +107,6 @@ CalamaresApplication::instance() } -void -CalamaresApplication::setDebug( bool enabled ) -{ - m_debugMode = enabled; -} - - -bool -CalamaresApplication::isDebug() -{ - return m_debugMode; -} - - CalamaresWindow* CalamaresApplication::mainWindow() { diff --git a/src/calamares/CalamaresApplication.h b/src/calamares/CalamaresApplication.h index 634f4cdb2..091361602 100644 --- a/src/calamares/CalamaresApplication.h +++ b/src/calamares/CalamaresApplication.h @@ -49,16 +49,6 @@ public: void init(); static CalamaresApplication* instance(); - /** - * @brief setDebug controls whether debug mode is enabled - */ - void setDebug( bool enabled ); - - /** - * @brief isDebug returns true if running in debug mode, otherwise false. - */ - bool isDebug(); - /** * @brief mainWindow returns the Calamares application main window. */ @@ -78,8 +68,6 @@ private: CalamaresWindow* m_mainwindow; Calamares::ModuleManager* m_moduleManager; - - bool m_debugMode; }; #endif // CALAMARESAPPLICATION_H diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index e451cf8cc..e2f5c0fd9 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -73,8 +73,7 @@ handle_args( CalamaresApplication& a ) parser.process( a ); - a.setDebug( parser.isSet( debugOption ) ); - Logger::setupLogLevel( a.isDebug() ? Logger::LOGVERBOSE : debug_level( parser, debugLevelOption ) ); + Logger::setupLogLevel( parser.isSet( debugOption ) ? Logger::LOGVERBOSE : debug_level( parser, debugLevelOption ) ); if ( parser.isSet( configOption ) ) { CalamaresUtils::setAppDataDir( QDir( parser.value( configOption ) ) ); @@ -83,6 +82,8 @@ handle_args( CalamaresApplication& a ) { CalamaresUtils::setXdgDirs(); } + + a.init(); } int @@ -110,11 +111,10 @@ main( int argc, char* argv[] ) // TODO: umount anything in /tmp/calamares-... as an emergency save function #endif - handle_args( a ); KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances ); if ( guard.isPrimaryInstance() ) { - a.init(); + handle_args( a ); return a.exec(); } else From 68e8b0695d0439b9f5cd0f08e676d53e411717d6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Feb 2020 16:14:56 +0100 Subject: [PATCH 07/10] [calamares] Make declaration order match calling order --- src/calamares/CalamaresApplication.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calamares/CalamaresApplication.h b/src/calamares/CalamaresApplication.h index 091361602..23239d79e 100644 --- a/src/calamares/CalamaresApplication.h +++ b/src/calamares/CalamaresApplication.h @@ -60,8 +60,9 @@ private slots: void initFailed( const QStringList& l ); private: - void initQmlPath(); + // Initialization steps happen in this order void initSettings(); + void initQmlPath(); void initBranding(); void initModuleManager(); void initJobQueue(); From 4525060c26860917a0adeb09384b80a4a17bad0e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Feb 2020 16:48:49 +0100 Subject: [PATCH 08/10] [calamares] Refactor Settings initialization - add a Settings::init() to do actual work - remove the same kind of code from CalamaresApplication - make constructor of Settings private - initialize settings before the application --- src/calamares/CalamaresApplication.cpp | 78 ++------------------- src/calamares/CalamaresApplication.h | 1 - src/calamares/main.cpp | 3 +- src/calamares/testmain.cpp | 2 +- src/libcalamares/Settings.cpp | 94 +++++++++++++++++++++++++- src/libcalamares/Settings.h | 9 ++- src/modules/shellprocess/Tests.cpp | 2 +- 7 files changed, 107 insertions(+), 82 deletions(-) diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 1ce8f5eaa..48e54b76e 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -76,7 +76,11 @@ CalamaresApplication::init() cDebug() << "Calamares version:" << CALAMARES_VERSION; cDebug() << " languages:" << QString( CALAMARES_TRANSLATION_LANGUAGES ).replace( ";", ", " ); - initSettings(); + if ( !Calamares::Settings::instance() ) + { + cError() << "Must create Calamares::Settings before the application."; + ::exit( 1 ); + } initQmlPath(); initBranding(); @@ -142,35 +146,6 @@ qmlDirCandidates( bool assumeBuilddir ) } -static QStringList -settingsFileCandidates( bool assumeBuilddir ) -{ - static const char settings[] = "settings.conf"; - - QStringList settingsPaths; - if ( CalamaresUtils::isAppDataDirOverridden() ) - { - settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings ); - } - else - { - if ( assumeBuilddir ) - { - settingsPaths << QDir::current().absoluteFilePath( settings ); - } - if ( CalamaresUtils::haveExtraDirs() ) - for ( auto s : CalamaresUtils::extraConfigDirs() ) - { - settingsPaths << ( s + settings ); - } - settingsPaths << CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf"; // String concat - settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings ); - } - - return settingsPaths; -} - - static QStringList brandingFileCandidates( bool assumeBuilddir, const QString& brandingFilename ) { @@ -236,49 +211,6 @@ CalamaresApplication::initQmlPath() } -void -CalamaresApplication::initSettings() -{ - QStringList settingsFileCandidatesByPriority = settingsFileCandidates( isDebug() ); - - QFileInfo settingsFile; - bool found = false; - - foreach ( const QString& path, settingsFileCandidatesByPriority ) - { - QFileInfo pathFi( path ); - if ( pathFi.exists() && pathFi.isReadable() ) - { - settingsFile = pathFi; - found = true; - break; - } - } - - if ( !found || !settingsFile.exists() || !settingsFile.isReadable() ) - { - cError() << "Cowardly refusing to continue startup without settings." - << Logger::DebugList( settingsFileCandidatesByPriority ); - if ( CalamaresUtils::isAppDataDirOverridden() ) - { - cError() << "FATAL: explicitly configured application data directory is missing settings.conf"; - } - else - { - cError() << "FATAL: none of the expected configuration file paths exist."; - } - ::exit( EXIT_FAILURE ); - } - - auto* settings = new Calamares::Settings( settingsFile.absoluteFilePath(), isDebug(), this ); // Creates singleton - if ( settings->modulesSequence().count() < 1 ) - { - cError() << "FATAL: no sequence set."; - ::exit( EXIT_FAILURE ); - } -} - - void CalamaresApplication::initBranding() { diff --git a/src/calamares/CalamaresApplication.h b/src/calamares/CalamaresApplication.h index 23239d79e..f42c21b56 100644 --- a/src/calamares/CalamaresApplication.h +++ b/src/calamares/CalamaresApplication.h @@ -61,7 +61,6 @@ private slots: private: // Initialization steps happen in this order - void initSettings(); void initQmlPath(); void initBranding(); void initModuleManager(); diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index e2f5c0fd9..9369d59e5 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -20,7 +20,7 @@ #include "CalamaresApplication.h" -#include "CalamaresConfig.h" +#include "Settings.h" #include "utils/Dirs.h" #include "utils/Logger.h" @@ -83,6 +83,7 @@ handle_args( CalamaresApplication& a ) CalamaresUtils::setXdgDirs(); } + Calamares::Settings::init( parser.isSet( debugOption ) ); a.init(); } diff --git a/src/calamares/testmain.cpp b/src/calamares/testmain.cpp index 885915041..0845218eb 100644 --- a/src/calamares/testmain.cpp +++ b/src/calamares/testmain.cpp @@ -225,7 +225,7 @@ main( int argc, char* argv[] ) return 1; } - std::unique_ptr< Calamares::Settings > settings_p( new Calamares::Settings( QString(), true ) ); + std::unique_ptr< Calamares::Settings > settings_p( Calamares::Settings::init( QString() ) ); std::unique_ptr< Calamares::JobQueue > jobqueue_p( new Calamares::JobQueue( nullptr ) ); QMainWindow* mw = nullptr; diff --git a/src/libcalamares/Settings.cpp b/src/libcalamares/Settings.cpp index 668868812..48f8c606d 100644 --- a/src/libcalamares/Settings.cpp +++ b/src/libcalamares/Settings.cpp @@ -21,6 +21,7 @@ #include "Settings.h" +#include "CalamaresConfig.h" #include "utils/Dirs.h" #include "utils/Logger.h" #include "utils/Yaml.h" @@ -193,8 +194,8 @@ interpretSequence( const YAML::Node& node, Settings::ModuleSequence& moduleSeque } } -Settings::Settings( const QString& settingsFilePath, bool debugMode, QObject* parent ) - : QObject( parent ) +Settings::Settings( const QString& settingsFilePath, bool debugMode ) + : QObject() , m_debug( debugMode ) , m_doChroot( true ) , m_promptInstall( false ) @@ -265,4 +266,93 @@ Settings::brandingComponentName() const return m_brandingComponentName; } +static QStringList +settingsFileCandidates( bool assumeBuilddir ) +{ + static const char settings[] = "settings.conf"; + + QStringList settingsPaths; + if ( CalamaresUtils::isAppDataDirOverridden() ) + { + settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings ); + } + else + { + if ( assumeBuilddir ) + { + settingsPaths << QDir::current().absoluteFilePath( settings ); + } + if ( CalamaresUtils::haveExtraDirs() ) + for ( auto s : CalamaresUtils::extraConfigDirs() ) + { + settingsPaths << ( s + settings ); + } + settingsPaths << CMAKE_INSTALL_FULL_SYSCONFDIR "/calamares/settings.conf"; // String concat + settingsPaths << CalamaresUtils::appDataDir().absoluteFilePath( settings ); + } + + return settingsPaths; +} + +Settings* +Settings::init( bool debugMode ) +{ + if ( s_instance ) + { + cWarning() << "Calamares::Settings already created"; + return s_instance; + } + + QStringList settingsFileCandidatesByPriority = settingsFileCandidates( debugMode ); + + QFileInfo settingsFile; + bool found = false; + + foreach ( const QString& path, settingsFileCandidatesByPriority ) + { + QFileInfo pathFi( path ); + if ( pathFi.exists() && pathFi.isReadable() ) + { + settingsFile = pathFi; + found = true; + break; + } + } + + if ( !found || !settingsFile.exists() || !settingsFile.isReadable() ) + { + cError() << "Cowardly refusing to continue startup without settings." + << Logger::DebugList( settingsFileCandidatesByPriority ); + if ( CalamaresUtils::isAppDataDirOverridden() ) + { + cError() << "FATAL: explicitly configured application data directory is missing settings.conf"; + } + else + { + cError() << "FATAL: none of the expected configuration file paths exist."; + } + ::exit( EXIT_FAILURE ); + } + + auto* settings = new Calamares::Settings( settingsFile.absoluteFilePath(), debugMode ); // Creates singleton + if ( settings->modulesSequence().count() < 1 ) + { + cError() << "FATAL: no sequence set."; + ::exit( EXIT_FAILURE ); + } + + return settings; +} + +Settings* +Settings::init( const QString& path ) +{ + if ( s_instance ) + { + cWarning() << "Calamares::Settings already created"; + return s_instance; + } + return new Calamares::Settings( path, true ); +} + } // namespace Calamares diff --git a/src/libcalamares/Settings.h b/src/libcalamares/Settings.h index bd980caaa..26990f027 100644 --- a/src/libcalamares/Settings.h +++ b/src/libcalamares/Settings.h @@ -35,11 +35,14 @@ namespace Calamares class DLLEXPORT Settings : public QObject { Q_OBJECT + explicit Settings( const QString& settingsFilePath, bool debugMode ); public: - explicit Settings( const QString& settingsFilePath, bool debugMode, QObject* parent = nullptr ); - static Settings* instance(); - + /// @brief Find a settings.conf, following @p debugMode + static Settings* init( bool debugMode ); + /// @brief Explicif filename, debug is always true (for testing) + static Settings* init( const QString& filename ); + QStringList modulesSearchPaths() const; using InstanceDescription = QMap< QString, QString >; diff --git a/src/modules/shellprocess/Tests.cpp b/src/modules/shellprocess/Tests.cpp index 943a70957..e991973db 100644 --- a/src/modules/shellprocess/Tests.cpp +++ b/src/modules/shellprocess/Tests.cpp @@ -176,7 +176,7 @@ script: if ( !Calamares::JobQueue::instance() ) (void)new Calamares::JobQueue( nullptr ); if ( !Calamares::Settings::instance() ) - (void)new Calamares::Settings( QString(), true ); + (void)Calamares::Settings::init( QString() ); Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); QVERIFY( gs != nullptr ); From 24c2c435a0865df2c22f7b84264d8eafa5c35184 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Feb 2020 17:08:47 +0100 Subject: [PATCH 09/10] [libcalamares] Try repairing tests - Fail on FreeBSD with an instant timeout --- src/libcalamares/network/Tests.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/network/Tests.cpp b/src/libcalamares/network/Tests.cpp index 559a955fe..3a15b3c59 100644 --- a/src/libcalamares/network/Tests.cpp +++ b/src/libcalamares/network/Tests.cpp @@ -19,6 +19,7 @@ #include "Tests.h" #include "Manager.h" +#include "utils/Logger.h" #include @@ -43,6 +44,9 @@ NetworkTests::testInstance() void NetworkTests::testPing() { - auto& nam = CalamaresUtils::Network::Manager::instance(); - QVERIFY( nam.synchronousPing( QUrl( "https://www.kde.org" ) ) ); + using namespace CalamaresUtils::Network; + Logger::setupLogLevel( Logger::LOGVERBOSE ); + auto& nam = Manager::instance(); + auto r = nam.synchronousPing( QUrl( "https://www.kde.org" ), RequestOptions( RequestOptions::FollowRedirect ) ); + QVERIFY( r ); } From 4b3f7eb2090815727247446a0441308e70100800 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Feb 2020 17:48:39 +0100 Subject: [PATCH 10/10] [calamares] Local translations can be a separate setting - Don't stick this in Settings, though, it becomes overly complicated. --- src/calamares/main.cpp | 7 ++++++- src/libcalamares/utils/Retranslator.cpp | 15 ++++++++++++--- src/libcalamares/utils/Retranslator.h | 9 +++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index 9369d59e5..670b7a654 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -23,6 +23,7 @@ #include "Settings.h" #include "utils/Dirs.h" #include "utils/Logger.h" +#include "utils/Retranslator.h" #include "3rdparty/kdsingleapplicationguard/kdsingleapplicationguard.h" @@ -57,6 +58,9 @@ handle_args( CalamaresApplication& a ) "Also look in current directory for configuration. Implies -D8." ); QCommandLineOption debugLevelOption( QStringLiteral( "D" ), "Verbose output for debugging purposes (0-8).", "level" ); + QCommandLineOption debugTxOption( QStringList { "T", "debug-translation" }, + "Also look in the current directory for translation." ); + QCommandLineOption configOption( QStringList { "c", "config" }, "Configuration directory to use, for testing purposes.", "config" ); QCommandLineOption xdgOption( QStringList { "X", "xdg-config" }, "Use XDG_{CONFIG,DATA}_DIRS as well." ); @@ -70,6 +74,7 @@ handle_args( CalamaresApplication& a ) parser.addOption( debugLevelOption ); parser.addOption( configOption ); parser.addOption( xdgOption ); + parser.addOption( debugTxOption ); parser.process( a ); @@ -82,7 +87,7 @@ handle_args( CalamaresApplication& a ) { CalamaresUtils::setXdgDirs(); } - + CalamaresUtils::setAllowLocalTranslation( parser.isSet( debugOption ) || parser.isSet( debugTxOption ) ); Calamares::Settings::init( parser.isSet( debugOption ) ); a.init(); } diff --git a/src/libcalamares/utils/Retranslator.cpp b/src/libcalamares/utils/Retranslator.cpp index 85dfb62b6..767d0581e 100644 --- a/src/libcalamares/utils/Retranslator.cpp +++ b/src/libcalamares/utils/Retranslator.cpp @@ -27,6 +27,8 @@ #include #include +static bool s_allowLocalTranslations = false; + /** @brief Helper class for loading translations * * This is used by the loadSingletonTranslator() function to hand off @@ -131,7 +133,7 @@ static bool tryLoad( QTranslator* translator, const QString& prefix, const QString& localeName ) { // In debug-mode, try loading from the current directory - if ( Calamares::Settings::instance() && Calamares::Settings::instance()->debugMode() && translator->load( prefix + localeName ) ) + if ( s_allowLocalTranslations && translator->load( prefix + localeName ) ) { cDebug() << Logger::SubEntry << "Loaded local translation" << prefix << localeName; return true; @@ -139,14 +141,15 @@ tryLoad( QTranslator* translator, const QString& prefix, const QString& localeNa // Or load from appDataDir -- often /usr/share/calamares -- subdirectory land/ QDir localeData( CalamaresUtils::appDataDir() ); - if ( localeData.exists() && translator->load( localeData.absolutePath() + QStringLiteral("/lang/") + prefix + localeName) ) + if ( localeData.exists() + && translator->load( localeData.absolutePath() + QStringLiteral( "/lang/" ) + prefix + localeName ) ) { cDebug() << Logger::SubEntry << "Loaded appdata translation" << prefix << localeName; return true; } // Or from QRC (most common) - if ( translator->load( QStringLiteral( ":/lang/") + prefix + localeName ) ) + if ( translator->load( QStringLiteral( ":/lang/" ) + prefix + localeName ) ) { cDebug() << Logger::SubEntry << "Loaded QRC translation" << prefix << localeName; return true; @@ -260,5 +263,11 @@ Retranslator::eventFilter( QObject* obj, QEvent* e ) return QObject::eventFilter( obj, e ); } +void +setAllowLocalTranslation( bool allow ) +{ + s_allowLocalTranslations = allow; +} + } // namespace CalamaresUtils diff --git a/src/libcalamares/utils/Retranslator.h b/src/libcalamares/utils/Retranslator.h index 58c60b761..af322e5b5 100644 --- a/src/libcalamares/utils/Retranslator.h +++ b/src/libcalamares/utils/Retranslator.h @@ -42,6 +42,15 @@ DLLEXPORT void installTranslator( const QLocale& locale, const QString& branding DLLEXPORT QString translatorLocaleName(); +/** @brief Set @p allow to true to load translations from current dir. + * + * If false, (or never called) the translations are loaded only from + * system locations (the AppData dir) and from QRC (compiled in). + * Enable local translations to test translations stored in the + * current directory. + */ +DLLEXPORT void setAllowLocalTranslation( bool allow ); + class Retranslator : public QObject { Q_OBJECT