[NetworkManager-fortisslvpn/lr/gtk4: 5/5] all: add support for Gtk4




commit 7d4e1051b9d8611ccd192a5f4baada59ffbbc352
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Mon Oct 11 12:56:39 2021 +0200

    all: add support for Gtk4

 .gitignore                                |  1 +
 Makefile.am                               | 39 ++++++++++++++-
 configure.ac                              | 30 +++++++++---
 properties/nm-fortisslvpn-editor-plugin.c | 32 +++++++++----
 properties/nm-fortisslvpn-editor.c        | 80 ++++++++++++++++---------------
 5 files changed, 126 insertions(+), 56 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index b2c8982..9e3c97c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,6 +23,7 @@ stamp-*
 .libs
 autom4te.cache
 intltool-*
+gtk4/
 po/boldquot.sed
 po/en@boldquot.header
 po/en@quot.header
diff --git a/Makefile.am b/Makefile.am
index 883a730..8ccfa2c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -143,12 +143,20 @@ 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=$(builddir)/gtk4 --generate-source 
--internal
+
+gtk4/%.ui: properties/%.ui
+       @mkdir -p $(builddir)/gtk4/properties
+       gtk4-builder-tool simplify --3to4 $< >$@
+
 plugin_sources = \
        properties/nm-fortisslvpn-editor-plugin.c \
        properties/nm-fortisslvpn-editor-plugin.h
 
 editor_sources = \
-       properties/resources.c \
        properties/resources.h \
        properties/nm-fortisslvpn-editor.c \
        properties/nm-fortisslvpn-editor.h \
@@ -219,6 +227,7 @@ plugin_LTLIBRARIES += properties/libnm-vpn-plugin-fortisslvpn-editor.la
 endif
 
 properties_libnm_vpn_plugin_fortisslvpn_editor_la_SOURCES = \
+       properties/resources.c \
        $(editor_sources)
 
 properties_libnm_vpn_plugin_fortisslvpn_editor_la_CPPFLAGS = \
@@ -241,6 +250,33 @@ properties_libnm_vpn_plugin_fortisslvpn_editor_la_LDFLAGS = \
 
 ###############################################################################
 
+if WITH_GTK4
+plugin_LTLIBRARIES += properties/libnm-gtk4-vpn-plugin-fortisslvpn-editor.la
+endif
+
+properties_libnm_gtk4_vpn_plugin_fortisslvpn_editor_la_SOURCES = \
+       gtk4/resources.c \
+       $(editor_sources)
+
+properties_libnm_gtk4_vpn_plugin_fortisslvpn_editor_la_CPPFLAGS = \
+       -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_EDITOR \
+       $(properties_cppflags) \
+       $(GTK4_CFLAGS) \
+       $(LIBNM_CFLAGS) \
+       $(LIBNMA_GTK4_CFLAGS)
+
+properties_libnm_gtk4_vpn_plugin_fortisslvpn_editor_la_LIBADD = \
+       properties/libnm-vpn-plugin-fortisslvpn-utils.la \
+       $(GLIB_LIBS) \
+       $(GTK4_LIBS) \
+       $(LIBNM_LIBS) \
+       $(LIBNMA_GTK4_LIBS)
+
+properties_libnm_gtk4_vpn_plugin_fortisslvpn_editor_la_LDFLAGS = \
+       $(properties_libnm_vpn_plugin_fortisslvpn_editor_la_LDFLAGS)
+
+###############################################################################
+
 if WITH_LIBNM_GLIB
 noinst_LTLIBRARIES += properties/libnm-fortisslvpn-properties-core.la
 endif
@@ -248,6 +284,7 @@ endif
 properties_libnm_fortisslvpn_properties_core_la_SOURCES = \
        $(shared_sources) \
        $(plugin_sources) \
+       properties/resources.c \
        $(editor_sources)
 
 properties_libnm_fortisslvpn_properties_core_la_CPPFLAGS = \
diff --git a/configure.ac b/configure.ac
index 01b89be..d1cc4c9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,6 +74,7 @@ dnl
 dnl GNOME support
 dnl
 AC_ARG_WITH(gnome, AS_HELP_STRING([--without-gnome], [Build NetworkManager-fortisslvpn without GNOME 
support, e.g. vpn service only]), [], [with_gnome_specified=no])
+AC_ARG_WITH(gtk4, AS_HELP_STRING([--with-gtk4], [Build NetworkManager-fortisslvpn with libnma-gtk4 
support]), [], [with_gtk4_specified=no])
 AC_ARG_WITH(libnm-glib, AS_HELP_STRING([--with-libnm-glib], [Build NetworkManager-fortisslvpn with 
libnm-glib comatibility (depreacted)]), [], [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
@@ -83,6 +84,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
@@ -90,6 +97,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)]))
@@ -108,17 +116,19 @@ AC_SUBST(GLIB_LIBS)
 GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32"
 GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"
 
