[svn] pinentry - r203 - in trunk: . gtk+-2 pinentry

svn author marcus cvs at cvs.gnupg.org
Tue Apr 14 21:27:15 CEST 2009


Author: marcus
Date: 2009-04-14 21:27:15 +0200 (Tue, 14 Apr 2009)
New Revision: 203

Modified:
   trunk/ChangeLog
   trunk/gtk+-2/pinentry-gtk-2.c
   trunk/pinentry/pinentry-curses.c
   trunk/pinentry/pinentry.c
   trunk/pinentry/pinentry.h
Log:
2009-04-14  Marcus Brinkmann  <marcus at g10code.de>

	* pinentry/pinentry.h (struct pinentry): New member NOTOK.
	Rename member USER_CLOSED to CANCELED.
	* pinentry/pinentry.c: Add initializer for NOTOK.
	(register_commands): Add SETNOTOK.
	* pinentry/pinentry-curses.c (STRING_NOTOK): New macro.
	(dialog_pos_t): New value DIALOG_POS_NOTOK.
	(struct dialog): New members notok, notok_x, notok_y.
	(dialog_create): Implement NOTOK.
	(dialog_switch_pos): Likewise.
	(dialog_run): Likewise.
	* gtk+-2/pinentry-gtk-2.c: Rename confirm_yes to confirm_value.
	(confirm_value_t): New type.  Use it for confirm_value.
	(window_closed): Remove.
	(confirm_button_clicked): Set confirm_value.
	(create_window): Implement NOTOK.
	(gtk_cmd_handler): Implement cancel behaviour a bit differently.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-04-09 13:42:29 UTC (rev 202)
+++ trunk/ChangeLog	2009-04-14 19:27:15 UTC (rev 203)
@@ -1,3 +1,22 @@
+2009-04-14  Marcus Brinkmann  <marcus at g10code.de>
+
+	* pinentry/pinentry.h (struct pinentry): New member NOTOK.
+	Rename member USER_CLOSED to CANCELED.
+	* pinentry/pinentry.c: Add initializer for NOTOK.
+	(register_commands): Add SETNOTOK.
+	* pinentry/pinentry-curses.c (STRING_NOTOK): New macro.
+	(dialog_pos_t): New value DIALOG_POS_NOTOK.
+	(struct dialog): New members notok, notok_x, notok_y.
+	(dialog_create): Implement NOTOK.
+	(dialog_switch_pos): Likewise.
+	(dialog_run): Likewise.
+	* gtk+-2/pinentry-gtk-2.c: Rename confirm_yes to confirm_value.
+	(confirm_value_t): New type.  Use it for confirm_value.
+	(window_closed): Remove.
+	(confirm_button_clicked): Set confirm_value.
+	(create_window): Implement NOTOK.
+	(gtk_cmd_handler): Implement cancel behaviour a bit differently.
+
 2009-04-09  Marcus Brinkmann  <marcus at g10code.de>
 
 	* qt4/qsecurelineedit.h (QSecureLineEdit): Don't export.

Modified: trunk/gtk+-2/pinentry-gtk-2.c
===================================================================
--- trunk/gtk+-2/pinentry-gtk-2.c	2009-04-09 13:42:29 UTC (rev 202)
+++ trunk/gtk+-2/pinentry-gtk-2.c	2009-04-14 19:27:15 UTC (rev 203)
@@ -53,8 +53,8 @@
 
 static pinentry_t pinentry;
 static int passphrase_ok;
-static int confirm_yes;
-static int window_closed;
+typedef enum { CONFIRM_CANCEL, CONFIRM_OK, CONFIRM_NOTOK } confirm_value_t;
+static confirm_value_t confirm_value;
 
 static GtkWidget *entry;
 static GtkWidget *qualitybar;
@@ -150,7 +150,6 @@
 static int
 delete_event (GtkWidget *widget, GdkEvent *event, gpointer data)
 {
-  window_closed = 1;
   gtk_main_quit ();
   return TRUE;
 }
@@ -193,10 +192,7 @@
 static void
 confirm_button_clicked (GtkWidget *widget, gpointer data)
 {
-  if (data)
-    /* Okay button.  */
-    confirm_yes = 1;
-
+  confirm_value = (int) data;
   gtk_main_quit ();
 }
 
@@ -445,10 +441,24 @@
       gtk_container_add (GTK_CONTAINER (bbox), w);
       g_signal_connect (G_OBJECT (w), "clicked",
                         G_CALLBACK (confirm_mode ? confirm_button_clicked
-                                    : button_clicked), NULL);
+                                    : button_clicked),
+			(gpointer) CONFIRM_CANCEL);
       GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
     }
   
