[network-manager-sstp/gtk4-work: 3/6] Porting properties to GTK4




commit bcb69c4b1d84e9a4d939adbe10b10438142580b7
Author: Eivind Næss <eivnaes yahoo com>
Date:   Tue Mar 22 08:52:33 2022 -0700

    Porting properties to GTK4
    
    Signed-off-by: Eivind Næss <eivnaes yahoo com>

 .gitignore                         |  1 +
 Makefile.am                        | 45 +++++++++++++++++++-
 configure.ac                       | 16 +++++++
 properties/advanced-dialog.c       | 85 +++++++++++++++++++-------------------
 properties/nm-sstp-editor-plugin.c | 33 ++++++++++-----
 properties/nm-sstp-editor.c        | 39 ++++++++---------
 properties/nm-sstp-editor.h        | 11 +++++
 7 files changed, 158 insertions(+), 72 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 1c14489..1333d67 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,7 @@ m4/lt*.m4
 appdata/network-manager-sstp.metainfo.xml
 /cscope.*
 /properties/resources.[ch]
+/gtk4
 
 auth-dialog/nm-sstp-auth-dialog
 nm-sstp-service.name
diff --git a/Makefile.am b/Makefile.am
index 19077ff..c1bb95c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -135,6 +135,14 @@ properties/resources.h: properties/gresource.xml
 properties/resources.c: properties/gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) 
--sourcedir=$(srcdir)/properties --generate-dependencies $(srcdir)/properties/gresource.xml)
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $< --target=$@ --sourcedir=$(srcdir)/properties 
--generate-source --internal
 
+gtk4/resources.c: properties/gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies 
$(srcdir)/properties/gresource.xml |sed "s,^,$(builddir)/gtk4/,")
+       @mkdir -p $(builddir)/gtk4
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $< --target=$@ --sourcedir=$(srcdir)/gtk4 
--sourcedir=$(builddir)/gtk4 --generate-source --internal
+
+gtk4/%.ui: properties/%.ui
+       @mkdir -p $(builddir)/gtk4
+       gtk4-builder-tool simplify --3to4 $< |grep -v can-default >$@
+
 plugin_sources = \
        shared/nm-utils/nm-vpn-plugin-macros.h \
        properties/nm-sstp-editor-plugin.c \
@@ -156,7 +164,9 @@ properties_cppflags = \
 
 CLEANFILES += \
        properties/resources.c \
-       properties/resources.h
+       properties/resources.h \
+       gtk4/resources.c \
+       gtk4/nm-sstp-dialog.ui
 
 EXTRA_DIST += \
        properties/nm-sstp-dialog.ui \
@@ -221,6 +231,39 @@ properties_libnm_vpn_plugin_sstp_editor_la_LDFLAGS = \
 
 ###############################################################################
 
+if WITH_GTK4
+plugin_LTLIBRARIES += properties/libnm-gtk4-vpn-plugin-sstp-editor.la
+endif
+
+properties_libnm_gtk4_vpn_plugin_sstp_editor_la_SOURCES = \
+       $(editor_sources)
+
+nodist_properties_libnm_gtk4_vpn_plugin_sstp_editor_la_SOURCES = \
+       gtk4/resources.c \
+       properties/resources.h
+
+properties_libnm_gtk4_vpn_plugin_sstp_editor_la_CFLAGS = \
+       $(GLIB_CFLAGS) \
+       $(GTK4_CFLAGS) \
+       $(LIBNM_CFLAGS) \
+       $(LIBNMA_GTK4_CFLAGS) \
+       $(GNUTLS_CFLAGS)
+
+properties_libnm_gtk4_vpn_plugin_sstp_editor_la_CPPFLAGS = \
+       $(properties_libnm_vpn_plugin_sstp_editor_la_CPPFLAGS)
+
+properties_libnm_gtk4_vpn_plugin_sstp_editor_la_LIBADD = \
+       $(GLIB_LIBS) \
+       $(GTK4_LIBS) \
+       $(LIBNM_LIBS) \
+       $(LIBNMA_GTK4_LIBS) \
+       $(GNUTLS_LIBS)
+
+properties_libnm_gtk4_vpn_plugin_sstp_editor_la_LDFLAGS = \
+       $(properties_libnm_vpn_plugin_sstp_editor_la_LDFLAGS)
+
+###############################################################################
+
 if WITH_LIBNM_GLIB
 plugin_LTLIBRARIES += properties/libnm-sstp-properties.la
 endif
