GcrPrompt: Gcr Library Reference Manual

## GcrPrompt GcrPrompt — a user prompt |

## Functions

const gchar * | gcr_prompt_password ()
void | gcr_prompt_password_async ()
const gchar * | gcr_prompt_password_finish ()
const gchar * | gcr_prompt_password_run ()
GcrPromptReply | gcr_prompt_confirm ()
void | gcr_prompt_confirm_async ()
GcrPromptReply | gcr_prompt_confirm_finish ()
GcrPromptReply | gcr_prompt_confirm_run ()
void | gcr_prompt_reset ()
void | gcr_prompt_close ()
gchar * | gcr_prompt_get_title ()
void | gcr_prompt_set_title ()
gchar * | gcr_prompt_get_message ()
void | gcr_prompt_set_message ()
gchar * | gcr_prompt_get_description ()
void | gcr_prompt_set_description ()
gchar * | gcr_prompt_get_warning ()
void | gcr_prompt_set_warning ()
gchar * | gcr_prompt_get_continue_label ()
void | gcr_prompt_set_continue_label ()
gchar * | gcr_prompt_get_cancel_label ()
void | gcr_prompt_set_cancel_label ()
gchar * | gcr_prompt_get_choice_label ()
void | gcr_prompt_set_choice_label ()
gboolean | gcr_prompt_get_choice_chosen ()
void | gcr_prompt_set_choice_chosen ()
gboolean | gcr_prompt_get_password_new ()
void | gcr_prompt_set_password_new ()
gint | gcr_prompt_get_password_strength ()
gchar * | gcr_prompt_get_caller_window ()
void | gcr_prompt_set_caller_window ()

## Properties

gchar * | caller-window | Read / Write / Construct
gchar * | cancel-label | Read / Write / Construct
gboolean | choice-chosen | Read / Write
gchar * | choice-label | Read / Write / Construct
gchar * | continue-label | Read / Write / Construct
gchar * | description | Read / Write / Construct
gchar * | message | Read / Write / Construct
gboolean | password-new | Read / Write
gint | password-strength | Read
gchar * | title | Read / Write / Construct
gchar * | warning | Read / Write / Construct

## Signals

void | prompt-close | Run First

## Types and Values

| GcrPrompt
struct | GcrPromptIface
enum | GcrPromptReply

## Object Hierarchy

        GInterface
        ╰── GcrPrompt

## Prerequisites

GcrPrompt requires GObject.

## Known Implementations

GcrPrompt is implemented by GcrPromptDialog and GcrSystemPrompt.

## Description

A GcrPrompt represents a prompt displayed to the user. It is an interface with various implementations.

Various properties are set on the prompt, and then the prompt is displayed the various prompt methods like `gcr_prompt_password_run()`.

A GcrPrompt may be used to display multiple related prompts. Most implemantions do not hide the window between display of multiple related prompts, and the GcrPrompt must be closed or destroyed in order to make it go away. This allows the user to see that the prompts are related.

Use GcrPromptDialog to create an in-process GTK+ dialog prompt. Use GcrSystemPrompt to create a system prompt in a prompter process.

The prompt implementation will always display the GcrPrompt:message property, but may choose not to display the GcrPrompt:description or GcrPrompt:title properties.

## Functions

### gcr_prompt_password ()

    const gchar *
    gcr_prompt_password (GcrPrompt *prompt,
                         GCancellable *cancellable,
                         GError **error);

Prompts for password. Set the various properties on the prompt before calling this method to explain which password should be entered.

This method will block until the a response is returned from the prompter.

A password will be returned if the user enters a password successfully. The returned password is valid until the next time a method is called to display another prompt.

`NULL` will be returned if the user cancels or if an error occurs. Check the `error` argument to tell the difference.

#### Parameters

prompt | a prompt |
cancellable | optional cancellation object |
error | location to place error on failure |

#### Returns

the password owned by the prompt, or `NULL`

### gcr_prompt_password_async ()

    void
    gcr_prompt_password_async (GcrPrompt *prompt,
                               GCancellable *cancellable,
                               GAsyncReadyCallback callback,
                               gpointer user_data);

Prompts for password. Set the various properties on the prompt before calling this method to explain which password should be entered.

This method will return immediately and complete asynchronously.

#### Parameters

prompt | a prompt |
cancellable | optional cancellation object |
callback | called when the operation completes |
user_data | data to pass to the callback |

