[four-in-a-row] Use GResource.



commit b0c73f12d24ef3ece9cc255a48f7a3c39b9c3ab1
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Sep 19 21:56:47 2019 +0200

    Use GResource.

 data/meson.build                |  3 +--
 data/{ => ui}/four-in-a-row.ui  |  0
 po/POTFILES.in                  |  2 +-
 src/four-in-a-row.gresource.xml |  6 ++++++
 src/four-in-a-row.vala          | 19 +++++++------------
 src/meson.build                 | 11 +++++++----
 6 files changed, 22 insertions(+), 19 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index d8e7043..c13c747 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -53,8 +53,7 @@ install_data(
         'themes/tileset_50x50_faenza-gnect-icon.svg',
         'themes/tileset_50x50_hcinverse.svg',
         'themes/tileset_50x50_hcontrast.svg',
-        'bg_toplight.png',
-        'four-in-a-row.ui'
+        'bg_toplight.png'
     ],
     install_dir: datadir
 )
diff --git a/data/four-in-a-row.ui b/data/ui/four-in-a-row.ui
similarity index 100%
rename from data/four-in-a-row.ui
rename to data/ui/four-in-a-row.ui
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d88136c..b57d29f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,6 @@
 # List of source files containing translatable strings.
 # Please keep this file in alphabetical order.
-data/four-in-a-row.ui
+data/ui/four-in-a-row.ui
 data/org.gnome.Four-in-a-row.appdata.xml.in
 data/org.gnome.Four-in-a-row.desktop.in
 data/org.gnome.Four-in-a-row.gschema.xml
diff --git a/src/four-in-a-row.gresource.xml b/src/four-in-a-row.gresource.xml
new file mode 100644
index 0000000..f3d549c
--- /dev/null
+++ b/src/four-in-a-row.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/Four-in-a-row/ui">
+    <file preprocess="xml-stripblanks" compressed="true" 
alias="four-in-a-row.ui">../data/ui/four-in-a-row.ui</file>
+  </gresource>
+</gresources>
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index 7957786..63948dc 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -681,15 +681,9 @@ private class FourInARow : Gtk.Application {
     protected override void startup() {
         base.startup();
 
-        Gtk.AspectFrame frame;
-        GLib.Menu app_menu, section;
-        Gtk.MenuButton menu_button;
-        Gtk.Builder builder;
-        Gtk.CssProvider css_provider;
-
         Gtk.Window.set_default_icon_name("org.gnome.Four-in-a-row");
 
-        css_provider = new Gtk.CssProvider();
+        Gtk.CssProvider css_provider = new Gtk.CssProvider();
         try {
             css_provider.load_from_data("GtkButtonBox {-GtkButtonBox-child-internal-pad-x:0;}\0");
         } catch (Error error) {
@@ -700,7 +694,7 @@ private class FourInARow : Gtk.Application {
                                                  css_provider,
                                                  Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
         game_board_view = new GameBoardView(game_board);
-        builder = new Gtk.Builder.from_file(DATA_DIRECTORY + "/four-in-a-row.ui");
+        Gtk.Builder builder = new Gtk.Builder.from_resource("/org/gnome/Four-in-a-row/ui/four-in-a-row.ui");
 
         window = builder.get_object("fiar-window") as Gtk.ApplicationWindow;
         window.application = this;
@@ -712,15 +706,16 @@ private class FourInARow : Gtk.Application {
 
         add_actions();
 
-        menu_button = builder.get_object ("menu_button") as Gtk.MenuButton;
-        app_menu = new GLib.Menu ();
+        /* hamburger button */
+        Gtk.MenuButton menu_button = builder.get_object ("menu_button") as Gtk.MenuButton;
+        GLib.Menu app_menu = new GLib.Menu ();
 
         GLib.Menu appearance_menu = new GLib.Menu ();
         for (uint8 i = 0; i < theme.length; i++)     // TODO default theme
             appearance_menu.append (theme_get_title (i), @"app.theme-id($i)");
         appearance_menu.freeze ();
 
-        section = new GLib.Menu ();
+        GLib.Menu section = new GLib.Menu ();
         /* Translators: hamburger menu entry; "Appearance" submenu (with a mnemonic that appears pressing 
Alt) */
         section.append_submenu (_("A_ppearance"), (!) appearance_menu);
 
@@ -744,7 +739,7 @@ private class FourInARow : Gtk.Application {
         app_menu.freeze ();
         menu_button.set_menu_model (app_menu);
 
-        frame = builder.get_object("frame") as Gtk.AspectFrame;
+        Gtk.AspectFrame frame = builder.get_object("frame") as Gtk.AspectFrame;
 
         frame.add(game_board_view);
         game_board_view.column_clicked.connect(column_clicked_cb);
diff --git a/src/meson.build b/src/meson.build
index e282438..52166bc 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,4 +1,6 @@
-four_in_a_row_tests = executable('four-in-a-row-tests', 
+# Tests
+four_in_a_row_tests = executable(
+    'four-in-a-row-tests',
     [
         'ai.vala',
         'test-ai.vala'
@@ -8,11 +10,12 @@ four_in_a_row_tests = executable('four-in-a-row-tests',
         glib_dependency
     ]
 )
-test('four-in-a-row-tests', 
+test('four-in-a-row-tests',
     four_in_a_row_tests,
     timeout: 180)
 
-
+# Application
+resources = gnome.compile_resources (meson.project_name(), 'four-in-a-row.gresource.xml')
 
 sources = files(
     'ai.vala',
@@ -29,7 +32,7 @@ sources = files(
 
 executable(
     meson.project_name(),
-    sources,
+    sources + resources,
     dependencies: [
         glib_dependency,
         gsound_dependency,


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