[evolution-data-server/wip/mcrha/gtk4] Fix ECredentialsPrompterImplPassword



commit 2a89f9c7aa50abdfe4d6d76a8282323a93a67ba2
Author: Milan Crha <mcrha redhat com>
Date:   Tue Oct 19 16:20:29 2021 +0200

    Fix ECredentialsPrompterImplPassword

 .../e-credentials-prompter-impl-password.c         | 45 ++++++++++++++++++----
 1 file changed, 38 insertions(+), 7 deletions(-)
---
diff --git a/src/libedataserverui/e-credentials-prompter-impl-password.c 
b/src/libedataserverui/e-credentials-prompter-impl-password.c
index 84ec68528..a888346b9 100644
--- a/src/libedataserverui/e-credentials-prompter-impl-password.c
+++ b/src/libedataserverui/e-credentials-prompter-impl-password.c
@@ -40,6 +40,7 @@ struct _ECredentialsPrompterImplPasswordPrivate {
 
 G_DEFINE_TYPE_WITH_PRIVATE (ECredentialsPrompterImplPassword, e_credentials_prompter_impl_password, 
E_TYPE_CREDENTIALS_PROMPTER_IMPL)
 
+#if !GTK_CHECK_VERSION(4, 0, 0)
 static gboolean
 password_dialog_map_event_cb (GtkWidget *dialog,
                              GdkEvent *event,
@@ -49,6 +50,7 @@ password_dialog_map_event_cb (GtkWidget *dialog,
 
        return FALSE;
 }
+#endif
 
 static void
 credentials_prompter_impl_password_get_prompt_strings (ESourceRegistry *registry,
@@ -223,7 +225,6 @@ response_cb (GtkDialog *dialog,
             RunInfo *run_info)
 {
        run_info->response_id = response_id;
-       gtk_window_destroy (GTK_WINDOW (dialog));
        shutdown_loop (run_info);
 }
 
@@ -232,17 +233,18 @@ close_requested_cb (GtkDialog *dialog,
                    RunInfo *run_info)
 {
        shutdown_loop (run_info);
-       return GDK_EVENT_PROPAGATE;
+       return GDK_EVENT_STOP;
 }
 
 static gint
 gtk_dialog_run (GtkDialog *dialog)
 {
        RunInfo run_info;
+       gulong close_request_id, reponse_id, unmap_id;
 
-       g_signal_connect (dialog, "close-request", G_CALLBACK (close_requested_cb), &run_info);
-       g_signal_connect (dialog, "response", G_CALLBACK (response_cb), &run_info);
-       g_signal_connect (dialog, "unmap", G_CALLBACK (unmap_cb), &run_info);
+       close_request_id = g_signal_connect (dialog, "close-request", G_CALLBACK (close_requested_cb), 
&run_info);
+       reponse_id = g_signal_connect (dialog, "response", G_CALLBACK (response_cb), &run_info);
+       unmap_id = g_signal_connect (dialog, "unmap", G_CALLBACK (unmap_cb), &run_info);
 
        run_info.response_id = GTK_RESPONSE_NONE;
        run_info.loop = g_main_loop_new (NULL, FALSE);
@@ -253,6 +255,10 @@ gtk_dialog_run (GtkDialog *dialog)
        g_main_loop_run (run_info.loop);
        g_clear_pointer (&run_info.loop, g_main_loop_unref);
 
+       g_signal_handler_disconnect (dialog, close_request_id);
+       g_signal_handler_disconnect (dialog, reponse_id);
+       g_signal_handler_disconnect (dialog, unmap_id);
+
        return run_info.response_id;
 }
 
@@ -277,7 +283,11 @@ e_credentials_prompter_impl_password_show_dialog (ECredentialsPrompterImplPasswo
        GtkGrid *grid;
        GtkEntry *username_entry = NULL;
        GtkEntry *password_entry;
+#if GTK_CHECK_VERSION(4, 0, 0)
+       GtkCheckButton *remember_check = NULL;
+#else
        GtkToggleButton *remember_toggle = NULL;
+#endif
        GtkWindow *dialog_parent;
        ECredentialsPrompter *prompter;
        gchar *title;
@@ -443,8 +453,13 @@ e_credentials_prompter_impl_password_show_dialog (ECredentialsPrompterImplPasswo
        if (e_named_parameters_get (prompter_password->priv->credentials, E_SOURCE_CREDENTIAL_PASSWORD))
                gtk_entry_set_text (password_entry, e_named_parameters_get 
(prompter_password->priv->credentials, E_SOURCE_CREDENTIAL_PASSWORD));
 
-       g_signal_connect (dialog, "map-event", G_CALLBACK (password_dialog_map_event_cb),
-               (username_entry && g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (username_entry)), "") == 0) ? 
username_entry : password_entry);
+       widget = GTK_WIDGET ((username_entry && g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (username_entry)), 
"") == 0) ? username_entry : password_entry);
+
+#if GTK_CHECK_VERSION(4, 0, 0)
+       g_signal_connect_swapped (dialog, "map", G_CALLBACK (gtk_widget_grab_focus), widget);
+#else
+       g_signal_connect (dialog, "map-event", G_CALLBACK (password_dialog_map_event_cb), widget);
+#endif
 
        gtk_grid_attach (grid, GTK_WIDGET (password_entry), 1, row, 1, 1);
        row++;
@@ -479,8 +494,13 @@ e_credentials_prompter_impl_password_show_dialog (ECredentialsPrompterImplPasswo
        if (auth_extension && !is_scratch_source) {
                /* Remember password check */
                widget = gtk_check_button_new_with_mnemonic (_("_Add this password to your keyring"));
+#if GTK_CHECK_VERSION(4, 0, 0)
+               remember_check = GTK_CHECK_BUTTON (widget);
+               gtk_check_button_set_active (remember_check, e_source_authentication_get_remember_password 
(auth_extension));
+#else
                remember_toggle = GTK_TOGGLE_BUTTON (widget);
                gtk_toggle_button_set_active (remember_toggle, e_source_authentication_get_remember_password 
(auth_extension));
+#endif
                g_object_set (
                        G_OBJECT (widget),
                        "hexpand", TRUE,
@@ -505,13 +525,24 @@ e_credentials_prompter_impl_password_show_dialog (ECredentialsPrompterImplPasswo
                e_named_parameters_set (prompter_password->priv->credentials,
                        E_SOURCE_CREDENTIAL_PASSWORD, gtk_entry_get_text (password_entry));
 
+#if GTK_CHECK_VERSION(4, 0, 0)
+               if (auth_extension && remember_check) {
+                       e_source_authentication_set_remember_password (auth_extension,
+                               gtk_check_button_get_active (remember_check));
+               }
+#else
                if (auth_extension && remember_toggle) {
                        e_source_authentication_set_remember_password (auth_extension,
                                gtk_toggle_button_get_active (remember_toggle));
                }
+#endif
        }
 
+#if GTK_CHECK_VERSION(4, 0, 0)
+       gtk_window_destroy (GTK_WINDOW (dialog));
+#else
        g_object_unref (dialog);
+#endif
        prompter_password->priv->dialog = NULL;
 
        g_string_free (info_markup, TRUE);


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