From: James Turner Date: Mon, 23 Feb 2015 13:41:30 +0000 (+0000) Subject: Qt launcher: additional arguments UI X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c9c083374191a8c73b9b526e99125f0845cfc2db;p=flightgear.git Qt launcher: additional arguments UI Add a plain text edit widget to the launcher to support custom command line arguments. --- diff --git a/src/GUI/Launcher.ui b/src/GUI/Launcher.ui index 05ddb78b3..4cd666bd9 100644 --- a/src/GUI/Launcher.ui +++ b/src/GUI/Launcher.ui @@ -6,8 +6,8 @@ 0 0 - 696 - 711 + 700 + 700 @@ -376,14 +376,26 @@ Settings - - + + + 10 + + + 10 + + + 10 + + Time of day: + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + @@ -432,53 +444,28 @@ - - - - - - Season: - - - - - - - - Summer - - - - - Winter - - - - - - - + Enable Multi-sample anti-aliasing - + Enable deferred rendering (Rembrandt) - + Enable automatic scenery downloading (TerraSync) - + @@ -511,49 +498,21 @@ - + Fetch real weather online - - - - Start full-screen - - - - + Start paused - - - - - - Custom aircraft directory: - - - - - - - Open in Finder - - - false - - - - - - + Additional scenery locations @@ -631,18 +590,89 @@ - - - - Qt::Vertical + + + + + + Season: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + Summer + + + + + Winter + + + + + + + + + + Start full-screen - - - 20 - 40 - + + + + + + + + Custom aircraft directory: + + + + + + + Open in Finder + + + false + + + + + + + + + Additional options - + + + 8 + + + 8 + + + 8 + + + 8 + + + + + --option=value --prop:/sim/name=value + + + + + diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 815939177..2f1e63445 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -396,6 +396,106 @@ private: } }; +class ArgumentsTokenizer +{ +public: + class Arg + { + public: + explicit Arg(QString k, QString v = QString()) : arg(k), value(v) {} + + QString arg; + QString value; + }; + + QList tokenize(QString in) const + { + int index = 0; + const int len = in.count(); + QChar c, nc; + State state = Start; + QString key, value; + QList result; + + for (; index < len; ++index) { + c = in.at(index); + nc = index < (len - 1) ? in.at(index + 1) : QChar(); + + switch (state) { + case Start: + if (c == QChar('-')) { + if (nc == QChar('-')) { + state = Key; + key.clear(); + ++index; + } else { + // should we pemit single hyphen arguments? + // choosing to fail for now + return QList(); + } + } else if (c.isSpace()) { + break; + } + break; + + case Key: + if (c == QChar('=')) { + state = Value; + value.clear(); + } else if (c.isSpace()) { + state = Start; + result.append(Arg(key)); + } else { + // could check for illegal charatcers here + key.append(c); + } + break; + + case Value: + if (c == QChar('"')) { + state = Quoted; + } else if (c.isSpace()) { + state = Start; + result.append(Arg(key, value)); + } else { + value.append(c); + } + break; + + case Quoted: + if (c == QChar('\\')) { + // check for escaped double-quote inside quoted value + if (nc == QChar('"')) { + ++index; + } + } else if (c == QChar('"')) { + state = Value; + } else { + value.append(c); + } + break; + } // of state switch + } // of character loop + + // ensure last argument isn't lost + if (state == Key) { + result.append(Arg(key)); + } else if (state == Value) { + result.append(Arg(key, value)); + } + + return result; + } + +private: + enum State { + Start = 0, + Key, + Value, + Quoted + }; +}; + } // of anonymous namespace class AirportSearchModel : public QAbstractListModel @@ -746,6 +846,8 @@ void QtLauncher::restoreSettings() QStringList sceneryPaths = settings.value("scenery-paths").toStringList(); m_ui->sceneryPathsList->addItems(sceneryPaths); + + m_ui->commandLineArgs->setPlainText(settings.value("additional-args").toString()); } void QtLauncher::saveSettings() @@ -769,6 +871,7 @@ void QtLauncher::saveSettings() } settings.setValue("scenery-paths", paths); + settings.setValue("additional-args", m_ui->commandLineArgs->toPlainText()); } void QtLauncher::setEnableDisableOptionFromCheckbox(QCheckBox* cbox, QString name) const @@ -858,6 +961,17 @@ void QtLauncher::onRun() opt->addOption("fg-scenery", path.toStdString()); } + // additional arguments + ArgumentsTokenizer tk; + Q_FOREACH(ArgumentsTokenizer::Arg a, tk.tokenize(m_ui->commandLineArgs->toPlainText())) { + if (a.arg.startsWith("prop:")) { + QString v = a.arg.mid(5) + "=" + a.value; + opt->addOption("prop", v.toStdString()); + } else { + opt->addOption(a.arg.toStdString(), a.value.toStdString()); + } + } + saveSettings(); }