[welcome] Restructure requirements checking

- Move widget behavior into its own container / widget class
 - Change the RequirementsChecker class to just check the
   requirements, returning a results list
 - Connect from the module manager to the results widget.
This commit is contained in:
Adriaan de Groot 2017-12-02 09:56:03 -05:00
parent b6fed964ce
commit bd27dda474
9 changed files with 251 additions and 177 deletions

View File

@ -6,8 +6,9 @@ find_package( Qt5 ${QT_VERSION} CONFIG REQUIRED DBus Network )
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui ) include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
set( CHECKER_SOURCES set( CHECKER_SOURCES
checker/CheckItemWidget.cpp checker/CheckerContainer.cpp
checker/CheckerWidget.cpp checker/CheckerWidget.cpp
checker/CheckItemWidget.cpp
checker/RequirementsChecker.cpp checker/RequirementsChecker.cpp
checker/partman_devices.c checker/partman_devices.c
) )

View File

@ -22,10 +22,13 @@
#include "ui_WelcomePage.h" #include "ui_WelcomePage.h"
#include "CalamaresVersion.h" #include "CalamaresVersion.h"
#include "checker/CheckerContainer.h"
#include "checker/RequirementsChecker.h" #include "checker/RequirementsChecker.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "modulesystem/ModuleManager.h"
#include "ViewManager.h" #include "ViewManager.h"
#include <QApplication> #include <QApplication>
@ -39,11 +42,13 @@
#include "Branding.h" #include "Branding.h"
WelcomePage::WelcomePage( RequirementsChecker* requirementsChecker, QWidget* parent ) WelcomePage::WelcomePage( QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, ui( new Ui::WelcomePage ) , ui( new Ui::WelcomePage )
, m_requirementsChecker( requirementsChecker ) , m_checkingWidget( new CheckerContainer( this ) )
{ {
connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsResult, m_checkingWidget, &CheckerContainer::requirementsChecked );
connect( Calamares::ModuleManager::instance(), &Calamares::ModuleManager::requirementsComplete, m_checkingWidget, &CheckerContainer::requirementsComplete );
ui->setupUi( this ); ui->setupUi( this );
ui->verticalLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() * 2 ); ui->verticalLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() * 2 );
@ -102,7 +107,7 @@ WelcomePage::WelcomePage( RequirementsChecker* requirementsChecker, QWidget* par
mb.exec(); mb.exec();
} ); } );
ui->verticalLayout->insertWidget( 3, m_requirementsChecker->widget() ); ui->verticalLayout->insertWidget( 3, m_checkingWidget);
} }
@ -257,3 +262,7 @@ WelcomePage::focusInEvent( QFocusEvent* e )
e->accept(); e->accept();
} }
bool WelcomePage::verdict() const
{
return m_checkingWidget->verdict();
}

View File

@ -26,26 +26,27 @@ namespace Ui
class WelcomePage; class WelcomePage;
} }
class RequirementsChecker; class CheckerContainer;
class WelcomePage : public QWidget class WelcomePage : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit WelcomePage( RequirementsChecker* requirementsChecker, explicit WelcomePage( QWidget* parent = nullptr );
QWidget* parent = nullptr );
void setUpLinks( bool showSupportUrl, void setUpLinks( bool showSupportUrl,
bool showKnownIssuesUrl, bool showKnownIssuesUrl,
bool showReleaseNotesUrl ); bool showReleaseNotesUrl );
bool verdict() const;
protected: protected:
void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus void focusInEvent( QFocusEvent* e ) override; //choose the child widget to focus
private: private:
void initLanguages(); void initLanguages();
Ui::WelcomePage* ui; Ui::WelcomePage* ui;
RequirementsChecker* m_requirementsChecker; CheckerContainer* m_checkingWidget;
}; };
#endif // WELCOMEPAGE_H #endif // WELCOMEPAGE_H

View File

@ -32,7 +32,7 @@ WelcomeViewStep::WelcomeViewStep( QObject* parent )
, m_requirementsChecker( new RequirementsChecker( this ) ) , m_requirementsChecker( new RequirementsChecker( this ) )
{ {
emit nextStatusChanged( true ); emit nextStatusChanged( true );
m_widget = new WelcomePage( m_requirementsChecker ); m_widget = new WelcomePage();
} }
@ -72,7 +72,7 @@ WelcomeViewStep::back()
bool bool
WelcomeViewStep::isNextEnabled() const WelcomeViewStep::isNextEnabled() const
{ {
return m_requirementsChecker->verdict(); return m_widget->verdict();
} }
@ -131,4 +131,3 @@ WelcomeViewStep::setConfigurationMap( const QVariantMap& configurationMap )
cDebug() << "WARNING: no valid requirements map found in welcome " cDebug() << "WARNING: no valid requirements map found in welcome "
"module configuration."; "module configuration.";
} }

View File

@ -21,6 +21,7 @@
#include <QObject> #include <QObject>
#include <modulesystem/Requirement.h>
#include <utils/PluginFactory.h> #include <utils/PluginFactory.h>
#include <viewpages/ViewStep.h> #include <viewpages/ViewStep.h>
@ -58,7 +59,6 @@ public:
private: private:
WelcomePage* m_widget; WelcomePage* m_widget;
RequirementsChecker* m_requirementsChecker; RequirementsChecker* m_requirementsChecker;
}; };

