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 "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();
}

View file

@ -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;

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

@ -40,7 +40,9 @@
#include <Include/version.h>
#include <Viewer/WindowBuilder.hxx>
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();
}

View file

@ -41,6 +41,10 @@ public:
static bool runDialog(bool usingDefaultRoot);
static SGPath restoreUserSelectedRoot();
static void askRootOnNextLaunch();
static QString rootPathKey();
private slots:
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 (showLauncher) {
flightgear::checkKeyboardModifiersForSettingFGRoot();
if (!flightgear::runLauncherDialog()) {
return EXIT_SUCCESS;
}