[libcalamaresui] Refactor Requirements-Checking
- Move the actual checking into a separate object with some lifecycle- management signals. - Right now this is still single-threaded and blocking, so no net gain.
This commit is contained in:
parent
bbb9ff0cbf
commit
c678cd80b4
@ -6,6 +6,7 @@ set( calamaresui_SOURCES
|
||||
modulesystem/ModuleManager.cpp
|
||||
modulesystem/ProcessJobModule.cpp
|
||||
modulesystem/Requirement.cpp
|
||||
modulesystem/RequirementsChecker.cpp
|
||||
modulesystem/ViewModule.cpp
|
||||
|
||||
utils/CalamaresUtilsGui.cpp
|
||||
|
@ -21,11 +21,13 @@
|
||||
|
||||
#include "ExecutionViewStep.h"
|
||||
#include "Module.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/YamlUtils.h"
|
||||
#include "RequirementsChecker.h"
|
||||
#include "Settings.h"
|
||||
#include "ViewManager.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/YamlUtils.h"
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include <QApplication>
|
||||
@ -306,32 +308,21 @@ void
|
||||
ModuleManager::checkRequirements()
|
||||
{
|
||||
cDebug() << "Checking module requirements ..";
|
||||
QTimer::singleShot( 0, this, [ this ]()
|
||||
|
||||
QVector< Module* > modules( m_loadedModulesByInstanceKey.count() );
|
||||
int count = 0;
|
||||
for (const auto& module : m_loadedModulesByInstanceKey )
|
||||
{
|
||||
bool acceptable = true;
|
||||
modules[count++] = module;
|
||||
}
|
||||
|
||||
for (const auto& module : m_loadedModulesByInstanceKey )
|
||||
{
|
||||
RequirementsList l = module->checkRequirements();
|
||||
if ( l.length() > 0 )
|
||||
{
|
||||
cDebug() << " .." << module->name() << "has" << l.length() << "requirements";
|
||||
emit requirementsResult( l );
|
||||
}
|
||||
int count = 0;
|
||||
for (const auto& r : l)
|
||||
{
|
||||
if ( r.mandatory && !r.satisfied )
|
||||
{
|
||||
cDebug() << " .. requirement" << count << r.name << "is not satisfied.";
|
||||
acceptable = false;
|
||||
}
|
||||
++count;
|
||||
}
|
||||
}
|
||||
RequirementsChecker *rq = new RequirementsChecker( modules, this );
|
||||
connect( rq, &RequirementsChecker::requirementsResult, this, &ModuleManager::requirementsResult );
|
||||
connect( rq, &RequirementsChecker::requirementsComplete, this, &ModuleManager::requirementsComplete );
|
||||
connect( rq, &RequirementsChecker::done, rq, &RequirementsChecker::deleteLater );
|
||||
connect( rq, &RequirementsChecker::requirementsProgress, this, &ModuleManager::requirementsProgress );
|
||||
|
||||
emit requirementsComplete( acceptable );
|
||||
} );
|
||||
QTimer::singleShot( 0, rq, &RequirementsChecker::run );
|
||||
}
|
||||
|
||||
QStringList
|
||||
|
@ -93,8 +93,10 @@ signals:
|
||||
void initDone();
|
||||
void modulesLoaded(); /// All of the modules were loaded successfully
|
||||
void modulesFailed( QStringList ); /// .. or not
|
||||
// Below, see RequirementsChecker documentation
|
||||
void requirementsComplete( bool );
|
||||
void requirementsResult( RequirementsList& );
|
||||
void requirementsProgress( const QString& );
|
||||
|
||||
private slots:
|
||||
void doInit();
|
||||
|
73
src/libcalamaresui/modulesystem/RequirementsChecker.cpp
Normal file
73
src/libcalamaresui/modulesystem/RequirementsChecker.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "RequirementsChecker.h"
|
||||
|
||||
#include "Module.h"
|
||||
#include "Requirement.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
|
||||
RequirementsChecker::RequirementsChecker( QVector< Module* > modules, QObject* parent )
|
||||
: QObject( parent )
|
||||
, m_modules( std::move( modules ) )
|
||||
{
|
||||
}
|
||||
|
||||
RequirementsChecker::~RequirementsChecker()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RequirementsChecker::run()
|
||||
{
|
||||
bool acceptable = true;
|
||||
|
||||
for (const auto& module : m_modules )
|
||||
{
|
||||
RequirementsList l = module->checkRequirements();
|
||||
if ( l.length() > 0 )
|
||||
{
|
||||
cDebug() << " .." << module->name() << "has" << l.length() << "requirements";
|
||||
emit requirementsResult( l );
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (const auto& r : l)
|
||||
{
|
||||
if ( r.mandatory && !r.satisfied )
|
||||
{
|
||||
cDebug() << " .. requirement" << count << r.name << "is not satisfied.";
|
||||
acceptable = false;
|
||||
}
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
emit requirementsComplete( acceptable );
|
||||
|
||||
QTimer::singleShot(0, this, &RequirementsChecker::done );
|
||||
}
|
||||
|
||||
|
||||
}
|
66
src/libcalamaresui/modulesystem/RequirementsChecker.h
Normal file
66
src/libcalamaresui/modulesystem/RequirementsChecker.h
Normal file
@ -0,0 +1,66 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2019, Adriaan de Groot <groot@kde.org>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef CALAMARES_REQUIREMENTSCHECKER_H
|
||||
#define CALAMARES_REQUIREMENTSCHECKER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVector>
|
||||
|
||||
#include "Requirement.h"
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
|
||||
class Module;
|
||||
|
||||
/** @brief A manager-class that checks all the module requirements
|
||||
*
|
||||
* Asynchronously checks the requirements for each module, and
|
||||
* emits progress signals as appropriate.
|
||||
*/
|
||||
class RequirementsChecker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RequirementsChecker( QVector< Module* > modules, QObject* parent = nullptr );
|
||||
virtual ~RequirementsChecker() override;
|
||||
|
||||
public slots:
|
||||
void run();
|
||||
|
||||
signals:
|
||||
/// @brief Human-readable progress message
|
||||
void requirementsProgress( const QString& );
|
||||
/// @brief Requirements from a single module
|
||||
void requirementsResult( RequirementsList& );
|
||||
/** @brief When all requirements are collected
|
||||
*
|
||||
* The argument indicates if all mandatory requirements are satisfied.
|
||||
*/
|
||||
void requirementsComplete( bool );
|
||||
/// @brief Emitted after requirementsComplete
|
||||
void done();
|
||||
|
||||
private:
|
||||
QVector< Module* > m_modules;
|
||||
} ;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user