### gcr_prompt_password_finish ()

    const gchar *
    gcr_prompt_password_finish (GcrPrompt *prompt,
                                GAsyncResult *result,
                                GError **error);

Complete an operation to prompt for a password.

A password will be returned if the user enters a password successfully. The returned password is valid until the next time a method is called to display another prompt.

`NULL` will be returned if the user cancels or if an error occurs. Check the `error` argument to tell the difference.

#### Parameters

prompt | a prompt |
result | asynchronous result passed to callback |
error | location to place error on failure |

#### Returns

the password owned by the prompt, or `NULL`

### gcr_prompt_password_run ()

    const gchar *
    gcr_prompt_password_run (GcrPrompt *prompt,
                             GCancellable *cancellable,
                             GError **error);

Prompts for password. Set the various properties on the prompt before calling this method to explain which password should be entered.

This method will block until the a response is returned from the prompter and will run a main loop similar to a `gtk_dialog_run()`. The application will remain responsive but care must be taken to handle reentrancy issues.

A password will be returned if the user enters a password successfully. The returned password is valid until the next time a method is called to display another prompt.

`NULL` will be returned if the user cancels or if an error occurs. Check the `error` argument to tell the difference.

#### Parameters

prompt | a prompt |
cancellable | optional cancellation object |
error | location to place error on failure |

#### Returns

the password owned by the prompt, or `NULL`

### gcr_prompt_confirm ()

    GcrPromptReply
    gcr_prompt_confirm (GcrPrompt *prompt,
                        GCancellable *cancellable,
                        GError **error);

Prompts for confirmation asking a cancel/continue style question. Set the various properties on the prompt before calling this function to represent the question correctly.

This method will block until the a response is returned from the prompter.

`GCR_PROMPT_REPLY_CONTINUE` will be returned if the user confirms the prompt. The return value will also be `GCR_PROMPT_REPLY_CANCEL` if the user cancels or if an error occurs. Check the `error` argument to tell the difference.

#### Parameters

prompt | a prompt |
cancellable | optional cancellation object |
error | location to place error on failure |

#### Returns

the reply from the prompt

### gcr_prompt_confirm_async ()

    void
    gcr_prompt_confirm_async (GcrPrompt *prompt,
                              GCancellable *cancellable,
                              GAsyncReadyCallback callback,
                              gpointer user_data);

Prompts for confirmation asking a cancel/continue style question. Set the various properties on the prompt before calling this method to represent the question correctly.

This method will return immediately and complete asynchronously.

#### Parameters

prompt | a prompt |
cancellable | optional cancellation object |
callback | called when the operation completes |
user_data | data to pass to the callback |

### gcr_prompt_confirm_finish ()

    GcrPromptReply
    gcr_prompt_confirm_finish (GcrPrompt *prompt,
                               GAsyncResult *result,
                               GError **error);

Complete an operation to prompt for confirmation.

`GCR_PROMPT_REPLY_CONTINUE` will be returned if the user confirms the prompt. The return value will also be `GCR_PROMPT_REPLY_CANCEL` if the user cancels or if an error occurs. Check the `error` argument to tell the difference.

#### Parameters

prompt | a prompt |
result | asynchronous result passed to callback |
error | location to place error on failure |

#### Returns

the reply from the prompt

### gcr_prompt_confirm_run ()

    GcrPromptReply
    gcr_prompt_confirm_run (GcrPrompt *prompt,
                            GCancellable *cancellable,
                            GError **error);

Prompts for confirmation asking a cancel/continue style question. Set the various properties on the prompt before calling this function to represent the question correctly.

This method will block until the a response is returned from the prompter and will run a main loop similar to a `gtk_dialog_run()`. The application will remain responsive but care must be taken to handle reentrancy issues.

`GCR_PROMPT_REPLY_CONTINUE` will be returned if the user confirms the prompt. The return value will also be `GCR_PROMPT_REPLY_CANCEL` if the user cancels or if an error occurs. Check the `error` argument to tell the difference.

#### Parameters

prompt | a prompt |
cancellable | optional cancellation object |
error | location to place error on failure |

#### Returns

the reply from the prompt

### gcr_prompt_reset ()

    void
    gcr_prompt_reset (GcrPrompt *prompt);

Reset the contents and properties of the prompt.

