diff --git a/doc/gpgme.texi b/doc/gpgme.texi index 511384f9..99627c4b 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 +@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: + +@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); +@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 1a8698c3..d0542d9f 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 cf767c72..2b196a25 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 d9217ecd..817c5691 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 c10ccaa8..066a7f5d 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 9f2e1751..1daf173c 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);