[NetworkManager-vpnc/lr/gtk-4.0: 7/15] properties: load the GtkBuilder data from a resource




commit 3b5b1f78574268558541de5121a4a16d7a210bd3
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Wed Nov 3 13:56:13 2021 +0100

    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.

 .gitignore                  |  2 ++
 Makefile.am                 | 26 ++++++++++++++++++--------
 configure.ac                |  1 +
 properties/gresource.xml    |  6 ++++++
 properties/nm-vpnc-editor.c |  9 +--------
 5 files changed, 28 insertions(+), 16 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 9cb590f..68495af 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,6 +46,8 @@ nm-vpnc-service.name
 nm-vpnc.desktop
 properties/tests/test-import-export
 properties/tests/test-import-export-glib
+properties/resources.c
+properties/resources.h
 src/nm-vpnc-service
 src/nm-vpnc-service-vpnc-helper
 src/test-vpnc-output
diff --git a/Makefile.am b/Makefile.am
index 26fb247..787863b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -90,6 +90,12 @@ plugin_LTLIBRARIES += properties/libnm-vpnc-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
+
 plugin_sources = \
        properties/nm-vpnc-helper.c \
        properties/nm-vpnc-helper.h \
@@ -100,11 +106,6 @@ editor_sources = \
        properties/nm-vpnc-editor.c \
        properties/nm-vpnc-editor.h
 
-uidir = $(datadir)/gnome-vpn-properties/vpnc
-if WITH_GNOME
-ui_DATA = properties/nm-vpnc-dialog.ui
-endif
-
 ###############################################################################
 
 properties_libnm_vpn_plugin_vpnc_la_SOURCES = \
@@ -136,10 +137,13 @@ properties_libnm_vpn_plugin_vpnc_editor_la_SOURCES = \
        $(shared_sources) \
        $(editor_sources)
 
+nodist_properties_libnm_vpn_plugin_vpnc_editor_la_SOURCES = \
+       properties/resources.h \
+       properties/resources.c
+
 properties_libnm_vpn_plugin_vpnc_editor_la_CFLAGS = \
        -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB_EDITOR \
        $(common_cppflags) \
-       -DUIDIR=\""$(uidir)"\" \
        $(GTK_CFLAGS) \
        $(LIBNM_CFLAGS) \
        $(LIBNMA_CFLAGS)
@@ -160,11 +164,14 @@ properties_libnm_vpnc_properties_la_SOURCES = \
        $(plugin_sources) \
        $(editor_sources)
 
+nodist_properties_libnm_vpnc_properties_la_SOURCES = \
+       properties/resources.h \
+       properties/resources.c
+
 properties_libnm_vpnc_properties_la_CFLAGS = \
        -DNM_VPN_OLD \
        -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_LIB \
        -DLOCALEDIR=\"$(datadir)/locale\"
-       -DUIDIR=\""$(uidir)"\" \
        $(common_cppflags) \
        $(GTK_CFLAGS) \
        $(LIBNM_GLIB_CFLAGS) \
@@ -311,6 +318,7 @@ EXTRA_DIST = \
        properties/libnm-vpn-plugin-vpnc-editor.ver \
        properties/libnm-vpnc-properties.ver \
        properties/nm-vpnc-dialog.ui \
+       properties/gresource.xml \
        \
        properties/tests/pcf/basic.pcf \
        properties/tests/pcf/everything-via-vpn.pcf \
@@ -341,7 +349,9 @@ EXTRA_DIST = \
 
 CLEANFILES = *.bak *~ \
        $(nmvpnservice_DATA) \
-       $(appdata_files)
+       $(appdata_files) \
+       properties/resources.c \
+       properties/resources.h
 
 DISTCLEANFILES = intltool-extract intltool-merge intltool-update
 
diff --git a/configure.ac b/configure.ac
index 07467e4..3c71d19 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,6 +18,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..fb4339d
--- /dev/null
+++ b/properties/gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+        <gresource prefix="/org/freedesktop/network-manager-vpnc">
+                <file preprocess="xml-stripblanks">nm-vpnc-dialog.ui</file>
+        </gresource>
+</gresources>
diff --git a/properties/nm-vpnc-editor.c b/properties/nm-vpnc-editor.c
index f266cc3..2c0db1e 100644
--- a/properties/nm-vpnc-editor.c
+++ b/properties/nm-vpnc-editor.c
@@ -940,7 +940,6 @@ nm_vpnc_editor_new (NMConnection *connection, GError **error)
 {
        NMVpnEditor *object;
        VpncEditorPrivate *priv;
-       char *ui_file;
        NMSettingVpn *s_vpn;
        gboolean is_new = TRUE;
 
@@ -956,22 +955,16 @@ nm_vpnc_editor_new (NMConnection *connection, GError **error)
 
        priv = VPNC_EDITOR_GET_PRIVATE (object);
 
-       ui_file = g_strdup_printf ("%s/%s", UIDIR, "nm-vpnc-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-vpnc/nm-vpnc-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, NMV_EDITOR_PLUGIN_ERROR_FAILED,
-                            "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, "vpnc-vbox"));
        if (!priv->widget) {


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