[welcome] Refactor results-details dialog

- Factor out the "details" dialog into a separate class
   with a translation slot. This resolves the crash reported in #1307.
This commit is contained in:
Adriaan de Groot 2020-01-27 19:35:41 +01:00
parent b3f5e28738
commit 41ac21bdcd

View File

@ -24,6 +24,7 @@
#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"
@ -70,7 +71,9 @@ ResultsListWidget::init( const Calamares::RequirementsList& checkEntries )
allChecked = false; allChecked = false;
if ( entry.mandatory ) if ( entry.mandatory )
{
requirementsSatisfied = false; requirementsSatisfied = false;
}
ciw->setAutoFillBackground( true ); ciw->setAutoFillBackground( true );
QPalette pal( ciw->palette() ); QPalette pal( ciw->palette() );
@ -94,50 +97,45 @@ ResultsListWidget::init( const Calamares::RequirementsList& checkEntries )
if ( !requirementsSatisfied ) if ( !requirementsSatisfied )
{ {
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE( QString message = Calamares::Settings::instance()->isSetupMode()
QString message = Calamares::Settings::instance()->isSetupMode() ? tr( "This computer does not satisfy the minimum "
? tr( "This computer does not satisfy the minimum " "requirements for setting up %1.<br/>"
"requirements for setting up %1.<br/>" "Setup cannot continue. "
"Setup cannot continue. " "<a href=\"#details\">Details...</a>" )
"<a href=\"#details\">Details...</a>" ) : tr( "This computer does not satisfy the minimum "
: tr( "This computer does not satisfy the minimum " "requirements for installing %1.<br/>"
"requirements for installing %1.<br/>" "Installation cannot continue. "
"Installation cannot continue. " "<a href=\"#details\">Details...</a>" );
"<a href=\"#details\">Details...</a>" ); textLabel->setText( message.arg( *Calamares::Branding::ShortVersionedName ) ); )
textLabel->setText( message.arg( *Calamares::Branding::ShortVersionedName ) );
)
textLabel->setOpenExternalLinks( false ); textLabel->setOpenExternalLinks( false );
connect( textLabel, &QLabel::linkActivated, connect( textLabel, &QLabel::linkActivated, this, [this, checkEntries]( const QString& link ) {
this, [ this, checkEntries ]( const QString& link )
{
if ( link == "#details" ) if ( link == "#details" )
{
showDetailsDialog( checkEntries ); showDetailsDialog( checkEntries );
}
} ); } );
} }
else else
{ {
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE( QString message = Calamares::Settings::instance()->isSetupMode()
QString message = Calamares::Settings::instance()->isSetupMode() ? tr( "This computer does not satisfy some of the "
? tr( "This computer does not satisfy some of the " "recommended requirements for setting up %1.<br/>"
"recommended requirements for setting up %1.<br/>" "Setup can continue, but some features "
"Setup can continue, but some features " "might be disabled." )
"might be disabled." ) : tr( "This computer does not satisfy some of the "
: tr( "This computer does not satisfy some of the " "recommended requirements for installing %1.<br/>"
"recommended requirements for installing %1.<br/>" "Installation can continue, but some features "
"Installation can continue, but some features " "might be disabled." );
"might be disabled." ); textLabel->setText( message.arg( *Calamares::Branding::ShortVersionedName ) ); )
textLabel->setText( message.arg( *Calamares::Branding::ShortVersionedName ) );
)
} }
} }
if ( allChecked && requirementsSatisfied ) if ( allChecked && requirementsSatisfied )
{ {
if ( !Calamares::Branding::instance()-> if ( !Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductWelcome ).isEmpty() )
imagePath( Calamares::Branding::ProductWelcome ).isEmpty() )
{ {
QPixmap theImage = QPixmap( Calamares::Branding::instance()-> QPixmap theImage
imagePath( Calamares::Branding::ProductWelcome ) ); = QPixmap( Calamares::Branding::instance()->imagePath( Calamares::Branding::ProductWelcome ) );
if ( !theImage.isNull() ) if ( !theImage.isNull() )
{ {
QLabel* imageLabel; QLabel* imageLabel;
@ -159,41 +157,48 @@ ResultsListWidget::init( const Calamares::RequirementsList& checkEntries )
imageLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); imageLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
} }
} }
CALAMARES_RETRANSLATE( CALAMARES_RETRANSLATE( textLabel->setText( tr( "This program will ask you some questions and "
textLabel->setText( tr( "This program will ask you some questions and " "set up %2 on your computer." )
"set up %2 on your computer." ) .arg( *Calamares::Branding::ProductName ) );
.arg( *Calamares::Branding::ProductName ) ); textLabel->setAlignment( Qt::AlignCenter ); )
textLabel->setAlignment( Qt::AlignCenter );
)
} }
else else
{
m_mainLayout->addStretch(); m_mainLayout->addStretch();
}
} }
class ResultsListDialog : public QDialog
void
ResultsListWidget::showDetailsDialog( const Calamares::RequirementsList& checkEntries )
{ {
QDialog* detailsDialog = new QDialog( this ); public:
QBoxLayout* mainLayout = new QVBoxLayout; ResultsListDialog( QWidget* parent, const Calamares::RequirementsList& checkEntries );
detailsDialog->setLayout( mainLayout ); virtual ~ResultsListDialog();
QLabel* textLabel = new QLabel; private:
mainLayout->addWidget( textLabel ); QLabel* m_title;
CALAMARES_RETRANSLATE( QList< ResultWidget* > m_resultWidgets;
textLabel->setText( tr( "For best results, please ensure that this computer:" ) ); const Calamares::RequirementsList& m_entries;
)
QBoxLayout* entriesLayout = new QVBoxLayout; void retranslate();
CalamaresUtils::unmarginLayout( entriesLayout ); };
mainLayout->addLayout( entriesLayout );
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 );
for ( const auto& entry : checkEntries ) for ( const auto& entry : checkEntries )
{ {
if ( !entry.hasDetails() ) if ( !entry.hasDetails() )
{
continue; continue;
}
ResultWidget* ciw = new ResultWidget( entry.satisfied, entry.mandatory ); ResultWidget* ciw = new ResultWidget( entry.satisfied, entry.mandatory );
CALAMARES_RETRANSLATE( ciw->setText( entry.enumerationText() ); )
entriesLayout->addWidget( ciw ); entriesLayout->addWidget( ciw );
ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred ); ciw->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Preferred );
@ -204,18 +209,53 @@ ResultsListWidget::showDetailsDialog( const Calamares::RequirementsList& checkEn
bgColor.setHsv( bgHue, 64, bgColor.value() ); bgColor.setHsv( bgHue, 64, bgColor.value() );
pal.setColor( QPalette::Window, bgColor ); pal.setColor( QPalette::Window, bgColor );
ciw->setPalette( pal ); ciw->setPalette( pal );
m_resultWidgets.append( ciw );
} }
QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Close, QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Close, Qt::Horizontal, this );
Qt::Horizontal,
this ); mainLayout->addWidget( m_title );
mainLayout->addLayout( entriesLayout );
mainLayout->addWidget( buttonBox ); mainLayout->addWidget( buttonBox );
detailsDialog->setModal( true ); setLayout( mainLayout );
detailsDialog->setWindowTitle( tr( "System requirements" ) );
connect( buttonBox, &QDialogButtonBox::clicked, CALAMARES_RETRANSLATE_SLOT( &ResultsListDialog::retranslate )
detailsDialog, &QDialog::close );
detailsDialog->exec(); connect( buttonBox, &QDialogButtonBox::clicked, this, &QDialog::close );
detailsDialog->deleteLater(); retranslate(); // Do it now to fill in the texts
}
ResultsListDialog::~ResultsListDialog()
{
cDebug() << "~ResultsListDialog @" << (void*)this;
}
void
ResultsListDialog::retranslate()
{
cDebug() << "ResultsListDialog::retranslate @" << (void*)this;
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 ( !entry.hasDetails() )
{
continue;
}
m_resultWidgets[ i ]->setText( entry.enumerationText() );
i++;
}
}
void
ResultsListWidget::showDetailsDialog( const Calamares::RequirementsList& checkEntries )
{
auto* dialog = new ResultsListDialog( this, checkEntries );
dialog->exec();
dialog->deleteLater();
} }