-if test x"$with_gnome" != xno; then
-       PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 3.4)
-       GTK_CFLAGS="$GTK_CFLAGS -DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_4"
-       GTK_CFLAGS="$GTK_CFLAGS -DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_3_4"
-
-       PKG_CHECK_MODULES(LIBNMA, libnma >= 1.2.0)
+if test x"$with_gnome" != xno || test x"$with_gtk4" != xno; then
        PKG_CHECK_MODULES(LIBSECRET, libsecret-1 >= 0.18, [], [
                dnl We use the secret service API that went stable in 0.18
                PKG_CHECK_MODULES(LIBSECRET, libsecret-unstable)
                LIBSECRET_CFLAGS="$LIBSECRET_CFLAGS -DSECRET_API_SUBJECT_TO_CHANGE"
        ])
+fi
+
+if test x"$with_gnome" != xno; then
+       PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 3.4)
+       GTK_CFLAGS="$GTK_CFLAGS -DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_4"
+       GTK_CFLAGS="$GTK_CFLAGS -DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_3_4"
+       PKG_CHECK_MODULES(LIBNMA, libnma >= 1.2.0)
 
        if test x"$with_libnm_glib" != xno; then
                PKG_CHECK_MODULES(LIBNM_GTK, libnm-gtk >= 1.2.0)
@@ -133,6 +143,13 @@ if test x"$with_gnome" != xno; then
        fi
 fi
 
+if test x"$with_gtk4" != xno; then
+       PKG_CHECK_MODULES(GTK4, gtk4 >= 3.96)
+       GTK4_CFLAGS="$GTK4_CFLAGS -DGTK_VERSION_MIN_REQUIRED=GTK_VERSION_3_96"
+       GTK4_CFLAGS="$GTK4_CFLAGS -DGTK_VERSION_MAX_ALLOWED=GTK_VERSION_3_96"
+       PKG_CHECK_MODULES(LIBNMA_GTK4, libnma-gtk4 >= 1.8.32)
+fi
+
 PKG_CHECK_MODULES(LIBNM, libnm >= 1.2.0)
 LIBNM_CFLAGS="$LIBNM_CFLAGS -DNM_VERSION_MIN_REQUIRED=NM_VERSION_1_2"
 LIBNM_CFLAGS="$LIBNM_CFLAGS -DNM_VERSION_MAX_ALLOWED=NM_VERSION_1_2"
@@ -170,6 +187,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 "  --enable-absolute-paths=$enable_absolute_paths"
diff --git a/properties/nm-fortisslvpn-editor-plugin.c b/properties/nm-fortisslvpn-editor-plugin.c
index 0c5ff73..26e1f59 100644
--- a/properties/nm-fortisslvpn-editor-plugin.c
+++ b/properties/nm-fortisslvpn-editor-plugin.c
@@ -79,23 +79,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 (FORTISSLVPN_IS_EDITOR_PLUGIN (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-fortisslvpn-editor.so";
+       } else {
+               editor = "libnm-gtk4-vpn-plugin-fortisslvpn-editor.so";
+       }
+
 #ifdef NM_VPN_OLD
-               return nm_fortisslvpn_editor_new (connection, error);
+       return nm_fortisslvpn_editor_new (connection, error);
 #else
-               return nm_vpn_plugin_utils_load_editor ("libnm-vpn-plugin-fortisslvpn-editor.so",
-                                                       "nm_vpn_editor_factory_fortisslvpn",
-                                                       _call_editor_factory,
-                                                       iface,
-                                                       connection,
-                                                       NULL,
-                                                       error);
+       return nm_vpn_plugin_utils_load_editor (editor,
+                                               "nm_vpn_editor_factory_fortisslvpn",
+                                               _call_editor_factory,
+                                               iface,
+                                               connection,
+                                               NULL,
+                                               error);
 #endif
-       }
 }
 
 static void
diff --git a/properties/nm-fortisslvpn-editor.c b/properties/nm-fortisslvpn-editor.c
index 293f12e..819e9df 100644
--- a/properties/nm-fortisslvpn-editor.c
+++ b/properties/nm-fortisslvpn-editor.c
@@ -35,6 +35,17 @@
 
 /*****************************************************************************/
 
