[NetworkManager-openconnect/lr/gtk-4.0: 9/12] properties: load the GtkBuilder data from a resource




commit 0b7aff75a3b0abf6dc888a36ea5e0110027efee8
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Mon Oct 25 17:34:11 2021 +0200

    properties: load the GtkBuilder data from a resource
    
    This makes some useful things possible, such as running from a built source
    tree or, in future, using a modified version of the file for Gtk4 version.

 Makefile.am                        | 27 +++++++++++++++++++++------
 configure.ac                       |  1 +
 properties/gresource.xml           |  6 ++++++
 properties/nm-openconnect-editor.c |  9 +--------
 4 files changed, 29 insertions(+), 14 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index bc0ec62..de5f5b1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -69,6 +69,19 @@ plugin_LTLIBRARIES += properties/libnm-openconnect-properties.la
 endif
 endif
 
+properties/resources.h: properties/gresource.xml
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) $< --target=$@ --sourcedir=$(srcdir)/properties 
--generate-header --internal
+
+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
+
+CLEANFILES += \
+       properties/resources.c \
+       properties/resources.h
+
+EXTRA_DIST += \
+       properties/gresource.xml
+
 plugin_sources = \
        properties/nm-openconnect-editor-plugin.c \
        properties/nm-openconnect-editor-plugin.h \
@@ -81,16 +94,10 @@ editor_sources = \
        properties/nm-openconnect-editor.h
        $(NULL)
 
-uidir = $(datadir)/gnome-vpn-properties/openconnect
-if WITH_GNOME
-ui_DATA = properties/nm-openconnect-dialog.ui
-endif
-
 properties_cppflags = \
        $(GLIB_CFLAGS) \
        $(OPENCONNECT_CFLAGS) \
        -I$(top_srcdir)/shared \
-       -DUIDIR=\""$(uidir)"\" \
        -DLOCALEDIR=\"$(datadir)/locale\"
 
 ###############################################################################
@@ -122,6 +129,10 @@ properties_libnm_vpn_plugin_openconnect_la_LDFLAGS = \
 properties_libnm_vpn_plugin_openconnect_editor_la_SOURCES = \
        $(editor_sources)
 
+nodist_properties_libnm_vpn_plugin_openconnect_editor_la_SOURCES = \
+       properties/resources.h \
+       properties/resources.c
+
 properties_libnm_vpn_plugin_openconnect_editor_la_CFLAGS = \
        -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_EDITOR \
        $(properties_cppflags) \
@@ -143,6 +154,10 @@ properties_libnm_openconnect_properties_la_SOURCES = \
        $(plugin_sources) \
        $(editor_sources)
 
+nodist_properties_libnm_openconnect_properties_la_SOURCES = \
+       properties/resources.h \
+       properties/resources.c
+
 properties_libnm_openconnect_properties_la_CFLAGS = \
        -DNM_VPN_OLD \
        -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB \
diff --git a/configure.ac b/configure.ac
index fff96b6..d0e8866 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,6 +20,7 @@ AC_PROG_CC
 AM_PROG_CC_C_O
 AC_PROG_INSTALL
 AC_PROG_LIBTOOL
+AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
 
 AC_GNU_SOURCE
 
diff --git a/properties/gresource.xml b/properties/gresource.xml
new file mode 100644
index 0000000..45efce2
--- /dev/null
+++ b/properties/gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+       <gresource prefix="/org/freedesktop/network-manager-openconnect">
+               <file preprocess="xml-stripblanks">nm-openconnect-dialog.ui</file>
+       </gresource>
+</gresources>
diff --git a/properties/nm-openconnect-editor.c b/properties/nm-openconnect-editor.c
index 85883a0..7744d05 100644
--- a/properties/nm-openconnect-editor.c
+++ b/properties/nm-openconnect-editor.c
@@ -547,7 +547,6 @@ nm_vpn_editor_new (NMConnection *connection, GError **error)
 {
        NMVpnEditor *object;
        OpenconnectEditorPrivate *priv;
-       char *ui_file;
 
        if (error)
                g_return_val_if_fail (*error == NULL, NULL);
@@ -560,22 +559,16 @@ nm_vpn_editor_new (NMConnection *connection, GError **error)
 
        priv = OPENCONNECT_EDITOR_GET_PRIVATE (object);
 
-       ui_file = g_strdup_printf ("%s/%s", UIDIR, "nm-openconnect-dialog.ui");
        priv->builder = gtk_builder_new ();
 
        gtk_builder_set_translation_domain (priv->builder, GETTEXT_PACKAGE);
 
-       if (!gtk_builder_add_from_file (priv->builder, ui_file, error)) {
+       if (!gtk_builder_add_from_resource (priv->builder, 
"/org/freedesktop/network-manager-openconnect/nm-openconnect-dialog.ui", error)) {
                g_warning ("Couldn't load builder file: %s",
                           error && *error ? (*error)->message : "(unknown)");
-               g_clear_error (error);
-               g_set_error (error, NMV_EDITOR_PLUGIN_ERROR, 0,
-                            "could not load required resources at %s", ui_file);
-               g_free (ui_file);
                g_object_unref (object);
                return NULL;
        }
-       g_free (ui_file);
 
        priv->widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "openconnect-vbox"));
        if (!priv->widget) {


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