diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index 3a48098dd..5414d6447 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" @@ -158,21 +159,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; } } } diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index dffbe69d0..aa66c4615 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -287,7 +287,7 @@ void DatabaseWidget::createEntry() void DatabaseWidget::setIconFromParent() { - if (!config()->get("UseGroupIconOnEntryCreation", true).toBool()) { + if (!config()->get("UseGroupIconOnEntryCreation").toBool()) { return; } @@ -1068,8 +1068,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; @@ -1093,16 +1092,10 @@ void DatabaseWidget::reloadDatabaseFile() restoreGroupEntryFocus(groupBeforeReload, entryBeforeReload); } - else { - m_messageWidget->showMessage( - tr("Could not parse or unlock the new database file while attempting" - " to autoreload this database."), MessageWidget::Error); - } - } - else { + } else { m_messageWidget->showMessage( tr("Could not open the new database file while attempting to autoreload this database."), - MessageWidget::Error); + MessageWidget::Error); } // Rewatch the database file