diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 482342483..497d173a2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,6 +13,9 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR}/libcalamaresui ) include_directories( ${CMAKE_CURRENT_LIST_DIR}/libcalamaresui ) add_subdirectory( libcalamaresui ) +# all things qml +add_subdirectory( qml ) + # application add_subdirectory( calamares ) @@ -21,3 +24,4 @@ add_subdirectory( modules ) # branding components add_subdirectory( branding ) + diff --git a/src/branding/default/show.qml b/src/branding/default/show.qml index 70ac54c31..40321bf01 100644 --- a/src/branding/default/show.qml +++ b/src/branding/default/show.qml @@ -1,13 +1,63 @@ +/* === This file is part of Calamares - === + * + * Copyright 2015, Teo Mrnjavac + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + import QtQuick 2.0; -import slideshow 1.0; +import calamares.slideshow 1.0; Presentation { id: presentation - width: 1280 - height: 720 + + Timer { + interval: 5000 + running: false + repeat: true + onTriggered: presentation.goToNextSlide() + } Slide { - centeredText: "Calamares is really nice" + + Image { + id: background + source: "squid.png" + width: 200; height: 200 + fillMode: Image.PreserveAspectFit + anchors.centerIn: parent + } + Text { + anchors.horizontalCenter: background.horizontalCenter + anchors.top: background.bottom + text: "This is a customizable QML slideshow.
"+ + "Distributions should provide their own slideshow and list it in
"+ + "their custom branding.desc file.
"+ + "To create a Calamares presentation in QML, import calamares.slideshow,
"+ + "define a Presentation element with as many Slide elements as needed." + wrapMode: Text.WordWrap + width: root.width + horizontalAlignment: Text.Center + } + } + + Slide { + centeredText: "This is a second Slide element." + } + + Slide { + centeredText: "This is a third Slide element." } } diff --git a/src/calamares/CalamaresApplication.cpp b/src/calamares/CalamaresApplication.cpp index 78b16e3bb..ede38342b 100644 --- a/src/calamares/CalamaresApplication.cpp +++ b/src/calamares/CalamaresApplication.cpp @@ -75,8 +75,8 @@ CalamaresApplication::init() setQuitOnLastWindowClosed( false ); + initQmlPath(); initSettings(); - initBranding(); setWindowIcon( QIcon( Calamares::Branding::instance()-> @@ -136,6 +136,64 @@ CalamaresApplication::startPhase( Calamares::Phase phase ) } +void +CalamaresApplication::initQmlPath() +{ + QDir importPath; + + QString subpath( "qml" ); + + if ( CalamaresUtils::isAppDataDirOverridden() ) + { + importPath = QDir( CalamaresUtils::appDataDir() + .absoluteFilePath( subpath ) ); + if ( !importPath.exists() || !importPath.isReadable() ) + { + cLog() << "FATAL ERROR: explicitly configured application data directory" + << CalamaresUtils::appDataDir().absolutePath() + << "does not contain a valid QML modules directory at" + << importPath.absolutePath() + << "\nCowardly refusing to continue startup without the QML directory."; + ::exit( EXIT_FAILURE ); + } + } + else + { + QStringList qmlDirCandidatesByPriority; + if ( isDebug() ) + { + qmlDirCandidatesByPriority.append( + QDir::current().absoluteFilePath( + QString( "src/%1" ) + .arg( subpath ) ) ); + } + qmlDirCandidatesByPriority.append( CalamaresUtils::appDataDir() + .absoluteFilePath( subpath ) ); + + foreach ( const QString& path, qmlDirCandidatesByPriority ) + { + QDir dir( path ); + if ( dir.exists() && dir.isReadable() ) + { + importPath = dir; + break; + } + } + + if ( !importPath.exists() || !importPath.isReadable() ) + { + cLog() << "FATAL ERROR: none of the expected QML paths (" + << qmlDirCandidatesByPriority.join( ", " ) + << ") exist." + << "\nCowardly refusing to continue startup without the QML directory."; + ::exit( EXIT_FAILURE ); + } + } + + CalamaresUtils::setQmlModulesDir( importPath ); +} + + void CalamaresApplication::initSettings() { diff --git a/src/calamares/CalamaresApplication.h b/src/calamares/CalamaresApplication.h index c14385277..385954b2e 100644 --- a/src/calamares/CalamaresApplication.h +++ b/src/calamares/CalamaresApplication.h @@ -53,6 +53,7 @@ private slots: void onPluginsReady(); private: + void initQmlPath(); void initSettings(); void initBranding(); void initPlugins(); diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index 1b4cbaccd..66450945b 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -42,6 +42,7 @@ namespace CalamaresUtils { static QDir s_appDataDir( CMAKE_INSTALL_FULL_DATADIR ); +static QDir s_qmlModulesDir( QString( CMAKE_INSTALL_FULL_DATADIR ) + "/qml" ); static bool s_isAppDataDirOverridden = false; static QTranslator* s_translator = nullptr; @@ -77,6 +78,14 @@ isWritableDir( const QDir& dir ) return true; } + +QDir +qmlModulesDir() +{ + return s_qmlModulesDir; +} + + void setAppDataDir( const QDir& dir ) { @@ -176,6 +185,13 @@ installTranslator( const QString& localeName, QObject* parent ) } +void +setQmlModulesDir( const QDir &dir ) +{ + s_qmlModulesDir = dir; +} + + QString removeDiacritics( const QString& string ) { diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/CalamaresUtils.h index 00777fb67..ad1c3ce41 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/CalamaresUtils.h @@ -33,6 +33,7 @@ class QObject; namespace CalamaresUtils { + DLLEXPORT QDir qmlModulesDir(); DLLEXPORT QDir appDataDir(); DLLEXPORT QDir appLogDir(); DLLEXPORT QDir systemLibDir(); @@ -44,6 +45,8 @@ namespace CalamaresUtils DLLEXPORT void setAppDataDir( const QDir& dir ); DLLEXPORT bool isAppDataDirOverridden(); + DLLEXPORT void setQmlModulesDir( const QDir& dir ); + DLLEXPORT QString removeDiacritics( const QString& string ); } diff --git a/src/libcalamaresui/CMakeLists.txt b/src/libcalamaresui/CMakeLists.txt index 9c8721861..330e6511b 100644 --- a/src/libcalamaresui/CMakeLists.txt +++ b/src/libcalamaresui/CMakeLists.txt @@ -45,5 +45,3 @@ calamares_add_library( ${CALAMARESUI_LIBRARY_TARGET} EXPORT CalamaresLibraryDepends VERSION ${CALAMARES_VERSION_SHORT} ) - -add_subdirectory( slideshow ) diff --git a/src/libcalamaresui/InstallationViewStep.cpp b/src/libcalamaresui/InstallationViewStep.cpp index 80fa88d20..5e5ea0f5e 100644 --- a/src/libcalamaresui/InstallationViewStep.cpp +++ b/src/libcalamaresui/InstallationViewStep.cpp @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Aurélien Gâteau + * Copyright 2015, Teo Mrnjavac * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -52,61 +53,8 @@ InstallationViewStep::InstallationViewStep( QObject* parent ) m_slideShow->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); m_slideShow->setResizeMode( QQuickWidget::SizeRootObjectToView ); - QDir importPath; - { - QString subpath( "slideshow" ); + m_slideShow->engine()->addImportPath( CalamaresUtils::qmlModulesDir().absolutePath() ); - if ( CalamaresUtils::isAppDataDirOverridden() ) - { - importPath = QDir( CalamaresUtils::appDataDir() - .absoluteFilePath( subpath ) ); - if ( !importPath.exists() || !importPath.isReadable() ) - { - cLog() << "FATAL ERROR: explicitly configured application data directory" - << CalamaresUtils::appDataDir().absolutePath() - << "does not contain a valid slideshow directory at" - << importPath.absolutePath() - << "\nCowardly refusing to continue startup without slideshow."; - ::exit( EXIT_FAILURE ); - } - } - else - { - QStringList slideshowDirCandidatesByPriority; - if ( Calamares::Settings::instance()->debugMode() ) - { - slideshowDirCandidatesByPriority.append( - QDir::current().absoluteFilePath( - QString( "src/libcalamaresui/%1" ) - .arg( subpath ) ) ); - } - slideshowDirCandidatesByPriority.append( CalamaresUtils::appDataDir() - .absoluteFilePath( subpath ) ); - - foreach ( const QString& path, slideshowDirCandidatesByPriority ) - { - QDir dir( path ); - if ( dir.exists() && dir.isReadable() ) - { - importPath = dir; - break; - } - } - - if ( !importPath.exists() || !importPath.isReadable() ) - { - cLog() << "FATAL ERROR: none of the expected slideshow paths (" - << slideshowDirCandidatesByPriority.join( ", " ) - << ") exist." - << "\nCowardly refusing to continue startup without slideshow."; - ::exit( EXIT_FAILURE ); - } - } - } - cDebug() << "importPath:" << importPath; - importPath.cdUp(); - - m_slideShow->engine()->addImportPath( importPath.absolutePath() ); m_slideShow->setSource( QUrl::fromLocalFile( Calamares::Branding::instance() ->slideshowPath() ) ); @@ -117,8 +65,7 @@ InstallationViewStep::InstallationViewStep( QObject* parent ) connect( JobQueue::instance(), &JobQueue::progress, this, &InstallationViewStep::updateFromJobQueue ); - cDebug() << "importPathList:" << m_slideShow->engine()->importPathList(); - + cDebug() << "QML import paths:" << m_slideShow->engine()->importPathList(); } QString diff --git a/src/libcalamaresui/InstallationViewStep.h b/src/libcalamaresui/InstallationViewStep.h index 2ba38c167..2e2085ab4 100644 --- a/src/libcalamaresui/InstallationViewStep.h +++ b/src/libcalamaresui/InstallationViewStep.h @@ -1,6 +1,7 @@ /* === This file is part of Calamares - === * * Copyright 2014, Aurélien Gâteau + * Copyright 2015, Teo Mrnjavac * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/libcalamaresui/slideshow/CMakeLists.txt b/src/libcalamaresui/slideshow/CMakeLists.txt deleted file mode 100644 index babb35824..000000000 --- a/src/libcalamaresui/slideshow/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -set( QML_FILES - qmldir - Presentation.qml - Slide.qml -) - -set( SLIDESHOW_DIR share/calamares/slideshow ) - -foreach( QML_FILE ${QML_FILES} ) - configure_file( ${QML_FILE} ${QML_FILE} COPYONLY ) - install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${QML_FILE} - DESTINATION ${SLIDESHOW_DIR} ) -endforeach() - diff --git a/src/qml/CMakeLists.txt b/src/qml/CMakeLists.txt new file mode 100644 index 000000000..8a949d02e --- /dev/null +++ b/src/qml/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory( calamares ) diff --git a/src/qml/calamares/CMakeLists.txt b/src/qml/calamares/CMakeLists.txt new file mode 100644 index 000000000..ba2fb38b7 --- /dev/null +++ b/src/qml/calamares/CMakeLists.txt @@ -0,0 +1,27 @@ +file( GLOB SUBDIRECTORIES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*" ) + +# Iterate over all the subdirectories which have a qmldir file, copy them over to the build dir, +# and install them into share/calamares/qml/calamares +foreach( SUBDIRECTORY ${SUBDIRECTORIES} ) + if( IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}" + AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/qmldir" ) + + set( QML_DIR share/calamares/qml ) + set( QML_MODULE_DESTINATION ${QML_DIR}/calamares/${SUBDIRECTORY} ) + + # We glob all the files inside the subdirectory, and we make sure they are + # synced with the bindir structure and installed. + file( GLOB QML_MODULE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY} "${SUBDIRECTORY}/*" ) + foreach( QML_MODULE_FILE ${QML_MODULE_FILES} ) + if( NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/${QML_MODULE_FILE} ) + configure_file( ${SUBDIRECTORY}/${QML_MODULE_FILE} ${SUBDIRECTORY}/${QML_MODULE_FILE} COPYONLY ) + + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${SUBDIRECTORY}/${QML_MODULE_FILE} + DESTINATION ${QML_MODULE_DESTINATION} ) + endif() + endforeach() + + message( "-- ${BoldYellow}Configured QML module: ${BoldRed}calamares.${SUBDIRECTORY}${ColorReset}" ) + + endif() +endforeach() diff --git a/src/libcalamaresui/slideshow/Presentation.qml b/src/qml/calamares/slideshow/Presentation.qml similarity index 100% rename from src/libcalamaresui/slideshow/Presentation.qml rename to src/qml/calamares/slideshow/Presentation.qml diff --git a/src/libcalamaresui/slideshow/Slide.qml b/src/qml/calamares/slideshow/Slide.qml similarity index 100% rename from src/libcalamaresui/slideshow/Slide.qml rename to src/qml/calamares/slideshow/Slide.qml diff --git a/src/libcalamaresui/slideshow/qmldir b/src/qml/calamares/slideshow/qmldir similarity index 67% rename from src/libcalamaresui/slideshow/qmldir rename to src/qml/calamares/slideshow/qmldir index 9b3160e66..5a0c277b4 100644 --- a/src/libcalamaresui/slideshow/qmldir +++ b/src/qml/calamares/slideshow/qmldir @@ -1,4 +1,4 @@ -module slideshow +module calamares.slideshow Presentation 1.0 Presentation.qml Slide 1.0 Slide.qml