[gnome-klotski] Use GResource for loading the app-menu.



commit 0a4032842a202e18832b6823e08d67fb73de7ab9
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon Feb 2 06:29:02 2015 +0100

    Use GResource for loading the app-menu.

 configure.ac              |    6 ++++++
 data/Makefile.am          |    3 +++
 data/klotski-menus.ui     |   26 ++++++++++++++++++++++++++
 src/Makefile.am           |   12 +++++++++++-
 src/gnome-klotski.vala    |   45 ---------------------------------------------
 src/klotski.gresource.xml |   10 ++++++++++
 6 files changed, 56 insertions(+), 46 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9c6cbd9..35d4fa8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,6 +30,12 @@ PKG_CHECK_MODULES(GNOME_KLOTSKI, [
 AC_PATH_PROG([DESKTOP_FILE_VALIDATE], [desktop-file-validate], [/bin/true])
 
 dnl ###########################################################################
+dnl GResources
+dnl ###########################################################################
+
+AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
+
+dnl ###########################################################################
 dnl Internationalization
 dnl ###########################################################################
 
diff --git a/data/Makefile.am b/data/Makefile.am
index d6c9ef4..828317e 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -5,6 +5,9 @@ gsettings_SCHEMAS = org.gnome.klotski.gschema.xml
 
 man_MANS = gnome-klotski.6
 
+dist_noinst_DATA = \
+       klotski-menus.ui
+
 pixmapdir = $(datadir)/gnome-klotski
 pixmap_DATA = \
        gnome-klotski.svg
diff --git a/data/klotski-menus.ui b/data/klotski-menus.ui
new file mode 100644
index 0000000..e6a669e
--- /dev/null
+++ b/data/klotski-menus.ui
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <menu id="app-menu">
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Scores</attribute>
+        <attribute name="action">app.scores</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name="label" translatable="yes">_Help</attribute>
+        <attribute name="action">app.help</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_About</attribute>
+        <attribute name="action">app.about</attribute>
+      </item>
+      <item>
+        <attribute name="label" translatable="yes">_Quit</attribute>
+        <attribute name="action">app.quit</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/src/Makefile.am b/src/Makefile.am
index 7a784bb..920da62 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,12 +1,15 @@
 bin_PROGRAMS = gnome-klotski
 
+BUILT_SOURCES = klotski-resources.c
+
 gnome_klotski_SOURCES = \
        config.vapi \
        gnome-klotski.vala \
        history.vala \
        puzzle.vala \
        puzzle-view.vala \
-       score-dialog.vala
+       score-dialog.vala \
+       $(BUILT_SOURCES)
 
 gnome_klotski_CFLAGS = \
        -DVERSION=\"$(VERSION)\" \
@@ -24,6 +27,9 @@ gnome_klotski_VALAFLAGS = \
 gnome_klotski_LDADD = \
        $(GNOME_KLOTSKI_LIBS)
 
+klotski-resources.c: $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies klotski.gresource.xml)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
klotski.gresource.xml
+
 CLEANFILES = \
        $(patsubst %.vala,%.c,$(filter %.vala, $(SOURCES))) \
        *_vala.stamp
@@ -31,4 +37,8 @@ CLEANFILES = \
 DISTCLEANFILES = \
        Makefile.in
 
+MAINTAINERCLEANFILES = klotski-resources.c
+
+EXTRA_DIST = klotski.gresource.xml
+
 -include $(top_srcdir)/git.mk
diff --git a/src/gnome-klotski.vala b/src/gnome-klotski.vala
index 4d8717d..becb3f4 100644
--- a/src/gnome-klotski.vala
+++ b/src/gnome-klotski.vala
@@ -517,51 +517,6 @@ public class Klotski : Gtk.Application
         var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 25);
         window.add (hbox);
 
-        /* Create the menu */
-
-        var builder_str =
-               "<interface>" +
-                /* string for menu */
-               """
-               <menu id='app-menu'>
-                  <section>
-                   <item>
-                      <attribute name='label' translatable='yes'>_Scores</attribute>
-                      <attribute name='action'>app.scores</attribute>
-                   </item>
-                  </section>
-                  <section>
-                   <item>
-                      <attribute name='label' translatable='yes'>_Help</attribute>
-                      <attribute name='action'>app.help</attribute>
-                   </item>
-                   <item>
-                      <attribute name='label' translatable='yes'>_About</attribute>
-                      <attribute name='action'>app.about</attribute>
-                   </item>
-                   <item>
-                      <attribute name='label' translatable='yes'>_Quit</attribute>
-                      <attribute name='action'>app.quit</attribute>
-                   </item>
-                  </section>
-                </menu>
-               </interface>
-               """;
-
-        Gtk.Builder builder = new Gtk.Builder ();
-
-        try
-        {
-            builder.add_from_string (builder_str, -1);
-        }
-        catch (GLib.Error e)
-        {
-            stderr.printf ("%s\n", "Error in gnome-klotski.vala function startup() - builder.add_from_string 
failed");
-            GLib.error (e.message);
-        }
-
-        set_app_menu (builder.get_object ("app-menu") as MenuModel);
-
         puzzles = new Gtk.TreeStore (3, typeof (string), typeof (bool), typeof (int));
 
         Gtk.TreeIter huarong_item;
diff --git a/src/klotski.gresource.xml b/src/klotski.gresource.xml
new file mode 100644
index 0000000..adf4e0e
--- /dev/null
+++ b/src/klotski.gresource.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <!-- <gresource prefix="/org/gnome/klotski/ui">
+    <file preprocess="xml-stripblanks" alias="klotski.ui">../data/klotski.ui</file>
+    <file alias="klotski.css">../data/klotski.css</file>
+  </gresource> -->
+  <gresource prefix="/org/gnome/klotski/gtk">
+    <file preprocess="xml-stripblanks" alias="menus.ui">../data/klotski-menus.ui</file>
+  </gresource>
+</gresources>


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