[svn] pinentry - r185 - in trunk: . qt4

svn author marcus cvs at cvs.gnupg.org
Thu Jul 24 16:49:22 CEST 2008


Author: marcus
Date: 2008-07-24 16:49:21 +0200 (Thu, 24 Jul 2008)
New Revision: 185

Added:
   trunk/qt4/
   trunk/qt4/Makefile.am
   trunk/qt4/main.cpp
   trunk/qt4/pinentrydialog.cpp
   trunk/qt4/pinentrydialog.h
Modified:
   trunk/ChangeLog
   trunk/Makefile.am
   trunk/NEWS
   trunk/configure.ac
Log:
2008-07-24  Marcus Brinkmann  <marcus at g10code.de>

	* qt4/pinentrydialog.h, qt4/pinentrydialog.cpp, qt4/main.cpp,
	qt4/Makefile.am: New files.
	* configure.ac: Add check for Qt4.
	(AC_CONFIG_FILES): Add qt4/Makefile.am.
	* Makefile.am (pinentry_qt4): New variable.
	(SUBDIRS): Add ${pinentry_qt4}.


[The diff below has been truncated]

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-07-23 11:48:00 UTC (rev 184)
+++ trunk/ChangeLog	2008-07-24 14:49:21 UTC (rev 185)
@@ -1,3 +1,12 @@
+2008-07-24  Marcus Brinkmann  <marcus at g10code.de>
+
+	* qt4/pinentrydialog.h, qt4/pinentrydialog.cpp, qt4/main.cpp,
+	qt4/Makefile.am: New files.
+	* configure.ac: Add check for Qt4.
+	(AC_CONFIG_FILES): Add qt4/Makefile.am.
+	* Makefile.am (pinentry_qt4): New variable.
+	(SUBDIRS): Add ${pinentry_qt4}.
+
 2008-07-23  Werner Koch  <wk at g10code.com>
 
 	* secmem/secmem.c (secmem_init): Fix apostrophe in error

Modified: trunk/Makefile.am
===================================================================
--- trunk/Makefile.am	2008-07-23 11:48:00 UTC (rev 184)
+++ trunk/Makefile.am	2008-07-24 14:49:21 UTC (rev 185)
@@ -47,6 +47,12 @@
 pinentry_qt = 
 endif
 
+if BUILD_PINENTRY_QT4
+pinentry_qt4 = qt4
+else
+pinentry_qt4 = 
+endif
+
 if BUILD_PINENTRY_W32
 pinentry_w32 = w32
 else
@@ -54,7 +60,8 @@
 endif
 
 SUBDIRS = assuan secmem pinentry ${pinentry_curses} \
-	${pinentry_gtk} ${pinentry_gtk_2} ${pinentry_qt} ${pinentry_w32} doc
+	${pinentry_gtk} ${pinentry_gtk_2} ${pinentry_qt} ${pinentry_qt4} \
+	${pinentry_w32} doc
 
 
 install-exec-local:

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2008-07-23 11:48:00 UTC (rev 184)
+++ trunk/NEWS	2008-07-24 14:49:21 UTC (rev 185)
@@ -3,6 +3,8 @@
 
  * Make Gtk+-2 pinentry transient to the root window.
 
+ * Add Qt4 pinentry.
+
 Noteworthy changes in version 0.7.5 (2008-02-15)
 ------------------------------------------------
 

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2008-07-23 11:48:00 UTC (rev 184)
+++ trunk/configure.ac	2008-07-24 14:49:21 UTC (rev 185)
@@ -46,7 +46,7 @@
 AC_PROG_CPP
 AC_PROG_INSTALL
 AC_PROG_RANLIB
-# We need to check for cplusplus here becuase we may not do the test
+# We need to check for cplusplus here because we may not do the test
 # for Qt and autoconf does does not allow that.
 AC_PROG_CXX
 AC_PROG_LN_S
@@ -355,6 +355,56 @@
 dnl fi
 
 
