From 15a288aa5bb5477ab01304a8660daff9862b4df5 Mon Sep 17 00:00:00 2001 From: Louis-Bertrand Varin Date: Mon, 6 Mar 2017 17:12:07 -0500 Subject: [PATCH] Adding warning messages when config access error. --- src/core/Config.cpp | 14 ++++++++++++++ src/core/Config.h | 2 ++ src/gui/SettingsWidget.cpp | 5 +++++ src/gui/SettingsWidgetGeneral.ui | 9 +++++++++ 4 files changed, 30 insertions(+) diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 28b17536f..e3a1cb633 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -35,6 +35,16 @@ QVariant Config::get(const QString& key, const QVariant& defaultValue) return m_settings->value(key, defaultValue); } +bool Config::hasAccessError() +{ + return m_settings->status() & QSettings::AccessError; +} + +QString Config::getFileName() +{ + return m_settings->fileName(); +} + void Config::set(const QString& key, const QVariant& value) { m_settings->setValue(key, value); @@ -92,6 +102,10 @@ void Config::init(const QString& fileName) { m_settings.reset(new QSettings(fileName, QSettings::IniFormat)); + if (hasAccessError()) { + qWarning("Access error with config file %s", qPrintable(fileName)); + } + m_defaults.insert("RememberLastDatabases", true); m_defaults.insert("RememberLastKeyFiles", true); m_defaults.insert("OpenPreviousDatabasesOnStartup", true); diff --git a/src/core/Config.h b/src/core/Config.h index 09aa02fb1..1fb937cf9 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -31,7 +31,9 @@ public: ~Config(); QVariant get(const QString& key); QVariant get(const QString& key, const QVariant& defaultValue); + QString getFileName(); void set(const QString& key, const QVariant& value); + bool hasAccessError(); static Config* instance(); static void createConfigFromFile(const QString& file); diff --git a/src/gui/SettingsWidget.cpp b/src/gui/SettingsWidget.cpp index 62af276e8..2002bc733 100644 --- a/src/gui/SettingsWidget.cpp +++ b/src/gui/SettingsWidget.cpp @@ -62,6 +62,11 @@ SettingsWidget::SettingsWidget(QWidget* parent) addPage(tr("General"), FilePath::instance()->icon("categories", "preferences-other"), m_generalWidget); addPage(tr("Security"), FilePath::instance()->icon("status", "security-high"), m_secWidget); + if (config()->hasAccessError()) { + m_generalUi->messageWidget->showMessage( + tr("Access error with config file ") + config()->getFileName(), MessageWidget::Error); + } + if (!autoType()->isAvailable()) { m_generalUi->generalSettingsTabWidget->removeTab(1); } diff --git a/src/gui/SettingsWidgetGeneral.ui b/src/gui/SettingsWidgetGeneral.ui index 88d7cad45..fb9fb1709 100644 --- a/src/gui/SettingsWidgetGeneral.ui +++ b/src/gui/SettingsWidgetGeneral.ui @@ -23,6 +23,9 @@ 0 + + + @@ -368,6 +371,12 @@ QLineEdit
autotype/ShortcutWidget.h
+ + MessageWidget + QWidget +
gui/MessageWidget.h
+ 1 +