diff --git a/configure.ac b/configure.ac
index 5bfd335..fa5780f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -134,6 +134,7 @@ dnl
 dnl GNOME support
 dnl
 AC_ARG_WITH(gnome, AS_HELP_STRING([--without-gnome], [Build NetworkManager-sstp without GNOME support, e.g. 
vpn service only]), [], [with_gnome_specified=no])
+AC_ARG_WITH(gtk4, AS_HELP_STRING([--with-gtk4], [Build NetworkManager-sstp with libnma-gtk4 support]), [], 
[with_gtk4_specified=no])
 AC_ARG_WITH(libnm-glib, AS_HELP_STRING([--with-libnm-glib], [Build NetworkManager-sstp with libnm-glib 
comatibility (deprecated)]), [], [with_libnm_glib_specified=no])
 if test "$with_libnm_glib_specified" != no -a "$with_libnm_glib" != no; then
        if test "$with_gnome_specified" != no -a "$with_gnome" == no; then
@@ -143,6 +144,12 @@ fi
 if test "$with_gnome" != no; then
        with_gnome=yes
 fi
+if test "$with_gtk4_specified" == no; then
+       with_gtk4=no
+fi
+if test "$with_gtk4" != yes; then
+       with_gtk4=no
+fi
 if test "$with_libnm_glib_specified" == no; then
        with_libnm_glib=no
 fi
@@ -150,6 +157,7 @@ if test "$with_libnm_glib" != yes; then
        with_libnm_glib=no
 fi
 AM_CONDITIONAL(WITH_GNOME, test "$with_gnome" != no)
+AM_CONDITIONAL(WITH_GTK4, test "$with_gtk4" != no)
 AM_CONDITIONAL(WITH_LIBNM_GLIB, test "$with_libnm_glib" != no)
 AC_ARG_ENABLE(absolute-paths, AS_HELP_STRING([--enable-absolute-paths], [Use absolute paths to in .name 
files. Useful for development. (default is no)]))
 
@@ -188,6 +196,13 @@ if test x"$with_gnome" != xno; then
        fi
 fi
 
+if test x"$with_gtk4" != xno; then
+       PKG_CHECK_MODULES(GTK4, gtk4 >= 4.0)
+       GTK4_CFLAGS="$GTK4_CFLAGS -DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_4_0"
+       GTK4_CFLAGS="$GTK4_CFLAGS -DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_4_0"
+       PKG_CHECK_MODULES(LIBNMA_GTK4, libnma-gtk4 >= 1.8.33)
+fi
+
 PKG_CHECK_MODULES(LIBNM, libnm >= 1.7.0)
 LIBNM_CFLAGS="$LIBNM_CFLAGS -DNM_VERSION_MIN_REQUIRED=NM_VERSION_1_8"
 LIBNM_CFLAGS="$LIBNM_CFLAGS -DNM_VERSION_MAX_ALLOWED=NM_VERSION_1_8"
@@ -236,6 +251,7 @@ echo ""
 echo "Build configuration: "
 echo "  --with-dist-version=$ac_distver"
 echo "  --with-gnome=$with_gnome"
+echo "  --with-gtk4=$with_gtk4"
 echo "  --with-libnm-glib=$with_libnm_glib"
 echo "  --with-pppd-plugin-dir=$PPPD_PLUGIN_DIR"
 echo "  --with-pppd-auth-notify-support=$with_pppd_auth_notify_support"
diff --git a/properties/advanced-dialog.c b/properties/advanced-dialog.c
index 52e1fb8..2670a4e 100644
--- a/properties/advanced-dialog.c
+++ b/properties/advanced-dialog.c
@@ -22,6 +22,7 @@
 
 #include "nm-default.h"
 
+#include "nm-sstp-editor.h"
 #include "advanced-dialog.h"
 
 #include <string.h>
@@ -89,8 +90,8 @@ show_proxy_password_toggled_cb (GtkCheckButton *button, gpointer user_data)
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "proxy_password_entry"));
     g_assert (widget);
     
