Adding warning messages when config access error.

This commit is contained in:
Louis-Bertrand Varin 2017-03-06 17:12:07 -05:00 committed by Louis-Bertrand Varin
parent c4d6fa855c
commit 15a288aa5b
4 changed files with 30 additions and 0 deletions

View File

@ -35,6 +35,16 @@ QVariant Config::get(const QString& key, const QVariant& defaultValue)
return m_settings->value(key, 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) void Config::set(const QString& key, const QVariant& value)
{ {
m_settings->setValue(key, value); m_settings->setValue(key, value);
@ -92,6 +102,10 @@ void Config::init(const QString& fileName)
{ {
m_settings.reset(new QSettings(fileName, QSettings::IniFormat)); 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("RememberLastDatabases", true);
m_defaults.insert("RememberLastKeyFiles", true); m_defaults.insert("RememberLastKeyFiles", true);
m_defaults.insert("OpenPreviousDatabasesOnStartup", true); m_defaults.insert("OpenPreviousDatabasesOnStartup", true);

View File

@ -31,7 +31,9 @@ public:
~Config(); ~Config();
QVariant get(const QString& key); QVariant get(const QString& key);
QVariant get(const QString& key, const QVariant& defaultValue); QVariant get(const QString& key, const QVariant& defaultValue);
QString getFileName();
void set(const QString& key, const QVariant& value); void set(const QString& key, const QVariant& value);
bool hasAccessError();
static Config* instance(); static Config* instance();
static void createConfigFromFile(const QString& file); static void createConfigFromFile(const QString& file);

View File

@ -62,6 +62,11 @@ SettingsWidget::SettingsWidget(QWidget* parent)
addPage(tr("General"), FilePath::instance()->icon("categories", "preferences-other"), m_generalWidget); addPage(tr("General"), FilePath::instance()->icon("categories", "preferences-other"), m_generalWidget);
addPage(tr("Security"), FilePath::instance()->icon("status", "security-high"), m_secWidget); 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()) { if (!autoType()->isAvailable()) {
m_generalUi->generalSettingsTabWidget->removeTab(1); m_generalUi->generalSettingsTabWidget->removeTab(1);
} }

View File

@ -23,6 +23,9 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item>
<widget class="MessageWidget" name="messageWidget" native="true"/>
</item>
<item> <item>
<widget class="QTabWidget" name="generalSettingsTabWidget"> <widget class="QTabWidget" name="generalSettingsTabWidget">
<property name="currentIndex"> <property name="currentIndex">
@ -368,6 +371,12 @@
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
<header>autotype/ShortcutWidget.h</header> <header>autotype/ShortcutWidget.h</header>
</customwidget> </customwidget>
<customwidget>
<class>MessageWidget</class>
<extends>QWidget</extends>
<header>gui/MessageWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>