+#if !GTK_CHECK_VERSION(3,96,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 gtk3_widget_show_all(widget)           gtk_widget_show_all(widget)
+#define gtk_widget_get_root(widget)            gtk_widget_get_toplevel(widget)
+#else
+#define gtk3_widget_show_all(widget)
+#endif
+
+/*****************************************************************************/
+
 typedef struct {
        GtkBuilder *builder;
        GtkWidget *widget;
@@ -78,7 +89,7 @@ setup_password_widget (FortisslvpnEditor *self,
 
        if (s_vpn) {
                value = nm_setting_vpn_get_secret (s_vpn, secret_name);
-               gtk_entry_set_text (GTK_ENTRY (widget), value ? value : "");
+               gtk_editable_set_text (GTK_EDITABLE (widget), value ? value : "");
        }
 
        g_signal_connect (widget, "changed", G_CALLBACK (stuff_changed_cb), self);
@@ -133,7 +144,7 @@ init_password_icon (FortisslvpnEditor *self,
         */
        if (s_vpn)
                nm_setting_get_secret_flags (NM_SETTING (s_vpn), secret_key, &pw_flags, NULL);
-       value = gtk_entry_get_text (GTK_ENTRY (entry));
+       value = gtk_editable_get_text (GTK_EDITABLE (entry));
        if ((!value || !*value) && (pw_flags == NM_SETTING_SECRET_FLAG_NONE))
                nma_utils_update_password_storage (entry, NM_SETTING_SECRET_FLAG_NOT_SAVED,
                                                   (NMSetting *) s_vpn, secret_key);
@@ -154,8 +165,8 @@ advanced_dialog_response_cb (GtkWidget *dialog, gint response, gpointer user_dat
 {
        FortisslvpnEditor *self = FORTISSLVPN_EDITOR (user_data);
        FortisslvpnEditorPrivate *priv = FORTISSLVPN_EDITOR_GET_PRIVATE (self);
-       GtkEntry *trusted_cert_entry = GTK_ENTRY (gtk_builder_get_object (priv->builder, 
"trusted_cert_entry"));
-       GtkEntry *realm_entry = GTK_ENTRY (gtk_builder_get_object (priv->builder, "realm_entry"));
+       GtkEditable *trusted_cert_entry = GTK_EDITABLE (gtk_builder_get_object (priv->builder, 
"trusted_cert_entry"));
+       GtkEditable *realm_entry = GTK_EDITABLE (gtk_builder_get_object (priv->builder, "realm_entry"));
        GtkSwitch *use_otp = GTK_SWITCH (gtk_builder_get_object (priv->builder, "use_otp"));
 
        g_return_if_fail (trusted_cert_entry);
@@ -163,8 +174,8 @@ advanced_dialog_response_cb (GtkWidget *dialog, gint response, gpointer user_dat
 
        if (response == GTK_RESPONSE_OK) {
                g_free (priv->trusted_cert);
-               priv->trusted_cert = g_strdup (gtk_entry_get_text (trusted_cert_entry));
-               priv->realm = g_strdup (gtk_entry_get_text (realm_entry));
+               priv->trusted_cert = g_strdup (gtk_editable_get_text (trusted_cert_entry));
+               priv->realm = g_strdup (gtk_editable_get_text (realm_entry));
                stuff_changed_cb (NULL, self);
 
                if (gtk_switch_get_active (use_otp))
@@ -172,8 +183,8 @@ advanced_dialog_response_cb (GtkWidget *dialog, gint response, gpointer user_dat
                else
                        priv->otp_flags &= ~NM_SETTING_SECRET_FLAG_NOT_SAVED;
        } else {
-               gtk_entry_set_text (trusted_cert_entry, priv->trusted_cert);
-               gtk_entry_set_text (realm_entry, priv->realm);
+               gtk_editable_set_text (trusted_cert_entry, priv->trusted_cert);
+               gtk_editable_set_text (realm_entry, priv->realm);
                gtk_switch_set_active (use_otp,
                                       priv->otp_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED);
        }
@@ -187,20 +198,25 @@ advanced_button_clicked_cb (GtkWidget *button, gpointer user_data)
        FortisslvpnEditor *self = FORTISSLVPN_EDITOR (user_data);
        FortisslvpnEditorPrivate *priv = FORTISSLVPN_EDITOR_GET_PRIVATE (self);
        GtkWidget *dialog = GTK_WIDGET (gtk_builder_get_object (priv->builder, "advanced_dialog"));
+       void *root;
+
        g_assert (dialog);
 
-       if (!priv->window_added) {
-               GtkWidget *toplevel = gtk_widget_get_toplevel (priv->widget);
+       if (!priv->window_added)
+               root = gtk_widget_get_root (priv->widget);
+       else
+               root = NULL;
 
-               g_assert (gtk_widget_is_toplevel (toplevel));
-               gtk_window_group_add_window (priv->window_group, GTK_WINDOW (toplevel));
+       if (GTK_IS_WINDOW(root)) {
+               gtk_window_group_add_window (priv->window_group, GTK_WINDOW (root));
                gtk_window_group_add_window (priv->window_group, GTK_WINDOW (dialog));
-               gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
+               gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (root));
                priv->window_added = TRUE;
        }
 
        gtk_widget_grab_focus (GTK_WIDGET (gtk_builder_get_object (priv->builder, "ok_button")));
-       gtk_widget_show_all (dialog);
+       gtk3_widget_show_all (dialog);
+       gtk_widget_show (dialog);
 }
 
 static gboolean
@@ -222,7 +238,7 @@ init_editor_plugin (FortisslvpnEditor *self, NMConnection *connection, GError **
        if (s_vpn) {
                value = nm_setting_vpn_get_data_item (s_vpn, NM_FORTISSLVPN_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);
 
@@ -232,7 +248,7 @@ init_editor_plugin (FortisslvpnEditor *self, NMConnection *connection, GError **
        if (s_vpn) {
                value = nm_setting_vpn_get_data_item (s_vpn, NM_FORTISSLVPN_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 (stuff_changed_cb), self);
 
@@ -243,7 +259,7 @@ init_editor_plugin (FortisslvpnEditor *self, NMConnection *connection, GError **
                                                                             
NM_FORTISSLVPN_KEY_TRUSTED_CERT));
                if (!priv->trusted_cert)
                        priv->trusted_cert = g_strdup ("");
-               gtk_entry_set_text (GTK_ENTRY (widget), priv->trusted_cert);
+               gtk_editable_set_text (GTK_EDITABLE (widget), priv->trusted_cert);
        }
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "realm_entry"));
@@ -253,7 +269,7 @@ init_editor_plugin (FortisslvpnEditor *self, NMConnection *connection, GError **
                                                                      NM_FORTISSLVPN_KEY_REALM));
                if (!priv->realm)
                        priv->realm = g_strdup ("");
-               gtk_entry_set_text (GTK_ENTRY (widget), priv->realm);
+               gtk_editable_set_text (GTK_EDITABLE (widget), priv->realm);
        }
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "use_otp"));
@@ -322,7 +338,11 @@ init_editor_plugin (FortisslvpnEditor *self, NMConnection *connection, GError **
        g_return_val_if_fail (widget, FALSE);
 
        g_signal_connect (G_OBJECT (widget), "response", G_CALLBACK (advanced_dialog_response_cb), self);
+#if GTK_CHECK_VERSION(3,90,0)
+       g_signal_connect (G_OBJECT (widget), "close-request", G_CALLBACK (advanced_dialog_delete_cb), NULL);
+#else
        g_signal_connect (G_OBJECT (widget), "delete-event", G_CALLBACK (advanced_dialog_delete_cb), NULL);
+#endif
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "advanced_button"));
        g_return_val_if_fail (widget, FALSE);
@@ -359,7 +379,7 @@ save_password_and_flags (NMSettingVpn *s_vpn,
        switch (flags) {
        case NM_SETTING_SECRET_FLAG_NONE:
        case NM_SETTING_SECRET_FLAG_AGENT_OWNED:
-               password = gtk_entry_get_text (GTK_ENTRY (entry));
+               password = gtk_editable_get_text (GTK_EDITABLE (entry));
                if (password && strlen (password))
                        nm_setting_vpn_add_secret (s_vpn, secret_key, password);
                break;
@@ -387,13 +407,13 @@ 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_FORTISSLVPN_KEY_GATEWAY, str);
 
        /* 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_FORTISSLVPN_KEY_USER, str);
 
@@ -403,24 +423,6 @@ update_connection (NMVpnEditor *iface,
                                 "user_password_entry",
                                 NM_FORTISSLVPN_KEY_PASSWORD);
 
-       /* CA file */
-       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "ca_chooser"));
-       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 = 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, "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);
-
        /* Trusted certificate */
        if (priv->trusted_cert && strlen (priv->trusted_cert))
                nm_setting_vpn_add_data_item (s_vpn,


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