diff options
author | saturneric <[email protected]> | 2023-12-02 14:01:16 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2023-12-02 14:01:16 +0000 |
commit | 0ec3358e4cfce7ad242e851c450292a25619221e (patch) | |
tree | 28a50308678ccbe0e0820d367f363df7df4e0be2 /src/ui/main_window/MainWindowSlotUI.cpp | |
parent | fix: add set owner struct action in keymanager menu (diff) | |
download | GpgFrontend-0ec3358e4cfce7ad242e851c450292a25619221e.tar.gz GpgFrontend-0ec3358e4cfce7ad242e851c450292a25619221e.zip |
feat: add buddled qt pinentry and make it works
Diffstat (limited to 'src/ui/main_window/MainWindowSlotUI.cpp')
-rw-r--r-- | src/ui/main_window/MainWindowSlotUI.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp index 6c9705ac..d640d337 100644 --- a/src/ui/main_window/MainWindowSlotUI.cpp +++ b/src/ui/main_window/MainWindowSlotUI.cpp @@ -26,9 +26,15 @@ * */ +#include <qnamespace.h> + #include "MainWindow.h" +#include "UISignalStation.h" #include "core/GpgConstants.h" +#include "core/function/CoreSignalStation.h" #include "core/function/GlobalSettingStation.h" +#include "pinentry/pinentrydialog.h" +#include "spdlog/spdlog.h" #include "ui/UserInterfaceUtils.h" #include "ui/dialog/Wizard.h" #include "ui/main_window/KeyMgmt.h" @@ -223,4 +229,52 @@ void MainWindow::SetCryptoMenuStatus( } } +void MainWindow::SlotRaisePinentry() { + auto* pinentry = + new PinEntryDialog(this, 0, 0, true, false, QString(), + QString::fromStdString(_("Show passphrase")), + QString::fromStdString(_("Hide passphrase"))); + + SPDLOG_DEBUG("setting pinetry's arguments"); + + pinentry->setPinentryInfo(new struct pinentry()); + pinentry->setPrompt(QString::fromStdString(_("PIN:"))); + pinentry->setDescription(QString()); + pinentry->setRepeatErrorText( + QString::fromStdString(_("Passphrases do not match"))); + pinentry->setGenpinLabel(QString()); + pinentry->setGenpinTT(QString()); + pinentry->setCapsLockHint(QString::fromStdString(_("Caps Lock is on"))); + pinentry->setFormattedPassphrase({false, QString()}); + pinentry->setConstraintsOptions({false, QString(), QString(), QString()}); + + pinentry->setWindowTitle(_("Pinentry")); + + /* If we reuse the same dialog window. */ + pinentry->setPin(QString()); + + pinentry->setOkText(_("Confirm")); + pinentry->setCancelText(_("Cancel")); + + SPDLOG_DEBUG("pinentry is ready to start"); + + connect(pinentry, &PinEntryDialog::finished, this, [pinentry](int result) { + bool ret = result != 0; + SPDLOG_DEBUG("PinEntryDialog finished, ret: {}", ret); + + if (!ret) { + emit CoreSignalStation::GetInstance()->SignalUserInputPassphraseCallback( + {}); + return -1; + } + + auto pin = pinentry->pin().toUtf8(); + emit CoreSignalStation::GetInstance()->SignalUserInputPassphraseCallback( + pin); + return 0; + }); + + pinentry->open(); +} + } // namespace GpgFrontend::UI |