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

svn author wk cvs at cvs.gnupg.org
Tue Feb 16 19:58:19 CET 2010


Author: wk
Date: 2010-02-16 19:58:19 +0100 (Tue, 16 Feb 2010)
New Revision: 214

Added:
   trunk/qt4/document-encrypt.png
   trunk/qt4/gtk-cancel.png
   trunk/qt4/gtk-ok.png
Modified:
   trunk/ChangeLog
   trunk/qt4/main.cpp
   trunk/qt4/pinentrydialog.cpp
   trunk/qt4/pinentrydialog.h
   trunk/qt4/pinentrydialog.moc
Log:
Applied patches to the qt4 versions.
Note: It does not build.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-12-16 17:21:59 UTC (rev 213)
+++ trunk/ChangeLog	2010-02-16 18:58:19 UTC (rev 214)
@@ -1,3 +1,77 @@
+2010-02-16  Werner Koch  <wk at g10code.com>
+
+	* qt4/document-encrypt.png, qt4/gtk-cancel.png, qt4/gtk-ok.png: New.
+	* qt4/Makefile.am (EXTRA_DIST): Add them.
+
+2010-02-15  Christoph Schleifenbaum <christoph at kdab.com>  (wk)
+
+	Also attributed to Marc Mutz <marc at kdab.com>.
+
+	* qt4/main.cpp, qt/pinentrydialog.cpp: If the style says so,
+	set (GTK) icons on OK and Cancel buttons.
+
+2010-02-15  Christoph Schleifenbaum <christoph at kdab.com>  (wk)
+
+	* qt4/main.cpp: Use an explicit QMessageBox instead of the
+	'information' convenience method.  We do this for two reasons:
+	1. So we can set our own icon (icon()).  2. So we can call our
+	raiseWindow() function on it.
+
+2010-02-15  Christoph Schleifenbaum <christoph at kdab.com>
+
+	* qt4/main.cpp: Use title. Use Qt translation of "OK" and "Cancel"
+
+	* qt4/pinentrydialog.cpp: Don't show the question-mark icon in the
+	window title.
+
+2010-02-15  Christoph Schleifenbaum <christoph at kdab.com>  (wk)
+
+	* qt4/pinentrydialog.h, qt4/pinentrydialog.cpp: Use the
+	document-encrypt icon instead of the
+	QMessageBox::{Information,Critical} ones.
+
+2010-02-15  Christoph Schleifenbaum <christoph at kdab.com>  (wk)
+
+	Also attributed to Marc Mutz <marc at kdab.com>.
+
+	* qt4/pinentrydialog.cpp: Properly show/hide optional widgets.
+
+2010-02-15  Christoph Schleifenbaum <christoph at kdab.com>
+
+	* qt4/pinentrydialog.cpp: Set text color or error label to red.
+
+2010-02-15  Christoph Schleifenbaum <christoph at kdab.com>  (wk)
+
+	Also attributed to Marc Mutz <marc at kdab.com>.
+
+	* qt4/pinentrydialog.cpp: Gather scattered layouting code, use a
+	single gridlayout for all, and use QDialogButtonBox.
+
+2010-02-15  Christoph Schleifenbaum <christoph at kdab.com>  (wk)
+
+	* qt4/pinentrydialog.cpp: Call SetForegroundWindow on showEvent()
+	and set a fixed size on the dialog.
+
+	* qt4/main.cpp: Set document-encrypt as the window icon.
+
+2010-02-15  Marc Mutz <marc at kdab.com>  (wk)
+
+	* qt4/main.cpp: Load the correct Qt translation file based on
+	either lc_messages or the current locale.
+
+	* qt4/main.cpp: Use pinentry_t->parent_wid also for message-box
+	case.
+
+	* qt4/main.cpp: Properly delete the QApplication.
+
+2010-02-15  Christoph Schleifenbaum <christoph at kdab.com>  (wk)
+
+	* qt4/main.cpp: Remove guard clause with impossible condition.
+
+	* qt4/main.cpp: Respect pinentry_t->title.
+
+	* qt4/main.cpp: Include config.h.
+
 2009-12-16  Marcus Brinkmann  <marcus at g10code.de>
 
 	* gtk+-2/gtksecentry.c: Don't translate properties.

Added: trunk/qt4/document-encrypt.png
===================================================================
(Binary files differ)


Property changes on: trunk/qt4/document-encrypt.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/qt4/gtk-cancel.png
===================================================================
(Binary files differ)


Property changes on: trunk/qt4/gtk-cancel.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/qt4/gtk-ok.png
===================================================================
(Binary files differ)


