forked from qt-creator/qt-creator
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:
@@ -27,6 +27,7 @@
|
|||||||
#include "designmode.h"
|
#include "designmode.h"
|
||||||
#include "editmode.h"
|
#include "editmode.h"
|
||||||
#include "helpmanager.h"
|
#include "helpmanager.h"
|
||||||
|
#include "icore.h"
|
||||||
#include "idocument.h"
|
#include "idocument.h"
|
||||||
#include "infobar.h"
|
#include "infobar.h"
|
||||||
#include "iwizardfactory.h"
|
#include "iwizardfactory.h"
|
||||||
@@ -63,6 +64,8 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QSettings>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -232,6 +235,7 @@ void CorePlugin::extensionsInitialized()
|
|||||||
errorOverview->setModal(true);
|
errorOverview->setModal(true);
|
||||||
errorOverview->show();
|
errorOverview->show();
|
||||||
}
|
}
|
||||||
|
checkSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CorePlugin::delayedInitialize()
|
bool CorePlugin::delayedInitialize()
|
||||||
@@ -295,6 +299,45 @@ void CorePlugin::addToPathChooserContextMenu(Utils::PathChooser *pathChooser, QM
|
|||||||
menu->insertSeparator(firstAction);
|
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()
|
ExtensionSystem::IPlugin::ShutdownFlag CorePlugin::aboutToShutdown()
|
||||||
{
|
{
|
||||||
Find::aboutToShutdown();
|
Find::aboutToShutdown();
|
||||||
|
@@ -80,6 +80,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static void addToPathChooserContextMenu(Utils::PathChooser *pathChooser, QMenu *menu);
|
static void addToPathChooserContextMenu(Utils::PathChooser *pathChooser, QMenu *menu);
|
||||||
|
void checkSettings();
|
||||||
|
|
||||||
MainWindow *m_mainWindow = nullptr;
|
MainWindow *m_mainWindow = nullptr;
|
||||||
EditMode *m_editMode = nullptr;
|
EditMode *m_editMode = nullptr;
|
||||||
|
Reference in New Issue
Block a user