[moserial] ui: Load UI files from GResource



commit 790a4c03b20f2fe95ad2efa6e0bf6df612f63609
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Nov 7 15:55:08 2015 +0100

    ui: Load UI files from GResource
    
    Which shouldn't fail unless there's a programmer error.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757737

 Makefile.am                    |   15 +++++++++++----
 configure.ac                   |    3 ++-
 data/Makefile.am               |   10 +++++++---
 data/moserial.gresource.xml    |   14 ++++++++++++++
 src/Config.vapi                |    2 +-
 src/MainWindow.vala            |    2 +-
 src/PreferencesDialog.vala     |    2 +-
 src/ReceiveChooserDialog.vala  |    2 +-
 src/ReceiveProgressDialog.vala |    2 +-
 src/RecordDialog.vala          |    2 +-
 src/SendChooserDialog.vala     |    2 +-
 src/SendProgressDialog.vala    |    2 +-
 src/SettingsDialog.vala        |    2 +-
 src/XmodemFilenameDialog.vala  |    2 +-
 14 files changed, 44 insertions(+), 18 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 2381172..0c41222 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,15 +8,21 @@ SUBDIRS = \
        po \
        $(NULL)
 
-gladedir = $(datadir)/moserial/glade
-INCLUDES = -DMOSERIAL_GLADEDIR=\""$(gladedir)"\" -DPACKAGE_LOCALEDIR=\""$(datadir)/locale"\"
+INCLUDES = -DUIROOT=\""/org/gnome/moserial/ui/"\" -DPACKAGE_LOCALEDIR=\""$(datadir)/locale"\"
+
+gresource_file = $(top_srcdir)/data/moserial.gresource.xml
+AM_VALAFLAGS = --gresources $(gresource_file)
+
+resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir=$(top_srcdir)/data 
$(gresource_file))
+src/resources.c: $(gresource_file) $(resource_files)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(top_srcdir)/data --generate-source $<
 
 AM_CPPFLAGS = \
        $(MOSERIAL_CFLAGS) \
        -include $(CONFIG_HEADER) \
        $(NULL)
 
-BUILT_SOURCES = src/moserial.vala.stamp
+BUILT_SOURCES = src/moserial.vala.stamp src/resources.c
 
 bin_PROGRAMS = moserial
 
@@ -46,7 +52,8 @@ moserial_VALASOURCES = \
        $(NULL)
 
 moserial_SOURCES = \
-       $(moserial_VALASOURCES:.vala=.c) \
+       $(moserial_VALASOURCES:.vala=.c)        \
+       src/resources.c                         \
        $(NULL)
 
 src/moserial.vala.stamp: $(moserial_VALASOURCES)
