From fed298b17963594afd601193c635e6e875d5bb71 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 10 Jan 2020 17:41:20 +0100 Subject: [PATCH] [libcalamaresui] Defer QML loading - need a configuration before we can start loading (to support the variable search paths) - refactor showing a failure in the spinner widget. On failure, the spinner will never go away, so a message for the user is good. - stop clang-format from messing up the table of names. --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 60 ++++++++++++++------ src/libcalamaresui/viewpages/QmlViewStep.h | 2 + 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index cf19fb2b4..779a624c1 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -34,12 +34,16 @@ static const NamedEnumTable< Calamares::QmlViewStep::QmlSearch >& searchNames() { - using QmlSearch = Calamares::QmlViewStep::QmlSearch; - static NamedEnumTable< Calamares::QmlViewStep::QmlSearch > names{ - { QStringLiteral( "both" ), QmlSearch::Both }, - { QStringLiteral( "qrc" ), QmlSearch::QrcOnly }, - { QStringLiteral( "branding" ), QmlSearch::BrandingOnly } + using Search = Calamares::QmlViewStep::QmlSearch; + // *INDENT-OFF* + // clang-format off + static NamedEnumTable< Search > names { + { QStringLiteral( "both" ), Search::Both }, + { QStringLiteral( "qrc" ), Search::QrcOnly }, + { QStringLiteral( "branding" ), Search::BrandingOnly } }; + // *INDENT-ON* + // clang-format on return names; } @@ -61,15 +65,7 @@ QmlViewStep::QmlViewStep( const QString& name, QObject* parent ) m_qmlWidget->setResizeMode( QQuickWidget::SizeRootObjectToView ); m_qmlWidget->engine()->addImportPath( CalamaresUtils::qmlModulesDir().absolutePath() ); - // TODO: search for suitable file - QString qrcName = QStringLiteral( "qrc:/%1.qml" ).arg( m_name ); - m_qmlFileName = qrcName; - - cDebug() << "QmlViewStep loading" << m_qmlFileName; - m_qmlComponent = new QQmlComponent( - m_qmlWidget->engine(), QUrl( m_qmlFileName ), QQmlComponent::CompilationMode::Asynchronous ); - connect( m_qmlComponent, &QQmlComponent::statusChanged, this, &QmlViewStep::loadComplete ); - cDebug() << Logger::SubEntry << "Status" << m_qmlComponent->status(); + // QML Loading starts when the configuration for the module is set. } QmlViewStep::~QmlViewStep() {} @@ -135,6 +131,10 @@ void Calamares::QmlViewStep::loadComplete() { cDebug() << "QML component" << m_qmlFileName << m_qmlComponent->status(); + if ( m_qmlComponent->status() == QQmlComponent::Error ) + { + showFailedQml(); + } if ( m_qmlComponent->isReady() && !m_qmlObject ) { cDebug() << "QML component complete" << m_qmlFileName; @@ -181,12 +181,40 @@ Calamares::QmlViewStep::showQml() } } -void Calamares::QmlViewStep::setConfigurationMap(const QVariantMap& configurationMap) +void +Calamares::QmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { bool ok = false; m_searchMethod = searchNames().find( CalamaresUtils::getString( configurationMap, "search" ), ok ); - if (!ok) + if ( !ok ) { cDebug() << "Bad QML search mode."; } + + if ( !m_qmlComponent ) + { + // TODO: search for suitable file + QString qrcName = QStringLiteral( "qrc:/X%1.qml" ).arg( m_name ); + m_qmlFileName = qrcName; + + cDebug() << "QmlViewStep" << moduleInstanceKey() << "loading" << m_qmlFileName; + m_qmlComponent = new QQmlComponent( + m_qmlWidget->engine(), QUrl( m_qmlFileName ), QQmlComponent::CompilationMode::Asynchronous ); + connect( m_qmlComponent, &QQmlComponent::statusChanged, this, &QmlViewStep::loadComplete ); + if ( m_qmlComponent->status() == QQmlComponent::Error ) + { + showFailedQml(); + } + } + else + { + cWarning() << "QML configuration set after component has loaded."; + } +} + +void +Calamares::QmlViewStep::showFailedQml() +{ + cWarning() << "QmlViewStep" << moduleInstanceKey() << "loading failed."; + m_spinner->setText( prettyName() + tr( "Loading failed." ) ); } diff --git a/src/libcalamaresui/viewpages/QmlViewStep.h b/src/libcalamaresui/viewpages/QmlViewStep.h index 38405a6a6..46ba29a53 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.h +++ b/src/libcalamaresui/viewpages/QmlViewStep.h @@ -82,6 +82,8 @@ private Q_SLOTS: private: /// @brief Swap out the spinner for the QQuickWidget void showQml(); + /// @brief Show error message in spinner. + void showFailedQml(); /// @brief Controls where m_name is searched QmlSearch m_searchMethod;