Handle errors when restoring/saving settings
This commit is contained in:
parent
05e0ad5696
commit
a829ca0e65
|
@ -123,7 +123,7 @@ include(BasicConfig)
|
|||
set(CONFIGURATION_PACKAGE_SUFFIX_QTUTILITIES
|
||||
"${CONFIGURATION_PACKAGE_SUFFIX}"
|
||||
CACHE STRING "sets the suffix for qtutilities")
|
||||
find_package(qtutilities${CONFIGURATION_PACKAGE_SUFFIX_QTUTILITIES} 6.8.0 REQUIRED)
|
||||
find_package(qtutilities${CONFIGURATION_PACKAGE_SUFFIX_QTUTILITIES} 6.11.0 REQUIRED)
|
||||
use_qt_utilities()
|
||||
|
||||
# find passwordfile
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
|
||||
using namespace CppUtilities;
|
||||
|
@ -35,6 +36,7 @@ int runWidgetsGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs,
|
|||
// restore Qt settings
|
||||
auto qtSettings = QtSettings();
|
||||
auto settings = QtUtilities::getSettings(QStringLiteral(PROJECT_NAME));
|
||||
auto settingsError = QtUtilities::errorMessageForSettings(*settings);
|
||||
qtSettings.restore(*settings);
|
||||
qtSettings.apply();
|
||||
|
||||
|
@ -43,6 +45,9 @@ int runWidgetsGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs,
|
|||
LOAD_QT_TRANSLATIONS;
|
||||
|
||||
// init widgets GUI
|
||||
if (!settingsError.isEmpty()) {
|
||||
QMessageBox::critical(nullptr, QCoreApplication::applicationName(), settingsError);
|
||||
}
|
||||
auto w = MainWindow(*settings, &qtSettings);
|
||||
w.show();
|
||||
if (!file.isEmpty()) {
|
||||
|
@ -51,6 +56,17 @@ int runWidgetsGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs,
|
|||
|
||||
// start event loop
|
||||
QObject::connect(&application, &QCoreApplication::aboutToQuit, &OpenSsl::clean);
|
||||
return application.exec();
|
||||
auto res = application.exec();
|
||||
|
||||
// save settings to disk
|
||||
settings->sync();
|
||||
if (settingsError.isEmpty()) {
|
||||
settingsError = QtUtilities::errorMessageForSettings(*settings);
|
||||
if (!settingsError.isEmpty()) {
|
||||
QMessageBox::critical(nullptr, QCoreApplication::applicationName(), settingsError);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
} // namespace QtGui
|
||||
|
|
|
@ -318,6 +318,9 @@ Kirigami.ApplicationWindow {
|
|||
})
|
||||
}
|
||||
}
|
||||
onSettingsError: {
|
||||
showPassiveNotification(errorMessage)
|
||||
}
|
||||
onPasswordRequired: {
|
||||
enterPasswordDialog.askForExistingPassword(
|
||||
qsTr("Password required to open %1").arg(
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <qtutilities/misc/compat.h>
|
||||
#include <qtutilities/misc/dialogutils.h>
|
||||
#include <qtutilities/resources/resources.h>
|
||||
|
||||
#include <c++utilities/io/nativefilestream.h>
|
||||
#include <c++utilities/io/path.h>
|
||||
|
@ -122,6 +123,9 @@ void Controller::init()
|
|||
if (!m_filePath.isEmpty()) {
|
||||
load();
|
||||
}
|
||||
if (const auto error = QtUtilities::errorMessageForSettings(m_settings); !error.isEmpty()) {
|
||||
emit settingsError(error);
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::load()
|
||||
|
|
|
@ -128,6 +128,7 @@ Q_SIGNALS:
|
|||
void undoStackChanged(QUndoStack *undoStack);
|
||||
void undoTextChanged(const QString &undoText);
|
||||
void redoTextChanged(const QString &redoText);
|
||||
void settingsError(const QString &errorMessage);
|
||||
|
||||
private Q_SLOTS:
|
||||
void handleEntriesRemoved(const QModelIndex &parentIndex, int first, int last);
|
||||
|
|
Loading…
Reference in New Issue