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

svn author wk cvs at cvs.gnupg.org
Wed Jan 24 19:25:11 CET 2007


Author: wk
Date: 2007-01-24 19:25:10 +0100 (Wed, 24 Jan 2007)
New Revision: 154

Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/TODO
   trunk/doc/pinentry.texi
   trunk/gtk+-2/pinentry-gtk-2.c
   trunk/gtk/pinentry-gtk.c
   trunk/pinentry/pinentry-curses.c
   trunk/pinentry/pinentry.c
   trunk/pinentry/pinentry.h
Log:
	* pinentry/pinentry.c (cmd_message): New.
	(cmd_confirm): New command option --one-button.
	(cmd_getpin): Zeroise ONE_BUTTON.
	* pinentry/pinentry.h (struct pinentry): Add field ONE_BUTTON.
        * gtk/pinentry-gtk.c (create_window): Take care of new option.
        * gtk+-2/pinentry-gtk-2.c (create_window): Ditto.
        * pinentry/pinentry-curses.c (dialog_create): Ditto.
    	(dialog_create, dialog_switch_pos): Allow CANCEL to be optional.
		 


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-07-29 00:10:45 UTC (rev 153)
+++ trunk/ChangeLog	2007-01-24 18:25:10 UTC (rev 154)
@@ -1,3 +1,14 @@
+2007-01-24  Werner Koch  <wk at g10code.com>
+
+	* pinentry/pinentry.c (cmd_message): New.
+	(cmd_confirm): New command option --one-button.
+	(cmd_getpin): Zeroise ONE_BUTTON.
+	* pinentry/pinentry.h (struct pinentry): Add field ONE_BUTTON.
+	* gtk/pinentry-gtk.c (create_window): Take care of new option.
+	* gtk+-2/pinentry-gtk-2.c (create_window): Ditto.
+	* pinentry/pinentry-curses.c (dialog_create): Ditto.
+	(dialog_create, dialog_switch_pos): Allow CANCEL to be optional.
+
 2006-07-29  Marcus Brinkmann  <marcus at g10code.de>
 
 	* secmem/secmem.c (init_pool): Close FD after establishing the

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2006-07-29 00:10:45 UTC (rev 153)
+++ trunk/NEWS	2007-01-24 18:25:10 UTC (rev 154)
@@ -1,7 +1,10 @@
 Noteworthy changes in version 0.7.3
 ------------------------------------------------
 
+ * New command MESSAGE and --one-button compatibility option to
+   CONFIRM.
 
+
 Noteworthy changes in version 0.7.2 (2005-01-27)
 ------------------------------------------------
 

Modified: trunk/TODO
===================================================================
--- trunk/TODO	2006-07-29 00:10:45 UTC (rev 153)
+++ trunk/TODO	2007-01-24 18:25:10 UTC (rev 154)
@@ -15,3 +15,5 @@
   the gpg-agent is better able to cope with jammed pinentries.
 
 * The gtk+-2 pinentry needs auditing.
+
+* Implement the one_button feature in Qt.

Modified: trunk/doc/pinentry.texi
===================================================================
--- trunk/doc/pinentry.texi	2006-07-29 00:10:45 UTC (rev 153)
+++ trunk/doc/pinentry.texi	2007-01-24 18:25:10 UTC (rev 154)
@@ -298,6 +298,21 @@
 The value returned is either OK for YES or the error code
 @code{ASSUAN_Not_Confirmed}.
 
+ at item Show a message
+To show a message, you can use this command:
+ at example
+  C: MESSAGE
+  S: OK
+ at end example
+alternativly you may add an option to confirm:
+ at example
+  C: CONFIRM --one-button
+  S: OK
+ at end example
+The client should use SETDESC to set an appropriate text before issuing
+this command, and may use SETOK to set the text for the dismiss button.
+The value returned is OK or an error message.
+
 @item Set the output device
 When using X, the @pinentry{} program must be invoked with an
 appropriate @code{DISPLAY} environment variable or the

Modified: trunk/gtk/pinentry-gtk.c
===================================================================
--- trunk/gtk/pinentry-gtk.c	2006-07-29 00:10:45 UTC (rev 153)
+++ trunk/gtk/pinentry-gtk.c	2007-01-24 18:25:10 UTC (rev 154)
@@ -345,13 +345,17 @@
 
   gtk_widget_show (w);
   
