diff --git a/src/GUI/LaunchConfig.cxx b/src/GUI/LaunchConfig.cxx index 3635e9505..4038858c3 100644 --- a/src/GUI/LaunchConfig.cxx +++ b/src/GUI/LaunchConfig.cxx @@ -9,6 +9,8 @@ #include #include #include +#include +#include static bool static_enableDownloadDirUI = true; static QSettings::Format static_binaryFormat = QSettings::InvalidFormat; @@ -175,6 +177,46 @@ QString LaunchConfig::htmlForCommandLine() return html; } +static QString formatArgForClipboard(const LaunchConfig::Arg& a) +{ + if (a.value.isEmpty()) { + return "--" + a.arg + " "; + } else if (a.arg == "prop") { + return "--" + a.arg + ":" + a.value + " "; + } else { + return "--" + a.arg + "=" + a.value + " "; + } +} + +void LaunchConfig::copyCommandLine() +{ + QString r; + + for (auto opt : flightgear::Options::sharedInstance()->extractOptions()) { + r += "--" + QString::fromStdString(opt) + " "; + } + + reset(); + collect(); + const auto extraArgs = extraArgNames(); + + for (auto arg : valuesFromLauncher()) { + auto it = extraArgs.find(arg.arg.toStdString()); + if (it != extraArgs.end()) { + continue; // skipped due to extra arg overriding + } + + r += formatArgForClipboard(arg); + } + + for (auto arg : valuesFromExtraArgs()) { + r += formatArgForClipboard(arg); + } + + QClipboard *clipboard = QGuiApplication::clipboard(); + clipboard->setText(r); +} + bool LaunchConfig::saveConfigToINI() { // create settings using default type (INI) and path (inside FG_HOME), @@ -228,7 +270,7 @@ QVariant LaunchConfig::getValueForKey(QString group, QString key, QVariant defau m_loadSaveSettings->beginGroup(group); auto v = m_loadSaveSettings->value(key, defaultValue); - bool convertedOk = v.convert(defaultValue.type()); + bool convertedOk = v.convert(static_cast(defaultValue.type())); if (!convertedOk) { qWarning() << "type forcing on loaded value failed:" << key << v << v.typeName() << defaultValue; } diff --git a/src/GUI/LaunchConfig.hxx b/src/GUI/LaunchConfig.hxx index f93f686d9..045a0bb41 100644 --- a/src/GUI/LaunchConfig.hxx +++ b/src/GUI/LaunchConfig.hxx @@ -57,6 +57,8 @@ public: Q_INVOKABLE QString htmlForCommandLine(); + Q_INVOKABLE void copyCommandLine(); + bool saveConfigToINI(); bool loadConfigFromINI(); diff --git a/src/GUI/qml/ViewCommandLine.qml b/src/GUI/qml/ViewCommandLine.qml index cb932d459..e2cd18f9c 100644 --- a/src/GUI/qml/ViewCommandLine.qml +++ b/src/GUI/qml/ViewCommandLine.qml @@ -5,12 +5,31 @@ import "." Item { + Row { + id: buttonRow + spacing: Style.margin + height: childrenRect.height + anchors { + margins: Style.margin + top: parent.top + left: parent.left + right: parent.right + } + + Button { + text: qsTr("Copy to clipboard") + onClicked: { + _config.copyCommandLine(); + } + } + } + Flickable { id: flick anchors { left: parent.left right: scrollbar.right - top: parent.top + top: buttonRow.bottom bottom: parent.bottom margins: Style.margin }