[libnma/lr/gtk-4.0: 10/23] vpn-password-dialog: port to Gtk4




commit 5c70d1fcab047ba209ae9e6298470149292cd2a7
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Tue Oct 12 14:52:44 2021 +0200

    vpn-password-dialog: port to Gtk4

 src/nma-vpn-password-dialog.c  | 20 +++++++++++++++++++-
 src/nma-vpn-password-dialog.ui | 11 ++++++++---
 2 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/src/nma-vpn-password-dialog.c b/src/nma-vpn-password-dialog.c
index 87377052..f39480ea 100644
--- a/src/nma-vpn-password-dialog.c
+++ b/src/nma-vpn-password-dialog.c
@@ -31,6 +31,9 @@ typedef struct {
        GtkWidget *password_entry_secondary;
        GtkWidget *password_entry_tertiary;
        GtkWidget *show_passwords_checkbox;
+
+       GMainLoop *loop;
+       gint response_id;
 } NMAVpnPasswordDialogPrivate;
 
 G_DEFINE_TYPE_WITH_CODE (NMAVpnPasswordDialog, nma_vpn_password_dialog, GTK_TYPE_DIALOG,
@@ -48,6 +51,7 @@ static void nma_vpn_password_dialog_init       (NMAVpnPasswordDialog      *passw
 /* GtkDialog callbacks */
 static void dialog_show_callback (GtkWidget *widget, gpointer callback_data);
 static void dialog_close_callback (GtkWidget *widget, gpointer callback_data);
+static void dialog_response_callback (GtkWidget *widget, gint response_id, gpointer callback_data);
 
 static void
 show_passwords_toggled_cb (GtkWidget *widget, gpointer user_data)
@@ -91,6 +95,7 @@ nma_vpn_password_dialog_class_init (NMAVpnPasswordDialogClass *klass)
 
        gtk_widget_class_bind_template_callback (widget_class, dialog_close_callback);
        gtk_widget_class_bind_template_callback (widget_class, dialog_show_callback);
+       gtk_widget_class_bind_template_callback (widget_class, dialog_response_callback);
        gtk_widget_class_bind_template_callback (widget_class, entry_activate_cb);
        gtk_widget_class_bind_template_callback (widget_class, show_passwords_toggled_cb);
 }
@@ -129,6 +134,19 @@ dialog_close_callback (GtkWidget *widget, gpointer callback_data)
        gtk_widget_hide (widget);
 }
 
+static void
+dialog_response_callback (GtkWidget *widget, gint response_id, gpointer callback_data)
+{
+       NMAVpnPasswordDialog *dialog = NMA_VPN_PASSWORD_DIALOG (callback_data);
+       NMAVpnPasswordDialogPrivate *priv = NMA_VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
+
+       priv->response_id = response_id;
+       if (priv->loop == NULL)
+               return;
+       if (g_main_loop_is_running (priv->loop))
+               g_main_loop_quit (priv->loop);
+}
+
 /* Public NMAVpnPasswordDialog methods */
 GtkWidget *
 nma_vpn_password_dialog_new (const char *title,
@@ -138,7 +156,7 @@ nma_vpn_password_dialog_new (const char *title,
        GtkWidget *dialog;
        NMAVpnPasswordDialogPrivate *priv;
 
-       dialog = gtk_widget_new (NMA_VPN_TYPE_PASSWORD_DIALOG, "title", title, NULL);
+       dialog = g_object_new (NMA_VPN_TYPE_PASSWORD_DIALOG, "title", title, NULL);
        if (!dialog)
                return NULL;
        priv = NMA_VPN_PASSWORD_DIALOG_GET_PRIVATE (dialog);
diff --git a/src/nma-vpn-password-dialog.ui b/src/nma-vpn-password-dialog.ui
index 72fb81c0..c84fb87b 100644
--- a/src/nma-vpn-password-dialog.ui
+++ b/src/nma-vpn-password-dialog.ui
@@ -8,20 +8,26 @@
     <property name="modal">True</property>
     <signal name="close" handler="dialog_close_callback" swapped="no"/>
     <signal name="show" handler="dialog_show_callback" swapped="no"/>
+    <signal name="response" handler="dialog_response_callback" swapped="no"/>
     <child internal-child="vbox">
       <object class="GtkBox">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <child internal-child="action_area">
-          <object class="GtkButtonBox">
+          <object class="GtkBox">
+            <property name="visible">True</property>
             <property name="can_focus">False</property>
+            <property name="spacing">6</property>
+            <property name="margin_start">6</property>
+            <property name="margin_end">6</property>
+            <property name="margin_top">6</property>
+            <property name="margin_bottom">6</property>
             <child>
               <object class="GtkButton" id="cancel_button">
                 <property name="label" translatable="yes">_Cancel</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="can_default">True</property>
                 <property name="receives_default">True</property>
                 <property name="valign">baseline</property>
                 <property name="use_underline">True</property>
@@ -38,7 +44,6 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="can_default">True</property>
-                <property name="has_default">True</property>
                 <property name="receives_default">True</property>
                 <property name="valign">baseline</property>
                 <property name="use_underline">True</property>


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