#### Parameters

prompt | the prompt |

### gcr_prompt_close ()

    void
    gcr_prompt_close (GcrPrompt *prompt);

Closes the prompt so that in can no longer be used to prompt. The various prompt methods will return results as if the user dismissed the prompt.

The prompt may also be closed by the implementor of the GcrPrompt object.

This emits the GcrPrompt::prompt-close signal on the prompt object.

#### Parameters

prompt | a prompt |

### gcr_prompt_get_title ()

    gchar *
    gcr_prompt_get_title (GcrPrompt *prompt);

Gets the title of the prompt.

A prompt implementation may choose not to display the prompt title. The prompt message should contain relevant information.

#### Parameters

prompt | the prompt |

#### Returns

a newly allocated string containing the prompt title.

[transfer full]

### gcr_prompt_set_title ()

    void
    gcr_prompt_set_title (GcrPrompt *prompt,
                          const gchar *title);

Sets the title of the prompt.

A prompt implementation may choose not to display the prompt title. The prompt message should contain relevant information.

#### Parameters

prompt | the prompt |
title | the prompt title |

### gcr_prompt_get_message ()

    gchar *
    gcr_prompt_get_message (GcrPrompt *prompt);

Gets the prompt message for the user.

A prompt implementation should always display this message.

#### Parameters

prompt | the prompt |

#### Returns

a newly allocated string containing the detailed description of the prompt.

[transfer full]

### gcr_prompt_set_message ()

    void
    gcr_prompt_set_message (GcrPrompt *prompt,
                            const gchar *message);

Sets the prompt message for the user.

A prompt implementation should always display this message.

#### Parameters

prompt | the prompt |
message | the prompt message |

### gcr_prompt_get_description ()

    gchar *
    gcr_prompt_get_description (GcrPrompt *prompt);

Get the detailed description of the prompt.

A prompt implementation may choose not to display this detailed description. The prompt message should contain relevant information.

#### Parameters

prompt | the prompt |

#### Returns

a newly allocated string containing the detailed description of the prompt.

[transfer full]

### gcr_prompt_set_description ()

    void
    gcr_prompt_set_description (GcrPrompt *prompt,
                                const gchar *description);

Set the detailed description of the prompt.

A prompt implementation may choose not to display this detailed description. Use `gcr_prompt_set_message()` to set a general message containing relevant information.

#### Parameters

prompt | the prompt |
description | the detailed description |

### gcr_prompt_get_warning ()

    gchar *
    gcr_prompt_get_warning (GcrPrompt *prompt);

Get a prompt warning displayed on the prompt.

This is a warning like "The password is incorrect." usually displayed to the user about a previous 'unsuccessful' prompt.

If this string is `NULL` then no warning is displayed.

#### Parameters

prompt | the prompt |

#### Returns

a newly allocated string containing the prompt warning, or `NULL` if no warning.

[transfer full]

### gcr_prompt_set_warning ()

    void
    gcr_prompt_set_warning (GcrPrompt *prompt,
                            const gchar *warning);

Set a prompt warning displayed on the prompt.

This is a warning like "The password is incorrect." usually displayed to the user about a previous 'unsuccessful' prompt.

If this string is `NULL` then no warning is displayed.

#### Parameters

prompt | the prompt |
warning | the warning or `NULL`. | [allow-none]

### gcr_prompt_get_continue_label ()

    gchar *
    gcr_prompt_get_continue_label (GcrPrompt *prompt);

Get the label for the continue button.

This is the button that results in a `GCR_PROMPT_REPLY_CONTINUE` reply from the prompt.

#### Parameters

prompt | the prompt |

#### Returns

a newly allocated string containing the label.

[transfer full]

### gcr_prompt_set_continue_label ()

    void
    gcr_prompt_set_continue_label (GcrPrompt *prompt,
                                   const gchar *continue_label);

Set the label for the continue button.

This is the button that results in a `GCR_PROMPT_REPLY_CONTINUE` reply from the prompt.

#### Parameters

prompt | the prompt |
continue_label | the label |

### gcr_prompt_get_cancel_label ()

    gchar *
    gcr_prompt_get_cancel_label (GcrPrompt *prompt);

Get the label for the cancel button.

This is the button that results in a `GCR_PROMPT_REPLY_CANCEL` reply from the prompt.

#### Parameters

prompt | the prompt |