Property changes on: trunk/qt4/gtk-ok.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: trunk/qt4/main.cpp
===================================================================
--- trunk/qt4/main.cpp	2009-12-16 17:21:59 UTC (rev 213)
+++ trunk/qt4/main.cpp	2010-02-16 18:58:19 UTC (rev 214)
@@ -24,19 +24,29 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
 #include "pinentrydialog.h"
 #include "pinentry.h"
 
 #include <qapplication.h>
+#include <QIcon>
 #include <QString>
 #include <qwidget.h>
 #include <qmessagebox.h>
+#include <QLocale>
+#include <QTranslator>
+#include <QDialogButtonBox>
+#include <QPushButton>
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
 
+#include <memory>
+
 #ifdef FALLBACK_CURSES
 #include <pinentry-curses.h>
 #endif
@@ -62,19 +72,27 @@
 {
   QWidget *parent = 0;
 
+  QTranslator trans;
+  const QString lang = pe->lc_messages ? QString::fromLatin1 (pe->lc_messages) : QLocale ().name () ;
+  if( trans.load (QString::fromLatin1(":/qt_%1").arg(lang)) )
+    qApp->installTranslator (&trans);
+
+  /* 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;
 
   if (want_pass)
     {
-      /* FIXME: Add parent window ID to pinentry and GTK.  */
-      if (pe->parent_wid)
-	parent = new ForeignWidget ((WId) pe->parent_wid);
-
       PinEntryDialog pinentry (parent, 0, true, !!pe->quality_bar);
 
       pinentry.setPinentryInfo (pe);
       pinentry.setPrompt (QString::fromUtf8 (pe->prompt));
       pinentry.setDescription (QString::fromUtf8 (pe->description));
+      if ( pe->title )
+          pinentry.setWindowTitle( QString::fromUtf8( pe->title ) );
+
       /* If we reuse the same dialog window.  */
       pinentry.setPin (secqstring());
 
@@ -95,8 +113,6 @@
 
       const secstring pinUtf8 = toUtf8( pinentry.pin() );
       const char *pin = pinUtf8.data();
-      if (!pin)
-	return -1;
 
       int len = strlen (pin);
       if (len >= 0)
@@ -112,14 +128,48 @@
     }
   else
     {
-      QString desc = QString::fromUtf8 (pe->description? pe->description :"");
-      QString ok   = QString::fromUtf8 (pe->ok ? pe->ok : "OK");
-      QString can  = QString::fromUtf8 (pe->cancel ? pe->cancel : "Cancel");
-      bool ret;
+      const QString title = pe->title       ? QString::fromUtf8 ( pe->title )       : QString();
+      const QString desc  = pe->description ? QString::fromUtf8 ( pe->description ) : QString();
+      const QString ok    = pe->ok          ? QString::fromUtf8 ( pe->ok )          : QDialogButtonBox::tr( "&OK" );
+      const QString can   = pe->cancel      ? QString::fromUtf8 ( pe->cancel )      : QDialogButtonBox::tr( "Cancel" );
 
-      ret = QMessageBox::information (parent, "", desc, ok, can );
+      QMessageBox box( parent );
 
-      return !ret;
+      if ( !title.isEmpty() )
+        box.setWindowTitle( title );
+
+      if ( !ok.isEmpty() )
+          if ( !can.isEmpty() )
+              box.setStandardButtons( QMessageBox::Ok|QMessageBox::Cancel );
+          else
+              box.setStandardButtons( QMessageBox::Ok );
+      else
+          if ( !can.isEmpty() )
+              box.setStandardButtons( QMessageBox::Cancel );
+          else
+              box.setStandardButtons( QMessageBox::NoButton );
+
+      if ( !ok.isEmpty() )
+        {
+          box.button( QMessageBox::Ok )->setText( ok );
+          if ( box.style()->styleHint( QStyle::SH_DialogButtonBox_ButtonsHaveIcons ) )
+            box.button( QMessageBox::Ok )->setIcon( QIcon( QLatin1String( ":/gtk-ok.png" ) ) );
+        }
+
+      if ( !can.isEmpty() )
+        {
+          box.button( QMessageBox::Cancel )->setText( can );
+          if ( box.style()->styleHint( QStyle::SH_DialogButtonBox_ButtonsHaveIcons ) )
+            box.button( QMessageBox::Cancel )->setIcon( QIcon( QLatin1String( ":/gtk-cancel.png" ) ) );
+        }
+
+      box.setText( desc );
+      box.setIconPixmap( icon() );
+
+      box.show();
+      raiseWindow( &box );
+
+      return box.exec() == QMessageBox::Ok ;
     }
 }
 