+dnl
+dnl Check for Qt4 pinentry program.
+dnl
+AC_ARG_ENABLE(pinentry-qt4,
+            AC_HELP_STRING([--enable-pinentry-qt4], [build Qt4 pinentry]),
+            pinentry_qt4=$enableval, pinentry_qt4=maybe)
+
+
+dnl
+dnl Checks for Qt4 libraries.  Deal correctly with $pinentry_qt4 = maybe.
+dnl
+if test "$pinentry_qt4" != "no"; then
+PKG_CHECK_MODULES(QT4_CORE, QtCore,,
+if test "$pinentry_qt4" = "yes"; then
+    AC_MSG_ERROR([[
+***
+*** Qt4 Core is required.
+***]])
+else
+    pinentry_qt4=no
+fi)
+fi
+
+if test "$pinentry_qt4" != "no"; then
+PKG_CHECK_MODULES(QT4_GUI, QtGui,,
+if test "$pinentry_qt4" = "yes"; then
+    AC_MSG_ERROR([[
+***
+*** Qt4 Gui is required.
+***]])
+else
+    pinentry_qt4=no
+fi)
+fi
+
+dnl If we have come so far, Qt4 pinentry can be build.
+if test "$pinentry_qt4" != "no"; then
+    pinentry_qt4=yes
+fi
+AM_CONDITIONAL(BUILD_PINENTRY_QT4, test "$pinentry_qt4" = "yes")
+if test "$pinentry_qt4" = "yes"; then
+  AC_DEFINE(PINENTRY_QT4, 1, [The Qt4 version of Pinentry is to be build])
+fi
+
+dnl if test "$pinentry_qt4" = "yes"; then
+dnl Additional checks for Qt4 pinentry.
+dnl End of additional checks for Qt4 pinentry.
+dnl fi
+
+
 #
 # Check whether we should build the W32 pinentry.  This is actually
 # the simplest check as we do this only for that platform.
@@ -399,6 +449,7 @@
 gtk/Makefile
 gtk+-2/Makefile
 qt/Makefile
+qt4/Makefile
 w32/Makefile
 doc/Makefile
 Makefile
@@ -413,6 +464,7 @@
 	GTK+ Pinentry: $pinentry_gtk
 	GTK+-2 Pinentry: $pinentry_gtk_2
 	Qt Pinentry: $pinentry_qt
+	Qt4 Pinentry: $pinentry_qt4
         W32 Pinentry: $pinentry_w32
 
 	Fallback to Curses: $fallback_curses

Added: trunk/qt4/Makefile.am
===================================================================
--- trunk/qt4/Makefile.am	2008-07-23 11:48:00 UTC (rev 184)
+++ trunk/qt4/Makefile.am	2008-07-24 14:49:21 UTC (rev 185)
@@ -0,0 +1,48 @@
+# Makefile.am
+# Copyright (C) 2002 g10 Code GmbH, Klarälvdalens Datakonsult AB
+# Copyright (C) 2008 g10 Code GmbH
+#
+# This file is part of PINENTRY.
+#
+# PINENTRY 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.
+#
+# PINENTRY 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+
+## Process this file with automake to produce Makefile.in
+
+bin_PROGRAMS = pinentry-qt4
+
+if FALLBACK_CURSES
+ncurses_include = $(NCURSES_INCLUDE)
+libcurses = ../pinentry/libpinentry-curses.a $(LIBCURSES) $(LIBICONV)
+else
+ncurses_include =
+libcurses =
+endif
+
+
+AM_CPPFLAGS = -I$(top_srcdir)/assuan -I$(top_srcdir)/secmem \
+	$(ncurses_include) -I$(top_srcdir)/pinentry
+AM_CXXFLAGS = $(QT4_CORE_CFLAGS) $(QT4_GUI_CFLAGS)
+pinentry_qt4_LDADD = $(QT4_CORE_LIBS) $(QT4_GUI_LIBS) $(libcurses) \
+	../pinentry/libpinentry.a $(top_builddir)/assuan/libassuan.a \
+	$(top_builddir)/secmem/libsecmem.a $(LIBCAP)
+
+pinentry_qt4_SOURCES = pinentrydialog.h pinentrydialog.cpp \
+	main.cpp 
+nodist_pinentry_qt4_SOURCES = pinentrydialog.moc
+
+DISTCLEANFILES = $(nodist_pinentry_qt4_SOURCES)
+
+%.moc: $(srcdir)/%.h
+	$(MOC) $< -o $@