+  if (confirm_mode && !pinentry->one_button && pinentry->notok)
+    {
+      msg = pinentry_utf8_validate (pinentry->notok);
+      w = gtk_button_new_with_label (msg);
+      g_free (msg);
+
+      gtk_container_add (GTK_CONTAINER (bbox), w);
+      g_signal_connect (G_OBJECT (w), "clicked",
+                        G_CALLBACK (confirm_button_clicked),
+			(gpointer) CONFIRM_NOTOK);
+      GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
+    }
+  
   if (pinentry->ok)
     {
       msg = pinentry_utf8_validate (pinentry->ok);
@@ -471,7 +481,8 @@
   else
     {
       g_signal_connect (G_OBJECT (w), "clicked",
-			G_CALLBACK(confirm_button_clicked), "ok");
+			G_CALLBACK(confirm_button_clicked),
+			(gpointer) CONFIRM_OK);
       GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
     }
 
@@ -490,8 +501,7 @@
   int want_pass = !!pe->pin;
 
   pinentry = pe;
-  confirm_yes = 0;
-  window_closed = 0;
+  confirm_value = CONFIRM_CANCEL;
   passphrase_ok = 0;
   w = create_window (want_pass ? 0 : 1);
   gtk_main ();
@@ -499,8 +509,8 @@
   while (gtk_events_pending ())
     gtk_main_iteration ();
 
-  if (window_closed)
-    pe->user_closed = 1;
+  if (confirm_value == CONFIRM_CANCEL)
+    pe->canceled = 1;
 
   pinentry = NULL;
   if (want_pass)
@@ -511,7 +521,7 @@
 	return -1;
     }
   else
-    return confirm_yes;
+    return (confirm_value == CONFIRM_OK) ? 1 : 0;
 }
 
 

Modified: trunk/pinentry/pinentry-curses.c
===================================================================
--- trunk/pinentry/pinentry-curses.c	2009-04-09 13:42:29 UTC (rev 202)
+++ trunk/pinentry/pinentry-curses.c	2009-04-14 19:27:15 UTC (rev 203)
@@ -45,6 +45,7 @@
 #include "pinentry.h"
 
 #define STRING_OK "<OK>"
+#define STRING_NOTOK "<No>"
 #define STRING_CANCEL "<Cancel>"
 
 #define USE_COLORS		(has_colors () && COLOR_PAIRS >= 2)
@@ -58,6 +59,7 @@
     DIALOG_POS_NONE,
     DIALOG_POS_PIN,
     DIALOG_POS_OK,
+    DIALOG_POS_NOTOK,
     DIALOG_POS_CANCEL
   }
 dialog_pos_t;
@@ -82,6 +84,9 @@
   int cancel_y;
   int cancel_x;
   char *cancel;
+  int notok_y;
+  int notok_x;
+  char *notok;
 };
 typedef struct dialog *dialog_t;
 
@@ -195,6 +200,10 @@
     MAKE_BUTTON (cancel, STRING_CANCEL);
   else
     dialog->cancel = NULL;
+  if (!pinentry->one_button && pinentry->notok)
+    MAKE_BUTTON (notok, STRING_NOTOK);
+  else
+    dialog->notok = NULL;
 
   getmaxyx (stdscr, size_y, size_x);
 
@@ -281,13 +290,16 @@
       if (new_x > x)
 	x = new_x;
     }
-  /* We position the buttons after the first and second third of the
-     width.  Account for rounding.  */
-  if (x < 2 * strlen (dialog->ok))
-    x = 2 * strlen (dialog->ok);
+  /* We position the buttons after the first, second and third fourth
+     of the width.  Account for rounding.  */
+  if (x < 3 * strlen (dialog->ok))
+    x = 3 * strlen (dialog->ok);
   if (dialog->cancel)
-    if (x < 2 * strlen (dialog->cancel))
-      x = 2 * strlen (dialog->cancel);
+    if (x < 3 * strlen (dialog->cancel))
+      x = 3 * strlen (dialog->cancel);
+  if (dialog->notok)
+    if (x < 3 * strlen (dialog->notok))
+      x = 3 * strlen (dialog->notok);
 
   /* Add the frame.  */
   x += 4;
@@ -415,19 +427,30 @@
   move (ypos, xpos);
   addch (ACS_VLINE);
 
