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@gnupg.org>
This commit is contained in:
Werner Koch 2017-01-31 09:44:29 +01:00
parent 7bd6ab4a91
commit 752d3597ef
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
6 changed files with 49 additions and 1 deletions

View File

@ -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

View File

@ -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. */

View File

@ -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":"";

View File

@ -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)

View File

@ -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;

View File

@ -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);