[Pkg-gnupg-commit] [gpgme] 41/132: core: Add new context flag "redraw".

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Apr 26 01:01:20 UTC 2017


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch experimental
in repository gpgme.

commit 752d3597ef02a95efd693373132bf1e246f0edb0
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Jan 31 09:44:29 2017 +0100

    core: Add new context flag "redraw".
    
    * src/context.h (struct gpgme_context): New field 'redraw_suggested'.
    * src/op-support.c (_gpgme_op_reset): Clear REDRAW_SUGGESTED.
    * src/progress.c (_gpgme_progress_status_handler): Set REDRAW_SUGGESTED.
    * src/gpgme.c (gpgme_set_ctx_flag, gpgme_get_ctx_flag): Add "redraw".
    * tests/run-sign.c (main): Use it.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 doc/gpgme.texi   | 23 +++++++++++++++++++++++
 src/context.h    |  6 +++++-
 src/gpgme.c      |  8 ++++++++
 src/op-support.c |  1 +
 src/progress.c   |  8 ++++++++
 tests/run-sign.c |  4 ++++
 6 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/doc/gpgme.texi b/doc/gpgme.texi
index 511384f..99627c4 100644
--- a/doc/gpgme.texi
+++ b/doc/gpgme.texi
@@ -2888,6 +2888,29 @@ by this function.  The properties are identified by the following
 values for @var{name}:
 
 @table @code
+ at item "redraw"
+This flag is normally not changed by the caller because GPGME sets and
+clears it automatically: The flag is cleared before an operation and
+set if an operation noticed that the engine has launched a Pinentry.
+A Curses based application may use this information to redraw the
+screen; for example:
+
+ at example
+    err = gpgme_op_keylist_start (ctx, "foo@@example.org", 0);
+    while (!err)
+      @{
+        err = gpgme_op_keylist_next (ctx, &key);
+        if (err)
+          break;
+        show_key (key);
+        gpgme_key_release (key);
+      @}
+    if ((s = gpgme_get_ctx_flag (ctx, "redraw")) && *s)
+      redraw_screen ();
+    gpgme_release (ctx);
+ at end example
+
+
 @item "full-status"
 Using a @var{value} of "1" the status callback set by
 gpgme_set_status_cb returns all status lines with the exception of
diff --git a/src/context.h b/src/context.h
index 1a8698c..d0542d9 100644
--- a/src/context.h
+++ b/src/context.h
@@ -114,10 +114,14 @@ struct gpgme_context
   /* True if session keys should be exported upon decryption.  */
   unsigned int export_session_keys : 1;
 
+  /* True if a Pinentry was launched during the last operation.  This
+   * flag is cleared with each operation.  */
+  unsigned int redraw_suggested : 1;
+
   /* Flags for keylist mode.  */
   gpgme_keylist_mode_t keylist_mode;
 
-  /* The current pinnetry mode.  */
+  /* The current pinentry mode.  */
   gpgme_pinentry_mode_t pinentry_mode;
 
   /* Number of certs to be included.  */
diff --git a/src/gpgme.c b/src/gpgme.c
index cf767c7..2b196a2 100644
--- a/src/gpgme.c
+++ b/src/gpgme.c
@@ -508,6 +508,10 @@ gpgme_set_ctx_flag (gpgme_ctx_t ctx, const char *name, const char *value)
 
   if (!ctx || !name || !value)
     err = gpg_error (GPG_ERR_INV_VALUE);
+  else if (!strcmp (name, "redraw"))
+    {
+      ctx->redraw_suggested = abool;
+    }
   else if (!strcmp (name, "full-status"))
     {
       ctx->full_status = abool;
@@ -544,6 +548,10 @@ gpgme_get_ctx_flag (gpgme_ctx_t ctx, const char *name)
 {
   if (!ctx || !name)
     return NULL;
+  else if (!strcmp (name, "redraw"))
+    {
+      return ctx->redraw_suggested? "1":"";
+    }
   else if (!strcmp (name, "full-status"))
     {
       return ctx->full_status? "1":"";
diff --git a/src/op-support.c b/src/op-support.c
index d9217ec..817c569 100644
--- a/src/op-support.c
+++ b/src/op-support.c
@@ -94,6 +94,7 @@ _gpgme_op_reset (gpgme_ctx_t ctx, int type)
   _gpgme_release_result (ctx);
   LOCK (ctx->lock);
   ctx->canceled = 0;
+  ctx->redraw_suggested = 0;
   UNLOCK (ctx->lock);
 
   if (ctx->engine && no_reset)
diff --git a/src/progress.c b/src/progress.c
index c10ccaa..066a7f5 100644
--- a/src/progress.c
+++ b/src/progress.c
@@ -31,6 +31,8 @@
 #include "debug.h"
 
 
+/* The status handler for progress status lines which also monitors
+ * the PINENTRY_LAUNCHED status.  */
 gpgme_error_t
 _gpgme_progress_status_handler (void *priv, gpgme_status_code_t code,
 				char *args)
@@ -42,6 +44,12 @@ _gpgme_progress_status_handler (void *priv, gpgme_status_code_t code,
   int current = 0;
   int total = 0;
 
+  if (code == GPGME_STATUS_PINENTRY_LAUNCHED)
+    {
+      ctx->redraw_suggested = 1;
+      return 0;
+    }
+
   if (code != GPGME_STATUS_PROGRESS || !*args || !ctx->progress_cb)
     return 0;
 
diff --git a/tests/run-sign.c b/tests/run-sign.c
index 9f2e175..1daf173 100644
--- a/tests/run-sign.c
+++ b/tests/run-sign.c
@@ -103,6 +103,7 @@ main (int argc, char **argv)
   int print_status = 0;
   int use_loopback = 0;
   const char *sender = NULL;
+  const char *s;
 
   if (argc)
     { argc--; argv++; }
@@ -229,6 +230,9 @@ main (int argc, char **argv)
       exit (1);
     }
 
+  if ((s = gpgme_get_ctx_flag (ctx, "redraw")) && *s)
+    fputs ("Screen redraw suggested\n", stdout);
+
   fputs ("Begin Output:\n", stdout);
   print_data (out);
   fputs ("End Output.\n", stdout);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list