[NetworkManager-openconnect/lr/gtk-4.0: 8/8] properties: port to Gtk4




commit ba1755971f60579c78d90764438f293967a5f607
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Mon Oct 25 18:40:44 2021 +0200

    properties: port to Gtk4

 Makefile.am                               | 40 ++++++++++++++++++++++++++++++-
 configure.ac                              | 22 +++++++++++++++--
 properties/nm-openconnect-editor-plugin.c | 32 +++++++++++++++++--------
 properties/nm-openconnect-editor.c        | 39 +++++++++++++++++-------------
 4 files changed, 104 insertions(+), 29 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 5096331..8648a8e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -68,6 +68,9 @@ if WITH_LIBNM_GLIB
 plugin_LTLIBRARIES += properties/libnm-openconnect-properties.la
 endif
 endif
+if WITH_GTK4
+plugin_LTLIBRARIES += properties/libnm-gtk4-vpn-plugin-openconnect-editor.la
+endif
 
 properties/resources.h: properties/gresource.xml
        $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $< --target=$@ --sourcedir=$(srcdir)/properties 
--generate-header --internal
@@ -75,7 +78,16 @@ 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
+       gtk4-builder-tool simplify --3to4 $< |grep -v can-default >$@
+
 CLEANFILES += \
+       gtk4/resources.c \
        properties/resources.c \
        properties/resources.h
 
@@ -156,6 +168,32 @@ properties_libnm_vpn_plugin_openconnect_editor_la_LDFLAGS = \
 
 ###############################################################################
 
+properties_libnm_gtk4_vpn_plugin_openconnect_editor_la_SOURCES = \
+       $(editor_sources)
+
+nodist_properties_libnm_gtk4_vpn_plugin_openconnect_editor_la_SOURCES = \
+       properties/resources.h \
+       gtk4/resources.c
+
+properties_libnm_gtk4_vpn_plugin_openconnect_editor_la_CFLAGS = \
+       -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_EDITOR \
+       $(properties_cppflags) \
+       $(GTK4_CFLAGS) \
+       $(LIBNM_CFLAGS) \
+       $(LIBNMA_GTK4_CFLAGS)
+
+properties_libnm_gtk4_vpn_plugin_openconnect_editor_la_LIBADD = \
+       $(GTK4_LIBS) \
+       $(LIBNM_LIBS) \
+       $(LIBNMA_GTK4_LIBS) \
+       $(OPENCONNECT_LIBS)
+
+properties_libnm_gtk4_vpn_plugin_openconnect_editor_la_LDFLAGS = \
+       -avoid-version \
+       -Wl,--version-script="$(srcdir)/properties/libnm-vpn-plugin-openconnect-editor.ver"
+
+###############################################################################
+
 properties_libnm_openconnect_properties_la_SOURCES = \
        $(plugin_sources) \
        $(editor_sources)
@@ -246,7 +284,7 @@ nm-openconnect-service.name: $(srcdir)/nm-openconnect-service.name.in
            -e 's|[@]PLUGINDIR[@]/|@NM_PLUGIN_DIR_NAME_FILE@|g' \
            $< >$@
 
-DISTCHECK_CONFIGURE_FLAGS = --enable-more-warnings=yes
+DISTCHECK_CONFIGURE_FLAGS = --enable-more-warnings=yes --with-gtk4
 
 CLEANFILES +=                          \
        $(nmvpnservice_DATA)            \