-  if (dialog->cancel)
+  if (dialog->cancel || dialog->notok)
     {
       dialog->ok_y = ypos;
       /* Calculating the left edge of the left button, rounding down.  */
-      dialog->ok_x = xpos + 2 + ((x - 4) / 2 - strlen (dialog->ok)) / 2;
+      dialog->ok_x = xpos + 2 + ((x - 4) / 3 - strlen (dialog->ok)) / 2;
       move (dialog->ok_y, dialog->ok_x);
       addstr (dialog->ok);
 
-      dialog->cancel_y = ypos;
-      /* Calculating the left edge of the right button, rounding up.  */
-      dialog->cancel_x = xpos + x - 2 - ((x - 4) / 2 + strlen (dialog->cancel)) / 2;
-      move (dialog->cancel_y, dialog->cancel_x);
-      addstr (dialog->cancel);
+      if (dialog->notok)
+	{
+	  dialog->notok_y = ypos;
+	  /* Calculating the left edge of the middle button, rounding up.  */
+	  dialog->notok_x = xpos + x / 2 - strlen (dialog->notok) / 2;
+	  move (dialog->notok_y, dialog->notok_x);
+	  addstr (dialog->notok);
+	}
+      if (dialog->cancel)
+	{
+	  dialog->cancel_y = ypos;
+	  /* Calculating the left edge of the right button, rounding up.  */
+	  dialog->cancel_x = xpos + x - 2 - ((x - 4) / 3 + strlen (dialog->cancel)) / 2;
+	  move (dialog->cancel_y, dialog->cancel_x);
+	  addstr (dialog->cancel);
+	}
     }
   else
     {
@@ -478,6 +501,13 @@
 	  move (diag->ok_y, diag->ok_x);
 	  addstr (diag->ok);
 	  break;
+	case DIALOG_POS_NOTOK:
+          if (diag->notok)
+            {
+              move (diag->notok_y, diag->notok_x);
+              addstr (diag->notok);
+            }
+	  break;
 	case DIALOG_POS_CANCEL:
           if (diag->cancel)
             {
@@ -503,6 +533,17 @@
 	  standend ();
 	  move (diag->ok_y, diag->ok_x);
 	  break;
+	case DIALOG_POS_NOTOK:
+          if (diag->notok)
+            {
+              set_cursor_state (0);
+              move (diag->notok_y, diag->notok_x);
+              standout ();
+              addstr (diag->notok);
+              standend ();
+              move (diag->notok_y, diag->notok_x);
+            }
+	  break;
 	case DIALOG_POS_CANCEL:
           if (diag->cancel)
             {
@@ -665,9 +706,15 @@
 	      if (diag.pin)
 		dialog_switch_pos (&diag, DIALOG_POS_PIN);
 	      break;
-	    case DIALOG_POS_CANCEL:
+	    case DIALOG_POS_NOTOK:
 	      dialog_switch_pos (&diag, DIALOG_POS_OK);
 	      break;
+	    case DIALOG_POS_CANCEL:
+	      if (diag.notok)
+		dialog_switch_pos (&diag, DIALOG_POS_NOTOK);
+	      else
+		dialog_switch_pos (&diag, DIALOG_POS_OK);
+	      break;
 	    default:
 	      break;
 	    }
@@ -681,6 +728,12 @@
 	      dialog_switch_pos (&diag, DIALOG_POS_OK);
 	      break;
 	    case DIALOG_POS_OK:
+	      if (diag.notok)
+		dialog_switch_pos (&diag, DIALOG_POS_NOTOK);
+	      else
+		dialog_switch_pos (&diag, DIALOG_POS_CANCEL);
+	      break;
+	    case DIALOG_POS_NOTOK:
 	      dialog_switch_pos (&diag, DIALOG_POS_CANCEL);
 	      break;
 	    default:
@@ -695,6 +748,12 @@
 	      dialog_switch_pos (&diag, DIALOG_POS_OK);
 	      break;
 	    case DIALOG_POS_OK:
+	      if (diag.notok)
+		dialog_switch_pos (&diag, DIALOG_POS_NOTOK);
+	      else
+		dialog_switch_pos (&diag, DIALOG_POS_CANCEL);	      
+	      break;
+	    case DIALOG_POS_NOTOK:
 	      dialog_switch_pos (&diag, DIALOG_POS_CANCEL);
 	      break;
 	    case DIALOG_POS_CANCEL:
@@ -719,6 +778,9 @@
 	    case DIALOG_POS_OK:
 	      done = 1;
 	      break;
+	    case DIALOG_POS_NOTOK:
+	      done = -1;
+	      break;
 	    case DIALOG_POS_CANCEL:
 	      done = -2;
 	      break;
@@ -745,7 +807,10 @@
     fclose (ttyfo);
   /* XXX Factor out into dialog_release or something.  */
   free (diag.ok);
-  free (diag.cancel);
+  if (diag.cancel)
+    free (diag.cancel);
+  if (diag.notok)
+    free (diag.notok);
 
   if (pinentry->pin)
     {
@@ -761,6 +826,9 @@
 	}
     }
 
+  if (done == -2)
+    pinentry->canceled = 1;
+
   return diag.pin ? (done < 0 ? -1 : diag.pin_len) : (done < 0 ? 0 : 1);
 }
 

