[PATCH pinentry 3/4] qt: Disable echoing if backspace is pressed first.
Damien Goutte-Gattat
dgouttegattat at incenp.org
Sat Aug 4 23:24:10 CEST 2018
* qt/pinlineedit.h: New file.
* qt/pinlineedit.cpp: New file.
* qt/Makefile.am: Add new source files.
* qt/pinentrydialog.cpp (PinEntryDialog): New member _got_input;
Type of _edit member changed to PinLineEdit.
(PinEntryDialog::onBackspace): New slot.
GnuPG-bug-id: 3428
Signed-off-by: Damien Goutte-Gattat <dgouttegattat at incenp.org>
---
qt/Makefile.am | 9 +++++----
qt/pinentrydialog.cpp | 18 +++++++++++++++++-
qt/pinentrydialog.h | 7 +++++--
qt/pinlineedit.cpp | 36 ++++++++++++++++++++++++++++++++++++
qt/pinlineedit.h | 38 ++++++++++++++++++++++++++++++++++++++
5 files changed, 101 insertions(+), 7 deletions(-)
create mode 100644 qt/pinlineedit.cpp
create mode 100644 qt/pinlineedit.h
diff --git a/qt/Makefile.am b/qt/Makefile.am
index 698005e..840d0c0 100644
--- a/qt/Makefile.am
+++ b/qt/Makefile.am
@@ -43,16 +43,17 @@ pinentry_qt_LDADD = \
$(COMMON_LIBS) $(PINENTRY_QT_LIBS) $(libcurses) $(LIBCAP)
BUILT_SOURCES = \
- pinentryconfirm.moc pinentrydialog.moc
+ pinentryconfirm.moc pinentrydialog.moc pinlineedit.moc
CLEANFILES = \
- pinentryconfirm.moc pinentrydialog.moc
+ pinentryconfirm.moc pinentrydialog.moc pinlineedit.moc
pinentry_qt_SOURCES = pinentrydialog.h pinentrydialog.cpp \
- main.cpp qrc_pinentry.cpp pinentryconfirm.cpp pinentryconfirm.h
+ main.cpp qrc_pinentry.cpp pinentryconfirm.cpp pinentryconfirm.h \
+ pinlineedit.h pinlineedit.cpp
nodist_pinentry_qt_SOURCES = \
- pinentryconfirm.moc pinentrydialog.moc
+ pinentryconfirm.moc pinentrydialog.moc pinlineedit.moc
.h.moc:
$(MOC) `test -f '$<' || echo '$(srcdir)/'`$< -o $@
diff --git a/qt/pinentrydialog.cpp b/qt/pinentrydialog.cpp
index d42ae4a..b7f2e53 100644
--- a/qt/pinentrydialog.cpp
+++ b/qt/pinentrydialog.cpp
@@ -36,6 +36,7 @@
#include <QLineEdit>
#include <QAction>
#include <QCheckBox>
+#include "pinlineedit.h"
#ifdef Q_OS_WIN
#include <windows.h>
@@ -137,6 +138,7 @@ PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name,
: QDialog(parent),
mRepeat(NULL),
_grabbed(false),
+ _got_input(false),
mVisibilityTT(visibilityTT),
mHideTT(hideTT),
mVisiActionEdit(NULL),
@@ -163,7 +165,7 @@ PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name,
_prompt = new QLabel(this);
_prompt->hide();
- _edit = new QLineEdit(this);
+ _edit = new PinLineEdit(this);
_edit->setMaxLength(256);
_edit->setEchoMode(QLineEdit::Password);
@@ -205,6 +207,8 @@ PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name,
this, SLOT(updateQuality(QString)));
connect(_edit, SIGNAL(textChanged(QString)),
this, SLOT(textChanged(QString)));
+ connect(_edit, SIGNAL(backspacePressed()),
+ this, SLOT(onBackspace()));
QTimer::singleShot(0, _edit, SLOT(setFocus()));
@@ -356,6 +360,16 @@ void PinEntryDialog::setQualityBarTT(const QString &txt)
}
}
+void PinEntryDialog::onBackspace()
+{
+ if (!_got_input) {
+ _edit->setEchoMode(QLineEdit::NoEcho);
+ if (mRepeat) {
+ mRepeat->setEchoMode(QLineEdit::NoEcho);
+ }
+ }
+}
+
void PinEntryDialog::updateQuality(const QString &txt)
{
int length;
@@ -366,6 +380,8 @@ void PinEntryDialog::updateQuality(const QString &txt)
_timer->stop();
}
+ _got_input = true;
+
if (!_have_quality_bar || !_pinentry_info) {
return;
}
diff --git a/qt/pinentrydialog.h b/qt/pinentrydialog.h
index 52b7343..396f03b 100644
--- a/qt/pinentrydialog.h
+++ b/qt/pinentrydialog.h
@@ -33,6 +33,7 @@
class QLabel;
class QPushButton;
class QLineEdit;
+class PinLineEdit;
class QString;
class QProgressBar;
class QCheckBox;
@@ -89,6 +90,7 @@ protected slots:
void textChanged(const QString &);
void focusChanged(QWidget *old, QWidget *now);
void toggleVisibility();
+ void onBackspace();
protected:
/* reimp */ void showEvent(QShowEvent *event);
@@ -100,13 +102,14 @@ private:
QLabel *_prompt;
QLabel *_quality_bar_label;
QProgressBar *_quality_bar;
- QLineEdit *_edit;
- QLineEdit *mRepeat;
+ PinLineEdit *_edit;
+ QLineEdit *mRepeat;
QPushButton *_ok;
QPushButton *_cancel;
bool _grabbed;
bool _have_quality_bar;
bool _timed_out;
+ bool _got_input;
pinentry_t _pinentry_info;
QTimer *_timer;
QString mRepeatError,
diff --git a/qt/pinlineedit.cpp b/qt/pinlineedit.cpp
new file mode 100644
index 0000000..6e62f50
--- /dev/null
+++ b/qt/pinlineedit.cpp
@@ -0,0 +1,36 @@
+/* pinlineedit.cpp - Modified QLineEdit widget.
+ * Copyright (C) 2018 Damien Goutte-Gattat
+ *
+ * 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 the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "pinlineedit.h"
+
+#include <QKeyEvent>
+
+PinLineEdit::PinLineEdit(QWidget *parent) : QLineEdit(parent)
+{
+}
+
+void
+PinLineEdit::keyPressEvent(QKeyEvent *e)
+{
+ QLineEdit::keyPressEvent(e);
+
+ if ( e->key() == Qt::Key::Key_Backspace )
+ emit backspacePressed();
+}
+
+#include "pinlineedit.moc"
diff --git a/qt/pinlineedit.h b/qt/pinlineedit.h
new file mode 100644
index 0000000..ffc1ef1
--- /dev/null
+++ b/qt/pinlineedit.h
@@ -0,0 +1,38 @@
+/* pinlineedit.h - Modified QLineEdit widget.
+ * Copyright (C) 2018 Damien Goutte-Gattat
+ *
+ * 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 the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses/>.
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _PINLINEEDIT_H_
+#define _PINLINEEDIT_H_
+
+#include <QLineEdit>
+
+class PinLineEdit : public QLineEdit
+{
+ Q_OBJECT
+
+public:
+ PinLineEdit(QWidget *);
+
+signals:
+ void backspacePressed();
+
+protected:
+ void keyPressEvent(QKeyEvent *);
+};
+
+#endif // _PINLINEEDIT_H_
--
2.14.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.gnupg.org/pipermail/gnupg-devel/attachments/20180804/728d61df/attachment.sig>
More information about the Gnupg-devel
mailing list