@@ -130,6 +180,8 @@
 {
   pinentry_init ("pinentry-qt4");
 
+  std::auto_ptr<QApplication> app;
+
 #ifdef FALLBACK_CURSES
   if (!pinentry_have_display (argc, argv))
     pinentry_cmd_handler = curses_cmd_handler;
@@ -171,7 +223,9 @@
       /* We use a modal dialog window, so we don't need the application
          window anymore.  */
       i = argc;
-      new QApplication (i, new_argv);
+      app.reset (new QApplication (i, new_argv));
+      const QIcon icon( QLatin1String( ":/document-encrypt.png" ) );
+      app->setWindowIcon( icon );
     }
 
 
@@ -179,11 +233,11 @@
   if (pinentry_parse_opts (argc, argv))
     {
       printf ("pinentry-qt4 (pinentry) " /* VERSION */ "\n");
-      exit (EXIT_SUCCESS);
+      return EXIT_SUCCESS;
     }
+  else
+    {
+      return pinentry_loop () ? EXIT_FAILURE : EXIT_SUCCESS ;
+    }
 
-  if (pinentry_loop ())
-    return 1;
-
-  return 0;
 }

Modified: trunk/qt4/pinentrydialog.cpp
===================================================================
--- trunk/qt4/pinentrydialog.cpp	2009-12-16 17:21:59 UTC (rev 213)
+++ trunk/qt4/pinentrydialog.cpp	2010-02-16 18:58:19 UTC (rev 214)
@@ -26,75 +26,118 @@
 
 #include "qsecurelineedit.h"
 
+#include <QApplication>
+#include <QStyle>
+#include <QPainter>
 #include <QVBoxLayout>
 #include <QHBoxLayout>
 #include <QPushButton>
+#include <QDialogButtonBox>
 #include <QKeyEvent>
 #include <QLabel>
 #include <QMessageBox>
+#include <QTextDocument>
+#include <QPalette>
 
