Skip to content

Commit

Permalink
Fix password generator close button for good
Browse files Browse the repository at this point in the history
* Avoids using QDialog which breaks the standalone password generator

Revert "Fix password dialog close button"

This reverts commit 5b47190.
  • Loading branch information
droidmonkey committed Nov 23, 2023
1 parent 6e8fa34 commit 013db19
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/browser/BrowserAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ QJsonObject BrowserAction::handleGeneratePassword(QLocalSocket* socket, const QJ
errorReply["requestID"] = requestId;
}

// Show the existing password generator
browserService()->showPasswordGenerator({});
return errorReply;
}

Expand Down
12 changes: 4 additions & 8 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand Down Expand Up @@ -512,7 +511,7 @@ QList<Entry*> BrowserService::confirmEntries(QList<Entry*>& 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()) {
Expand All @@ -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(),
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,11 @@ private slots:

bool m_dialogActive;
bool m_bringToFrontRequested;
bool m_passwordGeneratorRequested;
WindowState m_prevWindowState;
QUuid m_keepassBrowserUUID;

QPointer<DatabaseWidget> m_currentDatabaseWidget;
QScopedPointer<PasswordGeneratorWidget> m_passwordGenerator;
QPointer<PasswordGeneratorWidget> m_passwordGenerator;

Q_DISABLE_COPY(BrowserService);

Expand Down
7 changes: 3 additions & 4 deletions src/gui/PasswordGeneratorWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <[email protected]>
* Copyright (C) 2013 Felix Geyer <[email protected]>
* Copyright (C) 2022 KeePassXC Team <[email protected]>
*
* 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
Expand Down Expand Up @@ -34,13 +34,12 @@
#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())
{
m_ui->setupUi(this);
setWindowFlags(Qt::Widget);

m_ui->buttonGenerate->setIcon(icons()->icon("refresh"));
m_ui->buttonGenerate->setToolTip(
Expand Down Expand Up @@ -122,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)
Expand Down
9 changes: 5 additions & 4 deletions src/gui/PasswordGeneratorWidget.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2023 KeePassXC Team <[email protected]>
* Copyright (C) 2013 Felix Geyer <[email protected]>
* Copyright (C) 2022 KeePassXC Team <[email protected]>
*
* 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
Expand All @@ -20,7 +20,6 @@
#define KEEPASSX_PASSWORDGENERATORWIDGET_H

#include <QComboBox>
#include <QDialog>
#include <QTimer>

#include "core/PassphraseGenerator.h"
Expand All @@ -35,7 +34,7 @@ class PasswordGenerator;
class PasswordHealth;
class PassphraseGenerator;

class PasswordGeneratorWidget : public QDialog
class PasswordGeneratorWidget : public QWidget
{
Q_OBJECT

Expand Down Expand Up @@ -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();
Expand All @@ -87,7 +89,6 @@ private slots:
bool m_passwordGenerated = false;
int m_firstCustomWordlistIndex;

void closeEvent(QCloseEvent* event) override;
PasswordGenerator::CharClasses charClasses();
PasswordGenerator::GeneratorFlags generatorFlags();

Expand Down

0 comments on commit 013db19

Please sign in to comment.