diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index 7c3e8fca2..335dc712a 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -5,6 +5,7 @@ set( calamaresui_SOURCES modulesystem/Module.cpp modulesystem/ModuleManager.cpp modulesystem/ProcessJobModule.cpp + modulesystem/Requirement.cpp modulesystem/ViewModule.cpp utils/CalamaresUtilsGui.cpp diff --git a/src/libcalamaresui/modulesystem/Module.cpp b/src/libcalamaresui/modulesystem/Module.cpp index 0af30e08e..671881646 100644 --- a/src/libcalamaresui/modulesystem/Module.cpp +++ b/src/libcalamaresui/modulesystem/Module.cpp @@ -297,9 +297,10 @@ Module::initFrom( const QVariantMap& moduleDescriptor ) m_name = moduleDescriptor.value( "name" ).toString(); } -void +RequirementsList Module::checkRequirements() { + return RequirementsList(); } } //ns diff --git a/src/libcalamaresui/modulesystem/Module.h b/src/libcalamaresui/modulesystem/Module.h index 294b516e2..468475930 100644 --- a/src/libcalamaresui/modulesystem/Module.h +++ b/src/libcalamaresui/modulesystem/Module.h @@ -20,6 +20,7 @@ #ifndef CALAMARES_MODULE_H #define CALAMARES_MODULE_H +#include "Requirement.h" #include "UiDllMacro.h" #include @@ -165,7 +166,7 @@ public: /** * @brief Check the requirements of this module. */ - virtual void checkRequirements(); + virtual RequirementsList checkRequirements(); protected: explicit Module(); diff --git a/src/libcalamaresui/modulesystem/ModuleManager.cpp b/src/libcalamaresui/modulesystem/ModuleManager.cpp index 573cfa915..ac01b851a 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.cpp +++ b/src/libcalamaresui/modulesystem/ModuleManager.cpp @@ -318,14 +318,27 @@ ModuleManager::loadModules() void ModuleManager::checkRequirements() { + cDebug() << "Checking module requirements .."; QTimer::singleShot( 0, this, [ this ]() { + bool acceptable = true; + for (const auto& module : m_loadedModulesByInstanceKey ) { - module->checkRequirements(); + auto l = module->checkRequirements(); + if ( l.length() > 0 ) + { + cDebug() << " .." << module->name() << l.length() << "requirements"; + emit requirementsResult( l ); + } + for (const auto& r : l) + { + if (r.required && !r.checked) + acceptable = false; + } } - emit modulesChecked(); + emit requirementsComplete( acceptable ); } ); } diff --git a/src/libcalamaresui/modulesystem/ModuleManager.h b/src/libcalamaresui/modulesystem/ModuleManager.h index 9444b96f3..8eff846ce 100644 --- a/src/libcalamaresui/modulesystem/ModuleManager.h +++ b/src/libcalamaresui/modulesystem/ModuleManager.h @@ -19,6 +19,7 @@ #ifndef MODULELOADER_H #define MODULELOADER_H +#include "Requirement.h" #include "Typedefs.h" #include @@ -29,6 +30,7 @@ namespace Calamares { class Module; +class RequirementEntry; // from Requirement.h /** * @brief The ModuleManager class is a singleton which manages Calamares modules. @@ -89,7 +91,8 @@ public: signals: void initDone(); void modulesLoaded(); - void modulesChecked(); + void requirementsComplete( bool ); + void requirementsResult( RequirementsList& ); private slots: void doInit(); diff --git a/src/libcalamaresui/modulesystem/Requirement.cpp b/src/libcalamaresui/modulesystem/Requirement.cpp new file mode 100644 index 000000000..3347a2ae8 --- /dev/null +++ b/src/libcalamaresui/modulesystem/Requirement.cpp @@ -0,0 +1,19 @@ +/* === This file is part of Calamares - === + * + * Copyright 2017, 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 "Requirement.h" + diff --git a/src/libcalamaresui/modulesystem/Requirement.h b/src/libcalamaresui/modulesystem/Requirement.h new file mode 100644 index 000000000..a90d5775b --- /dev/null +++ b/src/libcalamaresui/modulesystem/Requirement.h @@ -0,0 +1,52 @@ +/* === This file is part of Calamares - === + * + * Copyright 2017, 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 CALAMARES_REQUIREMENT_H +#define CALAMARES_REQUIREMENT_H + +#include +#include + +#include + +namespace Calamares +{ + +/** + * An indication of a requirement, which is checked in preparation + * for system installation. An entry has a name and some explanation, + * as well as three meaningful states: + * - checked = true, the requirement is met (green) + * - checked = false, the requirement is not met + * - required = false, warn about it (yellow), no failure + * - required = true, prohibit installation (red) + */ +struct RequirementEntry +{ + QString name; + std::function< QString() > enumerationText; //Partial string, inserted in a + //list of requirements to satisfy. + std::function< QString() > negatedText; //Complete sentence about this requirement + //not having been met. + bool checked; + bool required; +}; + +using RequirementsList = QList< RequirementEntry >; + +} // namespace Calamares +#endif diff --git a/src/modules/welcome/WelcomeViewStep.cpp b/src/modules/welcome/WelcomeViewStep.cpp index 3c9d29993..755a74210 100644 --- a/src/modules/welcome/WelcomeViewStep.cpp +++ b/src/modules/welcome/WelcomeViewStep.cpp @@ -33,8 +33,6 @@ WelcomeViewStep::WelcomeViewStep( QObject* parent ) { emit nextStatusChanged( true ); m_widget = new WelcomePage( m_requirementsChecker ); - connect( m_requirementsChecker, &RequirementsChecker::verdictChanged, - this, &WelcomeViewStep::nextStatusChanged ); } diff --git a/src/modules/welcome/checker/CheckerWidget.cpp b/src/modules/welcome/checker/CheckerWidget.cpp index 2476847b6..44ac35982 100644 --- a/src/modules/welcome/checker/CheckerWidget.cpp +++ b/src/modules/welcome/checker/CheckerWidget.cpp @@ -53,12 +53,12 @@ CheckerWidget::CheckerWidget( QWidget* parent ) void -CheckerWidget::init( const QList< PrepareEntry >& checkEntries ) +CheckerWidget::init( const Calamares::RequirementsList& checkEntries ) { bool allChecked = true; bool requirementsSatisfied = true; - for ( const PrepareEntry& entry : checkEntries ) + for ( const auto& entry : checkEntries ) { if ( !entry.checked ) { @@ -162,7 +162,7 @@ CheckerWidget::init( const QList< PrepareEntry >& checkEntries ) void -CheckerWidget::showDetailsDialog( const QList< PrepareEntry >& checkEntries ) +CheckerWidget::showDetailsDialog( const Calamares::RequirementsList& checkEntries ) { QDialog* detailsDialog = new QDialog( this ); QBoxLayout* mainLayout = new QVBoxLayout; @@ -177,7 +177,7 @@ CheckerWidget::showDetailsDialog( const QList< PrepareEntry >& checkEntries ) CalamaresUtils::unmarginLayout( entriesLayout ); mainLayout->addLayout( entriesLayout ); - for ( const PrepareEntry& entry : checkEntries ) + for ( const auto& entry : checkEntries ) { if ( entry.enumerationText().isEmpty() ) continue; diff --git a/src/modules/welcome/checker/CheckerWidget.h b/src/modules/welcome/checker/CheckerWidget.h index 9e4accf23..922d6b0ea 100644 --- a/src/modules/welcome/checker/CheckerWidget.h +++ b/src/modules/welcome/checker/CheckerWidget.h @@ -19,6 +19,7 @@ #ifndef CHECKERWIDGET_H #define CHECKERWIDGET_H +#include "modulesystem/Requirement.h" #include "RequirementsChecker.h" #include @@ -30,10 +31,10 @@ class CheckerWidget : public QWidget public: explicit CheckerWidget( QWidget* parent = nullptr ); - void init( const QList< PrepareEntry >& checkEntries ); + void init( const Calamares::RequirementsList& checkEntries ); private: - void showDetailsDialog( const QList< PrepareEntry >& checkEntries ); + void showDetailsDialog( const Calamares::RequirementsList& checkEntries ); QBoxLayout* m_mainLayout; QBoxLayout* m_entriesLayout; diff --git a/src/modules/welcome/checker/RequirementsChecker.cpp b/src/modules/welcome/checker/RequirementsChecker.cpp index 741802fb5..e198b60c8 100644 --- a/src/modules/welcome/checker/RequirementsChecker.cpp +++ b/src/modules/welcome/checker/RequirementsChecker.cpp @@ -23,6 +23,7 @@ #include "CheckerWidget.h" #include "partman_devices.h" +#include "modulesystem/Requirement.h" #include "widgets/WaitingWidget.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" @@ -30,6 +31,7 @@ #include "utils/CalamaresUtilsSystem.h" #include "utils/Units.h" + #include "JobQueue.h" #include "GlobalStorage.h" @@ -107,7 +109,7 @@ RequirementsChecker::RequirementsChecker( QObject* parent ) << " hasInternet:" << hasInternet << " isRoot:" << isRoot; - QList< PrepareEntry > checkEntries; + Calamares::RequirementsList checkEntries; foreach ( const QString& entry, m_entriesToCheck ) { if ( entry == "storage" ) @@ -171,7 +173,7 @@ RequirementsChecker::RequirementsChecker( QObject* parent ) m_widget->layout()->addWidget( m_actualWidget ); bool canGoNext = true; - foreach ( const PrepareEntry& entry, checkEntries ) + foreach ( const auto& entry, checkEntries ) { if ( !entry.checked && entry.required ) { diff --git a/src/modules/welcome/checker/RequirementsChecker.h b/src/modules/welcome/checker/RequirementsChecker.h index 23ee39f74..e320d3f1d 100644 --- a/src/modules/welcome/checker/RequirementsChecker.h +++ b/src/modules/welcome/checker/RequirementsChecker.h @@ -23,31 +23,9 @@ #include #include -#include - class CheckerWidget; class QWidget; -/** - * An indication of a requirement, which is checked in preparation - * for system installation. An entry has a name and some explanation, - * as well as three meaningful states: - * - checked = true, the requirement is met (green) - * - checked = false, the requirement is not met - * - required = false, warn about it (yellow), no failure - * - required = true, prohibit installation (red) - */ -struct PrepareEntry -{ - QString name; - std::function< QString() > enumerationText; //Partial string, inserted in a - //list of requirements to satisfy. - std::function< QString() > negatedText; //Complete sentence about this requirement - //not having been met. - bool checked; - bool required; -}; - class RequirementsChecker : public QObject { Q_OBJECT