diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-09-21 15:23:55 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-09-22 20:39:52 +0200 |
commit | a15472716dbef63f1e5ad27ee412c2a2408b44e2 (patch) | |
tree | 444b0227f2bfca21ee2fbc43e69f381d4bcebd9b /tools/qml | |
parent | 5e3de6aa6083f0cf312e60dc4fc9a7d999bc6c90 (diff) |
Teach the qml runtime to load config files by basename
Also, --list-conf will now list the conf files that it finds;
and --verbose will show more information about the path(s) to them.
[ChangeLog][QtQml][qml] The QML Runtime tool's -c / --config option
now can find a directory containing a file called configuration.qml
under QStandardPaths::AppConfigLocation, in addition to being able to
give the full path to the configuration file, as before. I.e. on
Linux you could write a custom configuration into
~/.config/QtProject/Qml Runtime/myconfig/configuration.qml
and then use it via qml -c myconfig somefile.qml. The --list-conf
option will list the configurations that can be found in this way.
Task-number: QTBUG-26366
Fixes: QTBUG-96740
Change-Id: I72798b22255b71b9d4184a67f86b249766b64233
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tools/qml')
-rw-r--r-- | tools/qml/main.cpp | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 3dd6a4de5c..6ac49661f4 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -97,6 +97,7 @@ static int exitTimerId = -1; #endif static const QString iconResourcePath(QStringLiteral(":/qt-project.org/QmlRuntime/resources/qml-64.png")); static const QString confResourcePath(QStringLiteral(":/qt-project.org/QmlRuntime/conf/")); +static const QString customConfFileName(QStringLiteral("configuration.qml")); static bool verboseMode = false; static bool quietMode = false; static bool glShareContexts = true; @@ -124,7 +125,11 @@ static void loadConf(const QString &override, bool quiet) // Terminates app on f settingsUrl = QUrl::fromLocalFile(fi.absoluteFilePath()); builtIn = true; } else { - fi.setFile(override); + fi.setFile(QDir(QStandardPaths::locate(QStandardPaths::AppConfigLocation, override, QStandardPaths::LocateDirectory)), customConfFileName); + if (fi.exists()) + settingsUrl = QUrl::fromLocalFile(fi.absoluteFilePath()); + else + fi.setFile(override); if (!fi.exists()) { printf("qml: Couldn't find required configuration file: %s\n", qPrintable(QDir::toNativeSeparators(fi.absoluteFilePath()))); @@ -167,10 +172,30 @@ void noFilesGiven() static void listConfFiles() { - QDir confResourceDir(confResourcePath); + const QDir confResourceDir(confResourcePath); printf("%s\n", qPrintable(QCoreApplication::translate("main", "Built-in configurations:"))); for (const QFileInfo &fi : confResourceDir.entryInfoList(QDir::Files)) printf(" %s\n", qPrintable(fi.baseName())); + printf("%s\n", qPrintable(QCoreApplication::translate("main", "Other configurations:"))); + bool foundOther = false; + const QStringList otherLocations = QStandardPaths::standardLocations(QStandardPaths::AppConfigLocation); + for (const auto &confDirPath : otherLocations) { + const QDir confDir(confDirPath); + for (const QFileInfo &fi : confDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) { + foundOther = true; + if (verboseMode) + printf(" %s\n", qPrintable(fi.absoluteFilePath())); + else + printf(" %s\n", qPrintable(fi.baseName())); + } + } + if (!foundOther) + printf(" %s\n", qPrintable(QCoreApplication::translate("main", "none"))); + if (verboseMode) { + printf("%s\n", qPrintable(QCoreApplication::translate("main", "Checked in:"))); + for (const auto &confDirPath : otherLocations) + printf(" %s\n", qPrintable(confDirPath)); + } exit(0); } @@ -493,6 +518,12 @@ int main(int argc, char *argv[]) parser.showVersion(); if (parser.isSet(helpOption)) parser.showHelp(); + if (parser.isSet(verboseOption)) + verboseMode = true; + if (parser.isSet(quietOption)) { + quietMode = true; + verboseMode = false; + } if (parser.isSet(listConfOption)) listConfFiles(); if (applicationType == QmlApplicationTypeUnknown) { @@ -503,12 +534,6 @@ int main(int argc, char *argv[]) #endif // QT_WIDGETS_LIB parser.showHelp(); } - if (parser.isSet(verboseOption)) - verboseMode = true; - if (parser.isSet(quietOption)) { - quietMode = true; - verboseMode = false; - } #if QT_CONFIG(qml_animation) if (parser.isSet(slowAnimationsOption)) QUnifiedTimer::instance()->setSlowModeEnabled(true); |