Block the install process if an entry is required but unsatisfied.
This commit is contained in:
parent
87711c89fc
commit
5434a04ebc
@ -47,11 +47,11 @@ PreparePage::PreparePage( QWidget* parent )
|
||||
|
||||
|
||||
void
|
||||
PreparePage::init( const QList< QPair< QString, bool > > &checkEntries )
|
||||
PreparePage::init( const QList< PrepareEntry >& checkEntries )
|
||||
{
|
||||
for ( const QPair< QString, bool >& entry : checkEntries )
|
||||
for ( const PrepareEntry& entry : checkEntries )
|
||||
{
|
||||
PrepareCheckWidget* pcw = new PrepareCheckWidget( entry.first, entry.second );
|
||||
PrepareCheckWidget* pcw = new PrepareCheckWidget( entry.text, entry.checked );
|
||||
m_entriesLayout->addWidget( pcw );
|
||||
pcw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
#ifndef PREPAREPAGE_H
|
||||
#define PREPAREPAGE_H
|
||||
|
||||
#include "PrepareViewStep.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
@ -28,7 +30,7 @@ class PreparePage : public QWidget
|
||||
public:
|
||||
explicit PreparePage( QWidget* parent = nullptr );
|
||||
|
||||
void init( const QList< QPair< QString, bool > >& checkEntries );
|
||||
void init( const QList< PrepareEntry >& checkEntries );
|
||||
|
||||
private:
|
||||
QBoxLayout* m_entriesLayout;
|
||||
|
@ -82,43 +82,82 @@ PrepareViewStep::PrepareViewStep( QObject* parent )
|
||||
connect( timer, &QTimer::timeout,
|
||||
[=]()
|
||||
{
|
||||
bool enoughStorage, enoughRam, hasPower, hasInternet;
|
||||
bool enoughStorage = false;
|
||||
bool enoughRam = false;
|
||||
bool hasPower = false;
|
||||
bool hasInternet = false;
|
||||
|
||||
qint64 requiredStorageB = m_requiredStorageGB * 1073741824L; /*powers of 2*/
|
||||
cDebug() << "Need at least storage bytes:" << requiredStorageB;
|
||||
if ( m_entriesToCheck.contains( "storage" ) )
|
||||
enoughStorage = checkEnoughStorage( requiredStorageB );
|
||||
|
||||
qint64 requiredRamB = m_requiredRamGB * 1073741824L; /*powers of 2*/
|
||||
cDebug() << "Need at least ram bytes:" << requiredRamB;
|
||||
if ( m_entriesToCheck.contains( "ram" ) )
|
||||
enoughRam = checkEnoughRam( requiredRamB );
|
||||
|
||||
if ( m_entriesToCheck.contains( "power" ) )
|
||||
hasPower = checkHasPower();
|
||||
|
||||
if ( m_entriesToCheck.contains( "internet" ) )
|
||||
hasInternet = checkHasInternet();
|
||||
|
||||
cDebug() << "enoughStorage, enoughRam, hasPower, hasInternet: "
|
||||
<< enoughStorage << enoughRam << hasPower << hasInternet;
|
||||
|
||||
QList< QPair< QString, bool > > checkEntries;
|
||||
checkEntries.append( qMakePair(
|
||||
QList< PrepareEntry > checkEntries;
|
||||
foreach ( const QString& entry, m_entriesToCheck )
|
||||
{
|
||||
if ( entry == "storage" )
|
||||
checkEntries.append( {
|
||||
entry,
|
||||
tr( "has at least %1 GB available drive space" )
|
||||
.arg( m_requiredStorageGB ),
|
||||
enoughStorage ) );
|
||||
checkEntries.append( qMakePair(
|
||||
enoughStorage,
|
||||
m_entriesToRequire.contains( entry )
|
||||
} );
|
||||
else if ( entry == "ram" )
|
||||
checkEntries.append( {
|
||||
entry,
|
||||
tr( "has at least %1 GB working memory" )
|
||||
.arg( m_requiredRamGB ),
|
||||
enoughRam ) );
|
||||
checkEntries.append( qMakePair(
|
||||
enoughRam,
|
||||
m_entriesToRequire.contains( entry )
|
||||
} );
|
||||
else if ( entry == "power" )
|
||||
checkEntries.append( {
|
||||
entry,
|
||||
tr( "is plugged in to a power source" ),
|
||||
hasPower ) );
|
||||
checkEntries.append( qMakePair(
|
||||
hasPower,
|
||||
m_entriesToRequire.contains( entry )
|
||||
} );
|
||||
else if ( entry == "internet" )
|
||||
checkEntries.append( {
|
||||
entry,
|
||||
tr( "is connected to the Internet" ),
|
||||
hasInternet ) );
|
||||
hasInternet,
|
||||
m_entriesToRequire.contains( entry )
|
||||
} );
|
||||
}
|
||||
|
||||
m_actualWidget->init( checkEntries );
|
||||
m_widget->layout()->removeWidget( waitingWidget );
|
||||
waitingWidget->deleteLater();
|
||||
m_widget->layout()->addWidget( m_actualWidget );
|
||||
m_nextEnabled = true;
|
||||
|
||||
bool canGoNext = true;
|
||||
foreach ( const PrepareEntry& entry, checkEntries )
|
||||
{
|
||||
if ( !entry.checked && entry.required )
|
||||
{
|
||||
canGoNext = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_nextEnabled = canGoNext;
|
||||
emit nextStatusChanged( m_nextEnabled );
|
||||
|
||||
timer->deleteLater();
|
||||
} );
|
||||
timer->start( 0 );
|
||||
@ -222,6 +261,20 @@ PrepareViewStep::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
{
|
||||
m_requiredRamGB = 1.;
|
||||
}
|
||||
|
||||
if ( configurationMap.contains( "check" ) &&
|
||||
configurationMap.value( "check" ).type() == QVariant::List )
|
||||
{
|
||||
m_entriesToCheck.clear();
|
||||
m_entriesToCheck.append( configurationMap.value( "check" ).toStringList() );
|
||||
}
|
||||
|
||||
if ( configurationMap.contains( "required" ) &&
|
||||
configurationMap.value( "required" ).type() == QVariant::List )
|
||||
{
|
||||
m_entriesToRequire.clear();
|
||||
m_entriesToRequire.append( configurationMap.value( "required" ).toStringList() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,12 +20,21 @@
|
||||
#define PREPAREPAGEPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
#include "viewpages/ViewStep.h"
|
||||
#include "PluginDllMacro.h"
|
||||
|
||||
class PreparePage;
|
||||
|
||||
struct PrepareEntry
|
||||
{
|
||||
QString name;
|
||||
QString text;
|
||||
bool checked;
|
||||
bool required;
|
||||
};
|
||||
|
||||
class PLUGINDLLEXPORT PrepareViewStep : public Calamares::ViewStep
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -56,6 +65,9 @@ public:
|
||||
void setConfigurationMap( const QVariantMap& configurationMap ) override;
|
||||
|
||||
private:
|
||||
QStringList m_entriesToCheck;
|
||||
QStringList m_entriesToRequire;
|
||||
|
||||
bool checkEnoughStorage( qint64 requiredSpace );
|
||||
bool checkEnoughRam( qint64 requiredRam );
|
||||
bool checkBatteryExists();
|
||||
|
@ -1,3 +1,11 @@
|
||||
---
|
||||
requiredStorage: 5.5
|
||||
requiredRam: 2.0
|
||||
check:
|
||||
- storage
|
||||
- ram
|
||||
- power
|
||||
- internet
|
||||
required:
|
||||
- storage
|
||||
- ram
|
Loading…
Reference in New Issue
Block a user