-    visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
-    gtk_entry_set_visibility (GTK_ENTRY (widget), visible);
+    visible = gtk_check_button_get_active (GTK_CHECK_BUTTON (button));
+    gtk_entry_set_visibility (GTK_ENTRY(widget), visible);
 }
 
 static void
@@ -161,7 +162,7 @@ static void handle_mppe_changed (GtkWidget *check, gboolean is_init, GtkBuilder
     gboolean valid;
 
     mppe_sensitive = gtk_widget_get_sensitive (check);
-    use_mppe = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
+    use_mppe = gtk_check_button_get_active (GTK_CHECK_BUTTON (check));
 
     /* (De)-sensitize MPPE related stuff */
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_mppe_security_label"));
@@ -314,7 +315,7 @@ check_toggled_cb (GtkCellRendererToggle *cell, gchar *path_str, gpointer user_da
     /* Make sure MPPE is non-sensitive if MSCHAP, MSCHAPv2 and EAP are disabled */
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_use_mppe"));
     if (!mppe) {
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
+        gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), FALSE);
         gtk_widget_set_sensitive (widget, FALSE);
     } else {
         gtk_widget_set_sensitive (widget, TRUE);
@@ -449,7 +450,7 @@ auth_methods_setup (GtkBuilder *builder, GHashTable *hash)
     /* Make sure MPPE is non-sensitive if MSCHAP and MSCHAPv2 are disabled */
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_use_mppe"));
     if (!mschap_state && !mschap2_state && !eap_state) {
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
+        gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), FALSE);
         gtk_widget_set_sensitive (widget, FALSE);
     } else
         gtk_widget_set_sensitive (widget, TRUE);
@@ -469,10 +470,10 @@ tls_page_setup(GtkBuilder *builder, GHashTable *hash, gboolean is_tls, gchar *su
         widget = GTK_WIDGET (gtk_builder_get_object (builder, "tls_identity"));
         value = g_hash_table_lookup (hash, NM_SSTP_KEY_TLS_IDENTITY);
         if (value && strlen (value)) {
-            gtk_entry_set_text (GTK_ENTRY (widget), value);
+            gtk_editable_set_text (GTK_EDITABLE (widget), value);
         }
         else if (subject && strlen (subject)) {
-            gtk_entry_set_text (GTK_ENTRY (widget), subject);
+            gtk_editable_set_text (GTK_EDITABLE (widget), subject);
         }
 
         value = g_hash_table_lookup (hash, NM_SSTP_KEY_TLS_VERIFY_METHOD);
@@ -518,15 +519,15 @@ tls_page_setup(GtkBuilder *builder, GHashTable *hash, gboolean is_tls, gchar *su
         widget = GTK_WIDGET (gtk_builder_get_object (builder, "tls_remote_entry"));
         value = g_hash_table_lookup (hash, NM_SSTP_KEY_TLS_REMOTENAME);
         if (value && strlen (value)) {
-          gtk_entry_set_text (GTK_ENTRY (widget), value);
+          gtk_editable_set_text (GTK_EDITABLE (widget), value);
         }
 
         active = -1;
         widget = GTK_WIDGET (gtk_builder_get_object (builder, "tls_remote_keyusage_check"));
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), FALSE);
+        gtk_check_button_set_active (GTK_CHECK_BUTTON(widget), FALSE);
         value = g_hash_table_lookup (hash, NM_SSTP_KEY_TLS_VERIFY_KEY_USAGE);
         if (value && !strcmp (value, "yes"))
-            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), TRUE);
+            gtk_check_button_set_active (GTK_CHECK_BUTTON(widget), TRUE);
 
 #ifndef USE_PPP_EXT_TLS_SETTINGS
         widget = GTK_WIDGET (gtk_builder_get_object (builder, "vbox_tls_validation"));
@@ -590,7 +591,7 @@ checkbox_toggled_update_widget_cb (GtkWidget *check, gpointer user_data)
 {
     GtkWidget *widget = (GtkWidget*) user_data;
 
-    gtk_widget_set_sensitive (widget, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+    gtk_widget_set_sensitive (widget, gtk_check_button_get_active (GTK_CHECK_BUTTON (check)));
 }
 
 GtkWidget *
@@ -650,13 +651,13 @@ advanced_dialog_new (GHashTable *hash, gboolean is_tls, gchar *subject)
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "tls_cert_warn_checkbutton"));
     value = g_hash_table_lookup (hash, NM_SSTP_KEY_IGN_CERT_WARN);
     if (value && !strcmp (value, "yes")) {
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+        gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), TRUE);
     }
     
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "tls_hostext_checkbutton"));
     value = g_hash_table_lookup (hash, NM_SSTP_KEY_TLS_EXT_ENABLE);
     if (value && !strcmp (value, "yes")) {
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+        gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), TRUE);
     }
 
     setup_security_combo (builder, hash);
@@ -675,30 +676,30 @@ advanced_dialog_new (GHashTable *hash, gboolean is_tls, gchar *subject)
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_use_mppe"));
     if (mppe)
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+        gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), TRUE);
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_allow_stateful_mppe"));
     value = g_hash_table_lookup (hash, NM_SSTP_KEY_MPPE_STATEFUL);
     if (value && !strcmp (value, "yes"))
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+        gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), TRUE);
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_allow_bsdcomp"));
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+    gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), TRUE);
     value = g_hash_table_lookup (hash, NM_SSTP_KEY_NOBSDCOMP);
     if (value && !strcmp (value, "yes"))
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
+        gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), FALSE);
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_allow_deflate"));
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+    gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), TRUE);
     value = g_hash_table_lookup (hash, NM_SSTP_KEY_NODEFLATE);
     if (value && !strcmp (value, "yes"))
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
+        gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), FALSE);
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_usevj"));
-    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+    gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), TRUE);
     value = g_hash_table_lookup (hash, NM_SSTP_KEY_NO_VJ_COMP);
     if (value && !strcmp (value, "yes"))
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
+        gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), FALSE);
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_send_echo_packets"));
     value = g_hash_table_lookup (hash, NM_SSTP_KEY_LCP_ECHO_INTERVAL);
@@ -708,7 +709,7 @@ advanced_dialog_new (GHashTable *hash, gboolean is_tls, gchar *subject)
         errno = 0;
         tmp_int = strtol (value, NULL, 10);
         if (errno == 0 && tmp_int > 0)
-            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+            gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), TRUE);
     }
 
     auth_methods_setup (builder, hash);
@@ -734,18 +735,18 @@ advanced_dialog_new (GHashTable *hash, gboolean is_tls, gchar *subject)
         gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), (gdouble) tmp);
         
         widget = GTK_WIDGET (gtk_builder_get_object (builder, "proxy_server_entry"));
-        gtk_entry_set_text (GTK_ENTRY (widget), value);
+        gtk_editable_set_text (GTK_EDITABLE (widget), value);
         
         value = g_hash_table_lookup (hash, NM_SSTP_KEY_PROXY_USER);
         if (value && strlen (value)) {
             widget = GTK_WIDGET (gtk_builder_get_object (builder, "proxy_username_entry"));
-            gtk_entry_set_text (GTK_ENTRY (widget), value);
+            gtk_editable_set_text (GTK_EDITABLE (widget), value);
         }
         
         value = g_hash_table_lookup (hash, NM_SSTP_KEY_PROXY_PASSWORD);
         if (value && strlen (value)) {
             widget = GTK_WIDGET (gtk_builder_get_object (builder, "proxy_password_entry"));
-            gtk_entry_set_text (GTK_ENTRY (widget), value);
+            gtk_editable_set_text (GTK_EDITABLE (widget), value);
         }
         
         value = g_hash_table_lookup (hash, NM_SSTP_KEY_PROXY_PASSWORD_FLAGS);
@@ -773,14 +774,14 @@ advanced_dialog_new (GHashTable *hash, gboolean is_tls, gchar *subject)
         errno = 0;
         tmp = strtol (value, NULL, 10);
         if (errno == 0 && tmp >= 0 && tmp < 65536) {
-            gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+            gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), TRUE);
 
             widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_unit_spinbutton"));
             gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), (gdouble) tmp);
             gtk_widget_set_sensitive (widget, TRUE);
         }
     } else {
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
+        gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), FALSE);
 
         widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_unit_spinbutton"));
         gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), 0.0);