Added: trunk/qt4/main.cpp
===================================================================
--- trunk/qt4/main.cpp	2008-07-23 11:48:00 UTC (rev 184)
+++ trunk/qt4/main.cpp	2008-07-24 14:49:21 UTC (rev 185)
@@ -0,0 +1,191 @@
+/* 
+   main.cpp - A (not yet) secure Qt 4 dialog for PIN entry.
+
+   Copyright (C) 2002 Klarälvdalens Datakonsult AB
+   Copyright (C) 2003 g10 Code GmbH
+   Copyright 2007 Ingo Klöcker
+
+   Written by Steffen Hansen <steffen at klaralvdalens-datakonsult.se>.
+   Modified by Marcus Brinkmann <marcus at g10code.de>.
+   
+   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, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+
+#include <stdlib.h>
+#include <errno.h>
+
+#include <qapplication.h>
+#include <QString>
+#include <qwidget.h>
+#include <qmessagebox.h>
+// #include "secqstring.h"
+
+#include "pinentrydialog.h"
+
+#include "pinentry.h"
+
+extern "C"
+{
+#include "memory.h"
+}
+
+#include <stdio.h>
+
+#ifdef FALLBACK_CURSES
+#include <pinentry-curses.h>
+#endif
+
+/* Hack for creating a QWidget with a "foreign" window ID */
+class ForeignWidget : public QWidget
+{
+public:
+  ForeignWidget( WId wid ) : QWidget( 0 )
+  {
+    QWidget::destroy();
+    create( wid, false, false );
+  }
+ 
+  ~ForeignWidget()
+  {
+    destroy( false, false );
+  }
+};
+
+static int
+qt_cmd_handler (pinentry_t pe)
+{
+  QWidget *parent = 0;
+
+  int want_pass = !!pe->pin;
+
+  if (want_pass)
+    {
+      /* FIXME: Add parent window ID to pinentry and GTK.  */
+      if (pe->parent_wid)
+	parent = new ForeignWidget (pe->parent_wid);
+
+      PinEntryDialog pinentry (parent, 0, true);
+
+      pinentry.setPrompt (QString::fromUtf8 (pe->prompt));
+      pinentry.setDescription (QString::fromUtf8 (pe->description));
+      /* If we reuse the same dialog window.  */
+#if 0
+      pinentry.setText (SecQString::null);
+#endif
+
+      if (pe->ok)
+	pinentry.setOkText (QString::fromUtf8 (pe->ok));
+      if (pe->cancel)
+	pinentry.setCancelText (QString::fromUtf8 (pe->cancel));
+      if (pe->error)
+	pinentry.setError (QString::fromUtf8 (pe->error));
+
+      bool ret = pinentry.exec ();
+      if (!ret)
+	return -1;
+
+      QByteArray pinUtf8 = pinentry.text().toUtf8();
+      char *pin = pinUtf8.data();
+      if (!pin)
+	return -1;
+
+      int len = strlen (pin);
+      if (len >= 0)
+	{
+	  pinentry_setbufferlen (pe, len + 1);
+	  if (pe->pin)
+	    {
+	      strcpy (pe->pin, pin);
+	      // ::secmem_free (pin);
+	      return len;
+	    }
+	}
+      // ::secmem_free (pin);
+      return -1;
+    }
+  else
+    {
+      bool ret = QMessageBox::information (parent, "", pe->description,
+					   pe->ok ? pe->ok : "OK",
+					   pe->cancel ? pe->cancel : "Cancel");
+      return !ret;
+    }
+}
+
+pinentry_cmd_handler_t pinentry_cmd_handler = qt_cmd_handler;
+
+int 
+main (int argc, char *argv[])
+{
+  pinentry_init ("pinentry-qt4");
+
+#ifdef FALLBACK_CURSES
+  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-qt4: 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] = "-display";
+            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;
+      new QApplication (i, new_argv);
+    }
+  
+
+  /* Consumes all arguments.  */
+  if (pinentry_parse_opts (argc, argv))
+    {
+      printf ("pinentry-qt4 (pinentry) " /* VERSION */ "\n");
+      exit (EXIT_SUCCESS);
+    }
+
+  if (pinentry_loop ())
+    return 1;
+
+  return 0;
+}