diff --git a/configure.ac b/configure.ac
index 5f03806..4bbbf47 100644
--- a/configure.ac
+++ b/configure.ac
@@ -71,6 +71,7 @@ dnl
 dnl GNOME support
 dnl
 AC_ARG_WITH(gnome, AS_HELP_STRING([--without-gnome], [Build NetworkManager-openconnect without GNOME 
support, e.g. vpn service only]), [], [with_gnome_specified=no])
+AC_ARG_WITH(gtk4, AS_HELP_STRING([--with-gtk4], [Build NetworkManager-openconnect with libnma-gtk4 
support]), [], [with_gtk4_specified=no])
 AC_ARG_WITH(libnm-glib, AS_HELP_STRING([--with-libnm-glib], [Build NetworkManager-openconnect 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
@@ -80,6 +81,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
@@ -87,6 +94,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)]))
@@ -103,6 +111,10 @@ GLIB_CFLAGS="$GLIB_CFLAGS -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_32"
 
 PKG_CHECK_MODULES(LIBXML, libxml-2.0)
 
+if test x"$with_gnome" != xno || test x"$with_gtk4" != xno; then
+       PKG_CHECK_MODULES(LIBSECRET, libsecret-1 >= 0.18)
+fi
+
 if test x"$with_gnome" != xno; then
        PKG_CHECK_MODULES(GTK, gtk+-3.0 >= 3.12)
        GTK_CFLAGS="$GTK_CFLAGS -DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_12"
@@ -112,8 +124,6 @@ if test x"$with_gnome" != xno; then
        PKG_CHECK_MODULES(GCR, gcr-3 >= 3.4)
        GCR_CFLAGS="$GCR_CFLAGS -DGCR_API_SUBJECT_TO_CHANGE"
 
-       PKG_CHECK_MODULES(LIBSECRET, libsecret-1 >= 0.18)
-
        if test x"$with_libnm_glib" != xno; then
                PKG_CHECK_MODULES(LIBNM_GLIB,
                        NetworkManager >= 1.2.0
@@ -126,6 +136,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.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_4"
@@ -178,6 +195,7 @@ AC_OUTPUT
 echo ""
 echo "Build configuration: "
 echo "  --with-gnome=$with_gnome"
+echo "  --with-gtk4=$with_gtk4"
 echo "  --with-libnm-glib=$with_libnm_glib"
 echo "  --with-authdlg=$with_authdlg"
 echo "  --enable-absolute-paths=$enable_absolute_paths"
diff --git a/properties/nm-openconnect-editor-plugin.c b/properties/nm-openconnect-editor-plugin.c
index 2b3ce41..f475c7d 100644
--- a/properties/nm-openconnect-editor-plugin.c
+++ b/properties/nm-openconnect-editor-plugin.c
@@ -515,23 +515,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 (OPENCONNECT_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-openconnect-editor.so";
+       } else {
+               editor = "libnm-gtk4-vpn-plugin-openconnect-editor.so";
+       }
+
 #ifdef NM_VPN_OLD
-               return nm_vpn_editor_new (connection, error);
+       return nm_vpn_editor_new (connection, error);
 #else
-               return nm_vpn_plugin_utils_load_editor ("libnm-vpn-plugin-openconnect-editor.so",
-                                                       "nm_vpn_editor_factory_openconnect",
-                                                       _call_editor_factory,
-                                                       iface,
-                                                       connection,
-                                                       NULL,
-                                                       error);
+       return nm_vpn_plugin_utils_load_editor (editor,
+                                               "nm_vpn_editor_factory_openconnect",
+                                               _call_editor_factory,
+                                               iface,
+                                               connection,
+                                               NULL,
+                                               error);
 #endif
-       }
 }
 
 static void
diff --git a/properties/nm-openconnect-editor.c b/properties/nm-openconnect-editor.c
index 7744d05..de0c27a 100644
--- a/properties/nm-openconnect-editor.c
+++ b/properties/nm-openconnect-editor.c
@@ -49,6 +49,13 @@
 
 #include "auth-helpers.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_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)
+#endif
+
 /************** UI widget class **************/
 
 static void openconnect_editor_interface_init (NMVpnEditorInterface *iface_class);
