From 7f8a31007a8e07dcd0e430b9f7443777a9b8bc9a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 13 Jan 2020 22:04:27 +0100 Subject: [PATCH] [dummyqml] Search for files - start implementation of searching-for-qml - add a *filename* configuration item, so that the filename can be set per-instance (via the config file) --- src/libcalamaresui/viewpages/QmlViewStep.cpp | 45 ++++++++++++++++++-- src/modules/dummyqml/dummyqml.conf | 3 ++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/libcalamaresui/viewpages/QmlViewStep.cpp b/src/libcalamaresui/viewpages/QmlViewStep.cpp index e26b02430..8fcc75a9b 100644 --- a/src/libcalamaresui/viewpages/QmlViewStep.cpp +++ b/src/libcalamaresui/viewpages/QmlViewStep.cpp @@ -181,6 +181,40 @@ Calamares::QmlViewStep::showQml() } } + +/** @brief Find a suitable QML file, given the search method and name hints + * + * Returns QString() if nothing is found (which would mean the module + * is badly configured). + */ +QString +searchQmlFile( Calamares::QmlViewStep::QmlSearch method, const QString& configuredName, const QString& moduleName ) +{ + cDebug() << "Looking for QML for" << moduleName; + for ( const QString& candidate : + QStringList { configuredName.isEmpty() ? QString() : QStringLiteral( ":/%1.qml" ).arg( configuredName ), + moduleName.isEmpty() ? QString() : QStringLiteral( ":/%1.qml" ).arg( moduleName ) } ) + { + if ( candidate.isEmpty() ) + { + continue; + } + cDebug() << Logger::SubEntry << "Looking at QML file" << candidate; + if ( QFile::exists( candidate ) ) + { + if ( candidate.startsWith( ':' ) ) + { + // Inconsistency: QFile only sees the file with :, + // but QML needs an explicit scheme (of qrc:) + return QStringLiteral( "qrc" ) + candidate; + } + return candidate; + } + } + cDebug() << Logger::SubEntry << "None found."; + return QString(); +} + void Calamares::QmlViewStep::setConfigurationMap( const QVariantMap& configurationMap ) { @@ -191,11 +225,14 @@ Calamares::QmlViewStep::setConfigurationMap( const QVariantMap& configurationMap cDebug() << "Bad QML search mode."; } - if ( !m_qmlComponent ) + QString qmlFile = CalamaresUtils::getString( configurationMap, "filename" ); + if ( qmlFile.isEmpty() ) { - // TODO: search for suitable file - QString qrcName = QStringLiteral( "qrc:/%1.qml" ).arg( m_name ); - m_qmlFileName = qrcName; + cWarning() << "No QML file for module" << m_name; + } + else if ( !m_qmlComponent ) + { + m_qmlFileName = searchQmlFile( m_searchMethod, qmlFile, m_name ); cDebug() << "QmlViewStep" << moduleInstanceKey() << "loading" << m_qmlFileName; m_qmlComponent = new QQmlComponent( diff --git a/src/modules/dummyqml/dummyqml.conf b/src/modules/dummyqml/dummyqml.conf index a861b68bd..e62d35383 100644 --- a/src/modules/dummyqml/dummyqml.conf +++ b/src/modules/dummyqml/dummyqml.conf @@ -15,5 +15,8 @@ # To support instanced QML modules, searches in the branding # directory look for the full module@instanceid name as well. --- +# Search mode. Valid values are "both", "qrc" and "branding" search: both +# Name of the QML file. If not set, uses the name of the module. +filename: dummyqml