Merge pull request #391 from louib/fix/checkPermissions

Adding warning messages when config access error.
This commit is contained in:
Janek Bevendorff 2017-03-19 23:36:19 +01:00 committed by GitHub
commit 7608405a1f
4 changed files with 34 additions and 1 deletions

View File

@ -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);

View File

@ -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);

View File

@ -314,6 +314,12 @@ MainWindow::MainWindow()
connect(m_ui->tabWidget, SIGNAL(messageDismissTab()), this, SLOT(hideTabMessage()));
updateTrayIcon();
if (config()->hasAccessError()) {
m_ui->globalMessageWidget->showMessage(
tr("Access error for config file %1").arg(config()->getFileName()), MessageWidget::Error);
}
}
MainWindow::~MainWindow()

View File

@ -68,7 +68,7 @@ SettingsWidget::SettingsWidget(QWidget* parent)
#ifdef Q_OS_MAC
// systray not useful on OS X
m_generalUi->systraySettings->setVisible(false);
m_generalUi->systraySettings->setVisible(false);
#endif
connect(this, SIGNAL(accepted()), SLOT(saveSettings()));
@ -99,6 +99,12 @@ void SettingsWidget::addSettingsPage(ISettingsPage* page)
void SettingsWidget::loadSettings()
{
if (config()->hasAccessError()) {
showMessage(
tr("Access error for config file %1").arg(config()->getFileName()), MessageWidget::Error);
}
m_generalUi->rememberLastDatabasesCheckBox->setChecked(config()->get("RememberLastDatabases").toBool());
m_generalUi->rememberLastKeyFilesCheckBox->setChecked(config()->get("RememberLastKeyFiles").toBool());
m_generalUi->openPreviousDatabasesOnStartupCheckBox->setChecked(
@ -154,6 +160,15 @@ void SettingsWidget::loadSettings()
void SettingsWidget::saveSettings()
{
if (config()->hasAccessError()) {
showMessage(
tr("Access error for config file %1").arg(config()->getFileName()), MessageWidget::Error);
// We prevent closing the settings page if we could not write to
// the config file.
return;
}
config()->set("RememberLastDatabases", m_generalUi->rememberLastDatabasesCheckBox->isChecked());
config()->set("RememberLastKeyFiles", m_generalUi->rememberLastKeyFilesCheckBox->isChecked());
config()->set("OpenPreviousDatabasesOnStartup",