[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.
This commit is contained in:
parent
0fd7fec25e
commit
8d6e3e547c
@ -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()
|
||||
{
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user