Load QML modules in a central place + dummy QML slideshow.

This commit is contained in:
Teo Mrnjavac 2015-01-23 20:24:12 +01:00
parent 14ddba70ef
commit 9622888d1d
15 changed files with 170 additions and 78 deletions

View File

@ -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 )

View File

@ -1,13 +1,63 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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.<br/>"+
"Distributions should provide their own slideshow and list it in <br/>"+
"their custom branding.desc file.<br/>"+
"To create a Calamares presentation in QML, import calamares.slideshow,<br/>"+
"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."
}
}

View File

@ -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()
{

View File

@ -53,6 +53,7 @@ private slots:
void onPluginsReady();
private:
void initQmlPath();
void initSettings();
void initBranding();
void initPlugins();

View File

@ -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 )
{

View File

@ -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 );
}

View File

@ -45,5 +45,3 @@ calamares_add_library( ${CALAMARESUI_LIBRARY_TARGET}
EXPORT CalamaresLibraryDepends
VERSION ${CALAMARES_VERSION_SHORT}
)
add_subdirectory( slideshow )

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
*
* 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

View File

@ -1,6 +1,7 @@
/* === This file is part of Calamares - <http://github.com/calamares> ===
*
* Copyright 2014, Aurélien Gâteau <agateau@kde.org>
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
*
* Calamares is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -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()

1
src/qml/CMakeLists.txt Normal file
View File

@ -0,0 +1 @@
add_subdirectory( calamares )

View File

@ -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()

View File

@ -1,4 +1,4 @@
module slideshow
module calamares.slideshow
Presentation 1.0 Presentation.qml
Slide 1.0 Slide.qml