#### Returns

a newly allocated string containing the label.

[transfer full]

### gcr_prompt_set_cancel_label ()

    void
    gcr_prompt_set_cancel_label (GcrPrompt *prompt,
                                 const gchar *cancel_label);

Set the label for the continue button.

This is the button that results in a `GCR_PROMPT_REPLY_CANCEL` reply from the prompt.

#### Parameters

prompt | the prompt |
cancel_label | the label |

### gcr_prompt_get_choice_label ()

    gchar *
    gcr_prompt_get_choice_label (GcrPrompt *prompt);

Get the label for the additional choice.

This will be `NULL` if no additional choice is being displayed.

#### Parameters

prompt | the prompt |

#### Returns

a newly allocated string containing the additional choice or `NULL`.

[transfer full]

### gcr_prompt_set_choice_label ()

    void
    gcr_prompt_set_choice_label (GcrPrompt *prompt,
                                 const gchar *choice_label);

Set the label for the additional choice.

If this is a non-`NULL` value then an additional boolean choice will be displayed by the prompt allowing the user to select or deselect it.

The initial value of the choice can be set with the `gcr_prompt_set_choice_label()` method.

If this is `NULL`, then no additional choice is being displayed.

#### Parameters

prompt | the prompt |
choice_label | the additional choice or `NULL`. | [allow-none]

### gcr_prompt_get_choice_chosen ()

    gboolean
    gcr_prompt_get_choice_chosen (GcrPrompt *prompt);

Get whether the additional choice was chosen or not.

The additional choice would have been setup using `gcr_prompt_set_choice_label()`.

#### Parameters

prompt | the prompt |

#### Returns

whether chosen

### gcr_prompt_set_choice_chosen ()

    void
    gcr_prompt_set_choice_chosen (GcrPrompt *prompt,
                                  gboolean chosen);

Set whether the additional choice is chosen or not.

The additional choice should be set up using `gcr_prompt_set_choice_label()`.

#### Parameters

prompt | the prompt |
chosen | whether chosen |

### gcr_prompt_get_password_new ()

    gboolean
    gcr_prompt_get_password_new (GcrPrompt *prompt);

Get whether the prompt will prompt for a new password.

This will cause the prompt implementation to ask the user to confirm the password and/or display other relevant user interface for creating a new password.

#### Parameters

prompt | the prompt |

#### Returns

whether in new password mode or not

### gcr_prompt_set_password_new ()

    void
    gcr_prompt_set_password_new (GcrPrompt *prompt,
                                 gboolean new_password);

Set whether the prompt will prompt for a new password.

This will cause the prompt implementation to ask the user to confirm the password and/or display other relevant user interface for creating a new password.

#### Parameters

prompt | the prompt |
new_password | whether in new password mode or not |

### gcr_prompt_get_password_strength ()

    gint
    gcr_prompt_get_password_strength (GcrPrompt *prompt);

Get indication of the password strength.

Prompts will return a zero value if the password is empty, and a value greater than zero if the password has any characters.

This is only valid after a successful prompt for a password.

#### Parameters

prompt | the prompt |

#### Returns

zero if the password is empty, greater than zero if not

### gcr_prompt_get_caller_window ()

    gchar *
    gcr_prompt_get_caller_window (GcrPrompt *prompt);

Get the string handle of the caller's window.

The caller window indicates to the prompt which window is prompting the user. The prompt may choose to ignore this information or use it in whatever way it sees fit.

#### Parameters

prompt | the prompt |

#### Returns

a newly allocated string containing the string handle of the window.

[transfer full]

### gcr_prompt_set_caller_window ()

    void
    gcr_prompt_set_caller_window (GcrPrompt *prompt,
                                  const gchar *window_id);

Set the string handle of the caller's window.

The caller window indicates to the prompt which window is prompting the user. The prompt may choose to ignore this information or use it in whatever way it sees fit.

#### Parameters

prompt | the prompt |
window_id | the window id |

## Types and Values

### GcrPrompt

    typedef struct _GcrPrompt GcrPrompt;

Represents a GcrPrompt displayed to the user.

