From af3b2b943f15144b16f1d27ad33b54ea5156fb0a Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Tue, 15 Aug 2023 07:52:48 -0400 Subject: [PATCH] Fix password generator close button for good * Avoids using QDialog which breaks the standalone password generator Revert "Fix password dialog close button" This reverts commit 5b47190fcc4b2f51fb11849cef7f53346e8fe439. --- src/browser/BrowserAction.cpp | 2 ++ src/browser/BrowserService.cpp | 12 ++++-------- src/browser/BrowserService.h | 3 +-- src/gui/PasswordGeneratorWidget.cpp | 6 +++--- src/gui/PasswordGeneratorWidget.h | 9 +++++---- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/browser/BrowserAction.cpp b/src/browser/BrowserAction.cpp index 8fe2244490..b576ff1803 100644 --- a/src/browser/BrowserAction.cpp +++ b/src/browser/BrowserAction.cpp @@ -279,6 +279,8 @@ QJsonObject BrowserAction::handleGeneratePassword(QLocalSocket* socket, const QJ errorReply["requestID"] = requestId; } + // Show the existing password generator + browserService()->showPasswordGenerator({}); return errorReply; } diff --git a/src/browser/BrowserService.cpp b/src/browser/BrowserService.cpp index 0a2ec6eaf3..74c9ddcb96 100644 --- a/src/browser/BrowserService.cpp +++ b/src/browser/BrowserService.cpp @@ -74,7 +74,6 @@ BrowserService::BrowserService() , m_browserHost(new BrowserHost) , m_dialogActive(false) , m_bringToFrontRequested(false) - , m_passwordGeneratorRequested(false) , m_prevWindowState(WindowState::Normal) , m_keepassBrowserUUID(Tools::hexToUuid("de887cc3036343b8974b5911b8816224")) { @@ -512,7 +511,7 @@ QList BrowserService::confirmEntries(QList& entriesToConfirm, void BrowserService::showPasswordGenerator(const KeyPairMessage& keyPairMessage) { if (!m_passwordGenerator) { - m_passwordGenerator.reset(PasswordGeneratorWidget::popupGenerator(m_currentDatabaseWidget)); + m_passwordGenerator = PasswordGeneratorWidget::popupGenerator(); connect(m_passwordGenerator.data(), &PasswordGeneratorWidget::closed, m_passwordGenerator.data(), [=] { if (!m_passwordGenerator->isPasswordGenerated()) { @@ -521,9 +520,7 @@ void BrowserService::showPasswordGenerator(const KeyPairMessage& keyPairMessage) m_browserHost->sendClientMessage(keyPairMessage.socket, errorMessage); } - m_passwordGenerator.reset(); - hideWindow(); - m_passwordGeneratorRequested = false; + QTimer::singleShot(50, this, [&] { hideWindow(); }); }); connect(m_passwordGenerator.data(), @@ -537,19 +534,18 @@ void BrowserService::showPasswordGenerator(const KeyPairMessage& keyPairMessage) params, keyPairMessage.publicKey, keyPairMessage.secretKey)); - hideWindow(); }); } - m_passwordGeneratorRequested = true; raiseWindow(); + m_passwordGenerator->show(); m_passwordGenerator->raise(); m_passwordGenerator->activateWindow(); } bool BrowserService::isPasswordGeneratorRequested() const { - return m_passwordGeneratorRequested; + return m_passwordGenerator && m_passwordGenerator->isVisible(); } QString BrowserService::storeKey(const QString& key) diff --git a/src/browser/BrowserService.h b/src/browser/BrowserService.h index 01daaee852..eb91fd1ec3 100644 --- a/src/browser/BrowserService.h +++ b/src/browser/BrowserService.h @@ -205,12 +205,11 @@ private slots: bool m_dialogActive; bool m_bringToFrontRequested; - bool m_passwordGeneratorRequested; WindowState m_prevWindowState; QUuid m_keepassBrowserUUID; QPointer m_currentDatabaseWidget; - QScopedPointer m_passwordGenerator; + QPointer m_passwordGenerator; Q_DISABLE_COPY(BrowserService); diff --git a/src/gui/PasswordGeneratorWidget.cpp b/src/gui/PasswordGeneratorWidget.cpp index 5ccd966132..084efa60f1 100644 --- a/src/gui/PasswordGeneratorWidget.cpp +++ b/src/gui/PasswordGeneratorWidget.cpp @@ -1,6 +1,6 @@ /* - * Copyright (C) 2023 KeePassXC Team * Copyright (C) 2013 Felix Geyer + * Copyright (C) 2022 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ #include "gui/styles/StateColorPalette.h" PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent) - : QDialog(parent) + : QWidget(parent) , m_passwordGenerator(new PasswordGenerator()) , m_dicewareGenerator(new PassphraseGenerator()) , m_ui(new Ui::PasswordGeneratorWidget()) @@ -121,7 +121,7 @@ void PasswordGeneratorWidget::closeEvent(QCloseEvent* event) { // Emits closed signal when clicking X from title bar emit closed(); - event->accept(); + QWidget::closeEvent(event); } PasswordGeneratorWidget* PasswordGeneratorWidget::popupGenerator(QWidget* parent) diff --git a/src/gui/PasswordGeneratorWidget.h b/src/gui/PasswordGeneratorWidget.h index 9413ebea60..2257cbf084 100644 --- a/src/gui/PasswordGeneratorWidget.h +++ b/src/gui/PasswordGeneratorWidget.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2023 KeePassXC Team * Copyright (C) 2013 Felix Geyer + * Copyright (C) 2022 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,7 +20,6 @@ #define KEEPASSX_PASSWORDGENERATORWIDGET_H #include -#include #include #include "core/PassphraseGenerator.h" @@ -35,7 +34,7 @@ class PasswordGenerator; class PasswordHealth; class PassphraseGenerator; -class PasswordGeneratorWidget : public QDialog +class PasswordGeneratorWidget : public QWidget { Q_OBJECT @@ -71,6 +70,9 @@ public slots: void deleteWordList(); void addWordList(); +protected: + void closeEvent(QCloseEvent* event) override; + private slots: void updateButtonsEnabled(const QString& password); void updatePasswordStrength(); @@ -87,7 +89,6 @@ private slots: bool m_passwordGenerated = false; int m_firstCustomWordlistIndex; - void closeEvent(QCloseEvent* event) override; PasswordGenerator::CharClasses charClasses(); PasswordGenerator::GeneratorFlags generatorFlags();