From 8d6e3e547c45d2ea1c28e8ad4e01efbbf6184f2a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 12 Mar 2020 04:17:48 +0100 Subject: [PATCH 1/6] [libcalamaresui] Add qmlSearch for non-modules - Refactor into a support method and two API points - Use std::transform for doing-things-to-a-list - Add searchQmlFile that only takes a name, for non-modules to use. --- src/libcalamaresui/utils/Qml.cpp | 62 ++++++++++++++++++++++++-------- src/libcalamaresui/utils/Qml.h | 1 + 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/libcalamaresui/utils/Qml.cpp b/src/libcalamaresui/utils/Qml.cpp index 5dca2fba1..0b2c84616 100644 --- a/src/libcalamaresui/utils/Qml.cpp +++ b/src/libcalamaresui/utils/Qml.cpp @@ -52,30 +52,48 @@ callQMLFunction( QQuickItem* qmlObject, const char* method ) } } - -QString -searchQmlFile( QmlSearch method, const QString& configuredName, const Calamares::ModuleSystem::InstanceKey& i ) +/** @brief Appends to @p candidates suitable expansions of @p names + * + * Depending on @p method, adds search expansions for branding, or QRC, + * or both (with branding having precedence). + */ +static void +addExpansions( QmlSearch method, QStringList& candidates, const QStringList& names ) { QString bPath( QStringLiteral( "%1/%2.qml" ) ); QString qrPath( QStringLiteral( ":/%1.qml" ) ); - cDebug() << "Looking for QML for" << i.toString(); + if ( ( method == QmlSearch::Both ) || ( method == QmlSearch::BrandingOnly ) ) + { + QString brandDir = Calamares::Branding::instance()->componentDirectory(); + std::transform( names.constBegin(), + names.constEnd(), + std::back_inserter( candidates ), + [&]( const QString& s ) { return s.isEmpty() ? QString() : bPath.arg( brandDir, s ); } ); + } + if ( ( method == QmlSearch::Both ) || ( method == QmlSearch::QrcOnly ) ) + { + std::transform( names.constBegin(), + names.constEnd(), + std::back_inserter( candidates ), + [&]( const QString& s ) { return s.isEmpty() ? QString() : qrPath.arg( s ); } ); + } +} + +/** @brief Does actual search and returns result. + * + * Empty items in @p candidates are ignored. + */ +static QString +searchQmlFile( QmlSearch method, const QString& configuredName, const QStringList& hints ) +{ QStringList candidates; if ( configuredName.startsWith( '/' ) ) { candidates << configuredName; } - if ( ( method == QmlSearch::Both ) || ( method == QmlSearch::BrandingOnly ) ) - { - QString brandDir = Calamares::Branding::instance()->componentDirectory(); - candidates << ( configuredName.isEmpty() ? QString() : bPath.arg( brandDir, configuredName ) ) - << bPath.arg( brandDir, i.toString() ) << bPath.arg( brandDir, i.module() ); - } - if ( ( method == QmlSearch::Both ) || ( method == QmlSearch::QrcOnly ) ) - { - candidates << ( configuredName.isEmpty() ? QString() : qrPath.arg( configuredName ) ) - << qrPath.arg( i.toString() ) << qrPath.arg( i.module() ); - } + addExpansions( method, candidates, hints ); + for ( const QString& candidate : candidates ) { if ( candidate.isEmpty() ) @@ -98,6 +116,20 @@ searchQmlFile( QmlSearch method, const QString& configuredName, const Calamares: return QString(); } +QString +searchQmlFile( QmlSearch method, const QString& configuredName, const Calamares::ModuleSystem::InstanceKey& i ) +{ + cDebug() << "Looking for QML for" << i.toString(); + return searchQmlFile( method, configuredName, { configuredName, i.toString(), i.module() } ); +} + +QString +searchQmlFile( QmlSearch method, const QString& configuredName ) +{ + cDebug() << "Looking for QML for" << configuredName; + return searchQmlFile( method, configuredName, { configuredName } ); +} + const NamedEnumTable< QmlSearch >& qmlSearchNames() { diff --git a/src/libcalamaresui/utils/Qml.h b/src/libcalamaresui/utils/Qml.h index f859add21..f4c722fba 100644 --- a/src/libcalamaresui/utils/Qml.h +++ b/src/libcalamaresui/utils/Qml.h @@ -70,6 +70,7 @@ UIDLLEXPORT const NamedEnumTable< QmlSearch >& qmlSearchNames(); UIDLLEXPORT QString searchQmlFile( QmlSearch method, const QString& configuredName, const Calamares::ModuleSystem::InstanceKey& i ); +UIDLLEXPORT QString searchQmlFile( QmlSearch method, const QString& fileNameNoSuffix ); } // namespace CalamaresUtils From 32ebb087889beced382a55c25608820f64d21161 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 12 Mar 2020 04:21:03 +0100 Subject: [PATCH 2/6] [calamares] Search for sidebar QML file - change name to "calamares-sidebar" so it's clear that it is a core component. --- src/calamares/CalamaresWindow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calamares/CalamaresWindow.cpp b/src/calamares/CalamaresWindow.cpp index 33bf66373..71e82cb90 100644 --- a/src/calamares/CalamaresWindow.cpp +++ b/src/calamares/CalamaresWindow.cpp @@ -136,7 +136,8 @@ CalamaresWindow::getQmlSidebar( int desiredWidth ) { CalamaresUtils::registerCalamaresModels(); QQuickWidget* w = new QQuickWidget( this ); - w->setSource( QUrl( ":/sidebar.qml" ) ); + w->setSource( QUrl( + CalamaresUtils::searchQmlFile( CalamaresUtils::QmlSearch::Both, QStringLiteral( "calamares-sidebar" ) ) ) ); return w; } From cc3b0b285906c8f5d6871ec8ae80f4ecf8f81842 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 12 Mar 2020 04:40:17 +0100 Subject: [PATCH 3/6] [calamares] Remove cruft from CMakeLists.txt --- src/calamares/CMakeLists.txt | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index 78245f614..dfd04c21b 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -11,22 +11,18 @@ set( calamaresSources ) include_directories( - . - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_BINARY_DIR}/../libcalamares - ${CMAKE_SOURCE_DIR}/src/libcalamares - ${CMAKE_SOURCE_DIR}/src//libcalamaresui - ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/src/libcalamaresui + ${CMAKE_BINARY_DIR}/src/libcalamares + ${CMAKE_CURRENT_SOURCE_DIR} ) # Translations include( CalamaresAddTranslations ) add_calamares_translations( ${CALAMARES_TRANSLATION_LANGUAGES} ) -set( final_src ${calamaresSources} ${calamaresRc} ${trans_outfile} ) - -add_executable( calamares_bin ${final_src} ) +add_executable( calamares_bin ${calamaresSources} ${calamaresRc} ${trans_outfile} ) +target_include_directories( calamares_bin PRIVATE ${CMAKE_SOURCE_DIR} ) set_target_properties(calamares_bin PROPERTIES ENABLE_EXPORTS TRUE @@ -37,7 +33,7 @@ calamares_autouic( calamares_bin ) target_link_libraries( calamares_bin PRIVATE - ${CALAMARES_LIBRARIES} + calamares calamaresui Qt5::Core Qt5::Widgets @@ -63,6 +59,6 @@ install( FILES ${CMAKE_SOURCE_DIR}/data/images/squid.svg if( BUILD_TESTING ) add_executable( loadmodule testmain.cpp ) - target_link_libraries( loadmodule ${CALAMARES_LIBRARIES} Qt5::Core Qt5::Widgets calamaresui ) + target_link_libraries( loadmodule PRIVATE Qt5::Core Qt5::Widgets calamares calamaresui ) # Don't install, it's just for enable_testing endif() From cec406e4029dc85d3b394193f300fe58b5ef2399 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 12 Mar 2020 04:59:01 +0100 Subject: [PATCH 4/6] [calamares] Add a sample QML-sidebar - The built-in one is loaded if no branding file is found. - This sidebar is just the most basic of QML examples. --- src/calamares/CMakeLists.txt | 1 + src/calamares/calamares-sidebar.qml | 12 ++++++++++++ src/calamares/calamares.qrc | 5 +++++ 3 files changed, 18 insertions(+) create mode 100644 src/calamares/calamares-sidebar.qml create mode 100644 src/calamares/calamares.qrc diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index dfd04c21b..81fd0d132 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -20,6 +20,7 @@ include_directories( # Translations include( CalamaresAddTranslations ) add_calamares_translations( ${CALAMARES_TRANSLATION_LANGUAGES} ) +qt5_add_resources( calamaresRc calamares.qrc ) add_executable( calamares_bin ${calamaresSources} ${calamaresRc} ${trans_outfile} ) target_include_directories( calamares_bin PRIVATE ${CMAKE_SOURCE_DIR} ) diff --git a/src/calamares/calamares-sidebar.qml b/src/calamares/calamares-sidebar.qml new file mode 100644 index 000000000..6cab24bec --- /dev/null +++ b/src/calamares/calamares-sidebar.qml @@ -0,0 +1,12 @@ +import QtQuick 2.3 + +Rectangle { + width: 200 + height: 100 + color: "red" + + Text { + anchors.centerIn: parent + text: "Hello, World!" + } +} diff --git a/src/calamares/calamares.qrc b/src/calamares/calamares.qrc new file mode 100644 index 000000000..fdcd5e05d --- /dev/null +++ b/src/calamares/calamares.qrc @@ -0,0 +1,5 @@ + + + calamares-sidebar.qml + + From b5a09d2f83886d006e2266d7d4382334618fa14c Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 12 Mar 2020 05:00:03 +0100 Subject: [PATCH 5/6] [branding] Don't hide the sidebar by default --- src/branding/default/branding.desc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/branding/default/branding.desc b/src/branding/default/branding.desc index c3c0796cd..e7b9d9898 100644 --- a/src/branding/default/branding.desc +++ b/src/branding/default/branding.desc @@ -45,7 +45,7 @@ windowPlacement: center # - "widget" or unset, use traditional sidebar (logo, items) # - "none", hide it entirely # - "qml", use sidebar.qml from branding folder -sidebar: none +sidebar: widget # These are strings shown to the user in the user interface. # There is no provision for translating them -- since they From aeffda945f53604e57ce7d6ef5e03d6570b5f21d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 12 Mar 2020 15:38:49 +0100 Subject: [PATCH 6/6] [calamares] Use the ViewManager model to show steps --- src/calamares/calamares-sidebar.qml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/calamares/calamares-sidebar.qml b/src/calamares/calamares-sidebar.qml index 6cab24bec..a486bdb17 100644 --- a/src/calamares/calamares-sidebar.qml +++ b/src/calamares/calamares-sidebar.qml @@ -1,12 +1,35 @@ import QtQuick 2.3 +import io.calamares.ui 1.0 +import io.calamares.core 1.0 + +Column { Rectangle { + id: hello width: 200 height: 100 color: "red" Text { anchors.centerIn: parent - text: "Hello, World!" + text: Branding.string(Branding.VersionedName) } } + +/* perhaps we could show a branding image here */ + +Repeater { + model: ViewManager + Rectangle { + width: 200 + height: 75 + color: "black" + + Text { + color: completed ? "green" : "yellow" + text: display + } + } +} + +}