From 311e7802e522a2b44517758c948d80258a6006b3 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Sat, 25 Feb 2017 02:34:47 +0100 Subject: [PATCH 1/2] Don't show error message when trying to reload a locked database --- src/gui/DatabaseWidget.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 1ccf35dd4..8a7b2cf3b 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -1061,8 +1061,7 @@ void DatabaseWidget::reloadDatabaseFile() // Merge the old database into the new one m_db->setEmitModified(false); db->merge(m_db); - } - else { + } else { // Since we are accepting the new file as-is, internally mark as unmodified // TODO: when saving is moved out of DatabaseTabWidget, this should be replaced m_databaseModified = false; @@ -1086,16 +1085,9 @@ void DatabaseWidget::reloadDatabaseFile() restoreGroupEntryFocus(groupBeforeReload, entryBeforeReload); } - else { - MessageBox::critical(this, tr("Autoreload Failed"), - tr("Could not parse or unlock the new database file while attempting" - " to autoreload this database.")); - } - } - else { + } else { MessageBox::critical(this, tr("Autoreload Failed"), - tr("Could not open the new database file while attempting to autoreload" - " this database.")); + tr("Could not open the new database file while attempting to autoreload this database.")); } // Rewatch the database file From 4ec2fe556aad61dc5691f760d9ff9733baaa001b Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Sat, 25 Feb 2017 03:40:49 +0100 Subject: [PATCH 2/2] Fix impossible dialog by providing a proper question with approriate answers, resolves #202 --- src/gui/DatabaseTabWidget.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index c425332f7..8042c1130 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "autotype/AutoType.h" #include "core/Config.h" @@ -157,21 +158,29 @@ void DatabaseTabWidget::openDatabase(const QString& fileName, const QString& pw, // for now silently ignore if we can't create a lock file // due to lack of permissions if (lockFile->error() != QLockFile::PermissionError) { - QMessageBox::StandardButton result = MessageBox::question(this, tr("Open database"), - tr("The database you are trying to open is locked by another instance of KeePassXC.\n" - "Do you want to open it anyway? Alternatively the database is opened read-only."), - QMessageBox::Yes | QMessageBox::No); + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Database already opened")); + msgBox.setText(tr("The database you are trying to open is locked by another instance of KeePassXC.\n\n" + "Do you want to open it anyway?")); + msgBox.setIcon(QMessageBox::Question); + msgBox.addButton(QMessageBox::Yes); + msgBox.addButton(QMessageBox::No); + auto readOnlyButton = msgBox.addButton(tr("Open read-only"), QMessageBox::AcceptRole); + msgBox.setDefaultButton(readOnlyButton); + msgBox.setEscapeButton(QMessageBox::No); + auto result = msgBox.exec(); - if (result == QMessageBox::No) { + if (msgBox.clickedButton() == readOnlyButton) { dbStruct.readOnly = true; delete lockFile; lockFile = nullptr; - } - else { + } else if (result == QMessageBox::Yes) { // take over the lock file if possible if (lockFile->removeStaleLockFile()) { lockFile->tryLock(); } + } else { + return; } } }