-  w = gtk_button_new_with_label (pinentry->cancel ? pinentry->cancel : "Cancel");
-  gtk_container_add (GTK_CONTAINER(bbox), w);
-  gtk_accel_group_add (acc, GDK_Escape, 0, 0, GTK_OBJECT(w), "clicked");
-  gtk_signal_connect (GTK_OBJECT(w), "clicked", 
-                      confirm_mode? confirm_button_clicked: button_clicked,
-                      NULL);
-  GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
+  if (!pinentry->one_button)
+    {
+      w = gtk_button_new_with_label (pinentry->cancel 
+                                     ? pinentry->cancel : "Cancel");
+      gtk_container_add (GTK_CONTAINER(bbox), w);
+      gtk_accel_group_add (acc, GDK_Escape, 0, 0, GTK_OBJECT(w), "clicked");
+      gtk_signal_connect (GTK_OBJECT(w), "clicked", 
+                          confirm_mode? confirm_button_clicked: button_clicked,
+                          NULL);
+      GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
+    }
 
   gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
 

Modified: trunk/gtk+-2/pinentry-gtk-2.c
===================================================================
--- trunk/gtk+-2/pinentry-gtk-2.c	2006-07-29 00:10:45 UTC (rev 153)
+++ trunk/gtk+-2/pinentry-gtk-2.c	2007-01-24 18:25:10 UTC (rev 154)
@@ -304,19 +304,22 @@
   gtk_box_set_spacing (GTK_BOX (bbox), 6);
   gtk_box_pack_start (GTK_BOX (wvbox), bbox, TRUE, FALSE, 0);
 
-  if (pinentry->cancel)
+  if (!pinentry->one_button)
     {
-      msg = pinentry_utf8_validate (pinentry->cancel);
-      w = gtk_button_new_with_label (msg);
-      g_free (msg);
+      if (pinentry->cancel)
+        {
+          msg = pinentry_utf8_validate (pinentry->cancel);
+          w = gtk_button_new_with_label (msg);
+          g_free (msg);
+        }
+      else
+        w = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
+      gtk_container_add (GTK_CONTAINER (bbox), w);
+      g_signal_connect (G_OBJECT (w), "clicked",
+                        G_CALLBACK (confirm_mode ? confirm_button_clicked
+                                    : button_clicked), NULL);
+      GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
     }
-  else
-    w = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
-  gtk_container_add (GTK_CONTAINER (bbox), w);
-  g_signal_connect (G_OBJECT (w), "clicked",
-		    G_CALLBACK (confirm_mode ? confirm_button_clicked
-				: button_clicked), NULL);
-  GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
   
   if (pinentry->ok)
     {

Modified: trunk/pinentry/pinentry-curses.c
===================================================================
--- trunk/pinentry/pinentry-curses.c	2006-07-29 00:10:45 UTC (rev 153)
+++ trunk/pinentry/pinentry-curses.c	2007-01-24 18:25:10 UTC (rev 154)
@@ -181,7 +181,10 @@
   while (0)
 
   MAKE_BUTTON (ok, STRING_OK);
-  MAKE_BUTTON (cancel, STRING_CANCEL);
+  if (!pinentry->one_button)
+    MAKE_BUTTON (cancel, STRING_CANCEL);
+  else
+    dialog->cancel = NULL;
 
   getmaxyx (stdscr, size_y, size_x);
 
@@ -272,8 +275,9 @@
      width.  Account for rounding.  */
   if (x < 2 * strlen (dialog->ok))
     x = 2 * strlen (dialog->ok);
-  if (x < 2 * strlen (dialog->cancel))
-    x = 2 * strlen (dialog->cancel);
+  if (dialog->cancel)
+    if (x < 2 * strlen (dialog->cancel))
+      x = 2 * strlen (dialog->cancel);
 
   /* Add the frame.  */
   x += 4;
@@ -399,11 +403,13 @@
   dialog->ok_x = xpos + 2 + ((x - 4) / 2 - 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->cancel)
+    {
+      dialog->cancel_y = ypos;
+      /* Calculating the left edge of the right button, rounding up.  */
+      move (dialog->cancel_y, dialog->cancel_x);
+      addstr (dialog->cancel);
+    }
 
  out:
   if (description)
@@ -446,8 +452,11 @@
 	  addstr (diag->ok);
 	  break;
 	case DIALOG_POS_CANCEL:
-	  move (diag->cancel_y, diag->cancel_x);
-	  addstr (diag->cancel);
+          if (diag->cancel)
+            {
+              move (diag->cancel_y, diag->cancel_x);
+              addstr (diag->cancel);
+            }
 	  break;
 	default:
 	  break;
@@ -468,12 +477,15 @@
 	  move (diag->ok_y, diag->ok_x);
 	  break;
 	case DIALOG_POS_CANCEL:
-	  set_cursor_state (0);
-	  move (diag->cancel_y, diag->cancel_x);
-	  standout ();
-	  addstr (diag->cancel);
-	  standend ();
-	  move (diag->cancel_y, diag->cancel_x);
+          if (diag->cancel)
+            {
+              set_cursor_state (0);
+              move (diag->cancel_y, diag->cancel_x);
+              standout ();
+              addstr (diag->cancel);
+              standend ();
+              move (diag->cancel_y, diag->cancel_x);
+            }
 	  break;
 	case DIALOG_POS_NONE:
 	  set_cursor_state (0);

Modified: trunk/pinentry/pinentry.c
===================================================================
--- trunk/pinentry/pinentry.c	2006-07-29 00:10:45 UTC (rev 153)
+++ trunk/pinentry/pinentry.c	2007-01-24 18:25:10 UTC (rev 154)
@@ -66,7 +66,8 @@
     1,		/* Global grab.  */
     0,		/* Parent Window ID.  */
     0,		/* Result.  */
-    0           /* Locale error flag. */
+    0,          /* Locale error flag. */
+    0           /* One-button flag.  */
   };
 
 
