[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.
This commit is contained in:
Adriaan de Groot 2020-05-19 21:25:05 +02:00
parent 6dffec2730
commit 1fec95ac48
4 changed files with 77 additions and 60 deletions

View File

@ -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 )
#ifdef WITH_QML
if ( !CalamaresUtils::initQmlModulesDir() )
{
QDir dir( path );
if ( dir.exists() && dir.isReadable() )
{
importPath = dir;
found = true;
break;
}
}
if ( !found || !importPath.exists() || !importPath.isReadable() )
{
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
}

View File

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

View File

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

View File

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