[git] Pinentry - branch, master, updated. pinentry-0.9.7-7-g04115b3

by Andre Heinecke cvs at cvs.gnupg.org
Thu Apr 14 12:12:11 CEST 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The standard pinentry collection".

The branch, master has been updated
       via  04115b3289dcc9b02044f88c08580618c055a571 (commit)
       via  c6b43bd147186deee84dcccbc14f5763db67a0f3 (commit)
       via  8d801fe2c74041f2f8c563785ed7cba73f47500e (commit)
      from  30aa1046afe9a745c918fc1311c1f598c91bf913 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 04115b3289dcc9b02044f88c08580618c055a571
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Apr 14 12:00:51 2016 +0200

    Qt: Implement repeat and improve grabbing
    
    The keyboard is now only grabbed if an edit has input focus.
    
    * qt/main.cpp (qt_cmd_handler): Parse repeat values. Set repeat_okay.
    * qt/pinentrydialog.cpp (PinentryDialog::PinentryDialog): Update
     layout. Add repeat label and edit. Connect focusChanged.
     (PinEntryDialog::hideEvent): Remove grabbing hack.
     (PinEntryDialog::focusChanged): New. Properly handle grabbing.
     (PinEntryDialog::checkRepeat): New. Enable Ok if repeat matches.
     (PinEntryDialog::repeatedPin): New. Getter for repeated pin.
     (PinEntryDialog::setRepeatErrorText): Setter for error.
    * qt/pinentrydialog.h: Update accordingly.
    
    --
    Adding repeat mode made it neccessary to fix the grabbing
    which globally grabbed the keyboard for the line edit
    as long as the window was shown.
    
    Now we only grab when a line edit has focus. This has the
    advantage that you can still work with other windows while
    pinentry is open but not focused.
    
    The new grabbing should improve security a bit as it reduces
    the need for a global no-grab setting. I've verified with xev
    that keyboard grabbing still works when one of the lineedits
    in pinentry has focus.

diff --git a/qt/main.cpp b/qt/main.cpp
index 9065588..3c653ee 100644
--- a/qt/main.cpp
+++ b/qt/main.cpp
@@ -163,13 +163,21 @@ qt_cmd_handler(pinentry_t pe)
     const QString title =
         pe->title ? from_utf8(pe->title) :
         /* else */  QLatin1String("pinentry-qt") ;
+    const QString repeatError =
+        pe->repeat_error_string ? from_utf8(pe->repeat_error_string) :
+                                  QLatin1String("Passphrases do not match");
+    const QString repeatString =
+        pe->repeat_passphrase ? from_utf8(pe->repeat_passphrase) :
+                                QString();
 
     if (want_pass) {
-        PinEntryDialog pinentry(parent, 0, pe->timeout, true, !!pe->quality_bar);
+        PinEntryDialog pinentry(parent, 0, pe->timeout, true, !!pe->quality_bar,
+                                repeatString);
 
         pinentry.setPinentryInfo(pe);
         pinentry.setPrompt(escape_accel(from_utf8(pe->prompt)));
         pinentry.setDescription(from_utf8(pe->description));
+        pinentry.setRepeatErrorText(repeatError);
         if (pe->title) {
             pinentry.setWindowTitle(from_utf8(pe->title));
         }
@@ -194,7 +202,15 @@ qt_cmd_handler(pinentry_t pe)
             return -1;
         }
 
-        QByteArray pin = pinentry.pin().toUtf8();
+        const QString pinStr = pinentry.pin();
+        QByteArray pin = pinStr.toUtf8();
+
+        if (!!pe->repeat_passphrase) {
+            /* Should not have been possible to accept
+               the dialog in that case but we do a safety
+               check here */
+            pe->repeat_okay = (pinStr == pinentry.repeatedPin());
+        }
 
         int len = strlen(pin.constData());
         if (len >= 0) {
diff --git a/qt/pinentrydialog.cpp b/qt/pinentrydialog.cpp
index 91d5adb..aca3a52 100644
--- a/qt/pinentrydialog.cpp
+++ b/qt/pinentrydialog.cpp
@@ -2,8 +2,10 @@
 
    Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
    Copyright 2007 Ingo Klöcker
+   Copyright 2016 Intevation GmbH
 
    Written by Steffen Hansen <steffen at klaralvdalens-datakonsult.se>.
+   Modified by Andre Heinecke <aheinecke at intevation.de>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -109,8 +111,9 @@ void PinEntryDialog::slotTimeout()
 }
 
 PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name,
-                               int timeout, bool modal, bool enable_quality_bar)
-    : QDialog(parent, Qt::WindowStaysOnTopHint), _grabbed(false)
+                               int timeout, bool modal, bool enable_quality_bar,
+                               const QString &repeatString)
+    : QDialog(parent, Qt::WindowStaysOnTopHint), mRepeat(NULL), _grabbed(false)
 {
     setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
 
@@ -179,28 +182,40 @@ PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name,
     _edit->setFocus();
 
     QGridLayout *const grid = new QGridLayout(this);
-    grid->addWidget(_icon, 0, 0, 5, 1, Qt::AlignTop | Qt::AlignLeft);
-    grid->addWidget(_error, 1, 1, 1, 2);
-    grid->addWidget(_desc,  2, 1, 1, 2);
+    int row = 1;
+    grid->addWidget(_error, row++, 1, 1, 2);
+    grid->addWidget(_desc,  row++, 1, 1, 2);
     //grid->addItem( new QSpacerItem( 0, _edit->height() / 10, QSizePolicy::Minimum, QSizePolicy::Fixed ), 1, 1 );
-    grid->addWidget(_prompt, 3, 1);
-    grid->addWidget(_edit, 3, 2);
     if (enable_quality_bar) {
-        grid->addWidget(_quality_bar_label, 4, 1);
-        grid->addWidget(_quality_bar, 4, 2);
+        grid->addWidget(_quality_bar_label, row, 1);
+        grid->addWidget(_quality_bar, row++, 2);
     }
-    grid->addWidget(buttons, 5, 0, 1, 3);
+    grid->addWidget(_prompt, row, 1);
+    grid->addWidget(_edit, row++, 2);
+    if (!repeatString.isNull()) {
+        mRepeat = new QLineEdit;
+        mRepeat->setMaxLength(256);
+        mRepeat->setEchoMode(QLineEdit::Password);
+        connect(mRepeat, SIGNAL(textChanged(QString)),
+                this, SLOT(checkRepeat(QString)));
+        connect(_edit, SIGNAL(textChanged(QString)),
+                this, SLOT(checkRepeat(QString)));
+        QLabel *repeatLabel = new QLabel(repeatString);
+        repeatLabel->setBuddy(mRepeat);
+        grid->addWidget(repeatLabel, row, 1);
+        grid->addWidget(mRepeat, row++, 2);
+        setTabOrder(_edit, mRepeat);
+        setTabOrder(mRepeat, _ok);
+    }
+    row += 2;
+    grid->addWidget(buttons, row, 0, 1, 3);
+
+    grid->addWidget(_icon, 0, 0, row - 1, 1, Qt::AlignVCenter | Qt::AlignLeft);
 
     grid->setSizeConstraint(QLayout::SetFixedSize);
-}
 
