Core: Warn the user if the settings file cannot be read

Do an initial check and if it fails, warn the user that they cannot
expect subsequent operations to succeed.

Task-number: QTCREATORBUG-18294
Change-Id: I3bb323cf7b7ed99f97258da94cfd7669f8520717
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Christian Kandeler
2019-07-08 17:38:28 +02:00
parent 5dd4bb62b1
commit b7a96a9342
2 changed files with 44 additions and 0 deletions

View File

@@ -27,6 +27,7 @@
#include "designmode.h"
#include "editmode.h"
#include "helpmanager.h"
#include "icore.h"
#include "idocument.h"
#include "infobar.h"
#include "iwizardfactory.h"
@@ -63,6 +64,8 @@
#include <QDebug>
#include <QDir>
#include <QMenu>
#include <QMessageBox>
#include <QSettings>
#include <QUuid>
#include <cstdlib>
@@ -232,6 +235,7 @@ void CorePlugin::extensionsInitialized()
errorOverview->setModal(true);
errorOverview->show();
}
checkSettings();
}
bool CorePlugin::delayedInitialize()
@@ -295,6 +299,45 @@ void CorePlugin::addToPathChooserContextMenu(Utils::PathChooser *pathChooser, QM
menu->insertSeparator(firstAction);
}
void CorePlugin::checkSettings()
{
const auto showMsgBox = [this](const QString &msg, QMessageBox::Icon icon) {
connect(ICore::instance(), &ICore::coreOpened, this, [msg, icon]() {
QMessageBox msgBox(ICore::dialogParent());
msgBox.setWindowTitle(tr("Settings File Error"));
msgBox.setText(msg);
msgBox.setIcon(icon);
msgBox.exec();
}, Qt::QueuedConnection);
};
const QSettings * const userSettings = ICore::settings();
QString errorDetails;
switch (userSettings->status()) {
case QSettings::NoError: {
const QFileInfo fi(userSettings->fileName());
if (fi.exists() && !fi.isWritable()) {
const QString errorMsg = tr("The settings file \"%1\" is not writable.\n"
"You will not be able to store any %2 settings.")
.arg(QDir::toNativeSeparators(userSettings->fileName()),
QLatin1String(Core::Constants::IDE_DISPLAY_NAME));
showMsgBox(errorMsg, QMessageBox::Warning);
}
return;
}
case QSettings::AccessError:
errorDetails = tr("The file is not readable.");
break;
case QSettings::FormatError:
errorDetails = tr("The file is invalid.");
break;
}
const QString errorMsg = tr("Error reading settings file \"%1\": %2\n"
"You will likely experience further problems using this instance of %3.")
.arg(QDir::toNativeSeparators(userSettings->fileName()), errorDetails,
QLatin1String(Core::Constants::IDE_DISPLAY_NAME));
showMsgBox(errorMsg, QMessageBox::Critical);
}
ExtensionSystem::IPlugin::ShutdownFlag CorePlugin::aboutToShutdown()
{
Find::aboutToShutdown();

View File

@@ -80,6 +80,7 @@ private slots:
private:
static void addToPathChooserContextMenu(Utils::PathChooser *pathChooser, QMenu *menu);
void checkSettings();
MainWindow *m_mainWindow = nullptr;
EditMode *m_editMode = nullptr;