1
0
Fork 0

Fix reset-data-path dialog logic

Use correct root path key in QSettings, everywhere
Use the direct Win32 API until Qt wrapper is fixed.
This commit is contained in:
James Turner 2020-03-26 17:10:14 +00:00
parent 0483f2996a
commit 8ddf4d6699
5 changed files with 30 additions and 18 deletions

View file

@ -53,6 +53,7 @@
#include "FlightPlanController.hxx" #include "FlightPlanController.hxx"
#include "ModelDataExtractor.hxx" #include "ModelDataExtractor.hxx"
#include "CarriersLocationModel.hxx" #include "CarriersLocationModel.hxx"
#include "SetupRootDialog.hxx"
using namespace simgear::pkg; using namespace simgear::pkg;
@ -767,7 +768,7 @@ void LauncherController::requestChangeDataPath()
{ {
QString currentLocText; QString currentLocText;
QSettings settings; QSettings settings;
QString root = settings.value("fg-root").toString(); QString root = settings.value(SetupRootDialog::rootPathKey()).toString();
if (root.isNull()) { if (root.isNull()) {
currentLocText = tr("Currently the built-in data files are being used"); currentLocText = tr("Currently the built-in data files are being used");
} }
@ -791,12 +792,7 @@ void LauncherController::requestChangeDataPath()
return; return;
} }
{ SetupRootDialog::askRootOnNextLaunch();
QSettings settings;
// set the option to the magic marker value
settings.setValue("fg-root", "!ask");
} // scope the ensure settings are written nicely
flightgear::restartTheApp(); flightgear::restartTheApp();
} }

View file

@ -356,19 +356,22 @@ void initQSettings()
bool checkKeyboardModifiersForSettingFGRoot() bool checkKeyboardModifiersForSettingFGRoot()
{ {
initQSettings(); 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(); Qt::KeyboardModifiers mods = qApp->queryKeyboardModifiers();
if (mods & (Qt::AltModifier | Qt::ShiftModifier)) { if (mods & (Qt::AltModifier | Qt::ShiftModifier))
#endif
{
qWarning() << "Alt/shift pressed during launch"; qWarning() << "Alt/shift pressed during launch";
QSettings settings;
settings.setValue("fg-root", "!ask");
return true; return true;
} }
return false; return false;
} }
void restartTheApp() void restartTheApp()
{ {
QStringList fgArgs; QStringList fgArgs;

20
src/GUI/SetupRootDialog.cxx Normal file → Executable file
View file

@ -40,7 +40,9 @@
#include <Include/version.h> #include <Include/version.h>
#include <Viewer/WindowBuilder.hxx> #include <Viewer/WindowBuilder.hxx>
static QString rootPathKey() #include "QtLauncher.hxx"
QString SetupRootDialog::rootPathKey()
{ {
// return a settings key like fg-root-2018-3-0 // return a settings key like fg-root-2018-3-0
return QString("fg-root-") + QString(FLIGHTGEAR_VERSION).replace('.', '-'); return QString("fg-root-") + QString(FLIGHTGEAR_VERSION).replace('.', '-');
@ -99,7 +101,8 @@ SGPath SetupRootDialog::restoreUserSelectedRoot()
{ {
QSettings settings; QSettings settings;
QString path = settings.value(rootPathKey()).toString(); QString path = settings.value(rootPathKey()).toString();
if (path == "!ask") { bool ask = flightgear::checkKeyboardModifiersForSettingFGRoot();
if (ask || (path == QStringLiteral("!ask"))) {
bool ok = runDialog(ManualChoiceRequested); bool ok = runDialog(ManualChoiceRequested);
Q_ASSERT(ok); Q_ASSERT(ok);
// run dialog either exit()s or sets fg_root, so this // run dialog either exit()s or sets fg_root, so this
@ -108,7 +111,7 @@ SGPath SetupRootDialog::restoreUserSelectedRoot()
} }
if (path.isEmpty()) { if (path.isEmpty()) {
return std::string(); // use the default path return SGPath{}; // use the default path
} }
if (validatePath(path) && validateVersion(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 // let's see if the default root is acceptable, in which case we will
// switch to it. (This gives a more friendly upgrade experience). // switch to it. (This gives a more friendly upgrade experience).
if (defaultRootAcceptable()) { 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 // 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) bool SetupRootDialog::validatePath(QString path)
{ {
// check assorted files exist in the root location, to avoid any chance of // 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()); m_browsedPath = QString::fromStdString(r.utf8Str());
globals->set_fg_root(r); globals->set_fg_root(r);
QSettings settings; QSettings settings;
settings.remove("fg-root"); // remove any setting settings.remove(rootPathKey()); // remove any setting
accept(); accept();
} }

View file

@ -41,6 +41,10 @@ public:
static bool runDialog(bool usingDefaultRoot); static bool runDialog(bool usingDefaultRoot);
static SGPath restoreUserSelectedRoot(); static SGPath restoreUserSelectedRoot();
static void askRootOnNextLaunch();
static QString rootPathKey();
private slots: private slots:
void onBrowse(); void onBrowse();

1
src/Main/main.cxx Normal file → Executable file
View file

@ -629,7 +629,6 @@ int fgMainInit( int argc, char **argv )
#if defined(HAVE_QT) #if defined(HAVE_QT)
if (showLauncher) { if (showLauncher) {
flightgear::checkKeyboardModifiersForSettingFGRoot();
if (!flightgear::runLauncherDialog()) { if (!flightgear::runLauncherDialog()) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }