[gnome-chess] Use GResource.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess] Use GResource.
- Date: Wed, 25 Feb 2015 21:03:36 +0000 (UTC)
commit ec662df5e74201fd25555ef92b1b495d4037b6ad
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Wed Feb 25 21:41:15 2015 +0100
Use GResource.
configure.ac | 6 +++++
data/Makefile.am | 3 +-
data/menu.ui | 2 +-
src/Makefile.am | 10 ++++++++-
src/chess.gresource.xml | 12 +++++++++++
src/gnome-chess.vala | 48 +++-------------------------------------------
6 files changed, 33 insertions(+), 48 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 998a271..8d4ff1e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -54,6 +54,12 @@ AM_CONDITIONAL([WITH_PRCTL], [test x$ac_cv_header_linux_prctl_h = xyes])
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 ca621d1..aeddab3 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -10,8 +10,7 @@ appstream_XML = $(appstream_in_files:.appdata.xml.in=.appdata.xml)
@APPSTREAM_XML_RULES@
@INTLTOOL_XML_RULE@
-uidir = $(pkgdatadir)
-dist_ui_DATA = \
+dist_noinst_DATA = \
gnome-chess.ui \
preferences.ui \
promotion-type-selector.ui \
diff --git a/data/menu.ui b/data/menu.ui
index 4bc1f5b..b246e02 100644
--- a/data/menu.ui
+++ b/data/menu.ui
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
- <menu id="appmenu">
+ <menu id="app-menu">
<section>
<item>
<attribute name="label" translatable="yes">Preferences</attribute>
diff --git a/src/Makefile.am b/src/Makefile.am
index d761630..38e3913 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,7 @@
bin_PROGRAMS = gnome-chess
+BUILT_SOURCES = chess-resources.c
+
gnome_chess_SOURCES = \
config.vapi \
portability.vapi \
@@ -11,7 +13,8 @@ gnome_chess_SOURCES = \
chess-engine-cecp.vala \
chess-engine-uci.vala \
chess-scene.vala \
- chess-view.vala
+ chess-view.vala \
+ $(BUILT_SOURCES)
gnome_chess_CFLAGS = \
-w
@@ -38,10 +41,15 @@ gnome_chess_VALAFLAGS = \
--target-glib=$(GLIB_REQUIRED) \
$(top_builddir)/lib/libchess.vapi
+chess-resources.c: $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies chess.gresource.xml)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate-source
chess.gresource.xml
+
CLEANFILES = \
$(patsubst %.vala,%.c,$(filter %.vala, $(SOURCES))) \
*_vala.stamp \
*.log \
*.trs
+EXTRA_DIST = chess.gresource.xml
+
-include $(top_srcdir)/git.mk
diff --git a/src/chess.gresource.xml b/src/chess.gresource.xml
new file mode 100644
index 0000000..57c6bb9
--- /dev/null
+++ b/src/chess.gresource.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/chess/ui">
+ <file preprocess="xml-stripblanks" alias="gnome-chess.ui">../data/gnome-chess.ui</file>
+ <file preprocess="xml-stripblanks" alias="preferences.ui">../data/preferences.ui</file>
+ <file preprocess="xml-stripblanks"
alias="promotion-type-selector.ui">../data/promotion-type-selector.ui</file>
+ </gresource>
+ <gresource prefix="/org/gnome/chess/gtk">
+ <file preprocess="xml-stripblanks" alias="menus.ui">../data/menu.ui</file>
+ </gresource>
+</gresources>
+
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 888bd80..73bd58f 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -18,8 +18,6 @@ public class ChessApplication : Gtk.Application
private int window_height;
private Settings settings;
- private Gtk.Builder builder;
- private Gtk.Builder preferences_builder;
private Gtk.ApplicationWindow window;
private Gtk.Container view_container;
private ChessScene scene;
@@ -129,28 +127,7 @@ public class ChessApplication : Gtk.Application
settings = new Settings ("org.gnome.chess");
add_action_entries (app_entries, this);
- builder = new Gtk.Builder ();
-
- try
- {
- builder.add_from_file (Path.build_filename (PKGDATADIR, "menu.ui", null));
- }
- catch (Error e)
- {
- error ("Error loading menu UI: %s", e.message);
- }
-
- var app_menu = (Menu) builder.get_object ("appmenu");
- set_app_menu (app_menu);
-
- try
- {
- builder.add_from_file (Path.build_filename (PKGDATADIR, "gnome-chess.ui", null));
- }
- catch (Error e)
- {
- warning ("Could not load UI: %s", e.message);
- }
+ Gtk.Builder builder = new Gtk.Builder.from_resource ("/org/gnome/chess/ui/gnome-chess.ui");
window = (Gtk.ApplicationWindow) builder.get_object ("gnome_chess_app");
window.set_default_size (settings.get_int ("width"), settings.get_int ("height"));
@@ -292,17 +269,7 @@ public class ChessApplication : Gtk.Application
public PieceType? show_promotion_type_selector ()
{
- Gtk.Builder promotion_type_selector_builder;
-
- promotion_type_selector_builder = new Gtk.Builder ();
- try
- {
- promotion_type_selector_builder.add_from_file (Path.build_filename (PKGDATADIR,
"promotion-type-selector.ui", null));
- }
- catch (Error e)
- {
- warning ("Could not load promotion type selector UI: %s", e.message);
- }
+ Gtk.Builder promotion_type_selector_builder = new Gtk.Builder.from_resource
("/org/gnome/chess/ui/promotion-type-selector.ui");
Gtk.Dialog promotion_type_selector_dialog = promotion_type_selector_builder.get_object
("dialog_promotion_type_selector") as Gtk.Dialog;
promotion_type_selector_dialog.transient_for = window;
@@ -1677,15 +1644,8 @@ public class ChessApplication : Gtk.Application
return;
}
- preferences_builder = new Gtk.Builder ();
- try
- {
- preferences_builder.add_from_file (Path.build_filename (PKGDATADIR, "preferences.ui", null));
- }
- catch (Error e)
- {
- warning ("Could not load preferences UI: %s", e.message);
- }
+ Gtk.Builder preferences_builder = new Gtk.Builder.from_resource
("/org/gnome/chess/ui/preferences.ui");
+
preferences_dialog = (Gtk.Dialog) preferences_builder.get_object ("preferences");
preferences_dialog.transient_for = window;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]