Modified: trunk/pinentry/pinentry.c
===================================================================
--- trunk/pinentry/pinentry.c	2009-04-09 13:42:29 UTC (rev 202)
+++ trunk/pinentry/pinentry.c	2009-04-14 19:27:15 UTC (rev 203)
@@ -53,6 +53,7 @@
     NULL,	/* Error.  */
     NULL,	/* Prompt.  */
     NULL,	/* Ok button.  */
+    NULL,	/* Not-Ok button.  */
     NULL,	/* Cancel button.  */
     NULL,	/* PIN.  */
     2048,	/* PIN length.  */
@@ -67,6 +68,7 @@
     0,		/* Parent Window ID.  */
     NULL,       /* Touch file.  */
     0,		/* Result.  */
+    0,		/* Result Not-OK.  */
     0,          /* Locale error flag. */
     0,          /* One-button flag.  */
     NULL,       /* Quality-Bar flag and description.  */
@@ -730,6 +732,23 @@
 
 
 static int
+cmd_setnotok (ASSUAN_CONTEXT ctx, char *line)
+{
+  char *newo;
+  newo = malloc (strlen (line) + 1);
+
+  if (!newo)
+    return ASSUAN_Out_Of_Core;
+
+  strcpy_escaped (newo, line);
+  if (pinentry.notok)
+    free (pinentry.notok);
+  pinentry.notok = newo;
+  return 0;
+}
+
+
+static int
 cmd_setcancel (ASSUAN_CONTEXT ctx, char *line)
 {
   char *newc;
@@ -819,7 +838,6 @@
       set_prompt = 1;
     }
   pinentry.locale_err = 0;
-  pinentry.user_closed = 0;
   pinentry.one_button = 0;
   pinentry.ctx_assuan = ctx;
   result = (*pinentry_cmd_handler) (&pinentry);
@@ -876,7 +894,7 @@
   pinentry.one_button = !!strstr (line, "--one-button");
   pinentry.quality_bar = 0;
   pinentry.locale_err = 0;
-  pinentry.user_closed = 0;
+  pinentry.canceled = 0;
   result = (*pinentry_cmd_handler) (&pinentry);
   if (pinentry.error)
     {
@@ -888,7 +906,7 @@
                 : (pinentry.locale_err? ASSUAN_Locale_Problem
                                       : (pinentry.one_button 
                                          ? 0
-                                         : (pinentry.user_closed
+                                         : (pinentry.canceled
                                             ? ASSUAN_Canceled
                                             : ASSUAN_Not_Confirmed)));
 }
@@ -902,7 +920,6 @@
   pinentry.one_button = 1;
   pinentry.quality_bar = 0;
   pinentry.locale_err = 0;
-  pinentry.user_closed = 0;
   result = (*pinentry_cmd_handler) (&pinentry);
   if (pinentry.error)
     {
@@ -961,6 +978,7 @@
       { "SETPROMPT",  0,  cmd_setprompt },
       { "SETERROR",   0,  cmd_seterror },
       { "SETOK",      0,  cmd_setok },
+      { "SETNOTOK",   0,  cmd_setnotok },
       { "SETCANCEL",  0,  cmd_setcancel },
       { "GETPIN",     0,  cmd_getpin },
       { "CONFIRM",    0,  cmd_confirm },

Modified: trunk/pinentry/pinentry.h
===================================================================
--- trunk/pinentry/pinentry.h	2009-04-09 13:42:29 UTC (rev 202)
+++ trunk/pinentry/pinentry.h	2009-04-14 19:27:15 UTC (rev 203)
@@ -48,6 +48,8 @@
   char *prompt;
   /* The OK button text to display, or NULL.  */
   char *ok;
+  /* The Not-OK button text to display, or NULL.  */
+  char *notok;
   /* The Cancel button text to display, or NULL.  */
   char *cancel;
   /* The buffer to store the secret into.  */
@@ -84,9 +86,8 @@
      and to the length of the PIN stored in pin otherwise.  */
   int result;
 
-  /* The user should set this is the pinentry window was closed by the
-     user without using a button.  */
-  int user_closed;
+  /* The user should set this if the NOTOK button was pressed.  */
+  int canceled;
 
   /* The user should set this to true if an error with the local
      conversion occured. */




More information about the Gnupg-commits mailing list