From 48ac3790c25cf0a4d3b069801c42e870e7ab3b38 Mon Sep 17 00:00:00 2001 From: Janek Bevendorff Date: Mon, 15 Jan 2018 00:09:15 +0100 Subject: [PATCH] Show "key already exists" warning only if key really exists --- src/browser/BrowserService.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/browser/BrowserService.cpp b/src/browser/BrowserService.cpp index 97b8fea42..b6af4e391 100644 --- a/src/browser/BrowserService.cpp +++ b/src/browser/BrowserService.cpp @@ -174,15 +174,15 @@ QString BrowserService::storeKey(const QString& key) Entry* config = getConfigEntry(true); if (!config) { - return QString(); + return {}; } - bool contains = false; + bool contains; QMessageBox::StandardButton dialogResult = QMessageBox::No; do { bool ok = false; - id = QInputDialog::getText(0, tr("KeePassXC: New key association request"), + id = QInputDialog::getText(nullptr, tr("KeePassXC: New key association request"), tr("You have received an association " "request for the above key.\n" "If you would like to allow it access " @@ -190,13 +190,17 @@ QString BrowserService::storeKey(const QString& key) "give it a unique name to identify and accept it."), QLineEdit::Normal, QString(), &ok); if (!ok || id.isEmpty()) { - return QString(); + return {}; } contains = config->attributes()->contains(QLatin1String(ASSOCIATE_KEY_PREFIX) + id); - dialogResult = QMessageBox::warning(0, tr("KeePassXC: Overwrite existing key?"), - tr("A shared encryption key with the name \"%1\" already exists.\nDo you want to overwrite it?").arg(id), - QMessageBox::Yes | QMessageBox::No); + if (contains) { + dialogResult = QMessageBox::warning(nullptr, tr("KeePassXC: Overwrite existing key?"), + tr("A shared encryption key with the name \"%1\" " + "already exists.\nDo you want to overwrite it?") + .arg(id), + QMessageBox::Yes | QMessageBox::No); + } } while (contains && dialogResult == QMessageBox::No); config->attributes()->set(QLatin1String(ASSOCIATE_KEY_PREFIX) + id, key, true);