[svn] pinentry - r195 - in trunk: . qt4
svn author marcus
cvs at cvs.gnupg.org
Fri Apr 3 17:10:22 CEST 2009
Author: marcus
Date: 2009-04-03 17:10:22 +0200 (Fri, 03 Apr 2009)
New Revision: 195
Modified:
trunk/ChangeLog
trunk/qt4/main.cpp
trunk/qt4/pinentrydialog.cpp
trunk/qt4/pinentrydialog.h
trunk/qt4/pinentrydialog.moc
trunk/qt4/qsecurelineedit.cpp
trunk/qt4/qsecurelineedit.moc
Log:
2009-04-02 Till Adam <till at kdab.net>
* qt4/qsecurelineedit.moc, qt4/main.cpp, qt4/pinentrydialog.moc,
qt4/qsecurelineedit.cpp, qt4/pinentrydialog.cpp,
qt4/pinentrydialog.h: Implement quality bar and grabbing.
* qt4/pinentrydialog.cpp (PinEntryDialog): Enable word wrapping.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-04-03 15:05:37 UTC (rev 194)
+++ trunk/ChangeLog 2009-04-03 15:10:22 UTC (rev 195)
@@ -1,3 +1,11 @@
+2009-04-02 Till Adam <till at kdab.net>
+
+ * qt4/qsecurelineedit.moc, qt4/main.cpp, qt4/pinentrydialog.moc,
+ qt4/qsecurelineedit.cpp, qt4/pinentrydialog.cpp,
+ qt4/pinentrydialog.h: Implement quality bar and grabbing.
+
+ * qt4/pinentrydialog.cpp (PinEntryDialog): Enable word wrapping.
+
2009-04-03 Marcus Brinkmann <marcus at g10code.de>
* qt4/main.cpp (qt_cmd_handler): Cast window handle ID.
Modified: trunk/qt4/main.cpp
===================================================================
--- trunk/qt4/main.cpp 2009-04-03 15:05:37 UTC (rev 194)
+++ trunk/qt4/main.cpp 2009-04-03 15:10:22 UTC (rev 195)
@@ -1,4 +1,4 @@
-/*
+/*
main.cpp - A (not yet) secure Qt 4 dialog for PIN entry.
Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
@@ -8,17 +8,17 @@
Written by Steffen Hansen <steffen at klaralvdalens-datakonsult.se>.
Modified by Marcus Brinkmann <marcus at g10code.de>.
Modified by Marc Mutz <marc at kdab.com>
-
+
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.
@@ -50,7 +50,7 @@
QWidget::destroy();
create( wid, false, false );
}
-
+
~ForeignWidget()
{
destroy( false, false );
@@ -70,8 +70,9 @@
if (pe->parent_wid)
parent = new ForeignWidget ((HWND) pe->parent_wid);
- PinEntryDialog pinentry (parent, 0, true);
+ PinEntryDialog pinentry (parent, 0, true, !!pe->quality_bar);
+ pinentry.setPinentryInfo (pe);
pinentry.setPrompt (QString::fromUtf8 (pe->prompt));
pinentry.setDescription (QString::fromUtf8 (pe->description));
/* If we reuse the same dialog window. */
@@ -83,6 +84,10 @@
pinentry.setCancelText (QString::fromUtf8 (pe->cancel));
if (pe->error)
pinentry.setError (QString::fromUtf8 (pe->error));
+ if (pe->quality_bar)
+ pinentry.setQualityBar (QString::fromUtf8 (pe->quality_bar));
+ if (pe->quality_bar_tt)
+ pinentry.setQualityBarTT (QString::fromUtf8 (pe->quality_bar_tt));
bool ret = pinentry.exec ();
if (!ret)
@@ -111,16 +116,16 @@
QString ok = QString::fromUtf8 (pe->ok ? pe->ok : "OK");
QString can = QString::fromUtf8 (pe->cancel ? pe->cancel : "Cancel");
bool ret;
-
+
ret = QMessageBox::information (parent, "", desc, ok, can );
-
+
return !ret;
}
}
pinentry_cmd_handler_t pinentry_cmd_handler = qt_cmd_handler;
-int
+int
main (int argc, char *argv[])
{
pinentry_init ("pinentry-qt4");
@@ -149,7 +154,7 @@
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"))
@@ -168,8 +173,8 @@
i = argc;
new QApplication (i, new_argv);
}
-
+
/* Consumes all arguments. */
if (pinentry_parse_opts (argc, argv))
{
Modified: trunk/qt4/pinentrydialog.cpp
===================================================================
--- trunk/qt4/pinentrydialog.cpp 2009-04-03 15:05:37 UTC (rev 194)
+++ trunk/qt4/pinentrydialog.cpp 2009-04-03 15:10:22 UTC (rev 195)
@@ -1,27 +1,28 @@
-/*
+/*
pinentrydialog.cpp - A (not yet) secure Qt 4 dialog for PIN entry.
Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
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 "pinentrydialog.h"
+#include <QGridLayout>
#include "qsecurelineedit.h"
@@ -32,7 +33,8 @@
#include <QLabel>
#include <QMessageBox>
-PinEntryDialog::PinEntryDialog( QWidget* parent, const char* name, bool modal )
+PinEntryDialog::PinEntryDialog( QWidget* parent, const char* name, bool modal,
+ bool enable_quality_bar )
: QDialog( parent ), _grabbed( false )
{
if ( modal ) {
@@ -52,22 +54,38 @@
upperLayout->addLayout( labelLayout );
_error = new QLabel( this );
+ _error->setWordWrap(true);
labelLayout->addWidget( _error );
_desc = new QLabel( this );
+ _desc->setWordWrap(true);
labelLayout->addWidget( _desc );
- QBoxLayout* l = new QHBoxLayout();
- top->addLayout( l );
+ QGridLayout* grid = new QGridLayout;
+ top->addLayout( grid );
+
_prompt = new QLabel( this );
- l->addWidget( _prompt );
+ grid->addWidget( _prompt, 0, 0 );
_edit = new QSecureLineEdit( this );
_edit->setMaxLength( 256 );
- l->addWidget( _edit );
+ grid->addWidget( _edit, 0, 1 );
- l = new QHBoxLayout();
- top->addLayout( l );
+ 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 );
+
_ok = new QPushButton( tr("OK"), this );
_cancel = new QPushButton( tr("Cancel"), this );
@@ -81,7 +99,8 @@
this, SIGNAL( accepted() ) );
connect( _cancel, SIGNAL( clicked() ),
this, SIGNAL( rejected() ) );
-
+ connect( _edit, SIGNAL( textChanged(secqstring) ),
+ this, SLOT( updateQuality(secqstring) ) );
connect (this, SIGNAL (accepted ()),
this, SLOT (accept ()));
connect (this, SIGNAL (rejected ()),
@@ -90,25 +109,15 @@
_edit->setFocus();
}
-void PinEntryDialog::showEvent( QShowEvent* ev )
-{
- // Grab keyboard when widget is mapped to screen
- // It might be a little weird to do it here, but it works!
- QDialog::showEvent( ev );
- if( !_grabbed ) {
- _edit->grabKeyboard();
- _grabbed = true;
- }
-}
-
void PinEntryDialog::hideEvent( QHideEvent* ev )
{
- _edit->releaseKeyboard();
+ if ( !_pinentry_info || _pinentry_info->grab )
+ _edit->releaseKeyboard();
_grabbed = false;
QDialog::hideEvent( ev );
}
-void PinEntryDialog::keyPressEvent( QKeyEvent* e )
+void PinEntryDialog::keyPressEvent( QKeyEvent* e )
{
if ( e->modifiers() == Qt::NoModifier && e->key() == Qt::Key_Escape ) {
emit rejected();
@@ -117,45 +126,45 @@
QDialog::keyPressEvent( e );
}
-void PinEntryDialog::setDescription( const QString& txt )
+void PinEntryDialog::setDescription( const QString& txt )
{
_desc->setText( txt );
_icon->setPixmap( QMessageBox::standardIcon( QMessageBox::Information ) );
setError( QString::null );
}
-QString PinEntryDialog::description() const
+QString PinEntryDialog::description() const
{
return _desc->text();
}
-void PinEntryDialog::setError( const QString& txt )
+void PinEntryDialog::setError( const QString& txt )
{
if( !txt.isNull() )_icon->setPixmap( QMessageBox::standardIcon( QMessageBox::Critical ) );
_error->setText( txt );
}
-QString PinEntryDialog::error() const
+QString PinEntryDialog::error() const
{
return _error->text();
}
-void PinEntryDialog::setPin( const secqstring & txt )
+void PinEntryDialog::setPin( const secqstring & txt )
{
_edit->setText( txt );
}
-secqstring PinEntryDialog::pin() const
+secqstring PinEntryDialog::pin() const
{
return _edit->text();
}
-void PinEntryDialog::setPrompt( const QString& txt )
+void PinEntryDialog::setPrompt( const QString& txt )
{
_prompt->setText( txt );
}
-QString PinEntryDialog::prompt() const
+QString PinEntryDialog::prompt() const
{
return _prompt->text();
}
@@ -170,4 +179,68 @@
_cancel->setText( txt );
}
+void PinEntryDialog::setQualityBar( const QString& txt )
+{
+ if (_have_quality_bar)
+ _quality_bar_label->setText( txt );
+}
+
+void PinEntryDialog::setQualityBarTT( const QString& txt )
+{
+ if (_have_quality_bar)
+ _quality_bar->setToolTip( txt );
+}
+
+void PinEntryDialog::updateQuality(const secqstring & txt )
+{
+ int length;
+ int percent;
+ QPalette pal;
+
+ if (!_have_quality_bar || !_pinentry_info)
+ return;
+ secstring pinStr = toUtf8(txt);
+ const char* pin = pinStr.c_str();
+ // The Qt3 version called ::secmem_free (pin) here, but from other usage of secstring,
+ // it seems like this is not needed anymore - 16 Mar. 2009 13:15 -- Jesper K. Pedersen
+ 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);
+ }
+}
+
+void PinEntryDialog::setPinentryInfo(pinentry_t peinfo)
+{
+ _pinentry_info = peinfo;
+}
+
+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;
+ }
+
+}
+
#include "pinentrydialog.moc"
Modified: trunk/qt4/pinentrydialog.h
===================================================================
--- trunk/qt4/pinentrydialog.h 2009-04-03 15:05:37 UTC (rev 194)
+++ trunk/qt4/pinentrydialog.h 2009-04-03 15:10:22 UTC (rev 195)
@@ -1,21 +1,21 @@
-/*
+/*
pinentrydialog.h - A (not yet) secure Qt 4 dialog for PIN entry.
Copyright (C) 2002, 2008 Klarälvdalens Datakonsult AB (KDAB)
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.
@@ -24,9 +24,11 @@
#ifndef __PINENTRYDIALOG_H__
#define __PINENTRYDIALOG_H__
+#include <QProgressBar>
#include <QDialog>
#include "secstring.h"
+#include "pinentry.h"
class QLabel;
class QPushButton;
@@ -44,7 +46,7 @@
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, bool modal = false );
+ explicit PinEntryDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, bool enable_quality_bar = false );
void setDescription( const QString& );
QString description() const;
@@ -57,10 +59,18 @@
void setPrompt( const QString& );
QString prompt() const;
-
+
void setOkText( const QString& );
void setCancelText( const QString& );
+ void setQualityBar( const QString& );
+ void setQualityBarTT( const QString& );
+
+ void setPinentryInfo (pinentry_t);
+
+public slots:
+ void updateQuality(const secqstring&);
+
signals:
void accepted();
void rejected();
@@ -68,17 +78,21 @@
protected:
/* reimp */ void keyPressEvent( QKeyEvent *e );
/* reimp */ void hideEvent( QHideEvent* );
- /* reimp */ void showEvent( QShowEvent* );
+ /* reimp */ void paintEvent( QPaintEvent* event );
private:
QLabel* _icon;
QLabel* _desc;
QLabel* _error;
QLabel* _prompt;
+ QLabel* _quality_bar_label;
+ QProgressBar* _quality_bar;
QSecureLineEdit* _edit;
QPushButton* _ok;
- QPushButton* _cancel;
+ QPushButton* _cancel;
bool _grabbed;
+ bool _have_quality_bar;
+ pinentry_t _pinentry_info;
};
#endif // __PINENTRYDIALOG_H__
Modified: trunk/qt4/pinentrydialog.moc
===================================================================
--- trunk/qt4/pinentrydialog.moc 2009-04-03 15:05:37 UTC (rev 194)
+++ trunk/qt4/pinentrydialog.moc 2009-04-03 15:10:22 UTC (rev 195)
@@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'pinentrydialog.h'
**
-** Created: Mon Oct 20 09:30:12 2008
+** Created: Mon Mar 16 13:03:03 2009
** by: The Qt Meta Object Compiler version 59 (Qt 4.4.1)
**
** WARNING! All changes made in this file will be lost!
@@ -23,27 +23,31 @@
1, // revision
0, // classname
0, 0, // classinfo
- 2, 10, // methods
- 4, 20, // properties
+ 3, 10, // methods
+ 4, 25, // properties
0, 0, // enums/sets
// signals: signature, parameters, type, tag, flags
16, 15, 15, 15, 0x05,
27, 15, 15, 15, 0x05,
+ // slots: signature, parameters, type, tag, flags
+ 38, 15, 15, 15, 0x0a,
+
// properties: name, type, flags
- 46, 38, 0x0a095103,
- 58, 38, 0x0a095103,
- 75, 64, 0x0009510b,
- 79, 38, 0x0a095103,
+ 72, 64, 0x0a095103,
+ 84, 64, 0x0a095103,
+ 101, 90, 0x0009510b,
+ 105, 64, 0x0a095103,
0 // eod
};
static const char qt_meta_stringdata_PinEntryDialog[] = {
"PinEntryDialog\0\0accepted()\0rejected()\0"
- "QString\0description\0error\0secqstring\0"
- "pin\0prompt\0"
+ "updateQuality(secqstring)\0QString\0"
+ "description\0error\0secqstring\0pin\0"
+ "prompt\0"
};
const QMetaObject PinEntryDialog::staticMetaObject = {
@@ -73,8 +77,9 @@
switch (_id) {
case 0: accepted(); break;
case 1: rejected(); break;
+ case 2: updateQuality((*reinterpret_cast< const secqstring(*)>(_a[1]))); break;
}
- _id -= 2;
+ _id -= 3;
}
#ifndef QT_NO_PROPERTIES
else if (_c == QMetaObject::ReadProperty) {
Modified: trunk/qt4/qsecurelineedit.cpp
===================================================================
--- trunk/qt4/qsecurelineedit.cpp 2009-04-03 15:05:37 UTC (rev 194)
+++ trunk/qt4/qsecurelineedit.cpp 2009-04-03 15:10:22 UTC (rev 195)
@@ -1,20 +1,20 @@
-/*
+/*
qsecurelineedit.cpp - QLineEdit that uses secmem
Copyright (C) 2008 Klarälvdalens Datakonsult AB (KDAB)
Written by Marc Mutz <marc at kdab.com>.
-
+
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.
@@ -2165,7 +2165,7 @@
// Focus in if currently in navigation focus on the widget
// Only focus in on preedits, to allow input methods to
// commit text as they focus out without interfering with focus
- if (QApplication::keypadNavigationEnabled() &&
+ if (QApplication::keypadNavigationEnabled() &&
hasFocus() && !hasEditFocus()
&& !e->preeditString().isEmpty()) {
setEditFocus(true);
Modified: trunk/qt4/qsecurelineedit.moc
===================================================================
--- trunk/qt4/qsecurelineedit.moc 2009-04-03 15:05:37 UTC (rev 194)
+++ trunk/qt4/qsecurelineedit.moc 2009-04-03 15:10:22 UTC (rev 195)
@@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'qsecurelineedit.h'
**
-** Created: Mon Oct 20 09:29:54 2008
+** Created: Mon Mar 16 13:03:26 2009
** by: The Qt Meta Object Compiler version 59 (Qt 4.4.1)
**
** WARNING! All changes made in this file will be lost!
More information about the Gnupg-commits
mailing list