+#ifdef Q_WS_WIN
+#include <windows.h>
+#endif
+
+#ifdef Q_WS_WIN
+void SetForegroundWindowEx( HWND hWnd )
+{
+   //Attach foreground window thread to our thread
+   const DWORD ForeGroundID = GetWindowThreadProcessId(::GetForegroundWindow(),NULL);
+   const DWORD CurrentID   = GetCurrentThreadId();
+ 
+   AttachThreadInput ( ForeGroundID, CurrentID, TRUE );
+   //Do our stuff here
+   HWND hLastActivePopupWnd = GetLastActivePopup( hWnd );
+   SetForegroundWindow( hLastActivePopupWnd );
+ 
+   //Detach the attached thread
+   AttachThreadInput ( ForeGroundID, CurrentID, FALSE );
+}// End SetForegroundWindowEx
+#endif
+
+void raiseWindow( QWidget* w )
+{
+#ifdef Q_WS_WIN
+    SetForegroundWindowEx( w->winId() );
+#endif
+    w->raise();
+    w->activateWindow();
+}
+
+QPixmap icon( QStyle::StandardPixmap which )
+{
+    QPixmap pm = qApp->windowIcon().pixmap( 48, 48 );
+   
+    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 ) );
+    }
+
+    return pm;
+}
+
 PinEntryDialog::PinEntryDialog( QWidget* parent, const char* name, bool modal,
                                 bool enable_quality_bar )
   : QDialog( parent ), _grabbed( false )
 {
+  setWindowFlags( windowFlags() & ~Qt::WindowContextHelpButtonHint );
+
   if ( modal ) {
     setWindowModality( Qt::ApplicationModal );
   }
 
-  QBoxLayout* top = new QVBoxLayout( this );
-  top->setMargin( 6 );
-  QBoxLayout* upperLayout = new QHBoxLayout();
-  top->addLayout( upperLayout, 1 );
-
   _icon = new QLabel( this );
-  _icon->setPixmap( QMessageBox::standardIcon( QMessageBox::Information ) );
-  upperLayout->addWidget( _icon );
+  _icon->setPixmap( icon() );
 
-  QBoxLayout* labelLayout = new QVBoxLayout();
-  upperLayout->addLayout( labelLayout, 5 );
-
   _error = new QLabel( this );
   _error->setWordWrap(true);
-  labelLayout->addWidget( _error, 1 );
+  QPalette pal;
+  pal.setColor( QPalette::WindowText, Qt::red );
+  _error->setPalette( pal );
+  _error->hide();
 
   _desc = new QLabel( this );
   _desc->setWordWrap(true);
-  labelLayout->addWidget( _desc, 5 );
+  _desc->hide();
 
-  QGridLayout* grid = new QGridLayout;
-  top->addLayout( grid );
+  _prompt = new QLabel( this );
+  _prompt->hide();
 
-  _prompt = new QLabel( this );
-  grid->addWidget( _prompt, 0, 0 );
   _edit = new QSecureLineEdit( this );
   _edit->setMaxLength( 256 );
-  grid->addWidget( _edit, 0, 1 );
 
   if (enable_quality_bar)
   {
     _quality_bar_label = new QLabel( this );
     _quality_bar_label->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
-    grid->addWidget ( _quality_bar_label, 1, 0 );
     _quality_bar = new QProgressBar( this );
     _quality_bar->setAlignment( Qt::AlignCenter );
-    grid->addWidget( _quality_bar, 1, 1 );
     _have_quality_bar = true;
   }
   else
     _have_quality_bar = false;
 
-  QBoxLayout* l = new QHBoxLayout();
-  top->addLayout( l );
+  QDialogButtonBox* const buttons = new QDialogButtonBox( this );
+  buttons->setStandardButtons( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
+  _ok = buttons->button( QDialogButtonBox::Ok );
+  _cancel = buttons->button( QDialogButtonBox::Cancel );
 
-  _ok = new QPushButton( tr("OK"), this );
-  _cancel = new QPushButton( tr("Cancel"), this );
-
-  l->addWidget( _ok );
-  l->addStretch();
-  l->addWidget( _cancel );
-
   _ok->setDefault(true);
 
+  if ( style()->styleHint( QStyle::SH_DialogButtonBox_ButtonsHaveIcons ) )
+    {
+      _ok->setIcon( QIcon( QLatin1String( ":/gtk-ok.png" ) ) );
+      _cancel->setIcon( QIcon( QLatin1String( ":/gtk-cancel.png" ) ) );
+    }
+ 
   connect( _ok, SIGNAL( clicked() ),
 	   this, SIGNAL( accepted() ) );
   connect( _cancel, SIGNAL( clicked() ),
@@ -107,6 +150,25 @@
 	   this, SLOT (reject ()));
 
   _edit->setFocus();
+
+  QBoxLayout* const labels = new QVBoxLayout;
+  labels->addWidget( _error );
+  labels->addWidget( _desc );
+  labels->addItem( new QSpacerItem( 0, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ) );
+
+  QGridLayout* const grid = new QGridLayout( this );
+  grid->addWidget( _icon, 0, 0, 4, 1, Qt::AlignTop|Qt::AlignLeft );
+  grid->addLayout( labels, 0, 1, 1, 2 );
+  grid->addItem( new QSpacerItem( 0, _edit->height() / 10, QSizePolicy::Minimum, QSizePolicy::Fixed ), 1, 1 );
+  grid->addWidget( _prompt, 2, 1 );
+  grid->addWidget( _edit, 2, 2 );
+  if( enable_quality_bar )
+  {
+    grid->addWidget( _quality_bar_label, 3, 1 );
+    grid->addWidget( _quality_bar, 3, 2 );
+  }
+  grid->addWidget( buttons, 4, 0, 1, 3 );
+
   setMinimumWidth( 450 );
   resize( minimumSizeHint() );
 }
@@ -119,6 +181,27 @@
   QDialog::hideEvent( ev );
 }
 
