Fix impossible dialog by providing a proper question with approriate answers, resolves #202

This commit is contained in:
Janek Bevendorff 2017-02-25 03:40:49 +01:00 committed by Jonathan White
parent 311e7802e5
commit 4ec2fe556a

View File

@ -21,6 +21,7 @@
#include <QLockFile> #include <QLockFile>
#include <QSaveFile> #include <QSaveFile>
#include <QTabWidget> #include <QTabWidget>
#include <QPushButton>
#include "autotype/AutoType.h" #include "autotype/AutoType.h"
#include "core/Config.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 // for now silently ignore if we can't create a lock file
// due to lack of permissions // due to lack of permissions
if (lockFile->error() != QLockFile::PermissionError) { if (lockFile->error() != QLockFile::PermissionError) {
QMessageBox::StandardButton result = MessageBox::question(this, tr("Open database"), QMessageBox msgBox;
tr("The database you are trying to open is locked by another instance of KeePassXC.\n" msgBox.setWindowTitle(tr("Database already opened"));
"Do you want to open it anyway? Alternatively the database is opened read-only."), msgBox.setText(tr("The database you are trying to open is locked by another instance of KeePassXC.\n\n"
QMessageBox::Yes | QMessageBox::No); "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; dbStruct.readOnly = true;
delete lockFile; delete lockFile;
lockFile = nullptr; lockFile = nullptr;
} } else if (result == QMessageBox::Yes) {
else {
// take over the lock file if possible // take over the lock file if possible
if (lockFile->removeStaleLockFile()) { if (lockFile->removeStaleLockFile()) {
lockFile->tryLock(); lockFile->tryLock();
} }
} else {
return;
} }
} }
} }