@@ -835,13 +836,13 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
 
     /* Ignore Certificate Warnings */
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "tls_cert_warn_checkbutton"));
-    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+    if (gtk_check_button_get_active (GTK_CHECK_BUTTON (widget))) {
         g_hash_table_insert (hash, g_strdup(NM_SSTP_KEY_IGN_CERT_WARN), g_strdup("yes"));
     }
 
     /* Enable TLS hostname extensions */
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "tls_hostext_checkbutton"));
-    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+    if (gtk_check_button_get_active (GTK_CHECK_BUTTON (widget))) {
         g_hash_table_insert (hash, g_strdup (NM_SSTP_KEY_TLS_EXT_ENABLE), g_strdup ("yes"));
     }
 
@@ -882,7 +883,7 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
     }
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_use_mppe"));
-    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+    if (gtk_check_button_get_active (GTK_CHECK_BUTTON (widget))) {
 
         widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_mppe_security_combo"));
         switch (gtk_combo_box_get_active (GTK_COMBO_BOX (widget))) {
@@ -898,30 +899,30 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
         }
 
         widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_allow_stateful_mppe"));
-        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
+        if (gtk_check_button_get_active (GTK_CHECK_BUTTON (widget)))
             g_hash_table_insert (hash, g_strdup (NM_SSTP_KEY_MPPE_STATEFUL), g_strdup ("yes"));
     }
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_allow_bsdcomp"));
-    if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
+    if (!gtk_check_button_get_active (GTK_CHECK_BUTTON (widget)))
         g_hash_table_insert (hash, g_strdup (NM_SSTP_KEY_NOBSDCOMP), g_strdup ("yes"));
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_allow_deflate"));
-    if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
+    if (!gtk_check_button_get_active (GTK_CHECK_BUTTON (widget)))
         g_hash_table_insert (hash, g_strdup (NM_SSTP_KEY_NODEFLATE), g_strdup ("yes"));
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_usevj"));
-    if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
+    if (!gtk_check_button_get_active (GTK_CHECK_BUTTON (widget)))
         g_hash_table_insert (hash, g_strdup (NM_SSTP_KEY_NO_VJ_COMP), g_strdup ("yes"));
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_send_echo_packets"));
-    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+    if (gtk_check_button_get_active (GTK_CHECK_BUTTON (widget))) {
         g_hash_table_insert (hash, g_strdup (NM_SSTP_KEY_LCP_ECHO_FAILURE), g_strdup_printf ("%d", 5));
         g_hash_table_insert (hash, g_strdup (NM_SSTP_KEY_LCP_ECHO_INTERVAL), g_strdup_printf ("%d", 30));
     }
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_unit_checkbutton"));
-    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+    if (gtk_check_button_get_active (GTK_CHECK_BUTTON (widget))) {
         int unit_num;
 
         widget = GTK_WIDGET (gtk_builder_get_object (builder, "ppp_unit_spinbutton"));
@@ -932,7 +933,7 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
 
     /* TLS Authentication */
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "tls_identity"));
-    value = gtk_entry_get_text (GTK_ENTRY (widget));
+    value = gtk_editable_get_text (GTK_EDITABLE (widget));
     if (value && strlen (value)) {
         g_hash_table_insert (hash,
                              g_strdup (NM_SSTP_KEY_TLS_IDENTITY),
@@ -955,7 +956,7 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
     }
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "tls_remote_entry"));
-    value = gtk_entry_get_text (GTK_ENTRY (widget));
+    value = gtk_editable_get_text (GTK_EDITABLE (widget));
     if (value && strlen (value)) {
         g_hash_table_insert (hash,
                              g_strdup (NM_SSTP_KEY_TLS_REMOTENAME),
@@ -964,7 +965,7 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "tls_remote_keyusage_check"));
     g_hash_table_insert (hash, g_strdup (NM_SSTP_KEY_TLS_VERIFY_KEY_USAGE),
-                               g_strdup (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)) ? "yes" : 
"no"));
+                               g_strdup (gtk_check_button_get_active (GTK_CHECK_BUTTON (widget)) ? "yes" : 
"no"));
 
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "tls_version_max_combo"));
     model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
@@ -983,7 +984,7 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
 
     /* Proxy support */
     widget = GTK_WIDGET (gtk_builder_get_object (builder, "proxy_server_entry"));
