[NetworkManager-fortisslvpn/lr/gtk4: 3/5] editor: use NmaCertChooser




commit 62109d521f48d0402e0759446e7735a57ca55448
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Mon Oct 11 13:40:19 2021 +0200

    editor: use NmaCertChooser

 properties/nm-fortisslvpn-dialog.ui | 74 +++++++------------------------------
 properties/nm-fortisslvpn-editor.c  | 41 ++++++++++----------
 2 files changed, 36 insertions(+), 79 deletions(-)
---
diff --git a/properties/nm-fortisslvpn-dialog.ui b/properties/nm-fortisslvpn-dialog.ui
index 88a24ae..3bf49df 100644
--- a/properties/nm-fortisslvpn-dialog.ui
+++ b/properties/nm-fortisslvpn-dialog.ui
@@ -201,75 +201,29 @@ config: the first parameter of fortisslvpn</property>
     <property name="row_spacing">6</property>
     <property name="column_spacing">12</property>
     <child>
-      <object class="GtkFileChooserButton" id="key_chooser">
+      <object class="NmaCertChooser" id="ca_chooser">
+        <property name="flags">5</property>
+        <property name="title">CA</property>
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="top_attach">8</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkFileChooserButton" id="cert_chooser">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="top_attach">7</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkFileChooserButton" id="ca_chooser">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="top_attach">6</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="label7">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes">User _Key</property>
-        <property name="use_underline">True</property>
-        <property name="mnemonic_widget">key_chooser</property>
-        <property name="xalign">1</property>
-      </object>
-      <packing>
-        <property name="left_attach">0</property>
-        <property name="top_attach">8</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="label">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes">_User Certificate</property>
-        <property name="use_underline">True</property>
-        <property name="mnemonic_widget">cert_chooser</property>
-        <property name="xalign">1</property>
+        <property name="can-focus">False</property>
       </object>
       <packing>
-        <property name="left_attach">0</property>
-        <property name="top_attach">7</property>
+        <property name="left-attach">0</property>
+        <property name="top-attach">6</property>
+        <property name="width">2</property>
       </packing>
     </child>
     <child>
-      <object class="GtkLabel" id="label5">
+      <object class="NmaCertChooser" id="cert_chooser">
+        <property name="flags">4</property>
+        <property name="title">User</property>
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="label" translatable="yes">_CA Certificate</property>
-        <property name="use_underline">True</property>
-        <property name="mnemonic_widget">ca_chooser</property>
-        <property name="xalign">1</property>
+        <property name="can-focus">False</property>
       </object>
       <packing>
-        <property name="left_attach">0</property>
-        <property name="top_attach">6</property>
+        <property name="left-attach">0</property>
+        <property name="top-attach">7</property>
+        <property name="width">2</property>
       </packing>
     </child>
     <child>
diff --git a/properties/nm-fortisslvpn-editor.c b/properties/nm-fortisslvpn-editor.c
index 6d87d87..293f12e 100644
--- a/properties/nm-fortisslvpn-editor.c
+++ b/properties/nm-fortisslvpn-editor.c
@@ -24,6 +24,8 @@
 #include "nm-fortisslvpn-editor.h"
 #include "nm-fortissl-properties.h"
 
+#include "nma-cert-chooser.h"
+
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <errno.h>
@@ -288,32 +290,33 @@ init_editor_plugin (FortisslvpnEditor *self, NMConnection *connection, GError **
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "ca_chooser"));
        g_return_val_if_fail (widget, FALSE);
 
+       nma_cert_chooser_add_to_size_group (NMA_CERT_CHOOSER (widget), group);
        if (s_vpn) {
                value = nm_setting_vpn_get_data_item (s_vpn, NM_FORTISSLVPN_KEY_CA);
-               if (value && strlen (value))
-                       gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
+               if (value && strlen (value)) {
+                       nma_cert_chooser_set_cert (NMA_CERT_CHOOSER (widget), value,
+                                                  NM_SETTING_802_1X_CK_SCHEME_PATH);
+               }
        }
-       g_signal_connect (G_OBJECT (widget), "update-preview", G_CALLBACK (stuff_changed_cb), self);
+       g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "cert_chooser"));
        g_return_val_if_fail (widget, FALSE);
 
+       nma_cert_chooser_add_to_size_group (NMA_CERT_CHOOSER (widget), group);
        if (s_vpn) {
                value = nm_setting_vpn_get_data_item (s_vpn, NM_FORTISSLVPN_KEY_CERT);
-               if (value && strlen (value))
-                       gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
-       }
-       g_signal_connect (G_OBJECT (widget), "update-preview", G_CALLBACK (stuff_changed_cb), self);
-
-       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "key_chooser"));
-       g_return_val_if_fail (widget, FALSE);
-
-       if (s_vpn) {
+               if (value && strlen (value)) {
+                       nma_cert_chooser_set_cert (NMA_CERT_CHOOSER (widget), value,
+                                                  NM_SETTING_802_1X_CK_SCHEME_PATH);
+               }
                value = nm_setting_vpn_get_data_item (s_vpn, NM_FORTISSLVPN_KEY_KEY);
-               if (value && strlen (value))
-                       gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (widget), value);
+               if (value && strlen (value)) {
+                       nma_cert_chooser_set_key (NMA_CERT_CHOOSER (widget), value,
+                                                 NM_SETTING_802_1X_CK_SCHEME_PATH);
+               }
        }
-       g_signal_connect (G_OBJECT (widget), "update-preview", G_CALLBACK (stuff_changed_cb), self);
+       g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "advanced_dialog"));
        g_return_val_if_fail (widget, FALSE);
@@ -402,19 +405,19 @@ update_connection (NMVpnEditor *iface,
 
        /* CA file */
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "ca_chooser"));
-       str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
+       str = nma_cert_chooser_get_cert (NMA_CERT_CHOOSER (widget), NULL);
        if (str && strlen (str))
                nm_setting_vpn_add_data_item (s_vpn, NM_FORTISSLVPN_KEY_CA, str);
 
        /* User certificate */
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "cert_chooser"));
-       str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
+       str = nma_cert_chooser_get_cert (NMA_CERT_CHOOSER (widget), NULL);
        if (str && strlen (str))
                nm_setting_vpn_add_data_item (s_vpn, NM_FORTISSLVPN_KEY_CERT, str);
 
        /* User key */
-       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "key_chooser"));
-       str = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "cert_chooser"));
+       str = nma_cert_chooser_get_key (NMA_CERT_CHOOSER (widget), NULL);
        if (str && strlen (str))
                nm_setting_vpn_add_data_item (s_vpn, NM_FORTISSLVPN_KEY_KEY, str);
 


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