summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbuj <[email protected]>2019-05-02 12:21:04 +0200
committerraveit65 <[email protected]>2019-05-04 21:11:48 +0200
commitb3605bee34d6b62eb4e5057bbad40513bdc600df (patch)
treeae1e2c3c91b19dca750974667b3d265b88c10557
parentd97327cd31de7d47054ee4caa299de51d9b4349e (diff)
downloadmate-calc-b3605bee34d6b62eb4e5057bbad40513bdc600df.tar.bz2
mate-calc-b3605bee34d6b62eb4e5057bbad40513bdc600df.tar.xz
Use gresources for UI files
.ui files are combined into a binary resource bundle, and they are marked as compressed, so they will be automatically uncompressed when the resource is used. REF https://developer.gnome.org/gio/stable/GResource.html
-rw-r--r--configure.ac18
-rw-r--r--data/Makefile.am9
-rw-r--r--po/POTFILES.in10
-rw-r--r--src/Makefile.am23
-rw-r--r--src/buttons-advanced.ui (renamed from data/buttons-advanced.ui)0
-rw-r--r--src/buttons-basic.ui (renamed from data/buttons-basic.ui)0
-rw-r--r--src/buttons-financial.ui (renamed from data/buttons-financial.ui)0
-rw-r--r--src/buttons-programming.ui (renamed from data/buttons-programming.ui)0
-rw-r--r--src/math-buttons.c20
-rw-r--r--src/math-preferences.c4
-rw-r--r--src/org.mate.calculator.gresource.xml26
-rw-r--r--src/preferences.ui (renamed from data/preferences.ui)0
12 files changed, 81 insertions, 29 deletions
diff --git a/configure.ac b/configure.ac
index b54c8ba..104c103 100644
--- a/configure.ac
+++ b/configure.ac
@@ -49,6 +49,24 @@ dnl ###########################################################################
IT_PROG_INTLTOOL([0.35.0])
AC_SUBST(GETTEXT_PACKAGE, mate-calc)
+# **********************
+# GLIB_COMPILE_RESOURCES
+# **********************
+AC_ARG_VAR([GLIB_COMPILE_RESOURCES],[glib-compile-resources bin])
+AC_PATH_PROG([GLIB_COMPILE_RESOURCES],[glib-compile-resources],[])
+if test -z "$GLIB_COMPILE_RESOURCES"; then
+ AC_MSG_ERROR([glib-compile-resources not found])
+fi
+
+# *******
+# XMLLINT
+# *******
+AC_ARG_VAR([XMLLINT],[xmllint bin])
+AC_PATH_PROG([XMLLINT],[xmllint],[])
+if test -z "$XMLLINT"; then
+ AC_MSG_ERROR([xmllint not found])
+fi
+
dnl ###########################################################################
dnl Documentation
dnl ###########################################################################
diff --git a/data/Makefile.am b/data/Makefile.am
index f9e00c2..1a8150b 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,11 +1,3 @@
-uidir = $(datadir)/mate-calc
-ui_DATA = \
- preferences.ui \
- buttons-basic.ui \
- buttons-advanced.ui \
- buttons-financial.ui \
- buttons-programming.ui
-
@INTLTOOL_XML_RULE@
appdatadir = $(datadir)/metainfo
appdata_in_files = mate-calc.appdata.xml.in
@@ -22,7 +14,6 @@ Utilities_DATA = $(Utilities_in_files:.desktop.in=.desktop)
man1_MANS = mate-calc.1 mate-calc-cmd.1
EXTRA_DIST = \
- $(ui_DATA) \
org.mate.calc.gschema.xml.in \
mate-calc.desktop.in \
$(appdata_in_files) \
diff --git a/po/POTFILES.in b/po/POTFILES.in
index fe8c21b..40f90fe 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,11 +1,11 @@
# List of source files containing translatable strings.
# Please keep this file sorted alphabetically.
[encoding: UTF-8]
-[type: gettext/glade]data/buttons-advanced.ui
-[type: gettext/glade]data/buttons-basic.ui
-[type: gettext/glade]data/buttons-financial.ui
-[type: gettext/glade]data/buttons-programming.ui
-[type: gettext/glade]data/preferences.ui
+[type: gettext/glade]src/buttons-advanced.ui
+[type: gettext/glade]src/buttons-basic.ui
+[type: gettext/glade]src/buttons-financial.ui
+[type: gettext/glade]src/buttons-programming.ui
+[type: gettext/glade]src/preferences.ui
data/mate-calc.appdata.xml.in
data/mate-calc.desktop.in
data/org.mate.calc.gschema.xml.in
diff --git a/src/Makefile.am b/src/Makefile.am
index e187118..b6690a1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,13 +4,18 @@ noinst_PROGRAMS = test-mp test-mp-equation
TESTS = test-mp test-mp-equation
AM_CPPFLAGS = \
- -DUI_DIR=\""$(datadir)/mate-calc"\" \
-DVERSION=\""$(VERSION)"\" \
-DLOCALE_DIR=\""$(localedir)"\" \
-DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
$(WARN_CFLAGS) \
$(MATE_CALC_CFLAGS)
+BUILT_SOURCES = \
+ mate-calc-resources.c \
+ mate-calc-resources.h
+
+nodist_mate_calc_SOURCES= $(BUILT_SOURCES)
+
mate_calc_SOURCES = \
mate-calc.c \
currency.c \
@@ -151,7 +156,8 @@ test_mp_equation_LDADD = \
CLEANFILES = \
mp-enums.c \
- mp-enums.h
+ mp-enums.h \
+ $(BUILT_SOURCES)
# Generate enum types
mp-enums.h: mp-enums.h.template mp-serializer.h
@@ -164,6 +170,11 @@ mp-enums.c: mp-enums.c.template mp-enums.h mp-serializer.h
math-serializer.c: mp-enums.h
math-equation.c: mp-enums.h
+# Generate resources
+mate-calc-resources.h mate-calc-resources.c: org.mate.calculator.gresource.xml Makefile $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir $(srcdir) $(srcdir)/org.mate.calculator.gresource.xml)
+ $(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir $(srcdir) --generate --c-name calculator $<
+
+
# Install a symlink between mate-calc and mate-calculator
install-exec-hook:
test -e "$(DESTDIR)$(bindir)/mate-calculator" \
@@ -175,8 +186,14 @@ uninstall-local:
&& rm -f "$(DESTDIR)$(bindir)/mate-calculator"
EXTRA_DIST = \
+ buttons-advanced.ui \
+ buttons-basic.ui \
+ buttons-financial.ui \
+ buttons-programming.ui \
mp-enums.c.template \
- mp-enums.h.template
+ mp-enums.h.template \
+ org.mate.calculator.gresource.xml \
+ preferences.ui
DISTCLEANFILES = \
Makefile.in
diff --git a/data/buttons-advanced.ui b/src/buttons-advanced.ui
index a4b756b..a4b756b 100644
--- a/data/buttons-advanced.ui
+++ b/src/buttons-advanced.ui
diff --git a/data/buttons-basic.ui b/src/buttons-basic.ui
index 387b590..387b590 100644
--- a/data/buttons-basic.ui
+++ b/src/buttons-basic.ui
diff --git a/data/buttons-financial.ui b/src/buttons-financial.ui
index d0a775e..d0a775e 100644
--- a/data/buttons-financial.ui
+++ b/src/buttons-financial.ui
diff --git a/data/buttons-programming.ui b/src/buttons-programming.ui
index 71d5c4e..71d5c4e 100644
--- a/data/buttons-programming.ui
+++ b/src/buttons-programming.ui
diff --git a/src/math-buttons.c b/src/math-buttons.c
index a97d6ee..50b15a7 100644
--- a/src/math-buttons.c
+++ b/src/math-buttons.c
@@ -60,10 +60,10 @@ struct MathButtonsPrivate
G_DEFINE_TYPE_WITH_PRIVATE (MathButtons, math_buttons, GTK_TYPE_BOX);
-#define UI_BASIC_FILE UI_DIR "/buttons-basic.ui"
-#define UI_ADVANCED_FILE UI_DIR "/buttons-advanced.ui"
-#define UI_FINANCIAL_FILE UI_DIR "/buttons-financial.ui"
-#define UI_PROGRAMMING_FILE UI_DIR "/buttons-programming.ui"
+#define UI_BASIC_RESOURCE_PATH "/org/mate/calculator/ui/buttons-basic.ui"
+#define UI_ADVANCED_RESOURCE_PATH "/org/mate/calculator/ui/buttons-advanced.ui"
+#define UI_FINANCIAL_RESOURCE_PATH "/org/mate/calculator/ui/buttons-financial.ui"
+#define UI_PROGRAMMING_RESOURCE_PATH "/org/mate/calculator/ui/buttons-programming.ui"
#define GET_WIDGET(ui, name) \
GTK_WIDGET(gtk_builder_get_object((ui), (name)))
@@ -478,7 +478,7 @@ load_mode(MathButtons *buttons, ButtonMode mode)
GtkBuilder *builder, **builder_ptr;
gint i;
gchar *name;
- const gchar *builder_file;
+ const gchar *path;
static gchar *objects[] = { "button_panel", "character_code_dialog", "currency_dialog",
"ctrm_dialog", "ddb_dialog", "fv_dialog", "gpm_dialog",
"pmt_dialog", "pv_dialog", "rate_dialog", "sln_dialog",
@@ -490,22 +490,22 @@ load_mode(MathButtons *buttons, ButtonMode mode)
default:
case BASIC:
builder_ptr = &buttons->priv->basic_ui;
- builder_file = UI_BASIC_FILE;
+ path = UI_BASIC_RESOURCE_PATH;
panel = &buttons->priv->bas_panel;
break;
case ADVANCED:
builder_ptr = &buttons->priv->advanced_ui;
- builder_file = UI_ADVANCED_FILE;
+ path = UI_ADVANCED_RESOURCE_PATH;
panel = &buttons->priv->adv_panel;
break;
case FINANCIAL:
builder_ptr = &buttons->priv->financial_ui;
- builder_file = UI_FINANCIAL_FILE;
+ path = UI_FINANCIAL_RESOURCE_PATH;
panel = &buttons->priv->fin_panel;
break;
case PROGRAMMING:
builder_ptr = &buttons->priv->programming_ui;
- builder_file = UI_PROGRAMMING_FILE;
+ path = UI_PROGRAMMING_RESOURCE_PATH;
panel = &buttons->priv->prog_panel;
break;
}
@@ -515,7 +515,7 @@ load_mode(MathButtons *buttons, ButtonMode mode)
builder = *builder_ptr = gtk_builder_new();
// FIXME: Show dialog if failed to load
- gtk_builder_add_objects_from_file(builder, builder_file, objects, &error);
+ gtk_builder_add_objects_from_resource(builder, path, objects, &error);
if (error) {
g_warning("Error loading button UI: %s", error->message);
g_clear_error(&error);
diff --git a/src/math-preferences.c b/src/math-preferences.c
index 1ba91cc..adbd58e 100644
--- a/src/math-preferences.c
+++ b/src/math-preferences.c
@@ -28,7 +28,7 @@ struct MathPreferencesDialogPrivate
G_DEFINE_TYPE_WITH_PRIVATE (MathPreferencesDialog, math_preferences, GTK_TYPE_DIALOG);
-#define UI_DIALOGS_FILE UI_DIR "/preferences.ui"
+#define UI_DIALOGS_RESOURCE_PATH "/org/mate/calculator/ui/preferences.ui"
#define GET_WIDGET(ui, name) \
GTK_WIDGET(gtk_builder_get_object(ui, name))
@@ -229,7 +229,7 @@ create_gui(MathPreferencesDialog *dialog)
// FIXME: Handle errors
dialog->priv->ui = gtk_builder_new();
- gtk_builder_add_objects_from_file(dialog->priv->ui, UI_DIALOGS_FILE, objects, &error);
+ gtk_builder_add_objects_from_resource(dialog->priv->ui, UI_DIALOGS_RESOURCE_PATH, objects, &error);
if (error)
g_warning("Error loading preferences UI: %s", error->message);
g_clear_error(&error);
diff --git a/src/org.mate.calculator.gresource.xml b/src/org.mate.calculator.gresource.xml
new file mode 100644
index 0000000..c31c1ba
--- /dev/null
+++ b/src/org.mate.calculator.gresource.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ This file is part of MATE Calc.
+
+ MATE Calc is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ MATE Calc is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with MATE Calc. If not, see <http://www.gnu.org/licenses/>.
+-->
+<gresources>
+ <gresource prefix="/org/mate/calculator/ui">
+ <file compressed="true" preprocess="xml-stripblanks">buttons-advanced.ui</file>
+ <file compressed="true" preprocess="xml-stripblanks">buttons-basic.ui</file>
+ <file compressed="true" preprocess="xml-stripblanks">buttons-financial.ui</file>
+ <file compressed="true" preprocess="xml-stripblanks">buttons-programming.ui</file>
+ <file compressed="true" preprocess="xml-stripblanks">preferences.ui</file>
+ </gresource>
+</gresources>
diff --git a/data/preferences.ui b/src/preferences.ui
index 56635b4..56635b4 100644
--- a/data/preferences.ui
+++ b/src/preferences.ui