### struct GcrPromptIface

    struct GcrPromptIface {
    	GTypeInterface parent_iface;

    	void               (* prompt_password_async)    (GcrPrompt *prompt,
    	                                                 GCancellable *cancellable,
    	                                                 GAsyncReadyCallback callback,
    	                                                 gpointer user_data);

    	const gchar *      (* prompt_password_finish)   (GcrPrompt *prompt,
    	                                                 GAsyncResult *result,
    	                                                 GError **error);

    	void               (* prompt_confirm_async)     (GcrPrompt *prompt,
    	                                                 GCancellable *cancellable,
    	                                                 GAsyncReadyCallback callback,
    	                                                 gpointer user_data);

    	GcrPromptReply     (* prompt_confirm_finish)    (GcrPrompt *prompt,
    	                                                 GAsyncResult *result,
    	                                                 GError **error);

    	void               (* prompt_close)             (GcrPrompt *prompt);
    };

The interface for implementing GcrPrompt.

#### Members

GTypeInterface `parent_iface`; | parent interface |
`prompt_password_async` () | begin a password prompt |
`prompt_password_finish` () | complete a password prompt |
`prompt_confirm_async` () | begin a confirm prompt |
`prompt_confirm_finish` () | complete a confirm prompt |
`prompt_close` () | close a prompt |

### enum GcrPromptReply

Various replies returned by `gcr_prompt_confirm()` and friends.

#### Members

GCR_PROMPT_REPLY_CANCEL | the prompt was cancelled |
GCR_PROMPT_REPLY_CONTINUE | the user replied with 'ok' |

## Property Details

### The `“caller-window”` property

      “caller-window”            gchar *

The string handle of the caller's window.

The caller window indicates to the prompt which window is prompting the user. The prompt may choose to ignore this information or use it in whatever way it sees fit.

Flags: Read / Write / Construct

Default value: NULL

### The `“cancel-label”` property

      “cancel-label”             gchar *

The label for the cancel button in the prompt.

Flags: Read / Write / Construct

Default value: "Cancel"

### The `“choice-chosen”` property

      “choice-chosen”            gboolean

Whether the additional choice is chosen or not.

The additional choice would have been setup using “choice-label”.

Flags: Read / Write

Default value: FALSE

### The `“choice-label”` property

      “choice-label”             gchar *

The label for the additional choice.

If this is a non-`NULL` value then an additional boolean choice will be displayed by the prompt allowing the user to select or deselect it.

If `NULL`, then no additional choice is displayed.

The initial value of the choice can be set with “choice-chosen”.

Flags: Read / Write / Construct

Default value: NULL

### The `“continue-label”` property

      “continue-label”           gchar *

The label for the continue button in the prompt.

Flags: Read / Write / Construct

Default value: "Continue"

### The `“description”` property

      “description”              gchar *

The detailed description of the prompt.

A prompt implementation may choose not to display this detailed description. The prompt message should contain relevant information.

Flags: Read / Write / Construct

Default value: NULL

### The `“message”` property

      “message”                  gchar *

The prompt message for the user.

A prompt implementation should always display this message.

Flags: Read / Write / Construct

Default value: NULL

### The `“password-new”` property

      “password-new”             gboolean

Whether the prompt will prompt for a new password.

This will cause the prompt implementation to ask the user to confirm the password and/or display other relevant user interface for creating a new password.

Flags: Read / Write

Default value: FALSE

### The `“password-strength”` property

      “password-strength”        gint

Indication of the password strength.

Prompts will return a zero value if the password is empty, and a value greater than zero if the password has any characters.

This is only valid after a successful prompt for a password.

Flags: Read

Allowed values: >= 0

Default value: 0

### The `“title”` property

      “title”                    gchar *

The title of the prompt.

A prompt implementation may choose not to display the prompt title. The “message” should contain relevant information.

Flags: Read / Write / Construct

Default value: NULL

### The `“warning”` property

      “warning”                  gchar *

A prompt warning displayed on the prompt, or `NULL` for no warning.

This is a warning like "The password is incorrect." usually displayed to the user about a previous 'unsuccessful' prompt.

Flags: Read / Write / Construct

Default value: NULL

## Signal Details

### The `“prompt-close”` signal

    void
    user_function (GcrPrompt *arg0,
                   gpointer   user_data)

Action signal fired when the prompt is to be closed. After the default handler has run, the prompt is closed. The various prompting methods will return results as if the user dismissed the prompt.

You can use the `gcr_prompt_close()` method to emit this signal.

#### Parameters

user_data | user data set when the signal handler was connected. |

Flags: Run First