Commit 1fec95ac authored by Adriaan de Groot's avatar Adriaan de Groot

[libcalamares] Move QML search-path initialization

- QML files need to be searched in specific places; this was initialized
  by Calamares, but not for the text application. Move initialization
  into the library.
parent 6dffec27
......@@ -120,34 +120,6 @@ CalamaresApplication::mainWindow()
}
static QStringList
qmlDirCandidates( bool assumeBuilddir )
{
static const char QML[] = "qml";
QStringList qmlDirs;
if ( CalamaresUtils::isAppDataDirOverridden() )
{
qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML );
}
else
{
if ( assumeBuilddir )
{
qmlDirs << QDir::current().absoluteFilePath( "src/qml" ); // In build-dir
}
if ( CalamaresUtils::haveExtraDirs() )
for ( auto s : CalamaresUtils::extraDataDirs() )
{
qmlDirs << ( s + QML );
}
qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML );
}
return qmlDirs;
}
static QStringList
brandingFileCandidates( bool assumeBuilddir, const QString& brandingFilename )
{
......@@ -178,38 +150,12 @@ brandingFileCandidates( bool assumeBuilddir, const QString& brandingFilename )
void
CalamaresApplication::initQmlPath()
{
QDir importPath; // Right now, current-dir
QStringList qmlDirCandidatesByPriority = qmlDirCandidates( isDebug() );
bool found = false;
foreach ( const QString& path, qmlDirCandidatesByPriority )
{
QDir dir( path );
if ( dir.exists() && dir.isReadable() )
{
importPath = dir;
found = true;
break;
}
}
if ( !found || !importPath.exists() || !importPath.isReadable() )
#ifdef WITH_QML
if ( !CalamaresUtils::initQmlModulesDir() )
{
cError() << "Cowardly refusing to continue startup without a QML directory."
<< Logger::DebugList( qmlDirCandidatesByPriority );
if ( CalamaresUtils::isAppDataDirOverridden() )
{
cError() << "FATAL: explicitly configured application data directory is missing qml/";
}
else
{
cError() << "FATAL: none of the expected QML paths exist.";
}
::exit( EXIT_FAILURE );
}
cDebug() << "Using Calamares QML directory" << importPath.absolutePath();
CalamaresUtils::setQmlModulesDir( importPath );
#endif
}
......
......@@ -33,6 +33,9 @@
#include "modulesystem/ModuleManager.h"
#include "modulesystem/ViewModule.h"
#include "utils/Logger.h"
#ifdef WITH_QML
#include "utils/Qml.h"
#endif
#include "utils/Yaml.h"
#include "viewpages/ExecutionViewStep.h"
......@@ -366,6 +369,10 @@ main( int argc, char* argv[] )
gs->insert( "localeConf", vm );
}
#ifdef WITH_QML
CalamaresUtils::initQmlModulesDir(); // don't care if failed
#endif
cDebug() << "Calamares module-loader testing" << module.moduleName();
Calamares::Module* m = load_module( module );
if ( !m )
......
......@@ -21,7 +21,9 @@
#include "Branding.h"
#include "GlobalStorage.h"
#include "JobQueue.h"
#include "Settings.h"
#include "ViewManager.h"
#include "utils/Dirs.h"
#include "utils/Logger.h"
#include <QByteArray>
......@@ -46,6 +48,62 @@ setQmlModulesDir( const QDir& dir )
s_qmlModulesDir = dir;
}
static QStringList
qmlDirCandidates( bool assumeBuilddir )
{
static const char QML[] = "qml";
QStringList qmlDirs;
if ( CalamaresUtils::isAppDataDirOverridden() )
{
qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML );
}
else
{
if ( assumeBuilddir )
{
qmlDirs << QDir::current().absoluteFilePath( "src/qml" ); // In build-dir
}
if ( CalamaresUtils::haveExtraDirs() )
for ( auto s : CalamaresUtils::extraDataDirs() )
{
qmlDirs << ( s + QML );
}
qmlDirs << CalamaresUtils::appDataDir().absoluteFilePath( QML );
}
return qmlDirs;
}
bool
initQmlModulesDir()
{
QStringList qmlDirCandidatesByPriority
= qmlDirCandidates( Calamares::Settings::instance() && Calamares::Settings::instance()->debugMode() );
for ( const QString& path : qmlDirCandidatesByPriority )
{
QDir dir( path );
if ( dir.exists() && dir.isReadable() )
{
cDebug() << "Using Calamares QML directory" << dir.absolutePath();
CalamaresUtils::setQmlModulesDir( dir );
return true;
}
}
cError() << "Cowardly refusing to continue startup without a QML directory."
<< Logger::DebugList( qmlDirCandidatesByPriority );
if ( CalamaresUtils::isAppDataDirOverridden() )
{
cError() << "FATAL: explicitly configured application data directory is missing qml/";
}
else
{
cError() << "FATAL: none of the expected QML paths exist.";
}
return false;
}
void
callQmlFunction( QQuickItem* qmlObject, const char* method )
......@@ -85,14 +143,14 @@ addExpansions( QmlSearch method, QStringList& candidates, const QStringList& nam
std::transform( names.constBegin(),
names.constEnd(),
std::back_inserter( candidates ),
[ & ]( const QString& s ) { return s.isEmpty() ? QString() : bPath.arg( brandDir, s ); } );
[&]( 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 ); } );
[&]( const QString& s ) { return s.isEmpty() ? QString() : qrPath.arg( s ); } );
}
}
......
......@@ -35,7 +35,13 @@ UIDLLEXPORT QDir qmlModulesDir();
/// @brief sets specific directory for searching for QML files
UIDLLEXPORT void setQmlModulesDir( const QDir& dir );
/** @brief initialize QML search path with branding directories
*
* Picks a suitable branding directory (from the build-dir in debug mode,
* otherwise based on the branding directory) and adds it to the
* QML modules directory; returns @c false if none is found.
*/
UIDLLEXPORT bool initQmlModulesDir();
/** @brief Sets up global Calamares models for QML
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment