[gcr/wip/gcr4: 2/2] gcr: Remove GcrPromptReply and replace it with a boolean




commit 608330423175c4976b50eedec3fb88df2af35c78
Author: Corentin Noël <corentin noel collabora com>
Date:   Thu Oct 7 15:53:00 2021 +0200

    gcr: Remove GcrPromptReply and replace it with a boolean
    
    CONTINUE is true and CANCELLED is false.

 gcr/gcr-mock-prompter.c   |  6 ++---
 gcr/gcr-prompt.c          | 59 +++++++++++++++++++----------------------------
 gcr/gcr-prompt.h          | 13 ++++-------
 gcr/gcr-system-prompt.c   | 17 +++++++-------
 gcr/gcr-system-prompter.c |  6 ++---
 gcr/test-system-prompt.c  |  8 +++----
 ui/frob-prompt.c          |  4 ++--
 ui/gcr-prompt-dialog.c    | 18 +++++++--------
 8 files changed, 57 insertions(+), 74 deletions(-)
---
diff --git a/gcr/gcr-mock-prompter.c b/gcr/gcr-mock-prompter.c
index 8a1a159..0495117 100644
--- a/gcr/gcr-mock-prompter.c
+++ b/gcr/gcr-mock-prompter.c
@@ -460,16 +460,16 @@ gcr_mock_prompt_confirm_async (GcrPrompt *prompt,
        g_object_unref (res);
 }
 
-static GcrPromptReply
+static gboolean
 gcr_mock_prompt_confirm_finish (GcrPrompt *prompt,
                                 GAsyncResult *result,
                                 GError **error)
 {
        g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (prompt),
-                             gcr_mock_prompt_confirm_async), GCR_PROMPT_REPLY_CANCEL);
+                             gcr_mock_prompt_confirm_async), FALSE);
 
        return g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (result)) ?
-                      GCR_PROMPT_REPLY_CONTINUE : GCR_PROMPT_REPLY_CANCEL;
+                      TRUE : FALSE;
 }
 
 static void
diff --git a/gcr/gcr-prompt.c b/gcr/gcr-prompt.c
index d62f258..e21e49e 100644
--- a/gcr/gcr-prompt.c
+++ b/gcr/gcr-prompt.c
@@ -67,14 +67,6 @@
  * The interface for implementing #GcrPrompt.
  */
 
-/**
- * GcrPromptReply:
- * @GCR_PROMPT_REPLY_CONTINUE: the user replied with 'ok'
- * @GCR_PROMPT_REPLY_CANCEL: the prompt was cancelled
- *
- * Various replies returned by gcr_prompt_confirm() and friends.
- */
-
 enum {
        PROMPT_CLOSE,
        NUM_SIGNALS
@@ -941,25 +933,24 @@ gcr_prompt_confirm_async (GcrPrompt *prompt,
  *
  * 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.
+ * %TRUE will be returned if the user confirms the prompt. Check the @error
+ * argument to tell the difference between cancellation and error.
  *
- * Returns: the reply from the prompt
+ * Returns: %TRUE if the user confirmed the prompt
  */
-GcrPromptReply
+gboolean
 gcr_prompt_confirm_finish (GcrPrompt *prompt,
                            GAsyncResult *result,
                            GError **error)
 {
        GcrPromptInterface *iface;
 
-       g_return_val_if_fail (GCR_IS_PROMPT (prompt), GCR_PROMPT_REPLY_CANCEL);
-       g_return_val_if_fail (G_IS_ASYNC_RESULT (result), GCR_PROMPT_REPLY_CANCEL);
-       g_return_val_if_fail (error == NULL || *error == NULL, GCR_PROMPT_REPLY_CANCEL);
+       g_return_val_if_fail (GCR_IS_PROMPT (prompt), FALSE);
+       g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
        iface = GCR_PROMPT_GET_IFACE (prompt);
-       g_return_val_if_fail (iface->prompt_confirm_async, GCR_PROMPT_REPLY_CANCEL);
+       g_return_val_if_fail (iface->prompt_confirm_async, FALSE);
 
        return (iface->prompt_confirm_finish) (prompt, result, error);
 }
@@ -976,23 +967,22 @@ gcr_prompt_confirm_finish (GcrPrompt *prompt,
  *
  * 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.
+ * %TRUE will be returned if the user confirms the prompt. Check the @error
+ * argument to tell the difference between cancellation and error.
  *
- * Returns: the reply from the prompt
+ * Returns: %TRUE if the user confirmed the prompt
  */
-GcrPromptReply
+gboolean
 gcr_prompt_confirm (GcrPrompt *prompt,
                     GCancellable *cancellable,
                     GError **error)
 {
        RunClosure *closure;
-       GcrPromptReply reply;
+       gboolean reply;
 
-       g_return_val_if_fail (GCR_IS_PROMPT (prompt), GCR_PROMPT_REPLY_CANCEL);
-       g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), GCR_PROMPT_REPLY_CANCEL);
-       g_return_val_if_fail (error == NULL || *error == NULL, GCR_PROMPT_REPLY_CANCEL);
+       g_return_val_if_fail (GCR_IS_PROMPT (prompt), FALSE);
+       g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
        closure = run_closure_begin (g_main_context_new ());
 
@@ -1020,23 +1010,22 @@ gcr_prompt_confirm (GcrPrompt *prompt,
  * 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.
+ * %TRUE will be returned if the user confirms the prompt. Check the @error
+ * argument to tell the difference between cancellation and error.
  *
- * Returns: the reply from the prompt
+ * Returns: %TRUE if the user confirmed the prompt
  */
-GcrPromptReply
+gboolean
 gcr_prompt_confirm_run (GcrPrompt *prompt,
                         GCancellable *cancellable,
                         GError **error)
 {
        RunClosure *closure;
-       GcrPromptReply reply;
+       gboolean reply;
 
-       g_return_val_if_fail (GCR_IS_PROMPT (prompt), GCR_PROMPT_REPLY_CANCEL);
-       g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), GCR_PROMPT_REPLY_CANCEL);
-       g_return_val_if_fail (error == NULL || *error == NULL, GCR_PROMPT_REPLY_CANCEL);
+       g_return_val_if_fail (GCR_IS_PROMPT (prompt), FALSE);
+       g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
+       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
        closure = run_closure_begin (NULL);
 
diff --git a/gcr/gcr-prompt.h b/gcr/gcr-prompt.h
index ed850ec..2e1a916 100644
--- a/gcr/gcr-prompt.h
+++ b/gcr/gcr-prompt.h
@@ -32,11 +32,6 @@
 
 G_BEGIN_DECLS
 
-typedef enum {
-       GCR_PROMPT_REPLY_CANCEL = 0,
-       GCR_PROMPT_REPLY_CONTINUE = 1,
-} GcrPromptReply;
-
 #define GCR_TYPE_PROMPT gcr_prompt_get_type ()
 G_DECLARE_INTERFACE(GcrPrompt, gcr_prompt, GCR, PROMPT, GObject)
 
@@ -57,7 +52,7 @@ struct _GcrPromptInterface {
                                                         GAsyncReadyCallback callback,
                                                         gpointer user_data);
 
-       GcrPromptReply     (* prompt_confirm_finish)    (GcrPrompt *prompt,
+       gboolean           (* prompt_confirm_finish)    (GcrPrompt *prompt,
                                                         GAsyncResult *result,
                                                         GError **error);
 
@@ -140,15 +135,15 @@ void                 gcr_prompt_confirm_async             (GcrPrompt *prompt,
                                                            GAsyncReadyCallback callback,
                                                            gpointer user_data);
 
-GcrPromptReply       gcr_prompt_confirm_finish            (GcrPrompt *prompt,
+gboolean             gcr_prompt_confirm_finish            (GcrPrompt *prompt,
                                                            GAsyncResult *result,
                                                            GError **error);
 
-GcrPromptReply       gcr_prompt_confirm                   (GcrPrompt *prompt,
+gboolean             gcr_prompt_confirm                   (GcrPrompt *prompt,
                                                            GCancellable *cancellable,
                                                            GError **error);
 
-GcrPromptReply       gcr_prompt_confirm_run               (GcrPrompt *prompt,
+gboolean             gcr_prompt_confirm_run               (GcrPrompt *prompt,
                                                            GCancellable *cancellable,
                                                            GError **error);
 
diff --git a/gcr/gcr-system-prompt.c b/gcr/gcr-system-prompt.c
index f444931..d9dce08 100644
--- a/gcr/gcr-system-prompt.c
+++ b/gcr/gcr-system-prompt.c
@@ -1234,24 +1234,23 @@ perform_prompt_async (GcrSystemPrompt *self,
        g_free (sent);
 }
 
-static GcrPromptReply
+static gboolean
 handle_last_response (GcrSystemPrompt *self)
 {
-       GcrPromptReply response;
+       gboolean response;
 
-       g_return_val_if_fail (self->pv->last_response != NULL,
-                             GCR_PROMPT_REPLY_CANCEL);
+       g_return_val_if_fail (self->pv->last_response != NULL, FALSE);
 
        if (g_str_equal (self->pv->last_response, GCR_DBUS_PROMPT_REPLY_YES)) {
-               response = GCR_PROMPT_REPLY_CONTINUE;
+               response = TRUE;
 
        } else if (g_str_equal (self->pv->last_response, GCR_DBUS_PROMPT_REPLY_NO) ||
                   g_str_equal (self->pv->last_response, GCR_DBUS_PROMPT_REPLY_NONE)) {
-               response = GCR_PROMPT_REPLY_CANCEL;
+               response = FALSE;
 
        } else {
                g_warning ("unknown response from prompter: %s", self->pv->last_response);
-               response = GCR_PROMPT_REPLY_CANCEL;
+               response = FALSE;
        }
 
        return response;
@@ -1284,7 +1283,7 @@ gcr_system_prompt_password_finish (GcrPrompt *prompt,
        if (g_simple_async_result_propagate_error (res, error))
                return FALSE;
 
-       if (handle_last_response (self) == GCR_PROMPT_REPLY_CONTINUE)
+       if (handle_last_response (self))
                return gcr_secret_exchange_get_secret (self->pv->exchange, NULL);
 
        return NULL;
@@ -1302,7 +1301,7 @@ gcr_system_prompt_confirm_async (GcrPrompt *prompt,
                              cancellable, callback, user_data);
 }
 
-static GcrPromptReply
+static gboolean
 gcr_system_prompt_confirm_finish (GcrPrompt *prompt,
                                   GAsyncResult *result,
                                   GError **error)
diff --git a/gcr/gcr-system-prompter.c b/gcr/gcr-system-prompter.c
index bb5c933..8dba83c 100644
--- a/gcr/gcr-system-prompter.c
+++ b/gcr/gcr-system-prompter.c
@@ -835,7 +835,7 @@ on_prompt_confirm (GObject *source,
                    gpointer user_data)
 {
        ActivePrompt *active = user_data;
-       GcrPromptReply reply;
+       gboolean reply;
        GError *error = NULL;
        const gchar *response;
 
@@ -853,10 +853,10 @@ on_prompt_confirm (GObject *source,
        }
 
        switch (reply) {
-       case GCR_PROMPT_REPLY_CONTINUE:
+       case TRUE:
                response = GCR_DBUS_PROMPT_REPLY_YES;
                break;
-       case GCR_PROMPT_REPLY_CANCEL:
+       case FALSE:
                response = GCR_DBUS_PROMPT_REPLY_NO;
                break;
        default:
diff --git a/gcr/test-system-prompt.c b/gcr/test-system-prompt.c
index 7b3b2e7..ba60a8f 100644
--- a/gcr/test-system-prompt.c
+++ b/gcr/test-system-prompt.c
@@ -601,7 +601,7 @@ test_close_from_prompter (Test *test,
 
        ret = gcr_prompt_confirm_run (prompt, NULL, &error);
        g_assert_no_error (error);
-       g_assert (ret == GCR_PROMPT_REPLY_CANCEL);
+       g_assert (ret == FALSE);
 
        /* The prompt should be closed now, these shouldn't reach the mock prompter */
 
@@ -610,7 +610,7 @@ test_close_from_prompter (Test *test,
 
        ret = gcr_prompt_confirm_run (prompt, NULL, &error);
        g_assert_no_error (error);
-       g_assert (ret == GCR_PROMPT_REPLY_CANCEL);
+       g_assert (ret == FALSE);
 
        password = gcr_prompt_password_run (prompt, NULL, &error);
        g_assert_no_error (error);
@@ -643,7 +643,7 @@ test_after_close_dismisses (Test *test,
 
        ret = gcr_prompt_confirm_run (prompt, NULL, &error);
        g_assert_no_error (error);
-       g_assert (ret == GCR_PROMPT_REPLY_CONTINUE);
+       g_assert (ret == TRUE);
 
        gcr_prompt_close (prompt);
        g_assert (prompt_closed);
@@ -652,7 +652,7 @@ test_after_close_dismisses (Test *test,
 
        ret = gcr_prompt_confirm_run (prompt, NULL, &error);
        g_assert_no_error (error);
-       g_assert (ret == GCR_PROMPT_REPLY_CANCEL);
+       g_assert (ret == FALSE);
 
        password = gcr_prompt_password_run (prompt, NULL, &error);
        g_assert_no_error (error);
diff --git a/ui/frob-prompt.c b/ui/frob-prompt.c
index 20f5482..28b771d 100644
--- a/ui/frob-prompt.c
+++ b/ui/frob-prompt.c
@@ -95,7 +95,7 @@ prompt_perform (GtkWidget *parent)
        GcrPrompt *prompt;
        const gchar *key;
        const gchar *password;
-       GcrPromptReply reply;
+       gboolean reply;
        gboolean cont = TRUE;
        GMainLoop *loop;
        gchar *type;
@@ -184,7 +184,7 @@ prompt_perform (GtkWidget *parent)
                        if (error != NULL)
                                g_error ("couldn't prompt for confirm: %s", error->message);
                        g_print ("prompt confirm: %d\n", reply);
-                       cont = (reply != GCR_PROMPT_REPLY_CANCEL);
+                       cont = (reply != FALSE);
                } else {
                        g_error ("unsupported prompt type: %s", type);
                }
diff --git a/ui/gcr-prompt-dialog.c b/ui/gcr-prompt-dialog.c
index bc6643c..dd2c2ab 100644
--- a/ui/gcr-prompt-dialog.c
+++ b/ui/gcr-prompt-dialog.c
@@ -103,7 +103,7 @@ struct _GcrPromptDialogPrivate {
        gchar *cancel_label;
 
        GSimpleAsyncResult *async_result;
-       GcrPromptReply last_reply;
+       gboolean last_reply;
        GtkWidget *widget_grid;
        GtkWidget *continue_button;
        GtkWidget *spinner;
@@ -798,11 +798,11 @@ gcr_prompt_dialog_response (GtkDialog *dialog,
                default:
                        break;
                }
-               self->pv->last_reply = GCR_PROMPT_REPLY_CONTINUE;
+               self->pv->last_reply = TRUE;
                break;
 
        default:
-               self->pv->last_reply = GCR_PROMPT_REPLY_CANCEL;
+               self->pv->last_reply = FALSE;
                break;
        }
 
@@ -954,7 +954,7 @@ gcr_prompt_dialog_password_async (GcrPrompt *prompt,
        gtk_entry_buffer_set_text (self->pv->confirm_buffer, "", 0);
 
        if (self->pv->was_closed) {
-               self->pv->last_reply = GCR_PROMPT_REPLY_CANCEL;
+               self->pv->last_reply = FALSE;
                g_simple_async_result_complete_in_idle (self->pv->async_result);
                return;
        }
@@ -989,7 +989,7 @@ gcr_prompt_dialog_password_finish (GcrPrompt *prompt,
        if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
                return NULL;
 
-       if (self->pv->last_reply == GCR_PROMPT_REPLY_CONTINUE)
+       if (self->pv->last_reply == TRUE)
                return gtk_entry_buffer_get_text (self->pv->password_buffer);
        return NULL;
 }
@@ -1014,7 +1014,7 @@ gcr_prompt_dialog_confirm_async (GcrPrompt *prompt,
                                                            gcr_prompt_dialog_confirm_async);
 
        if (self->pv->was_closed) {
-               self->pv->last_reply = GCR_PROMPT_REPLY_CANCEL;
+               self->pv->last_reply = FALSE;
                g_simple_async_result_complete_in_idle (self->pv->async_result);
                return;
        }
@@ -1038,7 +1038,7 @@ gcr_prompt_dialog_confirm_async (GcrPrompt *prompt,
        gtk_widget_show (GTK_WIDGET (self));
 }
 
-static GcrPromptReply
+static gboolean
 gcr_prompt_dialog_confirm_finish (GcrPrompt *prompt,
                                   GAsyncResult *result,
                                   GError **error)
@@ -1046,10 +1046,10 @@ gcr_prompt_dialog_confirm_finish (GcrPrompt *prompt,
        GcrPromptDialog *self = GCR_PROMPT_DIALOG (prompt);
 
        g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (prompt),
-                             gcr_prompt_dialog_confirm_async), GCR_PROMPT_REPLY_CANCEL);
+                             gcr_prompt_dialog_confirm_async), FALSE);
 
        if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
-               return GCR_PROMPT_REPLY_CANCEL;
+               return FALSE;
 
        return self->pv->last_reply;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]