Added: trunk/qt4/pinentrydialog.cpp
===================================================================
--- trunk/qt4/pinentrydialog.cpp	2008-07-23 11:48:00 UTC (rev 184)
+++ trunk/qt4/pinentrydialog.cpp	2008-07-24 14:49:21 UTC (rev 185)
@@ -0,0 +1,178 @@
+/* 
+   pinentrydialog.cpp - A (not yet) secure Qt 4 dialog for PIN entry.
+
+   Copyright (C) 2002 Klarälvdalens Datakonsult AB
+   Copyright 2007 Ingo Klöcker
+
+   Written by Steffen Hansen <steffen at klaralvdalens-datakonsult.se>.
+   
+   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, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QPushButton>
+#include <QKeyEvent>
+#include <QLabel>
+#include <QMessageBox>
+
+#ifdef WITH_SECURE_QSTRING
+#include "secqlineedit.h"
+#else
+#include <QLineEdit>
+#endif
+
+#include "pinentrydialog.h"
+
+PinEntryDialog::PinEntryDialog( QWidget* parent, const char* name, bool modal )
+  : QDialog( parent ), _grabbed( false )
+{
+  if ( modal ) {
+    setWindowModality( Qt::ApplicationModal );
+  }
+
+  QBoxLayout* top = new QVBoxLayout( this );
+  top->setMargin( 6 );
+  QBoxLayout* upperLayout = new QHBoxLayout();
+  top->addLayout( upperLayout );
+
+  _icon = new QLabel( this );
+  _icon->setPixmap( QMessageBox::standardIcon( QMessageBox::Information ) );
+  upperLayout->addWidget( _icon );
+
+  QBoxLayout* labelLayout = new QVBoxLayout();
+  upperLayout->addLayout( labelLayout );
+
+  _error = new QLabel( this );
+  labelLayout->addWidget( _error );
+
+  _desc = new QLabel( this );
+  labelLayout->addWidget( _desc );
+
+  QBoxLayout* l = new QHBoxLayout();
+  top->addLayout( l );
+  _prompt = new QLabel( this );
+  l->addWidget( _prompt );
+  _edit = new SecQLineEdit( this );
+  _edit->setMaxLength( 256 );
+  _edit->setEchoMode( SecQLineEdit::Password );
+  l->addWidget( _edit );
+
+  l = new QHBoxLayout();
+  top->addLayout( l );  
+
+  _ok = new QPushButton( tr("OK"), this );
+  _cancel = new QPushButton( tr("Cancel"), this );
+
+  l->addWidget( _ok );
+  l->addStretch();
+  l->addWidget( _cancel );
+
+  _ok->setDefault(true);
+
+  connect( _ok, SIGNAL( clicked() ),
+	   this, SIGNAL( accepted() ) );
+  connect( _cancel, SIGNAL( clicked() ),
+	   this, SIGNAL( rejected() ) );
+
+  connect (this, SIGNAL (accepted ()),
+	   this, SLOT (accept ()));
+  connect (this, SIGNAL (rejected ()),
+	   this, SLOT (reject ()));
+
+  _edit->setFocus();
+}
+
+void PinEntryDialog::paintEvent( QPaintEvent* ev )
+{
+  // Grab keyboard when widget is mapped to screen
+  // It might be a little weird to do it here, but it works!
+  if( !_grabbed ) {
+    _edit->grabKeyboard();
+    _grabbed = true;
+  }
+  QDialog::paintEvent( ev );
+}
+
+void PinEntryDialog::hideEvent( QHideEvent* ev )
+{
+  _edit->releaseKeyboard();
+  _grabbed = false;
+  QDialog::hideEvent( ev );
+}
+




More information about the Gnupg-commits mailing list