@@ -80,7 +87,7 @@ check_validity (OpenconnectEditor *self, GError **error)
        const char *str;
 
        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)) {
                g_set_error (error,
                             NMV_EDITOR_PLUGIN_ERROR,
@@ -91,7 +98,7 @@ check_validity (OpenconnectEditor *self, GError **error)
 
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "proxy_entry"));
-       str = gtk_entry_get_text (GTK_ENTRY (widget));
+       str = gtk_editable_get_text (GTK_EDITABLE (widget));
        if (str && str[0] &&
                strncmp(str, "socks://", 8) && strncmp(str, "http://";, 7)) {
                g_set_error (error,
@@ -323,7 +330,7 @@ init_editor_plugin (OpenconnectEditor *self, NMConnection *connection, GError **
        if (s_vpn) {
                value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_GATEWAY);
                if (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);
 
@@ -333,7 +340,7 @@ init_editor_plugin (OpenconnectEditor *self, NMConnection *connection, GError **
        if (s_vpn) {
                value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_PROXY);
                if (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);
 
@@ -343,7 +350,7 @@ init_editor_plugin (OpenconnectEditor *self, NMConnection *connection, GError **
        if (s_vpn) {
                value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_PEM_PASSPHRASE_FSID);
                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);
        }
        g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (stuff_changed_cb), self);
 
@@ -353,7 +360,7 @@ init_editor_plugin (OpenconnectEditor *self, NMConnection *connection, GError **
        if (s_vpn) {
                value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_PREVENT_INVALID_CERT);
                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);
        }
        g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (stuff_changed_cb), self);
 
@@ -363,7 +370,7 @@ init_editor_plugin (OpenconnectEditor *self, NMConnection *connection, GError **
        if (s_vpn) {
                value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_CSD_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);
        }
        g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (stuff_changed_cb), self);
 
@@ -373,7 +380,7 @@ init_editor_plugin (OpenconnectEditor *self, NMConnection *connection, GError **
        if (s_vpn) {
                value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_CSD_WRAPPER);
                if (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);
 
@@ -383,7 +390,7 @@ init_editor_plugin (OpenconnectEditor *self, NMConnection *connection, GError **
        if (s_vpn) {
                value = nm_setting_vpn_get_data_item (s_vpn, NM_OPENCONNECT_KEY_REPORTED_OS);
                if (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);
 
@@ -444,34 +451,34 @@ update_connection (NMVpnEditor *iface,
        }
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "gateway_entry"));
-       str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+       str = (char *) gtk_editable_get_text (GTK_EDITABLE (widget));
        if (str && strlen (str))
                nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_GATEWAY, str);
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "proxy_entry"));
-       str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+       str = (char *) gtk_editable_get_text (GTK_EDITABLE (widget));
        if (str && strlen (str))
                nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_PROXY, str);
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "fsid_button"));
-       str = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget))?"yes":"no";
+       str = gtk_check_button_get_active (GTK_CHECK_BUTTON (widget))?"yes":"no";
        nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_PEM_PASSPHRASE_FSID, str);
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "prevent_invalid_cert_button"));
-       str = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget))?"yes":"no";
+       str = gtk_check_button_get_active (GTK_CHECK_BUTTON (widget))?"yes":"no";
        nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_PREVENT_INVALID_CERT, str);
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "csd_button"));
-       str = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (widget))?"yes":"no";
+       str = gtk_check_button_get_active (GTK_CHECK_BUTTON (widget))?"yes":"no";
        nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_CSD_ENABLE, str);
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "csd_wrapper_entry"));
-       str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+       str = (char *) gtk_editable_get_text (GTK_EDITABLE (widget));
        if (str && strlen (str))
                nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_CSD_WRAPPER, str);
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "reported_os"));
-       str = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+       str = (char *) gtk_editable_get_text (GTK_EDITABLE (widget));
        if (str && strlen (str))
                nm_setting_vpn_add_data_item (s_vpn, NM_OPENCONNECT_KEY_REPORTED_OS, str);
 


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