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




commit a12202825fdfe8dcb732eb92c73a9f56ad2386dc
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 |  4 +++-
 src/nma-private.h                    |  1 +
 src/nma-ui-utils.c                   | 34 +++++++++++++++++++++++++++++++++-
 src/nma-vpn-password-dialog.c        |  2 +-
 5 files changed, 40 insertions(+), 5 deletions(-)
---
diff --git a/src/nma-cert-chooser-button.c b/src/nma-cert-chooser-button.c
index 9d5287f5..391c822c 100644
--- a/src/nma-cert-chooser-button.c
+++ b/src/nma-cert-chooser-button.c
@@ -203,7 +203,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));
@@ -242,7 +242,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 188aac0f..128b72f9 100644
--- a/src/nma-pkcs11-cert-chooser-dialog.c
+++ b/src/nma-pkcs11-cert-chooser-dialog.c
@@ -7,6 +7,8 @@
  */
 
 #include "nm-default.h"
+#include "nma-private.h"
+
 #include "nma-pkcs11-cert-chooser-dialog.h"
 #include "nma-pkcs11-token-login-dialog.h"
 
@@ -339,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 f58e1112..a0085f35 100644
--- a/src/nma-private.h
+++ b/src/nma-private.h
@@ -28,6 +28,7 @@
 typedef void GtkRoot;
 #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 a755f4f7..dd85db1c 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]