Merge branch 'issue-1307'

FIXES #1307
This commit is contained in:
Adriaan de Groot 2020-01-28 14:31:27 +01:00
commit ac96d91a65
3 changed files with 242 additions and 165 deletions

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2014-2017, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2017, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, 2019, Adriaan de Groot <groot@kde.org> * Copyright 2017, 2019-2020, Adriaan de Groot <groot@kde.org>
* Copyright 2017, Gabriel Craciunescu <crazy@frugalware.org> * Copyright 2017, Gabriel Craciunescu <crazy@frugalware.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
@ -29,6 +29,8 @@
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "widgets/WaitingWidget.h" #include "widgets/WaitingWidget.h"
#include <QHBoxLayout>
CheckerContainer::CheckerContainer( QWidget* parent ) CheckerContainer::CheckerContainer( QWidget* parent )
: QWidget( parent ) : QWidget( parent )
, m_waitingWidget( new WaitingWidget( QString(), this ) ) , m_waitingWidget( new WaitingWidget( QString(), this ) )
@ -40,10 +42,7 @@ CheckerContainer::CheckerContainer( QWidget* parent )
CalamaresUtils::unmarginLayout( mainLayout ); CalamaresUtils::unmarginLayout( mainLayout );
mainLayout->addWidget( m_waitingWidget ); mainLayout->addWidget( m_waitingWidget );
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE( if ( m_waitingWidget ) m_waitingWidget->setText( tr( "Gathering system information..." ) ); )
if ( m_waitingWidget )
m_waitingWidget->setText( tr( "Gathering system information..." ) );
)
} }
CheckerContainer::~CheckerContainer() CheckerContainer::~CheckerContainer()
@ -52,32 +51,37 @@ CheckerContainer::~CheckerContainer()
delete m_checkerWidget; delete m_checkerWidget;
} }
void CheckerContainer::requirementsComplete( bool ok ) void
CheckerContainer::requirementsComplete( bool ok )
{ {
layout()->removeWidget( m_waitingWidget ); layout()->removeWidget( m_waitingWidget );
m_waitingWidget->deleteLater(); m_waitingWidget->deleteLater();
m_waitingWidget = nullptr; // Don't delete in destructor m_waitingWidget = nullptr; // Don't delete in destructor
m_checkerWidget = new ResultsListWidget( this ); m_checkerWidget = new ResultsListWidget( this, m_requirements );
m_checkerWidget->init( m_requirements );
layout()->addWidget( m_checkerWidget ); layout()->addWidget( m_checkerWidget );
m_verdict = ok; m_verdict = ok;
} }
void CheckerContainer::requirementsChecked(const Calamares::RequirementsList& l) void
CheckerContainer::requirementsChecked( const Calamares::RequirementsList& l )
{ {
m_requirements.append( l ); m_requirements.append( l );
} }
void CheckerContainer::requirementsProgress(const QString& message) void
CheckerContainer::requirementsProgress( const QString& message )
{ {
if ( m_waitingWidget ) if ( m_waitingWidget )
{
m_waitingWidget->setText( message ); m_waitingWidget->setText( message );
}
} }
bool CheckerContainer::verdict() const bool
CheckerContainer::verdict() const
{ {
return m_verdict; return m_verdict;
} }

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2017, 2019, Adriaan de Groot <groot@kde.org> * Copyright 2017, 2019-2020, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -24,120 +24,176 @@
#include "Branding.h" #include "Branding.h"
#include "Settings.h" #include "Settings.h"
#include "utils/CalamaresUtilsGui.h" #include "utils/CalamaresUtilsGui.h"
#include "utils/Logger.h"
#include "utils/Retranslator.h" #include "utils/Retranslator.h"
#include "widgets/FixedAspectRatioLabel.h" #include "widgets/FixedAspectRatioLabel.h"
#include <QAbstractButton> #include <QAbstractButton>
#include <QBoxLayout>
#include <QDialog> #include <QDialog>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QLabel> #include <QLabel>
#include <QVBoxLayout>
/** @brief Add widgets to @p layout for the list @p checkEntries
ResultsListWidget::ResultsListWidget( QWidget* parent ) *
: QWidget( parent ) * The @p resultWidgets is filled with pointers to the widgets;
* for each entry in @p checkEntries that satisfies @p predicate,
* a widget is created, otherwise a nullptr is added instead.
*
* Adds all the widgets to the given @p layout.
*
* Afterwards, @p resultWidgets has a length equal to @p checkEntries.
*/
static void
createResultWidgets( QLayout* layout,
QList< ResultWidget* >& resultWidgets,
const Calamares::RequirementsList& checkEntries,
std::function< bool( const Calamares::RequirementEntry& ) > predicate )
{ {
setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); resultWidgets.clear();
resultWidgets.reserve( checkEntries.count() );
for ( const auto& entry : checkEntries )
{
if ( !predicate( entry ) )
{
resultWidgets.append( nullptr );
continue;
}
m_mainLayout = new QVBoxLayout; ResultWidget* ciw = new ResultWidget( entry.satisfied, entry.mandatory );
setLayout( m_mainLayout ); layout->addWidget( ciw );
ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
QHBoxLayout* spacerLayout = new QHBoxLayout; ciw->setAutoFillBackground( true );
m_mainLayout->addLayout( spacerLayout ); QPalette pal( ciw->palette() );
m_paddingSize = qBound( 32, CalamaresUtils::defaultFontHeight() * 4, 128 ); QColor bgColor = pal.window().color();
spacerLayout->addSpacing( m_paddingSize ); int bgHue = ( entry.satisfied ) ? bgColor.hue() : ( entry.mandatory ) ? 0 : 60;
m_entriesLayout = new QVBoxLayout; bgColor.setHsv( bgHue, 64, bgColor.value() );
spacerLayout->addLayout( m_entriesLayout ); pal.setColor( QPalette::Window, bgColor );
spacerLayout->addSpacing( m_paddingSize ); ciw->setPalette( pal );
CalamaresUtils::unmarginLayout( spacerLayout );
resultWidgets.append( ciw );
}
}
/** @brief A "details" dialog for the results-list
*
* This displays the same RequirementsList as ResultsListWidget,
* but the *details* part rather than the show description.
*
* This is an internal-to-the-widget class.
*/
class ResultsListDialog : public QDialog
{
public:
/** @brief Create a dialog for the given @p checkEntries list of requirements.
*
* The list must continue to exist for the lifetime of the dialog,
* or UB happens.
*/
ResultsListDialog( QWidget* parent, const Calamares::RequirementsList& checkEntries );
virtual ~ResultsListDialog();
private:
QLabel* m_title;
QList< ResultWidget* > m_resultWidgets; ///< One widget for each entry with details available
const Calamares::RequirementsList& m_entries;
void retranslate();
};
ResultsListDialog::ResultsListDialog( QWidget* parent, const Calamares::RequirementsList& checkEntries )
: QDialog( parent )
, m_entries( checkEntries )
{
auto* mainLayout = new QVBoxLayout;
auto* entriesLayout = new QVBoxLayout;
m_title = new QLabel( this );
createResultWidgets( entriesLayout, m_resultWidgets, checkEntries, []( const Calamares::RequirementEntry& e ) {
return e.hasDetails();
} );
QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Close, Qt::Horizontal, this );
mainLayout->addWidget( m_title );
mainLayout->addLayout( entriesLayout );
mainLayout->addWidget( buttonBox );
setLayout( mainLayout );
connect( buttonBox, &QDialogButtonBox::clicked, this, &QDialog::close );
CALAMARES_RETRANSLATE_SLOT( &ResultsListDialog::retranslate )
retranslate(); // Do it now to fill in the texts
}
ResultsListDialog::~ResultsListDialog() {}
void
ResultsListDialog::retranslate()
{
m_title->setText( tr( "For best results, please ensure that this computer:" ) );
setWindowTitle( tr( "System requirements" ) );
int i = 0;
for ( const auto& entry : m_entries )
{
if ( m_resultWidgets[ i ] )
{
m_resultWidgets[ i ]->setText( entry.enumerationText() );
}
i++;
}
} }
void ResultsListWidget::ResultsListWidget( QWidget* parent, const Calamares::RequirementsList& checkEntries )
ResultsListWidget::init( const Calamares::RequirementsList& checkEntries ) : QWidget( parent )
, m_entries( checkEntries )
{ {
bool allChecked = true; setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
bool requirementsSatisfied = true;
for ( const auto& entry : checkEntries ) QBoxLayout* mainLayout = new QVBoxLayout;
QBoxLayout* entriesLayout = new QVBoxLayout;
setLayout( mainLayout );
int paddingSize = qBound( 32, CalamaresUtils::defaultFontHeight() * 4, 128 );
QHBoxLayout* spacerLayout = new QHBoxLayout;
mainLayout->addLayout( spacerLayout );
spacerLayout->addSpacing( paddingSize );
spacerLayout->addLayout( entriesLayout );
spacerLayout->addSpacing( paddingSize );
CalamaresUtils::unmarginLayout( spacerLayout );
m_explanation = new QLabel;
m_explanation->setWordWrap( true );
m_explanation->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
m_explanation->setOpenExternalLinks( false );
connect( m_explanation, &QLabel::linkActivated, this, &ResultsListWidget::linkClicked );
entriesLayout->addWidget( m_explanation );
// Check that all are satisfied (gives warnings if not) and
// all *mandatory* entries are satisfied (gives errors if not).
auto isUnSatisfied = []( const Calamares::RequirementEntry& e ) { return !e.satisfied; };
const bool requirementsSatisfied = std::none_of( checkEntries.begin(), checkEntries.end(), isUnSatisfied );
createResultWidgets( entriesLayout, m_resultWidgets, checkEntries, isUnSatisfied );
if ( !requirementsSatisfied )
{ {
if ( !entry.satisfied ) entriesLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() / 2 );
{ mainLayout->addStretch();
ResultWidget* ciw = new ResultWidget( entry.satisfied, entry.mandatory );
CALAMARES_RETRANSLATE( ciw->setText( entry.negatedText() ); )
m_entriesLayout->addWidget( ciw );
ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
allChecked = false;
if ( entry.mandatory )
requirementsSatisfied = false;
ciw->setAutoFillBackground( true );
QPalette pal( ciw->palette() );
QColor bgColor = pal.window().color();
int bgHue = ( entry.satisfied ) ? bgColor.hue() : ( entry.mandatory ) ? 0 : 60;
bgColor.setHsv( bgHue, 64, bgColor.value() );
pal.setColor( QPalette::Window, bgColor );
ciw->setPalette( pal );
}
} }
else
QLabel* textLabel = new QLabel;
textLabel->setWordWrap( true );
m_entriesLayout->insertWidget( 0, textLabel );
textLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
if ( !allChecked )
{ {
m_entriesLayout->insertSpacing( 1, CalamaresUtils::defaultFontHeight() / 2 ); if ( !Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductWelcome ).isEmpty() )
if ( !requirementsSatisfied )
{ {
CALAMARES_RETRANSLATE( QPixmap theImage
QString message = Calamares::Settings::instance()->isSetupMode() = QPixmap( Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductWelcome ) );
? tr( "This computer does not satisfy the minimum "
"requirements for setting up %1.<br/>"
"Setup cannot continue. "
"<a href=\"#details\">Details...</a>" )
: tr( "This computer does not satisfy the minimum "
"requirements for installing %1.<br/>"
"Installation cannot continue. "
"<a href=\"#details\">Details...</a>" );
textLabel->setText( message.arg( *Calamares::Branding::ShortVersionedName ) );
)
textLabel->setOpenExternalLinks( false );
connect( textLabel, &QLabel::linkActivated,
this, [ this, checkEntries ]( const QString& link )
{
if ( link == "#details" )
showDetailsDialog( checkEntries );
} );
}
else
{
CALAMARES_RETRANSLATE(
QString message = Calamares::Settings::instance()->isSetupMode()
? tr( "This computer does not satisfy some of the "
"recommended requirements for setting up %1.<br/>"
"Setup can continue, but some features "
"might be disabled." )
: tr( "This computer does not satisfy some of the "
"recommended requirements for installing %1.<br/>"
"Installation can continue, but some features "
"might be disabled." );
textLabel->setText( message.arg( *Calamares::Branding::ShortVersionedName ) );
)
}
}
if ( allChecked && requirementsSatisfied )
{
if ( !Calamares::Branding::instance()->
imagePath( Calamares::Branding::ProductWelcome ).isEmpty() )
{
QPixmap theImage = QPixmap( Calamares::Branding::instance()->
imagePath( Calamares::Branding::ProductWelcome ) );
if ( !theImage.isNull() ) if ( !theImage.isNull() )
{ {
QLabel* imageLabel; QLabel* imageLabel;
@ -154,68 +210,82 @@ ResultsListWidget::init( const Calamares::RequirementsList& checkEntries )
} }
imageLabel->setContentsMargins( 4, CalamaresUtils::defaultFontHeight() * 3 / 4, 4, 4 ); imageLabel->setContentsMargins( 4, CalamaresUtils::defaultFontHeight() * 3 / 4, 4, 4 );
m_mainLayout->addWidget( imageLabel ); mainLayout->addWidget( imageLabel );
imageLabel->setAlignment( Qt::AlignCenter ); imageLabel->setAlignment( Qt::AlignCenter );
imageLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); imageLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
} }
} }
CALAMARES_RETRANSLATE( m_explanation->setAlignment( Qt::AlignCenter );
textLabel->setText( tr( "This program will ask you some questions and "
"set up %2 on your computer." )
.arg( *Calamares::Branding::ProductName ) );
textLabel->setAlignment( Qt::AlignCenter );
)
} }
else
m_mainLayout->addStretch(); CALAMARES_RETRANSLATE_SLOT( &ResultsListWidget::retranslate )
retranslate();
} }
void void
ResultsListWidget::showDetailsDialog( const Calamares::RequirementsList& checkEntries ) ResultsListWidget::linkClicked( const QString& link )
{ {
QDialog* detailsDialog = new QDialog( this ); if ( link == "#details" )
QBoxLayout* mainLayout = new QVBoxLayout;
detailsDialog->setLayout( mainLayout );
QLabel* textLabel = new QLabel;
mainLayout->addWidget( textLabel );
CALAMARES_RETRANSLATE(
textLabel->setText( tr( "For best results, please ensure that this computer:" ) );
)
QBoxLayout* entriesLayout = new QVBoxLayout;
CalamaresUtils::unmarginLayout( entriesLayout );
mainLayout->addLayout( entriesLayout );
for ( const auto& entry : checkEntries )
{ {
if ( !entry.hasDetails() ) auto* dialog = new ResultsListDialog( this, m_entries );
continue; dialog->exec();
dialog->deleteLater();
}
}
ResultWidget* ciw = new ResultWidget( entry.satisfied, entry.mandatory ); void
CALAMARES_RETRANSLATE( ciw->setText( entry.enumerationText() ); ) ResultsListWidget::retranslate()
entriesLayout->addWidget( ciw ); {
ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); int i = 0;
for ( const auto& entry : m_entries )
ciw->setAutoFillBackground( true ); {
QPalette pal( ciw->palette() ); if ( m_resultWidgets[ i ] )
QColor bgColor = pal.window().color(); {
int bgHue = ( entry.satisfied ) ? bgColor.hue() : ( entry.mandatory ) ? 0 : 60; m_resultWidgets[ i ]->setText( entry.negatedText() );
bgColor.setHsv( bgHue, 64, bgColor.value() ); }
pal.setColor( QPalette::Window, bgColor ); i++;
ciw->setPalette( pal );
} }
QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Close, // Check that all are satisfied (gives warnings if not) and
Qt::Horizontal, // all *mandatory* entries are satisfied (gives errors if not).
this ); auto isUnSatisfied = []( const Calamares::RequirementEntry& e ) { return !e.satisfied; };
mainLayout->addWidget( buttonBox ); auto isMandatoryAndUnSatisfied = []( const Calamares::RequirementEntry& e ) { return e.mandatory && !e.satisfied; };
const bool requirementsSatisfied = std::none_of( m_entries.begin(), m_entries.end(), isUnSatisfied );
const bool mandatorySatisfied = std::none_of( m_entries.begin(), m_entries.end(), isMandatoryAndUnSatisfied );
detailsDialog->setModal( true ); if ( !requirementsSatisfied )
detailsDialog->setWindowTitle( tr( "System requirements" ) ); {
QString message;
connect( buttonBox, &QDialogButtonBox::clicked, const bool setup = Calamares::Settings::instance()->isSetupMode();
detailsDialog, &QDialog::close ); if ( !mandatorySatisfied )
detailsDialog->exec(); {
detailsDialog->deleteLater(); message = setup ? tr( "This computer does not satisfy the minimum "
"requirements for setting up %1.<br/>"
"Setup cannot continue. "
"<a href=\"#details\">Details...</a>" )
: tr( "This computer does not satisfy the minimum "
"requirements for installing %1.<br/>"
"Installation cannot continue. "
"<a href=\"#details\">Details...</a>" );
}
else
{
message = setup ? tr( "This computer does not satisfy some of the "
"recommended requirements for setting up %1.<br/>"
"Setup can continue, but some features "
"might be disabled." )
: tr( "This computer does not satisfy some of the "
"recommended requirements for installing %1.<br/>"
"Installation can continue, but some features "
"might be disabled." );
}
m_explanation->setText( message.arg( *Calamares::Branding::ShortVersionedName ) );
}
else
{
m_explanation->setText( tr( "This program will ask you some questions and "
"set up %2 on your computer." )
.arg( *Calamares::Branding::ProductName ) );
}
} }

