[iagno] Use GResource.
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [iagno] Use GResource.
- Date: Tue, 16 Sep 2014 15:15:35 +0000 (UTC)
commit a4c6c1095a46569fb1cc2bea0c70115daab4028a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Tue Sep 16 07:08:08 2014 +0200
Use GResource.
https://bugzilla.gnome.org/show_bug.cgi?id=735053
configure.ac | 6 ++++++
data/iagno.ui | 12 ++++++++----
src/Makefile.am | 11 +++++++++--
src/iagno.gresource.xml | 15 +++++++++++++++
src/iagno.vala | 30 ++----------------------------
5 files changed, 40 insertions(+), 34 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f7207a8..41bf60f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,6 +35,12 @@ if ! test -x "${GTESTER}" ; then
fi
dnl ###########################################################################
+dnl GResources
+dnl ###########################################################################
+
+AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
+
+dnl ###########################################################################
dnl Internationalization
dnl ###########################################################################
diff --git a/data/iagno.ui b/data/iagno.ui
index 805bb0c..9c73c1c 100644
--- a/data/iagno.ui
+++ b/data/iagno.ui
@@ -62,7 +62,8 @@
<property name="row-spacing">18</property>
<property name="margin-end">12</property>
<child>
- <object class="GtkImage" id="mark-icon-dark"> <!-- TODO use GResource -->
+ <object class="GtkImage" id="mark-icon-dark">
+ <property name="resource">/org/gnome/iagno/images/mark.svg</property>
<property name="visible">True</property>
</object>
<packing>
@@ -71,7 +72,8 @@
</packing>
</child>
<child>
- <object class="GtkImage" id="dark-image"> <!-- TODO use GResource -->
+ <object class="GtkImage">
+ <property name="resource">/org/gnome/iagno/images/dark.svg</property>
<property name="visible">True</property>
</object>
<packing>
@@ -90,7 +92,8 @@
</packing>
</child>
<child>
- <object class="GtkImage" id="mark-icon-light"> <!-- TODO use GResource -->
+ <object class="GtkImage" id="mark-icon-light">
+ <property name="resource">/org/gnome/iagno/images/mark.svg</property>
<property name="visible">True</property>
</object>
<packing>
@@ -99,7 +102,8 @@
</packing>
</child>
<child>
- <object class="GtkImage" id="light-image"> <!-- TODO use GResource -->
+ <object class="GtkImage">
+ <property name="resource">/org/gnome/iagno/images/light.svg</property>
<property name="visible">True</property>
</object>
<packing>
diff --git a/src/Makefile.am b/src/Makefile.am
index 1ecc089..9e8fc39 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,13 +1,16 @@
bin_PROGRAMS = iagno
check_PROGRAMS = test-iagno
+BUILT_SOURCES = iagno-resources.c
+
iagno_SOURCES = \
config.vapi \
computer-player.vala \
game.vala \
game-view.vala \
iagno.vala \
- player.vala
+ player.vala \
+ $(BUILT_SOURCES)
iagno_CFLAGS = \
-DVERSION=\"$(VERSION)\" \
@@ -41,8 +44,12 @@ test_iagno_LDADD = $(IAGNO_LIBS)
check-local: $(check_PROGRAMS)
$(GTESTER) --keep-going --verbose $(check_PROGRAMS)
+iagno-resources.c: iagno.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies
iagno.gresource.xml)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source $<
+
CLEANFILES = \
$(patsubst %.vala,%.c,$(filter %.vala, $(SOURCES))) \
- *_vala.stamp
+ *_vala.stamp \
+ iagno-resources.c
-include $(top_srcdir)/git.mk
diff --git a/src/iagno.gresource.xml b/src/iagno.gresource.xml
new file mode 100644
index 0000000..38029b3
--- /dev/null
+++ b/src/iagno.gresource.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/iagno/images">
+ <file alias="dark.svg">../data/dark.svg</file>
+ <file alias="light.svg">../data/light.svg</file>
+ <file alias="mark.svg">../data/mark.svg</file>
+ </gresource>
+ <gresource prefix="/org/gnome/iagno/ui">
+ <file alias="iagno.ui" preprocess="xml-stripblanks">../data/iagno.ui</file>
+ <file alias="iagno-preferences.ui" preprocess="xml-stripblanks">../data/iagno-preferences.ui</file>
+ </gresource>
+ <gresource prefix="/org/gnome/iagno/gtk">
+ <file alias="menus.ui" preprocess="xml-stripblanks">../data/iagno-menus.ui</file>
+ </gresource>
+</gresources>
diff --git a/src/iagno.vala b/src/iagno.vala
index 9001c46..d62ca56 100644
--- a/src/iagno.vala
+++ b/src/iagno.vala
@@ -87,19 +87,7 @@ public class Iagno : Gtk.Application
return;
}
- // TODO use GResource & Gtk.Builder.from_resource()
- var builder = new Gtk.Builder ();
- try
- {
- builder.add_from_file (DATA_DIRECTORY + "/iagno-menus.ui");
- builder.add_from_file (DATA_DIRECTORY + "/iagno.ui");
- }
- catch (Error e)
- {
- error ("Could not load UI: %s\n", e.message);
- }
- set_app_menu (builder.get_object ("app-menu") as MenuModel);
- // end of TODO
+ var builder = new Gtk.Builder.from_resource ("/org/gnome/iagno/ui/iagno.ui");
window = builder.get_object ("iagno-window") as Gtk.ApplicationWindow;
window.configure_event.connect (window_configure_event_cb);
@@ -123,22 +111,8 @@ public class Iagno : Gtk.Application
headerbar = builder.get_object ("headerbar") as Gtk.HeaderBar;
light_score_label = builder.get_object ("light-score-label") as Gtk.Label;
dark_score_label = builder.get_object ("dark-score-label") as Gtk.Label;
-
- // TODO use GResource
- var dark = Path.build_filename (DATA_DIRECTORY, "images", "dark.svg");
- var dark_image = builder.get_object ("dark-image") as Gtk.Image;
- dark_image.set_from_file (dark);
-
- var light = Path.build_filename (DATA_DIRECTORY, "images", "light.svg");
- var light_image = builder.get_object ("light-image") as Gtk.Image;
- light_image.set_from_file (light);
-
- var mark = Path.build_filename (DATA_DIRECTORY, "images", "mark.svg");
mark_icon_dark = builder.get_object ("mark-icon-dark") as Gtk.Image;
- mark_icon_dark.set_from_file (mark);
mark_icon_light = builder.get_object ("mark-icon-light") as Gtk.Image;
- mark_icon_light.set_from_file (mark);
- // end of TODO
start_game ();
@@ -495,7 +469,7 @@ public class Iagno : Gtk.Application
private void create_preferences_dialog ()
{
- var builder = new Gtk.Builder.from_file (DATA_DIRECTORY + "/iagno-preferences.ui");
+ var builder = new Gtk.Builder.from_resource ("/org/gnome/iagno/ui/iagno-preferences.ui");
/* the dialog is not in the ui file for the use-header-bar flag to be switchable */
propbox = new Gtk.Dialog.with_buttons (_("Preferences"),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]