[libnma/lr/gtk-4.0: 19/33] nma-ui-utils: add a dialog run helper




commit 9c9adbda9c084035125d31626d55a14c7d0a888e
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Fri Oct 8 13:52:17 2021 +0200

    nma-ui-utils: add a dialog run helper
    
    This is going to be useful in few places where the library widgets
    invoke modal dialogs.

 src/nma-cert-chooser-button.c        |  4 ++--
 src/nma-pkcs11-cert-chooser-dialog.c |  3 ++-
 src/nma-private.h                    |  1 +
 src/nma-ui-utils.c                   | 34 +++++++++++++++++++++++++++++++++-
 src/nma-vpn-password-dialog.c        |  2 +-
 5 files changed, 39 insertions(+), 5 deletions(-)
---
diff --git a/src/nma-cert-chooser-button.c b/src/nma-cert-chooser-button.c
index eacaf9c1..e4d57773 100644
--- a/src/nma-cert-chooser-button.c
+++ b/src/nma-cert-chooser-button.c
@@ -205,7 +205,7 @@ select_from_token (NMACertChooserButton *button, GckSlot *slot)
                                                     _("Select"), GTK_RESPONSE_ACCEPT,
                                                     _("Cancel"), GTK_RESPONSE_CANCEL,
                                                     NULL);
-       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+       if (nma_gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
                if (priv->uri)
                        g_free (priv->uri);
                priv->uri = nma_pkcs11_cert_chooser_dialog_get_uri (NMA_PKCS11_CERT_CHOOSER_DIALOG (dialog));
@@ -244,7 +244,7 @@ select_from_file (NMACertChooserButton *button)
        if (priv->uri)
                gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), priv->uri);
        gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
-       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+       if (nma_gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
                if (priv->uri)
                        g_free (priv->uri);
                priv->uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
diff --git a/src/nma-pkcs11-cert-chooser-dialog.c b/src/nma-pkcs11-cert-chooser-dialog.c
index c632105a..f77a3886 100644
--- a/src/nma-pkcs11-cert-chooser-dialog.c
+++ b/src/nma-pkcs11-cert-chooser-dialog.c
@@ -8,6 +8,7 @@
 
 #include "nm-default.h"
 #include "nma-private.h"
+
 #include "nma-pkcs11-cert-chooser-dialog.h"
 #include "nma-pkcs11-token-login-dialog.h"
 
@@ -340,7 +341,7 @@ login_clicked (GtkButton *button, gpointer user_data)
        gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
        gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
 
-       if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
+       if (nma_gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
                priv->pin_length = nma_pkcs11_token_login_dialog_get_pin_length 
(NMA_PKCS11_TOKEN_LOGIN_DIALOG (dialog));
                priv->pin_value = g_memdup (nma_pkcs11_token_login_dialog_get_pin_value 
(NMA_PKCS11_TOKEN_LOGIN_DIALOG (dialog)),
                                            priv->pin_length + 1);
diff --git a/src/nma-private.h b/src/nma-private.h
index 8b407af2..b30015c4 100644
--- a/src/nma-private.h
+++ b/src/nma-private.h
@@ -35,6 +35,7 @@ _nma_window_hide_on_close (GtkWindow *window, gpointer user_data)
 }
 #endif
 
+int nma_gtk_dialog_run (GtkDialog *dialog);
 
 #define NMA_PRIVATE_H
 
diff --git a/src/nma-ui-utils.c b/src/nma-ui-utils.c
index 40042e96..a166ee3a 100644
--- a/src/nma-ui-utils.c
+++ b/src/nma-ui-utils.c
@@ -407,5 +407,37 @@ nma_utils_update_password_storage (GtkWidget *passwd_entry,
                change_password_storage_icon (passwd_entry, idx);
        }
 }
-/*---------------------------------------------------------------------------*/
 
+typedef struct {
+       GMainLoop *loop;
+       int response_id;
+} NmaDialogData;
+
+static void
+nma_dialog_response (GtkDialog *dialog, int response_id, gpointer user_data)
+{
+       NmaDialogData *data = user_data;
+
+       data->response_id = response_id;
+       g_main_loop_quit (data->loop);
+}
+
+int
+nma_gtk_dialog_run (GtkDialog *dialog)
+{
+       NmaDialogData data;
+
+       data.loop = g_main_loop_new (NULL, FALSE);
+       g_signal_connect (dialog, "response", G_CALLBACK (nma_dialog_response), &data);
+
+       gtk_window_set_hide_on_close (GTK_WINDOW (dialog), TRUE);
+       gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+       gtk_window_present (GTK_WINDOW (dialog));
+
+       g_main_loop_run (data.loop);
+       g_main_loop_unref (data.loop);
+
+       gtk_widget_hide (GTK_WIDGET (dialog));
+
+       return data.response_id;
+}
diff --git a/src/nma-vpn-password-dialog.c b/src/nma-vpn-password-dialog.c
index 49c38f21..87377052 100644
--- a/src/nma-vpn-password-dialog.c
+++ b/src/nma-vpn-password-dialog.c
@@ -161,7 +161,7 @@ nma_vpn_password_dialog_run_and_block (NMAVpnPasswordDialog *dialog)
        g_return_val_if_fail (dialog != NULL, FALSE);
        g_return_val_if_fail (NMA_VPN_IS_PASSWORD_DIALOG (dialog), FALSE);
 
-       button_clicked = gtk_dialog_run (GTK_DIALOG (dialog));
+       button_clicked = nma_gtk_dialog_run (GTK_DIALOG (dialog));
        gtk_widget_hide (GTK_WIDGET (dialog));
 
        return button_clicked == GTK_RESPONSE_OK;


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