From 5434a04ebca8c5accc52ae3f471c8c027b7b4f32 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 26 Aug 2014 17:26:40 +0200 Subject: [PATCH] Block the install process if an entry is required but unsatisfied. --- src/modules/prepare/PreparePage.cpp | 6 +- src/modules/prepare/PreparePage.h | 4 +- src/modules/prepare/PrepareViewStep.cpp | 95 +++++++++++++++++++------ src/modules/prepare/PrepareViewStep.h | 12 ++++ src/modules/prepare/prepare.conf | 8 +++ 5 files changed, 100 insertions(+), 25 deletions(-) diff --git a/src/modules/prepare/PreparePage.cpp b/src/modules/prepare/PreparePage.cpp index 521911377..b07029bec 100644 --- a/src/modules/prepare/PreparePage.cpp +++ b/src/modules/prepare/PreparePage.cpp @@ -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 ); } diff --git a/src/modules/prepare/PreparePage.h b/src/modules/prepare/PreparePage.h index 3230656d9..1751f0bbd 100644 --- a/src/modules/prepare/PreparePage.h +++ b/src/modules/prepare/PreparePage.h @@ -19,6 +19,8 @@ #ifndef PREPAREPAGE_H #define PREPAREPAGE_H +#include "PrepareViewStep.h" + #include #include @@ -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; diff --git a/src/modules/prepare/PrepareViewStep.cpp b/src/modules/prepare/PrepareViewStep.cpp index f49d3c0bb..136b66570 100644 --- a/src/modules/prepare/PrepareViewStep.cpp +++ b/src/modules/prepare/PrepareViewStep.cpp @@ -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; - enoughStorage = checkEnoughStorage( requiredStorageB ); + if ( m_entriesToCheck.contains( "storage" ) ) + enoughStorage = checkEnoughStorage( requiredStorageB ); qint64 requiredRamB = m_requiredRamGB * 1073741824L; /*powers of 2*/ cDebug() << "Need at least ram bytes:" << requiredRamB; - enoughRam = checkEnoughRam( requiredRamB ); + if ( m_entriesToCheck.contains( "ram" ) ) + enoughRam = checkEnoughRam( requiredRamB ); + + if ( m_entriesToCheck.contains( "power" ) ) + hasPower = checkHasPower(); + + if ( m_entriesToCheck.contains( "internet" ) ) + hasInternet = checkHasInternet(); - hasPower = checkHasPower(); - hasInternet = checkHasInternet(); cDebug() << "enoughStorage, enoughRam, hasPower, hasInternet: " << enoughStorage << enoughRam << hasPower << hasInternet; - QList< QPair< QString, bool > > checkEntries; - checkEntries.append( qMakePair( - tr( "has at least %1 GB available drive space" ) - .arg( m_requiredStorageGB ), - enoughStorage ) ); - checkEntries.append( qMakePair( - tr( "has at least %1 GB working memory" ) - .arg( m_requiredRamGB ), - enoughRam ) ); - checkEntries.append( qMakePair( - tr( "is plugged in to a power source" ), - hasPower ) ); - checkEntries.append( qMakePair( - tr( "is connected to the Internet" ), - hasInternet ) ); + 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, + m_entriesToRequire.contains( entry ) + } ); + else if ( entry == "ram" ) + checkEntries.append( { + entry, + tr( "has at least %1 GB working memory" ) + .arg( m_requiredRamGB ), + enoughRam, + m_entriesToRequire.contains( entry ) + } ); + else if ( entry == "power" ) + checkEntries.append( { + entry, + tr( "is plugged in to a power source" ), + hasPower, + m_entriesToRequire.contains( entry ) + } ); + else if ( entry == "internet" ) + checkEntries.append( { + entry, + tr( "is connected to the Internet" ), + 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() ); + } } diff --git a/src/modules/prepare/PrepareViewStep.h b/src/modules/prepare/PrepareViewStep.h index b01f9c62b..3dbfbf2dc 100644 --- a/src/modules/prepare/PrepareViewStep.h +++ b/src/modules/prepare/PrepareViewStep.h @@ -20,12 +20,21 @@ #define PREPAREPAGEPLUGIN_H #include +#include #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(); diff --git a/src/modules/prepare/prepare.conf b/src/modules/prepare/prepare.conf index 39baed9e7..6a44f85f0 100644 --- a/src/modules/prepare/prepare.conf +++ b/src/modules/prepare/prepare.conf @@ -1,3 +1,11 @@ --- requiredStorage: 5.5 requiredRam: 2.0 +check: + - storage + - ram + - power + - internet +required: + - storage + - ram \ No newline at end of file