View File

@ -1,7 +1,7 @@
/* === This file is part of Calamares - <https://github.com/calamares> === /* === This file is part of Calamares - <https://github.com/calamares> ===
* *
* Copyright 2014-2015, Teo Mrnjavac <teo@kde.org> * Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
* Copyright 2019, Adriaan de Groot <groot@kde.org> * Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
* *
* Calamares is free software: you can redistribute it and/or modify * Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -20,25 +20,28 @@
#ifndef CHECKER_RESULTSLISTWIDGET_H #ifndef CHECKER_RESULTSLISTWIDGET_H
#define CHECKER_RESULTSLISTWIDGET_H #define CHECKER_RESULTSLISTWIDGET_H
#include "ResultWidget.h"
#include "modulesystem/Requirement.h" #include "modulesystem/Requirement.h"
#include <QBoxLayout>
#include <QWidget> #include <QWidget>
class QLabel;
class ResultsListWidget : public QWidget class ResultsListWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ResultsListWidget( QWidget* parent = nullptr ); explicit ResultsListWidget( QWidget* parent, const Calamares::RequirementsList& checkEntries );
void init( const Calamares::RequirementsList& checkEntries );
private: private:
void showDetailsDialog( const Calamares::RequirementsList& checkEntries ); /// @brief A link in the explanatory text has been clicked
void linkClicked( const QString& link );
void retranslate();
QBoxLayout* m_mainLayout; QLabel* m_explanation = nullptr; ///< Explanatory text above the list, with link
QBoxLayout* m_entriesLayout; const Calamares::RequirementsList& m_entries;
int m_paddingSize; QList< ResultWidget* > m_resultWidgets; ///< One widget for each unsatisfied entry
}; };
#endif // CHECKER_RESULTSLISTWIDGET_H #endif // CHECKER_RESULTSLISTWIDGET_H