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



commit 2110abdd07cbe10ff2f56a5e9af160733f261934
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Feb 21 20:29:55 2015 +0100

    Use GResource for loading the app-menu.

 configure.ac              |    6 +++++
 data/Makefile.am          |    3 ++
 data/nibbles-menus.ui     |   42 ++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in            |    1 +
 src/Makefile.am           |   12 ++++++++++-
 src/main.c                |   49 ---------------------------------------------
 src/nibbles.gresource.xml |   11 ++++++++++
 7 files changed, 74 insertions(+), 50 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8810d42..fc521bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,6 +34,12 @@ PKG_CHECK_MODULES(GNOME_NIBBLES, [
 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 687bc71..e7949ec 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -3,6 +3,9 @@ SUBDIRS = icons levels pix
 gsettings_SCHEMAS = org.gnome.nibbles.gschema.xml
 @GSETTINGS_RULES@
 
+dist_noinst_DATA = \
+       nibbles-menus.ui
+
 soundsdir = $(datadir)/gnome-nibbles/sounds
 sounds_DATA = \
        appear.ogg \
diff --git a/data/nibbles-menus.ui b/data/nibbles-menus.ui
new file mode 100644
index 0000000..df53e93
--- /dev/null
+++ b/data/nibbles-menus.ui
@@ -0,0 +1,42 @@
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <menu id='app-menu'>
+    <section>
+      <item>
+        <attribute name='label' translatable='yes'>_New Game</attribute>
+        <attribute name='action'>app.newgame</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
+        <attribute name='label' translatable='yes'>_Pause</attribute>
+        <attribute name='action'>app.pause</attribute>
+        <attribute name='accel'>Pause</attribute>
+      </item>
+      <item>
+        <attribute name='label' translatable='yes'>_Preferences</attribute>
+        <attribute name='action'>app.preferences</attribute>
+      </item>
+      <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>
+        <attribute name='accel'>F1</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>
+        <attribute name='accel'>&lt;Primary&gt;q</attribute>
+      </item>
+    </section>
+  </menu>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index fe02b20..953e3ab 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -3,6 +3,7 @@
 [encoding: UTF-8]
 data/gnome-nibbles.appdata.xml.in
 data/gnome-nibbles.desktop.in
+[type: gettext/glade]data/nibbles-menus.ui
 data/org.gnome.nibbles.gschema.xml
 src/board.c
 src/games-controls.c
diff --git a/src/Makefile.am b/src/Makefile.am
index d917e79..49fd76e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -36,7 +36,13 @@ gnome_nibbles_SOURCES = \
        sound.c \
        sound.h \
        worm.c \
-       worm.h
+       worm.h \
+       $(BUILT_SOURCES)
+
+BUILT_SOURCES = nibbles-resources.c
+
+nibbles-resources.c: $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies nibbles.gresource.xml)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source 
nibbles.gresource.xml
 
 gnome_nibbles_CPPFLAGS = \
        -I$(top_srcdir) \
@@ -52,4 +58,8 @@ gnome_nibbles_CFLAGS = \
 gnome_nibbles_LDADD = \
        $(GNOME_NIBBLES_LIBS)
 
+MAINTAINERCLEANFILES = nibbles-resources.c
+
+EXTRA_DIST = nibbles.gresource.xml
+
 -include $(top_srcdir)/git.mk
diff --git a/src/main.c b/src/main.c
index 505ad25..c2b4aeb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -571,8 +571,6 @@ activate (GtkApplication* app,
 
   GtkWidget *packing;
 
-  GtkBuilder *builder;
-
   headerbar = gtk_header_bar_new ();
   gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (headerbar), TRUE);
   gtk_header_bar_set_title (GTK_HEADER_BAR (headerbar), _("Nibbles"));
@@ -583,53 +581,6 @@ activate (GtkApplication* app,
 
   g_action_map_add_action_entries (G_ACTION_MAP (app), app_entries, G_N_ELEMENTS (app_entries), app);
 
-  builder = gtk_builder_new ();
-
-  gtk_builder_add_from_string (builder,
-                               "<interface>"
-                               "  <menu id='app-menu'>"
-                               "    <section>"
-                               "      <item>"
-                               "        <attribute name='label' translatable='yes'>_New Game</attribute>"
-                               "        <attribute name='action'>app.newgame</attribute>"
-                               "      </item>"
-                               "    </section>"
-                               "    <section>"
-                               "      <item>"
-                               "        <attribute name='label' translatable='yes'>_Pause</attribute>"
-                               "        <attribute name='action'>app.pause</attribute>"
-                               "        <attribute name='accel'>Pause</attribute>"
-                               "      </item>"
-                               "      <item>"
-                               "        <attribute name='label' translatable='yes'>_Preferences</attribute>"
-                               "        <attribute name='action'>app.preferences</attribute>"
-                               "      </item>"
-                               "      <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>"
-                               "        <attribute name='accel'>F1</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>"
-                               "        <attribute name='accel'>&lt;Primary&gt;q</attribute>"
-                               "      </item>"
-                               "    </section>"
-                               "  </menu>"
-                               "</interface>", -1, NULL); 
-
-  gtk_application_set_app_menu (GTK_APPLICATION (app), G_MENU_MODEL (gtk_builder_get_object (builder, 
"app-menu")));
-
   pause_action          = G_SIMPLE_ACTION (g_action_map_lookup_action (G_ACTION_MAP (app) , "pause"));
 
   g_simple_action_set_enabled (pause_action, FALSE);
diff --git a/src/nibbles.gresource.xml b/src/nibbles.gresource.xml
new file mode 100644
index 0000000..96211f8
--- /dev/null
+++ b/src/nibbles.gresource.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <!-- <gresource prefix="/org/gnome/nibbles/ui">
+    <file preprocess="xml-stripblanks" alias="nibbles.ui">../data/nibbles.ui</file>
+    <file alias="nibbles.css">../data/nibbles.css</file>
+  </gresource> -->
+  <gresource prefix="/org/gnome/nibbles/gtk">
+    <file preprocess="xml-stripblanks" alias="menus.ui">../data/nibbles-menus.ui</file>
+  </gresource>
+</gresources>
+


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