From 368c9e9b0e582c696eecb354973cb2ef01e4a447 Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 17 Feb 2023 19:17:17 +0100 Subject: [PATCH] Add function to return an error message for a `QSettings` object --- resources/resources.cpp | 21 +++++++++++++++++++++ resources/resources.h | 1 + translations/qtutilities_de_DE.ts | 23 +++++++++++++++++++++++ translations/qtutilities_en_US.ts | 23 +++++++++++++++++++++++ translations/qtutilities_zh_CN.ts | 23 +++++++++++++++++++++++ 5 files changed, 91 insertions(+) diff --git a/resources/resources.cpp b/resources/resources.cpp index 4904f2e..2312e10 100644 --- a/resources/resources.cpp +++ b/resources/resources.cpp @@ -369,6 +369,27 @@ std::unique_ptr getSettings(const QString &organization, const QStrin return settings; } +/*! + * \brief Returns an error message for the specified \a settings or an empty string if there's no error. + */ +QString errorMessageForSettings(const QSettings &settings) +{ + auto errorMessage = QString(); + switch (settings.status()) { + case QSettings::NoError: + return QString(); + case QSettings::AccessError: + errorMessage = QCoreApplication::translate("QtUtilities", "unable to access file"); + break; + case QSettings::FormatError: + errorMessage = QCoreApplication::translate("QtUtilities", "file has invalid format"); + break; + default: + errorMessage = QCoreApplication::translate("QtUtilities", "unknown error"); + } + return QCoreApplication::translate("QtUtilities", "Unable to sync settings from \"%1\": %2").arg(settings.fileName(), errorMessage); +} + // namespace ApplicationInstances } // namespace QtUtilities diff --git a/resources/resources.h b/resources/resources.h index f20ee11..c9ee7a3 100644 --- a/resources/resources.h +++ b/resources/resources.h @@ -68,6 +68,7 @@ QT_UTILITIES_EXPORT bool hasCoreApp(); QT_UTILITIES_EXPORT void setupCommonQtApplicationAttributes(); QT_UTILITIES_EXPORT std::unique_ptr getSettings(const QString &organization, const QString &application = QString()); +QT_UTILITIES_EXPORT QString errorMessageForSettings(const QSettings &settings); } // namespace QtUtilities diff --git a/translations/qtutilities_de_DE.ts b/translations/qtutilities_de_DE.ts index dd28fbd..0b3c442 100644 --- a/translations/qtutilities_de_DE.ts +++ b/translations/qtutilities_de_DE.ts @@ -25,6 +25,29 @@ + + QtUtilities + + + unable to access file + Zugriff auf die Datei ist nicht möglich + + + + file has invalid format + Datei hat ungültiges Format + + + + unknown error + unbekannter Fehler + + + + Unable to sync settings from "%1": %2 + Settings können nicht unter "%1" synchronisiert werden: %2 + + QtUtilities::AboutDialog diff --git a/translations/qtutilities_en_US.ts b/translations/qtutilities_en_US.ts index 70983c6..7321520 100644 --- a/translations/qtutilities_en_US.ts +++ b/translations/qtutilities_en_US.ts @@ -25,6 +25,29 @@ + + QtUtilities + + + unable to access file + + + + + file has invalid format + + + + + unknown error + + + + + Unable to sync settings from "%1": %2 + + + QtUtilities::AboutDialog diff --git a/translations/qtutilities_zh_CN.ts b/translations/qtutilities_zh_CN.ts index ae03713..d855eb2 100644 --- a/translations/qtutilities_zh_CN.ts +++ b/translations/qtutilities_zh_CN.ts @@ -25,6 +25,29 @@ Qt + + QtUtilities + + + unable to access file + + + + + file has invalid format + + + + + unknown error + 未知错误 + + + + Unable to sync settings from "%1": %2 + + + QtUtilities::AboutDialog