diff --git a/src/GUI/LauncherController.cxx b/src/GUI/LauncherController.cxx index 84322c053..bd9be2439 100644 --- a/src/GUI/LauncherController.cxx +++ b/src/GUI/LauncherController.cxx @@ -53,6 +53,7 @@ #include "FlightPlanController.hxx" #include "ModelDataExtractor.hxx" #include "CarriersLocationModel.hxx" +#include "SetupRootDialog.hxx" using namespace simgear::pkg; @@ -767,7 +768,7 @@ void LauncherController::requestChangeDataPath() { QString currentLocText; QSettings settings; - QString root = settings.value("fg-root").toString(); + QString root = settings.value(SetupRootDialog::rootPathKey()).toString(); if (root.isNull()) { currentLocText = tr("Currently the built-in data files are being used"); } @@ -791,12 +792,7 @@ void LauncherController::requestChangeDataPath() return; } - { - QSettings settings; - // set the option to the magic marker value - settings.setValue("fg-root", "!ask"); - } // scope the ensure settings are written nicely - + SetupRootDialog::askRootOnNextLaunch(); flightgear::restartTheApp(); } diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 0f45e10e7..c1e18e5ce 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -356,19 +356,22 @@ void initQSettings() bool checkKeyboardModifiersForSettingFGRoot() { initQSettings(); - +#if defined(Q_OS_WIN) + const auto altState = GetAsyncKeyState(VK_MENU); + const auto shiftState = GetAsyncKeyState(VK_SHIFT); + if ((altState < 0) || (shiftState < 0)) +#else Qt::KeyboardModifiers mods = qApp->queryKeyboardModifiers(); - if (mods & (Qt::AltModifier | Qt::ShiftModifier)) { + if (mods & (Qt::AltModifier | Qt::ShiftModifier)) +#endif + { qWarning() << "Alt/shift pressed during launch"; - QSettings settings; - settings.setValue("fg-root", "!ask"); return true; } return false; } - void restartTheApp() { QStringList fgArgs; diff --git a/src/GUI/SetupRootDialog.cxx b/src/GUI/SetupRootDialog.cxx old mode 100644 new mode 100755 index 756380878..685db1e61 --- a/src/GUI/SetupRootDialog.cxx +++ b/src/GUI/SetupRootDialog.cxx @@ -40,7 +40,9 @@ #include #include -static QString rootPathKey() +#include "QtLauncher.hxx" + +QString SetupRootDialog::rootPathKey() { // return a settings key like fg-root-2018-3-0 return QString("fg-root-") + QString(FLIGHTGEAR_VERSION).replace('.', '-'); @@ -99,7 +101,8 @@ SGPath SetupRootDialog::restoreUserSelectedRoot() { QSettings settings; QString path = settings.value(rootPathKey()).toString(); - if (path == "!ask") { + bool ask = flightgear::checkKeyboardModifiersForSettingFGRoot(); + if (ask || (path == QStringLiteral("!ask"))) { bool ok = runDialog(ManualChoiceRequested); Q_ASSERT(ok); // run dialog either exit()s or sets fg_root, so this @@ -108,7 +111,7 @@ SGPath SetupRootDialog::restoreUserSelectedRoot() } if (path.isEmpty()) { - return std::string(); // use the default path + return SGPath{}; // use the default path } if (validatePath(path) && validateVersion(path)) { @@ -118,7 +121,7 @@ SGPath SetupRootDialog::restoreUserSelectedRoot() // let's see if the default root is acceptable, in which case we will // switch to it. (This gives a more friendly upgrade experience). if (defaultRootAcceptable()) { - return std::string(); // use the default path + return SGPath{}; // use the default path } // okay, we don't have an acceptable FG_DATA anywhere we can find, we @@ -131,6 +134,13 @@ SGPath SetupRootDialog::restoreUserSelectedRoot() } } +void SetupRootDialog::askRootOnNextLaunch() +{ + QSettings settings; + // set the option to the magic marker value + settings.setValue(rootPathKey(), "!ask"); +} + bool SetupRootDialog::validatePath(QString path) { // check assorted files exist in the root location, to avoid any chance of @@ -216,7 +226,7 @@ void SetupRootDialog::onUseDefaults() m_browsedPath = QString::fromStdString(r.utf8Str()); globals->set_fg_root(r); QSettings settings; - settings.remove("fg-root"); // remove any setting + settings.remove(rootPathKey()); // remove any setting accept(); } diff --git a/src/GUI/SetupRootDialog.hxx b/src/GUI/SetupRootDialog.hxx index d294c1938..79f758e3f 100644 --- a/src/GUI/SetupRootDialog.hxx +++ b/src/GUI/SetupRootDialog.hxx @@ -41,6 +41,10 @@ public: static bool runDialog(bool usingDefaultRoot); static SGPath restoreUserSelectedRoot(); + + static void askRootOnNextLaunch(); + + static QString rootPathKey(); private slots: void onBrowse(); diff --git a/src/Main/main.cxx b/src/Main/main.cxx old mode 100644 new mode 100755 index 6bb2828d6..9727d9a29 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -629,7 +629,6 @@ int fgMainInit( int argc, char **argv ) #if defined(HAVE_QT) if (showLauncher) { - flightgear::checkKeyboardModifiersForSettingFGRoot(); if (!flightgear::runLauncherDialog()) { return EXIT_SUCCESS; }