mirror of https://github.com/cutefishos/calamares
Merge branch 'requirements-checking'
commit
8cf3c217f7
@ -0,0 +1,19 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2017, 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 "Requirement.h"
|
||||
|
@ -0,0 +1,64 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2017, 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_REQUIREMENT_H
|
||||
#define CALAMARES_REQUIREMENT_H
|
||||
|
||||
#include <QList>
|
||||
#include <QMetaType>
|
||||
#include <QString>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
|
||||
/**
|
||||
* An indication of a requirement, which is checked in preparation
|
||||
* for system installation. An entry has a name and some explanation functions
|
||||
* (functions, because they need to respond to translations).
|
||||
*
|
||||
* A requirement can be *satisfied* or not.
|
||||
* A requirement can be optional (i.e. a "good to have") or mandatory.
|
||||
*
|
||||
* Requirements which are not satisfied, and also mandatory, will prevent the
|
||||
* installation from proceeding.
|
||||
*/
|
||||
struct RequirementEntry
|
||||
{
|
||||
using TextFunction = std::function< QString() >;
|
||||
|
||||
/// @brief name of this requirement; not shown to user and used as ID
|
||||
QString name;
|
||||
|
||||
/// @brief Description of this requirement, for use in user-visible lists
|
||||
TextFunction enumerationText;
|
||||
|
||||
/// @brief User-visible string to show that the requirement is not met
|
||||
TextFunction negatedText;
|
||||
|
||||
bool satisfied;
|
||||
bool mandatory;
|
||||
};
|
||||
|
||||
using RequirementsList = QList< RequirementEntry >;
|
||||
|
||||
} // namespace Calamares
|
||||
|
||||
Q_DECLARE_METATYPE(Calamares::RequirementEntry)
|
||||
|
||||
#endif
|
@ -0,0 +1,154 @@
|
||||
/* === 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 <algorithm>
|
||||
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
namespace Calamares
|
||||
{
|
||||
|
||||
static void
|
||||
registerMetatypes()
|
||||
{
|
||||
static bool done = false;
|
||||
|
||||
if ( !done )
|
||||
{
|
||||
qRegisterMetaType< RequirementEntry >( "RequirementEntry" );
|
||||
// It's sensitive to the names of types in parameters; in particular
|
||||
// althrough QList<RequirementEntry> is the same as RequirementsList,
|
||||
// because we *name* the type as RequirementsList in the parameters,
|
||||
// we need to register that (as well). Here, be safe and register
|
||||
// both names.
|
||||
qRegisterMetaType< QList< RequirementEntry > >( "QList<RequirementEntry>" );
|
||||
qRegisterMetaType< RequirementsList >( "RequirementsList" );
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
check( Module * const &m, RequirementsChecker *c )
|
||||
{
|
||||
RequirementsList l = m->checkRequirements();
|
||||
if ( l.count() > 0 )
|
||||
c->addCheckedRequirements( l );
|
||||
c->requirementsProgress( QObject::tr( "Requirements checking for module <i>%1</i> is complete." ).arg( m->name() ) );
|
||||
}
|
||||
|
||||
RequirementsChecker::RequirementsChecker( QVector< Module* > modules, QObject* parent )
|
||||
: QObject( parent )
|
||||
, m_modules( std::move( modules ) )
|
||||
, m_progressTimer( nullptr )
|
||||
, m_progressTimeouts( 0 )
|
||||
{
|
||||
m_watchers.reserve( m_modules.count() );
|
||||
m_collectedRequirements.reserve( m_modules.count() );
|
||||
|
||||
registerMetatypes();
|
||||
}
|
||||
|
||||
RequirementsChecker::~RequirementsChecker()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
RequirementsChecker::run()
|
||||
{
|
||||
m_progressTimer = new QTimer( this );
|
||||
connect( m_progressTimer, &QTimer::timeout, this, &RequirementsChecker::reportProgress );
|
||||
m_progressTimer->start( 1200 ); // msec
|
||||
|
||||
for (const auto& module : m_modules )
|
||||
{
|
||||
Watcher *watcher = new Watcher( this );
|
||||
watcher->setFuture( QtConcurrent::run( check, module, this ) );
|
||||
m_watchers.append( watcher );
|
||||
connect( watcher, &Watcher::finished, this, &RequirementsChecker::finished );
|
||||
}
|
||||
|
||||
QTimer::singleShot( 0, this, &RequirementsChecker::finished );
|
||||
}
|
||||
|
||||
void
|
||||
RequirementsChecker::finished()
|
||||
{
|
||||
if ( std::all_of( m_watchers.cbegin(), m_watchers.cend(), []( const Watcher *w ) { return w && w->isFinished(); } ) )
|
||||
{
|
||||
cDebug() << "All requirements have been checked.";
|
||||
|
||||
if ( m_progressTimer )
|
||||
m_progressTimer->stop();
|
||||
|
||||
bool acceptable = true;
|
||||
int count = 0;
|
||||
for ( const auto& r : m_collectedRequirements )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RequirementsChecker::addCheckedRequirements( RequirementsList l )
|
||||
{
|
||||
static QMutex addMutex;
|
||||
{
|
||||
QMutexLocker lock( &addMutex );
|
||||
m_collectedRequirements.append( l );
|
||||
}
|
||||
cDebug() << "Added" << l.count() << "requirement results";
|
||||
emit requirementsResult( l );
|
||||
}
|
||||
|
||||
void
|
||||
RequirementsChecker::reportProgress()
|
||||
{
|
||||
m_progressTimeouts++;
|
||||
|
||||
auto remaining = std::count_if( m_watchers.cbegin(), m_watchers.cend(), []( const Watcher *w ) { return w && !w->isFinished(); } );
|
||||
if ( remaining > 0 )
|
||||
{
|
||||
QString waiting = tr( "Waiting for %n module(s).", "", remaining );
|
||||
QString elapsed = tr( "(%n second(s))", "", m_progressTimeouts * m_progressTimer->interval() / 1000 );
|
||||
emit requirementsProgress( waiting + QString( " " ) + elapsed );
|
||||
}
|
||||
else
|
||||
emit requirementsProgress( tr( "System-requirements checking is complete." ) );
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
/* === 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 "Requirement.h"
|
||||
|
||||
#include <QFutureWatcher>
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
#include <QVector>
|
||||
|
||||
|
||||
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:
|
||||
/// @brief Start checking all the requirements
|
||||
void run();
|
||||
|
||||
/// @brief Called when requirements are reported by a module
|
||||
void addCheckedRequirements( RequirementsList );
|
||||
|
||||
/// @brief Called when all requirements have been checked
|
||||
void finished();
|
||||
|
||||
/// @brief Called periodically while requirements are being checked
|
||||
void reportProgress();
|
||||
|
||||
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;
|
||||
|
||||
using Watcher = QFutureWatcher< void >;
|
||||
QVector< Watcher* > m_watchers;
|
||||
|
||||
RequirementsList m_collectedRequirements;
|
||||
|
||||
QTimer *m_progressTimer;
|
||||
unsigned m_progressTimeouts;
|
||||
} ;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,78 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014-2017, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
||||
* Copyright 2017, Gabriel Craciunescu <crazy@frugalware.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/>.
|
||||
*/
|
||||
|
||||
/* Based on code extracted from RequirementsChecker.cpp */
|
||||
|
||||
#include "CheckerContainer.h"
|
||||
|
||||
#include "CheckerWidget.h"
|
||||
|
||||
#include "utils/CalamaresUtilsGui.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Retranslator.h"
|
||||
#include "widgets/WaitingWidget.h"
|
||||
|
||||
CheckerContainer::CheckerContainer(QWidget* parent)
|
||||
: QWidget( parent )
|
||||
, m_waitingWidget( new WaitingWidget( QString() ) )
|
||||
, m_checkerWidget( new CheckerWidget() )
|
||||
, m_verdict( false )
|
||||
{
|
||||
QBoxLayout* mainLayout = new QHBoxLayout;
|
||||
setLayout( mainLayout );
|
||||
CalamaresUtils::unmarginLayout( mainLayout );
|
||||
|
||||
mainLayout->addWidget( m_waitingWidget );
|
||||
CALAMARES_RETRANSLATE( m_waitingWidget->setText( tr( "Gathering system information..." ) ); )
|
||||
}
|
||||
|
||||
CheckerContainer::~CheckerContainer()
|
||||
{
|
||||
delete m_waitingWidget;
|
||||
delete m_checkerWidget;
|
||||
}
|
||||
|
||||
void CheckerContainer::requirementsComplete( bool ok )
|
||||
{
|
||||
m_checkerWidget->init( m_requirements );
|
||||
layout()->removeWidget( m_waitingWidget );
|
||||
m_waitingWidget->deleteLater();
|
||||
m_waitingWidget = nullptr; // Don't delete in destructor
|
||||
m_checkerWidget->setParent( this );
|
||||
layout()->addWidget( m_checkerWidget );
|
||||
|
||||
m_verdict = ok;
|
||||
}
|
||||
|
||||
void CheckerContainer::requirementsChecked(const Calamares::RequirementsList& l)
|
||||
{
|
||||
m_requirements.append( l );
|
||||
}
|
||||
|
||||
void CheckerContainer::requirementsProgress(const QString& message)
|
||||
{
|
||||
if ( m_waitingWidget )
|
||||
m_waitingWidget->setText( message );
|
||||
}
|
||||
|
||||
bool CheckerContainer::verdict() const
|
||||
{
|
||||
return m_verdict;
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014-2017, Teo Mrnjavac <teo@kde.org>
|
||||
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
||||
* Copyright 2017, Gabriel Craciunescu <crazy@frugalware.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/>.
|
||||
*/
|
||||
|
||||
/* Based on code extracted from RequirementsChecker.cpp */
|
||||
|
||||
#ifndef CHECKERCONTAINER_H
|
||||
#define CHECKERCONTAINER_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "modulesystem/Requirement.h"
|
||||
|
||||
class CheckerWidget;
|
||||
class WaitingWidget;
|
||||
|
||||
/**
|
||||
* A widget that collects requirements results; until the results are
|
||||
* all in, displays a spinner / waiting widget. Then it switches to
|
||||
* a (list) diplay of the results, plus some explanation of the
|
||||
* overall state of the entire list of results.
|
||||
*/
|
||||
class CheckerContainer : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CheckerContainer( QWidget* parent = nullptr );
|
||||
virtual ~CheckerContainer();
|
||||
|
||||
bool verdict() const;
|
||||
|
||||
public slots:
|
||||
void requirementsChecked( const Calamares::RequirementsList& );
|
||||
|
||||
/** @brief All the requirements are complete, switch to list view */
|
||||
void requirementsComplete( bool );
|
||||
|
||||
void requirementsProgress( const QString& message );
|
||||
|
||||
protected:
|
||||
WaitingWidget *m_waitingWidget;
|
||||
CheckerWidget *m_checkerWidget;
|
||||
|
||||
Calamares::RequirementsList m_requirements;
|
||||
bool m_verdict;
|
||||
} ;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue