From dab4b13bfdb1d9da89f0bb44e7211129eca2e121 Mon Sep 17 00:00:00 2001 From: Filippo Scognamiglio Date: Sat, 4 Oct 2014 00:43:15 +0200 Subject: [PATCH] Adding command line parameters to reset the default settings and to change the initial profile. --- app/main.cpp | 10 +++++++++- app/qml/ApplicationSettings.qml | 24 +++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index 259b64f..10c6b96 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -13,7 +13,15 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); QQmlApplicationEngine engine; - // Managing some env variables + // Manage command line arguments from the cpp side + QStringList args = app.arguments(); + if (args.contains("-h") || args.contains("--help")) { + qDebug() << "Usage: " + args.at(0) + " [--default-settings] [-h|--help]"; + qDebug() << " --default-settings Run cool-old-term with the default settings"; + qDebug() << " -p|--profile Run cool-old-term with the given profile."; + qDebug() << " -h|--help Print this help."; + return 0; + } // Manage import paths QStringList importPathList = engine.importPathList(); diff --git a/app/qml/ApplicationSettings.qml b/app/qml/ApplicationSettings.qml index 66327bf..e9fd1b8 100644 --- a/app/qml/ApplicationSettings.qml +++ b/app/qml/ApplicationSettings.qml @@ -379,9 +379,31 @@ Item{ } } + function getProfileIndexByName(name) { + for (var i = 0; i < profileslist.count; i++) { + if(profileslist.get(i).text === name) + return i; + } + return -1; + } + Component.onCompleted: { - loadSettings(); + // Manage the arguments from the QML side. + var args = Qt.application.arguments; + if (args.indexOf("--default-settings") === -1) { + loadSettings(); + } + loadCustomProfiles(); + + var profileArgPosition = args.indexOf("--profile"); + if (profileArgPosition !== -1) { + var profileIndex = getProfileIndexByName(args[profileArgPosition + 1]); + if (profileIndex !== -1) + loadProfile(profileIndex); + else + console.log("Warning: selected profile is not valid; ignoring it"); + } } Component.onDestruction: { storeSettings();