[svn] pinentry - r171 - in trunk: . assuan doc gtk+-2 pinentry qt
svn author wk
cvs at cvs.gnupg.org
Mon Nov 19 13:37:03 CET 2007
Author: wk
Date: 2007-11-19 13:36:53 +0100 (Mon, 19 Nov 2007)
New Revision: 171
Modified:
trunk/ChangeLog
trunk/assuan/assuan-util.c
trunk/doc/pinentry.texi
trunk/gtk+-2/gtksecentry.c
trunk/gtk+-2/pinentry-gtk-2.c
trunk/pinentry/pinentry.c
trunk/pinentry/pinentry.h
trunk/qt/main.cpp
trunk/qt/pinentrydialog.cpp
trunk/qt/pinentrydialog.h
Log:
Applied batch from Bernhard Herzog.
Allow caller to set the toolip.
The QT versions still crashes - someone else might want to look into it. TIA.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-09-18 17:52:39 UTC (rev 170)
+++ trunk/ChangeLog 2007-11-19 12:36:53 UTC (rev 171)
@@ -1,3 +1,33 @@
+2007-11-19 Werner Koch <wk at g10code.com>
+
+ * gtk+-2/pinentry-gtk-2.c (create_window): Use again map-event and
+ unmap-event as this works on my setup far more reliable than
+ expose-event/no-expose-event.
+
+ * gtk+-2/gtksecentry.c (get_cursor_time): s/time/blinktime/ t
+ avoid shadowing warning.
+
+ * pinentry/pinentry.h (struct pinentry): Change QUALITY_BAR to a
+ char ptr.
+ (struct pinentry): Add QUALITY_BAR_TT.
+ * pinentry/pinentry.c (cmd_setqualitybar): Allow to set a label text.
+ (cmd_setqualitybar_tt): New.
+ * gtk+-2/pinentry-gtk-2.c (create_window): Take label and tooltip
+ from global.
+ * qt/pinentrydialog.h (setQualityBar, setQualityBarTT)
+ (_quality_bar_label): New.
+ * qt/pinentrydialog.cpp (setQualityBar, setQualityBarTT): New.
+ (PinEntryDialog): Remove setting of tooltip.
+ * qt/main.cpp (qt_cmd_handler): Propagate quality bar label and tootip.
+
+2007-11-19 Bernhard Herzog <bernhard.herzog at intevation.de> (wk)
+
+ * qt/pinentrydialog.cpp (PinEntryDialog): Move the quality bar
+ below the text entry and align them properly. Show a tooltip.
+ * gtk+-2/pinentry-gtk-2.c (create_window): Ditto. Don't let it
+ change its height.
+ (QUALITYBAR_EMPTY_TEXT): New.
+
2007-09-18 Werner Koch <wk at g10code.com>
* qt/secqlineedit.h (SecQLineEdit): New signal textModified.
Modified: trunk/assuan/assuan-util.c
===================================================================
--- trunk/assuan/assuan-util.c 2007-09-18 17:52:39 UTC (rev 170)
+++ trunk/assuan/assuan-util.c 2007-11-19 12:36:53 UTC (rev 171)
@@ -161,7 +161,7 @@
void
_assuan_log_sanitized_string (const char *string)
{
- const unsigned char *s = string;
+ const unsigned char *s = (const unsigned char*)string;
#ifdef HAVE_JNLIB_LOGGING
FILE *fp = log_get_stream ();
#else
Modified: trunk/doc/pinentry.texi
===================================================================
--- trunk/doc/pinentry.texi 2007-09-18 17:52:39 UTC (rev 170)
+++ trunk/doc/pinentry.texi 2007-11-19 12:36:53 UTC (rev 171)
@@ -288,6 +288,11 @@
S: OK
@end example
+If a custom laber for the auality bar is required, just add that label
+as an argument as precent escaped string. You will need this feature to
+translate the label because pinentry has no internal gettext except for
+stock strings from the toolkit library.
+
@item Ask for a PIN
The meat of this tool is to ask for a passphrase of PIN, it is done with
this command:
Modified: trunk/gtk+-2/gtksecentry.c
===================================================================
--- trunk/gtk+-2/gtksecentry.c 2007-09-18 17:52:39 UTC (rev 170)
+++ trunk/gtk+-2/gtksecentry.c 2007-11-19 12:36:53 UTC (rev 171)
@@ -3210,11 +3210,11 @@
get_cursor_time(GtkSecureEntry * entry)
{
GtkSettings *settings = gtk_widget_get_settings(GTK_WIDGET(entry));
- gint time;
+ gint blinktime;
- g_object_get(settings, "gtk-cursor-blink-time", &time, NULL);
+ g_object_get(settings, "gtk-cursor-blink-time", &blinktime, NULL);
- return time;
+ return blinktime;
}
static void
Modified: trunk/gtk+-2/pinentry-gtk-2.c
===================================================================
--- trunk/gtk+-2/pinentry-gtk-2.c 2007-09-18 17:52:39 UTC (rev 170)
+++ trunk/gtk+-2/pinentry-gtk-2.c 2007-11-19 12:36:53 UTC (rev 171)
@@ -59,11 +59,19 @@
static GtkWidget *qualitybar;
static GtkWidget *insure;
static GtkWidget *time_out;
+static GtkTooltips *tooltips;
/* Gnome hig small and large space in pixels. */
#define HIG_SMALL 6
#define HIG_LARGE 12
+/* The text shown in the quality bar when no text is shown. This is not
+ * the empty string, becase because with an empty string the height of
+ * the quality bar is less than with a non-empty string. This results
+ * in ugly layout changes when the text changes from non-empty to empty
+ * and vice versa */
+#define QUALITYBAR_EMPTY_TEXT " "
+
/* Constrain size of the window the window should not shrink beyond
the requisition, and should not grow vertically. */
@@ -203,7 +211,7 @@
percent = length? pinentry_inq_quality (pinentry, s, length) : 0;
if (!length)
{
- *textbuf = 0;
+ strcpy(textbuf, QUALITYBAR_EMPTY_TEXT);
color.red = 0xffff;
}
else if (percent < 0)
@@ -229,11 +237,13 @@
create_window (int confirm_mode)
{
GtkWidget *w;
- GtkWidget *win, *box, *ebox;
+ GtkWidget *win, *box;
GtkWidget *wvbox, *chbox, *bbox;
GtkAccelGroup *acc;
gchar *msg;
+ tooltips = gtk_tooltips_new ();
+
/* FIXME: check the grabbing code against the one we used with the
old gpg-agent */
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
@@ -251,10 +261,10 @@
if (!confirm_mode)
{
g_signal_connect (G_OBJECT (win),
- pinentry->grab ? "expose-event" : "focus-in-event",
+ pinentry->grab ? "map-event" : "focus-in-event",
G_CALLBACK (grab_keyboard), NULL);
g_signal_connect (G_OBJECT (win),
- pinentry->grab ? "no-expose-event" : "focus-out-event",
+ pinentry->grab ? "unmap-event" : "focus-out-event",
G_CALLBACK (ungrab_keyboard), NULL);
}
gtk_window_add_accel_group (GTK_WINDOW (win), acc);
@@ -295,28 +305,23 @@
gtk_box_pack_start (GTK_BOX (box), w, TRUE, FALSE, 0);
gtk_widget_modify_fg (w, GTK_STATE_NORMAL, &color);
}
-
- if (pinentry->quality_bar)
- {
- qualitybar = gtk_progress_bar_new();
- gtk_progress_bar_set_text (GTK_PROGRESS_BAR (qualitybar), "");
- gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (qualitybar), 0.0);
- gtk_box_pack_start (GTK_BOX (box), qualitybar, TRUE, FALSE, 0);
- }
- else
- qualitybar = NULL;
-
- ebox = gtk_hbox_new (FALSE, HIG_SMALL);
- gtk_box_pack_start (GTK_BOX(box), ebox, FALSE, FALSE, 0);
+ qualitybar = NULL;
+
if (!confirm_mode)
{
+ GtkWidget* table = gtk_table_new (pinentry->quality_bar ? 2 : 1, 2,
+ FALSE);
+ gtk_box_pack_start (GTK_BOX (box), table, FALSE, FALSE, 0);
+
if (pinentry->prompt)
{
msg = pinentry_utf8_validate (pinentry->prompt);
w = gtk_label_new (msg);
g_free (msg);
- gtk_box_pack_start (GTK_BOX (ebox), w, FALSE, FALSE, 0);
+ gtk_misc_set_alignment (GTK_MISC (w), 1.0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), w, 0, 1, 0, 1,
+ GTK_FILL, GTK_FILL, 4, 0);
}
entry = gtk_secure_entry_new ();
@@ -325,10 +330,32 @@
G_CALLBACK (enter_callback), entry);
g_signal_connect (G_OBJECT (entry), "changed",
G_CALLBACK (changed_text_handler), entry);
- gtk_box_pack_start (GTK_BOX (ebox), entry, TRUE, TRUE, 0);
+ gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
+ GTK_EXPAND|GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
gtk_widget_grab_focus (entry);
gtk_widget_show (entry);
+ if (pinentry->quality_bar)
+ {
+ msg = pinentry_utf8_validate (pinentry->quality_bar);
+ w = gtk_label_new (msg);
+ g_free (msg);
+ gtk_misc_set_alignment (GTK_MISC (w), 1.0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), w, 0, 1, 1, 2,
+ GTK_FILL, GTK_FILL, 4, 0);
+ qualitybar = gtk_progress_bar_new();
+ gtk_widget_add_events (qualitybar,
+ GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
+ gtk_progress_bar_set_text (GTK_PROGRESS_BAR (qualitybar),
+ QUALITYBAR_EMPTY_TEXT);
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (qualitybar), 0.0);
+ if (pinentry->quality_bar_tt)
+ gtk_tooltips_set_tip (GTK_TOOLTIPS (tooltips), qualitybar,
+ pinentry->quality_bar_tt, "");
+ gtk_table_attach (GTK_TABLE (table), qualitybar, 1, 2, 1, 2,
+ GTK_EXPAND|GTK_FILL, GTK_EXPAND|GTK_FILL, 0, 0);
+ }
+
if (pinentry->enhanced)
{
GtkWidget *sbox = gtk_hbox_new (FALSE, HIG_SMALL);
Modified: trunk/pinentry/pinentry.c
===================================================================
--- trunk/pinentry/pinentry.c 2007-09-18 17:52:39 UTC (rev 170)
+++ trunk/pinentry/pinentry.c 2007-11-19 12:36:53 UTC (rev 171)
@@ -69,7 +69,8 @@
0, /* Result. */
0, /* Locale error flag. */
0, /* One-button flag. */
- 0, /* Quality-Bar flag. */
+ NULL, /* Quality-Bar flag and description. */
+ NULL, /* Quality-Bar tooltip. */
PINENTRY_COLOR_DEFAULT,
0,
PINENTRY_COLOR_DEFAULT,
@@ -640,7 +641,7 @@
}
-/* note, that it is sufficient to allocate the target string D as
+/* Note, that it is sufficient to allocate the target string D as
long as the source string S, i.e.: strlen(s)+1; */
static void
strcpy_escaped (char *d, const unsigned char *s)
@@ -749,11 +750,45 @@
static int
cmd_setqualitybar (ASSUAN_CONTEXT ctx, char *line)
{
- pinentry.quality_bar = 1;
+ char *newval;
+
+ if (!*line)
+ line = "Quality:";
+
+ newval = malloc (strlen (line) + 1);
+ if (!newval)
+ return ASSUAN_Out_Of_Core;
+
+ strcpy_escaped (newval, line);
+ if (pinentry.quality_bar)
+ free (pinentry.quality_bar);
+ pinentry.quality_bar = newval;
return 0;
}
+/* Set the tooltip to be used for a quality bar. */
+static int
+cmd_setqualitybar_tt (ASSUAN_CONTEXT ctx, char *line)
+{
+ char *newval;
+ if (*line)
+ {
+ newval = malloc (strlen (line) + 1);
+ if (!newval)
+ return ASSUAN_Out_Of_Core;
+
+ strcpy_escaped (newval, line);
+ }
+ else
+ newval = NULL;
+ if (pinentry.quality_bar_tt)
+ free (pinentry.quality_bar_tt);
+ pinentry.quality_bar_tt = newval;
+ return 0;
+}
+
+
static int
cmd_getpin (ASSUAN_CONTEXT ctx, char *line)
{
@@ -881,6 +916,7 @@
{ "CONFIRM", 0, cmd_confirm },
{ "MESSAGE", 0, cmd_message },
{ "SETQUALITYBAR", 0, cmd_setqualitybar },
+ { "SETQUALITYBAR_TT", 0, cmd_setqualitybar_tt },
{ NULL }
};
int i, j, rc;
Modified: trunk/pinentry/pinentry.h
===================================================================
--- trunk/pinentry/pinentry.h 2007-09-18 17:52:39 UTC (rev 170)
+++ trunk/pinentry/pinentry.h 2007-11-19 12:36:53 UTC (rev 171)
@@ -91,11 +91,15 @@
dismiss button is required. */
int one_button;
- /* If this is set, a passphrase quality indicator is shown. There
- will also be an inquiry back to the caller to get an indication
- of the quality for the passphrase entered so far. */
- int quality_bar;
+ /* If this is not NULL, a passphrase quality indicator is shown.
+ There will also be an inquiry back to the caller to get an
+ indication of the quality for the passphrase entered so far. The
+ string is used as a labe for the auality bar. */
+ char *quality_bar;
+ /* The tooltip to be show for the qualitybar. Malloced or NULL. */
+ char *quality_bar_tt;
+
/* For the curses pinentry, the color of error messages. */
pinentry_color_t color_fg;
int color_fg_bright;
Modified: trunk/qt/main.cpp
===================================================================
--- trunk/qt/main.cpp 2007-09-18 17:52:39 UTC (rev 170)
+++ trunk/qt/main.cpp 2007-11-19 12:36:53 UTC (rev 171)
@@ -84,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)
Modified: trunk/qt/pinentrydialog.cpp
===================================================================
--- trunk/qt/pinentrydialog.cpp 2007-09-18 17:52:39 UTC (rev 170)
+++ trunk/qt/pinentrydialog.cpp 2007-11-19 12:36:53 UTC (rev 171)
@@ -24,6 +24,7 @@
#include <qlabel.h>
#include <qmessagebox.h>
#include <qprogressbar.h>
+#include <qtooltip.h>
#include "secqlineedit.h"
@@ -46,29 +47,34 @@
_error = new QLabel( this );
labelLayout->addWidget( _error );
+ _desc = new QLabel( this );
+ labelLayout->addWidget( _desc );
+
+ QGridLayout* grid = new QGridLayout( labelLayout );
+
+ _prompt = new QLabel( this );
+ _prompt->setAlignment( Qt::AlignRight | Qt::AlignVCenter );
+ grid->addWidget( _prompt, 0, 0 );
+ _edit = new SecQLineEdit( this );
+ _edit->setMaxLength( 256 );
+ _edit->setEchoMode( SecQLineEdit::Password );
+ grid->addWidget( _edit, 0, 1 );
+
if (enable_quality_bar)
{
- _quality_bar = new QProgressBar (this);
- _quality_bar->setCenterIndicator (true);
- labelLayout->addWidget ( _quality_bar );
+ QLabel* _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->setCenterIndicator( true );
+ grid->addWidget( _quality_bar, 1, 1 );
_have_quality_bar = true;
}
else
_have_quality_bar = false;
-
- _desc = new QLabel( this );
- labelLayout->addWidget( _desc );
QBoxLayout* l = new QHBoxLayout( top );
- _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 );
-
_ok = new QPushButton( tr("OK"), this );
_cancel = new QPushButton( tr("Cancel"), this );
@@ -208,7 +214,18 @@
_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)
+ QToolTip::add ( _quality_bar, txt );
+}
+
void PinEntryDialog::setPinentryInfo (pinentry_t peinfo )
{
_pinentry_info = peinfo;
Modified: trunk/qt/pinentrydialog.h
===================================================================
--- trunk/qt/pinentrydialog.h 2007-09-18 17:52:39 UTC (rev 170)
+++ trunk/qt/pinentrydialog.h 2007-11-19 12:36:53 UTC (rev 171)
@@ -56,6 +56,9 @@
void setOkText( const QString& );
void setCancelText( const QString& );
+ void setQualityBar( const QString& );
+ void setQualityBarTT( const QString& );
+
void setPinentryInfo (pinentry_t);
public slots:
@@ -75,6 +78,7 @@
QLabel* _desc;
QLabel* _error;
QLabel* _prompt;
+ QLabel* _quality_bar_label;
QProgressBar* _quality_bar;
SecQLineEdit* _edit;
QPushButton* _ok;
More information about the Gnupg-commits
mailing list