View File

@ -0,0 +1,72 @@
/* === 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 constructor
m_checkerWidget->setParent( this );
layout()->addWidget( m_checkerWidget );
m_verdict = ok;
}
void CheckerContainer::requirementsChecked(const Calamares::RequirementsList& l)
{
m_requirements.append( l );
}
bool CheckerContainer::verdict() const
{
return m_verdict;
}

View File

@ -0,0 +1,62 @@
/* === 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 );
protected:
WaitingWidget *m_waitingWidget;
CheckerWidget *m_checkerWidget;
Calamares::RequirementsList m_requirements;
bool m_verdict;
} ;
#endif

View File

@ -20,7 +20,7 @@
#include "RequirementsChecker.h" #include "RequirementsChecker.h"
#include "CheckerWidget.h" #include "CheckerContainer.h"
#include "partman_devices.h" #include "partman_devices.h"
#include "modulesystem/Requirement.h" #include "modulesystem/Requirement.h"
@ -55,27 +55,15 @@
RequirementsChecker::RequirementsChecker( QObject* parent ) RequirementsChecker::RequirementsChecker( QObject* parent )
: QObject( parent ) : QObject( parent )
, m_widget( new QWidget() )
, m_requiredStorageGB( -1 ) , m_requiredStorageGB( -1 )
, m_requiredRamGB( -1 ) , m_requiredRamGB( -1 )
, m_actualWidget( new CheckerWidget() )
, m_verdict( false )
{ {
QBoxLayout* mainLayout = new QHBoxLayout; }
m_widget->setLayout( mainLayout );
CalamaresUtils::unmarginLayout( mainLayout );
WaitingWidget* waitingWidget = new WaitingWidget( QString() ); Calamares::RequirementsList RequirementsChecker::checkRequirements(QWidget* some_widget)
mainLayout->addWidget( waitingWidget );
CALAMARES_RETRANSLATE( waitingWidget->setText( tr( "Gathering system information..." ) ); )
QSize availableSize = qApp->desktop()->availableGeometry( m_widget ).size();
QTimer* timer = new QTimer;
timer->setSingleShot( true );
connect( timer, &QTimer::timeout,
[=]()
{ {
QSize availableSize = qApp->desktop()->availableGeometry( some_widget ).size();
bool enoughStorage = false; bool enoughStorage = false;
bool enoughRam = false; bool enoughRam = false;
bool hasPower = false; bool hasPower = false;
@ -165,47 +153,7 @@ RequirementsChecker::RequirementsChecker( QObject* parent )
false false
} ); } );
} }
return checkEntries;
m_actualWidget->init( checkEntries );
m_widget->layout()->removeWidget( waitingWidget );
waitingWidget->deleteLater();
m_actualWidget->setParent( m_widget );
m_widget->layout()->addWidget( m_actualWidget );
bool canGoNext = true;
foreach ( const auto& entry, checkEntries )
{
if ( !entry.checked && entry.required )
{
canGoNext = false;
break;
}
}
m_verdict = canGoNext;
emit verdictChanged( m_verdict );
if ( canGoNext )
detectFirmwareType();
timer->deleteLater();
} );
timer->start( 0 );
emit verdictChanged( true );
}
RequirementsChecker::~RequirementsChecker()
{
if ( m_widget && m_widget->parent() == nullptr )
m_widget->deleteLater();
}
QWidget*
RequirementsChecker::widget() const
{
return m_widget;
} }
@ -300,13 +248,6 @@ RequirementsChecker::setConfigurationMap( const QVariantMap& configurationMap )
} }
bool
RequirementsChecker::verdict() const
{
return m_verdict;
}
bool bool
RequirementsChecker::checkEnoughStorage( qint64 requiredSpace ) RequirementsChecker::checkEnoughStorage( qint64 requiredSpace )
{ {

View File

@ -23,24 +23,17 @@
#include <QObject> #include <QObject>
#include <QStringList> #include <QStringList>
class CheckerWidget; #include "modulesystem/Requirement.h"
class QWidget;
class RequirementsChecker : public QObject class RequirementsChecker : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit RequirementsChecker( QObject* parent = nullptr ); explicit RequirementsChecker( QObject* parent = nullptr );
virtual ~RequirementsChecker();
QWidget* widget() const;
void setConfigurationMap( const QVariantMap& configurationMap ); void setConfigurationMap( const QVariantMap& configurationMap );
bool verdict() const; Calamares::RequirementsList checkRequirements( QWidget* some_widget );
signals:
void verdictChanged( bool );
private: private:
QStringList m_entriesToCheck; QStringList m_entriesToCheck;
@ -54,13 +47,9 @@ private:
bool checkIsRoot(); bool checkIsRoot();
void detectFirmwareType(); void detectFirmwareType();
QWidget* m_widget;
qreal m_requiredStorageGB; qreal m_requiredStorageGB;
qreal m_requiredRamGB; qreal m_requiredRamGB;
QString m_checkHasInternetUrl; QString m_checkHasInternetUrl;
CheckerWidget* m_actualWidget;
bool m_verdict;
}; };
#endif // REQUIREMENTSCHECKER_H #endif // REQUIREMENTSCHECKER_H