-void PinEntryDialog::hideEvent(QHideEvent *ev)
-{
-    if (!_pinentry_info || _pinentry_info->grab) {
-        _edit->releaseKeyboard();
-    }
-    _grabbed = false;
-    QDialog::hideEvent(ev);
+    connect(qApp, SIGNAL(focusChanged(QWidget *, QWidget *)),
+            this, SLOT(focusChanged(QWidget *, QWidget *)));
 }
 
 void PinEntryDialog::showEvent(QShowEvent *event)
@@ -335,16 +350,44 @@ void PinEntryDialog::setPinentryInfo(pinentry_t peinfo)
     _pinentry_info = peinfo;
 }
 
-void PinEntryDialog::paintEvent(QPaintEvent *event)
+void PinEntryDialog::focusChanged(QWidget *old, QWidget *now)
 {
     // Grab keyboard. It might be a little weird to do it here, but it works!
     // Previously this code was in showEvent, but that did not work in Qt4.
-    QDialog::paintEvent(event);
-    if (!_grabbed && (!_pinentry_info || _pinentry_info->grab)) {
-        _edit->grabKeyboard();
-        _grabbed = true;
+    if (!_pinentry_info || _pinentry_info->grab) {
+        if (_grabbed && old && (old == _edit || old == mRepeat)) {
+            old->releaseKeyboard();
+            _grabbed = false;
+        }
+        if (!_grabbed && now && (now == _edit || now == mRepeat)) {
+            now->grabKeyboard();
+            _grabbed = true;
+        }
+    }
+
+}
+
+void PinEntryDialog::checkRepeat(const QString &repPin)
+{
+    if (mRepeat->text() == _edit->text()) {
+        _ok->setEnabled(true);
+        _ok->setToolTip(QString());
+    } else {
+        _ok->setEnabled(false);
+        _ok->setToolTip(mRepeatError);
     }
+}
 
+QString PinEntryDialog::repeatedPin() const
+{
+    if (mRepeat) {
+        return mRepeat->text();
+    }
+    return QString();
 }
 
+void PinEntryDialog::setRepeatErrorText(const QString &err)
+{
+    mRepeatError = err;
+}
 #include "pinentrydialog.moc"
diff --git a/qt/pinentrydialog.h b/qt/pinentrydialog.h
index 217213b..1713412 100644
--- a/qt/pinentrydialog.h
+++ b/qt/pinentrydialog.h
@@ -2,8 +2,10 @@
 
    Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
    Copyright 2007 Ingo Klöcker
+   Copyright 2016 Intevation GmbH
 
    Written by Steffen Hansen <steffen at klaralvdalens-datakonsult.se>.
+   Modified by Andre Heinecke <aheinecke at intevation.de>
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -48,8 +50,10 @@ class PinEntryDialog : public QDialog
     Q_PROPERTY(QString pin READ pin WRITE setPin)
     Q_PROPERTY(QString prompt READ prompt WRITE setPrompt)
 public:
-    friend class PinEntryController; // TODO: remove when assuan lets me use Qt eventloop.
-    explicit PinEntryDialog(QWidget *parent = 0, const char *name = 0, int timeout = 0, bool modal = false, bool enable_quality_bar = false);
+    explicit PinEntryDialog(QWidget *parent = 0, const char *name = 0,
+                            int timeout = 0, bool modal = false,
+                            bool enable_quality_bar = false,
+                            const QString &repeatString = QString());
 
     void setDescription(const QString &);
     QString description() const;
@@ -60,6 +64,9 @@ public:
     void setPin(const QString &);
     QString pin() const;
 
+    QString repeatedPin() const;
+    void setRepeatErrorText(const QString &);
+
     void setPrompt(const QString &);
     QString prompt() const;
 
@@ -71,14 +78,14 @@ public:
 
     void setPinentryInfo(pinentry_t);
 
-public slots:
+protected slots:
     void updateQuality(const QString &);
     void slotTimeout();
+    void checkRepeat(const QString &);
+    void focusChanged(QWidget *old, QWidget *now);
 
 protected:
     /* reimp */ void showEvent(QShowEvent *event);
-    /* reimp */ void hideEvent(QHideEvent *);
-    /* reimp */ void paintEvent(QPaintEvent *event);
 
 private:
     QLabel    *_icon;
@@ -88,12 +95,14 @@ private:
     QLabel    *_quality_bar_label;
     QProgressBar *_quality_bar;
     QLineEdit *_edit;
+    QLineEdit *mRepeat;
     QPushButton *_ok;
     QPushButton *_cancel;
     bool       _grabbed;
     bool       _have_quality_bar;
     pinentry_t _pinentry_info;
     QTimer    *_timer;
+    QString    mRepeatError;
 };
 
 #endif // __PINENTRYDIALOG_H__

commit c6b43bd147186deee84dcccbc14f5763db67a0f3
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Apr 14 09:53:37 2016 +0200

    Qt: Respect icon themes and only fallback to own
    
    * m4/qt.m4: Raise version requirement.
    * qt/main.cpp (main): Use QIcon::fromTheme to get the icon.

diff --git a/m4/qt.m4 b/m4/qt.m4
index 8e5a557..093f428 100644
--- a/m4/qt.m4
+++ b/m4/qt.m4
@@ -75,7 +75,7 @@ AC_DEFUN([FIND_QT],
   fi
   if test "$have_qt5_libs" != "yes"; then
     PKG_CHECK_MODULES(PINENTRY_QT,
-                      QtCore >= 4.4.0 QtGui >= 4.4.0,
+                      QtCore >= 4.6.0 QtGui >= 4.6.0,
                       [have_qt4_libs="yes"],
                       [have_qt4_libs="no"])
     if test "$have_qt4_libs" = "yes"; then
diff --git a/qt/main.cpp b/qt/main.cpp
index 4d648b6..9065588 100644
--- a/qt/main.cpp
+++ b/qt/main.cpp
@@ -318,7 +318,9 @@ main(int argc, char *argv[])
            window anymore.  */
         i = argc;
         app.reset(new QApplication(i, new_argv));
-        const QIcon icon(QLatin1String(":/document-encrypt.png"));
+        const QIcon fallback = QIcon(QLatin1String(":/document-encrypt.png"));
+        const QIcon icon = QIcon::fromTheme(QLatin1String("document-encrypt"),
+                                            fallback);
         app->setWindowIcon(icon);
     }
 

commit 8d801fe2c74041f2f8c563785ed7cba73f47500e
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Thu Apr 14 09:32:21 2016 +0200

    Qt: Unify coding style and encoding
    
    * qt/main.cpp, qt/pinentryconfirm.cpp, qt/pinentryconfirm.h,
      qt/pinentrydialog.cpp, qt/pinentrydialog.h: Use KDE coding style.
      Encode as UTF-8.
    
    --
    Code reformatted using kde-dev-scripts/astyle-kdelibs.
    Use git blame -w to show authorship as it was before this commit.

