From 156d78feb3d65ed158956dd9be8ba3eb9d57334d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 13 Dec 2019 11:50:12 +0100 Subject: [PATCH 002/119] [welcome] Add QML support - test application to display the QML (this will be extended with adding the locale model to it) - sample QML that does nothing useful yet (will display the locale model once it's there) --- src/modules/welcome/CMakeLists.txt | 3 ++ src/modules/welcome/qmlmain.cpp | 52 ++++++++++++++++++++++++++++++ src/modules/welcome/welcome.qml | 12 +++++++ 3 files changed, 67 insertions(+) create mode 100644 src/modules/welcome/qmlmain.cpp create mode 100644 src/modules/welcome/welcome.qml diff --git a/src/modules/welcome/CMakeLists.txt b/src/modules/welcome/CMakeLists.txt index e25b7f5d0..e0fbcfca1 100644 --- a/src/modules/welcome/CMakeLists.txt +++ b/src/modules/welcome/CMakeLists.txt @@ -40,3 +40,6 @@ calamares_add_plugin( welcome Qt5::Network SHARED_LIB ) + +add_executable( welcomeqmltest qmlmain.cpp ) +target_link_libraries( welcomeqmltest calamaresui ) diff --git a/src/modules/welcome/qmlmain.cpp b/src/modules/welcome/qmlmain.cpp new file mode 100644 index 000000000..81bf08df5 --- /dev/null +++ b/src/modules/welcome/qmlmain.cpp @@ -0,0 +1,52 @@ +/* Example executable showing a QML page and using the + * models from libcalamares for displaying a welcome. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "utils/Logger.h" + +int main(int argc, char **argv) +{ + QApplication a( argc, argv ); + + KAboutData aboutData( "calamares", + "Calamares", + "0.1", + "Calamares QML Test Application", + KAboutLicense::GPL_V3, + QString(), + QString(), + "https://calamares.io", + "https://github.com/calamares/calamares/issues" ); + KAboutData::setApplicationData( aboutData ); + a.setApplicationDisplayName( QString() ); // To avoid putting an extra "Calamares/" into the log-file + + Logger::setupLogLevel( Logger::LOGVERBOSE ); + + QMainWindow mw; + QWidget background; + QVBoxLayout vl; + QLabel l( "Hello, world", &mw ); + QQuickWidget qqw( &mw ); + vl.addWidget( &qqw ); + vl.addWidget( &l ); + background.setLayout( &vl ); + mw.setCentralWidget( &background ); + mw.resize( QSize( 400, 400 ) ); + mw.show(); + + qqw.setSource( QUrl::fromLocalFile("../src/modules/welcome/welcome.qml") ); + + return a.exec(); +} diff --git a/src/modules/welcome/welcome.qml b/src/modules/welcome/welcome.qml new file mode 100644 index 000000000..f73b66571 --- /dev/null +++ b/src/modules/welcome/welcome.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0; + +Rectangle { + width: 200; + height: 200; + color: "pink"; + + Text { + anchors.centerIn: parent; + text: "Welcome to Calamares"; + } +} From c59678594bbd81c6ddb7d39b32f48b8ae9471f6a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 13 Dec 2019 12:35:42 +0100 Subject: [PATCH 003/119] [welcome] More QML support - start of a class to hold configuration information; this can later be substituted into the WelcomeViewStep and filled from setConfigurationMap() In the example application: - register the Config type --- src/modules/welcome/CMakeLists.txt | 11 ++++++-- src/modules/welcome/Config.cpp | 27 ++++++++++++++++++++ src/modules/welcome/Config.h | 40 ++++++++++++++++++++++++++++++ src/modules/welcome/qmlmain.cpp | 10 ++++++++ src/modules/welcome/welcome.qml | 1 + 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 src/modules/welcome/Config.cpp create mode 100644 src/modules/welcome/Config.h diff --git a/src/modules/welcome/CMakeLists.txt b/src/modules/welcome/CMakeLists.txt index e0fbcfca1..b25bb6720 100644 --- a/src/modules/welcome/CMakeLists.txt +++ b/src/modules/welcome/CMakeLists.txt @@ -41,5 +41,12 @@ calamares_add_plugin( welcome SHARED_LIB ) -add_executable( welcomeqmltest qmlmain.cpp ) -target_link_libraries( welcomeqmltest calamaresui ) +add_executable( welcomeqmltest qmlmain.cpp Config.cpp ) +target_link_libraries( welcomeqmltest PRIVATE calamaresui Qt5::Core ) +set_target_properties( welcomeqmltest + PROPERTIES + ENABLE_EXPORTS TRUE + RUNTIME_OUTPUT_NAME welcomeqmltest +) +calamares_automoc( welcomeqmltest ) +calamares_autouic( welcomeqmltest ) diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp new file mode 100644 index 000000000..35ce99184 --- /dev/null +++ b/src/modules/welcome/Config.cpp @@ -0,0 +1,27 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, 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 . + */ + +#include "Config.h" + +Config::Config() +{ +} + +Config::~Config() +{ +} diff --git a/src/modules/welcome/Config.h b/src/modules/welcome/Config.h new file mode 100644 index 000000000..91f5bec5c --- /dev/null +++ b/src/modules/welcome/Config.h @@ -0,0 +1,40 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, 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 WELCOME_CONFIG_H +#define WELCOME_CONFIG_H + +#include +#include + +class Config : public QObject +{ + Q_OBJECT + Q_PROPERTY( QUrl helpUrl READ helpUrl WRITE setHelpUrl ) +public: + Config(); + virtual ~Config(); + + QUrl helpUrl() const { return m_helpUrl; } + void setHelpUrl( const QUrl& url ) { m_helpUrl = url; } + +private: + QUrl m_helpUrl; +}; + +#endif diff --git a/src/modules/welcome/qmlmain.cpp b/src/modules/welcome/qmlmain.cpp index 81bf08df5..cc538747a 100644 --- a/src/modules/welcome/qmlmain.cpp +++ b/src/modules/welcome/qmlmain.cpp @@ -16,6 +16,8 @@ #include "utils/Logger.h" +#include "Config.h" + int main(int argc, char **argv) { QApplication a( argc, argv ); @@ -46,6 +48,14 @@ int main(int argc, char **argv) mw.resize( QSize( 400, 400 ) ); mw.show(); + Config cnf; + if ( argc > 1 ) + { + cnf.setHelpUrl( QUrl( argv[1] ) ); + } + + qmlRegisterType< Config >( "io.calamares.modules.welcome", 1, 0, "Config" ); + qqw.setSource( QUrl::fromLocalFile("../src/modules/welcome/welcome.qml") ); return a.exec(); diff --git a/src/modules/welcome/welcome.qml b/src/modules/welcome/welcome.qml index f73b66571..d442bfa11 100644 --- a/src/modules/welcome/welcome.qml +++ b/src/modules/welcome/welcome.qml @@ -1,4 +1,5 @@ import QtQuick 2.0; +import io.calamares.modules.welcome 1.0; Rectangle { width: 200; From d41d8df2a55c794cbb74204dcb3978c54c88de28 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 13 Dec 2019 13:19:38 +0100 Subject: [PATCH 004/119] [welcome] Put Config object into context --- src/modules/welcome/Config.cpp | 1 + src/modules/welcome/Config.h | 2 +- src/modules/welcome/qmlmain.cpp | 9 ++++++++- src/modules/welcome/welcome.qml | 10 +++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/modules/welcome/Config.cpp b/src/modules/welcome/Config.cpp index 35ce99184..b46b85bf3 100644 --- a/src/modules/welcome/Config.cpp +++ b/src/modules/welcome/Config.cpp @@ -19,6 +19,7 @@ #include "Config.h" Config::Config() + : m_helpUrl( "https://www.kde.org/" ) { } diff --git a/src/modules/welcome/Config.h b/src/modules/welcome/Config.h index 91f5bec5c..7b0cfd734 100644 --- a/src/modules/welcome/Config.h +++ b/src/modules/welcome/Config.h @@ -25,7 +25,7 @@ class Config : public QObject { Q_OBJECT - Q_PROPERTY( QUrl helpUrl READ helpUrl WRITE setHelpUrl ) + Q_PROPERTY( QUrl helpUrl READ helpUrl WRITE setHelpUrl CONSTANT ) public: Config(); virtual ~Config(); diff --git a/src/modules/welcome/qmlmain.cpp b/src/modules/welcome/qmlmain.cpp index cc538747a..0aca1ddcd 100644 --- a/src/modules/welcome/qmlmain.cpp +++ b/src/modules/welcome/qmlmain.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,12 @@ #include "Config.h" +static Config* theConfig() +{ + static Config* cnf = new Config(); + return cnf; +} + int main(int argc, char **argv) { QApplication a( argc, argv ); @@ -54,7 +61,7 @@ int main(int argc, char **argv) cnf.setHelpUrl( QUrl( argv[1] ) ); } - qmlRegisterType< Config >( "io.calamares.modules.welcome", 1, 0, "Config" ); + qmlRegisterSingletonType< Config >( "io.calamares.modules.welcome", 1, 0, "PotatoConfig", [](QQmlEngine*, QJSEngine*) -> QObject* { return theConfig(); }); qqw.setSource( QUrl::fromLocalFile("../src/modules/welcome/welcome.qml") ); diff --git a/src/modules/welcome/welcome.qml b/src/modules/welcome/welcome.qml index d442bfa11..ba28d660b 100644 --- a/src/modules/welcome/welcome.qml +++ b/src/modules/welcome/welcome.qml @@ -1,4 +1,5 @@ import QtQuick 2.0; +import QtQuick.Controls 2.3; import io.calamares.modules.welcome 1.0; Rectangle { @@ -6,8 +7,15 @@ Rectangle { height: 200; color: "pink"; - Text { + Label { + id: label; anchors.centerIn: parent; text: "Welcome to Calamares"; } + + Button { + anchors.top: label.bottom; + text: PotatoConfig.helpUrl; + + } } From 03ed308bd93633466e7bde7852d7c21b9c3d5ed3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 13 Dec 2019 14:31:42 +0100 Subject: [PATCH 005/119] [welcome] Add QML model for translations --- src/modules/welcome/qmlmain.cpp | 4 ++++ src/modules/welcome/welcome.qml | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/modules/welcome/qmlmain.cpp b/src/modules/welcome/qmlmain.cpp index 0aca1ddcd..9c160fc1d 100644 --- a/src/modules/welcome/qmlmain.cpp +++ b/src/modules/welcome/qmlmain.cpp @@ -15,6 +15,7 @@ #include +#include "locale/LabelModel.h" #include "utils/Logger.h" #include "Config.h" @@ -61,8 +62,11 @@ int main(int argc, char **argv) cnf.setHelpUrl( QUrl( argv[1] ) ); } + // TODO: this should put the one config object in the context, rather than adding a factory function to share it everywhere qmlRegisterSingletonType< Config >( "io.calamares.modules.welcome", 1, 0, "PotatoConfig", [](QQmlEngine*, QJSEngine*) -> QObject* { return theConfig(); }); + qmlRegisterSingletonType< CalamaresUtils::Locale::LabelModel >( "io.calamares.locale", 1, 0, "LocaleModel", [](QQmlEngine*, QJSEngine*) -> QObject* { return CalamaresUtils::Locale::availableTranslations(); } ); + qqw.setSource( QUrl::fromLocalFile("../src/modules/welcome/welcome.qml") ); return a.exec(); diff --git a/src/modules/welcome/welcome.qml b/src/modules/welcome/welcome.qml index ba28d660b..bdb7c4416 100644 --- a/src/modules/welcome/welcome.qml +++ b/src/modules/welcome/welcome.qml @@ -1,6 +1,7 @@ import QtQuick 2.0; import QtQuick.Controls 2.3; import io.calamares.modules.welcome 1.0; +import io.calamares.locale 1.0; Rectangle { width: 200; @@ -14,8 +15,15 @@ Rectangle { } Button { + id: thebutton; anchors.top: label.bottom; text: PotatoConfig.helpUrl; } + + ListView { + anchors.fill: parent; + model: LocaleModel; + delegate: Label { text: display } + } } From 55f61fda3527c4072060b08d1833cd44788b4bc0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 13 Dec 2019 18:18:02 +0100 Subject: [PATCH 006/119] [welcome] Create branding and settings objects --- src/modules/welcome/qmlmain.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/modules/welcome/qmlmain.cpp b/src/modules/welcome/qmlmain.cpp index 9c160fc1d..93017a9c7 100644 --- a/src/modules/welcome/qmlmain.cpp +++ b/src/modules/welcome/qmlmain.cpp @@ -2,6 +2,8 @@ * models from libcalamares for displaying a welcome. */ +#include + #include #include #include @@ -15,6 +17,8 @@ #include +#include "JobQueue.h" +#include "Settings.h" #include "locale/LabelModel.h" #include "utils/Logger.h" @@ -44,6 +48,9 @@ int main(int argc, char **argv) Logger::setupLogLevel( Logger::LOGVERBOSE ); + std::unique_ptr< Calamares::Settings > settings_p( new Calamares::Settings( QString(), true ) ); + std::unique_ptr< Calamares::JobQueue > jobqueue_p( new Calamares::JobQueue( nullptr ) ); + QMainWindow mw; QWidget background; QVBoxLayout vl; From 6c4efc1f9ce512f710cecb78a0ef1eea94ed1b17 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 13 Dec 2019 18:23:01 +0100 Subject: [PATCH 007/119] [welcome] Add Branding object to QML demo --- src/modules/welcome/qmlmain.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/welcome/qmlmain.cpp b/src/modules/welcome/qmlmain.cpp index 93017a9c7..96d9d245f 100644 --- a/src/modules/welcome/qmlmain.cpp +++ b/src/modules/welcome/qmlmain.cpp @@ -17,6 +17,7 @@ #include +#include "Branding.h" #include "JobQueue.h" #include "Settings.h" #include "locale/LabelModel.h" @@ -51,6 +52,9 @@ int main(int argc, char **argv) std::unique_ptr< Calamares::Settings > settings_p( new Calamares::Settings( QString(), true ) ); std::unique_ptr< Calamares::JobQueue > jobqueue_p( new Calamares::JobQueue( nullptr ) ); + Calamares::Branding defaultBrand( "src/branding/default/branding.desc" ); + cDebug() << "Branding @" << (void *)Calamares::Branding::instance(); + QMainWindow mw; QWidget background; QVBoxLayout vl; From 53b208e891d1f8e7ecc77437ad6c3a0cd54228bd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 14 Dec 2019 12:48:09 +0100 Subject: [PATCH 008/119] [welcomeq] Start new ViewStep for QML-based welcome --- src/modules/welcomeq/CMakeLists.txt | 41 ++++ src/modules/welcomeq/Config.cpp | 28 +++ src/modules/welcomeq/Config.h | 40 ++++ src/modules/welcomeq/WelcomeQmlViewStep.cpp | 243 ++++++++++++++++++++ src/modules/welcomeq/WelcomeQmlViewStep.h | 85 +++++++ 5 files changed, 437 insertions(+) create mode 100644 src/modules/welcomeq/CMakeLists.txt create mode 100644 src/modules/welcomeq/Config.cpp create mode 100644 src/modules/welcomeq/Config.h create mode 100644 src/modules/welcomeq/WelcomeQmlViewStep.cpp create mode 100644 src/modules/welcomeq/WelcomeQmlViewStep.h diff --git a/src/modules/welcomeq/CMakeLists.txt b/src/modules/welcomeq/CMakeLists.txt new file mode 100644 index 000000000..2105c77e6 --- /dev/null +++ b/src/modules/welcomeq/CMakeLists.txt @@ -0,0 +1,41 @@ +set( _welcome ${CMAKE_CURRENT_SOURCE_DIR}/../welcome ) + +include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ${_welcome} ) + +# DUPLICATED WITH WELCOME MODULE +find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED DBus Network ) + +find_package( LIBPARTED ) +if ( LIBPARTED_FOUND ) + set( PARTMAN_SRC ${_welcome}/checker/partman_devices.c ) + set( CHECKER_LINK_LIBRARIES ${LIBPARTED_LIBRARY} ) +else() + set( PARTMAN_SRC ) + set( CHECKER_LINK_LIBRARIES ) + add_definitions( -DWITHOUT_LIBPARTED ) +endif() + +set( CHECKER_SOURCES + ${_welcome}/checker/CheckerContainer.cpp + ${_welcome}/checker/GeneralRequirements.cpp + ${_welcome}/checker/ResultWidget.cpp + ${_welcome}/checker/ResultsListWidget.cpp + ${PARTMAN_SRC} +) + +calamares_add_plugin( welcomeq + TYPE viewmodule + EXPORT_MACRO PLUGINDLLEXPORT_PRO + SOURCES + ${CHECKER_SOURCES} + WelcomeQmlViewStep.cpp + Config.cpp + RESOURCES + welcomeq.qrc + LINK_PRIVATE_LIBRARIES + calamaresui + ${CHECKER_LINK_LIBRARIES} + Qt5::DBus + Qt5::Network + SHARED_LIB +) diff --git a/src/modules/welcomeq/Config.cpp b/src/modules/welcomeq/Config.cpp new file mode 100644 index 000000000..b46b85bf3 --- /dev/null +++ b/src/modules/welcomeq/Config.cpp @@ -0,0 +1,28 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, 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 . + */ + +#include "Config.h" + +Config::Config() + : m_helpUrl( "https://www.kde.org/" ) +{ +} + +Config::~Config() +{ +} diff --git a/src/modules/welcomeq/Config.h b/src/modules/welcomeq/Config.h new file mode 100644 index 000000000..7b0cfd734 --- /dev/null +++ b/src/modules/welcomeq/Config.h @@ -0,0 +1,40 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, 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 WELCOME_CONFIG_H +#define WELCOME_CONFIG_H + +#include +#include + +class Config : public QObject +{ + Q_OBJECT + Q_PROPERTY( QUrl helpUrl READ helpUrl WRITE setHelpUrl CONSTANT ) +public: + Config(); + virtual ~Config(); + + QUrl helpUrl() const { return m_helpUrl; } + void setHelpUrl( const QUrl& url ) { m_helpUrl = url; } + +private: + QUrl m_helpUrl; +}; + +#endif diff --git a/src/modules/welcomeq/WelcomeQmlViewStep.cpp b/src/modules/welcomeq/WelcomeQmlViewStep.cpp new file mode 100644 index 000000000..6a01f1ada --- /dev/null +++ b/src/modules/welcomeq/WelcomeQmlViewStep.cpp @@ -0,0 +1,243 @@ +/* === This file is part of Calamares - === + * + * Copyright 2014-2015, 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 . + */ + +#include "WelcomeQmlViewStep.h" + +#include "checker/GeneralRequirements.h" + +#include "geoip/Handler.h" +#include "locale/LabelModel.h" +#include "locale/Lookup.h" +#include "utils/Logger.h" +#include "utils/Variant.h" + +#include "Branding.h" +#include "modulesystem/ModuleManager.h" + +#include +#include +#include + +CALAMARES_PLUGIN_FACTORY_DEFINITION( WelcomeQmlViewStepFactory, registerPlugin< WelcomeQmlViewStep >(); ) + +WelcomeQmlViewStep::WelcomeQmlViewStep( QObject* parent ) + : Calamares::ViewStep( parent ) + , m_requirementsChecker( new GeneralRequirements( this ) ) +{ + connect( Calamares::ModuleManager::instance(), + &Calamares::ModuleManager::requirementsComplete, + this, + &WelcomeQmlViewStep::nextStatusChanged ); +} + + +WelcomeQmlViewStep::~WelcomeQmlViewStep() +{ +} + + +QString +WelcomeQmlViewStep::prettyName() const +{ + return tr( "Welcome" ); +} + + +QWidget* +WelcomeQmlViewStep::widget() +{ + return nullptr; +} + + +bool +WelcomeQmlViewStep::isNextEnabled() const +{ + // TODO: should return true + return false; +} + + +bool +WelcomeQmlViewStep::isBackEnabled() const +{ + // TODO: should return true (it's weird that you are not allowed to have welcome *after* anything + return false; +} + + +bool +WelcomeQmlViewStep::isAtBeginning() const +{ + // TODO: adjust to "pages" in the QML + return true; +} + + +bool +WelcomeQmlViewStep::isAtEnd() const +{ + // TODO: adjust to "pages" in the QML + return true; +} + + +Calamares::JobList +WelcomeQmlViewStep::jobs() const +{ + return Calamares::JobList(); +} + + +/** @brief Look up a URL for a button + * + * Looks up @p key in @p map; if it is a *boolean* value, then + * assume an old-style configuration, and fetch the string from + * the branding settings @p e. If it is a string, not a boolean, + * use it as-is. If not found, or a weird type, returns empty. + * + * This allows switching the showKnownIssuesUrl and similar settings + * in welcome.conf from a boolean (deferring to branding) to an + * actual string for immediate use. Empty strings, as well as + * "false" as a setting, will hide the buttons as before. + */ +static QString +jobOrBrandingSetting( Calamares::Branding::StringEntry e, const QVariantMap& map, const QString& key ) +{ + if ( !map.contains( key ) ) + { + return QString(); + } + auto v = map.value( key ); + if ( v.type() == QVariant::Bool ) + { + return v.toBool() ? ( *e ) : QString(); + } + if ( v.type() == QVariant::String ) + { + return v.toString(); + } + + return QString(); +} + +void +WelcomeQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) +{ + using Calamares::Branding; + + m_config.setHelpUrl( jobOrBrandingSetting( Branding::SupportUrl, configurationMap, "showSupportUrl" ) ); + // TODO: expand Config class and set the remaining fields + + // TODO: figure out how the requirements (held by ModuleManager) should be accessible + // to QML as a odel. + if ( configurationMap.contains( "requirements" ) + && configurationMap.value( "requirements" ).type() == QVariant::Map ) + { + m_requirementsChecker->setConfigurationMap( configurationMap.value( "requirements" ).toMap() ); + } + else + cWarning() << "no valid requirements map found in welcome " + "module configuration."; + + bool ok = false; + QVariantMap geoip = CalamaresUtils::getSubMap( configurationMap, "geoip", ok ); + if ( ok ) + { + using FWString = QFutureWatcher< QString >; + + auto* handler = new CalamaresUtils::GeoIP::Handler( CalamaresUtils::getString( geoip, "style" ), + CalamaresUtils::getString( geoip, "url" ), + CalamaresUtils::getString( geoip, "selector" ) ); + if ( handler->type() != CalamaresUtils::GeoIP::Handler::Type::None ) + { + auto* future = new FWString(); + connect( future, &FWString::finished, [view = this, f = future, h = handler]() { + QString countryResult = f->future().result(); + cDebug() << "GeoIP result for welcome=" << countryResult; + view->setCountry( countryResult, h ); + f->deleteLater(); + delete h; + } ); + future->setFuture( handler->queryRaw() ); + } + else + { + // Would not produce useful country code anyway. + delete handler; + } + } + + QString language = CalamaresUtils::getString( configurationMap, "languageIcon" ); + if ( !language.isEmpty() ) + { + auto icon = Calamares::Branding::instance()->image( language, QSize( 48, 48 ) ); + if ( !icon.isNull() ) + { + // TODO: figure out where to set this: Config? + } + } +} + +Calamares::RequirementsList +WelcomeQmlViewStep::checkRequirements() +{ + return m_requirementsChecker->checkRequirements(); +} + +static inline void +logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler ) +{ + if ( handler ) + { + cDebug() << Logger::SubEntry << "Obtained from" << handler->url() << " (" + << static_cast< int >( handler->type() ) << handler->selector() << ')'; + } +} + +void +WelcomeQmlViewStep::setCountry( const QString& countryCode, CalamaresUtils::GeoIP::Handler* handler ) +{ + if ( countryCode.length() != 2 ) + { + cDebug() << "Unusable country code" << countryCode; + logGeoIPHandler( handler ); + return; + } + + auto c_l = CalamaresUtils::Locale::countryData( countryCode ); + if ( c_l.first == QLocale::Country::AnyCountry ) + { + cDebug() << "Unusable country code" << countryCode; + logGeoIPHandler( handler ); + return; + } + else + { + int r = CalamaresUtils::Locale::availableTranslations()->find( countryCode ); + if ( r < 0 ) + { + cDebug() << "Unusable country code" << countryCode << "(no suitable translation)"; + } + if ( ( r >= 0 ) ) + { + // TODO: update Config to point to selected language + } + } +} diff --git a/src/modules/welcomeq/WelcomeQmlViewStep.h b/src/modules/welcomeq/WelcomeQmlViewStep.h new file mode 100644 index 000000000..162df0a7f --- /dev/null +++ b/src/modules/welcomeq/WelcomeQmlViewStep.h @@ -0,0 +1,85 @@ +/* === This file is part of Calamares - === + * + * Copyright 20195, 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 WELCOME_QMLVIEWSTEP_H +#define WELCOME_QMLVIEWSTEP_H + +#include "Config.h" + +#include "modulesystem/Requirement.h" +#include "utils/PluginFactory.h" +#include "viewpages/ViewStep.h" + +#include + +#include +#include + +namespace CalamaresUtils +{ +namespace GeoIP +{ +class Handler; +} +} // namespace CalamaresUtils + +class GeneralRequirements; + +// TODO: Needs a generic Calamares::QmlViewStep as base class +// TODO: refactor and move what makes sense to base class +class PLUGINDLLEXPORT WelcomeQmlViewStep : public Calamares::ViewStep +{ + Q_OBJECT + +public: + explicit WelcomeQmlViewStep( QObject* parent = nullptr ); + virtual ~WelcomeQmlViewStep() override; + + QString prettyName() const override; + + QWidget* widget() override; + + bool isNextEnabled() const override; + bool isBackEnabled() const override; + + bool isAtBeginning() const override; + bool isAtEnd() const override; + + Calamares::JobList jobs() const override; + + void setConfigurationMap( const QVariantMap& configurationMap ) override; + + /** @brief Sets the country that Calamares is running in. + * + * This (ideally) sets up language and locale settings that are right for + * the given 2-letter country code. Uses the handler's information (if + * given) for error reporting. + */ + void setCountry( const QString&, CalamaresUtils::GeoIP::Handler* handler ); + + Calamares::RequirementsList checkRequirements() override; + +private: + // TODO: a generic QML viewstep should return a config object from a method + Config m_config; + GeneralRequirements* m_requirementsChecker; +}; + +CALAMARES_PLUGIN_FACTORY_DECLARATION( WelcomeQmlViewStepFactory ) + +#endif // WELCOME_QMLVIEWSTEP_H From 8e2d257040a1da0d1d75f50f0e5004001f76dfe1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sat, 14 Dec 2019 13:11:14 +0100 Subject: [PATCH 009/119] [welcomeq] Add QML machinery (uninitialized) --- src/modules/welcomeq/WelcomeQmlViewStep.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/modules/welcomeq/WelcomeQmlViewStep.h b/src/modules/welcomeq/WelcomeQmlViewStep.h index 162df0a7f..7d10e35ef 100644 --- a/src/modules/welcomeq/WelcomeQmlViewStep.h +++ b/src/modules/welcomeq/WelcomeQmlViewStep.h @@ -40,6 +40,10 @@ class Handler; class GeneralRequirements; +class QQmlComponent; +class QQuickItem; +class QQuickWidget; + // TODO: Needs a generic Calamares::QmlViewStep as base class // TODO: refactor and move what makes sense to base class class PLUGINDLLEXPORT WelcomeQmlViewStep : public Calamares::ViewStep @@ -78,6 +82,12 @@ private: // TODO: a generic QML viewstep should return a config object from a method Config m_config; GeneralRequirements* m_requirementsChecker; + + // TODO: these need to be in the base class (also a base class of ExecutionViewStep) + QQuickWidget* m_qmlWidget; + QQmlComponent* m_qmlComponent; + QQuickItem* m_qmlItem; + }; CALAMARES_PLUGIN_FACTORY_DECLARATION( WelcomeQmlViewStepFactory ) From 56f926094e6dd0f7b2a4f5a6c62fc70090c37a1c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 9 Jan 2020 15:11:36 +0100 Subject: [PATCH 010/119] [welcomeq] Update comments - Copyright years - Purpose of this module --- src/modules/welcomeq/CMakeLists.txt | 3 +++ src/modules/welcomeq/Config.cpp | 2 +- src/modules/welcomeq/Config.h | 2 +- src/modules/welcomeq/WelcomeQmlViewStep.cpp | 2 +- src/modules/welcomeq/WelcomeQmlViewStep.h | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/welcomeq/CMakeLists.txt b/src/modules/welcomeq/CMakeLists.txt index 2105c77e6..7ee0350af 100644 --- a/src/modules/welcomeq/CMakeLists.txt +++ b/src/modules/welcomeq/CMakeLists.txt @@ -1,3 +1,6 @@ +# This is a re-write of the welcome module using QML view steps +# instead of widgets. + set( _welcome ${CMAKE_CURRENT_SOURCE_DIR}/../welcome ) include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ${_welcome} ) diff --git a/src/modules/welcomeq/Config.cpp b/src/modules/welcomeq/Config.cpp index b46b85bf3..6d085143c 100644 --- a/src/modules/welcomeq/Config.cpp +++ b/src/modules/welcomeq/Config.cpp @@ -1,6 +1,6 @@ /* === This file is part of Calamares - === * - * Copyright 2019, Adriaan de Groot + * Copyright 2019-2020, 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 diff --git a/src/modules/welcomeq/Config.h b/src/modules/welcomeq/Config.h index 7b0cfd734..2295d4ee2 100644 --- a/src/modules/welcomeq/Config.h +++ b/src/modules/welcomeq/Config.h @@ -1,6 +1,6 @@ /* === This file is part of Calamares - === * - * Copyright 2019, Adriaan de Groot + * Copyright 2019-2020, 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 diff --git a/src/modules/welcomeq/WelcomeQmlViewStep.cpp b/src/modules/welcomeq/WelcomeQmlViewStep.cpp index 6a01f1ada..2a5b0f661 100644 --- a/src/modules/welcomeq/WelcomeQmlViewStep.cpp +++ b/src/modules/welcomeq/WelcomeQmlViewStep.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018,2020 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 diff --git a/src/modules/welcomeq/WelcomeQmlViewStep.h b/src/modules/welcomeq/WelcomeQmlViewStep.h index 7d10e35ef..5486d8d31 100644 --- a/src/modules/welcomeq/WelcomeQmlViewStep.h +++ b/src/modules/welcomeq/WelcomeQmlViewStep.h @@ -1,6 +1,6 @@ /* === This file is part of Calamares - === * - * Copyright 20195, Adriaan de Groot + * Copyright 2019-2020 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 From 63b8de00ef55f3a16d6512347d362f46e5f48c44 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 9 Jan 2020 15:25:30 +0100 Subject: [PATCH 011/119] CI: allow plain clang-format (Tumbleweed) --- ci/calamaresstyle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/calamaresstyle b/ci/calamaresstyle index 8b13b6f31..65dc83de7 100755 --- a/ci/calamaresstyle +++ b/ci/calamaresstyle @@ -8,7 +8,7 @@ # AS=$( which astyle ) -for _cf in clang-format-7 clang-format-8 clang-format70 clang-format80 +for _cf in clang-format-7 clang-format-8 clang-format70 clang-format80 clang-format do # Not an error if this particular clang-format isn't found CF=$( which $_cf || true ) From 970702daa080446b23b9c6af4df53fb95e3d6aa8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 9 Jan 2020 21:36:43 +0100 Subject: [PATCH 012/119] [libcalamaresui] Tidy up includes --- src/libcalamaresui/viewpages/BlankViewStep.h | 7 +------ src/libcalamaresui/viewpages/ViewStep.h | 8 ++++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/libcalamaresui/viewpages/BlankViewStep.h b/src/libcalamaresui/viewpages/BlankViewStep.h index 17d323c85..ab44205ac 100644 --- a/src/libcalamaresui/viewpages/BlankViewStep.h +++ b/src/libcalamaresui/viewpages/BlankViewStep.h @@ -19,12 +19,7 @@ #ifndef BLANKVIEWSTEP_H #define BLANKVIEWSTEP_H -#include - -#include -#include - -class QWidget; +#include "viewpages/ViewStep.h" namespace Calamares { diff --git a/src/libcalamaresui/viewpages/ViewStep.h b/src/libcalamaresui/viewpages/ViewStep.h index 8c5020f83..3ae05c49f 100644 --- a/src/libcalamaresui/viewpages/ViewStep.h +++ b/src/libcalamaresui/viewpages/ViewStep.h @@ -20,15 +20,15 @@ #ifndef VIEWSTEP_H #define VIEWSTEP_H -#include -#include -#include - #include "Job.h" #include "UiDllMacro.h" #include "modulesystem/Requirement.h" +#include +#include +#include + namespace Calamares { From 16a460adff38e7043e5cdd7347c7be97616beda5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 Jan 2020 11:56:30 +0100 Subject: [PATCH 013/119] [libcalamaresui] Move ExecutionViewStep where it belongs - viewpages/ collects the ViewStep implementations - chase header moving and tidy some #includes --- src/libcalamaresui/CMakeLists.txt | 2 +- src/libcalamaresui/ViewManager.cpp | 7 +++---- src/libcalamaresui/modulesystem/ModuleManager.cpp | 6 +++--- src/libcalamaresui/{ => viewpages}/ExecutionViewStep.cpp | 4 ++-- src/libcalamaresui/{ => viewpages}/ExecutionViewStep.h | 0 src/modules/summary/SummaryPage.cpp | 2 +- 6 files changed, 10 insertions(+), 11 deletions(-) rename src/libcalamaresui/{ => viewpages}/ExecutionViewStep.cpp (99%) rename src/libcalamaresui/{ => viewpages}/ExecutionViewStep.h (100%) diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index a9d31c2c3..c315a6b3e 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -18,6 +18,7 @@ set( calamaresui_SOURCES utils/Paste.cpp viewpages/BlankViewStep.cpp + viewpages/ExecutionViewStep.cpp viewpages/ViewStep.cpp widgets/ClickableLabel.cpp @@ -25,7 +26,6 @@ set( calamaresui_SOURCES widgets/WaitingWidget.cpp ${CMAKE_SOURCE_DIR}/3rdparty/waitingspinnerwidget.cpp - ExecutionViewStep.cpp Branding.cpp ViewManager.cpp ) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 68d918971..4721370b9 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -21,17 +21,16 @@ #include "ViewManager.h" -#include "viewpages/BlankViewStep.h" -#include "viewpages/ViewStep.h" - #include "Branding.h" -#include "ExecutionViewStep.h" #include "JobQueue.h" #include "Settings.h" #include "utils/Logger.h" #include "utils/Paste.h" #include "utils/Retranslator.h" +#include "viewpages/BlankViewStep.h" +#include "viewpages/ViewStep.h" +#include "viewpages/ExecutionViewStep.h" #include #include diff --git a/src/libcalamaresui/modulesystem/ModuleManager.cpp b/src/libcalamaresui/modulesystem/ModuleManager.cpp index 33b638e64..8591a558f 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.cpp +++ b/src/libcalamaresui/modulesystem/ModuleManager.cpp @@ -19,7 +19,6 @@ #include "ModuleManager.h" -#include "ExecutionViewStep.h" #include "Module.h" #include "RequirementsChecker.h" #include "Settings.h" @@ -27,6 +26,7 @@ #include "utils/Logger.h" #include "utils/Yaml.h" +#include "viewpages/ExecutionViewStep.h" #include #include @@ -131,9 +131,9 @@ ModuleManager::doInit() cDebug() << "ModuleManager module search path does not exist:" << path; } } - // At this point m_availableDescriptorsByModuleName is filled with + // At this point m_availableDescriptorsByModuleName is filled with // the modules that were found in the search paths. - cDebug() << "Found" + cDebug() << "Found" << m_availableDescriptorsByModuleName.count() << "modules" << m_moduleDirectoriesByModuleName.count() << "names"; emit initDone(); diff --git a/src/libcalamaresui/ExecutionViewStep.cpp b/src/libcalamaresui/viewpages/ExecutionViewStep.cpp similarity index 99% rename from src/libcalamaresui/ExecutionViewStep.cpp rename to src/libcalamaresui/viewpages/ExecutionViewStep.cpp index 501995c07..e0921910d 100644 --- a/src/libcalamaresui/ExecutionViewStep.cpp +++ b/src/libcalamaresui/viewpages/ExecutionViewStep.cpp @@ -18,16 +18,16 @@ * along with Calamares. If not, see . */ -#include +#include "ExecutionViewStep.h" #include "Branding.h" #include "Job.h" #include "JobQueue.h" #include "Settings.h" #include "ViewManager.h" + #include "modulesystem/Module.h" #include "modulesystem/ModuleManager.h" - #include "utils/CalamaresUtilsGui.h" #include "utils/Dirs.h" #include "utils/Logger.h" diff --git a/src/libcalamaresui/ExecutionViewStep.h b/src/libcalamaresui/viewpages/ExecutionViewStep.h similarity index 100% rename from src/libcalamaresui/ExecutionViewStep.h rename to src/libcalamaresui/viewpages/ExecutionViewStep.h diff --git a/src/modules/summary/SummaryPage.cpp b/src/modules/summary/SummaryPage.cpp index 61a9c2ec2..7114f27ee 100644 --- a/src/modules/summary/SummaryPage.cpp +++ b/src/modules/summary/SummaryPage.cpp @@ -23,13 +23,13 @@ #include "SummaryViewStep.h" #include "Branding.h" -#include "ExecutionViewStep.h" #include "Settings.h" #include "ViewManager.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" #include "utils/Retranslator.h" +#include "viewpages/ExecutionViewStep.h" #include #include From 492483921792c0a424bc97b717a714382702f74a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 Jan 2020 12:13:40 +0100 Subject: [PATCH 014/119] [libcalamaresui] Start QmlViewStep --- src/libcalamaresui/CMakeLists.txt | 1 + src/libcalamaresui/viewpages/QmlViewStep.cpp | 87 ++++++++++++++++++++ src/libcalamaresui/viewpages/QmlViewStep.h | 61 ++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 src/libcalamaresui/viewpages/QmlViewStep.cpp create mode 100644 src/libcalamaresui/viewpages/QmlViewStep.h diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index c315a6b3e..061a401bb 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -19,6 +19,7 @@ set( calamaresui_SOURCES viewpages/BlankViewStep.cpp viewpages/ExecutionViewStep.cpp + viewpages/QmlViewStep.cpp viewpages/ViewStep.cpp widgets/ClickableLabel.cpp diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp new file mode 100644 index 000000000..060a4660e --- /dev/null +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -0,0 +1,87 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, 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 . + */ + +#include "QmlViewStep.h" + +namespace Calamares +{ + +QmlViewStep::QmlViewStep( const QString& name, QObject* parent ) + : ViewStep( parent ) + , m_name( name ) +{ +} + +QmlViewStep::~QmlViewStep() {} + +QString +QmlViewStep::prettyName() const +{ + // TODO: query the QML itself + return tr( "QML Step %1" ).arg( m_name ); +} + + +} // namespace Calamares + +bool +Calamares::QmlViewStep::isAtBeginning() const +{ + return true; +} + +bool +Calamares::QmlViewStep::isAtEnd() const +{ + return true; +} +bool +Calamares::QmlViewStep::isBackEnabled() const +{ + return true; +} + +bool +Calamares::QmlViewStep::isNextEnabled() const +{ + return true; +} + +Calamares::JobList +Calamares::QmlViewStep::jobs() const +{ + return JobList(); +} + +void +Calamares::QmlViewStep::onActivate() +{ + // TODO: call into QML +} + +void +Calamares::QmlViewStep::onLeave() +{ + // TODO: call into QML +} + +QWidget* +Calamares::QmlViewStep::widget() +{ + return nullptr; +} diff --git a/src/libcalamaresui/viewpages/QmlViewStep.h b/src/libcalamaresui/viewpages/QmlViewStep.h new file mode 100644 index 000000000..53a5882d5 --- /dev/null +++ b/src/libcalamaresui/viewpages/QmlViewStep.h @@ -0,0 +1,61 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, 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 QMLVIEWSTEP_H +#define QMLVIEWSTEP_H + +#include "viewpages/ViewStep.h" + +namespace Calamares +{ + +/** @brief A viewstep that uses QML for the UI + * + * This is generally a **base** class for other view steps, but + * it can be used stand-alone for viewsteps that don't really have + * any functionality. + */ +class QmlViewStep : public Calamares::ViewStep +{ + Q_OBJECT + +public: + QmlViewStep( const QString& name, QObject* parent = nullptr ); + virtual ~QmlViewStep() override; + + virtual QString prettyName() const override; + + virtual QWidget* widget() override; + + virtual bool isNextEnabled() const override; + virtual bool isBackEnabled() const override; + + virtual bool isAtBeginning() const override; + virtual bool isAtEnd() const override; + + virtual void onActivate() override; + virtual void onLeave() override; + + virtual JobList jobs() const override; + +private: + QString m_name; +}; + +} // namespace Calamares +#endif From 1cc40bda83dc1245db97a6b1d54111b7faf15b28 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 Jan 2020 12:38:46 +0100 Subject: [PATCH 015/119] [dummyqml] Stub of a QML module --- src/modules/dummyqml/CMakeLists.txt | 11 +++++++ src/modules/dummyqml/DummyQmlViewStep.cpp | 35 ++++++++++++++++++++ src/modules/dummyqml/DummyQmlViewStep.h | 40 +++++++++++++++++++++++ src/modules/dummyqml/dummyqml.qml | 12 +++++++ src/modules/dummyqml/dummyqml.qrc | 5 +++ 5 files changed, 103 insertions(+) create mode 100644 src/modules/dummyqml/CMakeLists.txt create mode 100644 src/modules/dummyqml/DummyQmlViewStep.cpp create mode 100644 src/modules/dummyqml/DummyQmlViewStep.h create mode 100644 src/modules/dummyqml/dummyqml.qml create mode 100644 src/modules/dummyqml/dummyqml.qrc diff --git a/src/modules/dummyqml/CMakeLists.txt b/src/modules/dummyqml/CMakeLists.txt new file mode 100644 index 000000000..9a7532e9e --- /dev/null +++ b/src/modules/dummyqml/CMakeLists.txt @@ -0,0 +1,11 @@ +calamares_add_plugin( dummyqml + TYPE viewmodule + EXPORT_MACRO PLUGINDLLEXPORT_PRO + SOURCES + DummyQmlViewStep.cpp + RESOURCES + dummyqml.qrc + LINK_PRIVATE_LIBRARIES + calamaresui + SHARED_LIB +) diff --git a/src/modules/dummyqml/DummyQmlViewStep.cpp b/src/modules/dummyqml/DummyQmlViewStep.cpp new file mode 100644 index 000000000..985d2985a --- /dev/null +++ b/src/modules/dummyqml/DummyQmlViewStep.cpp @@ -0,0 +1,35 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, 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 . + */ + +#include "DummyQmlViewStep.h" + +DummyQmlViewStep::DummyQmlViewStep( QObject* parent ) + : Calamares::QmlViewStep( "dummyqml", parent ) +{ +} + +DummyQmlViewStep::~DummyQmlViewStep() {} + +QString +DummyQmlViewStep::prettyName() const +{ + return tr( "Example QML page" ); +} + + +CALAMARES_PLUGIN_FACTORY_DEFINITION( DummyQmlViewStepFactory, registerPlugin< DummyQmlViewStep >(); ) diff --git a/src/modules/dummyqml/DummyQmlViewStep.h b/src/modules/dummyqml/DummyQmlViewStep.h new file mode 100644 index 000000000..ffc358fe7 --- /dev/null +++ b/src/modules/dummyqml/DummyQmlViewStep.h @@ -0,0 +1,40 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, 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 DUMMYQMLVIEWSTEP_H +#define DUMMYQMLVIEWSTEP_H + +#include "utils/PluginFactory.h" +#include "viewpages/QmlViewStep.h" + +class DummyQmlViewStep : public Calamares::QmlViewStep +{ + Q_OBJECT + +public: + DummyQmlViewStep( QObject* parent = nullptr ); + virtual ~DummyQmlViewStep() override; + + virtual QString prettyName() const override; + +private: +}; + +CALAMARES_PLUGIN_FACTORY_DECLARATION( DummyQmlViewStepFactory ) + +#endif diff --git a/src/modules/dummyqml/dummyqml.qml b/src/modules/dummyqml/dummyqml.qml new file mode 100644 index 000000000..6cab24bec --- /dev/null +++ b/src/modules/dummyqml/dummyqml.qml @@ -0,0 +1,12 @@ +import QtQuick 2.3 + +Rectangle { + width: 200 + height: 100 + color: "red" + + Text { + anchors.centerIn: parent + text: "Hello, World!" + } +} diff --git a/src/modules/dummyqml/dummyqml.qrc b/src/modules/dummyqml/dummyqml.qrc new file mode 100644 index 000000000..85b1da5ca --- /dev/null +++ b/src/modules/dummyqml/dummyqml.qrc @@ -0,0 +1,5 @@ + + + dummyqml.qml + + From 60c1d40b2077df941a6d197b2d1ab0a711bc6316 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 Jan 2020 12:56:46 +0100 Subject: [PATCH 016/119] [libcalamaresui] Log which ViewStep is broken - a ViewStep with no widget will crash the application; print out its name before doing so. --- src/libcalamaresui/ViewManager.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/libcalamaresui/ViewManager.cpp b/src/libcalamaresui/ViewManager.cpp index 4721370b9..7492f1f8b 100644 --- a/src/libcalamaresui/ViewManager.cpp +++ b/src/libcalamaresui/ViewManager.cpp @@ -158,13 +158,6 @@ void ViewManager::insertViewStep( int before, ViewStep* step ) { m_steps.insert( before, step ); - QLayout* layout = step->widget()->layout(); - if ( layout ) - { - layout->setContentsMargins( 0, 0, 0, 0 ); - } - m_stack->insertWidget( before, step->widget() ); - connect( step, &ViewStep::enlarge, this, &ViewManager::enlarge ); connect( step, &ViewStep::nextStatusChanged, this, [this]( bool status ) { ViewStep* vs = qobject_cast< ViewStep* >( sender() ); @@ -177,6 +170,17 @@ ViewManager::insertViewStep( int before, ViewStep* step ) } } ); + if ( !step->widget() ) + { + cError() << "ViewStep" << step->moduleInstanceKey() << "has no widget."; + } + + QLayout* layout = step->widget()->layout(); + if ( layout ) + { + layout->setContentsMargins( 0, 0, 0, 0 ); + } + m_stack->insertWidget( before, step->widget() ); m_stack->setCurrentIndex( 0 ); step->widget()->setFocus(); } From 44b250809fbed389dadefdc88b2c32ff3de5249a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 Jan 2020 13:10:55 +0100 Subject: [PATCH 017/119] [libcalamaresui] Add spinner to QmlViewStep - view step now has a widget, doesn't load QML yet --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 11 ++++++++++- src/libcalamaresui/viewpages/QmlViewStep.h | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index 060a4660e..11637d04b 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -18,13 +18,22 @@ #include "QmlViewStep.h" +#include "widgets/WaitingWidget.h" + +#include +#include + namespace Calamares { QmlViewStep::QmlViewStep( const QString& name, QObject* parent ) : ViewStep( parent ) , m_name( name ) + , m_widget( new QWidget ) + , m_spinner( new WaitingWidget( tr( "Loading ..." ) ) ) { + QVBoxLayout* layout = new QVBoxLayout( m_widget ); + layout->addWidget( m_spinner ); } QmlViewStep::~QmlViewStep() {} @@ -83,5 +92,5 @@ Calamares::QmlViewStep::onLeave() QWidget* Calamares::QmlViewStep::widget() { - return nullptr; + return m_widget; } diff --git a/src/libcalamaresui/viewpages/QmlViewStep.h b/src/libcalamaresui/viewpages/QmlViewStep.h index 53a5882d5..d1b28af35 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.h +++ b/src/libcalamaresui/viewpages/QmlViewStep.h @@ -21,6 +21,11 @@ #include "viewpages/ViewStep.h" +class QQmlComponent; +class QQuickItem; +class QQuickWidget; +class WaitingWidget; + namespace Calamares { @@ -55,6 +60,12 @@ public: private: QString m_name; + + QWidget* m_widget = nullptr; + WaitingWidget* m_spinner = nullptr; + QQuickWidget* m_qmlShow = nullptr; + QQmlComponent* m_qmlComponent = nullptr; + QQuickItem* m_qmlObject = nullptr; }; } // namespace Calamares From c03c6fc8ed9e13bff8532dee983deebf9bbd06f6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 Jan 2020 13:39:03 +0100 Subject: [PATCH 018/119] [libcalamaresui] Qml loading - this is mostly copied from ExecutionViewStep (only the V2 QML loading), which does the same kind of thing. - loading from QRC does not work yet --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 71 ++++++++++++++++++++ src/libcalamaresui/viewpages/QmlViewStep.h | 9 ++- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index 11637d04b..3cfcc7371 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -18,8 +18,14 @@ #include "QmlViewStep.h" +#include "utils/Dirs.h" +#include "utils/Logger.h" #include "widgets/WaitingWidget.h" +#include +#include +#include +#include #include #include @@ -31,9 +37,24 @@ QmlViewStep::QmlViewStep( const QString& name, QObject* parent ) , m_name( name ) , m_widget( new QWidget ) , m_spinner( new WaitingWidget( tr( "Loading ..." ) ) ) + , m_qmlWidget( new QQuickWidget ) { QVBoxLayout* layout = new QVBoxLayout( m_widget ); layout->addWidget( m_spinner ); + + m_qmlWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); + m_qmlWidget->setResizeMode( QQuickWidget::SizeRootObjectToView ); + m_qmlWidget->engine()->addImportPath( CalamaresUtils::qmlModulesDir().absolutePath() ); + + // TODO: search for suitable file + QString qrcName = QStringLiteral( ":/%1.qml" ).arg( m_name ); + m_qmlFileName = qrcName; + + cDebug() << "QmlViewStep loading" << m_qmlFileName; + m_qmlComponent = new QQmlComponent( + m_qmlWidget->engine(), QUrl( m_qmlFileName ), QQmlComponent::CompilationMode::Asynchronous ); + connect( m_qmlComponent, &QQmlComponent::statusChanged, this, &QmlViewStep::loadComplete ); + cDebug() << Logger::SubEntry << "Status" << m_qmlComponent->status(); } QmlViewStep::~QmlViewStep() {} @@ -94,3 +115,53 @@ Calamares::QmlViewStep::widget() { return m_widget; } + +void +Calamares::QmlViewStep::loadComplete() +{ + cDebug() << "QML component" << m_qmlFileName << m_qmlComponent->status(); + if ( m_qmlComponent->isReady() && !m_qmlObject ) + { + cDebug() << "QML component complete" << m_qmlFileName; + // Don't do this again + disconnect( m_qmlComponent, &QQmlComponent::statusChanged, this, &QmlViewStep::loadComplete ); + + QObject* o = m_qmlComponent->create(); + m_qmlObject = qobject_cast< QQuickItem* >( o ); + if ( !m_qmlObject ) + { + cError() << Logger::SubEntry << "Could not create QML from" << m_qmlFileName; + delete o; + } + else + { + // setContent() is public API, but not documented publicly. + // It is marked \internal in the Qt sources, but does exactly + // what is needed: sets up visual parent by replacing the root + // item, and handling resizes. + m_qmlWidget->setContent( QUrl( m_qmlFileName ), m_qmlComponent, m_qmlObject ); + showQml(); + } + } +} + +void +Calamares::QmlViewStep::showQml() +{ + if ( !m_qmlWidget || !m_qmlObject ) + { + cDebug() << "showQml() called but no QML object"; + return; + } + if ( m_spinner ) + { + m_widget->layout()->removeWidget( m_spinner ); + m_widget->layout()->addWidget( m_qmlWidget ); + delete m_spinner; + m_spinner = nullptr; + } + else + { + cDebug() << "showQml() called twice"; + } +} diff --git a/src/libcalamaresui/viewpages/QmlViewStep.h b/src/libcalamaresui/viewpages/QmlViewStep.h index d1b28af35..0503f5cde 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.h +++ b/src/libcalamaresui/viewpages/QmlViewStep.h @@ -58,12 +58,19 @@ public: virtual JobList jobs() const override; +private Q_SLOTS: + void loadComplete(); + private: + /// @brief Swap out the spinner for the QQuickWidget + void showQml(); + QString m_name; + QString m_qmlFileName; QWidget* m_widget = nullptr; WaitingWidget* m_spinner = nullptr; - QQuickWidget* m_qmlShow = nullptr; + QQuickWidget* m_qmlWidget = nullptr; QQmlComponent* m_qmlComponent = nullptr; QQuickItem* m_qmlObject = nullptr; }; From e6713d456cfe71dbf27f81010903080a30f6bfb2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 Jan 2020 13:44:26 +0100 Subject: [PATCH 019/119] [libcalamaresui] Need explicit qrc: scheme --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index 3cfcc7371..4cee7c281 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -47,7 +47,7 @@ QmlViewStep::QmlViewStep( const QString& name, QObject* parent ) m_qmlWidget->engine()->addImportPath( CalamaresUtils::qmlModulesDir().absolutePath() ); // TODO: search for suitable file - QString qrcName = QStringLiteral( ":/%1.qml" ).arg( m_name ); + QString qrcName = QStringLiteral( "qrc:/%1.qml" ).arg( m_name ); m_qmlFileName = qrcName; cDebug() << "QmlViewStep loading" << m_qmlFileName; From e7e66497d2e583d8fb082d726af70a225ee12a9e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 Jan 2020 17:19:15 +0100 Subject: [PATCH 020/119] [libcalamaresui] Introduce search method for QML UI modules - add a sample config and documentation in dummyqml/ --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 25 ++++++++++++++++++++ src/libcalamaresui/viewpages/QmlViewStep.h | 21 ++++++++++++++++ src/modules/dummyqml/dummyqml.conf | 19 +++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 src/modules/dummyqml/dummyqml.conf diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index 4cee7c281..cf19fb2b4 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -20,6 +20,8 @@ #include "utils/Dirs.h" #include "utils/Logger.h" +#include "utils/NamedEnum.h" +#include "utils/Variant.h" #include "widgets/WaitingWidget.h" #include @@ -29,6 +31,19 @@ #include #include +static const NamedEnumTable< Calamares::QmlViewStep::QmlSearch >& +searchNames() +{ + using QmlSearch = Calamares::QmlViewStep::QmlSearch; + static NamedEnumTable< Calamares::QmlViewStep::QmlSearch > names{ + { QStringLiteral( "both" ), QmlSearch::Both }, + { QStringLiteral( "qrc" ), QmlSearch::QrcOnly }, + { QStringLiteral( "branding" ), QmlSearch::BrandingOnly } + }; + + return names; +} + namespace Calamares { @@ -165,3 +180,13 @@ Calamares::QmlViewStep::showQml() cDebug() << "showQml() called twice"; } } + +void Calamares::QmlViewStep::setConfigurationMap(const QVariantMap& configurationMap) +{ + bool ok = false; + m_searchMethod = searchNames().find( CalamaresUtils::getString( configurationMap, "search" ), ok ); + if (!ok) + { + cDebug() << "Bad QML search mode."; + } +} diff --git a/src/libcalamaresui/viewpages/QmlViewStep.h b/src/libcalamaresui/viewpages/QmlViewStep.h index 0503f5cde..38405a6a6 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.h +++ b/src/libcalamaresui/viewpages/QmlViewStep.h @@ -40,6 +40,20 @@ class QmlViewStep : public Calamares::ViewStep Q_OBJECT public: + enum class QmlSearch + { + QrcOnly, + BrandingOnly, + Both + }; + + /** @brief Creates a QML view step + * + * The name should not have an extension or schema or anything; + * just the plain name, which will be searched as "/.qml" in + * QRC files, or ".qml" in suitable branding paths. + * The search behavior depends on a QmlSearch value. + */ QmlViewStep( const QString& name, QObject* parent = nullptr ); virtual ~QmlViewStep() override; @@ -56,8 +70,12 @@ public: virtual void onActivate() override; virtual void onLeave() override; + /// @brief QML widgets don't produce jobs by default virtual JobList jobs() const override; + /// @brief Configure search paths; subclasses should call this as well + virtual void setConfigurationMap( const QVariantMap& configurationMap ) override; + private Q_SLOTS: void loadComplete(); @@ -65,6 +83,9 @@ private: /// @brief Swap out the spinner for the QQuickWidget void showQml(); + /// @brief Controls where m_name is searched + QmlSearch m_searchMethod; + QString m_name; QString m_qmlFileName; diff --git a/src/modules/dummyqml/dummyqml.conf b/src/modules/dummyqml/dummyqml.conf new file mode 100644 index 000000000..a861b68bd --- /dev/null +++ b/src/modules/dummyqml/dummyqml.conf @@ -0,0 +1,19 @@ +# The dummy QML module just displays a QML page. It doesn't +# have much in the way of own configuration, only where +# the QML file is searched. +# +# QML modules can search for the QML inside the Qt resources +# (QRC) which are compiled into the module, or in the branding +# setup for Calamares, (or both of them, with branding taking +# precedence). This allows the module to ship a default UI and +# branding to optionally introduce a replacement file. +# +# Generally, leave the search method set to "both" because if +# you don't want to brand the UI, just don't ship a branding +# QML file for it. +# +# To support instanced QML modules, searches in the branding +# directory look for the full module@instanceid name as well. +--- +search: both + From fed298b17963594afd601193c635e6e875d5bb71 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 Jan 2020 17:41:20 +0100 Subject: [PATCH 021/119] [libcalamaresui] Defer QML loading - need a configuration before we can start loading (to support the variable search paths) - refactor showing a failure in the spinner widget. On failure, the spinner will never go away, so a message for the user is good. - stop clang-format from messing up the table of names. --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 60 ++++++++++++++------ src/libcalamaresui/viewpages/QmlViewStep.h | 2 + 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index cf19fb2b4..779a624c1 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -34,12 +34,16 @@ static const NamedEnumTable< Calamares::QmlViewStep::QmlSearch >& searchNames() { - using QmlSearch = Calamares::QmlViewStep::QmlSearch; - static NamedEnumTable< Calamares::QmlViewStep::QmlSearch > names{ - { QStringLiteral( "both" ), QmlSearch::Both }, - { QStringLiteral( "qrc" ), QmlSearch::QrcOnly }, - { QStringLiteral( "branding" ), QmlSearch::BrandingOnly } + using Search = Calamares::QmlViewStep::QmlSearch; + // *INDENT-OFF* + // clang-format off + static NamedEnumTable< Search > names { + { QStringLiteral( "both" ), Search::Both }, + { QStringLiteral( "qrc" ), Search::QrcOnly }, + { QStringLiteral( "branding" ), Search::BrandingOnly } }; + // *INDENT-ON* + // clang-format on return names; } @@ -61,15 +65,7 @@ QmlViewStep::QmlViewStep( const QString& name, QObject* parent ) m_qmlWidget->setResizeMode( QQuickWidget::SizeRootObjectToView ); m_qmlWidget->engine()->addImportPath( CalamaresUtils::qmlModulesDir().absolutePath() ); - // TODO: search for suitable file - QString qrcName = QStringLiteral( "qrc:/%1.qml" ).arg( m_name ); - m_qmlFileName = qrcName; - - cDebug() << "QmlViewStep loading" << m_qmlFileName; - m_qmlComponent = new QQmlComponent( - m_qmlWidget->engine(), QUrl( m_qmlFileName ), QQmlComponent::CompilationMode::Asynchronous ); - connect( m_qmlComponent, &QQmlComponent::statusChanged, this, &QmlViewStep::loadComplete ); - cDebug() << Logger::SubEntry << "Status" << m_qmlComponent->status(); + // QML Loading starts when the configuration for the module is set. } QmlViewStep::~QmlViewStep() {} @@ -135,6 +131,10 @@ void Calamares::QmlViewStep::loadComplete() { cDebug() << "QML component" << m_qmlFileName << m_qmlComponent->status(); + if ( m_qmlComponent->status() == QQmlComponent::Error ) + { + showFailedQml(); + } if ( m_qmlComponent->isReady() && !m_qmlObject ) { cDebug() << "QML component complete" << m_qmlFileName; @@ -181,12 +181,40 @@ Calamares::QmlViewStep::showQml() } } -void Calamares::QmlViewStep::setConfigurationMap(const QVariantMap& configurationMap) +void +Calamares::QmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { bool ok = false; m_searchMethod = searchNames().find( CalamaresUtils::getString( configurationMap, "search" ), ok ); - if (!ok) + if ( !ok ) { cDebug() << "Bad QML search mode."; } + + if ( !m_qmlComponent ) + { + // TODO: search for suitable file + QString qrcName = QStringLiteral( "qrc:/X%1.qml" ).arg( m_name ); + m_qmlFileName = qrcName; + + cDebug() << "QmlViewStep" << moduleInstanceKey() << "loading" << m_qmlFileName; + m_qmlComponent = new QQmlComponent( + m_qmlWidget->engine(), QUrl( m_qmlFileName ), QQmlComponent::CompilationMode::Asynchronous ); + connect( m_qmlComponent, &QQmlComponent::statusChanged, this, &QmlViewStep::loadComplete ); + if ( m_qmlComponent->status() == QQmlComponent::Error ) + { + showFailedQml(); + } + } + else + { + cWarning() << "QML configuration set after component has loaded."; + } +} + +void +Calamares::QmlViewStep::showFailedQml() +{ + cWarning() << "QmlViewStep" << moduleInstanceKey() << "loading failed."; + m_spinner->setText( prettyName() + tr( "Loading failed." ) ); } diff --git a/src/libcalamaresui/viewpages/QmlViewStep.h b/src/libcalamaresui/viewpages/QmlViewStep.h index 38405a6a6..46ba29a53 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.h +++ b/src/libcalamaresui/viewpages/QmlViewStep.h @@ -82,6 +82,8 @@ private Q_SLOTS: private: /// @brief Swap out the spinner for the QQuickWidget void showQml(); + /// @brief Show error message in spinner. + void showFailedQml(); /// @brief Controls where m_name is searched QmlSearch m_searchMethod; From ce6d54ad9581bbb07b6818e0fb409fc57e6404fd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 Jan 2020 17:45:09 +0100 Subject: [PATCH 022/119] [libcalamaresui] Improve failure message, unbreak loading - example loading had an X inserted in filename (to test failure) - add a space between name and failure --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index 779a624c1..569eb6cd9 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -194,7 +194,7 @@ Calamares::QmlViewStep::setConfigurationMap( const QVariantMap& configurationMap if ( !m_qmlComponent ) { // TODO: search for suitable file - QString qrcName = QStringLiteral( "qrc:/X%1.qml" ).arg( m_name ); + QString qrcName = QStringLiteral( "qrc:/%1.qml" ).arg( m_name ); m_qmlFileName = qrcName; cDebug() << "QmlViewStep" << moduleInstanceKey() << "loading" << m_qmlFileName; @@ -216,5 +216,5 @@ void Calamares::QmlViewStep::showFailedQml() { cWarning() << "QmlViewStep" << moduleInstanceKey() << "loading failed."; - m_spinner->setText( prettyName() + tr( "Loading failed." ) ); + m_spinner->setText( prettyName() + ' ' + tr( "Loading failed." ) ); } From 04615b251c652e765503f11d0b9c9f813f9588ef Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 Jan 2020 17:47:02 +0100 Subject: [PATCH 023/119] [dummyqml] Make prettyName() return a sentence with . --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 2 +- src/modules/dummyqml/DummyQmlViewStep.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index 569eb6cd9..e26b02430 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -74,7 +74,7 @@ QString QmlViewStep::prettyName() const { // TODO: query the QML itself - return tr( "QML Step %1" ).arg( m_name ); + return tr( "QML Step %1." ).arg( m_name ); } diff --git a/src/modules/dummyqml/DummyQmlViewStep.cpp b/src/modules/dummyqml/DummyQmlViewStep.cpp index 985d2985a..32c1c60d0 100644 --- a/src/modules/dummyqml/DummyQmlViewStep.cpp +++ b/src/modules/dummyqml/DummyQmlViewStep.cpp @@ -28,7 +28,7 @@ DummyQmlViewStep::~DummyQmlViewStep() {} QString DummyQmlViewStep::prettyName() const { - return tr( "Example QML page" ); + return tr( "Example QML page." ); } From 7f8a31007a8e07dcd0e430b9f7443777a9b8bc9a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 13 Jan 2020 22:04:27 +0100 Subject: [PATCH 024/119] [dummyqml] Search for files - start implementation of searching-for-qml - add a *filename* configuration item, so that the filename can be set per-instance (via the config file) --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 45 ++++++++++++++++++-- src/modules/dummyqml/dummyqml.conf | 3 ++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index e26b02430..8fcc75a9b 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -181,6 +181,40 @@ Calamares::QmlViewStep::showQml() } } + +/** @brief Find a suitable QML file, given the search method and name hints + * + * Returns QString() if nothing is found (which would mean the module + * is badly configured). + */ +QString +searchQmlFile( Calamares::QmlViewStep::QmlSearch method, const QString& configuredName, const QString& moduleName ) +{ + cDebug() << "Looking for QML for" << moduleName; + for ( const QString& candidate : + QStringList { configuredName.isEmpty() ? QString() : QStringLiteral( ":/%1.qml" ).arg( configuredName ), + moduleName.isEmpty() ? QString() : QStringLiteral( ":/%1.qml" ).arg( moduleName ) } ) + { + if ( candidate.isEmpty() ) + { + continue; + } + cDebug() << Logger::SubEntry << "Looking at QML file" << candidate; + if ( QFile::exists( candidate ) ) + { + if ( candidate.startsWith( ':' ) ) + { + // Inconsistency: QFile only sees the file with :, + // but QML needs an explicit scheme (of qrc:) + return QStringLiteral( "qrc" ) + candidate; + } + return candidate; + } + } + cDebug() << Logger::SubEntry << "None found."; + return QString(); +} + void Calamares::QmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { @@ -191,11 +225,14 @@ Calamares::QmlViewStep::setConfigurationMap( const QVariantMap& configurationMap cDebug() << "Bad QML search mode."; } - if ( !m_qmlComponent ) + QString qmlFile = CalamaresUtils::getString( configurationMap, "filename" ); + if ( qmlFile.isEmpty() ) { - // TODO: search for suitable file - QString qrcName = QStringLiteral( "qrc:/%1.qml" ).arg( m_name ); - m_qmlFileName = qrcName; + cWarning() << "No QML file for module" << m_name; + } + else if ( !m_qmlComponent ) + { + m_qmlFileName = searchQmlFile( m_searchMethod, qmlFile, m_name ); cDebug() << "QmlViewStep" << moduleInstanceKey() << "loading" << m_qmlFileName; m_qmlComponent = new QQmlComponent( diff --git a/src/modules/dummyqml/dummyqml.conf b/src/modules/dummyqml/dummyqml.conf index a861b68bd..e62d35383 100644 --- a/src/modules/dummyqml/dummyqml.conf +++ b/src/modules/dummyqml/dummyqml.conf @@ -15,5 +15,8 @@ # To support instanced QML modules, searches in the branding # directory look for the full module@instanceid name as well. --- +# Search mode. Valid values are "both", "qrc" and "branding" search: both +# Name of the QML file. If not set, uses the name of the module. +filename: dummyqml From 750465153f4d6a329b97b2ed9786423b618411d9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 13 Jan 2020 22:28:21 +0100 Subject: [PATCH 025/119] [dummyqml] Improve QML searching - if the filename is an absolute path, use that - support searching in branding directory --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 25 +++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index 8fcc75a9b..44edba97d 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -18,6 +18,8 @@ #include "QmlViewStep.h" +#include "Branding.h" + #include "utils/Dirs.h" #include "utils/Logger.h" #include "utils/NamedEnum.h" @@ -190,10 +192,27 @@ Calamares::QmlViewStep::showQml() QString searchQmlFile( Calamares::QmlViewStep::QmlSearch method, const QString& configuredName, const QString& moduleName ) { + using QmlSearch = Calamares::QmlViewStep::QmlSearch; + cDebug() << "Looking for QML for" << moduleName; - for ( const QString& candidate : - QStringList { configuredName.isEmpty() ? QString() : QStringLiteral( ":/%1.qml" ).arg( configuredName ), - moduleName.isEmpty() ? QString() : QStringLiteral( ":/%1.qml" ).arg( moduleName ) } ) + QStringList candidates; + if ( configuredName.startsWith( '/' ) ) + { + candidates << configuredName; + } + if ( ( method == QmlSearch::Both ) || ( method == QmlSearch::BrandingOnly ) ) + { + QString brandDir = Calamares::Branding::instance()->componentDirectory(); + candidates << ( configuredName.isEmpty() ? QString() + : QStringLiteral( "%1/%2.qml" ).arg( brandDir, configuredName ) ) + << ( moduleName.isEmpty() ? QString() : QStringLiteral( "%1/%2.qml" ).arg( brandDir, moduleName ) ); + } + if ( ( method == QmlSearch::Both ) || ( method == QmlSearch::QrcOnly ) ) + { + candidates << ( configuredName.isEmpty() ? QString() : QStringLiteral( ":/%1.qml" ).arg( configuredName ) ) + << ( moduleName.isEmpty() ? QString() : QStringLiteral( ":/%1.qml" ).arg( moduleName ) ); + } + for ( const QString& candidate : candidates ) { if ( candidate.isEmpty() ) { From f2e68ddcf4dc62c38d0ffcdbbb504b7dae13cd11 Mon Sep 17 00:00:00 2001 From: demmm Date: Tue, 14 Jan 2020 12:30:22 +0100 Subject: [PATCH 026/119] adding configure option dummyqml sidebar entry can be configured and translated adding a more elaborate qml example keeping this in dummyqml for now, another commit will follow with continuation of dummyqml in a more aptly named module --- src/modules/dummyqml/DummyQmlViewStep.cpp | 20 +++++- src/modules/dummyqml/DummyQmlViewStep.h | 12 +++- src/modules/dummyqml/dummyqml.conf | 7 +++ src/modules/dummyqml/dummyqml.qml | 77 ++++++++++++++++++++--- 4 files changed, 105 insertions(+), 11 deletions(-) diff --git a/src/modules/dummyqml/DummyQmlViewStep.cpp b/src/modules/dummyqml/DummyQmlViewStep.cpp index 32c1c60d0..6bf0b4a60 100644 --- a/src/modules/dummyqml/DummyQmlViewStep.cpp +++ b/src/modules/dummyqml/DummyQmlViewStep.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2020, Adriaan de Groot + * Copyright 2020, Anke Boersma * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,6 +19,8 @@ #include "DummyQmlViewStep.h" +#include + DummyQmlViewStep::DummyQmlViewStep( QObject* parent ) : Calamares::QmlViewStep( "dummyqml", parent ) { @@ -28,8 +31,23 @@ DummyQmlViewStep::~DummyQmlViewStep() {} QString DummyQmlViewStep::prettyName() const { - return tr( "Example QML page." ); + return m_notesName ? m_notesName->get() : tr( "Notes" ); } +void +DummyQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) +{ + Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation + + bool qmlLabel_ok = false; + auto qmlLabel = CalamaresUtils::getSubMap( configurationMap, "qmlLabel", qmlLabel_ok ); + if ( qmlLabel_ok ) + { + if ( qmlLabel.contains( "notes" ) ) + { + m_notesName = new CalamaresUtils::Locale::TranslatedString( qmlLabel, "notes" ); + } + } +} CALAMARES_PLUGIN_FACTORY_DEFINITION( DummyQmlViewStepFactory, registerPlugin< DummyQmlViewStep >(); ) diff --git a/src/modules/dummyqml/DummyQmlViewStep.h b/src/modules/dummyqml/DummyQmlViewStep.h index ffc358fe7..6eb0d768e 100644 --- a/src/modules/dummyqml/DummyQmlViewStep.h +++ b/src/modules/dummyqml/DummyQmlViewStep.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2020, Adriaan de Groot + * Copyright 2020, Anke Boersma * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,10 +20,14 @@ #ifndef DUMMYQMLVIEWSTEP_H #define DUMMYQMLVIEWSTEP_H +#include +#include "locale/TranslatableConfiguration.h" +#include "utils/CalamaresUtilsSystem.h" +#include "utils/Variant.h" #include "utils/PluginFactory.h" #include "viewpages/QmlViewStep.h" -class DummyQmlViewStep : public Calamares::QmlViewStep +class PLUGINDLLEXPORT DummyQmlViewStep : public Calamares::QmlViewStep { Q_OBJECT @@ -30,9 +35,12 @@ public: DummyQmlViewStep( QObject* parent = nullptr ); virtual ~DummyQmlViewStep() override; - virtual QString prettyName() const override; + QString prettyName() const override; + + void setConfigurationMap( const QVariantMap& configurationMap ) override; private: + CalamaresUtils::Locale::TranslatedString* m_notesName; // As it appears in the sidebar }; CALAMARES_PLUGIN_FACTORY_DECLARATION( DummyQmlViewStepFactory ) diff --git a/src/modules/dummyqml/dummyqml.conf b/src/modules/dummyqml/dummyqml.conf index e62d35383..c3581911f 100644 --- a/src/modules/dummyqml/dummyqml.conf +++ b/src/modules/dummyqml/dummyqml.conf @@ -20,3 +20,10 @@ search: both # Name of the QML file. If not set, uses the name of the module. filename: dummyqml + +# Name of the QML file. If not set, uses the name of the module. +filename: notes + +qmlLabel: + notes: "Release Notes" + notes[nl]: "Opmerkingen" diff --git a/src/modules/dummyqml/dummyqml.qml b/src/modules/dummyqml/dummyqml.qml index 6cab24bec..3cbfa65fc 100644 --- a/src/modules/dummyqml/dummyqml.qml +++ b/src/modules/dummyqml/dummyqml.qml @@ -1,12 +1,73 @@ -import QtQuick 2.3 +/* === This file is part of Calamares - === + * + * Copyright 2020, Anke Boersma + * + * 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 . + */ -Rectangle { - width: 200 - height: 100 - color: "red" +import QtQuick 2.7 +import QtQuick.Controls 2.2 +import QtQuick.Window 2.2 +import QtQuick.Layouts 1.3 +import QtQuick.Controls.Material 2.1 - Text { - anchors.centerIn: parent - text: "Hello, World!" +Item { + width: 740 + height: 420 + + Flickable { + id: flick + anchors.fill: parent + contentHeight: 800 + + ScrollBar.vertical: ScrollBar { + width: 10 + policy: ScrollBar.AlwaysOn + } + + TextArea { + id: intro + x: 1 + y: 0 + width: 720 + font.pointSize: 14 + textFormat: Text.RichText + antialiasing: true + activeFocusOnPress: false + wrapMode: Text.WordWrap + + text: qsTr("

Generic GNU/Linux 2017.8 LTS Soapy Sousaphone

+

This an example QML file, showing options in RichText with Flickable content.

+ +

QML with RichText can use HTML tags, Flickable content is useful for touchscreens.

+ +

This is bold text

+

This is italic text

+

This is underlined text

+

This is strikethrough

+ +

Code example: + ls -l /home

+ +

Lists:

+
    +
  • Intel CPU systems
  • +
  • AMD CPU systems
  • +
+ +

The vertical scrollbar is adjustable, current width set to 10.

") + + } } } From 32eee827440da46ef8b644a607b19a6760bbd8c8 Mon Sep 17 00:00:00 2001 From: demmm Date: Tue, 14 Jan 2020 13:08:54 +0100 Subject: [PATCH 027/119] clean-up dummyqml.conf --- src/modules/dummyqml/dummyqml.conf | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/modules/dummyqml/dummyqml.conf b/src/modules/dummyqml/dummyqml.conf index c3581911f..48bbbc150 100644 --- a/src/modules/dummyqml/dummyqml.conf +++ b/src/modules/dummyqml/dummyqml.conf @@ -21,9 +21,6 @@ search: both # Name of the QML file. If not set, uses the name of the module. filename: dummyqml -# Name of the QML file. If not set, uses the name of the module. -filename: notes - qmlLabel: notes: "Release Notes" notes[nl]: "Opmerkingen" From 9f55cf4cf4d313cc87134e1561e78c3be14c109e Mon Sep 17 00:00:00 2001 From: demmm Date: Fri, 24 Jan 2020 15:12:10 +0100 Subject: [PATCH 028/119] part of the changes requested others fail to build, or no idea how to fix --- src/modules/dummyqml/DummyQmlViewStep.cpp | 3 +++ src/modules/dummyqml/DummyQmlViewStep.h | 4 +--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/dummyqml/DummyQmlViewStep.cpp b/src/modules/dummyqml/DummyQmlViewStep.cpp index 6bf0b4a60..39c95e993 100644 --- a/src/modules/dummyqml/DummyQmlViewStep.cpp +++ b/src/modules/dummyqml/DummyQmlViewStep.cpp @@ -19,6 +19,9 @@ #include "DummyQmlViewStep.h" +#include "utils/PluginFactory.h" +#include "viewpages/QmlViewStep.h" + #include DummyQmlViewStep::DummyQmlViewStep( QObject* parent ) diff --git a/src/modules/dummyqml/DummyQmlViewStep.h b/src/modules/dummyqml/DummyQmlViewStep.h index 6eb0d768e..adcd294fa 100644 --- a/src/modules/dummyqml/DummyQmlViewStep.h +++ b/src/modules/dummyqml/DummyQmlViewStep.h @@ -20,12 +20,10 @@ #ifndef DUMMYQMLVIEWSTEP_H #define DUMMYQMLVIEWSTEP_H -#include +#include "PluginDllMacro.h" #include "locale/TranslatableConfiguration.h" #include "utils/CalamaresUtilsSystem.h" #include "utils/Variant.h" -#include "utils/PluginFactory.h" -#include "viewpages/QmlViewStep.h" class PLUGINDLLEXPORT DummyQmlViewStep : public Calamares::QmlViewStep { From 538d8d5497f8f77ed8644244717b44c2d02b8e0a Mon Sep 17 00:00:00 2001 From: demmm Date: Fri, 24 Jan 2020 15:14:51 +0100 Subject: [PATCH 029/119] address qmlLabel changes too --- src/modules/dummyqml/DummyQmlViewStep.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/modules/dummyqml/DummyQmlViewStep.cpp b/src/modules/dummyqml/DummyQmlViewStep.cpp index 39c95e993..030779f7f 100644 --- a/src/modules/dummyqml/DummyQmlViewStep.cpp +++ b/src/modules/dummyqml/DummyQmlViewStep.cpp @@ -19,9 +19,6 @@ #include "DummyQmlViewStep.h" -#include "utils/PluginFactory.h" -#include "viewpages/QmlViewStep.h" - #include DummyQmlViewStep::DummyQmlViewStep( QObject* parent ) @@ -44,13 +41,12 @@ DummyQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) bool qmlLabel_ok = false; auto qmlLabel = CalamaresUtils::getSubMap( configurationMap, "qmlLabel", qmlLabel_ok ); - if ( qmlLabel_ok ) + + if ( qmlLabel.contains( "notes" ) ) { - if ( qmlLabel.contains( "notes" ) ) - { - m_notesName = new CalamaresUtils::Locale::TranslatedString( qmlLabel, "notes" ); - } + m_notesName = new CalamaresUtils::Locale::TranslatedString( qmlLabel, "notes" ); } + } CALAMARES_PLUGIN_FACTORY_DEFINITION( DummyQmlViewStepFactory, registerPlugin< DummyQmlViewStep >(); ) From b20a957c6ef9a22d4e9e8e158a4c1678d87a26b3 Mon Sep 17 00:00:00 2001 From: demmm Date: Fri, 24 Jan 2020 15:52:59 +0100 Subject: [PATCH 030/119] restore includes in header file to amke it build --- src/modules/dummyqml/DummyQmlViewStep.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/dummyqml/DummyQmlViewStep.h b/src/modules/dummyqml/DummyQmlViewStep.h index adcd294fa..cf49436b0 100644 --- a/src/modules/dummyqml/DummyQmlViewStep.h +++ b/src/modules/dummyqml/DummyQmlViewStep.h @@ -24,6 +24,8 @@ #include "locale/TranslatableConfiguration.h" #include "utils/CalamaresUtilsSystem.h" #include "utils/Variant.h" +#include "utils/PluginFactory.h" +#include "viewpages/QmlViewStep.h" class PLUGINDLLEXPORT DummyQmlViewStep : public Calamares::QmlViewStep { From abdeb07bd332c454a8937685552a3de34183f23c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 24 Jan 2020 17:14:45 +0100 Subject: [PATCH 031/119] [dummyqml] Minor polishing in Qml module - document the default filename better - mark TODO actually loading the instance-id file --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 5 +++-- src/modules/dummyqml/dummyqml.conf | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index 44edba97d..b009d1626 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -247,9 +247,10 @@ Calamares::QmlViewStep::setConfigurationMap( const QVariantMap& configurationMap QString qmlFile = CalamaresUtils::getString( configurationMap, "filename" ); if ( qmlFile.isEmpty() ) { - cWarning() << "No QML file for module" << m_name; + // TODO use the module instance } - else if ( !m_qmlComponent ) + + if ( !m_qmlComponent ) { m_qmlFileName = searchQmlFile( m_searchMethod, qmlFile, m_name ); diff --git a/src/modules/dummyqml/dummyqml.conf b/src/modules/dummyqml/dummyqml.conf index 48bbbc150..9e7a83fdd 100644 --- a/src/modules/dummyqml/dummyqml.conf +++ b/src/modules/dummyqml/dummyqml.conf @@ -18,9 +18,12 @@ # Search mode. Valid values are "both", "qrc" and "branding" search: both -# Name of the QML file. If not set, uses the name of the module. -filename: dummyqml +# Name of the QML file. If not set, uses the name of the instance +# of the module (e.g. if you list this module in `settings.conf` +# in the *instances* section, you get *id*, otherwise it would +# normally be "dummyqml"). +# filename: dummyqml -qmlLabel: +qmlLabel: notes: "Release Notes" notes[nl]: "Opmerkingen" From 91625c8ba8cf68228f785a45479e02ea1db3a3a1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Feb 2020 13:35:26 +0100 Subject: [PATCH 032/119] [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 033/119] [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 034/119] [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 035/119] [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 036/119] [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 037/119] [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 038/119] [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 039/119] [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 040/119] [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 041/119] [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 From 53b6113c7509572ceef98009aa7a477ff96bc456 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 5 Feb 2020 18:38:46 +0100 Subject: [PATCH 042/119] [welcome] Fix QML tests --- src/modules/welcome/qmlmain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/welcome/qmlmain.cpp b/src/modules/welcome/qmlmain.cpp index 96d9d245f..a9dd1875d 100644 --- a/src/modules/welcome/qmlmain.cpp +++ b/src/modules/welcome/qmlmain.cpp @@ -49,7 +49,7 @@ int main(int argc, char **argv) Logger::setupLogLevel( Logger::LOGVERBOSE ); - 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 ) ); Calamares::Branding defaultBrand( "src/branding/default/branding.desc" ); From b8505dc6215770ae7b09584e2d8e7a7101f32c6f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 6 Feb 2020 12:45:40 +0100 Subject: [PATCH 043/119] CI: tidy up txcheck.sh - Add license header with SPDX info - Add usage header - Support --help - Document internals a little more --- ci/txcheck.sh | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/ci/txcheck.sh b/ci/txcheck.sh index a2130c9d5..61fdd7030 100644 --- a/ci/txcheck.sh +++ b/ci/txcheck.sh @@ -1,5 +1,18 @@ #! /bin/sh +### LICENSE +# === This file is part of Calamares - === +# +# This file is Free Software: you can redistribute it and/or modify +# it under the terms of the 2-clause BSD License. +# https://spdx.org/licenses/BSD-2-Clause.html +# +# SPDX-License-Identifier: BSD-2-Clause +# SPDX-FileCopyrightText: 2019-2020 Adriaan de Groot +### END LICENSE + +### USAGE +# # Does the translation tag (from a previous txpush) exist? # This assumes that the release host has also locally done # a translations push, which works for the current development @@ -7,6 +20,13 @@ # the typical txpush log messages instead of the tag. # # Use --cleanup as an argument to clean things up. +# +# Normal use: +# $ sh ci/txcheck.sh +# If there are differences, fix them and then clean up: +# $ sh ci/txcheck.sh --cleanup +# +### END USAGE # The files that are translated; should match the contents of .tx/config TX_FILE_LIST="lang/calamares_en.ts lang/python.pot src/modules/dummypythonqt/lang/dummypythonqt.pot calamares.desktop" @@ -27,6 +47,9 @@ if test "x$1" = "x--cleanup" ; then tx_cleanup exit 0 fi +if test "x$1" = "x--help" ; then + sed -e '1,/USAGE/d' -e '/END.USAGE/,$d' < "$0" +fi test -z "$1" || { echo "! Usage: txcheck.sh [--cleanup]" ; exit 1 ; } @@ -67,6 +90,8 @@ fi if test `git describe` = `git describe --dirty` ; then : else + # Don't want any local changes, since those won't be + # reflected in the worktrees and we might miss a string change. echo "! There are local changes." exit 1 fi @@ -75,13 +100,20 @@ DATE_PREV=$( git log -1 translation --date=unix | sed -e '/^Date:/s+.*:++p' -e d DATE_HEAD=$( last_week ) test "$DATE_PREV" -le "$DATE_HEAD" || { echo "! Translation tag has not aged enough." ; git log -1 translation ; exit 1 ; } -# Tag is good, do real work of checking strings: collect names of relevant files +# Tag is good, check that necessary files exist. The list of +# files is hard-coded, but should match what is in the Transifex config. test -f ".tx/config" || { echo "! No Transifex configuration is present." ; exit 1 ; } for f in $TX_FILE_LIST ; do test -f $f || { echo "! Translation file '$f' does not exist." ; exit 1 ; } done -# The state of translations +### COMPARE TRANSLATIONS +# +# + +# The state of translations; assume that sha256 is enough +# to distinguish changed translations when we cat all the +# string sources together. tx_sum() { CURDIR=`pwd` From 44489d3d7b01efdbf97f1d93fb76799c92c36162 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 6 Feb 2020 12:51:06 +0100 Subject: [PATCH 044/119] CI: tidy up license header in txcheck.sh --- ci/txcheck.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/txcheck.sh b/ci/txcheck.sh index 61fdd7030..8eef04571 100644 --- a/ci/txcheck.sh +++ b/ci/txcheck.sh @@ -3,12 +3,12 @@ ### LICENSE # === This file is part of Calamares - === # -# This file is Free Software: you can redistribute it and/or modify -# it under the terms of the 2-clause BSD License. -# https://spdx.org/licenses/BSD-2-Clause.html -# # SPDX-License-Identifier: BSD-2-Clause # SPDX-FileCopyrightText: 2019-2020 Adriaan de Groot +# +# This file is Free Software: you can redistribute it and/or modify +# it under the terms of the 2-clause BSD License. +# ### END LICENSE ### USAGE From 0d2425ca78a4e733c21066c4a5b79290dbc28144 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 6 Feb 2020 13:01:55 +0100 Subject: [PATCH 045/119] CI: make shell-scripts tab-indented by default --- .editorconfig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.editorconfig b/.editorconfig index b2ae0dd2b..d282d6273 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,8 @@ trim_trailing_whitespace = true indent_style = space indent_size = 4 insert_final_newline = true + +[*.sh] +indent_style = tab +insert_final_newline = true + From dec30d70fd971b8e7a5d58a72757a82d1c88b24a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 6 Feb 2020 13:11:23 +0100 Subject: [PATCH 046/119] CI: tidy up scripts - Add SPDX headers - Indent consistently (tabs, not a mix of 2-space, 4-space, and tabs) The scripts were originally added without a license header. Since they are simple, and re-usable, and not particularly interesting, I've made the license explicitly 2-clause BSD. This is unlike the rest of Calamares, which is GPLv3+; the build system and support scripts are not the software itself. --- ci/txcheck.sh | 26 ++++++------- ci/txpull.sh | 64 ++++++++++++++++++------------ ci/txpush.sh | 106 ++++++++++++++++++++++++++++++-------------------- 3 files changed, 116 insertions(+), 80 deletions(-) diff --git a/ci/txcheck.sh b/ci/txcheck.sh index 8eef04571..9ce8f0c30 100644 --- a/ci/txcheck.sh +++ b/ci/txcheck.sh @@ -37,18 +37,18 @@ TX_FILE_LIST="lang/calamares_en.ts lang/python.pot src/modules/dummypythonqt/lan # normally used much later in the script. tx_cleanup() { - # Cleanup artifacs of checking - git worktree remove --force build-txcheck-head - git worktree remove --force build-txcheck-prev - git branch -D build-txcheck-head > /dev/null 2>&1 + # Cleanup artifacs of checking + git worktree remove --force build-txcheck-head + git worktree remove --force build-txcheck-prev + git branch -D build-txcheck-head > /dev/null 2>&1 } if test "x$1" = "x--cleanup" ; then - tx_cleanup - exit 0 + tx_cleanup + exit 0 fi if test "x$1" = "x--help" ; then - sed -e '1,/USAGE/d' -e '/END.USAGE/,$d' < "$0" + sed -e '1,/USAGE/d' -e '/END.USAGE/,$d' < "$0" fi test -z "$1" || { echo "! Usage: txcheck.sh [--cleanup]" ; exit 1 ; } @@ -59,22 +59,22 @@ test -z "$1" || { echo "! Usage: txcheck.sh [--cleanup]" ; exit 1 ; } XMLLINT="" for _xmllint in xmllint do - $_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint - test -n "$XMLLINT" && break + $_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint + test -n "$XMLLINT" && break done # Distinguish GNU date from BSD date if date +%s -d "1 week ago" > /dev/null 2>&1 ; then - last_week() { date +%s -d "1 week ago" ; } + last_week() { date +%s -d "1 week ago" ; } else - last_week() { date -v1w +%s; } + last_week() { date -v1w +%s; } fi # Distinguish GNU SHA executables from BSD ones if which sha256sum > /dev/null 2>&1 ; then - SHA256=sha256sum + SHA256=sha256sum else - SHA256=sha256 + SHA256=sha256 fi ### CHECK WORKING DIRECTORY diff --git a/ci/txpull.sh b/ci/txpull.sh index b320da300..734a689b5 100755 --- a/ci/txpull.sh +++ b/ci/txpull.sh @@ -1,4 +1,18 @@ #!/bin/sh + +### LICENSE +# === This file is part of Calamares - === +# +# SPDX-License-Identifier: BSD-2-Clause +# SPDX-FileCopyrightText: 2017-2020 Adriaan de Groot +# SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac +# +# This file is Free Software: you can redistribute it and/or modify +# it under the terms of the 2-clause BSD License. +# +### END LICENSE + +### USAGE # # Fetch the Transifex translations for Calamares and incorporate them # into the source tree, adding commits of the different files. @@ -6,6 +20,8 @@ # Run this (occasionally) at the top-level directory to get # new translations. See also CMakeLists.txt and ci/txstats.py # for update instructions. +# +### END USAGE ### INITIAL SETUP # @@ -32,8 +48,8 @@ test -f "calamares.desktop" || { echo "! Not at Calamares top-level" ; exit 1 ; XMLLINT="" for _xmllint in xmllint do - $_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint - test -n "$XMLLINT" && break + $_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint + test -n "$XMLLINT" && break done # XMLLINT is optional @@ -53,9 +69,9 @@ tx pull --force --source --all # so clean them up after pulling. # drop_language() { - rm -rf lang/python/"$1" src/modules/dummypythonqt/lang/"$1" lang/calamares_"$1".ts - grep -v "\\[$1]" calamares.desktop > calamares.desktop.new - mv calamares.desktop.new calamares.desktop + rm -rf lang/python/"$1" src/modules/dummypythonqt/lang/"$1" lang/calamares_"$1".ts + grep -v "\\[$1]" calamares.desktop > calamares.desktop.new + mv calamares.desktop.new calamares.desktop } drop_language es_ES @@ -68,10 +84,10 @@ mv calamares.desktop.new calamares.desktop # And fixup the XML files like in txpush.sh if test -n "$XMLLINT" ; then - for TS_FILE in lang/calamares_*.ts - do - $XMLLINT --c14n11 "$TS_FILE" | { echo "" ; cat - ; } | $XMLLINT --format --encode utf-8 -o "$TS_FILE".new - && mv "$TS_FILE".new "$TS_FILE" - done + for TS_FILE in lang/calamares_*.ts + do + $XMLLINT --c14n11 "$TS_FILE" | { echo "" ; cat - ; } | $XMLLINT --format --encode utf-8 -o "$TS_FILE".new - && mv "$TS_FILE".new "$TS_FILE" + done fi @@ -108,24 +124,24 @@ git diff --numstat src/modules | awk '($1==1 && $2==1){print $3}' | xargs git ch # Go through the Python modules; those with a lang/ subdir have their # own complete gettext-based setup. for MODULE_DIR in $(find src/modules -maxdepth 1 -mindepth 1 -type d) ; do - FILES=$(find "$MODULE_DIR" -name "*.py" -a -type f) - if test -n "$FILES" ; then - MODULE_NAME=$(basename ${MODULE_DIR}) - if [ -d ${MODULE_DIR}/lang ]; then - # Convert PO files to MO files - for POFILE in $(find ${MODULE_DIR} -name "*.po") ; do - sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE - msgfmt -o ${POFILE%.po}.mo $POFILE - done - git add --verbose ${MODULE_DIR}/lang/* - git commit "$AUTHOR" --message="i18n: [${MODULE_NAME}] $BOILERPLATE" | true - fi - fi + FILES=$(find "$MODULE_DIR" -name "*.py" -a -type f) + if test -n "$FILES" ; then + MODULE_NAME=$(basename ${MODULE_DIR}) + if [ -d ${MODULE_DIR}/lang ]; then + # Convert PO files to MO files + for POFILE in $(find ${MODULE_DIR} -name "*.po") ; do + sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE + msgfmt -o ${POFILE%.po}.mo $POFILE + done + git add --verbose ${MODULE_DIR}/lang/* + git commit "$AUTHOR" --message="i18n: [${MODULE_NAME}] $BOILERPLATE" | true + fi + fi done for POFILE in $(find lang -name "python.po") ; do - sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE - msgfmt -o ${POFILE%.po}.mo $POFILE + sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' $POFILE + msgfmt -o ${POFILE%.po}.mo $POFILE done git add --verbose lang/python* git commit "$AUTHOR" --message="i18n: [python] $BOILERPLATE" | true diff --git a/ci/txpush.sh b/ci/txpush.sh index 6882fa523..3195f42b4 100755 --- a/ci/txpush.sh +++ b/ci/txpush.sh @@ -1,13 +1,33 @@ #!/bin/sh + +### LICENSE +# === This file is part of Calamares - === +# +# SPDX-License-Identifier: BSD-2-Clause +# SPDX-FileCopyrightText: 2017-2020 Adriaan de Groot +# SPDX-FileCopyrightText: 2015-2016 Teo Mrnjavac +# +# This file is Free Software: you can redistribute it and/or modify +# it under the terms of the 2-clause BSD License. +# +### END LICENSE + +### USAGE # # Extract translations from Calamares source and send them -# to Transifex. +# to Transifex. Also (forcibly) updates the git "translation" +# tag to document that source texts were updated and sent; +# this is used by txcheck.sh to ensure that there's enough +# time between updates and releases, and that strings don't +# change between updates and releases. # # Run this at the top-level. # # Use the --no-tx option to do the extraction, but not the # pushing-to-Transifex part. This can be useful to check for # new strings or when testing the tools themselves. +# +### END USAGE ### INITIAL SETUP # @@ -28,21 +48,21 @@ test -f ".tx/config" || { echo "! Not at Calamares top-level" ; exit 1 ; } test -f "calamares.desktop" || { echo "! Not at Calamares top-level" ; exit 1 ; } if test "x$1" = "x--no-tx" ; then - # tx is the transifex command -- eat its arguments and do nothing - tx() { - echo "Skipped tx $*" - } - # txtag is used to tag in git to measure changes -- skip it too - txtag() { - echo "Skipped tx tagging." - } + # tx is the transifex command -- eat its arguments and do nothing + tx() { + echo "Skipped tx $*" + } + # txtag is used to tag in git to measure changes -- skip it too + txtag() { + echo "Skipped tx tagging." + } else - # tx is the regular transifex command - # txtag is used to tag in git to measure changes - txtag() { - git tag -f translation - git push --force origin translation - } + # tx is the regular transifex command + # txtag is used to tag in git to measure changes + txtag() { + git tag -f translation + git push --force origin translation + } fi @@ -52,18 +72,18 @@ fi LUPDATE="" for _lupdate in lupdate-qt5 lupdate do - export QT_SELECT=5 - $_lupdate -version > /dev/null 2>&1 || export QT_SELECT=qt5 - $_lupdate -version > /dev/null 2>&1 && LUPDATE=$_lupdate - test -n "$LUPDATE" && break + export QT_SELECT=5 + $_lupdate -version > /dev/null 2>&1 || export QT_SELECT=qt5 + $_lupdate -version > /dev/null 2>&1 && LUPDATE=$_lupdate + test -n "$LUPDATE" && break done test -n "$LUPDATE" || { echo "! No working lupdate" ; lupdate -version ; exit 1 ; } XMLLINT="" for _xmllint in xmllint do - $_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint - test -n "$XMLLINT" && break + $_xmllint --version > /dev/null 2>&1 && XMLLINT=$_xmllint + test -n "$XMLLINT" && break done # XMLLINT is optional @@ -82,8 +102,8 @@ $LUPDATE -no-obsolete $_srcdirs -ts lang/calamares_en.ts # $LUPDATE -no-obsolete -extensions cxxtr src/libcalamares/locale -ts lang/tz_en.ts if test -n "$XMLLINT" ; then - TS_FILE="lang/calamares_en.ts" - $XMLLINT --c14n11 "$TS_FILE" | { echo "" ; cat - ; } | $XMLLINT --format --encode utf-8 -o "$TS_FILE".new - && mv "$TS_FILE".new "$TS_FILE" + TS_FILE="lang/calamares_en.ts" + $XMLLINT --c14n11 "$TS_FILE" | { echo "" ; cat - ; } | $XMLLINT --format --encode utf-8 -o "$TS_FILE".new - && mv "$TS_FILE".new "$TS_FILE" fi tx push --source --no-interactive -r calamares.calamares-master @@ -103,29 +123,29 @@ PYGETTEXT="xgettext --keyword=_n:1,2 -L python" SHARED_PYTHON="" for MODULE_DIR in $(find src/modules -maxdepth 1 -mindepth 1 -type d) ; do - FILES=$(find "$MODULE_DIR" -name "*.py" -a -type f) - if test -n "$FILES" ; then - MODULE_NAME=$(basename ${MODULE_DIR}) - if [ -d ${MODULE_DIR}/lang ]; then - ${PYGETTEXT} -p ${MODULE_DIR}/lang -d ${MODULE_NAME} -o ${MODULE_NAME}.pot ${MODULE_DIR}/*.py - POTFILE="${MODULE_DIR}/lang/${MODULE_NAME}.pot" - if [ -f "$POTFILE" ]; then - sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' "$POTFILE" - tx set -r calamares.${MODULE_NAME} --source -l en "$POTFILE" - tx push --source --no-interactive -r calamares.${MODULE_NAME} - fi - else - SHARED_PYTHON="$SHARED_PYTHON $FILES" - fi - fi + FILES=$(find "$MODULE_DIR" -name "*.py" -a -type f) + if test -n "$FILES" ; then + MODULE_NAME=$(basename ${MODULE_DIR}) + if [ -d ${MODULE_DIR}/lang ]; then + ${PYGETTEXT} -p ${MODULE_DIR}/lang -d ${MODULE_NAME} -o ${MODULE_NAME}.pot ${MODULE_DIR}/*.py + POTFILE="${MODULE_DIR}/lang/${MODULE_NAME}.pot" + if [ -f "$POTFILE" ]; then + sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' "$POTFILE" + tx set -r calamares.${MODULE_NAME} --source -l en "$POTFILE" + tx push --source --no-interactive -r calamares.${MODULE_NAME} + fi + else + SHARED_PYTHON="$SHARED_PYTHON $FILES" + fi + fi done if test -n "$SHARED_PYTHON" ; then - ${PYGETTEXT} -p lang -d python -o python.pot $SHARED_PYTHON - POTFILE="lang/python.pot" - sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' "$POTFILE" - tx set -r calamares.python --source -l en "$POTFILE" - tx push --source --no-interactive -r calamares.python + ${PYGETTEXT} -p lang -d python -o python.pot $SHARED_PYTHON + POTFILE="lang/python.pot" + sed -i'' '/^"Content-Type/s/CHARSET/UTF-8/' "$POTFILE" + tx set -r calamares.python --source -l en "$POTFILE" + tx push --source --no-interactive -r calamares.python fi txtag From c766a0f10f44b90cfe7bee8fb2f7b7f040c98936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20M=C3=BCller?= Date: Fri, 7 Feb 2020 10:26:36 +0100 Subject: [PATCH 047/119] [machineid] create dbus var-lib folder when not existing See also #1314 --- src/modules/machineid/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/machineid/main.py b/src/modules/machineid/main.py index cde47cfd9..61f8c891e 100644 --- a/src/modules/machineid/main.py +++ b/src/modules/machineid/main.py @@ -4,7 +4,7 @@ # === This file is part of Calamares - === # # Copyright 2014, Kevin Kofler -# Copyright 2016, Philip Müller +# Copyright 2016,2020 Philip Müller # Copyright 2017, Alf Gaida # Copyright 2019, Adriaan de Groot # @@ -54,6 +54,10 @@ def run(): enable_symlink = libcalamares.job.configuration["symlink"] target_systemd_machineid_file = root_mount_point + "/etc/machine-id" target_dbus_machineid_file = root_mount_point + "/var/lib/dbus/machine-id" + target_dbus_folder = root_mount_point + "/var/lib/dbus" + + if not os.path.exists(target_dbus_folder): + os.mkdir(target_dbus_folder, 0644) if os.path.exists(target_dbus_machineid_file): os.remove(target_dbus_machineid_file) From 72d742e2f4a339929f0e8c0e9ae79704112bf741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20M=C3=BCller?= Date: Fri, 7 Feb 2020 10:34:01 +0100 Subject: [PATCH 048/119] [machineid] Use same approach as we do in Manjaro - See also https://gitlab.manjaro.org/applications/calamares/commit/da8f45ae - Fixes #1314 --- src/modules/machineid/main.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/modules/machineid/main.py b/src/modules/machineid/main.py index 61f8c891e..384193ed6 100644 --- a/src/modules/machineid/main.py +++ b/src/modules/machineid/main.py @@ -54,10 +54,6 @@ def run(): enable_symlink = libcalamares.job.configuration["symlink"] target_systemd_machineid_file = root_mount_point + "/etc/machine-id" target_dbus_machineid_file = root_mount_point + "/var/lib/dbus/machine-id" - target_dbus_folder = root_mount_point + "/var/lib/dbus" - - if not os.path.exists(target_dbus_folder): - os.mkdir(target_dbus_folder, 0644) if os.path.exists(target_dbus_machineid_file): os.remove(target_dbus_machineid_file) @@ -69,7 +65,7 @@ def run(): if enable_dbus: if enable_symlink and os.path.exists(target_systemd_machineid_file): - check_target_env_call(["ln", "-s", "/etc/machine-id", + check_target_env_call(["ln", "-sf", "/etc/machine-id", "/var/lib/dbus/machine-id"]) else: check_target_env_call(["dbus-uuidgen", "--ensure"]) From 97ddd30af48013b10034380f2654cb188062bf0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20M=C3=BCller?= Date: Fri, 7 Feb 2020 10:46:26 +0100 Subject: [PATCH 049/119] [machineid] folder needs to be created when not exists - See #1314 --- src/modules/machineid/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/machineid/main.py b/src/modules/machineid/main.py index 384193ed6..3c83ecf1a 100644 --- a/src/modules/machineid/main.py +++ b/src/modules/machineid/main.py @@ -54,6 +54,10 @@ def run(): enable_symlink = libcalamares.job.configuration["symlink"] target_systemd_machineid_file = root_mount_point + "/etc/machine-id" target_dbus_machineid_file = root_mount_point + "/var/lib/dbus/machine-id" + target_dbus_folder = root_mount_point + "/var/lib/dbus" + + if not os.path.exists(target_dbus_folder): + os.mkdir(target_dbus_folder, 0644) if os.path.exists(target_dbus_machineid_file): os.remove(target_dbus_machineid_file) From 9ef04192dbc621dbc2864c856d12b94eb139d4ce Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 11:03:40 +0100 Subject: [PATCH 050/119] [libcalamares] Simplify returns in targetPath() --- src/libcalamares/utils/CalamaresUtilsSystem.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index ea8f507bd..5d4b61a2f 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -266,8 +266,6 @@ System::runCommand( System::RunLocation location, QString System::targetPath( const QString& path ) const { - QString completePath; - if ( doChroot() ) { Calamares::GlobalStorage* gs @@ -279,14 +277,12 @@ System::targetPath( const QString& path ) const return QString(); } - completePath = gs->value( "rootMountPoint" ).toString() + '/' + path; + return gs->value( "rootMountPoint" ).toString() + '/' + path; } else { - completePath = QStringLiteral( "/" ) + path; + return QStringLiteral( "/" ) + path; } - - return completePath; } QString From bf882cec1d8ce7669645268d2ef4a2e5c49d9ecd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 11:14:57 +0100 Subject: [PATCH 051/119] [machineid] Migrate removeFile() to libcalamares - Becomes removeTargetFile() --- .../utils/CalamaresUtilsSystem.cpp | 20 ++++++++++++++++++- src/libcalamares/utils/CalamaresUtilsSystem.h | 11 +++++++++- src/modules/machineid/MachineIdJob.cpp | 10 ++++++---- src/modules/machineid/Workers.cpp | 11 ---------- src/modules/machineid/Workers.h | 3 --- 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index 5d4b61a2f..ede96305a 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Teo Mrnjavac - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2018, 2020, 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 @@ -285,6 +285,13 @@ System::targetPath( const QString& path ) const } } +/// @brief Cheap check if a path is absolute. +static inline bool +isAbsolutePath( const QString& path ) +{ + return path.startsWith( '/' ); +} + QString System::createTargetFile( const QString& path, const QByteArray& contents ) const { @@ -323,6 +330,17 @@ System::createTargetFile( const QString& path, const QByteArray& contents ) cons return QFileInfo( f ).canonicalFilePath(); } +void +System::removeTargetFile( const QString& path ) const +{ + if ( !isAbsolutePath( path ) ) + { + cWarning() << "Will not remove non-absolute path" << path; + return; + } + QFile::remove( targetPath( path ) ); +} + QPair< quint64, float > System::getTotalMemoryB() const diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.h b/src/libcalamares/utils/CalamaresUtilsSystem.h index 8265f0fdb..5c5e04eb2 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.h +++ b/src/libcalamares/utils/CalamaresUtilsSystem.h @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Teo Mrnjavac - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2018, 2020, 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 @@ -246,6 +246,15 @@ public: */ DLLEXPORT QString createTargetFile( const QString& path, const QByteArray& contents ) const; + /** @brief Remove a file from the target system. + * + * @param path Path to the file; this is interpreted from the root + * of the target system (@see targetPath()). + * + * Does no error checking to see if the target file was really removed. + */ + DLLEXPORT void removeTargetFile( const QString& path ) const; + /** * @brief getTotalMemoryB returns the total main memory, in bytes. * diff --git a/src/modules/machineid/MachineIdJob.cpp b/src/modules/machineid/MachineIdJob.cpp index 393950ded..af3a68d90 100644 --- a/src/modules/machineid/MachineIdJob.cpp +++ b/src/modules/machineid/MachineIdJob.cpp @@ -3,7 +3,7 @@ * Copyright 2014, Kevin Kofler * Copyright 2016, Philip Müller * Copyright 2017, Alf Gaida - * Copyright 2019, Adriaan de Groot + * Copyright 2019-2020, 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 @@ -68,18 +68,20 @@ MachineIdJob::exec() QString target_dbus_machineid_file = QStringLiteral( "/var/lib/dbus/machine-id" ); QString target_entropy_file = QStringLiteral( "/var/lib/urandom/random-seed" ); + const auto* system = CalamaresUtils::System::instance(); + // Clear existing files if ( m_entropy ) { - MachineId::removeFile( root, target_entropy_file ); + system->removeTargetFile( target_entropy_file ); } if ( m_dbus ) { - MachineId::removeFile( root, target_dbus_machineid_file ); + system->removeTargetFile( target_dbus_machineid_file ); } if ( m_systemd ) { - MachineId::removeFile( root, target_systemd_machineid_file ); + system->removeTargetFile( target_systemd_machineid_file ); } //Create new files diff --git a/src/modules/machineid/Workers.cpp b/src/modules/machineid/Workers.cpp index fefaf24b9..f1f7bb369 100644 --- a/src/modules/machineid/Workers.cpp +++ b/src/modules/machineid/Workers.cpp @@ -36,17 +36,6 @@ isAbsolutePath( const QString& fileName ) return fileName.startsWith( '/' ); } -// might need to use a helper to remove the file -void -removeFile( const QString& rootMountPoint, const QString& fileName ) -{ - if ( isAbsolutePath( fileName ) ) - { - QFile::remove( rootMountPoint + fileName ); - } - // Otherwise, do nothing -} - Calamares::JobResult copyFile( const QString& rootMountPoint, const QString& fileName ) { diff --git a/src/modules/machineid/Workers.h b/src/modules/machineid/Workers.h index 5cf6270d9..31561af1b 100644 --- a/src/modules/machineid/Workers.h +++ b/src/modules/machineid/Workers.h @@ -30,9 +30,6 @@ namespace MachineId * for moving files around in the target system. */ -/// @brief Remove @p fileName from the target system at @p rootMountPoint -void removeFile( const QString& rootMountPoint, const QString& fileName ); - /// @brief Copy @p fileName from host into target system at @p rootMountPoint Calamares::JobResult copyFile( const QString& rootMountPoint, const QString& fileName ); From 4af68365c9bd955ee66001ad54b5d8bb71ef8cf5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 11:16:40 +0100 Subject: [PATCH 052/119] [machineid] Remove obsolete implementation --- src/modules/machineid/main.py | 73 ----------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 src/modules/machineid/main.py diff --git a/src/modules/machineid/main.py b/src/modules/machineid/main.py deleted file mode 100644 index 384193ed6..000000000 --- a/src/modules/machineid/main.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# -# === This file is part of Calamares - === -# -# Copyright 2014, Kevin Kofler -# Copyright 2016,2020 Philip Müller -# Copyright 2017, Alf Gaida -# Copyright 2019, 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 . - -import libcalamares -import os -from libcalamares.utils import check_target_env_call, debug - -import gettext -_ = gettext.translation("calamares-python", - localedir=libcalamares.utils.gettext_path(), - languages=libcalamares.utils.gettext_languages(), - fallback=True).gettext - - -def pretty_name(): - return _("Generate machine-id.") - - -def run(): - """ - Generate machine-id using dbus and systemd. - - :return: - """ - root_mount_point = libcalamares.globalstorage.value("rootMountPoint") - - if root_mount_point is None: - libcalamares.utils.warning("rootMountPoint is empty, {!s}".format(root_mount_point)) - return (_("Configuration Error"), - _("No root mount point is given for
{!s}
to use." ).format("machineid")) - - enable_systemd = libcalamares.job.configuration["systemd"] - enable_dbus = libcalamares.job.configuration["dbus"] - enable_symlink = libcalamares.job.configuration["symlink"] - target_systemd_machineid_file = root_mount_point + "/etc/machine-id" - target_dbus_machineid_file = root_mount_point + "/var/lib/dbus/machine-id" - - if os.path.exists(target_dbus_machineid_file): - os.remove(target_dbus_machineid_file) - - if enable_systemd: - if os.path.exists(target_systemd_machineid_file): - os.remove(target_systemd_machineid_file) - check_target_env_call("systemd-machine-id-setup") - - if enable_dbus: - if enable_symlink and os.path.exists(target_systemd_machineid_file): - check_target_env_call(["ln", "-sf", "/etc/machine-id", - "/var/lib/dbus/machine-id"]) - else: - check_target_env_call(["dbus-uuidgen", "--ensure"]) - - return None From 95936549e2be8e8f8c1aa343bf4b794d9c14204a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 11:30:37 +0100 Subject: [PATCH 053/119] [libcalamares] Add a createTargetBasedirs() - Used to ensure that the directories leading up to a given path exist. Implementation is incomplete and broken for now. - While here, avoid removing an empty pathname in removeTargetFile() (the empty pathname indicates a broken configuration). --- .../utils/CalamaresUtilsSystem.cpp | 30 ++++++++++++++++++- src/libcalamares/utils/CalamaresUtilsSystem.h | 11 +++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index ede96305a..3b36a7ccf 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -338,7 +338,35 @@ System::removeTargetFile( const QString& path ) const cWarning() << "Will not remove non-absolute path" << path; return; } - QFile::remove( targetPath( path ) ); + QString target = targetPath( path ); + if ( !target.isEmpty() ) + { + QFile::remove( target ); + } + // If it was empty, a warning was already printed +} + +int +System::createTargetBasedirs(const QString& path) const +{ + if ( !isAbsolutePath( path ) ) + { + cWarning() << "Will not create basedirs for non-absolute path" << path; + return -1; + } + + QString target = targetPath( path ); + if ( target.isEmpty() ) + { + // If it was empty, a warning was already printed + return -1; + } + + QString base( "/" ); + QStringList parts = target.split( '/', QString::SplitBehavior::SkipEmptyParts ); + + cDebug() << parts; + return -1; } diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.h b/src/libcalamares/utils/CalamaresUtilsSystem.h index 5c5e04eb2..09a606e2c 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.h +++ b/src/libcalamares/utils/CalamaresUtilsSystem.h @@ -255,6 +255,17 @@ public: */ DLLEXPORT void removeTargetFile( const QString& path ) const; + /** @brief Ensure that the directories above @p path exist + * + * @param path a full pathname to a desired file. + * + * All the directory components before the last path component are + * created, as needed, with 0755 permissions. Returns the number + * of components that needed to be created; 0 if they all already + * existed, and < 0 on failure. + */ + DLLEXPORT int createTargetBasedirs( const QString& path ) const; + /** * @brief getTotalMemoryB returns the total main memory, in bytes. * From 15bca702c1adefa0ab71ea2ee2181601544858d0 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 11:51:13 +0100 Subject: [PATCH 054/119] [libcalamares] Add tests for path functions (part 1) --- src/libcalamares/utils/Tests.cpp | 27 +++++++++++++++++++++++++++ src/libcalamares/utils/Tests.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/src/libcalamares/utils/Tests.cpp b/src/libcalamares/utils/Tests.cpp index 16faec9a1..7f9f7f2bf 100644 --- a/src/libcalamares/utils/Tests.cpp +++ b/src/libcalamares/utils/Tests.cpp @@ -24,6 +24,9 @@ #include "UMask.h" #include "Yaml.h" +#include "GlobalStorage.h" +#include "JobQueue.h" + #include #include @@ -221,3 +224,27 @@ LibCalamaresTests::testPrintableEntropy() QVERIFY( c.cell() < 127 ); } } + +void +LibCalamaresTests::testTargetPath() +{ + // Ensure we have a system object, expect it to be a "bogus" one + const CalamaresUtils::System* system = CalamaresUtils::System::instance(); + QVERIFY( system ); + QVERIFY( system->doChroot() ); + + // Ensure we have a system-wide GlobalStorage with /tmp as root + if ( !Calamares::JobQueue::instance() ) + { + (void)new Calamares::JobQueue(); + } + Calamares::GlobalStorage* gs + = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; + QVERIFY( gs ); + gs->insert( "rootMountPoint", "/tmp" ); + + // Paths mapped normally + QCOMPARE( system->targetPath( "/etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); + QCOMPARE( system->targetPath( "//etc//calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); // extra / + QCOMPARE( system->targetPath( "etc/calamares" ), QString() ); // NOT ABSOLUTE +} diff --git a/src/libcalamares/utils/Tests.h b/src/libcalamares/utils/Tests.h index d369ed4cb..8ea9aa0ce 100644 --- a/src/libcalamares/utils/Tests.h +++ b/src/libcalamares/utils/Tests.h @@ -43,6 +43,9 @@ private Q_SLOTS: /** @brief Tests the entropy functions. */ void testEntropy(); void testPrintableEntropy(); + + /** @brief Tests file creation and removal. */ + void testTargetPath(); }; #endif From 31878dd43b0f6adb879585228d4ce61ed1e8a7b1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 13:29:35 +0100 Subject: [PATCH 055/119] [libcalamares] Avoid double / between root and path in targetPath() --- .../utils/CalamaresUtilsSystem.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index 3b36a7ccf..b5293c252 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -263,6 +263,13 @@ System::runCommand( System::RunLocation location, return ProcessResult( r, output ); } +/// @brief Cheap check if a path is absolute. +static inline bool +isAbsolutePath( const QString& path ) +{ + return path.startsWith( '/' ); +} + QString System::targetPath( const QString& path ) const { @@ -277,21 +284,15 @@ System::targetPath( const QString& path ) const return QString(); } - return gs->value( "rootMountPoint" ).toString() + '/' + path; + QString root = gs->value( "rootMountPoint" ).toString(); + return isAbsolutePath( path ) ? ( root + path ) : ( root + '/' + path ); } else { - return QStringLiteral( "/" ) + path; + return isAbsolutePath( path ) ? path : ( QStringLiteral( "/" ) + path ); } } -/// @brief Cheap check if a path is absolute. -static inline bool -isAbsolutePath( const QString& path ) -{ - return path.startsWith( '/' ); -} - QString System::createTargetFile( const QString& path, const QByteArray& contents ) const { @@ -347,7 +348,7 @@ System::removeTargetFile( const QString& path ) const } int -System::createTargetBasedirs(const QString& path) const +System::createTargetBasedirs( const QString& path ) const { if ( !isAbsolutePath( path ) ) { From daa5b804b3e7b78a6f0431f43cf270a85d2e0951 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 13:49:06 +0100 Subject: [PATCH 056/119] [libcalamares] Split paths-tests into own test executable - Since these tests all want a system object, and a GS with a sensible setup, give them one with its own initTestCase(). This could have been done with one executable, running tests from multiple classes, but there's not much overall benefit there. --- src/libcalamares/CMakeLists.txt | 12 ++++ src/libcalamares/utils/TestPaths.cpp | 89 ++++++++++++++++++++++++++++ src/libcalamares/utils/Tests.cpp | 24 -------- src/libcalamares/utils/Tests.h | 3 - 4 files changed, 101 insertions(+), 27 deletions(-) create mode 100644 src/libcalamares/utils/TestPaths.cpp diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index 0e7f7c6e7..cad7e7a6e 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -171,6 +171,18 @@ if ( ECM_FOUND AND BUILD_TESTING ) ) calamares_automoc( libcalamarestest ) + ecm_add_test( + utils/TestPaths.cpp + TEST_NAME + libcalamarestestpaths + LINK_LIBRARIES + calamares + Qt5::Core + Qt5::Test + ) + calamares_automoc( libcalamarestestpaths ) + + ecm_add_test( geoip/GeoIPTests.cpp ${geoip_src} diff --git a/src/libcalamares/utils/TestPaths.cpp b/src/libcalamares/utils/TestPaths.cpp new file mode 100644 index 000000000..5071b1289 --- /dev/null +++ b/src/libcalamares/utils/TestPaths.cpp @@ -0,0 +1,89 @@ +/* === This file is part of Calamares - === + * + * 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 . + */ + +#include "CalamaresUtilsSystem.h" +#include "Entropy.h" +#include "Logger.h" +#include "UMask.h" +#include "Yaml.h" + +#include "GlobalStorage.h" +#include "JobQueue.h" + +#include + +#include + +#include +#include +#include + +class TestPaths : public QObject +{ + Q_OBJECT +public: + TestPaths() {}; + virtual ~TestPaths() {}; + +private Q_SLOTS: + void initTestCase(); + + void testTargetPath(); + +private: + CalamaresUtils::System* m_system; // Points to singleton instance, not owned +}; + +void +TestPaths::initTestCase() +{ + Logger::setupLogLevel( Logger::LOGDEBUG ); + + // Ensure we have a system object, expect it to be a "bogus" one + CalamaresUtils::System* system = CalamaresUtils::System::instance(); + QVERIFY( system ); + QVERIFY( system->doChroot() ); + + // Ensure we have a system-wide GlobalStorage with /tmp as root + if ( !Calamares::JobQueue::instance() ) + { + (void)new Calamares::JobQueue(); + } + Calamares::GlobalStorage* gs + = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; + QVERIFY( gs ); + gs->insert( "rootMountPoint", "/tmp" ); + + m_system = system; +} + + +void +TestPaths::testTargetPath() +{ + // Paths mapped normally + QCOMPARE( m_system->targetPath( "/etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); + QCOMPARE( m_system->targetPath( "//etc//calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); // extra / + QCOMPARE( m_system->targetPath( "etc/calamares" ), QString() ); // NOT ABSOLUTE +} + +QTEST_GUILESS_MAIN( TestPaths ) + +#include "utils/moc-warnings.h" + +#include "TestPaths.moc" diff --git a/src/libcalamares/utils/Tests.cpp b/src/libcalamares/utils/Tests.cpp index 7f9f7f2bf..e39d182ea 100644 --- a/src/libcalamares/utils/Tests.cpp +++ b/src/libcalamares/utils/Tests.cpp @@ -224,27 +224,3 @@ LibCalamaresTests::testPrintableEntropy() QVERIFY( c.cell() < 127 ); } } - -void -LibCalamaresTests::testTargetPath() -{ - // Ensure we have a system object, expect it to be a "bogus" one - const CalamaresUtils::System* system = CalamaresUtils::System::instance(); - QVERIFY( system ); - QVERIFY( system->doChroot() ); - - // Ensure we have a system-wide GlobalStorage with /tmp as root - if ( !Calamares::JobQueue::instance() ) - { - (void)new Calamares::JobQueue(); - } - Calamares::GlobalStorage* gs - = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; - QVERIFY( gs ); - gs->insert( "rootMountPoint", "/tmp" ); - - // Paths mapped normally - QCOMPARE( system->targetPath( "/etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); - QCOMPARE( system->targetPath( "//etc//calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); // extra / - QCOMPARE( system->targetPath( "etc/calamares" ), QString() ); // NOT ABSOLUTE -} diff --git a/src/libcalamares/utils/Tests.h b/src/libcalamares/utils/Tests.h index 8ea9aa0ce..d369ed4cb 100644 --- a/src/libcalamares/utils/Tests.h +++ b/src/libcalamares/utils/Tests.h @@ -43,9 +43,6 @@ private Q_SLOTS: /** @brief Tests the entropy functions. */ void testEntropy(); void testPrintableEntropy(); - - /** @brief Tests file creation and removal. */ - void testTargetPath(); }; #endif From 8d23e665ea82e4aa75bfab3060e2f8298bea7f82 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 13:53:49 +0100 Subject: [PATCH 057/119] [libcalamares] Fix targetPath() tests - there is less simplification done than you might think --- src/libcalamares/utils/TestPaths.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/utils/TestPaths.cpp b/src/libcalamares/utils/TestPaths.cpp index 5071b1289..2232ca084 100644 --- a/src/libcalamares/utils/TestPaths.cpp +++ b/src/libcalamares/utils/TestPaths.cpp @@ -78,8 +78,8 @@ TestPaths::testTargetPath() { // Paths mapped normally QCOMPARE( m_system->targetPath( "/etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); - QCOMPARE( m_system->targetPath( "//etc//calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); // extra / - QCOMPARE( m_system->targetPath( "etc/calamares" ), QString() ); // NOT ABSOLUTE + QCOMPARE( m_system->targetPath( "//etc//calamares" ), QStringLiteral( "/tmp//etc//calamares" ) ); // extra / are not cleaned up + QCOMPARE( m_system->targetPath( "etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); // relative to root } QTEST_GUILESS_MAIN( TestPaths ) From 394eee395414b844ad27ac15b002d069883a3827 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 13:57:14 +0100 Subject: [PATCH 058/119] [libcalamares] Test more targetPath() scenario's --- src/libcalamares/utils/TestPaths.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libcalamares/utils/TestPaths.cpp b/src/libcalamares/utils/TestPaths.cpp index 2232ca084..7411dc5bb 100644 --- a/src/libcalamares/utils/TestPaths.cpp +++ b/src/libcalamares/utils/TestPaths.cpp @@ -80,6 +80,13 @@ TestPaths::testTargetPath() QCOMPARE( m_system->targetPath( "/etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); QCOMPARE( m_system->targetPath( "//etc//calamares" ), QStringLiteral( "/tmp//etc//calamares" ) ); // extra / are not cleaned up QCOMPARE( m_system->targetPath( "etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); // relative to root + + // Weird Paths + QCOMPARE( m_system->targetPath( QString() ), QStringLiteral( "/tmp/" ) ); + + // Now break GS + Calamares::JobQueue::instance()->globalStorage()->remove( "rootMountPoint" ); + QCOMPARE( m_system->targetPath( QString() ), QString() ); // Without root, no path } QTEST_GUILESS_MAIN( TestPaths ) From b502d78984e9b5406600f9eeea93ebc26171344f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 13:58:44 +0100 Subject: [PATCH 059/119] [libcalamares] Fix warning message - "create" was when this function was used elsewhere --- src/libcalamares/utils/CalamaresUtilsSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index b5293c252..0c21034af 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -280,7 +280,7 @@ System::targetPath( const QString& path ) const if ( !gs || !gs->contains( "rootMountPoint" ) ) { - cWarning() << "No rootMountPoint in global storage, cannot create target file" << path; + cWarning() << "No rootMountPoint in global storage, cannot name target file" << path; return QString(); } From 8b8ecf7b7bcdf42adff3e8c5082a4d67c3dd827e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 15:23:02 +0100 Subject: [PATCH 060/119] [libcalamars] Improve test init and cleanup - Test createTargetFile and removeTargetFile - Clean up afterwards - Ensure /tmp is the RMP for each test --- src/libcalamares/utils/TestPaths.cpp | 45 +++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/libcalamares/utils/TestPaths.cpp b/src/libcalamares/utils/TestPaths.cpp index 7411dc5bb..5de8ae4fc 100644 --- a/src/libcalamares/utils/TestPaths.cpp +++ b/src/libcalamares/utils/TestPaths.cpp @@ -42,13 +42,20 @@ public: private Q_SLOTS: void initTestCase(); + void init(); + void cleanupTestCase(); void testTargetPath(); + void testCreateTarget(); private: - CalamaresUtils::System* m_system; // Points to singleton instance, not owned + CalamaresUtils::System* m_system = nullptr; // Points to singleton instance, not owned + Calamares::GlobalStorage* m_gs = nullptr; }; +static const char testFile[] = "/calamares-testcreate"; +static const char absFile[] = "/tmp/calamares-testcreate"; // With rootMountPoint prepended + void TestPaths::initTestCase() { @@ -62,14 +69,28 @@ TestPaths::initTestCase() // Ensure we have a system-wide GlobalStorage with /tmp as root if ( !Calamares::JobQueue::instance() ) { + cDebug() << "Creating new JobQueue"; (void)new Calamares::JobQueue(); } Calamares::GlobalStorage* gs = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; QVERIFY( gs ); - gs->insert( "rootMountPoint", "/tmp" ); m_system = system; + m_gs = gs; +} + +void +TestPaths::cleanupTestCase() +{ + QFile::remove( absFile ); +} + +void +TestPaths::init() +{ + cDebug() << "Setting rootMountPoint"; + m_gs->insert( "rootMountPoint", "/tmp" ); } @@ -78,17 +99,33 @@ TestPaths::testTargetPath() { // Paths mapped normally QCOMPARE( m_system->targetPath( "/etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); - QCOMPARE( m_system->targetPath( "//etc//calamares" ), QStringLiteral( "/tmp//etc//calamares" ) ); // extra / are not cleaned up + QCOMPARE( m_system->targetPath( "//etc//calamares" ), + QStringLiteral( "/tmp//etc//calamares" ) ); // extra / are not cleaned up QCOMPARE( m_system->targetPath( "etc/calamares" ), QStringLiteral( "/tmp/etc/calamares" ) ); // relative to root // Weird Paths QCOMPARE( m_system->targetPath( QString() ), QStringLiteral( "/tmp/" ) ); // Now break GS - Calamares::JobQueue::instance()->globalStorage()->remove( "rootMountPoint" ); + m_gs->remove( "rootMountPoint" ); QCOMPARE( m_system->targetPath( QString() ), QString() ); // Without root, no path } + +void +TestPaths::testCreateTarget() +{ + QCOMPARE( m_system->createTargetFile( testFile, "Hello" ), QString( absFile ) ); // Success + + QFileInfo fi( absFile ); + QVERIFY( fi.exists() ); + QCOMPARE( fi.size(), 5 ); + + m_system->removeTargetFile( testFile ); + QFileInfo fi2( absFile ); // fi caches information + QVERIFY( !fi2.exists() ); +} + QTEST_GUILESS_MAIN( TestPaths ) #include "utils/moc-warnings.h" From e65969d5871e79b4a4fdaf46eab3af4b0baba7b8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 15:51:46 +0100 Subject: [PATCH 061/119] [libcalamares] Re-do createTargetDirs() - Drop the basedirs idea, replace return with just bool - Use QDir::mkpath, with some extra validation - Test it a bit --- .../utils/CalamaresUtilsSystem.cpp | 24 ++++++++---- src/libcalamares/utils/CalamaresUtilsSystem.h | 12 +++--- src/libcalamares/utils/TestPaths.cpp | 37 +++++++++++++++++-- 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index 0c21034af..7e6ef99d6 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -347,27 +347,35 @@ System::removeTargetFile( const QString& path ) const // If it was empty, a warning was already printed } -int -System::createTargetBasedirs( const QString& path ) const +bool +System::createTargetDirs( const QString& path ) const { if ( !isAbsolutePath( path ) ) { cWarning() << "Will not create basedirs for non-absolute path" << path; - return -1; + return false; } QString target = targetPath( path ); if ( target.isEmpty() ) { // If it was empty, a warning was already printed - return -1; + return false; } - QString base( "/" ); - QStringList parts = target.split( '/', QString::SplitBehavior::SkipEmptyParts ); + QString root = Calamares::JobQueue::instance()->globalStorage()->value( "rootMountPoint" ).toString(); + if ( root.isEmpty() ) + { + return false; + } - cDebug() << parts; - return -1; + QDir d( root ); + if ( !d.exists() ) + { + cWarning() << "Root mountpoint" << root << "does not exist."; + return false; + } + return d.mkpath( target ); // This re-does everything starting from the **host** / } diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.h b/src/libcalamares/utils/CalamaresUtilsSystem.h index 09a606e2c..e95d5731e 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.h +++ b/src/libcalamares/utils/CalamaresUtilsSystem.h @@ -257,14 +257,14 @@ public: /** @brief Ensure that the directories above @p path exist * - * @param path a full pathname to a desired file. + * @param path a full pathname to a desired directory. * - * All the directory components before the last path component are - * created, as needed, with 0755 permissions. Returns the number - * of components that needed to be created; 0 if they all already - * existed, and < 0 on failure. + * All the directory components including the last path component are + * created, as needed, with 0755 permissions. Returns true on success. + * + * @see QDir::mkpath */ - DLLEXPORT int createTargetBasedirs( const QString& path ) const; + DLLEXPORT bool createTargetDirs( const QString& path ) const; /** * @brief getTotalMemoryB returns the total main memory, in bytes. diff --git a/src/libcalamares/utils/TestPaths.cpp b/src/libcalamares/utils/TestPaths.cpp index 5de8ae4fc..36e8afe5e 100644 --- a/src/libcalamares/utils/TestPaths.cpp +++ b/src/libcalamares/utils/TestPaths.cpp @@ -25,13 +25,14 @@ #include "GlobalStorage.h" #include "JobQueue.h" -#include +#include +// #include #include -#include -#include -#include +// #include +// #include +// #include class TestPaths : public QObject { @@ -47,6 +48,7 @@ private Q_SLOTS: void testTargetPath(); void testCreateTarget(); + void testCreateTargetBasedirs(); private: CalamaresUtils::System* m_system = nullptr; // Points to singleton instance, not owned @@ -126,6 +128,33 @@ TestPaths::testCreateTarget() QVERIFY( !fi2.exists() ); } +struct DirRemover +{ + DirRemover( const QString& base, const QString& dir ) + : m_base( base ) + , m_dir( dir ) + { + } + ~DirRemover() { QDir( m_base ).rmpath( m_dir ); } + + bool exists() const { return QDir( m_base ).exists( m_dir ); } + + QString m_base, m_dir; +}; + +void +TestPaths::testCreateTargetBasedirs() +{ + { + DirRemover dirrm( "/tmp", "var/lib/dbus" ); + QVERIFY( m_system->createTargetDirs( "/" ) ); + QVERIFY( m_system->createTargetDirs( "/var/lib/dbus" ) ); + QVERIFY( QFile( "/tmp/var/lib/dbus" ).exists() ); + QVERIFY( dirrm.exists() ); + } + QVERIFY( !QFile( "/tmp/var/lib/dbus" ).exists() ); +} + QTEST_GUILESS_MAIN( TestPaths ) #include "utils/moc-warnings.h" From 6ede9f2c7ce40859275fead6882f49679932d7a8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 16:08:38 +0100 Subject: [PATCH 062/119] [libcalamares] Test QFileInfo::dir() for completeness --- src/libcalamares/utils/TestPaths.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libcalamares/utils/TestPaths.cpp b/src/libcalamares/utils/TestPaths.cpp index 36e8afe5e..2f9f4e657 100644 --- a/src/libcalamares/utils/TestPaths.cpp +++ b/src/libcalamares/utils/TestPaths.cpp @@ -153,6 +153,9 @@ TestPaths::testCreateTargetBasedirs() QVERIFY( dirrm.exists() ); } QVERIFY( !QFile( "/tmp/var/lib/dbus" ).exists() ); + + // QFileInfo.dir() behaves even when things don't exist + QCOMPARE( QFileInfo( "/tmp/var/lib/dbus/bogus" ).dir().path(), QStringLiteral( "/tmp/var/lib/dbus" ) ); } QTEST_GUILESS_MAIN( TestPaths ) From 240fe2a56481d59c2f4b92aa927f02900fee2f96 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 16:09:02 +0100 Subject: [PATCH 063/119] [libcalamares] Add convenience createTargetParentDirs() --- src/libcalamares/utils/CalamaresUtilsSystem.cpp | 6 ++++++ src/libcalamares/utils/CalamaresUtilsSystem.h | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.cpp b/src/libcalamares/utils/CalamaresUtilsSystem.cpp index 7e6ef99d6..61e05976a 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.cpp +++ b/src/libcalamares/utils/CalamaresUtilsSystem.cpp @@ -378,6 +378,12 @@ System::createTargetDirs( const QString& path ) const return d.mkpath( target ); // This re-does everything starting from the **host** / } +bool +System::createTargetParentDirs( const QString& filePath ) const +{ + return createTargetDirs( QFileInfo( filePath ).dir().path() ); +} + QPair< quint64, float > System::getTotalMemoryB() const diff --git a/src/libcalamares/utils/CalamaresUtilsSystem.h b/src/libcalamares/utils/CalamaresUtilsSystem.h index e95d5731e..ca8e0d797 100644 --- a/src/libcalamares/utils/CalamaresUtilsSystem.h +++ b/src/libcalamares/utils/CalamaresUtilsSystem.h @@ -255,17 +255,24 @@ public: */ DLLEXPORT void removeTargetFile( const QString& path ) const; - /** @brief Ensure that the directories above @p path exist + /** @brief Ensure that the directory @p path exists * * @param path a full pathname to a desired directory. * * All the directory components including the last path component are - * created, as needed, with 0755 permissions. Returns true on success. + * created, as needed. Returns true on success. * * @see QDir::mkpath */ DLLEXPORT bool createTargetDirs( const QString& path ) const; + /** @brief Convenience to create parent directories of a file path. + * + * Creates all the parent directories until the last + * component of @p filePath . @see createTargetDirs() + */ + DLLEXPORT bool createTargetParentDirs( const QString& filePath ) const; + /** * @brief getTotalMemoryB returns the total main memory, in bytes. * From b62004aae9039b44fd9d2c8e6eb9d74f5c88d863 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 16:10:13 +0100 Subject: [PATCH 064/119] [machineid] Create the DBus data directory - before running dbus-uuidgen or linking to systemd's UUID, create /var/lib/dbus; some distro's don't create that beforehand. FIXES #1314 --- src/modules/machineid/MachineIdJob.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/machineid/MachineIdJob.cpp b/src/modules/machineid/MachineIdJob.cpp index af3a68d90..fc535e356 100644 --- a/src/modules/machineid/MachineIdJob.cpp +++ b/src/modules/machineid/MachineIdJob.cpp @@ -68,7 +68,7 @@ MachineIdJob::exec() QString target_dbus_machineid_file = QStringLiteral( "/var/lib/dbus/machine-id" ); QString target_entropy_file = QStringLiteral( "/var/lib/urandom/random-seed" ); - const auto* system = CalamaresUtils::System::instance(); + const CalamaresUtils::System* system = CalamaresUtils::System::instance(); // Clear existing files if ( m_entropy ) @@ -106,6 +106,10 @@ MachineIdJob::exec() } if ( m_dbus ) { + if ( !system->createTargetParentDirs( target_dbus_machineid_file ) ) + { + cWarning() << "Could not create DBus data-directory."; + } if ( m_dbus_symlink && QFile::exists( root + target_systemd_machineid_file ) ) { auto r = MachineId::createDBusLink( root, target_dbus_machineid_file, target_systemd_machineid_file ); From 4cdcb48de6f0dd79264df56dbaf6ad961098931a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 16:12:17 +0100 Subject: [PATCH 065/119] [machineid] Functionality moved to libcalamares --- src/modules/machineid/Tests.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/modules/machineid/Tests.cpp b/src/modules/machineid/Tests.cpp index 273645e22..87853af82 100644 --- a/src/modules/machineid/Tests.cpp +++ b/src/modules/machineid/Tests.cpp @@ -35,7 +35,6 @@ public: private Q_SLOTS: void initTestCase(); - void testRemoveFile(); void testCopyFile(); void testPoolSize(); @@ -84,11 +83,6 @@ MachineIdTests::testCopyFile() } } -void -MachineIdTests::testRemoveFile() -{ -} - void MachineIdTests::testPoolSize() { From 110a84344bd8e88a6da156c0323de26d057890cd Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 20:29:42 +0100 Subject: [PATCH 066/119] [machineid] Test job function - Create a job and ask it to create dbus files -- either directly, or as a symlink. Since the target chroot isn't viable, this will fail but we can at least see that directories are created, etc. --- src/modules/machineid/CMakeLists.txt | 1 + src/modules/machineid/Tests.cpp | 63 +++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/modules/machineid/CMakeLists.txt b/src/modules/machineid/CMakeLists.txt index efb6454e8..a57d5163d 100644 --- a/src/modules/machineid/CMakeLists.txt +++ b/src/modules/machineid/CMakeLists.txt @@ -12,6 +12,7 @@ calamares_add_plugin( machineid if ( ECM_FOUND AND BUILD_TESTING ) ecm_add_test( Tests.cpp + MachineIdJob.cpp Workers.cpp TEST_NAME machineidtest diff --git a/src/modules/machineid/Tests.cpp b/src/modules/machineid/Tests.cpp index 87853af82..53abd0482 100644 --- a/src/modules/machineid/Tests.cpp +++ b/src/modules/machineid/Tests.cpp @@ -16,11 +16,14 @@ * along with Calamares. If not, see . */ +#include "MachineIdJob.h" #include "Workers.h" +#include "GlobalStorage.h" +#include "JobQueue.h" +#include "utils/CalamaresUtilsSystem.h" #include "utils/Logger.h" - #include #include #include @@ -38,6 +41,8 @@ private Q_SLOTS: void testCopyFile(); void testPoolSize(); + + void testJob(); }; void @@ -95,6 +100,62 @@ MachineIdTests::testPoolSize() #endif } +void +MachineIdTests::testJob() +{ + Logger::setupLogLevel( Logger::LOGDEBUG ); + + // Ensure we have a system object, expect it to be a "bogus" one + CalamaresUtils::System* system = CalamaresUtils::System::instance(); + QVERIFY( system ); + QVERIFY( system->doChroot() ); + + // Ensure we have a system-wide GlobalStorage with /tmp as root + if ( !Calamares::JobQueue::instance() ) + { + cDebug() << "Creating new JobQueue"; + (void)new Calamares::JobQueue(); + } + Calamares::GlobalStorage* gs + = Calamares::JobQueue::instance() ? Calamares::JobQueue::instance()->globalStorage() : nullptr; + QVERIFY( gs ); + gs->insert( "rootMountPoint", "/tmp" ); + + // Prepare part of the target filesystem + QVERIFY( system->createTargetDirs("/etc") ); + QVERIFY( !(system->createTargetFile( "/etc/machine-id", "Hello" ).isEmpty() ) ); + + MachineIdJob job( nullptr ); + QVERIFY( !job.prettyName().isEmpty() ); + + QVariantMap config; + config.insert( "dbus", true ); + job.setConfigurationMap( config ); + + { + auto r = job.exec(); + QVERIFY( !r ); // It's supposed to fail, because no dbus-uuidgen executable exists + QVERIFY( QFile::exists( "/tmp/var/lib/dbus" ) ); // but the target dir exists + } + + config.insert( "dbus-symlink", true ); + job.setConfigurationMap( config ); + { + auto r = job.exec(); + QVERIFY( !r ); // It's supposed to fail, because no dbus-uuidgen executable exists + QVERIFY( QFile::exists( "/tmp/var/lib/dbus" ) ); // but the target dir exists + + // These all (would) fail, because the chroot isn't viable +#if 0 + QVERIFY( QFile::exists( "/tmp/var/lib/dbus/machine-id" ) ); + + QFileInfo fi( "/tmp/var/lib/dbus/machine-id" ); + QVERIFY( fi.exists() ); + QVERIFY( fi.isSymLink() ); + QCOMPARE( fi.size(), 5); +#endif + } +} QTEST_GUILESS_MAIN( MachineIdTests ) From 3e2908ea166e3726e1cdd5bd0e961413ab2f5f38 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 20:31:15 +0100 Subject: [PATCH 067/119] [machineid] Follow Manjaro flags - add -f to ln(1) flags --- src/modules/machineid/Workers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/machineid/Workers.cpp b/src/modules/machineid/Workers.cpp index f1f7bb369..39acdfbf2 100644 --- a/src/modules/machineid/Workers.cpp +++ b/src/modules/machineid/Workers.cpp @@ -181,7 +181,7 @@ Calamares::JobResult createDBusLink( const QString& rootMountPoint, const QString& fileName, const QString& systemdFileName ) { Q_UNUSED( rootMountPoint ) - return runCmd( QStringList { QStringLiteral( "ln" ), QStringLiteral( "-s" ), systemdFileName, fileName } ); + return runCmd( QStringList { QStringLiteral( "ln" ), QStringLiteral( "-sf" ), systemdFileName, fileName } ); } } // namespace MachineId From 229d09927e6cc5ae8129fb547ab53168b2d2ad78 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 10:54:18 +0100 Subject: [PATCH 068/119] Changes: for 2020, new fake Linux distro name --- src/branding/default/branding.desc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index f70715aea..af1d39ca4 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -69,11 +69,11 @@ windowPlacement: center strings: productName: "@{NAME}" shortProductName: Generic - version: 2017.8 LTS - shortVersion: 2017.8 - versionedName: Generic GNU/Linux 2017.8 LTS "Soapy Sousaphone" - shortVersionedName: Generic 2017.8 - bootloaderEntryName: Generic + version: 2020.2 LTS + shortVersion: 2020.2 + versionedName: Fancy GNU/Linux 2020.2 LTS "Turgid Tuba" + shortVersionedName: FancyGL 2020.2 + bootloaderEntryName: FancyGL productUrl: https://calamares.io/ supportUrl: https://github.com/calamares/calamares/issues knownIssuesUrl: https://calamares.io/about/ From 12675be516880d6cc55285a6859edb66e83c10fa Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 21:25:55 +0100 Subject: [PATCH 069/119] [libcalamaresui] Factor out "simple" QML method calls --- src/libcalamaresui/CMakeLists.txt | 1 + src/libcalamaresui/utils/Qml.cpp | 52 +++++++++++++++++++ src/libcalamaresui/utils/Qml.h | 42 +++++++++++++++ .../viewpages/ExecutionViewStep.cpp | 32 +----------- 4 files changed, 97 insertions(+), 30 deletions(-) create mode 100644 src/libcalamaresui/utils/Qml.cpp create mode 100644 src/libcalamaresui/utils/Qml.h diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index 061a401bb..c603ca22d 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -16,6 +16,7 @@ set( calamaresui_SOURCES utils/CalamaresUtilsGui.cpp utils/ImageRegistry.cpp utils/Paste.cpp + utils/Qml.cpp viewpages/BlankViewStep.cpp viewpages/ExecutionViewStep.cpp diff --git a/src/libcalamaresui/utils/Qml.cpp b/src/libcalamaresui/utils/Qml.cpp new file mode 100644 index 000000000..1ea72e674 --- /dev/null +++ b/src/libcalamaresui/utils/Qml.cpp @@ -0,0 +1,52 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, 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 . + */ + +#include "Qml.h" + +#include "utils/Logger.h" + +#include +#include +#include +#include + +namespace CalamaresUtils +{ + +void +callQMLFunction( QQuickItem* qmlObject, const char* method ) +{ + QByteArray methodSignature( method ); + methodSignature.append( "()" ); + + if ( qmlObject && qmlObject->metaObject()->indexOfMethod( methodSignature ) >= 0 ) + { + QVariant returnValue; + QMetaObject::invokeMethod( qmlObject, method, Q_RETURN_ARG( QVariant, returnValue ) ); + if ( !returnValue.isNull() ) + { + cDebug() << "QML" << methodSignature << "returned" << returnValue; + } + } + else if ( qmlObject ) + { + cDebug() << "QML" << methodSignature << "is missing."; + } +} + +} // namespace CalamaresUtils diff --git a/src/libcalamaresui/utils/Qml.h b/src/libcalamaresui/utils/Qml.h new file mode 100644 index 000000000..70f59e7ec --- /dev/null +++ b/src/libcalamaresui/utils/Qml.h @@ -0,0 +1,42 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, 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_QML_H +#define UTILS_QML_H + +#include "DllMacro.h" + +class QQuickItem; + +namespace CalamaresUtils +{ + +/** @brief Calls the QML method @p method on @p qmlObject + * + * Pass in only the name of the method (e.g. onActivate). This function + * checks if the method exists (with no arguments) before trying to + * call it, so that no warnings are printed due to missing methods. + * + * If there is a return value from the QML method, it is logged (but not otherwise used). + */ +DLLEXPORT void +callQMLFunction( QQuickItem* qmlObject, const char* method ); + +} // namespace CalamaresUtils + +#endif diff --git a/src/libcalamaresui/viewpages/ExecutionViewStep.cpp b/src/libcalamaresui/viewpages/ExecutionViewStep.cpp index e0921910d..8ea918690 100644 --- a/src/libcalamaresui/viewpages/ExecutionViewStep.cpp +++ b/src/libcalamaresui/viewpages/ExecutionViewStep.cpp @@ -31,6 +31,7 @@ #include "utils/CalamaresUtilsGui.h" #include "utils/Dirs.h" #include "utils/Logger.h" +#include "utils/Qml.h" #include "utils/Retranslator.h" #include @@ -42,35 +43,6 @@ #include #include -/** @brief Calls the QML method @p method() - * - * Pass in only the name of the method (e.g. onActivate). This function - * checks if the method exists (with no arguments) before trying to - * call it, so that no warnings are printed due to missing methods. - * - * If there is a return value from the QML method, it is logged (but not otherwise used). - */ -static void -callQMLFunction( QQuickItem* qmlObject, const char* method ) -{ - QByteArray methodSignature( method ); - methodSignature.append( "()" ); - - if ( qmlObject && qmlObject->metaObject()->indexOfMethod( methodSignature ) >= 0 ) - { - QVariant returnValue; - QMetaObject::invokeMethod( qmlObject, method, Q_RETURN_ARG( QVariant, returnValue ) ); - if ( !returnValue.isNull() ) - { - cDebug() << "QML" << methodSignature << "returned" << returnValue; - } - } - else if ( qmlObject ) - { - cDebug() << "QML" << methodSignature << "is missing."; - } -} - namespace Calamares { @@ -205,7 +177,7 @@ changeSlideShowState( Slideshow state, QQuickItem* slideshow, QQuickWidget* widg if ( Branding::instance()->slideshowAPI() == 2 ) { // The QML was already loaded in the constructor, need to start it - callQMLFunction( slideshow, activate ? "onActivate" : "onLeave" ); + CalamaresUtils::callQMLFunction( slideshow, activate ? "onActivate" : "onLeave" ); } else if ( !Calamares::Branding::instance()->slideshowPath().isEmpty() ) { From 1f34c2834e7384aabf742016c9f913c680f7c6e1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 21:33:34 +0100 Subject: [PATCH 070/119] [libcalamaresui] Move definitions inside namespace {} - Remove the extra Calamares:: namespace specifier from half the definitions. --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 30 +++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index b009d1626..a7a157343 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -23,6 +23,7 @@ #include "utils/Dirs.h" #include "utils/Logger.h" #include "utils/NamedEnum.h" +#include "utils/Qml.h" #include "utils/Variant.h" #include "widgets/WaitingWidget.h" @@ -80,57 +81,56 @@ QmlViewStep::prettyName() const } -} // namespace Calamares bool -Calamares::QmlViewStep::isAtBeginning() const +QmlViewStep::isAtBeginning() const { return true; } bool -Calamares::QmlViewStep::isAtEnd() const +QmlViewStep::isAtEnd() const { return true; } bool -Calamares::QmlViewStep::isBackEnabled() const +QmlViewStep::isBackEnabled() const { return true; } bool -Calamares::QmlViewStep::isNextEnabled() const +QmlViewStep::isNextEnabled() const { return true; } Calamares::JobList -Calamares::QmlViewStep::jobs() const +QmlViewStep::jobs() const { return JobList(); } void -Calamares::QmlViewStep::onActivate() +QmlViewStep::onActivate() { // TODO: call into QML } void -Calamares::QmlViewStep::onLeave() +QmlViewStep::onLeave() { // TODO: call into QML } QWidget* -Calamares::QmlViewStep::widget() +QmlViewStep::widget() { return m_widget; } void -Calamares::QmlViewStep::loadComplete() +QmlViewStep::loadComplete() { cDebug() << "QML component" << m_qmlFileName << m_qmlComponent->status(); if ( m_qmlComponent->status() == QQmlComponent::Error ) @@ -163,7 +163,7 @@ Calamares::QmlViewStep::loadComplete() } void -Calamares::QmlViewStep::showQml() +QmlViewStep::showQml() { if ( !m_qmlWidget || !m_qmlObject ) { @@ -190,7 +190,7 @@ Calamares::QmlViewStep::showQml() * is badly configured). */ QString -searchQmlFile( Calamares::QmlViewStep::QmlSearch method, const QString& configuredName, const QString& moduleName ) +searchQmlFile( QmlViewStep::QmlSearch method, const QString& configuredName, const QString& moduleName ) { using QmlSearch = Calamares::QmlViewStep::QmlSearch; @@ -235,7 +235,7 @@ searchQmlFile( Calamares::QmlViewStep::QmlSearch method, const QString& configur } void -Calamares::QmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) +QmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { bool ok = false; m_searchMethod = searchNames().find( CalamaresUtils::getString( configurationMap, "search" ), ok ); @@ -270,8 +270,10 @@ Calamares::QmlViewStep::setConfigurationMap( const QVariantMap& configurationMap } void -Calamares::QmlViewStep::showFailedQml() +QmlViewStep::showFailedQml() { cWarning() << "QmlViewStep" << moduleInstanceKey() << "loading failed."; m_spinner->setText( prettyName() + ' ' + tr( "Loading failed." ) ); } + +} // namespace Calamares From 39a54539047666fe337b1aac16b891e06f70d811 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 22:18:23 +0100 Subject: [PATCH 071/119] [libcalamaresui] Add QML onActivate() and onLeave() calls. - This comes from the ExecutionViewStep, V2 loading, which notifies the QML that the QML is now active. --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 49 ++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index a7a157343..2bfc72757 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -19,6 +19,7 @@ #include "QmlViewStep.h" #include "Branding.h" +#include "ViewManager.h" #include "utils/Dirs.h" #include "utils/Logger.h" @@ -51,6 +52,36 @@ searchNames() return names; } +/// @brief State-change of the QML, for changeQMLState() +enum class QMLAction +{ + Start, + Stop +}; + +/** @brief Tells the QML we activated or left it. + * + * If @p action is @c QMLAction::Start, calls onActivate in the QML. + * If @p action is @c QMLAction::Stop, calls onLeave in the QML. + * + * Sets *activatedInCalamares* property on the QML as well (to true + * if @p action is @c QMLAction::Start, false otherwise). + */ +static void +changeQMLState( QMLAction action, QQuickItem* item ) +{ + static const char propertyName[] = "activatedInCalamares"; + + bool activate = action == QMLAction::Start; + CalamaresUtils::callQMLFunction( item, activate ? "onActivate" : "onLeave" ); + + auto property = item->property( propertyName ); + if ( property.isValid() && ( property.type() == QVariant::Bool ) && ( property.toBool() != activate ) ) + { + item->setProperty( propertyName, activate ); + } +} + namespace Calamares { @@ -81,7 +112,6 @@ QmlViewStep::prettyName() const } - bool QmlViewStep::isAtBeginning() const { @@ -114,13 +144,19 @@ QmlViewStep::jobs() const void QmlViewStep::onActivate() { - // TODO: call into QML + if ( m_qmlObject ) + { + changeQMLState( QMLAction::Start, m_qmlObject ); + } } void QmlViewStep::onLeave() { - // TODO: call into QML + if ( m_qmlObject ) + { + changeQMLState( QMLAction::Stop, m_qmlObject ); + } } QWidget* @@ -181,6 +217,13 @@ QmlViewStep::showQml() { cDebug() << "showQml() called twice"; } + + if ( ViewManager::instance()->currentStep() == this ) + { + // We're alreay visible! Must have been slow QML loading, and we + // passed onActivate already. + changeQMLState( QMLAction::Start, m_qmlObject ); + } } From 39ef67183620bfad013024d37786dd83512819e2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 7 Feb 2020 22:25:51 +0100 Subject: [PATCH 072/119] Changes: mention QML bits --- CHANGES | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGES b/CHANGES index 1f1d37f61..ce161f396 100644 --- a/CHANGES +++ b/CHANGES @@ -17,10 +17,18 @@ This release contains contributions from (alphabetically by first name): translations without requiring a recompile: helpful for translators and possibly for distributions with their own translation style. See the translators and deployers wiki for details. + - A new `ViewStep` base class, `QmlViewStep`, has been added that loads + a configurable QML file and plays it. This is used by the new *notesqml* + module -- which is in itself a minimal wrapper around the same that + adds only a translatable module name. ## Modules ## - The *machineid* and *users* modules now prefer high-quality random data from `/dev/urandom` rather than pseudo-random data. #1254 + - A new *notesqml* module supports loading QML. This can be used for + "fancy" release notes as a QML application, rather than a webview + or text widget. Note that this does not replace the slideshow-during- + installation module. # 3.2.18 (2020-01-28) # From 830cc1b4d28b46ab1c8ee933a63443b4e23d12ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20M=C3=BCller?= Date: Sat, 8 Feb 2020 12:56:30 +0100 Subject: [PATCH 073/119] [initcpiocfg] add bootsplash hook support --- src/modules/initcpiocfg/main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/modules/initcpiocfg/main.py b/src/modules/initcpiocfg/main.py index 6147a508a..1a46c630d 100644 --- a/src/modules/initcpiocfg/main.py +++ b/src/modules/initcpiocfg/main.py @@ -4,7 +4,7 @@ # === This file is part of Calamares - === # # Copyright 2014, Rohan Garg -# Copyright 2015,2019, Philip Müller +# Copyright 2015,2019,2020, Philip Müller # Copyright 2017, Alf Gaida # Copyright 2019, Adriaan de Groot # @@ -136,6 +136,12 @@ def modify_mkinitcpio_conf(partitions, root_mount_point): if detect_plymouth(): hooks.append("plymouth") + # Detect bootsplash theme and enable hook + bootsplash_folder = os.path.join(root_mount_point, "usr/lib/firmware/bootsplash-themes") + if os.path.exists(bootsplash_folder): + bootsplash_theme = os.listdir(bootsplash_folder) + hooks.append("bootsplash-{!s}".format(bootsplash_theme)) + for partition in partitions: if partition["fs"] == "linuxswap": swap_uuid = partition["uuid"] From 7477a4da8e32cb869c52d4d59435a2a0380ea784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20M=C3=BCller?= Date: Sat, 8 Feb 2020 13:06:51 +0100 Subject: [PATCH 074/119] [initcpiocfg] bootsplash: add hook for each theme --- src/modules/initcpiocfg/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/initcpiocfg/main.py b/src/modules/initcpiocfg/main.py index 1a46c630d..ba1d962bb 100644 --- a/src/modules/initcpiocfg/main.py +++ b/src/modules/initcpiocfg/main.py @@ -139,8 +139,9 @@ def modify_mkinitcpio_conf(partitions, root_mount_point): # Detect bootsplash theme and enable hook bootsplash_folder = os.path.join(root_mount_point, "usr/lib/firmware/bootsplash-themes") if os.path.exists(bootsplash_folder): - bootsplash_theme = os.listdir(bootsplash_folder) - hooks.append("bootsplash-{!s}".format(bootsplash_theme)) + bootsplash_themes = os.listdir(bootsplash_folder) + for bootsplash_theme in bootsplash_themes: + hooks.append("bootsplash-{!s}".format(bootsplash_theme)) for partition in partitions: if partition["fs"] == "linuxswap": From c0e1ebb72a2fe3ccaff1cc7e74ec840b2beca88a Mon Sep 17 00:00:00 2001 From: demmm Date: Sun, 9 Feb 2020 01:03:52 +0100 Subject: [PATCH 075/119] adding notesqml, copy of dummyqml included in settings.conf, commented out --- settings.conf | 1 + src/modules/notesqml/CMakeLists.txt | 11 ++++ src/modules/notesqml/NotesQmlViewStep.cpp | 52 ++++++++++++++++ src/modules/notesqml/NotesQmlViewStep.h | 48 +++++++++++++++ src/modules/notesqml/notesqml.conf | 25 ++++++++ src/modules/notesqml/notesqml.qml | 74 +++++++++++++++++++++++ src/modules/notesqml/notesqml.qrc | 5 ++ 7 files changed, 216 insertions(+) create mode 100644 src/modules/notesqml/CMakeLists.txt create mode 100644 src/modules/notesqml/NotesQmlViewStep.cpp create mode 100644 src/modules/notesqml/NotesQmlViewStep.h create mode 100644 src/modules/notesqml/notesqml.conf create mode 100644 src/modules/notesqml/notesqml.qml create mode 100644 src/modules/notesqml/notesqml.qrc diff --git a/settings.conf b/settings.conf index 1c7b773ff..875af11ad 100644 --- a/settings.conf +++ b/settings.conf @@ -87,6 +87,7 @@ modules-search: [ local ] sequence: - show: - welcome +# - notesqml # - dummypythonqt - locale - keyboard diff --git a/src/modules/notesqml/CMakeLists.txt b/src/modules/notesqml/CMakeLists.txt new file mode 100644 index 000000000..6aedab5aa --- /dev/null +++ b/src/modules/notesqml/CMakeLists.txt @@ -0,0 +1,11 @@ +calamares_add_plugin( notesqml + TYPE viewmodule + EXPORT_MACRO PLUGINDLLEXPORT_PRO + SOURCES + NotesQmlViewStep.cpp + RESOURCES + notesqml.qrc + LINK_PRIVATE_LIBRARIES + calamaresui + SHARED_LIB +) diff --git a/src/modules/notesqml/NotesQmlViewStep.cpp b/src/modules/notesqml/NotesQmlViewStep.cpp new file mode 100644 index 000000000..e729c2df7 --- /dev/null +++ b/src/modules/notesqml/NotesQmlViewStep.cpp @@ -0,0 +1,52 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, Adriaan de Groot + * Copyright 2020, Anke Boersma + * + * 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 "NotesQmlViewStep.h" + +#include + +NotesQmlViewStep::NotesQmlViewStep( QObject* parent ) + : Calamares::QmlViewStep( "notesqml", parent ) +{ +} + +NotesQmlViewStep::~NotesQmlViewStep() {} + +QString +NotesQmlViewStep::prettyName() const +{ + return m_notesName ? m_notesName->get() : tr( "Notes" ); +} + +void +NotesQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) +{ + Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation + + bool qmlLabel_ok = false; + auto qmlLabel = CalamaresUtils::getSubMap( configurationMap, "qmlLabel", qmlLabel_ok ); + + if ( qmlLabel.contains( "notes" ) ) + { + m_notesName = new CalamaresUtils::Locale::TranslatedString( qmlLabel, "notes" ); + } + +} + +CALAMARES_PLUGIN_FACTORY_DEFINITION( NotesQmlViewStepFactory, registerPlugin< NotesQmlViewStep >(); ) diff --git a/src/modules/notesqml/NotesQmlViewStep.h b/src/modules/notesqml/NotesQmlViewStep.h new file mode 100644 index 000000000..445b34c81 --- /dev/null +++ b/src/modules/notesqml/NotesQmlViewStep.h @@ -0,0 +1,48 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, Adriaan de Groot + * Copyright 2020, Anke Boersma + * + * 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 NOTESQMLVIEWSTEP_H +#define NOTESQMLVIEWSTEP_H + +#include "PluginDllMacro.h" +#include "locale/TranslatableConfiguration.h" +#include "utils/CalamaresUtilsSystem.h" +#include "utils/Variant.h" +#include "utils/PluginFactory.h" +#include "viewpages/QmlViewStep.h" + +class PLUGINDLLEXPORT NotesQmlViewStep : public Calamares::QmlViewStep +{ + Q_OBJECT + +public: + NotesQmlViewStep( QObject* parent = nullptr ); + virtual ~NotesQmlViewStep() override; + + QString prettyName() const override; + + void setConfigurationMap( const QVariantMap& configurationMap ) override; + +private: + CalamaresUtils::Locale::TranslatedString* m_notesName; // As it appears in the sidebar +}; + +CALAMARES_PLUGIN_FACTORY_DECLARATION( NotesQmlViewStepFactory ) + +#endif diff --git a/src/modules/notesqml/notesqml.conf b/src/modules/notesqml/notesqml.conf new file mode 100644 index 000000000..1dcc25cff --- /dev/null +++ b/src/modules/notesqml/notesqml.conf @@ -0,0 +1,25 @@ +# QML modules can search for the QML inside the Qt resources +# (QRC) which are compiled into the module, or in the branding +# setup for Calamares, (or both of them, with branding taking +# precedence). This allows the module to ship a default UI and +# branding to optionally introduce a replacement file. +# +# Generally, leave the search method set to "both" because if +# you don't want to brand the UI, just don't ship a branding +# QML file for it. +# +# To support instanced QML modules, searches in the branding +# directory look for the full module@instanceid name as well. +--- +# Search mode. Valid values are "both", "qrc" and "branding" +search: both + +# Name of the QML file. If not set, uses the name of the instance +# of the module (e.g. if you list this module in `settings.conf` +# in the *instances* section, you get *id*, otherwise it would +# normally be "notesqml"). +#filename: notesqml + +qmlLabel: + notes: "Release Notes" + notes[nl]: "Opmerkingen" diff --git a/src/modules/notesqml/notesqml.qml b/src/modules/notesqml/notesqml.qml new file mode 100644 index 000000000..0a60fd741 --- /dev/null +++ b/src/modules/notesqml/notesqml.qml @@ -0,0 +1,74 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, Anke Boersma + * + * 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 . + */ + +import QtQuick 2.7 +import QtQuick.Controls 2.2 +import QtQuick.Window 2.2 +import QtQuick.Layouts 1.3 +import QtQuick.Controls.Material 2.1 + +Item { + width: 740 + height: 420 + + Flickable { + id: flick + anchors.fill: parent + contentHeight: 800 + + ScrollBar.vertical: ScrollBar { + width: 10 + policy: ScrollBar.AlwaysOn + } + + TextArea { + id: intro + x: 1 + y: 0 + width: 720 + font.pointSize: 14 + textFormat: Text.RichText + antialiasing: true + activeFocusOnPress: false + wrapMode: Text.WordWrap + + text: qsTr("

Generic GNU/Linux 2020.2 LTS Turgid Tuba

+

This an example QML file, showing options in RichText with Flickable content.

+ +

QML with RichText can use HTML tags, Flickable content is useful for touchscreens.

+ +

This is bold text

+

This is italic text

+

This is underlined text

+

This text will be center-aligned.

+

This is strikethrough

+ +

Code example: + ls -l /home

+ +

Lists:

+
    +
  • Intel CPU systems
  • +
  • AMD CPU systems
  • +
+ +

The vertical scrollbar is adjustable, current width set to 10.

") + + } + } +} diff --git a/src/modules/notesqml/notesqml.qrc b/src/modules/notesqml/notesqml.qrc new file mode 100644 index 000000000..a4aa1909f --- /dev/null +++ b/src/modules/notesqml/notesqml.qrc @@ -0,0 +1,5 @@ + + + notesqml.qml + + From f75a1e1c9aae4fd9767a577478983bd4f4dc86bc Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 10 Feb 2020 11:06:55 +0100 Subject: [PATCH 076/119] Changes: remove obsolete badge --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index e2e87fddf..4a5610dc9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ --------- [![GitHub release](https://img.shields.io/github/release/calamares/calamares.svg)](https://github.com/calamares/calamares/releases) -[![Build Status](https://calamares.io/ci/buildStatus/icon?job=calamares-post_commit)](https://calamares.io/ci/job/calamares-post_commit/) [![Travis Build Status](https://travis-ci.org/calamares/calamares.svg?branch=master)](https://travis-ci.org/calamares/calamares) [![Coverity Scan Build Status](https://scan.coverity.com/projects/5389/badge.svg)](https://scan.coverity.com/projects/5389) [![GitHub license](https://img.shields.io/github/license/calamares/calamares.svg)](https://github.com/calamares/calamares/blob/master/LICENSE) From 0dde233c51d74fc3b59c534082fdb92d30f193a3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 10 Feb 2020 11:41:38 +0100 Subject: [PATCH 077/119] Docs: move HACKING to the wiki --- ci/HACKING.md | 212 +------------------------------------------------- 1 file changed, 1 insertion(+), 211 deletions(-) diff --git a/ci/HACKING.md b/ci/HACKING.md index 02eb8fd17..f1c8b750b 100644 --- a/ci/HACKING.md +++ b/ci/HACKING.md @@ -1,211 +1 @@ -Hacking on Calamares -==================== - -These are the guidelines for hacking on Calamares. Except for the licensing, -which **must** be GPLv3+, these are guidelines and -- like PEP8 -- the most -important thing is to know when you can ignore them. - - -Licensing ---------- -Calamares is released under the terms of the GNU GPL, version 3 or later. -Every source file must have a license header, with a list of copyright holders and years. - -Example: -``` -/* === This file is part of Calamares - === - * - * Copyright 2013-2014, Random Person - * Copyright 2010, Someone Else - * - * 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 . - */ -``` -Copyright holders must be physical or legal personalities. A statement such as -`Copyright 2014, The FooBarQuux project` has no legal value if "The FooBarQuux -project" is not the legal name of a person, company, incorporated -organization, etc. - -Please add your name to files you touch when making any contribution (even if -it's just a typo-fix which might not be copyrightable in all jurisdictions). - - -Formatting C++ --------------- -This formatting guide applies to C++ code only; for Python modules, we use -[pycodestyle](https://github.com/PyCQA/pycodestyle) to apply a check of -some PEP8 guidelines. - -* Spaces, not tabs. -* Indentation is 4 spaces. -* Lines should be limited to 90 characters. -* Spaces between brackets and argument functions, including for template arguments -* No space before brackets, except for keywords, for example `function( argument )` but - `if ( condition )`. -* For pointer and reference variable declarations, put a space before the variable name - and no space between the type and the `*` or `&`, e.g. `int* p`. -* `for`, `if`, `else`, `while` and similar statements put the braces on the next line, - if the following block is more than one statement. Always use braces. -* Function and class definitions have their braces on separate lines. -* A function implementation's return type is on its own line. -* `CamelCase.{cpp,h}` style file names. -* Lambdas are preferrably indented to a 4-space tab, even when passed as an - argument to functions. - -Example: -``` -bool -MyClass::myMethod( QStringList list, const QString& name ) -{ - if ( list.isEmpty() ) - return false; - - cDebug() << "Items in list .."; - foreach ( const QString& string, list ) - cDebug() << " .." << string; - - switch ( m_enumValue ) - { - case Something: - return true; - case SomethingElse: - doSomething(); - break; - } -} -``` - -You can use `clang-format` (version 7) to have Calamares sources formatted -the right way. There is a `.clang-format` file that specifies the details. -In general: -``` - $ clang-format-7 -i -style=file -``` -` - -**NOTE:** An .editorconfig file is included to assist with formatting. In -order to take advantage of this functionality you will need to acquire the -[EditorConfig](http://editorconfig.org/#download) plug-in for your editor. - - -Naming ------- -* Use CamelCase for everything. -* Local variables should start out with a lowercase letter. -* Class names are capitalized -* Prefix class member variables with `m_`, e.g. `m_queue`. -* Prefix static member variables with `s_`, e.g. `s_instance`. -* Functions are named in the Qt style, like Java's, without the 'get' prefix. - * A getter is `variable()`. - * If it's a getter for a boolean, prefix with 'is', so `isCondition()`. - * A setter is `setVariable( arg )`. - - -Includes --------- -Header includes should be listed in the following order: - -* own header, -* Calamares includes, -* includes for Qt-based libraries, -* Qt includes, -* other includes. - -They should also be sorted alphabetically for ease of locating them. - -Includes in a header file should be kept to the absolute minimum, as to keep -compile times short. This can be achieved by using forward declarations -instead of includes, like `class QListView;`. - -Example: -``` -#include "Settings.h" - -#include "CalamaresApplication.h" -#include "utils/CalamaresUtils.h" -#include "utils/Logger.h" -#include "YamlUtils.h" - -#include -#include - -#include -``` - -Use include guards, not `#pragma once`. - - -C++ tips --------- -All C++11 features are acceptable, and the use of new C++11 features is encouraged when -it makes the code easier to understand and more maintainable. - -The use of `nullptr` is preferred over the use of `0` or `NULL`. - -For Qt containers it is better to use Qt's own `foreach`. For all other containers, the -range-based `for` syntax introduced with C++11 is preferred ([see this blog post][1]). - -When re-implementing a virtual method, always add the `override` keyword. - -Try to keep your code const correct. Declare methods const if they don't mutate the -object, and use const variables. It improves safety, and also makes it easier to -understand the code. - -For the Qt signal-slot system, the new (Qt5) syntax is to be preferred because it allows -the compiler to check for the existence of signals and slots. As an added benefit, the -new syntax can also be used with `tr1::bind` and C++11 lambdas. For more information, see -the [Qt wiki][2]. - -Example: -``` -connect( m_next, &QPushButton::clicked, this, &ViewManager::next ); - -connect( m_moduleManager, &Calamares::ModuleManager::modulesLoaded, [this] -{ - m_mainwindow->show(); -}); -``` - -[1]: http://blog.qt.digia.com/blog/2011/05/26/cpp0x-in-qt/ -[2]: http://qt-project.org/wiki/New_Signal_Slot_Syntax - - -Debugging ---------- -Use `cDebug()` from `utils/Logger.h`. You can pass a debug-level to the -macro (6 is debugging, higher is less important). Use `cWarning()` for warning -messages (equivalent to level 2) and `cError()` for errors (level 1). Warnings -and errors will add relevant text automatically. See `libcalamares/utils/Logger.h` -for details. - -For log messages that are continued across multiple calls to `cDebug()`, -in particular listing things, conventional formatting is as follows: -* End the first debug message with ` ..` -* Start the next debug message by outputting `Logger::SubEntry` - -For single-outputs that need to be split across multiplt lines, -output `Logger::Continuation`. - - -Commit Messages ---------------- -Keep commit messages short(-ish) and try to describe what is being changed -*as well as why*. Use the commit keywords for GitHub, especially *FIXES:* -to auto-close issues when they are resolved. - -For functional changes to Calamares modules or libraries, try to put -*[modulename]* in front of the first line of the commit message. - -For non-functional changes to infrastructure, try to label the change -with the kind of change, e.g. *CMake* or *i18n* or *Documentation*. +This has moved [to the wiki](https://github.com/calamares/calamares/wiki/Develop-Code). From cc17898da8f67bfd97f3a95ae1e7fddc2524f9d8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 10 Feb 2020 11:56:24 +0100 Subject: [PATCH 078/119] Docs: remove references to HACKING.md (moved to wiki) --- README.md | 2 +- ci/RELEASE.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a5610dc9..7b12532e5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Coverity Scan Build Status](https://scan.coverity.com/projects/5389/badge.svg)](https://scan.coverity.com/projects/5389) [![GitHub license](https://img.shields.io/github/license/calamares/calamares.svg)](https://github.com/calamares/calamares/blob/master/LICENSE) -| [Report a Bug](https://github.com/calamares/calamares/issues/new) | [Contribute](https://github.com/calamares/calamares/blob/master/ci/HACKING.md) | [Translate](https://www.transifex.com/projects/p/calamares/) | Freenode (IRC): #calamares | [Wiki](https://github.com/calamares/calamares/wiki) | +| [Report a Bug](https://github.com/calamares/calamares/issues/new) | [Translate](https://www.transifex.com/projects/p/calamares/) | [Contribute](https://github.com/calamares/calamares/wiki/Develop-Guide) | Freenode (IRC): #calamares | [Wiki](https://github.com/calamares/calamares/wiki) | |:-----------------------------------------:|:----------------------:|:-----------------------:|:--------------------------:|:--------------------------:| ### Dependencies diff --git a/ci/RELEASE.md b/ci/RELEASE.md index 3198ee95d..0da086585 100644 --- a/ci/RELEASE.md +++ b/ci/RELEASE.md @@ -37,7 +37,7 @@ The Calamares release process * Bump version in `CMakeLists.txt`, *CALAMARES_VERSION* variables, and set RC to a non-zero value (e.g. doing -rc1, -rc2, ...). Push that. -* Check `README.md` and everything `ci/HACKING.md`, make sure it's all still +* Check `README.md` and the [Coding Guide](https://github.com/calamares/calamares/wiki/Develop-Code), make sure it's all still relevant. Run `ci/calamaresstyle` to check the C++ code style. Run pycodestyle on recently-modified Python modules, fix what makes sense. * Check defaults in `settings.conf` and other configuration files. From 04e608d164695a9e367d663d32e5a183c203ac39 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 10 Feb 2020 15:28:33 +0100 Subject: [PATCH 079/119] Docs: remove example dummypythonqml from settings.conf - PythonQt is going to go away (eventually), don't encourage it. --- settings.conf | 2 -- 1 file changed, 2 deletions(-) diff --git a/settings.conf b/settings.conf index 875af11ad..c2aa48a37 100644 --- a/settings.conf +++ b/settings.conf @@ -88,7 +88,6 @@ sequence: - show: - welcome # - notesqml -# - dummypythonqt - locale - keyboard - partition @@ -99,7 +98,6 @@ sequence: # - dummycpp # - dummyprocess # - dummypython -# - dummypythonqt - partition - mount - unpackfs From 4f60a6340e2ab5e1b3897f997bb6f9ac6c0ef39d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 12:20:39 +0100 Subject: [PATCH 080/119] [dummyqml] Drop module; it makes more sense to just be notesqml --- src/modules/dummyqml/CMakeLists.txt | 11 ---- src/modules/dummyqml/DummyQmlViewStep.cpp | 52 ------------------- src/modules/dummyqml/DummyQmlViewStep.h | 48 ----------------- src/modules/dummyqml/dummyqml.conf | 29 ----------- src/modules/dummyqml/dummyqml.qrc | 5 -- .../examples}/dummyqml.qml | 0 6 files changed, 145 deletions(-) delete mode 100644 src/modules/dummyqml/CMakeLists.txt delete mode 100644 src/modules/dummyqml/DummyQmlViewStep.cpp delete mode 100644 src/modules/dummyqml/DummyQmlViewStep.h delete mode 100644 src/modules/dummyqml/dummyqml.conf delete mode 100644 src/modules/dummyqml/dummyqml.qrc rename src/modules/{dummyqml => notesqml/examples}/dummyqml.qml (100%) diff --git a/src/modules/dummyqml/CMakeLists.txt b/src/modules/dummyqml/CMakeLists.txt deleted file mode 100644 index 9a7532e9e..000000000 --- a/src/modules/dummyqml/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -calamares_add_plugin( dummyqml - TYPE viewmodule - EXPORT_MACRO PLUGINDLLEXPORT_PRO - SOURCES - DummyQmlViewStep.cpp - RESOURCES - dummyqml.qrc - LINK_PRIVATE_LIBRARIES - calamaresui - SHARED_LIB -) diff --git a/src/modules/dummyqml/DummyQmlViewStep.cpp b/src/modules/dummyqml/DummyQmlViewStep.cpp deleted file mode 100644 index 030779f7f..000000000 --- a/src/modules/dummyqml/DummyQmlViewStep.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2020, Adriaan de Groot - * Copyright 2020, Anke Boersma - * - * 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 "DummyQmlViewStep.h" - -#include - -DummyQmlViewStep::DummyQmlViewStep( QObject* parent ) - : Calamares::QmlViewStep( "dummyqml", parent ) -{ -} - -DummyQmlViewStep::~DummyQmlViewStep() {} - -QString -DummyQmlViewStep::prettyName() const -{ - return m_notesName ? m_notesName->get() : tr( "Notes" ); -} - -void -DummyQmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) -{ - Calamares::QmlViewStep::setConfigurationMap( configurationMap ); // call parent implementation - - bool qmlLabel_ok = false; - auto qmlLabel = CalamaresUtils::getSubMap( configurationMap, "qmlLabel", qmlLabel_ok ); - - if ( qmlLabel.contains( "notes" ) ) - { - m_notesName = new CalamaresUtils::Locale::TranslatedString( qmlLabel, "notes" ); - } - -} - -CALAMARES_PLUGIN_FACTORY_DEFINITION( DummyQmlViewStepFactory, registerPlugin< DummyQmlViewStep >(); ) diff --git a/src/modules/dummyqml/DummyQmlViewStep.h b/src/modules/dummyqml/DummyQmlViewStep.h deleted file mode 100644 index cf49436b0..000000000 --- a/src/modules/dummyqml/DummyQmlViewStep.h +++ /dev/null @@ -1,48 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2020, Adriaan de Groot - * Copyright 2020, Anke Boersma - * - * 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 DUMMYQMLVIEWSTEP_H -#define DUMMYQMLVIEWSTEP_H - -#include "PluginDllMacro.h" -#include "locale/TranslatableConfiguration.h" -#include "utils/CalamaresUtilsSystem.h" -#include "utils/Variant.h" -#include "utils/PluginFactory.h" -#include "viewpages/QmlViewStep.h" - -class PLUGINDLLEXPORT DummyQmlViewStep : public Calamares::QmlViewStep -{ - Q_OBJECT - -public: - DummyQmlViewStep( QObject* parent = nullptr ); - virtual ~DummyQmlViewStep() override; - - QString prettyName() const override; - - void setConfigurationMap( const QVariantMap& configurationMap ) override; - -private: - CalamaresUtils::Locale::TranslatedString* m_notesName; // As it appears in the sidebar -}; - -CALAMARES_PLUGIN_FACTORY_DECLARATION( DummyQmlViewStepFactory ) - -#endif diff --git a/src/modules/dummyqml/dummyqml.conf b/src/modules/dummyqml/dummyqml.conf deleted file mode 100644 index 9e7a83fdd..000000000 --- a/src/modules/dummyqml/dummyqml.conf +++ /dev/null @@ -1,29 +0,0 @@ -# The dummy QML module just displays a QML page. It doesn't -# have much in the way of own configuration, only where -# the QML file is searched. -# -# QML modules can search for the QML inside the Qt resources -# (QRC) which are compiled into the module, or in the branding -# setup for Calamares, (or both of them, with branding taking -# precedence). This allows the module to ship a default UI and -# branding to optionally introduce a replacement file. -# -# Generally, leave the search method set to "both" because if -# you don't want to brand the UI, just don't ship a branding -# QML file for it. -# -# To support instanced QML modules, searches in the branding -# directory look for the full module@instanceid name as well. ---- -# Search mode. Valid values are "both", "qrc" and "branding" -search: both - -# Name of the QML file. If not set, uses the name of the instance -# of the module (e.g. if you list this module in `settings.conf` -# in the *instances* section, you get *id*, otherwise it would -# normally be "dummyqml"). -# filename: dummyqml - -qmlLabel: - notes: "Release Notes" - notes[nl]: "Opmerkingen" diff --git a/src/modules/dummyqml/dummyqml.qrc b/src/modules/dummyqml/dummyqml.qrc deleted file mode 100644 index 85b1da5ca..000000000 --- a/src/modules/dummyqml/dummyqml.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - dummyqml.qml - - diff --git a/src/modules/dummyqml/dummyqml.qml b/src/modules/notesqml/examples/dummyqml.qml similarity index 100% rename from src/modules/dummyqml/dummyqml.qml rename to src/modules/notesqml/examples/dummyqml.qml From c3c845e9d7e334ca60cbdc3c64e819f31e22ca46 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 12:29:18 +0100 Subject: [PATCH 081/119] [notesqml] Add some more module documentation --- src/modules/notesqml/notesqml.conf | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/notesqml/notesqml.conf b/src/modules/notesqml/notesqml.conf index 1dcc25cff..1afd9e682 100644 --- a/src/modules/notesqml/notesqml.conf +++ b/src/modules/notesqml/notesqml.conf @@ -1,3 +1,15 @@ +# The *notesqml* module can be used to display a QML file +# as an installer step. This is most useful for release-notes +# and similar somewhat-static content, but if you want to you +# can put SameGame in there as well. +# +# While the module compiles a QML file into a QRC for inclusion +# into the shared library, normal use will configure it with +# an external file, either from Calamares AppData directory or +# from the branding directory. +# +# --- +# # QML modules can search for the QML inside the Qt resources # (QRC) which are compiled into the module, or in the branding # setup for Calamares, (or both of them, with branding taking @@ -9,7 +21,7 @@ # QML file for it. # # To support instanced QML modules, searches in the branding -# directory look for the full module@instanceid name as well. +# directory look for the full notesqml@instanceid name as well. --- # Search mode. Valid values are "both", "qrc" and "branding" search: both @@ -20,6 +32,9 @@ search: both # normally be "notesqml"). #filename: notesqml +# This is the name of the module in the progress-tree / sidebar +# in Calamares. To support multiple instances of the QML module, +# the name is configurable and translatable here. qmlLabel: notes: "Release Notes" notes[nl]: "Opmerkingen" From 6c0fecd40d7c52dd02be1b9a41af19444407c922 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 12:55:26 +0100 Subject: [PATCH 082/119] [notesqml] Don't use a fixed width --- src/modules/notesqml/notesqml.qml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/notesqml/notesqml.qml b/src/modules/notesqml/notesqml.qml index 0a60fd741..d1ff4f1b5 100644 --- a/src/modules/notesqml/notesqml.qml +++ b/src/modules/notesqml/notesqml.qml @@ -32,6 +32,7 @@ Item { contentHeight: 800 ScrollBar.vertical: ScrollBar { + id: fscrollbar width: 10 policy: ScrollBar.AlwaysOn } @@ -40,7 +41,7 @@ Item { id: intro x: 1 y: 0 - width: 720 + width: parent.width - fscrollbar.width font.pointSize: 14 textFormat: Text.RichText antialiasing: true From dd33cbfa360e556ab0cd625f8760611d8ba363a3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 12:55:53 +0100 Subject: [PATCH 083/119] Docs: update RELEASE.md procedure --- ci/RELEASE.md | 108 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 73 insertions(+), 35 deletions(-) diff --git a/ci/RELEASE.md b/ci/RELEASE.md index 0da086585..5293abf6b 100644 --- a/ci/RELEASE.md +++ b/ci/RELEASE.md @@ -1,17 +1,16 @@ -The Calamares release process -============================= +# Calamares Release Process -> As releases from *master* are now rolling when-they-are-ready releases, -> some of these steps no longer are followed. In particular, -RC releases -> are not done anymore (although the RC variable is set in `CMakeLists.txt` -> to avoid accidents) and most things are automated through the release -> script [RELEASE.sh](RELEASE.sh) +> Calamares releases are now rolling when-they-are-ready releases. +> Releases are made from *master* and tagged there. When, in future, +> LTS releases resume, these steps may be edited again. +> +> Most things are automated through the release script [RELEASE.sh](RELEASE.sh) -#### (0) A week in advance +## (0) A week in advance -* (Only releases from master) - Run [Coverity scan][coverity], fix what's relevant. The Coverity scan runs - automatically once a week on master. +* Run [Coverity scan][coverity], fix what's relevant. The Coverity scan runs + automatically once a week on master. The badge is displayed on the + project front page and in the wiki. * Build with clang -Weverything, fix what's relevant. ``` rm -rf build ; mkdir build ; cd build @@ -26,34 +25,69 @@ The Calamares release process an additional environment variable to be set for some tests, which will destroy an attached disk. This is not always desirable. There are some sample config-files that are empty and which fail the config-tests. -* (Only releases from master) - Notify [translators][transifex]. In the dashboard there is an *Announcements* - link that you can use to send a translation announcement. +* Notify [translators][transifex]. In the dashboard there is an *Announcements* + link that you can use to send a translation announcement. Note that regular + use of `txpush.sh` will notify translators as well of any changes. [coverity]: https://scan.coverity.com/projects/calamares-calamares?tab=overview [transifex]: https://www.transifex.com/calamares/calamares/dashboard/ -#### (1) Preparation -* Bump version in `CMakeLists.txt`, *CALAMARES_VERSION* variables, and set - RC to a non-zero value (e.g. doing -rc1, -rc2, ...). Push that. -* Check `README.md` and the [Coding Guide](https://github.com/calamares/calamares/wiki/Develop-Code), make sure it's all still - relevant. Run `ci/calamaresstyle` to check the C++ code style. - Run pycodestyle on recently-modified Python modules, fix what makes sense. -* Check defaults in `settings.conf` and other configuration files. -* (Only releases from master) - Pull latest translations from Transifex. We only push / pull translations +## (1) Preparation + +* Pull latest translations from Transifex. We only push / pull translations from master, so longer-lived branches (e.g. 3.1.x) don't get translation - updates. This is to keep the translation workflow simple. + updates. This is to keep the translation workflow simple. The script + automatically commits changes to the translations. ``` sh ci/txpull.sh ``` -* (Only releases from master) - Update the list of enabled translation languages in `CMakeLists.txt`. +* Update the list of enabled translation languages in `CMakeLists.txt`. Check the [translation site][transifex] for the list of languages with - fairly complete translations. + fairly complete translations, or use `ci/txstats.py` for an automated + suggestion. If there are changes, commit them. +* Push the changes. +* Drop the RC variable to 0 in `CMakeLists.txt`, *CALAMARES_VERSION_RC*. +* Check `README.md` and the + [Coding Guide](https://github.com/calamares/calamares/wiki/Develop-Code), + make sure it's all still + relevant. Run `ci/calamaresstyle` to check the C++ code style. + Run pycodestyle on recently-modified Python modules, fix what makes sense. +* Check defaults in `settings.conf` and other configuration files. +* Edit `CHANGES` and set the date of the release. +* Commit both. This is usually done with commit-message + *Changes: pre-release housekeeping*. -#### (2) Tarball + +## (2) Release Day + +* Run the helper script `ci/RELEASE.sh` or follow steps below. + The script checks: + - for uncommitted local changes, + - if translations are up-to-date and translators + have had enough time to chase new strings, + - that the build is successful (with gcc and clang, if available), + - tests pass, + - tarball can be created, + - tarball can be signed. + On success, it prints out a suitable signature- and SHA256 blurb + for use in the release announcement. + +### (2.1) Buld and Test + +* Build with gcc. If available, build again with Clang and double-check + any warnings Clang produces. +* Run the tests; `make test` in the build directory should have no + failures (or if there are, know why they are there). + +### (2.2) Tag + +* `git tag -s v1.1.0` Make sure the signing key is known in GitHub, so that the + tag is shown as a verified tag. Do not sign -rc tags. + You can use `make show-version` in the build directory to get the right + version number -- this will fail if you didn't follow step (1). + +### (2.3) Tarball * Create tarball: `git-archive-all -v calamares-1.1-rc1.tar.gz` or without the helper script, @@ -64,21 +98,25 @@ The Calamares release process Double check that the tarball matches the version number. * Test tarball (e.g. unpack somewhere else and run the tests from step 0). -#### (3) Tag -* Set RC to zero in `CMakeLists.txt` if this is the actual release. -* `git tag -s v1.1.0` Make sure the signing key is known in GitHub, so that the - tag is shown as a verified tag. Do not sign -rc tags. +## (3) Housekeeping + * Generate MD5 and SHA256 checksums. * Upload tarball. * Announce on mailing list, notify packagers. * Write release article. - -#### (4) Release day - * Publish tarball. * Update download page. * Publish release article on `calamares.io`. * Publicize on social networks. * Close associated milestone on GitHub if this is the actual release. * Publish blog post. + +## (4) Post-Release + +* Bump the version number in `CMakeLists.txt` in the `project()` command. +* Set *CALAMARES_VERSION_RC* back to 1. +* Add a placeholder entry for the next release in `CHANGES` with date + text *not released yet*. +* Commit and push that, usually with the message + *Changes: post-release housekeeping*. From 340ffd070c13fb1eceb9b6495a6408f9f154087c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 12:57:12 +0100 Subject: [PATCH 084/119] Changes: credit to Anke Boersma for the example notes --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index ce161f396..1322f0449 100644 --- a/CHANGES +++ b/CHANGES @@ -6,7 +6,7 @@ website will have to do for older versions. # 3.2.19 (unreleased) # This release contains contributions from (alphabetically by first name): - - No other contributors this time around. + - Anke Boersma ## Core ## - *Assamese* translation has been completed. From 1b3d32ca7972ddd4bbef8781d1f3d700d6d12d1c Mon Sep 17 00:00:00 2001 From: Camilo Higuita Date: Thu, 12 Dec 2019 10:41:37 -0500 Subject: [PATCH 085/119] make label item from LabelModel qobject based and expose properties --- src/libcalamares/locale/Label.cpp | 11 ++++++++--- src/libcalamares/locale/Label.h | 18 +++++++++++++++--- src/libcalamares/locale/LabelModel.cpp | 17 +++++++++-------- src/libcalamares/locale/LabelModel.h | 4 +++- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 58c19101d..519e648bd 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -24,17 +24,19 @@ namespace CalamaresUtils namespace Locale { -Label::Label() - : m_locale( QLocale() ) +Label::Label( QObject* parent ) + : QObject( parent ) + , m_locale( QLocale() ) { m_localeId = m_locale.name(); setLabels( QString(), LabelFormat::IfNeededWithCountry ); } -Label::Label( const QString& locale, LabelFormat format ) +Label::Label( const QString& locale, LabelFormat format, QObject* parent ) : m_locale( Label::getLocale( locale ) ) , m_localeId( locale ) + , QObject( parent ) { setLabels( locale, format ); } @@ -42,6 +44,7 @@ Label::Label( const QString& locale, LabelFormat format ) void Label::setLabels( const QString& locale, LabelFormat format ) { + emit localeIdChanged(m_localeId); //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); @@ -62,8 +65,10 @@ Label::setLabels( const QString& locale, LabelFormat format ) countryName = m_locale.nativeCountryName(); } m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName; + emit labelChanged(m_label); m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) ) : englishName; + emit englishLabelChanged(m_englishLabel); } QLocale diff --git a/src/libcalamares/locale/Label.h b/src/libcalamares/locale/Label.h index 95129d38c..840c6f251 100644 --- a/src/libcalamares/locale/Label.h +++ b/src/libcalamares/locale/Label.h @@ -22,6 +22,7 @@ #include #include +#include namespace CalamaresUtils { @@ -35,8 +36,14 @@ namespace Locale * translation system) into QLocales, and also into consistent * human-readable text labels. */ -class Label +class Label : public QObject { + Q_OBJECT + + Q_PROPERTY(QString label READ label NOTIFY labelChanged CONSTANT FINAL) + Q_PROPERTY(QString englishLabel READ englishLabel NOTIFY englishLabelChanged CONSTANT FINAL) + Q_PROPERTY(QString localeId MEMBER m_localeId NOTIFY localeIdChanged CONSTANT FINAL) + public: /** @brief Formatting option for label -- add (country) to label. */ enum class LabelFormat @@ -46,7 +53,7 @@ public: }; /** @brief Empty locale. This uses the system-default locale. */ - Label(); + Label(QObject* parent = nullptr); /** @brief Construct from a locale name. * @@ -54,7 +61,7 @@ public: * The @p format determines whether the country name is always present * in the label (human-readable form) or only if needed for disambiguation. */ - Label( const QString& localeName, LabelFormat format = LabelFormat::IfNeededWithCountry ); + Label( const QString& localeName, LabelFormat format = LabelFormat::IfNeededWithCountry, QObject* parent = nullptr ); /** @brief Define a sorting order. * @@ -100,6 +107,11 @@ protected: QString m_localeId; // the locale identifier, e.g. "en_GB" QString m_label; // the native name of the locale QString m_englishLabel; + +signals: + void labelChanged( QString label ); + void englishLabelChanged( QString englishLabel ); + void localeIdChanged( QString localeIdChanged ); }; } // namespace Locale diff --git a/src/libcalamares/locale/LabelModel.cpp b/src/libcalamares/locale/LabelModel.cpp index bcb8af057..faec3edec 100644 --- a/src/libcalamares/locale/LabelModel.cpp +++ b/src/libcalamares/locale/LabelModel.cpp @@ -17,6 +17,7 @@ */ #include "LabelModel.h" +#include #include "Lookup.h" @@ -36,7 +37,7 @@ LabelModel::LabelModel( const QStringList& locales, QObject* parent ) for ( const auto& l : locales ) { - m_locales.push_back( Label( l ) ); + m_locales.push_back( new Label( l, Label::LabelFormat::IfNeededWithCountry, this ) ); } } @@ -65,9 +66,9 @@ LabelModel::data( const QModelIndex& index, int role ) const switch ( role ) { case LabelRole: - return locale.label(); + return locale->label(); case EnglishLabelRole: - return locale.englishLabel(); + return locale->englishLabel(); default: return QVariant(); } @@ -79,13 +80,13 @@ LabelModel::locale( int row ) const if ( ( row < 0 ) || ( row >= m_locales.count() ) ) { for ( const auto& l : m_locales ) - if ( l.isEnglish() ) + if ( l->isEnglish() ) { - return l; + return *l; } - return m_locales[ 0 ]; + return *m_locales[ 0 ]; } - return m_locales[ row ]; + return *m_locales[ row ]; } int @@ -93,7 +94,7 @@ LabelModel::find( std::function< bool( const Label& ) > predicate ) const { for ( int row = 0; row < m_locales.count(); ++row ) { - if ( predicate( m_locales[ row ] ) ) + if ( predicate( *m_locales[ row ] ) ) { return row; } diff --git a/src/libcalamares/locale/LabelModel.h b/src/libcalamares/locale/LabelModel.h index 03daddbf3..55dd35b8b 100644 --- a/src/libcalamares/locale/LabelModel.h +++ b/src/libcalamares/locale/LabelModel.h @@ -33,6 +33,8 @@ namespace Locale class DLLEXPORT LabelModel : public QAbstractListModel { + Q_OBJECT + public: enum { @@ -69,7 +71,7 @@ public: int find( const QString& countryCode ) const; private: - QVector< Label > m_locales; + QVector< Label* > m_locales; QStringList m_localeIds; }; From 241cb04f0661225f1daaafb27e43ea7463fa71ee Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 15:25:28 +0100 Subject: [PATCH 086/119] [libcalamares] Coding style --- src/libcalamares/locale/Label.cpp | 6 +++--- src/libcalamares/locale/Label.h | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 519e648bd..e526b633d 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -44,7 +44,7 @@ Label::Label( const QString& locale, LabelFormat format, QObject* parent ) void Label::setLabels( const QString& locale, LabelFormat format ) { - emit localeIdChanged(m_localeId); + emit localeIdChanged( m_localeId ); //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); @@ -65,10 +65,10 @@ Label::setLabels( const QString& locale, LabelFormat format ) countryName = m_locale.nativeCountryName(); } m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName; - emit labelChanged(m_label); + emit labelChanged( m_label ); m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) ) : englishName; - emit englishLabelChanged(m_englishLabel); + emit englishLabelChanged( m_englishLabel ); } QLocale diff --git a/src/libcalamares/locale/Label.h b/src/libcalamares/locale/Label.h index 840c6f251..ef6ac0aa3 100644 --- a/src/libcalamares/locale/Label.h +++ b/src/libcalamares/locale/Label.h @@ -21,8 +21,8 @@ #define LOCALE_LABEL_H #include -#include #include +#include namespace CalamaresUtils { @@ -40,9 +40,9 @@ class Label : public QObject { Q_OBJECT - Q_PROPERTY(QString label READ label NOTIFY labelChanged CONSTANT FINAL) - Q_PROPERTY(QString englishLabel READ englishLabel NOTIFY englishLabelChanged CONSTANT FINAL) - Q_PROPERTY(QString localeId MEMBER m_localeId NOTIFY localeIdChanged CONSTANT FINAL) + Q_PROPERTY( QString label READ label NOTIFY labelChanged CONSTANT FINAL ) + Q_PROPERTY( QString englishLabel READ englishLabel NOTIFY englishLabelChanged CONSTANT FINAL ) + Q_PROPERTY( QString localeId MEMBER m_localeId NOTIFY localeIdChanged CONSTANT FINAL ) public: /** @brief Formatting option for label -- add (country) to label. */ @@ -53,7 +53,7 @@ public: }; /** @brief Empty locale. This uses the system-default locale. */ - Label(QObject* parent = nullptr); + Label( QObject* parent = nullptr ); /** @brief Construct from a locale name. * @@ -61,7 +61,9 @@ public: * The @p format determines whether the country name is always present * in the label (human-readable form) or only if needed for disambiguation. */ - Label( const QString& localeName, LabelFormat format = LabelFormat::IfNeededWithCountry, QObject* parent = nullptr ); + Label( const QString& localeName, + LabelFormat format = LabelFormat::IfNeededWithCountry, + QObject* parent = nullptr ); /** @brief Define a sorting order. * From 27bc64e63fcba4c0a1f52dae1934de7e5533dff7 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 15:36:30 +0100 Subject: [PATCH 087/119] [libcalamares] C++ style, warnings-- --- src/libcalamares/locale/Label.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index e526b633d..2f35d6b03 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -34,9 +34,10 @@ Label::Label( QObject* parent ) } Label::Label( const QString& locale, LabelFormat format, QObject* parent ) - : m_locale( Label::getLocale( locale ) ) + : QObject( parent ) + , m_locale( Label::getLocale( locale ) ) , m_localeId( locale ) - , QObject( parent ) + { setLabels( locale, format ); } From df5a0d25bc845b985c720a320e130686df9663b9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 16:37:49 +0100 Subject: [PATCH 088/119] [libcalamares] Handle empty locale names quickly --- src/libcalamares/locale/Label.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 2f35d6b03..8e817a4ce 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -75,6 +75,10 @@ Label::setLabels( const QString& locale, LabelFormat format ) QLocale Label::getLocale( const QString& localeName ) { + if ( localeName.isEmpty() ) + { + return QLocale(); + } if ( localeName.contains( "@latin" ) ) { QLocale loc( localeName ); // Ignores @latin From b4b1bf5de213311bb11fc18014e7ad35edb3e44f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 16:39:39 +0100 Subject: [PATCH 089/119] [libcalamares] Call delegated constructor --- src/libcalamares/locale/Label.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 8e817a4ce..987c66811 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -25,18 +25,14 @@ namespace Locale { Label::Label( QObject* parent ) - : QObject( parent ) - , m_locale( QLocale() ) + : Label( QString(), LabelFormat::IfNeededWithCountry, parent ) { - m_localeId = m_locale.name(); - - setLabels( QString(), LabelFormat::IfNeededWithCountry ); } Label::Label( const QString& locale, LabelFormat format, QObject* parent ) : QObject( parent ) , m_locale( Label::getLocale( locale ) ) - , m_localeId( locale ) + , m_localeId( locale.isEmpty() ? m_locale.name() : locale ) { setLabels( locale, format ); From 684c5f477cf86e737d48c1c3e84ef831176555e4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 16:40:36 +0100 Subject: [PATCH 090/119] [libcalamares] Moc warnings-- - don't have a NOTIFY CONSTANT property - the data is constant, so drop NOTIFY - remove redundant signals - remove setLabels() now it's only needed from one constructor --- src/libcalamares/locale/Label.cpp | 9 --------- src/libcalamares/locale/Label.h | 13 +++---------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/src/libcalamares/locale/Label.cpp b/src/libcalamares/locale/Label.cpp index 987c66811..816246699 100644 --- a/src/libcalamares/locale/Label.cpp +++ b/src/libcalamares/locale/Label.cpp @@ -35,13 +35,6 @@ Label::Label( const QString& locale, LabelFormat format, QObject* parent ) , m_localeId( locale.isEmpty() ? m_locale.name() : locale ) { - setLabels( locale, format ); -} - -void -Label::setLabels( const QString& locale, LabelFormat format ) -{ - emit localeIdChanged( m_localeId ); //: language[name] (country[name]) QString longFormat = QObject::tr( "%1 (%2)" ); @@ -62,10 +55,8 @@ Label::setLabels( const QString& locale, LabelFormat format ) countryName = m_locale.nativeCountryName(); } m_label = needsCountryName ? longFormat.arg( languageName, countryName ) : languageName; - emit labelChanged( m_label ); m_englishLabel = needsCountryName ? longFormat.arg( englishName, QLocale::countryToString( m_locale.country() ) ) : englishName; - emit englishLabelChanged( m_englishLabel ); } QLocale diff --git a/src/libcalamares/locale/Label.h b/src/libcalamares/locale/Label.h index ef6ac0aa3..d7fa14453 100644 --- a/src/libcalamares/locale/Label.h +++ b/src/libcalamares/locale/Label.h @@ -40,9 +40,9 @@ class Label : public QObject { Q_OBJECT - Q_PROPERTY( QString label READ label NOTIFY labelChanged CONSTANT FINAL ) - Q_PROPERTY( QString englishLabel READ englishLabel NOTIFY englishLabelChanged CONSTANT FINAL ) - Q_PROPERTY( QString localeId MEMBER m_localeId NOTIFY localeIdChanged CONSTANT FINAL ) + Q_PROPERTY( QString label READ label CONSTANT FINAL ) + Q_PROPERTY( QString englishLabel READ englishLabel CONSTANT FINAL ) + Q_PROPERTY( QString localeId MEMBER m_localeId CONSTANT FINAL ) public: /** @brief Formatting option for label -- add (country) to label. */ @@ -103,17 +103,10 @@ public: static QLocale getLocale( const QString& localeName ); 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 QString m_englishLabel; - -signals: - void labelChanged( QString label ); - void englishLabelChanged( QString englishLabel ); - void localeIdChanged( QString localeIdChanged ); }; } // namespace Locale From 6432b7f42a1c59b4e27e3a1ba56165dc7c34a903 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 11 Feb 2020 16:46:44 +0100 Subject: [PATCH 091/119] [libcalamares] Hit Boost warnings with a hammer - Tons of warnings from Clang 9 in Boost::Python code, so turn of most of those warnings in the Boost-support code. --- src/libcalamares/PythonJob.cpp | 2 ++ src/libcalamares/PythonJobApi.h | 5 +++++ src/libcalamares/utils/boost-warnings.h | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index c18371881..bff7fcc74 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -27,6 +27,8 @@ #include #undef slots +#include "utils/boost-warnings.h" + #include #include diff --git a/src/libcalamares/PythonJobApi.h b/src/libcalamares/PythonJobApi.h index 3d3783f5f..981527951 100644 --- a/src/libcalamares/PythonJobApi.h +++ b/src/libcalamares/PythonJobApi.h @@ -25,8 +25,13 @@ #include "PythonJob.h" #undef slots +#include "utils/boost-warnings.h" #include +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + namespace CalamaresPython { diff --git a/src/libcalamares/utils/boost-warnings.h b/src/libcalamares/utils/boost-warnings.h index 65a66b0f6..69fb9ea30 100644 --- a/src/libcalamares/utils/boost-warnings.h +++ b/src/libcalamares/utils/boost-warnings.h @@ -5,4 +5,26 @@ #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" #pragma clang diagnostic ignored "-Wextra-semi-stmt" #pragma clang diagnostic ignored "-Wall" +#pragma clang diagnostic ignored "-Wimplicit-float-conversion" +#pragma clang diagnostic ignored "-Wundef" +#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec" +#pragma clang diagnostic ignored "-Wshadow-field-in-constructor" +#pragma clang diagnostic ignored "-Wshadow" +#pragma clang diagnostic ignored "-Wmissing-noreturn" +#pragma clang diagnostic ignored "-Wcast-qual" +#pragma clang diagnostic ignored "-Wcast-align" +#pragma clang diagnostic ignored "-Wsign-conversion" +#pragma clang diagnostic ignored "-Wdouble-promotion" +#pragma clang diagnostic ignored "-Wredundant-parens" +#pragma clang diagnostic ignored "-Wweak-vtables" +#pragma clang diagnostic ignored "-Wdeprecated" +#pragma clang diagnostic ignored "-Wmissing-field-initializers" +#pragma clang diagnostic ignored "-Wdisabled-macro-expansion" +#pragma clang diagnostic ignored "-Wdocumentation" +#pragma clang diagnostic ignored "-Wcomma" +#pragma clang diagnostic ignored "-Wunused-parameter" +#pragma clang diagnostic ignored "-Wunused-template" + +// Actually for Python headers +#pragma clang diagnostic ignored "-Wreserved-id-macro" #endif From 96580e5c40a7540935c6ece8946eb174f43023e3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 10:28:48 +0100 Subject: [PATCH 092/119] [libcalamares] Convenience header for Boost and its warnings --- src/libcalamares/utils/BoostPython.h | 73 ++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/libcalamares/utils/BoostPython.h diff --git a/src/libcalamares/utils/BoostPython.h b/src/libcalamares/utils/BoostPython.h new file mode 100644 index 000000000..7bd8865da --- /dev/null +++ b/src/libcalamares/utils/BoostPython.h @@ -0,0 +1,73 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019-2020, 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 . + */ + +/* + * The Python and Boost::Python headers are not C++14 warning-proof, especially + * with picky compilers like Clang 8 and 9. Since we use Clang for the + * find-all-the-warnings case, switch those warnings off for + * the we-can't-change-them system headers. + * + * This convenience header handles including all the bits we need for + * Python support, while silencing warnings. + */ +#ifndef UTILS_BOOSTPYTHON_H +#define UTILS_BOOSTPYTHON_H + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wreserved-id-macro" +#pragma clang diagnostic ignored "-Wold-style-cast" +#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" +#pragma clang diagnostic ignored "-Wextra-semi-stmt" +#pragma clang diagnostic ignored "-Wall" +#pragma clang diagnostic ignored "-Wimplicit-float-conversion" +#pragma clang diagnostic ignored "-Wundef" +#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec" +#pragma clang diagnostic ignored "-Wshadow-field-in-constructor" +#pragma clang diagnostic ignored "-Wshadow" +#pragma clang diagnostic ignored "-Wmissing-noreturn" +#pragma clang diagnostic ignored "-Wcast-qual" +#pragma clang diagnostic ignored "-Wcast-align" +#pragma clang diagnostic ignored "-Wsign-conversion" +#pragma clang diagnostic ignored "-Wdouble-promotion" +#pragma clang diagnostic ignored "-Wredundant-parens" +#pragma clang diagnostic ignored "-Wweak-vtables" +#pragma clang diagnostic ignored "-Wdeprecated" +#pragma clang diagnostic ignored "-Wmissing-field-initializers" +#pragma clang diagnostic ignored "-Wdisabled-macro-expansion" +#pragma clang diagnostic ignored "-Wdocumentation" +#pragma clang diagnostic ignored "-Wcomma" +#pragma clang diagnostic ignored "-Wunused-parameter" +#pragma clang diagnostic ignored "-Wunused-template" + +// Actually for Python headers +#pragma clang diagnostic ignored "-Wreserved-id-macro" +#endif + +#undef slots +#include +#include +#include +#include +#include + +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + +#endif From f3e7fe5eb416e38b228ba6f27b9eca1ee8d4af75 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 10:32:10 +0100 Subject: [PATCH 093/119] [libcalamares] Use more specific include --- src/libcalamares/PythonJob.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcalamares/PythonJob.h b/src/libcalamares/PythonJob.h index c63daacdc..103015932 100644 --- a/src/libcalamares/PythonJob.h +++ b/src/libcalamares/PythonJob.h @@ -23,7 +23,7 @@ #include "modulesystem/InstanceKey.h" -#include +#include namespace CalamaresPython { From d42e757576543f31b0cc9ac4cab74ca7f9da1370 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 10:48:19 +0100 Subject: [PATCH 094/119] [libcalamares] Simplify includes - CalamaresVersion used by the job, not the API presented to Python. - Untangle Qt includes from there. --- src/libcalamares/PythonJob.cpp | 1 + src/libcalamares/PythonJobApi.h | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index bff7fcc74..f5c033826 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -19,6 +19,7 @@ #include "PythonJob.h" +#include "CalamaresVersion.h" #include "GlobalStorage.h" #include "JobQueue.h" #include "PythonHelper.h" diff --git a/src/libcalamares/PythonJobApi.h b/src/libcalamares/PythonJobApi.h index 981527951..80a32b930 100644 --- a/src/libcalamares/PythonJobApi.h +++ b/src/libcalamares/PythonJobApi.h @@ -20,9 +20,7 @@ #ifndef PYTHONJOBAPI_H #define PYTHONJOBAPI_H -#include "CalamaresVersion.h" - -#include "PythonJob.h" +#include "qglobal.h" // For qreal #undef slots #include "utils/boost-warnings.h" @@ -32,6 +30,11 @@ #pragma clang diagnostic pop #endif +namespace Calamares +{ +class PythonJob; +} + namespace CalamaresPython { From f8998834cf9ce175b4860980b5da65572e63baa6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 10:55:36 +0100 Subject: [PATCH 095/119] [libcalamares] Simplify includes (no Python used in JobQueue) --- src/libcalamares/JobQueue.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libcalamares/JobQueue.cpp b/src/libcalamares/JobQueue.cpp index 6772671b7..2690769db 100644 --- a/src/libcalamares/JobQueue.cpp +++ b/src/libcalamares/JobQueue.cpp @@ -19,15 +19,11 @@ #include "JobQueue.h" +#include "CalamaresConfig.h" #include "GlobalStorage.h" #include "Job.h" #include "utils/Logger.h" -#include "CalamaresConfig.h" -#ifdef WITH_PYTHON -#include "PythonHelper.h" -#endif - #include namespace Calamares From 95722541d0482cb8c2b11f8c5313cce08b0244ab Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 11:02:38 +0100 Subject: [PATCH 096/119] [libcalamares] Untangle Python includes - Use BoostPython.h to manage overall includes - Remove local home-grown variations --- src/libcalamares/PythonHelper.cpp | 8 -------- src/libcalamares/PythonHelper.h | 12 +----------- src/libcalamares/PythonJob.cpp | 11 ++--------- src/libcalamares/PythonJobApi.cpp | 13 ++----------- src/libcalamares/PythonJobApi.h | 8 +------- 5 files changed, 6 insertions(+), 46 deletions(-) diff --git a/src/libcalamares/PythonHelper.cpp b/src/libcalamares/PythonHelper.cpp index 26a57ec14..d08fd66f1 100644 --- a/src/libcalamares/PythonHelper.cpp +++ b/src/libcalamares/PythonHelper.cpp @@ -25,14 +25,6 @@ #include #include -#undef slots -#include "utils/boost-warnings.h" -#include - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - namespace bp = boost::python; namespace CalamaresPython diff --git a/src/libcalamares/PythonHelper.h b/src/libcalamares/PythonHelper.h index 9035ba6d4..ed1d56151 100644 --- a/src/libcalamares/PythonHelper.h +++ b/src/libcalamares/PythonHelper.h @@ -21,20 +21,10 @@ #define CALAMARES_PYTHONJOBHELPER_H #include "PythonJob.h" +#include "utils/BoostPython.h" #include -#undef slots -#include "utils/boost-warnings.h" - -#include -#include -#include - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - namespace CalamaresPython { diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index f5c033826..db14c10f8 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -23,19 +23,12 @@ #include "GlobalStorage.h" #include "JobQueue.h" #include "PythonHelper.h" +#include "PythonJobApi.h" +#include "utils/BoostPython.h" #include "utils/Logger.h" #include -#undef slots -#include "utils/boost-warnings.h" - -#include -#include - -#include "PythonJobApi.h" - - namespace bp = boost::python; BOOST_PYTHON_FUNCTION_OVERLOADS( mount_overloads, CalamaresPython::mount, 2, 4 ); diff --git a/src/libcalamares/PythonJobApi.cpp b/src/libcalamares/PythonJobApi.cpp index 7b65e979c..e0bb686cd 100644 --- a/src/libcalamares/PythonJobApi.cpp +++ b/src/libcalamares/PythonJobApi.cpp @@ -19,26 +19,17 @@ #include "PythonJobApi.h" +#include "GlobalStorage.h" +#include "JobQueue.h" #include "PythonHelper.h" #include "utils/CalamaresUtilsSystem.h" #include "utils/Logger.h" #include "utils/String.h" -#include "GlobalStorage.h" -#include "JobQueue.h" - #include #include #include -#undef slots -#include "utils/boost-warnings.h" -#include - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - namespace bp = boost::python; static int diff --git a/src/libcalamares/PythonJobApi.h b/src/libcalamares/PythonJobApi.h index 80a32b930..941527d66 100644 --- a/src/libcalamares/PythonJobApi.h +++ b/src/libcalamares/PythonJobApi.h @@ -22,13 +22,7 @@ #include "qglobal.h" // For qreal -#undef slots -#include "utils/boost-warnings.h" -#include - -#ifdef __clang__ -#pragma clang diagnostic pop -#endif +#include "utils/BoostPython.h" namespace Calamares { From 3b35ca7bb99201232288fbbdc6cdf288c8065f4a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 11:04:15 +0100 Subject: [PATCH 097/119] [libcalamares] Simplify includes - PythonHelper.h already pulls in all the Python machinery --- src/libcalamares/GlobalStorage.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/libcalamares/GlobalStorage.cpp b/src/libcalamares/GlobalStorage.cpp index 5094ad2fd..2241a3c7a 100644 --- a/src/libcalamares/GlobalStorage.cpp +++ b/src/libcalamares/GlobalStorage.cpp @@ -29,13 +29,6 @@ #ifdef WITH_PYTHON #include "PythonHelper.h" - - -#undef slots -#include -#include - -namespace bp = boost::python; #endif using CalamaresUtils::operator""_MiB; From 8181808bec342bd2dbeb3f1998098c505af00e6a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 11:25:10 +0100 Subject: [PATCH 098/119] [libcalamares] Fix build - drop now-obsolete boost-warnings.h - add missing namespace alias to GlobalStorage.h (removed accidentally in previous commit) --- src/libcalamares/GlobalStorage.cpp | 1 + src/libcalamares/utils/boost-warnings.h | 30 ------------------------- 2 files changed, 1 insertion(+), 30 deletions(-) delete mode 100644 src/libcalamares/utils/boost-warnings.h diff --git a/src/libcalamares/GlobalStorage.cpp b/src/libcalamares/GlobalStorage.cpp index 2241a3c7a..2ccaf79b4 100644 --- a/src/libcalamares/GlobalStorage.cpp +++ b/src/libcalamares/GlobalStorage.cpp @@ -29,6 +29,7 @@ #ifdef WITH_PYTHON #include "PythonHelper.h" +namespace bp = boost::python; #endif using CalamaresUtils::operator""_MiB; diff --git a/src/libcalamares/utils/boost-warnings.h b/src/libcalamares/utils/boost-warnings.h deleted file mode 100644 index 69fb9ea30..000000000 --- a/src/libcalamares/utils/boost-warnings.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wreserved-id-macro" -#pragma clang diagnostic ignored "-Wold-style-cast" -#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" -#pragma clang diagnostic ignored "-Wextra-semi-stmt" -#pragma clang diagnostic ignored "-Wall" -#pragma clang diagnostic ignored "-Wimplicit-float-conversion" -#pragma clang diagnostic ignored "-Wundef" -#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec" -#pragma clang diagnostic ignored "-Wshadow-field-in-constructor" -#pragma clang diagnostic ignored "-Wshadow" -#pragma clang diagnostic ignored "-Wmissing-noreturn" -#pragma clang diagnostic ignored "-Wcast-qual" -#pragma clang diagnostic ignored "-Wcast-align" -#pragma clang diagnostic ignored "-Wsign-conversion" -#pragma clang diagnostic ignored "-Wdouble-promotion" -#pragma clang diagnostic ignored "-Wredundant-parens" -#pragma clang diagnostic ignored "-Wweak-vtables" -#pragma clang diagnostic ignored "-Wdeprecated" -#pragma clang diagnostic ignored "-Wmissing-field-initializers" -#pragma clang diagnostic ignored "-Wdisabled-macro-expansion" -#pragma clang diagnostic ignored "-Wdocumentation" -#pragma clang diagnostic ignored "-Wcomma" -#pragma clang diagnostic ignored "-Wunused-parameter" -#pragma clang diagnostic ignored "-Wunused-template" - -// Actually for Python headers -#pragma clang diagnostic ignored "-Wreserved-id-macro" -#endif From c1151cbcfa2c0d9b129ae5fc8b966aa8c3896c16 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 12:08:46 +0100 Subject: [PATCH 099/119] [libcalamares] Update copyright info --- src/libcalamares/PythonHelper.cpp | 2 +- src/libcalamares/PythonHelper.h | 2 +- src/libcalamares/PythonJob.cpp | 4 ++-- src/libcalamares/PythonJob.h | 1 + src/libcalamares/PythonJobApi.cpp | 2 +- src/libcalamares/PythonJobApi.h | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libcalamares/PythonHelper.cpp b/src/libcalamares/PythonHelper.cpp index d08fd66f1..88008692e 100644 --- a/src/libcalamares/PythonHelper.cpp +++ b/src/libcalamares/PythonHelper.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Teo Mrnjavac - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2018, 2020, 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 diff --git a/src/libcalamares/PythonHelper.h b/src/libcalamares/PythonHelper.h index ed1d56151..bb37eb868 100644 --- a/src/libcalamares/PythonHelper.h +++ b/src/libcalamares/PythonHelper.h @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018, 2020, 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 diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index db14c10f8..d94a20981 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2016, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018, 2020, 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 @@ -176,7 +176,7 @@ PythonJob::PythonJob( const ModuleSystem::InstanceKey& instance, , m_workingPath( workingPath ) , m_description() , m_configurationMap( moduleConfiguration ) - , m_weight( (instance.module() == QStringLiteral( "unpackfs" )) ? 12.0 : 1.0 ) + , m_weight( ( instance.module() == QStringLiteral( "unpackfs" ) ) ? 12.0 : 1.0 ) { } diff --git a/src/libcalamares/PythonJob.h b/src/libcalamares/PythonJob.h index 103015932..7cd1b7165 100644 --- a/src/libcalamares/PythonJob.h +++ b/src/libcalamares/PythonJob.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Teo Mrnjavac + * Copyright 2020, 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 diff --git a/src/libcalamares/PythonJobApi.cpp b/src/libcalamares/PythonJobApi.cpp index e0bb686cd..132a9dcf5 100644 --- a/src/libcalamares/PythonJobApi.cpp +++ b/src/libcalamares/PythonJobApi.cpp @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2016, Teo Mrnjavac - * Copyright 2017-2019, Adriaan de Groot + * Copyright 2017-2020, 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 diff --git a/src/libcalamares/PythonJobApi.h b/src/libcalamares/PythonJobApi.h index 941527d66..6fb27cd62 100644 --- a/src/libcalamares/PythonJobApi.h +++ b/src/libcalamares/PythonJobApi.h @@ -1,7 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014-2016, Teo Mrnjavac - * Copyright 2017-2018, Adriaan de Groot + * Copyright 2017-2018, 2020, 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 From 7efed8226cc2854ea9f425222cca78d3712b6bae Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 12:10:58 +0100 Subject: [PATCH 100/119] [libcalamares] Warnings--, update copyright --- src/libcalamares/utils/TestPaths.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcalamares/utils/TestPaths.cpp b/src/libcalamares/utils/TestPaths.cpp index 2f9f4e657..da67f9dd2 100644 --- a/src/libcalamares/utils/TestPaths.cpp +++ b/src/libcalamares/utils/TestPaths.cpp @@ -1,6 +1,6 @@ /* === This file is part of Calamares - === * - * Copyright 2018, Adriaan de Groot + * Copyright 2018, 2020, 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 @@ -38,8 +38,8 @@ class TestPaths : public QObject { Q_OBJECT public: - TestPaths() {}; - virtual ~TestPaths() {}; + TestPaths() {} + virtual ~TestPaths() {} private Q_SLOTS: void initTestCase(); From 090716ba4f7ac5220339512ccde15d16a241b158 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 12:15:13 +0100 Subject: [PATCH 101/119] [libcalamares] Warnings-- in Entropy - reading a file yields a qint64 - need to mash the unsigned data from twister to signed char data. --- src/libcalamares/utils/Entropy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcalamares/utils/Entropy.cpp b/src/libcalamares/utils/Entropy.cpp index 643346855..ce1f6ba9d 100644 --- a/src/libcalamares/utils/Entropy.cpp +++ b/src/libcalamares/utils/Entropy.cpp @@ -35,7 +35,7 @@ CalamaresUtils::getEntropy( int size, QByteArray& b ) char* buffer = b.data(); std::fill( buffer, buffer + size, 0xcb ); - int readSize = 0; + qint64 readSize = 0; QFile urandom( "/dev/urandom" ); if ( urandom.exists() && urandom.open( QIODevice::ReadOnly ) ) { @@ -62,7 +62,7 @@ CalamaresUtils::getEntropy( int size, QByteArray& b ) #define GET_ONE_BYTE \ if ( readSize < size ) \ { \ - buffer[ readSize++ ] = next & 0xff; \ + buffer[ readSize++ ] = char( next & 0xffU ); \ next = next >> 8; \ } GET_ONE_BYTE From a11280b427b8bfb06d8811d59e053aab343955ec Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 12:22:02 +0100 Subject: [PATCH 102/119] [libcalamares] Expand tests for printable entropy --- src/libcalamares/utils/Tests.cpp | 27 +++++++++++++++++++++++++++ src/libcalamares/utils/Tests.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/libcalamares/utils/Tests.cpp b/src/libcalamares/utils/Tests.cpp index e39d182ea..34701a940 100644 --- a/src/libcalamares/utils/Tests.cpp +++ b/src/libcalamares/utils/Tests.cpp @@ -224,3 +224,30 @@ LibCalamaresTests::testPrintableEntropy() QVERIFY( c.cell() < 127 ); } } + +void +LibCalamaresTests::testOddSizedPrintable() +{ + QString s; + for ( int l = 0; l <= 37; ++l ) + { + auto r = CalamaresUtils::getPrintableEntropy( l, s ); + if ( l == 0 ) + { + QCOMPARE( r, CalamaresUtils::EntropySource::None ); + } + else + { + QVERIFY( r != CalamaresUtils::EntropySource::None ); + } + QCOMPARE( s.length(), l ); + + for ( QChar c : s ) + { + QVERIFY( c.isPrint() ); + QCOMPARE( c.row(), 0 ); + QVERIFY( c.cell() > 32 ); // ASCII SPACE + QVERIFY( c.cell() < 127 ); + } + } +} diff --git a/src/libcalamares/utils/Tests.h b/src/libcalamares/utils/Tests.h index d369ed4cb..f9908c74c 100644 --- a/src/libcalamares/utils/Tests.h +++ b/src/libcalamares/utils/Tests.h @@ -43,6 +43,7 @@ private Q_SLOTS: /** @brief Tests the entropy functions. */ void testEntropy(); void testPrintableEntropy(); + void testOddSizedPrintable(); }; #endif From ad725b671e1d509cf5172d4a9432ae367c11b398 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 12:26:55 +0100 Subject: [PATCH 103/119] [hostinfo] Warnings-- - Physical memory can't be negative, so it is reported as an unsigned long, but the bytes-to-MiB functions do accept negative amounts. As long as no machine has more than 2**62 bytes of memory, we're good though. --- src/modules/hostinfo/HostInfoJob.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/hostinfo/HostInfoJob.cpp b/src/modules/hostinfo/HostInfoJob.cpp index 3e0e4258c..c2959fb6b 100644 --- a/src/modules/hostinfo/HostInfoJob.cpp +++ b/src/modules/hostinfo/HostInfoJob.cpp @@ -156,7 +156,8 @@ HostInfoJob::exec() gs->insert( "hostOSName", hostOSName() ); gs->insert( "hostCPU", hostCPU() ); - auto ram = CalamaresUtils::BytesToMiB( CalamaresUtils::System::instance()->getTotalMemoryB().first ); + // Memory can't be negative, so it's reported as unsigned long. + auto ram = CalamaresUtils::BytesToMiB( qint64( CalamaresUtils::System::instance()->getTotalMemoryB().first ) ); if ( ram ) { gs->insert( "hostRAMMiB", ram ); From 940860107445dbdc499a4a7f737ba84e40948674 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 12:37:43 +0100 Subject: [PATCH 104/119] [libcalamares] Move Python wrapper - Take the Python wrapper for GlobalStorage out of the GlobalStorage.h header and add it to PythonHelper instead, saving some work in all the cases that only GS is interesting, not the Python bits. --- src/libcalamares/GlobalStorage.cpp | 77 ------------------------------ src/libcalamares/GlobalStorage.h | 43 ----------------- src/libcalamares/PythonHelper.cpp | 63 ++++++++++++++++++++++++ src/libcalamares/PythonHelper.h | 27 +++++++++++ 4 files changed, 90 insertions(+), 120 deletions(-) diff --git a/src/libcalamares/GlobalStorage.cpp b/src/libcalamares/GlobalStorage.cpp index 2ccaf79b4..428b01103 100644 --- a/src/libcalamares/GlobalStorage.cpp +++ b/src/libcalamares/GlobalStorage.cpp @@ -27,11 +27,6 @@ #include #include -#ifdef WITH_PYTHON -#include "PythonHelper.h" -namespace bp = boost::python; -#endif - using CalamaresUtils::operator""_MiB; namespace Calamares @@ -161,75 +156,3 @@ GlobalStorage::loadYaml( const QString& filename ) } // namespace Calamares - -#ifdef WITH_PYTHON - -namespace CalamaresPython -{ - -Calamares::GlobalStorage* GlobalStoragePythonWrapper::s_gs_instance = nullptr; - -// The special handling for nullptr is only for the testing -// script for the python bindings, which passes in None; -// normal use will have a GlobalStorage from JobQueue::instance() -// passed in. Testing use will leak the allocated GlobalStorage -// object, but that's OK for testing. -GlobalStoragePythonWrapper::GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs ) - : m_gs( gs ? gs : s_gs_instance ) -{ - if ( !m_gs ) - { - s_gs_instance = new Calamares::GlobalStorage; - m_gs = s_gs_instance; - } -} - -bool -GlobalStoragePythonWrapper::contains( const std::string& key ) const -{ - return m_gs->contains( QString::fromStdString( key ) ); -} - - -int -GlobalStoragePythonWrapper::count() const -{ - return m_gs->count(); -} - - -void -GlobalStoragePythonWrapper::insert( const std::string& key, const bp::object& value ) -{ - m_gs->insert( QString::fromStdString( key ), CalamaresPython::variantFromPyObject( value ) ); -} - -bp::list -GlobalStoragePythonWrapper::keys() const -{ - bp::list pyList; - const auto keys = m_gs->keys(); - for ( const QString& key : keys ) - { - pyList.append( key.toStdString() ); - } - return pyList; -} - - -int -GlobalStoragePythonWrapper::remove( const std::string& key ) -{ - return m_gs->remove( QString::fromStdString( key ) ); -} - - -bp::object -GlobalStoragePythonWrapper::value( const std::string& key ) const -{ - return CalamaresPython::variantToPyObject( m_gs->value( QString::fromStdString( key ) ) ); -} - -} // namespace CalamaresPython - -#endif // WITH_PYTHON diff --git a/src/libcalamares/GlobalStorage.h b/src/libcalamares/GlobalStorage.h index b070e23f6..bef9ec1cc 100644 --- a/src/libcalamares/GlobalStorage.h +++ b/src/libcalamares/GlobalStorage.h @@ -26,20 +26,6 @@ #include #include -#ifdef WITH_PYTHON -namespace boost -{ -namespace python -{ -namespace api -{ -class object; -} -class list; -} // namespace python -} // namespace boost -#endif - namespace Calamares { @@ -106,33 +92,4 @@ private: } // namespace Calamares -#ifdef WITH_PYTHON -namespace CalamaresPython -{ - -class GlobalStoragePythonWrapper -{ -public: - explicit GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs ); - - bool contains( const std::string& key ) const; - int count() const; - void insert( const std::string& key, const boost::python::api::object& value ); - boost::python::list keys() const; - int remove( const std::string& key ); - boost::python::api::object value( const std::string& key ) const; - - // This is a helper for scripts that do not go through - // the JobQueue (i.e. the module testpython script), - // which allocate their own (singleton) GlobalStorage. - static Calamares::GlobalStorage* globalStorageInstance() { return s_gs_instance; } - -private: - Calamares::GlobalStorage* m_gs; - static Calamares::GlobalStorage* s_gs_instance; // See globalStorageInstance() -}; - -} // namespace CalamaresPython -#endif - #endif // CALAMARES_GLOBALSTORAGE_H diff --git a/src/libcalamares/PythonHelper.cpp b/src/libcalamares/PythonHelper.cpp index 88008692e..d9db8581e 100644 --- a/src/libcalamares/PythonHelper.cpp +++ b/src/libcalamares/PythonHelper.cpp @@ -19,6 +19,7 @@ #include "PythonHelper.h" +#include "GlobalStorage.h" #include "utils/Dirs.h" #include "utils/Logger.h" @@ -390,5 +391,67 @@ Helper::handleLastError() return QString( "
%1
" ).arg( msgList.join( "
" ) ); } +Calamares::GlobalStorage* GlobalStoragePythonWrapper::s_gs_instance = nullptr; + +// The special handling for nullptr is only for the testing +// script for the python bindings, which passes in None; +// normal use will have a GlobalStorage from JobQueue::instance() +// passed in. Testing use will leak the allocated GlobalStorage +// object, but that's OK for testing. +GlobalStoragePythonWrapper::GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs ) + : m_gs( gs ? gs : s_gs_instance ) +{ + if ( !m_gs ) + { + s_gs_instance = new Calamares::GlobalStorage; + m_gs = s_gs_instance; + } +} + +bool +GlobalStoragePythonWrapper::contains( const std::string& key ) const +{ + return m_gs->contains( QString::fromStdString( key ) ); +} + + +int +GlobalStoragePythonWrapper::count() const +{ + return m_gs->count(); +} + + +void +GlobalStoragePythonWrapper::insert( const std::string& key, const bp::object& value ) +{ + m_gs->insert( QString::fromStdString( key ), CalamaresPython::variantFromPyObject( value ) ); +} + +bp::list +GlobalStoragePythonWrapper::keys() const +{ + bp::list pyList; + const auto keys = m_gs->keys(); + for ( const QString& key : keys ) + { + pyList.append( key.toStdString() ); + } + return pyList; +} + + +int +GlobalStoragePythonWrapper::remove( const std::string& key ) +{ + return m_gs->remove( QString::fromStdString( key ) ); +} + + +bp::object +GlobalStoragePythonWrapper::value( const std::string& key ) const +{ + return CalamaresPython::variantToPyObject( m_gs->value( QString::fromStdString( key ) ) ); +} } // namespace CalamaresPython diff --git a/src/libcalamares/PythonHelper.h b/src/libcalamares/PythonHelper.h index bb37eb868..418c75e5f 100644 --- a/src/libcalamares/PythonHelper.h +++ b/src/libcalamares/PythonHelper.h @@ -25,6 +25,11 @@ #include +namespace Calamares +{ +class GlobalStorage; +} + namespace CalamaresPython { @@ -62,6 +67,28 @@ private: QStringList m_pythonPaths; }; +class GlobalStoragePythonWrapper +{ +public: + explicit GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs ); + + bool contains( const std::string& key ) const; + int count() const; + void insert( const std::string& key, const boost::python::api::object& value ); + boost::python::list keys() const; + int remove( const std::string& key ); + boost::python::api::object value( const std::string& key ) const; + + // This is a helper for scripts that do not go through + // the JobQueue (i.e. the module testpython script), + // which allocate their own (singleton) GlobalStorage. + static Calamares::GlobalStorage* globalStorageInstance() { return s_gs_instance; } + +private: + Calamares::GlobalStorage* m_gs; + static Calamares::GlobalStorage* s_gs_instance; // See globalStorageInstance() +}; + } // namespace CalamaresPython #endif // CALAMARES_PYTHONJOBHELPER_H From ca13d1670e0ab958a3aa985e0d95ec5277be9c47 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 13:40:59 +0100 Subject: [PATCH 105/119] [libcalamares] Merge more from Camilo - Complete the model for locales --- src/libcalamares/locale/LabelModel.cpp | 10 ++++++++-- src/libcalamares/locale/LabelModel.h | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/libcalamares/locale/LabelModel.cpp b/src/libcalamares/locale/LabelModel.cpp index faec3edec..da4e1a9f7 100644 --- a/src/libcalamares/locale/LabelModel.cpp +++ b/src/libcalamares/locale/LabelModel.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * - * Copyright 2019, Adriaan de Groot + * Copyright 2019-2020 Adriaan de Groot + * Copyright 2019, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +18,6 @@ */ #include "LabelModel.h" -#include #include "Lookup.h" @@ -74,6 +74,12 @@ LabelModel::data( const QModelIndex& index, int role ) const } } +QHash< int, QByteArray > +LabelModel::roleNames() const +{ + return { { LabelRole, "label" }, { EnglishLabelRole, "englishLabel" } }; +} + const Label& LabelModel::locale( int row ) const { diff --git a/src/libcalamares/locale/LabelModel.h b/src/libcalamares/locale/LabelModel.h index 55dd35b8b..7bd1fad67 100644 --- a/src/libcalamares/locale/LabelModel.h +++ b/src/libcalamares/locale/LabelModel.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * - * Copyright 2019, Adriaan de Groot + * Copyright 2019-2020, Adriaan de Groot + * Copyright 2019, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,6 +49,7 @@ public: int rowCount( const QModelIndex& parent ) const override; QVariant data( const QModelIndex& index, int role ) const override; + QHash< int, QByteArray > roleNames() const override; /** @brief Gets locale information for entry #n * From 1f2f1a657e0d3a530247a72ee3a7ddeeaaeb0e55 Mon Sep 17 00:00:00 2001 From: Camilo Higuita Date: Fri, 13 Dec 2019 14:22:15 +0100 Subject: [PATCH 106/119] [libcalamaresui] Expose Branding strings to QML --- src/libcalamaresui/Branding.cpp | 4 +++- src/libcalamaresui/Branding.h | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/libcalamaresui/Branding.cpp b/src/libcalamaresui/Branding.cpp index a5b6e5dce..9bdccfa51 100644 --- a/src/libcalamaresui/Branding.cpp +++ b/src/libcalamaresui/Branding.cpp @@ -3,6 +3,7 @@ * Copyright 2014-2015, Teo Mrnjavac * Copyright 2017-2019, Adriaan de Groot * Copyright 2018, Raul Rodrigo Segura (raurodse) + * Copyright 2019, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -74,7 +75,8 @@ const QStringList Branding::s_imageEntryStrings = { "productLogo", "productIcon", - "productWelcome" + "productWelcome", + "productWallpaper" }; const QStringList Branding::s_styleEntryStrings = diff --git a/src/libcalamaresui/Branding.h b/src/libcalamaresui/Branding.h index 30e8be846..e3952881e 100644 --- a/src/libcalamaresui/Branding.h +++ b/src/libcalamaresui/Branding.h @@ -3,6 +3,7 @@ * Copyright 2014-2015, Teo Mrnjavac * Copyright 2017-2018, Adriaan de Groot * Copyright 2018, Raul Rodrigo Segura (raurodse) + * Copyright 2019, Camilo Higuita * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,7 +49,7 @@ public: * e.g. *Branding::ProductName to get the string value for * the product name. */ - enum StringEntry : short + enum StringEntry { ProductName, Version, @@ -62,13 +63,16 @@ public: KnownIssuesUrl, ReleaseNotesUrl }; + Q_ENUM( StringEntry ) enum ImageEntry : short { ProductLogo, ProductIcon, - ProductWelcome + ProductWelcome, + ProductWallpaper }; + Q_ENUM( ImageEntry ) enum StyleEntry : short { @@ -77,6 +81,7 @@ public: SidebarTextSelect, SidebarTextHighlight }; + Q_ENUM( StyleEntry ) /** @brief Setting for how much the main window may expand. */ enum class WindowExpansion @@ -85,6 +90,7 @@ public: Fullscreen, Fixed }; + Q_ENUM( WindowExpansion ) /** @brief Setting for the main window size. * * The units are pixels (Pixies) or something-based-on-fontsize (Fonties), which @@ -96,6 +102,7 @@ public: Pixies, Fonties }; + Q_ENUM( WindowDimensionUnit ) class WindowDimension : public NamedSuffix< WindowDimensionUnit, WindowDimensionUnit::None > { public: From ffeed05a5d79742607f04583f1a6cbeda38dcd45 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 12 Feb 2020 14:09:09 +0100 Subject: [PATCH 107/119] Changes: credit Camilo Higuita for QML prep-work --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 1322f0449..439a3c882 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,7 @@ website will have to do for older versions. This release contains contributions from (alphabetically by first name): - Anke Boersma + - Camilo Higuita ## Core ## - *Assamese* translation has been completed. From c055e1da49dbedbe9d01cbccbd22eae2288d2b45 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 09:24:12 +0100 Subject: [PATCH 108/119] [partition] Use untranslated name of filesystem - Patch from Gabriel Craciunescu --- CHANGES | 1 + src/modules/partition/jobs/FillGlobalStorageJob.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 439a3c882..cb807cdc4 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,7 @@ website will have to do for older versions. This release contains contributions from (alphabetically by first name): - Anke Boersma - Camilo Higuita + - Gabriel Craciunescu ## Core ## - *Assamese* translation has been completed. diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 8b981ce3e..77b1e8aaa 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -89,7 +89,7 @@ mapForPartition( Partition* partition, const QString& uuid ) map[ "fs" ] = partition->fileSystem().name( { QStringLiteral("C") } ); // Untranslated if ( partition->fileSystem().type() == FileSystem::Luks && dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) - map[ "fs" ] = dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS()->name(); + map[ "fs" ] = dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS()->name( { QStringLiteral("C") } ); map[ "uuid" ] = uuid; // Debugging for inside the loop in createPartitionList(), From f410a4bb68c288821dad06fbc13374f74912fc0e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 10:12:02 +0100 Subject: [PATCH 109/119] [libcalamares] Convenience function for FS names Because getting the untranslated name of a FileSystem is something that needs doing consistently, add some functions for that; it makes it easier to spot places where that isn't done. Probably doesn't compile, and needs extra documentation. --- src/libcalamares/partition/FSName.h | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/libcalamares/partition/FSName.h diff --git a/src/libcalamares/partition/FSName.h b/src/libcalamares/partition/FSName.h new file mode 100644 index 000000000..f7dfcf5b4 --- /dev/null +++ b/src/libcalamares/partition/FSName.h @@ -0,0 +1,52 @@ +/* === This file is part of Calamares - === + * + * Copyright 2020, 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 . + */ + +/** @brief Gets filesystem names from KPMCore + * + * A name (e.g. "ext4") can be for internal, untranslated, use, or for + * user-visible use. In the latter case it should be translated. The + * KPMCore API gives user-visible names by default. + */ +#ifndef PARTITION_FSNAME_H +#define PARTITION_FSNAME_H + +#include + +#include + +namespace CalamaresUtils +{ +namespace Partition +{ + +static inline QString +untranslatedFS( FileSystem& fs ) +{ + return fs.name( { QStringLiteral( "C" ) } ); +} + +static inline QString +untranslatedFS( FileSystem* fs ) +{ + return fs ? untranslatedFS( *fs ) : QString(); +} + +} // namespace Partition +} // namespace CalamaresUtils + +#endif // PARTITION_FSNAME_H From a0449abab9d51211ef4a87e171a430b585734fd9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:06:53 +0100 Subject: [PATCH 110/119] [partition] Do not translate filesystem names - Move contents of FSName to KPMHelpers - Use the new functions from FillGlobalStorage Needs more use in the rest of the partition module. --- src/libcalamares/partition/FSName.h | 52 ------------------- src/modules/partition/core/KPMHelpers.h | 13 +++++ .../partition/jobs/FillGlobalStorageJob.cpp | 13 +++-- 3 files changed, 21 insertions(+), 57 deletions(-) delete mode 100644 src/libcalamares/partition/FSName.h diff --git a/src/libcalamares/partition/FSName.h b/src/libcalamares/partition/FSName.h deleted file mode 100644 index f7dfcf5b4..000000000 --- a/src/libcalamares/partition/FSName.h +++ /dev/null @@ -1,52 +0,0 @@ -/* === This file is part of Calamares - === - * - * Copyright 2020, 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 . - */ - -/** @brief Gets filesystem names from KPMCore - * - * A name (e.g. "ext4") can be for internal, untranslated, use, or for - * user-visible use. In the latter case it should be translated. The - * KPMCore API gives user-visible names by default. - */ -#ifndef PARTITION_FSNAME_H -#define PARTITION_FSNAME_H - -#include - -#include - -namespace CalamaresUtils -{ -namespace Partition -{ - -static inline QString -untranslatedFS( FileSystem& fs ) -{ - return fs.name( { QStringLiteral( "C" ) } ); -} - -static inline QString -untranslatedFS( FileSystem* fs ) -{ - return fs ? untranslatedFS( *fs ) : QString(); -} - -} // namespace Partition -} // namespace CalamaresUtils - -#endif // PARTITION_FSNAME_H diff --git a/src/modules/partition/core/KPMHelpers.h b/src/modules/partition/core/KPMHelpers.h index bca69d1f6..7ef9718ae 100644 --- a/src/modules/partition/core/KPMHelpers.h +++ b/src/modules/partition/core/KPMHelpers.h @@ -114,6 +114,19 @@ Partition* createNewEncryptedPartition( PartitionNode* parent, Partition* clonePartition( Device* device, Partition* partition ); QString prettyNameForFileSystemType( FileSystem::Type t ); + +static inline QString +untranslatedFS( FileSystem& fs ) +{ + return fs.name( { QStringLiteral( "C" ) } ); +} + +static inline QString +untranslatedFS( FileSystem* fs ) +{ + return fs ? untranslatedFS( *fs ) : QString(); +} + } #endif /* KPMHELPERS_H */ diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 77b1e8aaa..10554209c 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -20,11 +20,12 @@ #include "jobs/FillGlobalStorageJob.h" -#include "GlobalStorage.h" -#include "JobQueue.h" #include "core/PartitionInfo.h" #include "core/PartitionIterator.h" #include "core/KPMHelpers.h" + +#include "GlobalStorage.h" +#include "JobQueue.h" #include "Branding.h" #include "utils/Logger.h" @@ -40,6 +41,8 @@ #include #include +using KPMHelpers::untranslatedFS; + typedef QHash UuidForPartitionHash; static UuidForPartitionHash @@ -85,11 +88,11 @@ mapForPartition( Partition* partition, const QString& uuid ) QVariantMap map; map[ "device" ] = partition->partitionPath(); map[ "mountPoint" ] = PartitionInfo::mountPoint( partition ); - map[ "fsName" ] = partition->fileSystem().name(); - map[ "fs" ] = partition->fileSystem().name( { QStringLiteral("C") } ); // Untranslated + map[ "fsName" ] = partition->fileSystem().name(); // User-visible + map[ "fs" ] = untranslatedFS( partition->fileSystem() ); if ( partition->fileSystem().type() == FileSystem::Luks && dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) - map[ "fs" ] = dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS()->name( { QStringLiteral("C") } ); + map[ "fs" ] = untranslatedFS( dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ); map[ "uuid" ] = uuid; // Debugging for inside the loop in createPartitionList(), From dac5516b2c6841c89e97ef5df35ac1170a922764 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:12:22 +0100 Subject: [PATCH 111/119] [partition] Update copyright, coding style --- .../partition/jobs/FillGlobalStorageJob.cpp | 73 +++++++++++-------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 10554209c..7faa4b50f 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2015-2016, Teo Mrnjavac - * Copyright 2017, 2019, Adriaan de Groot + * Copyright 2017, 2019-2020, 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 @@ -20,13 +20,13 @@ #include "jobs/FillGlobalStorageJob.h" +#include "core/KPMHelpers.h" #include "core/PartitionInfo.h" #include "core/PartitionIterator.h" -#include "core/KPMHelpers.h" +#include "Branding.h" #include "GlobalStorage.h" #include "JobQueue.h" -#include "Branding.h" #include "utils/Logger.h" // KPMcore @@ -43,16 +43,15 @@ using KPMHelpers::untranslatedFS; -typedef QHash UuidForPartitionHash; +typedef QHash< QString, QString > UuidForPartitionHash; static UuidForPartitionHash -findPartitionUuids( QList < Device* > devices ) +findPartitionUuids( QList< Device* > devices ) { UuidForPartitionHash hash; foreach ( Device* device, devices ) { - for ( auto it = PartitionIterator::begin( device ); - it != PartitionIterator::end( device ); ++it ) + for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it ) { Partition* p = *it; QString path = p->partitionPath(); @@ -62,7 +61,9 @@ findPartitionUuids( QList < Device* > devices ) } if ( hash.isEmpty() ) + { cDebug() << "No UUIDs found for existing partitions."; + } return hash; } @@ -76,7 +77,9 @@ getLuksUuid( const QString& path ) process.start(); process.waitForFinished(); if ( process.exitStatus() != QProcess::NormalExit || process.exitCode() ) + { return QString(); + } QString uuid = QString::fromLocal8Bit( process.readAllStandardOutput() ).trimmed(); return uuid; } @@ -90,20 +93,20 @@ mapForPartition( Partition* partition, const QString& uuid ) map[ "mountPoint" ] = PartitionInfo::mountPoint( partition ); map[ "fsName" ] = partition->fileSystem().name(); // User-visible map[ "fs" ] = untranslatedFS( partition->fileSystem() ); - if ( partition->fileSystem().type() == FileSystem::Luks && - dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) + if ( partition->fileSystem().type() == FileSystem::Luks + && dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) + { map[ "fs" ] = untranslatedFS( dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ); + } map[ "uuid" ] = uuid; // Debugging for inside the loop in createPartitionList(), // so indent a bit Logger::CDebug deb; - using TR = Logger::DebugRow; + using TR = Logger::DebugRow< const char* const, const QString& >; deb << Logger::SubEntry << "mapping for" << partition->partitionPath() << partition->deviceNode() - << TR( "mtpoint:", PartitionInfo::mountPoint( partition ) ) - << TR( "fs:", map[ "fs" ].toString() ) - << TR( "fsname", map[ "fsName" ].toString() ) - << TR( "uuid", uuid ); + << TR( "mtpoint:", PartitionInfo::mountPoint( partition ) ) << TR( "fs:", map[ "fs" ].toString() ) + << TR( "fsname", map[ "fsName" ].toString() ) << TR( "uuid", uuid ); if ( partition->roles().has( PartitionRole::Luks ) ) { @@ -140,7 +143,7 @@ FillGlobalStorageJob::prettyDescription() const QStringList lines; const auto partitionList = createPartitionList().toList(); - for ( const QVariant &partitionItem : partitionList ) + for ( const QVariant& partitionItem : partitionList ) { if ( partitionItem.type() == QVariant::Map ) { @@ -149,32 +152,42 @@ FillGlobalStorageJob::prettyDescription() const QString mountPoint = partitionMap.value( "mountPoint" ).toString(); QString fsType = partitionMap.value( "fs" ).toString(); if ( mountPoint.isEmpty() || fsType.isEmpty() ) + { continue; + } if ( path.isEmpty() ) { if ( mountPoint == "/" ) + { lines.append( tr( "Install %1 on new %2 system partition." ) - .arg( *Calamares::Branding::ShortProductName ) - .arg( fsType ) ); + .arg( *Calamares::Branding::ShortProductName ) + .arg( fsType ) ); + } else + { lines.append( tr( "Set up new %2 partition with mount point " "%1." ) - .arg( mountPoint ) - .arg( fsType ) ); + .arg( mountPoint ) + .arg( fsType ) ); + } } else { if ( mountPoint == "/" ) + { lines.append( tr( "Install %2 on %3 system partition %1." ) - .arg( path ) - .arg( *Calamares::Branding::ShortProductName ) - .arg( fsType ) ); + .arg( path ) + .arg( *Calamares::Branding::ShortProductName ) + .arg( fsType ) ); + } else + { lines.append( tr( "Set up %3 partition %1 with mount point " "%2." ) - .arg( path ) - .arg( mountPoint ) - .arg( fsType ) ); + .arg( path ) + .arg( mountPoint ) + .arg( fsType ) ); + } } } } @@ -182,8 +195,7 @@ FillGlobalStorageJob::prettyDescription() const QVariant bootloaderMap = createBootLoaderMap(); if ( !m_bootLoaderPath.isEmpty() ) { - lines.append( tr( "Install boot loader on %1." ) - .arg( m_bootLoaderPath ) ); + lines.append( tr( "Install boot loader on %1." ).arg( m_bootLoaderPath ) ); } return lines.join( "
" ); } @@ -204,7 +216,9 @@ FillGlobalStorageJob::exec() { QVariant var = createBootLoaderMap(); if ( !var.isValid() ) + { cDebug() << "Failed to find path for boot loader"; + } cDebug() << "FillGlobalStorageJob writing bootLoader path:" << var; storage->insert( "bootLoader", var ); } @@ -225,8 +239,7 @@ FillGlobalStorageJob::createPartitionList() const for ( auto device : m_devices ) { cDebug() << Logger::SubEntry << "partitions on" << device->deviceNode(); - for ( auto it = PartitionIterator::begin( device ); - it != PartitionIterator::end( device ); ++it ) + for ( auto it = PartitionIterator::begin( device ); it != PartitionIterator::end( device ); ++it ) { // Debug-logging is done when creating the map lst << mapForPartition( *it, hash.value( ( *it )->partitionPath() ) ); @@ -244,7 +257,9 @@ FillGlobalStorageJob::createBootLoaderMap() const { Partition* partition = KPMHelpers::findPartitionByMountPoint( m_devices, path ); if ( !partition ) + { return QVariant(); + } path = partition->partitionPath(); } map[ "installPath" ] = path; From 29894cec6ae2f21cafe849b940c2b87a5dff4018 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:22:09 +0100 Subject: [PATCH 112/119] [partition] Convenience userVisibleFS() - Mark uses of filesystem-name where it's intentional that they are user-visible, with a new convenience function. --- src/modules/partition/core/KPMHelpers.h | 12 ++++++++++++ src/modules/partition/jobs/CreatePartitionJob.cpp | 13 +++++++++---- src/modules/partition/jobs/FillGlobalStorageJob.cpp | 5 +++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/modules/partition/core/KPMHelpers.h b/src/modules/partition/core/KPMHelpers.h index 7ef9718ae..bb510cafb 100644 --- a/src/modules/partition/core/KPMHelpers.h +++ b/src/modules/partition/core/KPMHelpers.h @@ -127,6 +127,18 @@ untranslatedFS( FileSystem* fs ) return fs ? untranslatedFS( *fs ) : QString(); } +static inline QString +userVisibleFS( FileSystem& fs ) +{ + return fs.name(); +} + +static inline QString +userVisibleFS( FileSystem* fs ) +{ + return fs ? userVisibleFS( *fs ) : QString(); +} + } #endif /* KPMHELPERS_H */ diff --git a/src/modules/partition/jobs/CreatePartitionJob.cpp b/src/modules/partition/jobs/CreatePartitionJob.cpp index 9f8a01004..b59bffcdc 100644 --- a/src/modules/partition/jobs/CreatePartitionJob.cpp +++ b/src/modules/partition/jobs/CreatePartitionJob.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2015, Teo Mrnjavac - * Copyright 2017, Adriaan de Groot + * Copyright 2017, 2020, 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 @@ -20,6 +20,8 @@ #include "jobs/CreatePartitionJob.h" +#include "core/KPMHelpers.h" + #include "utils/Logger.h" #include "utils/Units.h" @@ -32,6 +34,9 @@ #include #include +using KPMHelpers::untranslatedFS; +using KPMHelpers::userVisibleFS; + CreatePartitionJob::CreatePartitionJob( Device* device, Partition* partition ) : PartitionJob( partition ) , m_device( device ) @@ -42,7 +47,7 @@ QString CreatePartitionJob::prettyName() const { return tr( "Create new %2MiB partition on %4 (%3) with file system %1." ) - .arg( m_partition->fileSystem().name() ) + .arg( userVisibleFS( m_partition->fileSystem() ) .arg( CalamaresUtils::BytesToMiB( m_partition->capacity() ) ) .arg( m_device->name() ) .arg( m_device->deviceNode() ); @@ -54,7 +59,7 @@ CreatePartitionJob::prettyDescription() const { return tr( "Create new %2MiB partition on %4 " "(%3) with file system %1." ) - .arg( m_partition->fileSystem().name() ) + .arg( userVisibleFS( m_partition->fileSystem() ) ) .arg( CalamaresUtils::BytesToMiB( m_partition->capacity() ) ) .arg( m_device->name() ) .arg( m_device->deviceNode() ); @@ -65,7 +70,7 @@ QString CreatePartitionJob::prettyStatusMessage() const { return tr( "Creating new %1 partition on %2." ) - .arg( m_partition->fileSystem().name() ) + .arg( userVisibleFS( m_partition->fileSystem() ) ) .arg( m_device->deviceNode() ); } diff --git a/src/modules/partition/jobs/FillGlobalStorageJob.cpp b/src/modules/partition/jobs/FillGlobalStorageJob.cpp index 7faa4b50f..12faaf969 100644 --- a/src/modules/partition/jobs/FillGlobalStorageJob.cpp +++ b/src/modules/partition/jobs/FillGlobalStorageJob.cpp @@ -42,6 +42,7 @@ #include using KPMHelpers::untranslatedFS; +using KPMHelpers::userVisibleFS; typedef QHash< QString, QString > UuidForPartitionHash; @@ -91,7 +92,7 @@ mapForPartition( Partition* partition, const QString& uuid ) QVariantMap map; map[ "device" ] = partition->partitionPath(); map[ "mountPoint" ] = PartitionInfo::mountPoint( partition ); - map[ "fsName" ] = partition->fileSystem().name(); // User-visible + map[ "fsName" ] = userVisibleFS( partition->fileSystem() ); map[ "fs" ] = untranslatedFS( partition->fileSystem() ); if ( partition->fileSystem().type() == FileSystem::Luks && dynamic_cast< FS::luks& >( partition->fileSystem() ).innerFS() ) @@ -106,7 +107,7 @@ mapForPartition( Partition* partition, const QString& uuid ) using TR = Logger::DebugRow< const char* const, const QString& >; deb << Logger::SubEntry << "mapping for" << partition->partitionPath() << partition->deviceNode() << TR( "mtpoint:", PartitionInfo::mountPoint( partition ) ) << TR( "fs:", map[ "fs" ].toString() ) - << TR( "fsname", map[ "fsName" ].toString() ) << TR( "uuid", uuid ); + << TR( "fsName", map[ "fsName" ].toString() ) << TR( "uuid", uuid ); if ( partition->roles().has( PartitionRole::Luks ) ) { From bacca0469570f7e40bf820a3bdcdc60cbb0f2c0e Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:29:45 +0100 Subject: [PATCH 113/119] [partition] Be explicit about what's user visible in SetPartitionFlagsJob --- .../partition/jobs/SetPartitionFlagsJob.cpp | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/modules/partition/jobs/SetPartitionFlagsJob.cpp b/src/modules/partition/jobs/SetPartitionFlagsJob.cpp index d79f70479..09380a24c 100644 --- a/src/modules/partition/jobs/SetPartitionFlagsJob.cpp +++ b/src/modules/partition/jobs/SetPartitionFlagsJob.cpp @@ -21,6 +21,8 @@ #include "SetPartitionFlagsJob.h" +#include "core/KPMHelpers.h" + #include "utils/Logger.h" #include "utils/Units.h" @@ -32,6 +34,8 @@ #include using CalamaresUtils::BytesToMiB; +using KPMHelpers::untranslatedFS; +using KPMHelpers::userVisibleFS; SetPartFlagsJob::SetPartFlagsJob( Device* device, Partition* partition, @@ -48,10 +52,11 @@ SetPartFlagsJob::prettyName() const if ( !partition()->partitionPath().isEmpty() ) return tr( "Set flags on partition %1." ).arg( partition()->partitionPath() ); - if ( !partition()->fileSystem().name().isEmpty() ) + QString fsNameForUser = userVisibleFS( partition()->fileSystem() ); + if ( !fsNameForUser.isEmpty() ) return tr( "Set flags on %1MiB %2 partition." ) .arg( BytesToMiB( partition()->capacity() ) ) - .arg( partition()->fileSystem().name() ); + .arg( fsNameForUser ); return tr( "Set flags on new partition." ); } @@ -67,10 +72,11 @@ SetPartFlagsJob::prettyDescription() const return tr( "Clear flags on partition %1." ) .arg( partition()->partitionPath() ); - if ( !partition()->fileSystem().name().isEmpty() ) + QString fsNameForUser = userVisibleFS( partition()->fileSystem() ); + if ( !fsNameForUser.isEmpty() ) return tr( "Clear flags on %1MiB %2 partition." ) .arg( BytesToMiB( partition()->capacity() ) ) - .arg( partition()->fileSystem().name() ); + .arg( fsNameForUser ); return tr( "Clear flags on new partition." ); } @@ -81,11 +87,12 @@ SetPartFlagsJob::prettyDescription() const .arg( partition()->partitionPath() ) .arg( flagsList.join( ", " ) ); - if ( !partition()->fileSystem().name().isEmpty() ) + QString fsNameForUser = userVisibleFS( partition()->fileSystem() ); + if ( !fsNameForUser.isEmpty() ) return tr( "Flag %1MiB %2 partition as " "%3." ) .arg( BytesToMiB( partition()->capacity() ) ) - .arg( partition()->fileSystem().name() ) + .arg( fsNameForUser ) .arg( flagsList.join( ", " ) ); return tr( "Flag new partition as %1." ) @@ -103,10 +110,11 @@ SetPartFlagsJob::prettyStatusMessage() const return tr( "Clearing flags on partition %1." ) .arg( partition()->partitionPath() ); - if ( !partition()->fileSystem().name().isEmpty() ) + QString fsNameForUser = userVisibleFS( partition()->fileSystem() ); + if ( !fsNameForUser.isEmpty() ) return tr( "Clearing flags on %1MiB %2 partition." ) .arg( BytesToMiB( partition()->capacity() ) ) - .arg( partition()->fileSystem().name() ); + .arg( fsNameForUser ); return tr( "Clearing flags on new partition." ); } @@ -117,11 +125,12 @@ SetPartFlagsJob::prettyStatusMessage() const .arg( partition()->partitionPath() ) .arg( flagsList.join( ", " ) ); - if ( !partition()->fileSystem().name().isEmpty() ) + QString fsNameForUser = userVisibleFS( partition()->fileSystem() ); + if ( !fsNameForUser.isEmpty() ) return tr( "Setting flags %3 on " "%1MiB %2 partition." ) .arg( BytesToMiB( partition()->capacity() ) ) - .arg( partition()->fileSystem().name() ) + .arg( fsNameForUser ) .arg( flagsList.join( ", " ) ); return tr( "Setting flags %1 on new partition." ) From 88cff387c307daf88dfb7ba4b090bf0d08c977a2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:33:40 +0100 Subject: [PATCH 114/119] [partition] Be explicit about user-visible FS names, FormatPartitionJob --- src/modules/partition/jobs/FormatPartitionJob.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/modules/partition/jobs/FormatPartitionJob.cpp b/src/modules/partition/jobs/FormatPartitionJob.cpp index 0d43dfdb3..c877343c3 100644 --- a/src/modules/partition/jobs/FormatPartitionJob.cpp +++ b/src/modules/partition/jobs/FormatPartitionJob.cpp @@ -19,6 +19,8 @@ #include "jobs/FormatPartitionJob.h" +#include "core/KPMHelpers.h" + #include "utils/Logger.h" // KPMcore @@ -29,6 +31,9 @@ #include #include +using KPMHelpers::untranslatedFS; +using KPMHelpers::userVisibleFS; + FormatPartitionJob::FormatPartitionJob( Device* device, Partition* partition ) : PartitionJob( partition ) , m_device( device ) @@ -40,7 +45,7 @@ FormatPartitionJob::prettyName() const { return tr( "Format partition %1 (file system: %2, size: %3 MiB) on %4." ) .arg( m_partition->partitionPath() ) - .arg( m_partition->fileSystem().name() ) + .arg( userVisibleFS( m_partition->fileSystem() ) ) .arg( m_partition->capacity() / 1024 / 1024 ) .arg( m_device->name() ); } @@ -52,7 +57,7 @@ FormatPartitionJob::prettyDescription() const return tr( "Format %3MiB partition %1 with " "file system %2." ) .arg( m_partition->partitionPath() ) - .arg( m_partition->fileSystem().name() ) + .arg( userVisibleFS( m_partition->fileSystem() ) ) .arg( m_partition->capacity() / 1024 / 1024 ); } @@ -63,7 +68,7 @@ FormatPartitionJob::prettyStatusMessage() const return tr( "Formatting partition %1 with " "file system %2." ) .arg( m_partition->partitionPath() ) - .arg( m_partition->fileSystem().name() ); + .arg( userVisibleFS( m_partition->fileSystem() ) ); } From 05dfc24af675d04692148787f526914f7851f506 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:45:04 +0100 Subject: [PATCH 115/119] [partition] Be explicit about user-visible FS names, CreatePartitionDialog --- src/modules/partition/gui/CreatePartitionDialog.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/partition/gui/CreatePartitionDialog.cpp b/src/modules/partition/gui/CreatePartitionDialog.cpp index 7823d743d..b85d3e7e8 100644 --- a/src/modules/partition/gui/CreatePartitionDialog.cpp +++ b/src/modules/partition/gui/CreatePartitionDialog.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2016, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018, 2020, Adriaan de Groot * Copyright 2018, Andrius Štikonas * Copyright 2018, Caio Carvalho * @@ -106,7 +106,7 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par if ( fs->supportCreate() != FileSystem::cmdSupportNone && fs->type() != FileSystem::Extended ) { - fsNames << fs->name(); + fsNames << KPMHelpers::userVisibleFS( fs ); // This is put into the combobox if ( fs->type() == defaultFsType ) defaultFsIndex = fsCounter; fsCounter++; @@ -232,6 +232,7 @@ CreatePartitionDialog::updateMountPointUi() bool enabled = m_ui->primaryRadioButton->isChecked(); if ( enabled ) { + // This maps translated (user-visible) FS names to a type FileSystem::Type type = FileSystem::typeForName( m_ui->fsComboBox->currentText() ); enabled = !s_unmountableFS.contains( type ); From 472ec3261774447cdd5c7977b39384bcaebf08e3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 11:49:20 +0100 Subject: [PATCH 116/119] [partition] Be explicit about user-visible FS names, ReplaceWidget --- src/modules/partition/gui/ReplaceWidget.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/modules/partition/gui/ReplaceWidget.cpp b/src/modules/partition/gui/ReplaceWidget.cpp index 2ee360ced..3d0711761 100644 --- a/src/modules/partition/gui/ReplaceWidget.cpp +++ b/src/modules/partition/gui/ReplaceWidget.cpp @@ -22,6 +22,7 @@ #include "ui_ReplaceWidget.h" #include "core/DeviceModel.h" +#include "core/KPMHelpers.h" #include "core/PartitionCoreModule.h" #include "core/PartitionActions.h" #include "core/PartitionInfo.h" @@ -192,8 +193,8 @@ ReplaceWidget::onPartitionSelected() return; } - QString prettyName = tr( "Data partition (%1)" ) - .arg( partition->fileSystem().name() ); + QString fsNameForUser = KPMHelpers::userVisibleFS( partition->fileSystem() ); + QString prettyName = tr( "Data partition (%1)" ).arg( fsNameForUser ); for ( const QString& line : osproberLines ) { QStringList lineColumns = line.split( ':' ); @@ -210,13 +211,13 @@ ReplaceWidget::onPartitionSelected() if ( osName.isEmpty() ) { prettyName = tr( "Unknown system partition (%1)" ) - .arg( partition->fileSystem().name() ); + .arg( fsNameForUser ); } else { prettyName = tr ( "%1 system partition (%2)" ) .arg( osName.replace( 0, 1, osName.at( 0 ).toUpper() ) ) - .arg( partition->fileSystem().name() ); + .arg( fsNameForUser ); } break; } From ca67534cd23ab0490fde778e96ae372ead036c5b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 13:15:06 +0100 Subject: [PATCH 117/119] [partition] Improve logging of bad configs --- src/modules/partition/gui/PartitionViewStep.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 17ac339e9..1bb7f64fd 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -600,7 +600,7 @@ PartitionViewStep::setConfigurationMap( const QVariantMap& configurationMap ) else if ( fsType != FileSystem::Unknown ) cWarning() << "Partition-module setting *defaultFileSystemType* changed" << fsRealName; else - cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << fsRealName << ") using ext4."; + cWarning() << "Partition-module setting *defaultFileSystemType* is bad (" << fsName << ") using" << fsRealName << "instead."; gs->insert( "defaultFileSystemType", fsRealName ); From 57b608083e1ab4b0ae79f8fb27bad6f8848d6ba2 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 13:24:09 +0100 Subject: [PATCH 118/119] [partition] Fix build - missing ) --- src/modules/partition/jobs/CreatePartitionJob.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/partition/jobs/CreatePartitionJob.cpp b/src/modules/partition/jobs/CreatePartitionJob.cpp index b59bffcdc..0f9590bfd 100644 --- a/src/modules/partition/jobs/CreatePartitionJob.cpp +++ b/src/modules/partition/jobs/CreatePartitionJob.cpp @@ -47,7 +47,7 @@ QString CreatePartitionJob::prettyName() const { return tr( "Create new %2MiB partition on %4 (%3) with file system %1." ) - .arg( userVisibleFS( m_partition->fileSystem() ) + .arg( userVisibleFS( m_partition->fileSystem() ) ) .arg( CalamaresUtils::BytesToMiB( m_partition->capacity() ) ) .arg( m_device->name() ) .arg( m_device->deviceNode() ); From 5a50a3a40ca6a4749b7d4e38da6642b03d6dad19 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 13 Feb 2020 13:24:53 +0100 Subject: [PATCH 119/119] [partition] Consistent FS name usage - explicit use of user-visible names in EditExistingPartitionDialog - consistent conversion of config-values to FS names (user-visible). The GS value comes from the ViewStep, and should always match something -- it's already converted to the canonical un-translated so the type should be good. --- .../partition/gui/CreatePartitionDialog.cpp | 14 +++++-- .../gui/EditExistingPartitionDialog.cpp | 41 +++++++++++-------- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/modules/partition/gui/CreatePartitionDialog.cpp b/src/modules/partition/gui/CreatePartitionDialog.cpp index b85d3e7e8..926df03a3 100644 --- a/src/modules/partition/gui/CreatePartitionDialog.cpp +++ b/src/modules/partition/gui/CreatePartitionDialog.cpp @@ -93,11 +93,17 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par else initGptPartitionTypeUi(); - // File system - FileSystem::Type defaultFsType = FileSystem::typeForName( + // File system; the config value is translated (best-effort) to a type + FileSystem::Type defaultFSType; + QString untranslatedFSName = PartUtils::findFS( Calamares::JobQueue::instance()-> globalStorage()-> - value( "defaultFileSystemType" ).toString() ); + value( "defaultFileSystemType" ).toString(), &defaultFSType ); + if ( defaultFSType == FileSystem::Type::Unknown ) + { + defaultFSType = FileSystem::Type::Ext4; + } + int defaultFsIndex = -1; int fsCounter = 0; QStringList fsNames; @@ -107,7 +113,7 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par fs->type() != FileSystem::Extended ) { fsNames << KPMHelpers::userVisibleFS( fs ); // This is put into the combobox - if ( fs->type() == defaultFsType ) + if ( fs->type() == defaultFSType ) defaultFsIndex = fsCounter; fsCounter++; } diff --git a/src/modules/partition/gui/EditExistingPartitionDialog.cpp b/src/modules/partition/gui/EditExistingPartitionDialog.cpp index 3ad5080b4..6268a2a22 100644 --- a/src/modules/partition/gui/EditExistingPartitionDialog.cpp +++ b/src/modules/partition/gui/EditExistingPartitionDialog.cpp @@ -2,7 +2,7 @@ * * Copyright 2014, Aurélien Gâteau * Copyright 2016, Teo Mrnjavac - * Copyright 2018, Adriaan de Groot + * Copyright 2018, 2020, Adriaan de Groot * * Flags handling originally from KDE Partition Manager, * Copyright 2008-2009, Volker Lanz @@ -22,21 +22,21 @@ * along with Calamares. If not, see . */ -#include +#include "EditExistingPartitionDialog.h" -#include -#include -#include +#include "core/ColorUtils.h" +#include "core/PartitionCoreModule.h" +#include "core/PartitionInfo.h" #include "core/PartUtils.h" -#include +#include "core/KPMHelpers.h" #include "gui/PartitionDialogHelpers.h" -#include +#include "gui/PartitionSizeController.h" -#include +#include "ui_EditExistingPartitionDialog.h" -#include #include "GlobalStorage.h" #include "JobQueue.h" +#include "utils/Logger.h" // KPMcore #include @@ -77,7 +77,7 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit m_ui->fileSystemComboBox->setEnabled( doFormat ); if ( !doFormat ) - m_ui->fileSystemComboBox->setCurrentText( m_partition->fileSystem().name() ); + m_ui->fileSystemComboBox->setCurrentText( KPMHelpers::userVisibleFS( m_partition->fileSystem() ) ); updateMountPointPicker(); } ); @@ -93,16 +93,25 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit for ( auto fs : FileSystemFactory::map() ) { if ( fs->supportCreate() != FileSystem::cmdSupportNone && fs->type() != FileSystem::Extended ) - fsNames << fs->name(); + fsNames << KPMHelpers::userVisibleFS( fs ); // For the combo box } m_ui->fileSystemComboBox->addItems( fsNames ); - if ( fsNames.contains( m_partition->fileSystem().name() ) ) - m_ui->fileSystemComboBox->setCurrentText( m_partition->fileSystem().name() ); + FileSystem::Type defaultFSType; + QString untranslatedFSName = PartUtils::findFS( + Calamares::JobQueue::instance()-> + globalStorage()-> + value( "defaultFileSystemType" ).toString(), &defaultFSType ); + if ( defaultFSType == FileSystem::Type::Unknown ) + { + defaultFSType = FileSystem::Type::Ext4; + } + + QString thisFSNameForUser = KPMHelpers::userVisibleFS( m_partition->fileSystem() ); + if ( fsNames.contains( thisFSNameForUser ) ) + m_ui->fileSystemComboBox->setCurrentText( thisFSNameForUser ); else - m_ui->fileSystemComboBox->setCurrentText( Calamares::JobQueue::instance()-> - globalStorage()-> - value( "defaultFileSystemType" ).toString() ); + m_ui->fileSystemComboBox->setCurrentText( FileSystem::nameForType( defaultFSType ) ); m_ui->fileSystemLabel->setEnabled( m_ui->formatRadioButton->isChecked() ); m_ui->fileSystemComboBox->setEnabled( m_ui->formatRadioButton->isChecked() );