diff --git a/configure.ac b/configure.ac
index 075d797..d042472 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,11 +36,12 @@ PKG_CHECK_MODULES(MOSERIAL, glib-2.0 >= $GLIB_REQUIRED
 AC_SUBST(MOSERIAL_CFLAGS)
 AC_SUBST(MOSERIAL_LIBS)
 
+AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
+
 AC_CONFIG_FILES([
        Makefile
        po/Makefile.in
        data/Makefile
-       data/ui/Makefile
        data/icons/Makefile
        data/icons/48x48/Makefile
        data/icons/48x48/apps/Makefile
diff --git a/data/Makefile.am b/data/Makefile.am
index 1e653d1..ceaa97d 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = ui icons
+SUBDIRS = icons
 
 @INTLTOOL_DESKTOP_RULE@
 
@@ -13,13 +13,17 @@ appdata_in_files = moserial.appdata.xml.in
 
 man_MANS = moserial.1
 
+gresource_file = moserial.gresource.xml
+resource_files = $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies $(gresource_file))
+
 EXTRA_DIST =                   \
        $(desktop_in_files)     \
        $(desktop_DATA)         \
         $(appdata_in_files)     \
         $(appdata_DATA)         \
-       $(man_MANS)
-
+       $(man_MANS)             \
+       $(gresource_files)      \
+       $(resource_files)
 
 DISTCLEANFILES =                \
        $(desktop_DATA)         \
diff --git a/data/moserial.gresource.xml b/data/moserial.gresource.xml
new file mode 100644
index 0000000..1ef7684
--- /dev/null
+++ b/data/moserial.gresource.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/moserial">
+    <file preprocess="xml-stripblanks">ui/mainwindow.ui</file>
+    <file preprocess="xml-stripblanks">ui/preferences.ui</file>
+    <file preprocess="xml-stripblanks">ui/receive_chooser.ui</file>
+    <file preprocess="xml-stripblanks">ui/receive_progress.ui</file>
+    <file preprocess="xml-stripblanks">ui/record_dialog.ui</file>
+    <file preprocess="xml-stripblanks">ui/send_chooser_dialog.ui</file>
+    <file preprocess="xml-stripblanks">ui/send_progress_dialog.ui</file>
+    <file preprocess="xml-stripblanks">ui/settings_dialog.ui</file>
+    <file preprocess="xml-stripblanks">ui/xmodem_filename_dialog.ui</file>
+  </gresource>
+</gresources>
diff --git a/src/Config.vapi b/src/Config.vapi
index ce16fef..db4846e 100644
--- a/src/Config.vapi
+++ b/src/Config.vapi
@@ -2,7 +2,7 @@
 namespace Config
 {
        public const string VERSION;
-       public const string MOSERIAL_GLADEDIR;
+       public const string UIROOT;
        public const string GETTEXT_PACKAGE;
        public const string PACKAGE_DATADIR;
        public const string PACKAGE_LOCALEDIR;
diff --git a/src/MainWindow.vala b/src/MainWindow.vala
index 320b79c..1c13e1f 100644
--- a/src/MainWindow.vala
+++ b/src/MainWindow.vala
@@ -107,7 +107,7 @@ public class moserial.MainWindow : Gtk.Window //Have to extend Gtk.Winow to get
         }
         construct {
                 Builder builder = new Builder();
-                builder.add_from_file(Config.MOSERIAL_GLADEDIR + "/mainwindow.ui");
+                builder.add_from_resource(Config.UIROOT + "mainwindow.ui");
 
                 //setup window
                 gtkWindow = (Gtk.Window)builder.get_object("window");
diff --git a/src/PreferencesDialog.vala b/src/PreferencesDialog.vala
index 3038eb0..633591b 100644
--- a/src/PreferencesDialog.vala
+++ b/src/PreferencesDialog.vala
@@ -34,7 +34,7 @@ public class moserial.PreferencesDialog : GLib.Object
         public signal void updatePreferences(Preferences preferences);
         construct {
                 Builder builder = new Builder();
-                builder.add_from_file(Config.MOSERIAL_GLADEDIR + "/preferences.ui");
+                builder.add_from_resource(Config.UIROOT + "preferences.ui");
 
                 dialog = (Dialog)builder.get_object("preferences_dialog");
                 okButton = (Button)builder.get_object("preferences_ok");
diff --git a/src/ReceiveChooserDialog.vala b/src/ReceiveChooserDialog.vala
index 721cfd3..dbf3066 100644
--- a/src/ReceiveChooserDialog.vala
+++ b/src/ReceiveChooserDialog.vala
@@ -27,7 +27,7 @@ public class moserial.ReceiveChooserDialog : GLib.Object
 
         construct {
                 Builder builder = new Builder();
-                builder.add_from_file(Config.MOSERIAL_GLADEDIR + "/receive_chooser.ui");
+                builder.add_from_resource(Config.UIROOT + "receive_chooser.ui");
 
                 dialog = (FileChooserDialog)builder.get_object("receive_chooser_dialog");
 
diff --git a/src/ReceiveProgressDialog.vala b/src/ReceiveProgressDialog.vala
index 3ac5544..bb2febd 100644
--- a/src/ReceiveProgressDialog.vala
+++ b/src/ReceiveProgressDialog.vala
@@ -27,7 +27,7 @@ public class moserial.ReceiveProgressDialog : GLib.Object
         public signal void transferCanceled();
         construct {
                 Builder builder = new Builder();
-                builder.add_from_file(Config.MOSERIAL_GLADEDIR + "/receive_progress.ui");
+                builder.add_from_resource(Config.UIROOT + "receive_progress.ui");
 
                 dialog = (Dialog)builder.get_object("receive_progress_dialog");
                 cancelButton = (Button)builder.get_object("receive_progress_cancel");
diff --git a/src/RecordDialog.vala b/src/RecordDialog.vala
index 4df8592..400d1a0 100644
--- a/src/RecordDialog.vala
+++ b/src/RecordDialog.vala
@@ -29,7 +29,7 @@ public class moserial.RecordDialog : GLib.Object
         public SerialStreamRecorder.Direction direction;
         construct {
                 Builder builder = new Builder();
-                builder.add_from_file(Config.MOSERIAL_GLADEDIR + "/record_dialog.ui");
+                builder.add_from_resource(Config.UIROOT + "record_dialog.ui");
 
                 dialog = (FileChooserDialog)builder.get_object("record_dialog");
                 cancelButton = (Button)builder.get_object("record_cancel");
diff --git a/src/SendChooserDialog.vala b/src/SendChooserDialog.vala
index 3c0452e..0b636a1 100644
--- a/src/SendChooserDialog.vala
+++ b/src/SendChooserDialog.vala
@@ -26,7 +26,7 @@ public class moserial.SendChooserDialog : GLib.Object
         public string filename;
         construct {
                 Builder builder = new Builder();
-                builder.add_from_file(Config.MOSERIAL_GLADEDIR + "/send_chooser_dialog.ui");
+                builder.add_from_resource(Config.UIROOT + "send_chooser_dialog.ui");
 
                 dialog = (FileChooserDialog)builder.get_object("send_chooser_dialog");
 
diff --git a/src/SendProgressDialog.vala b/src/SendProgressDialog.vala
index 7636417..16738da 100644
--- a/src/SendProgressDialog.vala
+++ b/src/SendProgressDialog.vala
@@ -27,7 +27,7 @@ public class moserial.SendProgressDialog : GLib.Object
         public signal void transferCanceled();
         construct {
                 Builder builder = new Builder();
-                builder.add_from_file(Config.MOSERIAL_GLADEDIR + "/send_progress_dialog.ui");
+                builder.add_from_resource(Config.UIROOT + "send_progress_dialog.ui");
 
                 dialog = (Dialog)builder.get_object("send_progress_dialog");
                 cancelButton = (Button)builder.get_object("send_progress_cancel");
diff --git a/src/SettingsDialog.vala b/src/SettingsDialog.vala
index 3d84367..a49f160 100644
--- a/src/SettingsDialog.vala
+++ b/src/SettingsDialog.vala
@@ -44,7 +44,7 @@ public class moserial.SettingsDialog : GLib.Object
 
         construct {
                 Builder builder = new Builder();
-                builder.add_from_file(Config.MOSERIAL_GLADEDIR + "/settings_dialog.ui");
+                builder.add_from_resource(Config.UIROOT + "settings_dialog.ui");
 
                 dialog = (Dialog)builder.get_object("settings_dialog");
                 cancelButton = (Button)builder.get_object("settings_cancel_button");
diff --git a/src/XmodemFilenameDialog.vala b/src/XmodemFilenameDialog.vala
index 7845cd7..4db265c 100644
--- a/src/XmodemFilenameDialog.vala
+++ b/src/XmodemFilenameDialog.vala
@@ -25,7 +25,7 @@ public class moserial.XmodemFilenameDialog : GLib.Object
        public string filename;
        construct {
                 Builder builder = new Builder();
-                builder.add_from_file(Config.MOSERIAL_GLADEDIR + "/xmodem_filename_dialog.ui");
+                builder.add_from_resource(Config.UIROOT + "xmodem_filename_dialog.ui");
 
                dialog = (Dialog)builder.get_object("xmodem_filename_dialog");
                xmodemFilename = (Gtk.Entry)builder.get_object("xmodem_filename");


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