diff --git a/qt/main.cpp b/qt/main.cpp
index c7518fa..4d648b6 100644
--- a/qt/main.cpp
+++ b/qt/main.cpp
@@ -1,7 +1,6 @@
-/*
-   main.cpp - A Qt dialog for PIN entry.
+/* main.cpp - A Qt dialog for PIN entry.
 
-   Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
+   Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
    Copyright (C) 2003 g10 Code GmbH
    Copyright 2007 Ingo Klöcker
 
@@ -63,267 +62,267 @@
   #endif
 #endif
 
-static QString escape_accel( const QString & s ) {
+static QString escape_accel(const QString &s)
+{
 
-  QString result;
-  result.reserve( s.size() );
+    QString result;
+    result.reserve(s.size());
+
+    bool afterUnderscore = false;
+
+    for (unsigned int i = 0, end = s.size() ; i != end ; ++i) {
+        const QChar ch = s[i];
+        if (ch == QLatin1Char('_')) {
+            if (afterUnderscore) { // escaped _
+                result += QLatin1Char('_');
+                afterUnderscore = false;
+            } else { // accel
+                afterUnderscore = true;
+            }
+        } else {
+            if (afterUnderscore ||  // accel
+                    ch == QLatin1Char('&')) {  // escape & from being interpreted by Qt
+                result += QLatin1Char('&');
+            }
+            result += ch;
+            afterUnderscore = false;
+        }
+    }
 
-  bool afterUnderscore = false;
+    if (afterUnderscore)
+        // trailing single underscore: shouldn't happen, but deal with it robustly:
+    {
+        result += QLatin1Char('_');
+    }
 
-  for ( unsigned int i = 0, end = s.size() ; i != end ; ++i ) {
-    const QChar ch = s[i];
-    if ( ch == QLatin1Char( '_' ) )
-      {
-        if ( afterUnderscore ) // escaped _
-          {
-            result += QLatin1Char( '_' );
-            afterUnderscore = false;
-          }
-        else // accel
-          {
-            afterUnderscore = true;
-          }
-      }
-    else
-      {
-        if ( afterUnderscore || // accel
-             ch == QLatin1Char( '&' ) ) // escape & from being interpreted by Qt
-          result += QLatin1Char( '&' );
-        result += ch;
-        afterUnderscore = false;
-      }
-  }
-
-  if ( afterUnderscore )
-    // trailing single underscore: shouldn't happen, but deal with it robustly:
-    result += QLatin1Char( '_' );
-
-  return result;
+    return result;
 }
 
 /* Hack for creating a QWidget with a "foreign" window ID */
 class ForeignWidget : public QWidget
 {
 public:
-  explicit ForeignWidget( WId wid ) : QWidget( 0 )
-  {
-    QWidget::destroy();
-    create( wid, false, false );
-  }
-
-  ~ForeignWidget()
-  {
-    destroy( false, false );
-  }
+    explicit ForeignWidget(WId wid) : QWidget(0)
+    {
+        QWidget::destroy();
+        create(wid, false, false);
+    }
+
+    ~ForeignWidget()
+    {
+        destroy(false, false);
+    }
 };
 