+void PinEntryDialog::showEvent( QShowEvent* event )
+{
+    QDialog::showEvent( event );
+    QMetaObject::invokeMethod( this, "setFixedSize", Qt::QueuedConnection );
+}
+
+void PinEntryDialog::setFixedSize()
+{
+    QTextDocument doc;
+    doc.setDefaultFont( _desc->font() );
+    doc.setHtml( _desc->text() );
+    doc.setTextWidth( _desc->width() );
+    _desc->setFixedSize( doc.size().toSize() );
+   
+    layout()->activate();
+    setFixedHeight( minimumSizeHint().height() + 5 );
+    QDialog::setFixedSize( size() );
+    
+    raiseWindow( this );
+}
+
 void PinEntryDialog::keyPressEvent( QKeyEvent* e )
 {
   if ( e->modifiers() == Qt::NoModifier && e->key() == Qt::Key_Escape ) {
@@ -130,8 +213,9 @@
 
 void PinEntryDialog::setDescription( const QString& txt )
 {
+  _desc->setVisible( !txt.isEmpty() );
   _desc->setText( txt );
-  _icon->setPixmap( QMessageBox::standardIcon( QMessageBox::Information ) );
+  _icon->setPixmap( icon() );
   setError( QString::null );
 }
 
@@ -142,8 +226,9 @@
 
 void PinEntryDialog::setError( const QString& txt )
 {
-  if( !txt.isNull() )_icon->setPixmap( QMessageBox::standardIcon( QMessageBox::Critical ) );
+  if( !txt.isNull() )_icon->setPixmap( icon( QStyle::SP_MessageBoxCritical ) );
   _error->setText( txt );
+  _error->setVisible( !txt.isEmpty() );
 }
 
 QString PinEntryDialog::error() const
@@ -164,6 +249,7 @@
 void PinEntryDialog::setPrompt( const QString& txt )
 {
   _prompt->setText( txt );
+  _prompt->setVisible( !txt.isEmpty() );
 }
 
 QString PinEntryDialog::prompt() const
@@ -174,11 +260,13 @@
 void PinEntryDialog::setOkText( const QString& txt )
 {
   _ok->setText( txt );
+  _ok->setVisible( !txt.isEmpty() );
 }
 
 void PinEntryDialog::setCancelText( const QString& txt )
 {
   _cancel->setText( txt );
+  _cancel->setVisible( !txt.isEmpty() );
 }
 
 void PinEntryDialog::setQualityBar( const QString& txt )

Modified: trunk/qt4/pinentrydialog.h
===================================================================
--- trunk/qt4/pinentrydialog.h	2009-12-16 17:21:59 UTC (rev 213)
+++ trunk/qt4/pinentrydialog.h	2010-02-16 18:58:19 UTC (rev 214)
@@ -26,6 +26,7 @@
 
 #include <QProgressBar>
 #include <QDialog>
+#include <QStyle>
 
 #include "secstring.h"
 #include "pinentry.h"
@@ -35,7 +36,9 @@
 class QSecureLineEdit;
 class QString;
 
+QPixmap icon( QStyle::StandardPixmap which = QStyle::SP_CustomBase );
 
+void raiseWindow( QWidget* w );
 
 class PinEntryDialog : public QDialog {
   Q_OBJECT
@@ -76,10 +79,14 @@
   void rejected();
 
 protected:
+  /* reimp */ void showEvent( QShowEvent* event );
   /* reimp */ void keyPressEvent( QKeyEvent *e );
   /* reimp */ void hideEvent( QHideEvent* );
   /* reimp */ void paintEvent( QPaintEvent* event );
 
+private Q_SLOTS:
+  void setFixedSize();
+
 private:
   QLabel*    _icon;
   QLabel*    _desc;

Modified: trunk/qt4/pinentrydialog.moc
===================================================================
--- trunk/qt4/pinentrydialog.moc	2009-12-16 17:21:59 UTC (rev 213)
+++ trunk/qt4/pinentrydialog.moc	2010-02-16 18:58:19 UTC (rev 214)
@@ -23,8 +23,8 @@
        1,       // revision
        0,       // classname
        0,    0, // classinfo
-       3,   10, // methods
-       4,   25, // properties
+       4,   10, // methods
+       4,   30, // properties
        0,    0, // enums/sets
 
  // signals: signature, parameters, type, tag, flags
@@ -33,21 +33,22 @@
 
  // slots: signature, parameters, type, tag, flags
       38,   15,   15,   15, 0x0a,
+      64,   15,   15,   15, 0x08,
 
  // properties: name, type, flags
-      72,   64, 0x0a095103,
-      84,   64, 0x0a095103,
-     101,   90, 0x0009510b,
-     105,   64, 0x0a095103,
+      87,   79, 0x0a095103,
+      99,   79, 0x0a095103,
+     116,  105, 0x0009510b,
+     120,   79, 0x0a095103,
 
        0        // eod
 };
 
 static const char qt_meta_stringdata_PinEntryDialog[] = {
     "PinEntryDialog\0\0accepted()\0rejected()\0"
-    "updateQuality(secqstring)\0QString\0"
-    "description\0error\0secqstring\0pin\0"
-    "prompt\0"
+    "updateQuality(secqstring)\0setFixedSize()\0"
+    "QString\0description\0error\0secqstring\0"
+    "pin\0prompt\0"
 };
 
 const QMetaObject PinEntryDialog::staticMetaObject = {
@@ -78,8 +79,9 @@
         case 0: accepted(); break;
         case 1: rejected(); break;
         case 2: updateQuality((*reinterpret_cast< const secqstring(*)>(_a[1]))); break;
+        case 3: setFixedSize(); break;
         }
-        _id -= 3;
+        _id -= 4;
     }
 #ifndef QT_NO_PROPERTIES
       else if (_c == QMetaObject::ReadProperty) {




More information about the Gnupg-commits mailing list