[PINENTRY PATCH 6/8] qt: Report timeout.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Fri Nov 4 23:57:50 CET 2016


* qt/pinentryconfirm.h (PinentryConfirm): Add _timed_out, timedOut().
* qt/pinentrydialog.h (PinentryDialog): Add _timed_out, timedOut().
* qt/pinentryconfirm.cpp (slotTimeout): Record elapsed timeout.
(PinentryConfirm): Initialize _timed_out to false.
(timedOut): New. Returns value of _timed_out.
* qt/pinentryDialog.cpp (slotTimeout): Record elapsed timeout.
(PinentryDialog): Initialize _timed_out to false.
(timedOut): New. Returns value of _timed_out.
* qt/main.cpp (qt_cmd_handler): Report if canceled due to timeout.

Signed-off-by: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
---
 qt/main.cpp            | 6 ++++++
 qt/pinentryconfirm.cpp | 7 +++++++
 qt/pinentryconfirm.h   | 2 ++
 qt/pinentrydialog.cpp  | 7 +++++++
 qt/pinentrydialog.h    | 3 +++
 5 files changed, 25 insertions(+)

diff --git a/qt/main.cpp b/qt/main.cpp
index d5da4a8..8284960 100644
--- a/qt/main.cpp
+++ b/qt/main.cpp
@@ -44,6 +44,7 @@
 
 #include <memory>
 #include <stdexcept>
+#include <gpg-error.h>
 
 #ifdef FALLBACK_CURSES
 #include <pinentry-curses.h>
@@ -205,6 +206,8 @@ qt_cmd_handler(pinentry_t pe)
         }
         bool ret = pinentry.exec();
         if (!ret) {
+            if (pinentry.timedOut())
+                pe->specific_err = gpg_error (GPG_ERR_TIMEOUT);
             return -1;
         }
 
@@ -270,6 +273,9 @@ qt_cmd_handler(pinentry_t pe)
         if (rc == QMessageBox::Cancel) {
             pe->canceled = true;
         }
+        if (box.timedOut()) {
+          pe->specific_err = gpg_error (GPG_ERR_TIMEOUT);
+        }
 
         return rc == QMessageBox::Ok || rc == QMessageBox::Yes ;
 
diff --git a/qt/pinentryconfirm.cpp b/qt/pinentryconfirm.cpp
index e81b188..8b59d9d 100644
--- a/qt/pinentryconfirm.cpp
+++ b/qt/pinentryconfirm.cpp
@@ -24,6 +24,7 @@ PinentryConfirm::PinentryConfirm(Icon icon, int timeout, const QString &title,
                                  const QString &desc, StandardButtons buttons, QWidget *parent) :
     QMessageBox(icon, title, desc, buttons, parent)
 {
+    _timed_out = false;
     if (timeout > 0) {
         _timer = new QTimer(this);
         connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
@@ -36,6 +37,11 @@ PinentryConfirm::PinentryConfirm(Icon icon, int timeout, const QString &title,
     raiseWindow(this);
 }
 
+bool PinentryConfirm::timedOut() const
+{
+    return _timed_out;
+}
+
 void PinentryConfirm::showEvent(QShowEvent *event)
 {
     QDialog::showEvent(event);
@@ -45,6 +51,7 @@ void PinentryConfirm::showEvent(QShowEvent *event)
 void PinentryConfirm::slotTimeout()
 {
     QAbstractButton *b = button(QMessageBox::Cancel);
+    _timed_out = true;
 
     if (b) {
         b->animateClick(0);
diff --git a/qt/pinentryconfirm.h b/qt/pinentryconfirm.h
index 23e05dc..21b91c5 100644
--- a/qt/pinentryconfirm.h
+++ b/qt/pinentryconfirm.h
@@ -29,12 +29,14 @@ public:
     PinentryConfirm(Icon, int timeout, const QString &title,
                     const QString &desc, StandardButtons buttons,
                     QWidget *parent);
+    bool timedOut() const;
 
 private slots:
     void slotTimeout();
 
 private:
     QTimer *_timer;
+    bool _timed_out;
 
 protected:
     /* reimp */ void showEvent(QShowEvent *event);
diff --git a/qt/pinentrydialog.cpp b/qt/pinentrydialog.cpp
index f9dd700..92cf19e 100644
--- a/qt/pinentrydialog.cpp
+++ b/qt/pinentrydialog.cpp
@@ -121,6 +121,7 @@ QPixmap icon(QStyle::StandardPixmap which)
 
 void PinEntryDialog::slotTimeout()
 {
+    _timed_out = true;
     reject();
 }
 
@@ -137,6 +138,7 @@ PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name,
       mVisiActionEdit(NULL),
       mVisiCB(NULL)
 {
+    _timed_out = false;
     setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
 
     if (modal) {
@@ -463,6 +465,11 @@ QString PinEntryDialog::repeatedPin() const
     return QString();
 }
 
+bool PinEntryDialog::timedOut() const
+{
+    return _timed_out;
+}
+
 void PinEntryDialog::setRepeatErrorText(const QString &err)
 {
     mRepeatError = err;
diff --git a/qt/pinentrydialog.h b/qt/pinentrydialog.h
index c302f95..a996f8e 100644
--- a/qt/pinentrydialog.h
+++ b/qt/pinentrydialog.h
@@ -82,6 +82,8 @@ public:
 
     void setPinentryInfo(pinentry_t);
 
+    bool timedOut() const;
+    
 protected slots:
     void updateQuality(const QString &);
     void slotTimeout();
@@ -105,6 +107,7 @@ private:
     QPushButton *_cancel;
     bool       _grabbed;
     bool       _have_quality_bar;
+    bool       _timed_out;
     pinentry_t _pinentry_info;
     QTimer    *_timer;
     QString    mRepeatError,
-- 
2.10.1




More information about the Gnupg-devel mailing list