-namespace {
-    class InvalidUtf8 : public std::invalid_argument {
-    public:
-        InvalidUtf8() : std::invalid_argument( "invalid utf8" ) {}
-        ~InvalidUtf8() throw() {}
-    };
+namespace
+{
+class InvalidUtf8 : public std::invalid_argument
+{
+public:
+    InvalidUtf8() : std::invalid_argument("invalid utf8") {}
+    ~InvalidUtf8() throw() {}
+};
 }
 
 static const bool GPG_AGENT_IS_PORTED_TO_ONLY_SEND_UTF8 = false;
 
-static QString from_utf8( const char * s ) {
-    const QString result = QString::fromUtf8( s );
-    if ( result.contains( QChar::ReplacementCharacter ) )
-      {
-        if ( GPG_AGENT_IS_PORTED_TO_ONLY_SEND_UTF8 )
+static QString from_utf8(const char *s)
+{
+    const QString result = QString::fromUtf8(s);
+    if (result.contains(QChar::ReplacementCharacter)) {
+        if (GPG_AGENT_IS_PORTED_TO_ONLY_SEND_UTF8) {
             throw InvalidUtf8();
-        else
-            return QString::fromLocal8Bit( s );
-      }
+        } else {
+            return QString::fromLocal8Bit(s);
+        }
+    }
 
     return result;
 }
 
 static int
-qt_cmd_handler (pinentry_t pe)
+qt_cmd_handler(pinentry_t pe)
 {
-  QWidget *parent = 0;
+    QWidget *parent = 0;
 
-  /* FIXME: Add parent window ID to pinentry and GTK.  */
-  if (pe->parent_wid)
-    parent = new ForeignWidget ((WId) pe->parent_wid);
+    /* FIXME: Add parent window ID to pinentry and GTK.  */
+    if (pe->parent_wid) {
+        parent = new ForeignWidget((WId) pe->parent_wid);
+    }
 
-  int want_pass = !!pe->pin;
+    int want_pass = !!pe->pin;
+
+    const QString ok =
+        pe->ok             ? escape_accel(from_utf8(pe->ok)) :
+        pe->default_ok     ? escape_accel(from_utf8(pe->default_ok)) :
+        /* else */           QLatin1String("&OK") ;
+    const QString cancel =
+        pe->cancel         ? escape_accel(from_utf8(pe->cancel)) :
+        pe->default_cancel ? escape_accel(from_utf8(pe->default_cancel)) :
+        /* else */           QLatin1String("&Cancel") ;
+    const QString title =
+        pe->title ? from_utf8(pe->title) :
+        /* else */  QLatin1String("pinentry-qt") ;
+
+    if (want_pass) {
+        PinEntryDialog pinentry(parent, 0, pe->timeout, true, !!pe->quality_bar);
+
+        pinentry.setPinentryInfo(pe);
+        pinentry.setPrompt(escape_accel(from_utf8(pe->prompt)));
+        pinentry.setDescription(from_utf8(pe->description));
+        if (pe->title) {
+            pinentry.setWindowTitle(from_utf8(pe->title));
+        }
 
-  const QString ok =
-      pe->ok             ? escape_accel( from_utf8( pe->ok ) ) :
-      pe->default_ok     ? escape_accel( from_utf8( pe->default_ok ) ) :
-      /* else */           QLatin1String( "&OK" ) ;
-  const QString cancel =
-      pe->cancel         ? escape_accel( from_utf8( pe->cancel ) ) :
-      pe->default_cancel ? escape_accel( from_utf8( pe->default_cancel ) ) :
-      /* else */           QLatin1String( "&Cancel" ) ;
-  const QString title =
-      pe->title ? from_utf8( pe->title ) :
-      /* else */  QLatin1String( "pinentry-qt" ) ;
+        /* If we reuse the same dialog window.  */
+        pinentry.setPin(QString());
 
+        pinentry.setOkText(ok);
+        pinentry.setCancelText(cancel);
+        if (pe->error) {
+            pinentry.setError(from_utf8(pe->error));
+        }
+        if (pe->quality_bar) {
+            pinentry.setQualityBar(from_utf8(pe->quality_bar));
+        }
+        if (pe->quality_bar_tt) {
+            pinentry.setQualityBarTT(from_utf8(pe->quality_bar_tt));
+        }
 
-  if (want_pass)
-    {
-      PinEntryDialog pinentry (parent, 0, pe->timeout, true, !!pe->quality_bar);
-
-      pinentry.setPinentryInfo (pe);
-      pinentry.setPrompt (escape_accel (from_utf8 (pe->prompt)) );
-      pinentry.setDescription (from_utf8 (pe->description));
-      if ( pe->title )
-          pinentry.setWindowTitle( from_utf8( pe->title ) );
-
-      /* If we reuse the same dialog window.  */
-      pinentry.setPin (QString());
-
-      pinentry.setOkText (ok);
-      pinentry.setCancelText (cancel);
-      if (pe->error)
-	pinentry.setError (from_utf8 (pe->error));
-      if (pe->quality_bar)
-	pinentry.setQualityBar (from_utf8 (pe->quality_bar));
-      if (pe->quality_bar_tt)
-	pinentry.setQualityBarTT (from_utf8 (pe->quality_bar_tt));
-
-      bool ret = pinentry.exec ();
-      if (!ret)
-	return -1;
-
-      QByteArray pin = pinentry.pin().toUtf8 ();
-
-      int len = strlen (pin.constData ());
-      if (len >= 0)
-	{
-	  pinentry_setbufferlen (pe, len + 1);
-	  if (pe->pin)
-	    {
-	      strcpy (pe->pin, pin.constData ());
-	      return len;
-	    }
-	}
-      return -1;
-    }
-  else
-    {
-      const QString desc  = pe->description ? from_utf8 ( pe->description ) : QString();
-      const QString notok = pe->notok       ? escape_accel (from_utf8 ( pe->notok )) : QString();
-
-      const QMessageBox::StandardButtons buttons =
-          pe->one_button ? QMessageBox::Ok :
-          pe->notok      ? QMessageBox::Yes|QMessageBox::No|QMessageBox::Cancel :
-          /* else */       QMessageBox::Ok|QMessageBox::Cancel ;
-
-      PinentryConfirm box( QMessageBox::Information, pe->timeout, title, desc, buttons, parent );
-
-      const struct {
-          QMessageBox::StandardButton button;
-          QString label;
-      } buttonLabels[] = {
-          { QMessageBox::Ok,     ok     },
-          { QMessageBox::Yes,    ok     },
-          { QMessageBox::No,     notok  },
-          { QMessageBox::Cancel, cancel },
-      };
-
-      for ( size_t i = 0 ; i < sizeof buttonLabels / sizeof *buttonLabels ; ++i )
-        if ( (buttons & buttonLabels[i].button) && !buttonLabels[i].label.isEmpty() ) {
-            box.button( buttonLabels[i].button )->setText( buttonLabels[i].label );
+        bool ret = pinentry.exec();
+        if (!ret) {
+            return -1;
+        }
+
+        QByteArray pin = pinentry.pin().toUtf8();
+
+        int len = strlen(pin.constData());
+        if (len >= 0) {
+            pinentry_setbufferlen(pe, len + 1);
+            if (pe->pin) {
+                strcpy(pe->pin, pin.constData());
+                return len;
+            }
+        }
+        return -1;
+    } else {
+        const QString desc  = pe->description ? from_utf8(pe->description) : QString();
+        const QString notok = pe->notok       ? escape_accel(from_utf8(pe->notok)) : QString();
+
+        const QMessageBox::StandardButtons buttons =
+            pe->one_button ? QMessageBox::Ok :
+            pe->notok      ? QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel :
+            /* else */       QMessageBox::Ok | QMessageBox::Cancel ;
+
+        PinentryConfirm box(QMessageBox::Information, pe->timeout, title, desc, buttons, parent);
+
+        const struct {
+            QMessageBox::StandardButton button;
+            QString label;
+        } buttonLabels[] = {
+            { QMessageBox::Ok,     ok     },
+            { QMessageBox::Yes,    ok     },
+            { QMessageBox::No,     notok  },
+            { QMessageBox::Cancel, cancel },
+        };
+
+        for (size_t i = 0 ; i < sizeof buttonLabels / sizeof * buttonLabels ; ++i)
+            if ((buttons & buttonLabels[i].button) && !buttonLabels[i].label.isEmpty()) {
+                box.button(buttonLabels[i].button)->setText(buttonLabels[i].label);
 #ifndef QT_NO_ACCESSIBILITY
-            box.button( buttonLabels[i].button )->setAccessibleDescription ( buttonLabels[i].label );
+                box.button(buttonLabels[i].button)->setAccessibleDescription(buttonLabels[i].label);
 #endif
-        }
+            }
 
-      box.setIconPixmap( icon() );
+        box.setIconPixmap(icon());
 
-      if ( !pe->one_button )
-        box.setDefaultButton( QMessageBox::Cancel );
+        if (!pe->one_button) {
+            box.setDefaultButton(QMessageBox::Cancel);
+        }
 
-      box.show();
-      raiseWindow( &box );
+        box.show();
+        raiseWindow(&box);
 
-      const int rc = box.exec();
+        const int rc = box.exec();
 
-      if ( rc == QMessageBox::Cancel )
-        pe->canceled = true;
+        if (rc == QMessageBox::Cancel) {
+            pe->canceled = true;
+        }
 
-      return rc == QMessageBox::Ok || rc == QMessageBox::Yes ;
+        return rc == QMessageBox::Ok || rc == QMessageBox::Yes ;
 
     }
 }
 
 static int
-qt_cmd_handler_ex (pinentry_t pe)
+qt_cmd_handler_ex(pinentry_t pe)
 {
-  try {
-    return qt_cmd_handler (pe);
-  } catch ( const InvalidUtf8 & ) {
-    pe->locale_err = true;
-    return pe->pin ? -1 : false ;
-  } catch ( ... ) {
-    pe->canceled = true;
-    return pe->pin ? -1 : false ;
-  }
+    try {
+        return qt_cmd_handler(pe);
+    } catch (const InvalidUtf8 &) {
+        pe->locale_err = true;
+        return pe->pin ? -1 : false ;
+    } catch (...) {
+        pe->canceled = true;
+        return pe->pin ? -1 : false ;
+    }
 }
 
 pinentry_cmd_handler_t pinentry_cmd_handler = qt_cmd_handler_ex;
 
 int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
 {
-  pinentry_init ("pinentry-qt");
+    pinentry_init("pinentry-qt");
 
-  std::auto_ptr<QApplication> app;
+    std::auto_ptr<QApplication> app;
 
 #ifdef FALLBACK_CURSES
-  if (!pinentry_have_display (argc, argv))
-    pinentry_cmd_handler = curses_cmd_handler;
-  else
+    if (!pinentry_have_display(argc, argv)) {
+        pinentry_cmd_handler = curses_cmd_handler;
+    } else
 #endif
     {
-      /* Qt does only understand -display but not --display; thus we
-         are fixing that here.  The code is pretty simply and may get
-         confused if an argument is called "--display". */
-      char **new_argv, *p;
-      size_t n;
-      int i, done;
-
-      for (n=0,i=0; i < argc; i++)
-        n += strlen (argv[i])+1;
-      n++;
-      new_argv = (char**)calloc (argc+1, sizeof *new_argv);
-      if (new_argv)
-        *new_argv = (char*)malloc (n);
-      if (!new_argv || !*new_argv)
-        {
-          fprintf (stderr, "pinentry-qt: can't fixup argument list: %s\n",
-                   strerror (errno));
-          exit (EXIT_FAILURE);
+        /* Qt does only understand -display but not --display; thus we
+           are fixing that here.  The code is pretty simply and may get
+           confused if an argument is called "--display". */
+        char **new_argv, *p;
+        size_t n;
+        int i, done;
+
+        for (n = 0, i = 0; i < argc; i++) {
+            n += strlen(argv[i]) + 1;
+        }
+        n++;
+        new_argv = (char **)calloc(argc + 1, sizeof * new_argv);
+        if (new_argv) {
+            *new_argv = (char *)malloc(n);
+        }
+        if (!new_argv || !*new_argv) {
+            fprintf(stderr, "pinentry-qt: can't fixup argument list: %s\n",
+                    strerror(errno));
+            exit(EXIT_FAILURE);
 
         }
-      for (done=0,p=*new_argv,i=0; i < argc; i++)
-        if (!done && !strcmp (argv[i], "--display"))
-          {
-            new_argv[i] = strcpy (p, argv[i]+1);
-            p += strlen (argv[i]+1) + 1;
-            done = 1;
-          }
-        else
-          {
-            new_argv[i] = strcpy (p, argv[i]);
-            p += strlen (argv[i]) + 1;
-          }
-
-      /* We use a modal dialog window, so we don't need the application
-         window anymore.  */
-      i = argc;
-      app.reset (new QApplication (i, new_argv));
-      const QIcon icon( QLatin1String( ":/document-encrypt.png" ) );
-      app->setWindowIcon( icon );
+        for (done = 0, p = *new_argv, i = 0; i < argc; i++)
+            if (!done && !strcmp(argv[i], "--display")) {
+                new_argv[i] = strcpy(p, argv[i] + 1);
+                p += strlen(argv[i] + 1) + 1;
+                done = 1;
+            } else {
+                new_argv[i] = strcpy(p, argv[i]);
+                p += strlen(argv[i]) + 1;
+            }
+
+        /* We use a modal dialog window, so we don't need the application
+           window anymore.  */
+        i = argc;
+        app.reset(new QApplication(i, new_argv));
+        const QIcon icon(QLatin1String(":/document-encrypt.png"));
+        app->setWindowIcon(icon);
     }
 
+    pinentry_parse_opts(argc, argv);
 
-  pinentry_parse_opts (argc, argv);
-
-  return pinentry_loop () ? EXIT_FAILURE : EXIT_SUCCESS ;
+    return pinentry_loop() ? EXIT_FAILURE : EXIT_SUCCESS ;
 }
diff --git a/qt/pinentryconfirm.cpp b/qt/pinentryconfirm.cpp
index 6b3d545..e81b188 100644
--- a/qt/pinentryconfirm.cpp
+++ b/qt/pinentryconfirm.cpp
@@ -1,5 +1,4 @@
-/*
-   pinentryconfirm.cpp - A QMessageBox with a timeout
+/* pinentryconfirm.cpp - A QMessageBox with a timeout
 
    Copyright (C) 2011 Ben Kibbey <bjk at luxsci.net>
 
@@ -22,33 +21,34 @@
 #include <QAbstractButton>
 
 PinentryConfirm::PinentryConfirm(Icon icon, int timeout, const QString &title,
-	const QString &desc, StandardButtons buttons, QWidget *parent) :
+                                 const QString &desc, StandardButtons buttons, QWidget *parent) :
     QMessageBox(icon, title, desc, buttons, parent)
 {
     if (timeout > 0) {
-	_timer = new QTimer(this);
-	connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
-	_timer->start(timeout*1000);
+        _timer = new QTimer(this);
+        connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
+        _timer->start(timeout * 1000);
     }
 #ifndef QT_NO_ACCESSIBILITY
-    setAccessibleDescription (desc);
-    setAccessibleName (title);
+    setAccessibleDescription(desc);
+    setAccessibleName(title);
 #endif
-    raiseWindow (this);
+    raiseWindow(this);
 }
 
-void PinentryConfirm::showEvent( QShowEvent* event )
+void PinentryConfirm::showEvent(QShowEvent *event)
 {
-    QDialog::showEvent( event );
-    raiseWindow( this );
+    QDialog::showEvent(event);
+    raiseWindow(this);
 }
 
 void PinentryConfirm::slotTimeout()
 {
     QAbstractButton *b = button(QMessageBox::Cancel);
 
-    if (b)
-	b->animateClick(0);
+    if (b) {
+        b->animateClick(0);
+    }
 }
 
 #include "pinentryconfirm.moc"
diff --git a/qt/pinentryconfirm.h b/qt/pinentryconfirm.h
index 44fb3ae..23e05dc 100644
--- a/qt/pinentryconfirm.h
+++ b/qt/pinentryconfirm.h
@@ -1,5 +1,4 @@
-/*
-   pinentryconfirm.h - A QMessageBox with a timeout
+/* pinentryconfirm.h - A QMessageBox with a timeout
 
    Copyright (C) 2011 Ben Kibbey <bjk at luxsci.net>
 
@@ -26,19 +25,19 @@
 class PinentryConfirm : public QMessageBox
 {
     Q_OBJECT
-    public:
-	PinentryConfirm(Icon, int timeout, const QString &title,
-		const QString &desc, StandardButtons buttons,
-		QWidget *parent);
+public:
+    PinentryConfirm(Icon, int timeout, const QString &title,
+                    const QString &desc, StandardButtons buttons,
+                    QWidget *parent);
 
-    private slots:
-	void slotTimeout();
+private slots:
+    void slotTimeout();
 
-    private:
-	QTimer *_timer;
+private:
+    QTimer *_timer;
 
-    protected:
-    /* reimp */ void showEvent( QShowEvent* event );
+protected:
+    /* reimp */ void showEvent(QShowEvent *event);
 };
 
 #endif
diff --git a/qt/pinentrydialog.cpp b/qt/pinentrydialog.cpp
index 1b0d276..91d5adb 100644
--- a/qt/pinentrydialog.cpp
+++ b/qt/pinentrydialog.cpp
@@ -1,7 +1,6 @@
-/*
-   pinentrydialog.cpp - A (not yet) secure Qt 4 dialog for PIN entry.
+/* pinentrydialog.cpp - A (not yet) secure Qt 4 dialog for PIN entry.
 
-   Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
+   Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
    Copyright 2007 Ingo Klöcker
 
    Written by Steffen Hansen <steffen at klaralvdalens-datakonsult.se>.
@@ -52,53 +51,53 @@
    has not expired.
    */
 #ifdef Q_OS_WIN
-WINBOOL SetForegroundWindowEx( HWND hWnd )
+WINBOOL SetForegroundWindowEx(HWND hWnd)
 {
-   //Attach foreground window thread to our thread
-   const DWORD ForeGroundID = GetWindowThreadProcessId(::GetForegroundWindow(),NULL);
-   const DWORD CurrentID   = GetCurrentThreadId();
-   WINBOOL retval;
-
-   AttachThreadInput ( ForeGroundID, CurrentID, TRUE );
-   //Do our stuff here
-   HWND hLastActivePopupWnd = GetLastActivePopup( hWnd );
-   retval = SetForegroundWindow( hLastActivePopupWnd );
-
-   //Detach the attached thread
-   AttachThreadInput ( ForeGroundID, CurrentID, FALSE );
-   return retval;
+    //Attach foreground window thread to our thread
+    const DWORD ForeGroundID = GetWindowThreadProcessId(::GetForegroundWindow(), NULL);
+    const DWORD CurrentID   = GetCurrentThreadId();
+    WINBOOL retval;
+
+    AttachThreadInput(ForeGroundID, CurrentID, TRUE);
+    //Do our stuff here
+    HWND hLastActivePopupWnd = GetLastActivePopup(hWnd);
+    retval = SetForegroundWindow(hLastActivePopupWnd);
+
+    //Detach the attached thread
+    AttachThreadInput(ForeGroundID, CurrentID, FALSE);
+    return retval;
 }// End SetForegroundWindowEx
 #endif
 
-void raiseWindow( QWidget* w )
+void raiseWindow(QWidget *w)
 {
     /* Maybe Qt will become agressive enough one day that
      * this is enough on windows too*/
     w->raise();
 #ifdef Q_OS_WIN
     /* In the meantime we do our own attention grabbing */
-    if (!SetForegroundWindow ((HWND)w->winId()) &&
-            !SetForegroundWindowEx ((HWND)w->winId()))  {
+    if (!SetForegroundWindow((HWND)w->winId()) &&
+            !SetForegroundWindowEx((HWND)w->winId()))  {
         OutputDebugString("SetForegroundWindow (ex) failed");
         /* Yet another fallback which will not work on some
          * versions and is not recommended by msdn */
-        if (!ShowWindow ((HWND)w->winId(), SW_SHOWNORMAL)) {
-            OutputDebugString ("ShowWindow failed.");
+        if (!ShowWindow((HWND)w->winId(), SW_SHOWNORMAL)) {
+            OutputDebugString("ShowWindow failed.");
         }
     }
 #endif
 }
 
-QPixmap icon( QStyle::StandardPixmap which )
+QPixmap icon(QStyle::StandardPixmap which)
 {
-    QPixmap pm = qApp->windowIcon().pixmap( 48, 48 );
+    QPixmap pm = qApp->windowIcon().pixmap(48, 48);
 
-    if ( which != QStyle::SP_CustomBase ) {
-        const QIcon ic = qApp->style()->standardIcon( which );
-        QPainter painter( &pm );
+    if (which != QStyle::SP_CustomBase) {
+        const QIcon ic = qApp->style()->standardIcon(which);
+        QPainter painter(&pm);
         const int emblemSize = 22;
-        painter.drawPixmap( pm.width()-emblemSize, 0,
-                            ic.pixmap( emblemSize, emblemSize ) );
+        painter.drawPixmap(pm.width() - emblemSize, 0,
+                           ic.pixmap(emblemSize, emblemSize));
     }
 
     return pm;
@@ -109,143 +108,143 @@ void PinEntryDialog::slotTimeout()
     reject();
 }
 
-PinEntryDialog::PinEntryDialog( QWidget* parent, const char* name,
-	int timeout, bool modal, bool enable_quality_bar )
-  : QDialog( parent, Qt::WindowStaysOnTopHint ), _grabbed( false )
+PinEntryDialog::PinEntryDialog(QWidget *parent, const char *name,
+                               int timeout, bool modal, bool enable_quality_bar)
+    : QDialog(parent, Qt::WindowStaysOnTopHint), _grabbed(false)
 {
-  setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint );
-
-  if ( modal ) {
-    setWindowModality( Qt::ApplicationModal );
-  }
-
-  _icon = new QLabel( this );
-  _icon->setPixmap( icon() );
-
-  _error = new QLabel( this );
-  _error->setWordWrap(true);
-  QPalette pal;
-  pal.setColor( QPalette::WindowText, Qt::red );
-  _error->setPalette( pal );
-  _error->hide();
-
-  _desc = new QLabel( this );
-  _desc->setWordWrap(true);
-  _desc->hide();
-
-  _prompt = new QLabel( this );
-  _prompt->hide();
-
-  _edit = new QLineEdit( this );
-  _edit->setMaxLength( 256 );
-  _edit->setEchoMode( QLineEdit::Password );
-
-  _prompt->setBuddy( _edit );
-
-  if (enable_quality_bar)
-  {
-    _quality_bar_label = new QLabel( this );
-    _quality_bar_label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
-    _quality_bar = new QProgressBar( this );
-    _quality_bar->setAlignment( Qt::AlignCenter );
-    _have_quality_bar = true;
-  }
-  else
-    _have_quality_bar = false;
-
-  QDialogButtonBox* const buttons = new QDialogButtonBox( this );
-  buttons->setStandardButtons( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
-  _ok = buttons->button( QDialogButtonBox::Ok );
-  _cancel = buttons->button( QDialogButtonBox::Cancel );
-
-  _ok->setDefault(true);
-
-  if ( style()->styleHint( QStyle::SH_DialogButtonBox_ButtonsHaveIcons ) )
-    {
-      _ok->setIcon( style()->standardIcon( QStyle::SP_DialogOkButton ) );
-      _cancel->setIcon( style()->standardIcon( QStyle::SP_DialogCancelButton ) );
+    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
+
+    if (modal) {
+        setWindowModality(Qt::ApplicationModal);
+    }
+
+    _icon = new QLabel(this);
+    _icon->setPixmap(icon());
+
+    _error = new QLabel(this);
+    _error->setWordWrap(true);
+    QPalette pal;
+    pal.setColor(QPalette::WindowText, Qt::red);
+    _error->setPalette(pal);
+    _error->hide();
+
+    _desc = new QLabel(this);
+    _desc->setWordWrap(true);
+    _desc->hide();
+
+    _prompt = new QLabel(this);
+    _prompt->hide();
+
+    _edit = new QLineEdit(this);
+    _edit->setMaxLength(256);
+    _edit->setEchoMode(QLineEdit::Password);
+
+    _prompt->setBuddy(_edit);
+
+    if (enable_quality_bar) {
+        _quality_bar_label = new QLabel(this);
+        _quality_bar_label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
+        _quality_bar = new QProgressBar(this);
+        _quality_bar->setAlignment(Qt::AlignCenter);
+        _have_quality_bar = true;
+    } else {
+        _have_quality_bar = false;
+    }
+
+    QDialogButtonBox *const buttons = new QDialogButtonBox(this);
+    buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+    _ok = buttons->button(QDialogButtonBox::Ok);
+    _cancel = buttons->button(QDialogButtonBox::Cancel);
+
+    _ok->setDefault(true);
+
+    if (style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons)) {
+        _ok->setIcon(style()->standardIcon(QStyle::SP_DialogOkButton));
+        _cancel->setIcon(style()->standardIcon(QStyle::SP_DialogCancelButton));
+    }
+
+    if (timeout > 0) {
+        _timer = new QTimer(this);
+        connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
+        _timer->start(timeout * 1000);
+    } else {
+        _timer = NULL;
+    }
+
+    connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
+    connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
+    connect(_edit, SIGNAL(textChanged(QString)),
+            this, SLOT(updateQuality(QString)));
+
+    _edit->setFocus();
+
+    QGridLayout *const grid = new QGridLayout(this);
+    grid->addWidget(_icon, 0, 0, 5, 1, Qt::AlignTop | Qt::AlignLeft);
+    grid->addWidget(_error, 1, 1, 1, 2);
+    grid->addWidget(_desc,  2, 1, 1, 2);
+    //grid->addItem( new QSpacerItem( 0, _edit->height() / 10, QSizePolicy::Minimum, QSizePolicy::Fixed ), 1, 1 );
+    grid->addWidget(_prompt, 3, 1);
+    grid->addWidget(_edit, 3, 2);
+    if (enable_quality_bar) {
+        grid->addWidget(_quality_bar_label, 4, 1);
+        grid->addWidget(_quality_bar, 4, 2);
     }
+    grid->addWidget(buttons, 5, 0, 1, 3);
 
-  if (timeout > 0) {
-      _timer = new QTimer(this);
-      connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
-      _timer->start(timeout*1000);
-  }
-  else
-    _timer = NULL;
-
-  connect( buttons, SIGNAL(accepted()), this, SLOT(accept()) );
-  connect( buttons, SIGNAL(rejected()), this, SLOT(reject()) );
-  connect( _edit, SIGNAL( textChanged(QString) ),
-	   this, SLOT( updateQuality(QString) ) );
-
-  _edit->setFocus();
-
-  QGridLayout* const grid = new QGridLayout( this );
-  grid->addWidget( _icon, 0, 0, 5, 1, Qt::AlignTop|Qt::AlignLeft );
-  grid->addWidget( _error, 1, 1, 1, 2 );
-  grid->addWidget( _desc,  2, 1, 1, 2 );
-  //grid->addItem( new QSpacerItem( 0, _edit->height() / 10, QSizePolicy::Minimum, QSizePolicy::Fixed ), 1, 1 );
-  grid->addWidget( _prompt, 3, 1 );
-  grid->addWidget( _edit, 3, 2 );
-  if( enable_quality_bar )
-  {
-    grid->addWidget( _quality_bar_label, 4, 1 );
-    grid->addWidget( _quality_bar, 4, 2 );
-  }
-  grid->addWidget( buttons, 5, 0, 1, 3 );
-
-  grid->setSizeConstraint( QLayout::SetFixedSize );
+    grid->setSizeConstraint(QLayout::SetFixedSize);
 }
 
-void PinEntryDialog::hideEvent( QHideEvent* ev )
+void PinEntryDialog::hideEvent(QHideEvent *ev)
 {
-  if ( !_pinentry_info || _pinentry_info->grab )
-    _edit->releaseKeyboard();
-  _grabbed = false;
-  QDialog::hideEvent( ev );
+    if (!_pinentry_info || _pinentry_info->grab) {
+        _edit->releaseKeyboard();
+    }
+    _grabbed = false;
+    QDialog::hideEvent(ev);
 }
 
-void PinEntryDialog::showEvent( QShowEvent* event )
+void PinEntryDialog::showEvent(QShowEvent *event)
 {
-    QDialog::showEvent( event );
-    raiseWindow( this );
+    QDialog::showEvent(event);
+    raiseWindow(this);
 }
 
-void PinEntryDialog::setDescription( const QString& txt )
+void PinEntryDialog::setDescription(const QString &txt)
 {
-  _desc->setVisible( !txt.isEmpty() );
-  _desc->setText( txt );
+    _desc->setVisible(!txt.isEmpty());
+    _desc->setText(txt);
 #ifndef QT_NO_ACCESSIBILITY
-  _desc->setAccessibleDescription ( txt );
+    _desc->setAccessibleDescription(txt);
 #endif
-  _icon->setPixmap( icon() );
-  setError( QString::null );
+    _icon->setPixmap(icon());
+    setError(QString::null);
 }
 
 QString PinEntryDialog::description() const
 {
-  return _desc->text();
+    return _desc->text();
 }
 
-void PinEntryDialog::setError( const QString& txt )
+void PinEntryDialog::setError(const QString &txt)
 {
-  if( !txt.isNull() )_icon->setPixmap( icon( QStyle::SP_MessageBoxCritical ) );
-  _error->setText( txt );
+    if (!txt.isNull()) {
+        _icon->setPixmap(icon(QStyle::SP_MessageBoxCritical));
+    }
+    _error->setText(txt);
 #ifndef QT_NO_ACCESSIBILITY
-  _error->setAccessibleDescription ( txt );
+    _error->setAccessibleDescription(txt);
 #endif
-  _error->setVisible( !txt.isEmpty() );
+    _error->setVisible(!txt.isEmpty());
 }
 
 QString PinEntryDialog::error() const
 {
-  return _error->text();
+    return _error->text();
 }
 
-void PinEntryDialog::setPin( const QString & txt )
+void PinEntryDialog::setPin(const QString &txt)
 {
-    _edit->setText( txt );
+    _edit->setText(txt);
 }
 
 QString PinEntryDialog::pin() const
@@ -253,84 +252,81 @@ QString PinEntryDialog::pin() const
     return _edit->text();
 }
 
-void PinEntryDialog::setPrompt( const QString& txt )
+void PinEntryDialog::setPrompt(const QString &txt)
 {
-  _prompt->setText( txt );
-  _prompt->setVisible( !txt.isEmpty() );
+    _prompt->setText(txt);
+    _prompt->setVisible(!txt.isEmpty());
 }
 
 QString PinEntryDialog::prompt() const
 {
-  return _prompt->text();
+    return _prompt->text();
 }
 
-void PinEntryDialog::setOkText( const QString& txt )
+void PinEntryDialog::setOkText(const QString &txt)
 {
-  _ok->setText( txt );
+    _ok->setText(txt);
 #ifndef QT_NO_ACCESSIBILITY
-  _ok->setAccessibleDescription ( txt );
+    _ok->setAccessibleDescription(txt);
 #endif
-  _ok->setVisible( !txt.isEmpty() );
+    _ok->setVisible(!txt.isEmpty());
 }
 
-void PinEntryDialog::setCancelText( const QString& txt )
+void PinEntryDialog::setCancelText(const QString &txt)
 {
-  _cancel->setText( txt );
+    _cancel->setText(txt);
 #ifndef QT_NO_ACCESSIBILITY
-  _cancel->setAccessibleDescription ( txt );
+    _cancel->setAccessibleDescription(txt);
 #endif
-  _cancel->setVisible( !txt.isEmpty() );
+    _cancel->setVisible(!txt.isEmpty());
 }
 
-void PinEntryDialog::setQualityBar( const QString& txt )
+void PinEntryDialog::setQualityBar(const QString &txt)
 {
-  if (_have_quality_bar) {
-    _quality_bar_label->setText( txt );
+    if (_have_quality_bar) {
+        _quality_bar_label->setText(txt);
 #ifndef QT_NO_ACCESSIBILITY
-    _quality_bar_label->setAccessibleDescription ( txt );
+        _quality_bar_label->setAccessibleDescription(txt);
 #endif
-  }
+    }
 }
 
-void PinEntryDialog::setQualityBarTT( const QString& txt )
+void PinEntryDialog::setQualityBarTT(const QString &txt)
 {
-  if (_have_quality_bar)
-    _quality_bar->setToolTip( txt );
+    if (_have_quality_bar) {
+        _quality_bar->setToolTip(txt);
+    }
 }
 
-void PinEntryDialog::updateQuality(const QString & txt )
+void PinEntryDialog::updateQuality(const QString &txt)
 {
-  int length;
-  int percent;
-  QPalette pal;
-
-  if (_timer)
-    _timer->stop();
-
-  if (!_have_quality_bar || !_pinentry_info)
-    return;
-  const QByteArray utf8_pin = txt.toUtf8 ();
-  const char* pin = utf8_pin.constData ();
-  length = strlen (pin);
-  percent = length? pinentry_inq_quality (_pinentry_info, pin, length) : 0;
-  if (!length)
-    {
-      _quality_bar->reset ();
+    int length;
+    int percent;
+    QPalette pal;
+
+    if (_timer) {
+        _timer->stop();
     }
-  else
-    {
-      pal = _quality_bar->palette ();
-      if (percent < 0)
-        {
-          pal.setColor (QPalette::Highlight, QColor("red"));
-          percent = -percent;
-        }
-      else
-        {
-          pal.setColor (QPalette::Highlight, QColor("green"));
+
+    if (!_have_quality_bar || !_pinentry_info) {
+        return;
+    }
+    const QByteArray utf8_pin = txt.toUtf8();
+    const char *pin = utf8_pin.constData();
+    length = strlen(pin);
+    percent = length ? pinentry_inq_quality(_pinentry_info, pin, length) : 0;
+    if (!length) {
+        _quality_bar->reset();
+    } else {
+        pal = _quality_bar->palette();
+        if (percent < 0) {
+            pal.setColor(QPalette::Highlight, QColor("red"));
+            percent = -percent;
+        } else {
+            pal.setColor(QPalette::Highlight, QColor("green"));
         }
-      _quality_bar->setPalette (pal);
-      _quality_bar->setValue (percent);
+        _quality_bar->setPalette(pal);
+        _quality_bar->setValue(percent);
     }
 }
 
@@ -339,15 +335,15 @@ void PinEntryDialog::setPinentryInfo(pinentry_t peinfo)
     _pinentry_info = peinfo;
 }
 
-void PinEntryDialog::paintEvent( QPaintEvent* event )
+void PinEntryDialog::paintEvent(QPaintEvent *event)
 {
-  // Grab keyboard. It might be a little weird to do it here, but it works!
-  // Previously this code was in showEvent, but that did not work in Qt4.
-  QDialog::paintEvent( event );
-  if ( !_grabbed && ( !_pinentry_info || _pinentry_info->grab ) ) {
-    _edit->grabKeyboard();
-    _grabbed = true;
-  }
+    // Grab keyboard. It might be a little weird to do it here, but it works!
+    // Previously this code was in showEvent, but that did not work in Qt4.
+    QDialog::paintEvent(event);
+    if (!_grabbed && (!_pinentry_info || _pinentry_info->grab)) {
+        _edit->grabKeyboard();
+        _grabbed = true;
+    }
 
 }
 
diff --git a/qt/pinentrydialog.h b/qt/pinentrydialog.h
index 82755cd..217213b 100644
--- a/qt/pinentrydialog.h
+++ b/qt/pinentrydialog.h
@@ -1,7 +1,6 @@
-/*
-   pinentrydialog.h - A (not yet) secure Qt 4 dialog for PIN entry.
+/* pinentrydialog.h - A (not yet) secure Qt 4 dialog for PIN entry.
 
-   Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
+   Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
    Copyright 2007 Ingo Klöcker
 
    Written by Steffen Hansen <steffen at klaralvdalens-datakonsult.se>.
@@ -36,64 +35,65 @@ class QLineEdit;
 class QString;
 class QProgressBar;
 
-QPixmap icon( QStyle::StandardPixmap which = QStyle::SP_CustomBase );
+QPixmap icon(QStyle::StandardPixmap which = QStyle::SP_CustomBase);
 
-void raiseWindow( QWidget* w );
+void raiseWindow(QWidget *w);
 
-class PinEntryDialog : public QDialog {
-  Q_OBJECT
+class PinEntryDialog : public QDialog
+{
+    Q_OBJECT
 
-  Q_PROPERTY( QString description READ description WRITE setDescription )
-  Q_PROPERTY( QString error READ error WRITE setError )
-  Q_PROPERTY( QString pin READ pin WRITE setPin )
-  Q_PROPERTY( QString prompt READ prompt WRITE setPrompt )
+    Q_PROPERTY(QString description READ description WRITE setDescription)
+    Q_PROPERTY(QString error READ error WRITE setError)
+    Q_PROPERTY(QString pin READ pin WRITE setPin)
+    Q_PROPERTY(QString prompt READ prompt WRITE setPrompt)
 public:
-  friend class PinEntryController; // TODO: remove when assuan lets me use Qt eventloop.
-  explicit PinEntryDialog( QWidget* parent = 0, const char* name = 0, int timeout = 0, bool modal = false, bool enable_quality_bar = false );
+    friend class PinEntryController; // TODO: remove when assuan lets me use Qt eventloop.
+    explicit PinEntryDialog(QWidget *parent = 0, const char *name = 0, int timeout = 0, bool modal = false, bool enable_quality_bar = false);
 
-  void setDescription( const QString& );
-  QString description() const;
+    void setDescription(const QString &);
+    QString description() const;
 
-  void setError( const QString& );
-  QString error() const;
+    void setError(const QString &);
+    QString error() const;
 
-  void setPin( const QString & );
-  QString pin() const;
+    void setPin(const QString &);
+    QString pin() const;
 
-  void setPrompt( const QString& );
-  QString prompt() const;
+    void setPrompt(const QString &);
+    QString prompt() const;
 
-  void setOkText( const QString& );
-  void setCancelText( const QString& );
+    void setOkText(const QString &);
+    void setCancelText(const QString &);
 
-  void setQualityBar( const QString& );
-  void setQualityBarTT( const QString& );
+    void setQualityBar(const QString &);
+    void setQualityBarTT(const QString &);
 
-  void setPinentryInfo (pinentry_t);
+    void setPinentryInfo(pinentry_t);
 
 public slots:
-  void updateQuality(const QString&);
-  void slotTimeout();
+    void updateQuality(const QString &);
+    void slotTimeout();
 
 protected:
-  /* reimp */ void showEvent( QShowEvent* event );
-  /* reimp */ void hideEvent( QHideEvent* );
-  /* reimp */ void paintEvent( QPaintEvent* event );
+    /* reimp */ void showEvent(QShowEvent *event);
+    /* reimp */ void hideEvent(QHideEvent *);
+    /* reimp */ void paintEvent(QPaintEvent *event);
 
 private:
-  QLabel*    _icon;
-  QLabel*    _desc;
-  QLabel*    _error;
-  QLabel*    _prompt;
-  QLabel*    _quality_bar_label;
-  QProgressBar* _quality_bar;
-  QLineEdit* _edit;
-  QPushButton* _ok;
-  QPushButton* _cancel;
-  bool       _grabbed;
-  bool       _have_quality_bar;
-  pinentry_t _pinentry_info;
-  QTimer*    _timer;
+    QLabel    *_icon;
+    QLabel    *_desc;
+    QLabel    *_error;
+    QLabel    *_prompt;
+    QLabel    *_quality_bar_label;
+    QProgressBar *_quality_bar;
+    QLineEdit *_edit;
+    QPushButton *_ok;
+    QPushButton *_cancel;
+    bool       _grabbed;
+    bool       _have_quality_bar;
+    pinentry_t _pinentry_info;
+    QTimer    *_timer;
 };
 
 #endif // __PINENTRYDIALOG_H__

-----------------------------------------------------------------------

Summary of changes:
 m4/qt.m4               |   2 +-
 qt/main.cpp            | 435 +++++++++++++++++++++++++------------------------
 qt/pinentryconfirm.cpp |  28 ++--
 qt/pinentryconfirm.h   |  23 ++-
 qt/pinentrydialog.cpp  | 431 ++++++++++++++++++++++++++----------------------
 qt/pinentrydialog.h    |  99 ++++++-----
 6 files changed, 541 insertions(+), 477 deletions(-)


hooks/post-receive
-- 
The standard pinentry collection
http://git.gnupg.org




More information about the Gnupg-commits mailing list