-    value = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+    value = (char *) gtk_editable_get_text (GTK_EDITABLE (widget));
     if (value && strlen(value))
     {
         NMSettingSecretFlags pw_flags;
@@ -999,7 +1000,7 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
         }
         
         widget = GTK_WIDGET (gtk_builder_get_object (builder, "proxy_username_entry"));
-        value = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+        value = (char *) gtk_editable_get_text (GTK_EDITABLE (widget));
         if (value && strlen (value)) {
             g_hash_table_insert (hash,
                                  g_strdup (NM_SSTP_KEY_PROXY_USER),
@@ -1007,7 +1008,7 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
         }
         
         widget = GTK_WIDGET (gtk_builder_get_object (builder, "proxy_password_entry"));
-        value = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+        value = (char *) gtk_editable_get_text (GTK_EDITABLE (widget));
         if (value && strlen (value)) {
             g_hash_table_insert (hash,
                                  g_strdup (NM_SSTP_KEY_PROXY_PASSWORD),
diff --git a/properties/nm-sstp-editor-plugin.c b/properties/nm-sstp-editor-plugin.c
index 5a031b7..24c14a4 100644
--- a/properties/nm-sstp-editor-plugin.c
+++ b/properties/nm-sstp-editor-plugin.c
@@ -1,6 +1,7 @@
 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
 /***************************************************************************
  *
+ * Copyright (C) 2022 Eivind Naess <eivnaes yahoo com>
  * Copyright (C) 2008 Dan Williams, <dcbw redhat com>
  * Copyright (C) 2008 - 2011 Red Hat, Inc.
  * Based on work by David Zeuthen, <davidz redhat com>
@@ -151,23 +152,35 @@ _call_editor_factory (gpointer factory,
 static NMVpnEditor *
 get_editor (NMVpnEditorPlugin *iface, NMConnection *connection, GError **error)
 {
+       gpointer gtk3_only_symbol;
+       GModule *self_module;
+       const char *editor;
+
        g_return_val_if_fail (SSTP_IS_PLUGIN_UI (iface), NULL);
        g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
        g_return_val_if_fail (!error || !*error, NULL);
 
-       {
+       self_module = g_module_open (NULL, 0);
+       g_module_symbol (self_module, "gtk_container_add", &gtk3_only_symbol);
+       g_module_close (self_module);
+
+       if (gtk3_only_symbol) {
+               editor = "libnm-vpn-plugin-pptp-editor.so";
+       } else {
+               editor = "libnm-gtk4-vpn-plugin-pptp-editor.so";
+       }
+
 #if ((NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_UTIL)
-               return nm_vpn_plugin_ui_widget_interface_new (connection, error);
+       return nm_vpn_plugin_ui_widget_interface_new (connection, error);
 #else
-               return nm_vpn_plugin_utils_load_editor (NM_PLUGIN_DIR"/libnm-vpn-plugin-sstp-editor.so",
-                                                       "nm_vpn_editor_factory_sstp",
-                                                       _call_editor_factory,
-                                                       iface,
-                                                       connection,
-                                                       NULL,
-                                                       error);
+       return nm_vpn_plugin_utils_load_editor (editor,
+                                                                                       
"nm_vpn_editor_factory_sstp",
+                                                                                       _call_editor_factory,
+                                                                                       iface,
+                                                                                       connection,
+                                                                                       NULL,
+                                                                                       error);
 #endif
-       }
 }
 
 static void
diff --git a/properties/nm-sstp-editor.c b/properties/nm-sstp-editor.c
index 321ba1c..703a1ae 100644
--- a/properties/nm-sstp-editor.c
+++ b/properties/nm-sstp-editor.c
@@ -120,7 +120,7 @@ validate (SstpPluginUiWidget *self, GError **error)
 
     widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "gateway_entry"));
     g_return_val_if_fail (widget, FALSE);
-    str = gtk_entry_get_text (GTK_ENTRY (widget));
+    str = gtk_editable_get_text (GTK_EDITABLE (widget));
     if (str && nm_sstp_parse_gateway(str, NULL, NULL, NULL, NULL) == -1) {
         gtk_style_context_remove_class (gtk_widget_get_style_context (widget), "error");
     } else {
@@ -180,8 +180,8 @@ static void
 advanced_dialog_close_cb (GtkWidget *dialog, gpointer user_data)
 {
     gtk_widget_hide (dialog);
-    /* gtk_widget_destroy() will remove the window from the window group */
-    gtk_widget_destroy (dialog);
+    /* gtk_window_destroy() will remove the window from the window group */
+    gtk_window_destroy (GTK_WINDOW(dialog));
 }
 
 static void
@@ -214,10 +214,11 @@ advanced_button_clicked_cb (GtkWidget *button, gpointer user_data)
 {
     SstpPluginUiWidget *self = SSTP_PLUGIN_UI_WIDGET (user_data);
     SstpPluginUiWidgetPrivate *priv = SSTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
-    GtkWidget *dialog, *toplevel;
+    GtkWidget *dialog;
+    GtkRoot *root;
 
-    toplevel = gtk_widget_get_toplevel (priv->widget);
-    g_return_if_fail (gtk_widget_is_toplevel (toplevel));
+    root = gtk_widget_get_root (priv->widget);
+    g_return_if_fail (GTK_IS_WINDOW(root));
 
     dialog = advanced_dialog_new (priv->advanced, priv->is_tls, priv->subject);
     if (!dialog) {
@@ -227,15 +228,15 @@ advanced_button_clicked_cb (GtkWidget *button, gpointer user_data)
 
     gtk_window_group_add_window (priv->window_group, GTK_WINDOW (dialog));
     if (!priv->window_added) {
-        gtk_window_group_add_window (priv->window_group, GTK_WINDOW (toplevel));
+        gtk_window_group_add_window (priv->window_group, GTK_WINDOW (root));
         priv->window_added = TRUE;
     }
 
-    gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
+    gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (root));
     g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (advanced_dialog_response_cb), self);
     g_signal_connect (G_OBJECT (dialog), "close", G_CALLBACK (advanced_dialog_close_cb), self);
 
-    gtk_widget_show_all (dialog);
+    gtk_widget_show (dialog);
 }
 
 static void
@@ -245,7 +246,7 @@ show_toggled_cb (GtkCheckButton *button, SstpPluginUiWidget *self)
     GtkWidget *widget;
     gboolean visible;
 
-    visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+    visible = gtk_check_button_get_active (GTK_CHECK_BUTTON (button));
 
     widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_password_entry"));
     g_assert (widget);
@@ -490,7 +491,7 @@ pw_setup(SstpPluginUiWidget *self, NMSettingVpn *s_vpn, ChangedCallback changed_
     if (s_vpn) {
         value = nm_setting_vpn_get_data_item (s_vpn, NM_SSTP_KEY_USER);
         if (value && strlen (value))
-            gtk_entry_set_text (GTK_ENTRY (widget), value);
+            gtk_editable_set_text (GTK_EDITABLE (widget), value);
     }
     g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (changed_cb), self);
     
@@ -500,7 +501,7 @@ pw_setup(SstpPluginUiWidget *self, NMSettingVpn *s_vpn, ChangedCallback changed_
     if (s_vpn) {
         value = nm_setting_vpn_get_data_item (s_vpn, NM_SSTP_KEY_DOMAIN);
         if (value && strlen (value))
-            gtk_entry_set_text (GTK_ENTRY (widget), value);
+            gtk_editable_set_text (GTK_EDITABLE (widget), value);
     }
     g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (changed_cb), self);
  
@@ -510,7 +511,7 @@ pw_setup(SstpPluginUiWidget *self, NMSettingVpn *s_vpn, ChangedCallback changed_
     if (s_vpn) {
         value = nm_setting_vpn_get_secret (s_vpn, NM_SSTP_KEY_PASSWORD);
         if (value) {
-            gtk_entry_set_text (GTK_ENTRY (widget), value);
+            gtk_editable_set_text (GTK_EDITABLE (widget), value);
         }
     }
     g_signal_connect (widget, "changed", G_CALLBACK (changed_cb), self);
@@ -523,7 +524,7 @@ pw_setup(SstpPluginUiWidget *self, NMSettingVpn *s_vpn, ChangedCallback changed_
         nm_setting_get_secret_flags (NM_SETTING (s_vpn), NM_SSTP_KEY_PASSWORD, &pw_flags, NULL);
     }
 
-    value = gtk_entry_get_text (GTK_ENTRY (widget));
+    value = gtk_editable_get_text (GTK_EDITABLE (widget));
     if ((!value || !*value) && (pw_flags == NM_SETTING_SECRET_FLAG_NONE)) {
         nma_utils_update_password_storage (widget, NM_SETTING_SECRET_FLAG_NOT_SAVED,
                            (NMSetting *) s_vpn, NM_SSTP_KEY_PASSWORD);
@@ -559,7 +560,7 @@ init_plugin_ui (SstpPluginUiWidget *self, NMConnection *connection, GError **err
     if (s_vpn) {
         value = nm_setting_vpn_get_data_item (s_vpn, NM_SSTP_KEY_GATEWAY);
         if (value && strlen (value)) {
-            gtk_entry_set_text (GTK_ENTRY (widget), value);
+            gtk_editable_set_text (GTK_EDITABLE (widget), value);
         }
     }
     g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
@@ -677,7 +678,7 @@ update_connection (NMVpnEditor *iface,
 
     /* Gateway */
     widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "gateway_entry"));
-    str = gtk_entry_get_text (GTK_ENTRY (widget));
+    str = gtk_editable_get_text (GTK_EDITABLE (widget));
     if (str && strlen (str)) {
         nm_setting_vpn_add_data_item (s_vpn, NM_SSTP_KEY_GATEWAY, str);
     }
@@ -691,14 +692,14 @@ update_connection (NMVpnEditor *iface,
 
             /* Username */
             widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_entry"));
-            str = gtk_entry_get_text (GTK_ENTRY (widget));
+            str = gtk_editable_get_text (GTK_EDITABLE (widget));
             if (str && strlen (str)) {
                 nm_setting_vpn_add_data_item (s_vpn, NM_SSTP_KEY_USER, str);
             }
 
             /* User password */
             widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_password_entry"));
-            str = gtk_entry_get_text (GTK_ENTRY (widget));
+            str = gtk_editable_get_text (GTK_EDITABLE (widget));
             if (str && *str) {
                 nm_setting_vpn_add_secret (s_vpn, NM_SSTP_KEY_PASSWORD, str);
             }
@@ -709,7 +710,7 @@ update_connection (NMVpnEditor *iface,
 
             /* Domain */
             widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "domain_entry"));
-            str = gtk_entry_get_text (GTK_ENTRY (widget));
+            str = gtk_editable_get_text (GTK_EDITABLE (widget));
             if (str && strlen (str)) {
                 nm_setting_vpn_add_data_item (s_vpn, NM_SSTP_KEY_DOMAIN, str);
             }
diff --git a/properties/nm-sstp-editor.h b/properties/nm-sstp-editor.h
index a4a57e0..bd5888d 100644
--- a/properties/nm-sstp-editor.h
+++ b/properties/nm-sstp-editor.h
@@ -21,6 +21,17 @@
 #ifndef _NM_SSTP_H_
 #define _NM_SSTP_H_
 
+#if !GTK_CHECK_VERSION(4,0,0)
+#define gtk_editable_set_text(editable,text)        gtk_entry_set_text(GTK_ENTRY(editable), (text))
+#define gtk_editable_get_text(editable)             gtk_entry_get_text(GTK_ENTRY(editable))
+#define gtk_widget_get_root(widget)                 gtk_widget_get_toplevel(widget)
+#define gtk_window_destroy(window)                  gtk_widget_destroy(GTK_WIDGET (window))
+#define gtk_check_button_get_active(button)         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))
+#define gtk_check_button_set_active(button, active) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), 
active)
+
+typedef void GtkRoot;
+#endif
+
 #define SSTP_TYPE_PLUGIN_UI_WIDGET            (sstp_plugin_ui_widget_get_type ())
 #define SSTP_PLUGIN_UI_WIDGET(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
SSTP_TYPE_PLUGIN_UI_WIDGET, SstpPluginUiWidget))
 #define SSTP_PLUGIN_UI_WIDGET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), SSTP_TYPE_PLUGIN_UI_WIDGET, 
SstpPluginUiWidgetClass))


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