@@ -576,6 +577,7 @@
       set_prompt = 1;
     }
   pinentry.locale_err = 0;
+  pinentry.one_button = 0;
 
   result = (*pinentry_cmd_handler) (&pinentry);
   if (pinentry.error)
@@ -613,11 +615,19 @@
 }
 
 
+/* Note that the option --one-button is hack to allow the use of old
+   pinentries while the caller is ignoring the result.  Given that
+   options have never been used or flagged as an error the new option
+   is an easy way to enable the messsage mode while not requiring to
+   update pinentry or to have the caller test for the message
+   command.  New applications which are free to require an updated
+   pinentry should use MESSAGE instead. */
 static int
 cmd_confirm (ASSUAN_CONTEXT ctx, char *line)
 {
   int result;
 
+  pinentry.one_button = !!strstr (line, "--one-button");
   pinentry.locale_err = 0;
   result = (*pinentry_cmd_handler) (&pinentry);
   if (pinentry.error)
@@ -628,10 +638,32 @@
 
   return result ? 0
                 : (pinentry.locale_err? ASSUAN_Locale_Problem
-                                      : ASSUAN_Not_Confirmed);
+                                      : (pinentry.one_button 
+                                         ? 0
+                                         : ASSUAN_Not_Confirmed));
 }
 
 
+static int
+cmd_message (ASSUAN_CONTEXT ctx, char *line)
+{
+  int result;
+
+  pinentry.one_button = 1;
+  pinentry.locale_err = 0;
+  result = (*pinentry_cmd_handler) (&pinentry);
+  if (pinentry.error)
+    {
+      free (pinentry.error);
+      pinentry.error = NULL;
+    }
+
+  return result ? 0 
+                : (pinentry.locale_err? ASSUAN_Locale_Problem
+                                      : 0);
+}
+
+
 /* Tell the assuan library about our commands.  */
 static int
 register_commands (ASSUAN_CONTEXT ctx)
@@ -650,6 +682,7 @@
       { "SETCANCEL",  0,  cmd_setcancel },
       { "GETPIN",     0,  cmd_getpin },
       { "CONFIRM",    0,  cmd_confirm },
+      { "MESSAGE",    0,  cmd_message },
       { NULL }
     };
   int i, j, rc;

Modified: trunk/pinentry/pinentry.h
===================================================================
--- trunk/pinentry/pinentry.h	2006-07-29 00:10:45 UTC (rev 153)
+++ trunk/pinentry/pinentry.h	2007-01-24 18:25:10 UTC (rev 154)
@@ -75,6 +75,11 @@
      conversion occured. */
   int locale_err;
 
+  /* The caller should set this to true if only one button is
+     required.  This is useful for notification dialogs where only a
+     dismiss button is required. */
+  int one_button;
+
 };
 typedef struct pinentry *pinentry_t;
 




More information about the Gnupg-commits mailing list