mirror of https://github.com/cutefishos/calamares
[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.main
parent
bbb9ff0cbf
commit
c678cd80b4
@ -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 );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -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