LCOV - code coverage report
Current view: top level - gcr - gcr-prompt.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 183 209 87.6 %
Date: 2022-09-04 10:20:22 Functions: 34 36 94.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 82 198 41.4 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * gnome-keyring
       3                 :            :  *
       4                 :            :  * Copyright (C) 2011 Stefan Walter
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU Lesser General Public License as
       8                 :            :  * published by the Free Software Foundation; either version 2.1 of
       9                 :            :  * the License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful, but
      12                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14                 :            :  * Lesser General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU Lesser General Public
      17                 :            :  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
      18                 :            :  *
      19                 :            :  * Author: Stef Walter <stef@thewalter.net>
      20                 :            :  */
      21                 :            : 
      22                 :            : #include "config.h"
      23                 :            : 
      24                 :            : #include "gcr-prompt.h"
      25                 :            : 
      26                 :            : #include <glib/gi18n-lib.h>
      27                 :            : 
      28                 :            : /**
      29                 :            :  * GcrPrompt:
      30                 :            :  *
      31                 :            :  * A prompt displayed to the user. It is an interface with various
      32                 :            :  * implementations.
      33                 :            :  *
      34                 :            :  * Various properties are set on the prompt, and then the prompt is displayed
      35                 :            :  * the various prompt methods like [method@Prompt.password_run].
      36                 :            :  *
      37                 :            :  * A `GcrPrompt` may be used to display multiple related prompts. Most
      38                 :            :  * implementions do not hide the window between display of multiple related
      39                 :            :  * prompts, and the #GcrPrompt must be closed or destroyed in order to make
      40                 :            :  * it go away. This allows the user to see that the prompts are related.
      41                 :            :  *
      42                 :            :  * Use `GcrPromptDialog` (part of gcr-ui) to create an in-process GTK+ dialog
      43                 :            :  * prompt. Use [class@SystemPrompt] to create a system prompt in a prompter
      44                 :            :  * process.
      45                 :            :  *
      46                 :            :  * The prompt implementation will always display the [property@Prompt:message]
      47                 :            :  * property, but may choose not to display the [property@Prompt:description] or
      48                 :            :  * [property@Prompt:title] properties.
      49                 :            :  */
      50                 :            : 
      51                 :            : /**
      52                 :            :  * GcrPromptInterface:
      53                 :            :  * @parent_iface: parent interface
      54                 :            :  * @prompt_password_async: begin a password prompt
      55                 :            :  * @prompt_password_finish: complete a password prompt
      56                 :            :  * @prompt_confirm_async: begin a confirm prompt
      57                 :            :  * @prompt_confirm_finish: complete a confirm prompt
      58                 :            :  * @prompt_close: close a prompt
      59                 :            :  *
      60                 :            :  * The interface for implementing [iface@Prompt].
      61                 :            :  */
      62                 :            : 
      63                 :            : /**
      64                 :            :  * GcrPromptReply:
      65                 :            :  * @GCR_PROMPT_REPLY_CONTINUE: the user replied with 'ok'
      66                 :            :  * @GCR_PROMPT_REPLY_CANCEL: the prompt was cancelled
      67                 :            :  *
      68                 :            :  * Various replies returned by [method@Prompt.confirm] and friends.
      69                 :            :  */
      70                 :            : 
      71                 :            : enum {
      72                 :            :         PROMPT_CLOSE,
      73                 :            :         NUM_SIGNALS
      74                 :            : };
      75                 :            : 
      76                 :            : static guint signals[NUM_SIGNALS];
      77                 :            : 
      78                 :            : typedef struct {
      79                 :            :         GAsyncResult *result;
      80                 :            :         GMainLoop *loop;
      81                 :            :         GMainContext *context;
      82                 :            : } RunClosure;
      83                 :            : 
      84                 :            : static void   gcr_prompt_default_init    (GcrPromptInterface *iface);
      85                 :            : 
      86   [ +  +  +  -  :        375 : G_DEFINE_INTERFACE (GcrPrompt, gcr_prompt, G_TYPE_OBJECT);
                   +  + ]
      87                 :            : 
      88                 :            : static void
      89                 :          1 : gcr_prompt_default_init (GcrPromptInterface *iface)
      90                 :            : {
      91                 :            :         static gsize initialized = 0;
      92                 :            : 
      93   [ +  -  +  -  :          1 :         if (g_once_init_enter (&initialized)) {
                   +  - ]
      94                 :            : 
      95                 :            :                 /**
      96                 :            :                  * GcrPrompt:title:
      97                 :            :                  *
      98                 :            :                  * The title of the prompt.
      99                 :            :                  *
     100                 :            :                  * A prompt implementation may choose not to display the prompt title. The
     101                 :            :                  * #GcrPrompt:message should contain relevant information.
     102                 :            :                  */
     103                 :          1 :                 g_object_interface_install_property (iface,
     104                 :            :                                 g_param_spec_string ("title", "Title", "Prompt title",
     105                 :            :                                                      NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
     106                 :            : 
     107                 :            :                 /**
     108                 :            :                  * GcrPrompt:message:
     109                 :            :                  *
     110                 :            :                  * The prompt message for the user.
     111                 :            :                  *
     112                 :            :                  * A prompt implementation should always display this message.
     113                 :            :                  */
     114                 :          1 :                 g_object_interface_install_property (iface,
     115                 :            :                                 g_param_spec_string ("message", "Message", "Prompt message",
     116                 :            :                                                      NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
     117                 :            : 
     118                 :            :                 /**
     119                 :            :                  * GcrPrompt:description:
     120                 :            :                  *
     121                 :            :                  * The detailed description of the prompt.
     122                 :            :                  *
     123                 :            :                  * A prompt implementation may choose not to display this detailed description.
     124                 :            :                  * The prompt message should contain relevant information.
     125                 :            :                  */
     126                 :          1 :                 g_object_interface_install_property (iface,
     127                 :            :                                 g_param_spec_string ("description", "Description", "Prompt description",
     128                 :            :                                                      NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
     129                 :            : 
     130                 :            :                 /**
     131                 :            :                  * GcrPrompt:warning:
     132                 :            :                  *
     133                 :            :                  * A prompt warning displayed on the prompt, or %NULL for no warning.
     134                 :            :                  *
     135                 :            :                  * This is a warning like "The password is incorrect." usually displayed to the
     136                 :            :                  * user about a previous 'unsuccessful' prompt.
     137                 :            :                  */
     138                 :          1 :                 g_object_interface_install_property (iface,
     139                 :            :                                 g_param_spec_string ("warning", "Warning", "Prompt warning",
     140                 :            :                                                      NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
     141                 :            : 
     142                 :            :                 /**
     143                 :            :                  * GcrPrompt:password-new:
     144                 :            :                  *
     145                 :            :                  * Whether the prompt will prompt for a new password.
     146                 :            :                  *
     147                 :            :                  * This will cause the prompt implementation to ask the user to confirm the
     148                 :            :                  * password and/or display other relevant user interface for creating a new
     149                 :            :                  * password.
     150                 :            :                  */
     151                 :          1 :                 g_object_interface_install_property (iface,
     152                 :            :                                g_param_spec_boolean ("password-new", "Password new", "Whether prompting for a new password",
     153                 :            :                                                      FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
     154                 :            : 
     155                 :            :                 /**
     156                 :            :                  * GcrPrompt:password-strength:
     157                 :            :                  *
     158                 :            :                  * Indication of the password strength.
     159                 :            :                  *
     160                 :            :                  * Prompts will return a zero value if the password is empty, and a value
     161                 :            :                  * greater than zero if the password has any characters.
     162                 :            :                  *
     163                 :            :                  * This is only valid after a successful prompt for a password.
     164                 :            :                  */
     165                 :          1 :                 g_object_interface_install_property (iface,
     166                 :            :                                    g_param_spec_int ("password-strength", "Password strength", "String of new password",
     167                 :            :                                                      0, G_MAXINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
     168                 :            : 
     169                 :            :                 /**
     170                 :            :                  * GcrPrompt:choice-label:
     171                 :            :                  *
     172                 :            :                  * The label for the additional choice.
     173                 :            :                  *
     174                 :            :                  * If this is a non-%NULL value then an additional boolean choice will be
     175                 :            :                  * displayed by the prompt allowing the user to select or deselect it.
     176                 :            :                  *
     177                 :            :                  * If %NULL, then no additional choice is displayed.
     178                 :            :                  *
     179                 :            :                  * The initial value of the choice can be set with #GcrPrompt:choice-chosen.
     180                 :            :                  */
     181                 :          1 :                 g_object_interface_install_property (iface,
     182                 :            :                                 g_param_spec_string ("choice-label", "Choice label", "Label for prompt choice",
     183                 :            :                                                      NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
     184                 :            : 
     185                 :            :                 /**
     186                 :            :                  * GcrPrompt:choice-chosen:
     187                 :            :                  *
     188                 :            :                  * Whether the additional choice is chosen or not.
     189                 :            :                  *
     190                 :            :                  * The additional choice would have been setup using #GcrPrompt:choice-label.
     191                 :            :                  */
     192                 :          1 :                 g_object_interface_install_property (iface,
     193                 :            :                                g_param_spec_boolean ("choice-chosen", "Choice chosen", "Whether prompt choice is chosen",
     194                 :            :                                                      FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
     195                 :            : 
     196                 :            :                 /**
     197                 :            :                  * GcrPrompt:caller-window:
     198                 :            :                  *
     199                 :            :                  * The string handle of the caller's window.
     200                 :            :                  *
     201                 :            :                  * The caller window indicates to the prompt which window is prompting the
     202                 :            :                  * user. The prompt may choose to ignore this information or use it in whatever
     203                 :            :                  * way it sees fit.
     204                 :            :                  *
     205                 :            :                  * In X11, this will be a stringified version of the XWindow handle; in
     206                 :            :                  * Wayland this is the result of an export using the XDG foreign
     207                 :            :                  * protocol.
     208                 :            :                  */
     209                 :          1 :                 g_object_interface_install_property (iface,
     210                 :            :                                 g_param_spec_string ("caller-window", "Caller window", "Window ID of application window requesting prompt",
     211                 :            :                                                      NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
     212                 :            : 
     213                 :            :                 /**
     214                 :            :                  * GcrPrompt:continue-label:
     215                 :            :                  *
     216                 :            :                  * The label for the continue button in the prompt.
     217                 :            :                  */
     218                 :          1 :                 g_object_interface_install_property (iface,
     219                 :            :                                 g_param_spec_string ("continue-label", "Continue label", "Continue button label",
     220                 :            :                                                      _("Continue"), G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
     221                 :            : 
     222                 :            :                 /**
     223                 :            :                  * GcrPrompt:cancel-label:
     224                 :            :                  *
     225                 :            :                  * The label for the cancel button in the prompt.
     226                 :            :                  */
     227                 :          1 :                 g_object_interface_install_property (iface,
     228                 :            :                                 g_param_spec_string ("cancel-label", "Cancel label", "Cancel button label",
     229                 :            :                                                      _("Cancel"), G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
     230                 :            : 
     231                 :            :                 /**
     232                 :            :                  * GcrPrompt::prompt-close:
     233                 :            :                  *
     234                 :            :                  * Action signal fired when the prompt is to be closed. After the default
     235                 :            :                  * handler has run, the prompt is closed. The various prompting methods
     236                 :            :                  * will return results as if the user dismissed the prompt.
     237                 :            :                  *
     238                 :            :                  * You can use the [method@Prompt.close] method to emit this signal.
     239                 :            :                  */
     240                 :          1 :                 signals[PROMPT_CLOSE] = g_signal_new ("prompt-close", GCR_TYPE_PROMPT, G_SIGNAL_RUN_FIRST,
     241                 :            :                                                       G_STRUCT_OFFSET (GcrPromptInterface, prompt_close),
     242                 :            :                                                       NULL, NULL, NULL,
     243                 :            :                                                       G_TYPE_NONE, 0);
     244                 :            : 
     245                 :          1 :                 g_once_init_leave (&initialized, 1);
     246                 :            :         }
     247                 :          1 : }
     248                 :            : 
     249                 :            : static void
     250                 :         14 : run_closure_end (gpointer data)
     251                 :            : {
     252                 :         14 :         RunClosure *closure = data;
     253         [ +  - ]:         14 :         g_clear_object (&closure->result);
     254                 :         14 :         g_main_loop_unref (closure->loop);
     255         [ -  + ]:         14 :         if (closure->context != NULL) {
     256                 :          0 :                 g_main_context_pop_thread_default (closure->context);
     257                 :          0 :                 g_main_context_unref (closure->context);
     258                 :            :         }
     259                 :         14 :         g_free (closure);
     260                 :         14 : }
     261                 :            : 
     262                 :            : static RunClosure *
     263                 :         14 : run_closure_begin (GMainContext *context)
     264                 :            : {
     265                 :         14 :         RunClosure *closure = g_new0 (RunClosure, 1);
     266                 :         14 :         closure->loop = g_main_loop_new (context, FALSE);
     267                 :         14 :         closure->result = NULL;
     268                 :            : 
     269                 :            :         /* We assume ownership of context reference */
     270                 :         14 :         closure->context = context;
     271         [ -  + ]:         14 :         if (closure->context != NULL)
     272                 :          0 :                 g_main_context_push_thread_default (closure->context);
     273                 :            : 
     274                 :         14 :         return closure;
     275                 :            : }
     276                 :            : 
     277                 :            : static void
     278                 :         14 : on_run_complete (GObject *source,
     279                 :            :                  GAsyncResult *result,
     280                 :            :                  gpointer user_data)
     281                 :            : {
     282                 :         14 :         RunClosure *closure = user_data;
     283         [ -  + ]:         14 :         g_return_if_fail (closure->result == NULL);
     284                 :         14 :         closure->result = g_object_ref (result);
     285                 :         14 :         g_main_loop_quit (closure->loop);
     286                 :            : }
     287                 :            : 
     288                 :            : /**
     289                 :            :  * gcr_prompt_reset:
     290                 :            :  * @prompt: the prompt
     291                 :            :  *
     292                 :            :  * Reset the contents and properties of the prompt.
     293                 :            :  */
     294                 :            : void
     295                 :          1 : gcr_prompt_reset (GcrPrompt *prompt)
     296                 :            : {
     297                 :            :         GParamSpec **params;
     298                 :            :         GcrPromptInterface *iface;
     299                 :            :         guint i, n_params;
     300                 :            : 
     301         [ -  + ]:          1 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     302                 :            : 
     303                 :          1 :         iface = GCR_PROMPT_GET_IFACE (prompt);
     304                 :          1 :         params = g_object_interface_list_properties (iface, &n_params);
     305                 :            : 
     306                 :          1 :         g_object_freeze_notify (G_OBJECT (prompt));
     307                 :            : 
     308         [ +  + ]:         12 :         for (i = 0; i < n_params; i++) {
     309         [ +  + ]:         11 :                 if (!(params[i]->flags & G_PARAM_WRITABLE))
     310                 :          1 :                         continue;
     311                 :            : 
     312         [ +  + ]:         10 :                 if (params[i]->value_type == G_TYPE_STRING)
     313                 :          8 :                         g_object_set (prompt, params[i]->name,
     314                 :          8 :                                       ((GParamSpecString *)params[i])->default_value,
     315                 :            :                                       NULL);
     316                 :            : 
     317         [ -  + ]:          2 :                 else if (params[i]->value_type == G_TYPE_INT)
     318                 :          0 :                         g_object_set (prompt, params[i]->name,
     319                 :          0 :                                       ((GParamSpecInt *)params[i])->default_value,
     320                 :            :                                       NULL);
     321                 :            : 
     322         [ +  - ]:          2 :                 else if (params[i]->value_type == G_TYPE_BOOLEAN)
     323                 :          2 :                         g_object_set (prompt, params[i]->name,
     324                 :          2 :                                       ((GParamSpecBoolean *)params[i])->default_value,
     325                 :            :                                       NULL);
     326                 :            : 
     327                 :            :                 else
     328                 :          0 :                         g_assert_not_reached ();
     329                 :            :         }
     330                 :            : 
     331                 :          1 :         g_free (params);
     332                 :            : 
     333                 :          1 :         g_object_thaw_notify (G_OBJECT (prompt));
     334                 :            : }
     335                 :            : 
     336                 :            : /**
     337                 :            :  * gcr_prompt_get_title:
     338                 :            :  * @prompt: the prompt
     339                 :            :  *
     340                 :            :  * Gets the title of the prompt.
     341                 :            :  *
     342                 :            :  * A prompt implementation may choose not to display the prompt title. The
     343                 :            :  * prompt message should contain relevant information.
     344                 :            :  *
     345                 :            :  * Returns: (transfer full): a newly allocated string containing the prompt
     346                 :            :  *          title.
     347                 :            :  */
     348                 :            : gchar *
     349                 :          4 : gcr_prompt_get_title (GcrPrompt *prompt)
     350                 :            : {
     351                 :          4 :         gchar *title = NULL;
     352         [ -  + ]:          4 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
     353                 :          4 :         g_object_get (prompt, "title", &title, NULL);
     354                 :          4 :         return title;
     355                 :            : }
     356                 :            : 
     357                 :            : /**
     358                 :            :  * gcr_prompt_set_title:
     359                 :            :  * @prompt: the prompt
     360                 :            :  * @title: the prompt title
     361                 :            :  *
     362                 :            :  * Sets the title of the prompt.
     363                 :            :  *
     364                 :            :  * A prompt implementation may choose not to display the prompt title. The
     365                 :            :  * prompt message should contain relevant information.
     366                 :            :  */
     367                 :            : void
     368                 :          1 : gcr_prompt_set_title (GcrPrompt *prompt,
     369                 :            :                       const gchar *title)
     370                 :            : {
     371         [ -  + ]:          1 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     372                 :          1 :         g_object_set (prompt, "title", title, NULL);
     373                 :            : }
     374                 :            : 
     375                 :            : /**
     376                 :            :  * gcr_prompt_get_message:
     377                 :            :  * @prompt: the prompt
     378                 :            :  *
     379                 :            :  * Gets the prompt message for the user.
     380                 :            :  *
     381                 :            :  * A prompt implementation should always display this message.
     382                 :            :  *
     383                 :            :  * Returns: (transfer full): a newly allocated string containing the detailed
     384                 :            :  *          description of the prompt
     385                 :            :  */
     386                 :            : gchar *
     387                 :          4 : gcr_prompt_get_message (GcrPrompt *prompt)
     388                 :            : {
     389                 :          4 :         gchar *message = NULL;
     390         [ -  + ]:          4 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
     391                 :          4 :         g_object_get (prompt, "message", &message, NULL);
     392                 :          4 :         return message;
     393                 :            : }
     394                 :            : 
     395                 :            : /**
     396                 :            :  * gcr_prompt_set_message:
     397                 :            :  * @prompt: the prompt
     398                 :            :  * @message: the prompt message
     399                 :            :  *
     400                 :            :  * Sets the prompt message for the user.
     401                 :            :  *
     402                 :            :  * A prompt implementation should always display this message.
     403                 :            :  */
     404                 :            : void
     405                 :          1 : gcr_prompt_set_message (GcrPrompt *prompt,
     406                 :            :                         const gchar *message)
     407                 :            : {
     408         [ -  + ]:          1 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     409                 :          1 :         g_object_set (prompt, "message", message, NULL);
     410                 :            : }
     411                 :            : 
     412                 :            : /**
     413                 :            :  * gcr_prompt_get_description:
     414                 :            :  * @prompt: the prompt
     415                 :            :  *
     416                 :            :  * Get the detailed description of the prompt.
     417                 :            :  *
     418                 :            :  * A prompt implementation may choose not to display this detailed description.
     419                 :            :  * The prompt message should contain relevant information.
     420                 :            :  *
     421                 :            :  * Returns: (transfer full): a newly allocated string containing the detailed
     422                 :            :  *          description of the prompt
     423                 :            :  */
     424                 :            : gchar *
     425                 :          4 : gcr_prompt_get_description (GcrPrompt *prompt)
     426                 :            : {
     427                 :          4 :         gchar *description = NULL;
     428         [ -  + ]:          4 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
     429                 :          4 :         g_object_get (prompt, "description", &description, NULL);
     430                 :          4 :         return description;
     431                 :            : }
     432                 :            : 
     433                 :            : /**
     434                 :            :  * gcr_prompt_set_description:
     435                 :            :  * @prompt: the prompt
     436                 :            :  * @description: the detailed description
     437                 :            :  *
     438                 :            :  * Set the detailed description of the prompt.
     439                 :            :  *
     440                 :            :  * A prompt implementation may choose not to display this detailed description.
     441                 :            :  * Use gcr_prompt_set_message() to set a general message containing relevant
     442                 :            :  * information.
     443                 :            :  */
     444                 :            : void
     445                 :          1 : gcr_prompt_set_description (GcrPrompt *prompt,
     446                 :            :                             const gchar *description)
     447                 :            : {
     448         [ -  + ]:          1 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     449                 :          1 :         g_object_set (prompt, "description", description, NULL);
     450                 :            : }
     451                 :            : 
     452                 :            : /**
     453                 :            :  * gcr_prompt_get_warning:
     454                 :            :  * @prompt: the prompt
     455                 :            :  *
     456                 :            :  * Get a prompt warning displayed on the prompt.
     457                 :            :  *
     458                 :            :  * This is a warning like "The password is incorrect." usually displayed to the
     459                 :            :  * user about a previous 'unsuccessful' prompt.
     460                 :            :  *
     461                 :            :  * If this string is %NULL then no warning is displayed.
     462                 :            :  *
     463                 :            :  * Returns: (transfer full): a newly allocated string containing the prompt
     464                 :            :  *          warning, or %NULL if no warning
     465                 :            :  */
     466                 :            : gchar *
     467                 :          4 : gcr_prompt_get_warning (GcrPrompt *prompt)
     468                 :            : {
     469                 :          4 :         gchar *warning = NULL;
     470         [ -  + ]:          4 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
     471                 :          4 :         g_object_get (prompt, "warning", &warning, NULL);
     472                 :          4 :         return warning;
     473                 :            : }
     474                 :            : 
     475                 :            : /**
     476                 :            :  * gcr_prompt_set_warning:
     477                 :            :  * @prompt: the prompt
     478                 :            :  * @warning: (nullable): the warning or %NULL
     479                 :            :  *
     480                 :            :  * Set a prompt warning displayed on the prompt.
     481                 :            :  *
     482                 :            :  * This is a warning like "The password is incorrect." usually displayed to the
     483                 :            :  * user about a previous 'unsuccessful' prompt.
     484                 :            :  *
     485                 :            :  * If this string is %NULL then no warning is displayed.
     486                 :            :  */
     487                 :            : void
     488                 :          1 : gcr_prompt_set_warning (GcrPrompt *prompt,
     489                 :            :                         const gchar *warning)
     490                 :            : {
     491         [ -  + ]:          1 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     492                 :          1 :         g_object_set (prompt, "warning", warning, NULL);
     493                 :            : }
     494                 :            : 
     495                 :            : /**
     496                 :            :  * gcr_prompt_get_choice_label:
     497                 :            :  * @prompt: the prompt
     498                 :            :  *
     499                 :            :  * Get the label for the additional choice.
     500                 :            :  *
     501                 :            :  * This will be %NULL if no additional choice is being displayed.
     502                 :            :  *
     503                 :            :  * Returns: (transfer full): a newly allocated string containing the additional
     504                 :            :  *          choice or %NULL
     505                 :            :  */
     506                 :            : gchar *
     507                 :          4 : gcr_prompt_get_choice_label (GcrPrompt *prompt)
     508                 :            : {
     509                 :          4 :         gchar *choice_label = NULL;
     510         [ -  + ]:          4 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
     511                 :          4 :         g_object_get (prompt, "choice-label", &choice_label, NULL);
     512                 :          4 :         return choice_label;
     513                 :            : }
     514                 :            : 
     515                 :            : /**
     516                 :            :  * gcr_prompt_set_choice_label:
     517                 :            :  * @prompt: the prompt
     518                 :            :  * @choice_label: (nullable): the additional choice or %NULL
     519                 :            :  *
     520                 :            :  * Set the label for the additional choice.
     521                 :            :  *
     522                 :            :  * If this is a non-%NULL value then an additional boolean choice will be
     523                 :            :  * displayed by the prompt allowing the user to select or deselect it.
     524                 :            :  *
     525                 :            :  * The initial value of the choice can be set with the
     526                 :            :  * gcr_prompt_set_choice_label() method.
     527                 :            :  *
     528                 :            :  * If this is %NULL, then no additional choice is being displayed.
     529                 :            :  */
     530                 :            : void
     531                 :          1 : gcr_prompt_set_choice_label (GcrPrompt *prompt,
     532                 :            :                              const gchar *choice_label)
     533                 :            : {
     534         [ -  + ]:          1 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     535                 :          1 :         g_object_set (prompt, "choice-label", choice_label, NULL);
     536                 :            : }
     537                 :            : 
     538                 :            : /**
     539                 :            :  * gcr_prompt_get_choice_chosen:
     540                 :            :  * @prompt: the prompt
     541                 :            :  *
     542                 :            :  * Get whether the additional choice was chosen or not.
     543                 :            :  *
     544                 :            :  * The additional choice would have been setup using
     545                 :            :  * gcr_prompt_set_choice_label().
     546                 :            :  *
     547                 :            :  * Returns: whether chosen
     548                 :            :  */
     549                 :            : gboolean
     550                 :          5 : gcr_prompt_get_choice_chosen (GcrPrompt *prompt)
     551                 :            : {
     552                 :            :         gboolean choice_chosen;
     553         [ -  + ]:          5 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), FALSE);
     554                 :          5 :         g_object_get (prompt, "choice-chosen", &choice_chosen, NULL);
     555                 :          5 :         return choice_chosen;
     556                 :            : }
     557                 :            : 
     558                 :            : /**
     559                 :            :  * gcr_prompt_set_choice_chosen:
     560                 :            :  * @prompt: the prompt
     561                 :            :  * @chosen: whether chosen
     562                 :            :  *
     563                 :            :  * Set whether the additional choice is chosen or not.
     564                 :            :  *
     565                 :            :  * The additional choice should be set up using gcr_prompt_set_choice_label().
     566                 :            :  */
     567                 :            : void
     568                 :          1 : gcr_prompt_set_choice_chosen (GcrPrompt *prompt,
     569                 :            :                               gboolean chosen)
     570                 :            : {
     571         [ -  + ]:          1 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     572                 :          1 :         g_object_set (prompt, "choice-chosen", chosen, NULL);
     573                 :            : }
     574                 :            : 
     575                 :            : /**
     576                 :            :  * gcr_prompt_get_password_new:
     577                 :            :  * @prompt: the prompt
     578                 :            :  *
     579                 :            :  * Get whether the prompt will prompt for a new password.
     580                 :            :  *
     581                 :            :  * This will cause the prompt implementation to ask the user to confirm the
     582                 :            :  * password and/or display other relevant user interface for creating a new
     583                 :            :  * password.
     584                 :            :  *
     585                 :            :  * Returns: whether in new password mode or not
     586                 :            :  */
     587                 :            : gboolean
     588                 :          4 : gcr_prompt_get_password_new (GcrPrompt *prompt)
     589                 :            : {
     590                 :            :         gboolean password_new;
     591         [ -  + ]:          4 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), FALSE);
     592                 :          4 :         g_object_get (prompt, "password-new", &password_new, NULL);
     593                 :          4 :         return password_new;
     594                 :            : }
     595                 :            : 
     596                 :            : /**
     597                 :            :  * gcr_prompt_set_password_new:
     598                 :            :  * @prompt: the prompt
     599                 :            :  * @new_password: whether in new password mode or not
     600                 :            :  *
     601                 :            :  * Set whether the prompt will prompt for a new password.
     602                 :            :  *
     603                 :            :  * This will cause the prompt implementation to ask the user to confirm the
     604                 :            :  * password and/or display other relevant user interface for creating a new
     605                 :            :  * password.
     606                 :            :  */
     607                 :            : void
     608                 :          1 : gcr_prompt_set_password_new (GcrPrompt *prompt,
     609                 :            :                              gboolean new_password)
     610                 :            : {
     611         [ -  + ]:          1 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     612                 :          1 :         g_object_set (prompt, "password-new", new_password, NULL);
     613                 :            : }
     614                 :            : 
     615                 :            : /**
     616                 :            :  * gcr_prompt_get_password_strength:
     617                 :            :  * @prompt: the prompt
     618                 :            :  *
     619                 :            :  * Get indication of the password strength.
     620                 :            :  *
     621                 :            :  * Prompts will return a zero value if the password is empty, and a value
     622                 :            :  * greater than zero if the password has any characters.
     623                 :            :  *
     624                 :            :  * This is only valid after a successful prompt for a password.
     625                 :            :  *
     626                 :            :  * Returns: zero if the password is empty, greater than zero if not
     627                 :            :  */
     628                 :            : gint
     629                 :          3 : gcr_prompt_get_password_strength (GcrPrompt *prompt)
     630                 :            : {
     631                 :            :         gboolean password_strength;
     632         [ -  + ]:          3 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), 0);
     633                 :          3 :         g_object_get (prompt, "password-strength", &password_strength, NULL);
     634                 :          3 :         return password_strength;
     635                 :            : }
     636                 :            : 
     637                 :            : /**
     638                 :            :  * gcr_prompt_get_caller_window:
     639                 :            :  * @prompt: the prompt
     640                 :            :  *
     641                 :            :  * Get the string handle of the caller's window.
     642                 :            :  *
     643                 :            :  * The caller window indicates to the prompt which window is prompting the
     644                 :            :  * user. The prompt may choose to ignore this information or use it in whatever
     645                 :            :  * way it sees fit.
     646                 :            :  *
     647                 :            :  * Returns: (transfer full): a newly allocated string containing the string
     648                 :            :  *          handle of the window.
     649                 :            :  */
     650                 :            : gchar *
     651                 :          4 : gcr_prompt_get_caller_window (GcrPrompt *prompt)
     652                 :            : {
     653                 :          4 :         gchar *caller_window = NULL;
     654         [ -  + ]:          4 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
     655                 :          4 :         g_object_get (prompt, "caller-window", &caller_window, NULL);
     656                 :          4 :         return caller_window;
     657                 :            : }
     658                 :            : 
     659                 :            : /**
     660                 :            :  * gcr_prompt_set_caller_window:
     661                 :            :  * @prompt: the prompt
     662                 :            :  * @window_id: the window id
     663                 :            :  *
     664                 :            :  * Set the string handle of the caller's window.
     665                 :            :  *
     666                 :            :  * The caller window indicates to the prompt which window is prompting the
     667                 :            :  * user. The prompt may choose to ignore this information or use it in whatever
     668                 :            :  * way it sees fit.
     669                 :            :  */
     670                 :            : void
     671                 :          1 : gcr_prompt_set_caller_window (GcrPrompt *prompt,
     672                 :            :                               const gchar *window_id)
     673                 :            : {
     674         [ -  + ]:          1 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     675                 :          1 :         g_object_set (prompt, "caller-window", window_id, NULL);
     676                 :            : }
     677                 :            : 
     678                 :            : /**
     679                 :            :  * gcr_prompt_get_continue_label:
     680                 :            :  * @prompt: the prompt
     681                 :            :  *
     682                 :            :  * Get the label for the continue button.
     683                 :            :  *
     684                 :            :  * This is the button that results in a %GCR_PROMPT_REPLY_CONTINUE reply
     685                 :            :  * from the prompt.
     686                 :            :  *
     687                 :            :  * Returns: (transfer full): a newly allocated string containing the label
     688                 :            :  */
     689                 :            : gchar *
     690                 :          4 : gcr_prompt_get_continue_label (GcrPrompt *prompt)
     691                 :            : {
     692                 :          4 :         gchar *continue_label = NULL;
     693         [ -  + ]:          4 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
     694                 :          4 :         g_object_get (prompt, "continue-label", &continue_label, NULL);
     695                 :          4 :         return continue_label;
     696                 :            : }
     697                 :            : 
     698                 :            : /**
     699                 :            :  * gcr_prompt_set_continue_label:
     700                 :            :  * @prompt: the prompt
     701                 :            :  * @continue_label: the label
     702                 :            :  *
     703                 :            :  * Set the label for the continue button.
     704                 :            :  *
     705                 :            :  * This is the button that results in a %GCR_PROMPT_REPLY_CONTINUE reply
     706                 :            :  * from the prompt.
     707                 :            :  */
     708                 :            : void
     709                 :          1 : gcr_prompt_set_continue_label (GcrPrompt *prompt,
     710                 :            :                                const gchar *continue_label)
     711                 :            : {
     712         [ -  + ]:          1 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     713                 :          1 :         g_object_set (prompt, "continue-label", continue_label, NULL);
     714                 :            : }
     715                 :            : 
     716                 :            : /**
     717                 :            :  * gcr_prompt_get_cancel_label:
     718                 :            :  * @prompt: the prompt
     719                 :            :  *
     720                 :            :  * Get the label for the cancel button.
     721                 :            :  *
     722                 :            :  * This is the button that results in a %GCR_PROMPT_REPLY_CANCEL reply
     723                 :            :  * from the prompt.
     724                 :            :  *
     725                 :            :  * Returns: (transfer full): a newly allocated string containing the label
     726                 :            :  */
     727                 :            : gchar *
     728                 :          4 : gcr_prompt_get_cancel_label (GcrPrompt *prompt)
     729                 :            : {
     730                 :          4 :         gchar *cancel_label = NULL;
     731                 :          4 :         g_object_get (prompt, "cancel-label", &cancel_label, NULL);
     732                 :          4 :         return cancel_label;
     733                 :            : }
     734                 :            : 
     735                 :            : /**
     736                 :            :  * gcr_prompt_set_cancel_label:
     737                 :            :  * @prompt: the prompt
     738                 :            :  * @cancel_label: the label
     739                 :            :  *
     740                 :            :  * Set the label for the continue button.
     741                 :            :  *
     742                 :            :  * This is the button that results in a %GCR_PROMPT_REPLY_CANCEL reply
     743                 :            :  * from the prompt.
     744                 :            :  */
     745                 :            : void
     746                 :          1 : gcr_prompt_set_cancel_label (GcrPrompt *prompt,
     747                 :            :                              const gchar *cancel_label)
     748                 :            : {
     749         [ -  + ]:          1 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     750                 :          1 :         g_object_set (prompt, "cancel-label", cancel_label, NULL);
     751                 :            : }
     752                 :            : 
     753                 :            : /**
     754                 :            :  * gcr_prompt_password_async: (virtual prompt_password_async)
     755                 :            :  * @prompt: a prompt
     756                 :            :  * @cancellable: optional cancellation object
     757                 :            :  * @callback: called when the operation completes
     758                 :            :  * @user_data: data to pass to the callback
     759                 :            :  *
     760                 :            :  * Prompts for password. Set the various properties on the prompt before calling
     761                 :            :  * this method to explain which password should be entered.
     762                 :            :  *
     763                 :            :  * This method will return immediately and complete asynchronously.
     764                 :            :  */
     765                 :            : void
     766                 :         16 : gcr_prompt_password_async (GcrPrompt *prompt,
     767                 :            :                            GCancellable *cancellable,
     768                 :            :                            GAsyncReadyCallback callback,
     769                 :            :                            gpointer user_data)
     770                 :            : {
     771                 :            :         GcrPromptInterface *iface;
     772                 :            : 
     773         [ -  + ]:         16 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     774   [ +  +  -  +  :         16 :         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
          +  -  +  -  -  
                      + ]
     775                 :            : 
     776                 :         16 :         iface = GCR_PROMPT_GET_IFACE (prompt);
     777         [ -  + ]:         16 :         g_return_if_fail (iface->prompt_password_async);
     778                 :            : 
     779                 :         16 :         (iface->prompt_password_async) (prompt, cancellable, callback, user_data);
     780                 :            : }
     781                 :            : 
     782                 :            : /**
     783                 :            :  * gcr_prompt_password_finish: (virtual prompt_password_finish)
     784                 :            :  * @prompt: a prompt
     785                 :            :  * @result: asynchronous result passed to callback
     786                 :            :  * @error: location to place error on failure
     787                 :            :  *
     788                 :            :  * Complete an operation to prompt for a password.
     789                 :            :  *
     790                 :            :  * A password will be returned if the user enters a password successfully.
     791                 :            :  * The returned password is valid until the next time a method is called
     792                 :            :  * to display another prompt.
     793                 :            :  *
     794                 :            :  * %NULL will be returned if the user cancels or if an error occurs. Check the
     795                 :            :  * @error argument to tell the difference.
     796                 :            :  *
     797                 :            :  * Returns: the password owned by the prompt, or %NULL
     798                 :            :  */
     799                 :            : const gchar *
     800                 :         14 : gcr_prompt_password_finish (GcrPrompt *prompt,
     801                 :            :                             GAsyncResult *result,
     802                 :            :                             GError **error)
     803                 :            : {
     804                 :            :         GcrPromptInterface *iface;
     805                 :            : 
     806         [ -  + ]:         14 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
     807   [ -  +  +  -  :         14 :         g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
             -  +  -  + ]
     808   [ +  -  -  + ]:         14 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
     809                 :            : 
     810                 :         14 :         iface = GCR_PROMPT_GET_IFACE (prompt);
     811         [ -  + ]:         14 :         g_return_val_if_fail (iface->prompt_password_async, NULL);
     812                 :            : 
     813                 :         14 :         return (iface->prompt_password_finish) (prompt, result, error);
     814                 :            : }
     815                 :            : 
     816                 :            : /**
     817                 :            :  * gcr_prompt_password:
     818                 :            :  * @prompt: a prompt
     819                 :            :  * @cancellable: optional cancellation object
     820                 :            :  * @error: location to place error on failure
     821                 :            :  *
     822                 :            :  * Prompts for password. Set the various properties on the prompt before calling
     823                 :            :  * this method to explain which password should be entered.
     824                 :            :  *
     825                 :            :  * This method will block until the a response is returned from the prompter.
     826                 :            :  *
     827                 :            :  * A password will be returned if the user enters a password successfully.
     828                 :            :  * The returned password is valid until the next time a method is called
     829                 :            :  * to display another prompt.
     830                 :            :  *
     831                 :            :  * %NULL will be returned if the user cancels or if an error occurs. Check the
     832                 :            :  * @error argument to tell the difference.
     833                 :            :  *
     834                 :            :  * Returns: the password owned by the prompt, or %NULL
     835                 :            :  */
     836                 :            : const gchar *
     837                 :          0 : gcr_prompt_password (GcrPrompt *prompt,
     838                 :            :                      GCancellable *cancellable,
     839                 :            :                      GError **error)
     840                 :            : {
     841                 :            :         RunClosure *closure;
     842                 :            :         const gchar *reply;
     843                 :            : 
     844         [ #  # ]:          0 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
     845   [ #  #  #  #  :          0 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
          #  #  #  #  #  
                      # ]
     846   [ #  #  #  # ]:          0 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
     847                 :            : 
     848                 :          0 :         closure = run_closure_begin (g_main_context_new ());
     849                 :            : 
     850                 :          0 :         gcr_prompt_password_async (prompt, cancellable, on_run_complete, closure);
     851                 :            : 
     852                 :          0 :         g_main_loop_run (closure->loop);
     853                 :            : 
     854                 :          0 :         reply = gcr_prompt_password_finish (prompt, closure->result, error);
     855                 :          0 :         run_closure_end (closure);
     856                 :            : 
     857                 :          0 :         return reply;
     858                 :            : }
     859                 :            : 
     860                 :            : /**
     861                 :            :  * gcr_prompt_password_run:
     862                 :            :  * @prompt: a prompt
     863                 :            :  * @cancellable: optional cancellation object
     864                 :            :  * @error: location to place error on failure
     865                 :            :  *
     866                 :            :  * Prompts for password. Set the various properties on the prompt before calling
     867                 :            :  * this method to explain which password should be entered.
     868                 :            :  *
     869                 :            :  * This method will block until the a response is returned from the prompter
     870                 :            :  * and will run a main loop similar to a gtk_dialog_run(). The application
     871                 :            :  * will remain responsive but care must be taken to handle reentrancy issues.
     872                 :            :  *
     873                 :            :  * A password will be returned if the user enters a password successfully.
     874                 :            :  * The returned password is valid until the next time a method is called
     875                 :            :  * to display another prompt.
     876                 :            :  *
     877                 :            :  * %NULL will be returned if the user cancels or if an error occurs. Check the
     878                 :            :  * @error argument to tell the difference.
     879                 :            :  *
     880                 :            :  * Returns: the password owned by the prompt, or %NULL
     881                 :            :  */
     882                 :            : const gchar *
     883                 :          6 : gcr_prompt_password_run (GcrPrompt *prompt,
     884                 :            :                          GCancellable *cancellable,
     885                 :            :                          GError **error)
     886                 :            : {
     887                 :            :         RunClosure *closure;
     888                 :            :         const gchar *reply;
     889                 :            : 
     890         [ -  + ]:          6 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), NULL);
     891   [ -  +  -  -  :          6 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
          -  -  -  -  -  
                      - ]
     892   [ +  -  -  + ]:          6 :         g_return_val_if_fail (error == NULL || *error == NULL, NULL);
     893                 :            : 
     894                 :          6 :         closure = run_closure_begin (NULL);
     895                 :            : 
     896                 :          6 :         gcr_prompt_password_async (prompt, cancellable, on_run_complete, closure);
     897                 :            : 
     898                 :          6 :         g_main_loop_run (closure->loop);
     899                 :            : 
     900                 :          6 :         reply = gcr_prompt_password_finish (prompt, closure->result, error);
     901                 :          6 :         run_closure_end (closure);
     902                 :            : 
     903                 :          6 :         return reply;
     904                 :            : }
     905                 :            : 
     906                 :            : /**
     907                 :            :  * gcr_prompt_confirm_async: (virtual prompt_confirm_async)
     908                 :            :  * @prompt: a prompt
     909                 :            :  * @cancellable: optional cancellation object
     910                 :            :  * @callback: called when the operation completes
     911                 :            :  * @user_data: data to pass to the callback
     912                 :            :  *
     913                 :            :  * Prompts for confirmation asking a cancel/continue style question.
     914                 :            :  * Set the various properties on the prompt before calling this method to
     915                 :            :  * represent the question correctly.
     916                 :            :  *
     917                 :            :  * This method will return immediately and complete asynchronously.
     918                 :            :  */
     919                 :            : void
     920                 :         16 : gcr_prompt_confirm_async (GcrPrompt *prompt,
     921                 :            :                           GCancellable *cancellable,
     922                 :            :                           GAsyncReadyCallback callback,
     923                 :            :                           gpointer user_data)
     924                 :            : {
     925                 :            :         GcrPromptInterface *iface;
     926                 :            : 
     927         [ -  + ]:         16 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
     928   [ +  +  -  +  :         16 :         g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
          +  -  +  -  -  
                      + ]
     929                 :            : 
     930                 :         16 :         iface = GCR_PROMPT_GET_IFACE (prompt);
     931         [ -  + ]:         16 :         g_return_if_fail (iface->prompt_confirm_async);
     932                 :            : 
     933                 :         16 :         (iface->prompt_confirm_async) (prompt, cancellable, callback, user_data);
     934                 :            : }
     935                 :            : 
     936                 :            : /**
     937                 :            :  * gcr_prompt_confirm_finish: (virtual prompt_confirm_finish)
     938                 :            :  * @prompt: a prompt
     939                 :            :  * @result: asynchronous result passed to callback
     940                 :            :  * @error: location to place error on failure
     941                 :            :  *
     942                 :            :  * Complete an operation to prompt for confirmation.
     943                 :            :  *
     944                 :            :  * %GCR_PROMPT_REPLY_CONTINUE will be returned if the user confirms the prompt. The
     945                 :            :  * return value will also be %GCR_PROMPT_REPLY_CANCEL if the user cancels or if
     946                 :            :  * an error occurs. Check the @error argument to tell the difference.
     947                 :            :  *
     948                 :            :  * Returns: the reply from the prompt
     949                 :            :  */
     950                 :            : GcrPromptReply
     951                 :         16 : gcr_prompt_confirm_finish (GcrPrompt *prompt,
     952                 :            :                            GAsyncResult *result,
     953                 :            :                            GError **error)
     954                 :            : {
     955                 :            :         GcrPromptInterface *iface;
     956                 :            : 
     957         [ -  + ]:         16 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), GCR_PROMPT_REPLY_CANCEL);
     958   [ -  +  +  -  :         16 :         g_return_val_if_fail (G_IS_ASYNC_RESULT (result), GCR_PROMPT_REPLY_CANCEL);
             -  +  -  + ]
     959   [ +  -  -  + ]:         16 :         g_return_val_if_fail (error == NULL || *error == NULL, GCR_PROMPT_REPLY_CANCEL);
     960                 :            : 
     961                 :         16 :         iface = GCR_PROMPT_GET_IFACE (prompt);
     962         [ -  + ]:         16 :         g_return_val_if_fail (iface->prompt_confirm_async, GCR_PROMPT_REPLY_CANCEL);
     963                 :            : 
     964                 :         16 :         return (iface->prompt_confirm_finish) (prompt, result, error);
     965                 :            : }
     966                 :            : 
     967                 :            : /**
     968                 :            :  * gcr_prompt_confirm:
     969                 :            :  * @prompt: a prompt
     970                 :            :  * @cancellable: optional cancellation object
     971                 :            :  * @error: location to place error on failure
     972                 :            :  *
     973                 :            :  * Prompts for confirmation asking a cancel/continue style question.
     974                 :            :  * Set the various properties on the prompt before calling this function to
     975                 :            :  * represent the question correctly.
     976                 :            :  *
     977                 :            :  * This method will block until the a response is returned from the prompter.
     978                 :            :  *
     979                 :            :  * %GCR_PROMPT_REPLY_CONTINUE will be returned if the user confirms the prompt. The
     980                 :            :  * return value will also be %GCR_PROMPT_REPLY_CANCEL if the user cancels or if
     981                 :            :  * an error occurs. Check the @error argument to tell the difference.
     982                 :            :  *
     983                 :            :  * Returns: the reply from the prompt
     984                 :            :  */
     985                 :            : GcrPromptReply
     986                 :          0 : gcr_prompt_confirm (GcrPrompt *prompt,
     987                 :            :                     GCancellable *cancellable,
     988                 :            :                     GError **error)
     989                 :            : {
     990                 :            :         RunClosure *closure;
     991                 :            :         GcrPromptReply reply;
     992                 :            : 
     993         [ #  # ]:          0 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), GCR_PROMPT_REPLY_CANCEL);
     994   [ #  #  #  #  :          0 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), GCR_PROMPT_REPLY_CANCEL);
          #  #  #  #  #  
                      # ]
     995   [ #  #  #  # ]:          0 :         g_return_val_if_fail (error == NULL || *error == NULL, GCR_PROMPT_REPLY_CANCEL);
     996                 :            : 
     997                 :          0 :         closure = run_closure_begin (g_main_context_new ());
     998                 :            : 
     999                 :          0 :         gcr_prompt_confirm_async (prompt, cancellable, on_run_complete, closure);
    1000                 :            : 
    1001                 :          0 :         g_main_loop_run (closure->loop);
    1002                 :            : 
    1003                 :          0 :         reply = gcr_prompt_confirm_finish (prompt, closure->result, error);
    1004                 :          0 :         run_closure_end (closure);
    1005                 :            : 
    1006                 :          0 :         return reply;
    1007                 :            : }
    1008                 :            : 
    1009                 :            : /**
    1010                 :            :  * gcr_prompt_confirm_run:
    1011                 :            :  * @prompt: a prompt
    1012                 :            :  * @cancellable: optional cancellation object
    1013                 :            :  * @error: location to place error on failure
    1014                 :            :  *
    1015                 :            :  * Prompts for confirmation asking a cancel/continue style question.
    1016                 :            :  * Set the various properties on the prompt before calling this function to
    1017                 :            :  * represent the question correctly.
    1018                 :            :  *
    1019                 :            :  * This method will block until the a response is returned from the prompter
    1020                 :            :  * and will run a main loop similar to a `gtk_dialog_run()`. The application
    1021                 :            :  * will remain responsive but care must be taken to handle reentrancy issues.
    1022                 :            :  *
    1023                 :            :  * %GCR_PROMPT_REPLY_CONTINUE will be returned if the user confirms the prompt. The
    1024                 :            :  * return value will also be %GCR_PROMPT_REPLY_CANCEL if the user cancels or if
    1025                 :            :  * an error occurs. Check the @error argument to tell the difference.
    1026                 :            :  *
    1027                 :            :  * Returns: the reply from the prompt
    1028                 :            :  */
    1029                 :            : GcrPromptReply
    1030                 :          8 : gcr_prompt_confirm_run (GcrPrompt *prompt,
    1031                 :            :                         GCancellable *cancellable,
    1032                 :            :                         GError **error)
    1033                 :            : {
    1034                 :            :         RunClosure *closure;
    1035                 :            :         GcrPromptReply reply;
    1036                 :            : 
    1037         [ -  + ]:          8 :         g_return_val_if_fail (GCR_IS_PROMPT (prompt), GCR_PROMPT_REPLY_CANCEL);
    1038   [ -  +  -  -  :          8 :         g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), GCR_PROMPT_REPLY_CANCEL);
          -  -  -  -  -  
                      - ]
    1039   [ +  -  -  + ]:          8 :         g_return_val_if_fail (error == NULL || *error == NULL, GCR_PROMPT_REPLY_CANCEL);
    1040                 :            : 
    1041                 :          8 :         closure = run_closure_begin (NULL);
    1042                 :            : 
    1043                 :          8 :         gcr_prompt_confirm_async (prompt, cancellable, on_run_complete, closure);
    1044                 :            : 
    1045                 :          8 :         g_main_loop_run (closure->loop);
    1046                 :            : 
    1047                 :          8 :         reply = gcr_prompt_confirm_finish (prompt, closure->result, error);
    1048                 :          8 :         run_closure_end (closure);
    1049                 :            : 
    1050                 :          8 :         return reply;
    1051                 :            : }
    1052                 :            : 
    1053                 :            : /**
    1054                 :            :  * gcr_prompt_close:
    1055                 :            :  * @prompt: a prompt
    1056                 :            :  *
    1057                 :            :  * Closes the prompt so that in can no longer be used to prompt. The various
    1058                 :            :  * prompt methods will return results as if the user dismissed the prompt.
    1059                 :            :  *
    1060                 :            :  * The prompt may also be closed by the implementor of the prompt object.
    1061                 :            :  *
    1062                 :            :  * This emits the [signal@Prompt::prompt-close] signal on the prompt object.
    1063                 :            :  */
    1064                 :            : void
    1065                 :         41 : gcr_prompt_close (GcrPrompt *prompt)
    1066                 :            : {
    1067         [ -  + ]:         41 :         g_return_if_fail (GCR_IS_PROMPT (prompt));
    1068                 :         41 :         g_signal_emit (prompt, signals[PROMPT_CLOSE], 0);
    1069                 :            : }

Generated by: LCOV version 1.14