[goobox] use GResource to store ui files



commit 94136f6ece4a851e4a8b82a95e031c8f39e034dd
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sat Jun 2 22:24:08 2012 +0200

    use GResource to store ui files

 configure.ac                       |    5 +-
 data/Makefile.am                   |    2 +-
 src/Makefile.am                    |   20 +++++++--
 src/dlg-cover-chooser.c            |    2 +-
 src/dlg-extract.c                  |    2 +-
 src/dlg-preferences.c              |    4 +-
 src/dlg-properties.c               |    2 +-
 src/dlg-ripper.c                   |    2 +-
 src/goo-window.c                   |    2 +-
 src/goobox.gresource.xml           |   12 ++++++
 src/gtk-utils.c                    |   23 ++++++++++-
 src/gtk-utils.h                    |    5 +-
 src/ui.h                           |   74 ------------------------------------
 {data => src}/ui/.cvsignore        |    0
 {data => src}/ui/Makefile.am       |    7 +--
 {data => src}/ui/cover-chooser.ui  |    0
 {data => src}/ui/extract.ui        |    0
 {data => src}/ui/format-options.ui |    0
 src/ui/menu-toolbars.ui            |   70 ++++++++++++++++++++++++++++++++++
 {data => src}/ui/preferences.ui    |    0
 {data => src}/ui/properties.ui     |    0
 {data => src}/ui/ripper.ui         |    0
 22 files changed, 135 insertions(+), 97 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0a31605..7f72aec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@ GNOME_MAINTAINER_MODE_DEFINES
 GLIB_GSETTINGS
 
 GLIB_REQUIRED=2.30
-GTK_REQUIRED=3.2.0
+GTK_REQUIRED=3.4.0
 GSTREAMER_REQUIRED=0.10.12
 LIBNOTIFY_REQUIRED=0.4.3
 LIBMUSICBRAINZ4_REQUIRED=4.0.0
@@ -43,6 +43,7 @@ dnl ===========================================================================
 
 AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
 AC_PATH_PROG(GLIB_MKENUMS, glib-mkenums)
+AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
 
 dnl ===========================================================================
 
@@ -182,7 +183,6 @@ Makefile
 copy-n-paste/Makefile
 data/Makefile
 data/goobox.desktop.in
-data/ui/Makefile
 data/icons/Makefile
 data/icons/256x256/Makefile
 data/icons/256x256/apps/Makefile
@@ -191,6 +191,7 @@ data/icons/48x48/apps/Makefile
 help/Makefile
 src/Makefile
 src/icons/Makefile
+src/ui/Makefile
 po/Makefile.in
 ])
 
diff --git a/data/Makefile.am b/data/Makefile.am
index 9a30b41..b51221f 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = ui icons
+SUBDIRS = icons
 
 desktop_in_in_files = goobox.desktop.in.in
 desktop_in_files = $(desktop_in_in_files:.desktop.in.in=.desktop.in) 
diff --git a/src/Makefile.am b/src/Makefile.am
index bf6f75e..7198f7d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS=icons
+SUBDIRS = icons ui
 
 bin_PROGRAMS = goobox
 
@@ -20,10 +20,13 @@ INCLUDES =						\
 	$(GOO_CFLAGS)					\
 	$(LIBNOTIFY_CFLAGS)
 
-BUILT_SOURCES =				\
-	goo-marshal.c			\
-	goo-marshal.h
-
+BUILT_SOURCES =			\
+	goo-marshal.c		\
+	goo-marshal.h		\
+	goo-resources.c		\
+	goo-resources.h		\
+	$(NULL)
+	
 goobox_SOURCES = 				\
 	$(BUILT_SOURCES)			\
 	actions.c				\
@@ -84,6 +87,12 @@ goo-marshal.c: goo-marshal.list $(GLIB_GENMARSHAL)
 	echo "#include \"goo-marshal.h\"" > $@ && \
 	$(GLIB_GENMARSHAL) $< --body --prefix=goo_marshal >> $@
 
+goo-resources.c: goobox.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies goobox.gresource.xml)
+	$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name goo $(srcdir)/goobox.gresource.xml
+
+goo-resources.h: goobox.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies goobox.gresource.xml)
+	$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name goo $(srcdir)/goobox.gresource.xml
+
 goobox_LDADD = 				\
 	$(top_builddir)/copy-n-paste/libeggsmclient.la  \
 	$(GOO_LIBS) 			\
@@ -92,6 +101,7 @@ goobox_LDADD = 				\
 	$(SYSTEM_LIBS)
 
 EXTRA_DIST = 				\
+	goobox.gresource.xml		\
 	goo-marshal.list 
 
 CLEANFILES = $(BUILT_SOURCES)
diff --git a/src/dlg-cover-chooser.c b/src/dlg-cover-chooser.c
index 45412f7..b25f18b 100644
--- a/src/dlg-cover-chooser.c
+++ b/src/dlg-cover-chooser.c
@@ -469,7 +469,7 @@ dlg_cover_chooser (GooWindow  *window,
 
 	data = g_new0 (DialogData, 1);
 	data->window = window;
-	data->builder = _gtk_builder_new_from_file ("cover-chooser.ui", "");
+	data->builder = _gtk_builder_new_from_resource ("cover-chooser.ui");
 	data->album = g_strdup (album);
 	data->artist = g_strdup (artist);
 	data->cancellable = g_cancellable_new ();
diff --git a/src/dlg-extract.c b/src/dlg-extract.c
index 1ac0775..ef235b9 100644
--- a/src/dlg-extract.c
+++ b/src/dlg-extract.c
@@ -144,7 +144,7 @@ dlg_extract_ask (GooWindow *window)
 
 	data = g_new0 (DialogData, 1);
 	data->window = window;
-	data->builder = _gtk_builder_new_from_file ("extract.ui", "");
+	data->builder = _gtk_builder_new_from_resource ("extract.ui");
 	data->tracks = goo_window_get_tracks (window, FALSE);
 	data->selected_tracks = goo_window_get_tracks (window, TRUE);
 	data->player = g_object_ref (goo_window_get_player (window));
diff --git a/src/dlg-preferences.c b/src/dlg-preferences.c
index bb7766f..77bdb4f 100644
--- a/src/dlg-preferences.c
+++ b/src/dlg-preferences.c
@@ -185,7 +185,7 @@ dlg_preferences (GooWindow *window)
 
 	data = g_new0 (DialogData, 1);
 	data->window = window;
-	data->builder = _gtk_builder_new_from_file ("preferences.ui", "");
+	data->builder = _gtk_builder_new_from_resource ("preferences.ui");
 	data->settings_general = g_settings_new (GOOBOX_SCHEMA_GENERAL);
 	data->settings_ripper = g_settings_new (GOOBOX_SCHEMA_RIPPER);
 
@@ -448,7 +448,7 @@ dlg_format (DialogData    *preferences_data,
 	data = g_new0 (FormatDialogData, 1);
 	data->format = format;
 	data->settings_encoder = g_settings_new (GOOBOX_SCHEMA_ENCODER);
-	data->builder = _gtk_builder_new_from_file ("format-options.ui", "");
+	data->builder = _gtk_builder_new_from_resource ("format-options.ui");
 	data->dialog = GET_WIDGET ("format_dialog");
 
 	/* Set widgets data. */
diff --git a/src/dlg-properties.c b/src/dlg-properties.c
index 5420d90..acadd56 100644
--- a/src/dlg-properties.c
+++ b/src/dlg-properties.c
@@ -502,7 +502,7 @@ dlg_properties (GooWindow *window)
 
 	data = g_new0 (DialogData, 1);
 	data->window = window;
-	data->builder = _gtk_builder_new_from_file ("properties.ui", "");
+	data->builder = _gtk_builder_new_from_resource ("properties.ui");
 	data->cancellable = g_cancellable_new ();
 	data->searching = FALSE;
 	data->closing = FALSE;
diff --git a/src/dlg-ripper.c b/src/dlg-ripper.c
index 729b464..31a8a82 100644
--- a/src/dlg-ripper.c
+++ b/src/dlg-ripper.c
@@ -730,7 +730,7 @@ dlg_ripper (GooWindow *window,
 	data->window = window;
 	data->settings_ripper = g_settings_new (GOOBOX_SCHEMA_RIPPER);
 	data->settings_encoder = g_settings_new (GOOBOX_SCHEMA_ENCODER);
-	data->builder = _gtk_builder_new_from_file ("ripper.ui", "");
+	data->builder = _gtk_builder_new_from_resource ("ripper.ui");
 	data->dialog = GET_WIDGET ("ripper_dialog");
 	data->destination = g_settings_get_string (data->settings_ripper, PREF_RIPPER_DESTINATION);
 	if ((data->destination == NULL) || (strcmp (data->destination, "") == 0))
diff --git a/src/goo-window.c b/src/goo-window.c
index 91766b9..3e751ed 100644
--- a/src/goo-window.c
+++ b/src/goo-window.c
@@ -2401,7 +2401,7 @@ goo_window_construct (GooWindow    *window,
 	gtk_window_add_accel_group (GTK_WINDOW (window),
 				    gtk_ui_manager_get_accel_group (ui));
 
-	if (! gtk_ui_manager_add_ui_from_string (ui, ui_info, -1, &error)) {
+	if (! gtk_ui_manager_add_ui_from_resource (ui, "/org/gnome/Goobox/ui/menu-toolbars.ui", &error)) {
 		g_message ("building menus failed: %s", error->message);
 		g_error_free (error);
 	}
diff --git a/src/goobox.gresource.xml b/src/goobox.gresource.xml
new file mode 100644
index 0000000..fccbc2e
--- /dev/null
+++ b/src/goobox.gresource.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/gnome/Goobox">
+    <file compressed="true">ui/cover-chooser.ui</file>
+    <file compressed="true">ui/extract.ui</file>
+    <file compressed="true">ui/format-options.ui</file>
+    <file compressed="true">ui/menu-toolbars.ui</file>
+    <file compressed="true">ui/preferences.ui</file>
+    <file compressed="true">ui/properties.ui</file>
+    <file compressed="true">ui/ripper.ui</file>
+  </gresource>
+</gresources>
\ No newline at end of file
diff --git a/src/gtk-utils.c b/src/gtk-utils.c
index b5c2b24..a2954e1 100644
--- a/src/gtk-utils.c
+++ b/src/gtk-utils.c
@@ -28,6 +28,7 @@
 
 
 #define REQUEST_ENTRY_WIDTH 220
+#define RESOURCE_UI_PATH "/org/gnome/Goobox/ui/"
 
 
 static GtkWidget *
@@ -833,8 +834,7 @@ _gtk_container_get_n_children (GtkContainer *container)
 
 
 GtkBuilder *
-_gtk_builder_new_from_file (const char *ui_file,
-			    const char *extension)
+_gtk_builder_new_from_file (const char *ui_file)
 {
 	char       *filename;
 	GtkBuilder *builder;
@@ -852,6 +852,25 @@ _gtk_builder_new_from_file (const char *ui_file,
 }
 
 
+GtkBuilder *
+_gtk_builder_new_from_resource (const char *resource_path)
+{
+	GtkBuilder *builder;
+	char       *full_path;
+	GError     *error = NULL;
+
+	builder = gtk_builder_new ();
+	full_path = g_strconcat (RESOURCE_UI_PATH, resource_path, NULL);
+	if (! gtk_builder_add_from_resource (builder, full_path, &error)) {
+		g_warning ("%s\n", error->message);
+		g_clear_error (&error);
+	}
+	g_free (full_path);
+
+	return builder;
+}
+
+
 GtkWidget *
 _gtk_builder_get_widget (GtkBuilder *builder,
 			 const char *name)
diff --git a/src/gtk-utils.h b/src/gtk-utils.h
index 300ee0b..f9ace9b 100644
--- a/src/gtk-utils.h
+++ b/src/gtk-utils.h
@@ -98,8 +98,9 @@ int         _gtk_container_get_pos         (GtkContainer     *container,
 					    GtkWidget        *child);
 guint       _gtk_container_get_n_children  (GtkContainer     *container);
 GtkBuilder *
-	    _gtk_builder_new_from_file     (const char       *filename,
-					    const char       *extension);
+	    _gtk_builder_new_from_file     (const char       *filename);
+GtkBuilder *
+	    _gtk_builder_new_from_resource (const char       *resource_path);
 GtkWidget *
 	    _gtk_builder_get_widget        (GtkBuilder       *builder,
 			 		    const char       *name);
diff --git a/src/ui.h b/src/ui.h
index 641f79e..6b45cb9 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -161,78 +161,4 @@ static GtkToggleActionEntry action_toggle_entries[] = {
 };
 static guint n_action_toggle_entries = G_N_ELEMENTS (action_toggle_entries);
 
-
-static const gchar *ui_info =
-"<ui>"
-"  <menubar name='MenuBar'>"
-"    <menu action='CDMenu'>"
-"      <menuitem action='Extract'/>"
-"      <menuitem action='CopyDisc'/>"
-"      <menuitem action='Eject'/>"
-"      <separator />"
-"      <menuitem action='TogglePlay'/>"
-"      <menuitem action='Stop'/>"
-"      <menuitem action='Next'/>"
-"      <menuitem action='Prev'/>"
-"      <separator />"
-"      <menuitem action='Properties'/>"
-"      <separator />"
-"      <menuitem action='Quit'/>"
-"    </menu>"
-"    <menu action='EditMenu'>"
-"      <menuitem action='PlayAll'/>"
-"      <menuitem action='Repeat'/>"
-"      <menuitem action='Shuffle'/>"
-"      <separator/>"
-"      <menu action='CDCoverMenu'>"
-"        <menuitem action='PickCoverFromDisk'/>"
-"        <menuitem action='SearchCoverFromWeb'/>"
-"        <separator/>"
-"        <menuitem action='RemoveCover'/>"
-"      </menu>"
-"      <separator/>"
-"      <menuitem action='Preferences'/>"
-"    </menu>"
-"    <menu action='ViewMenu'>"
-"      <menuitem action='ViewToolbar'/>"
-"      <menuitem action='ViewStatusbar'/>"
-"    </menu>"
-"    <menu action='HelpMenu'>"
-"      <menuitem action='Contents'/>"
-"      <menuitem action='Shortcuts'/>"
-"      <separator name='sep01'/>"
-"      <menuitem action='About'/>"
-"    </menu>"
-"  </menubar>"
-"  <toolbar  name='ToolBar'>"
-"    <toolitem action='TogglePlay'/>"
-"    <toolitem action='Play'/>"
-"    <toolitem action='Pause'/>"
-"    <toolitem action='Next'/>"
-"    <separator />"
-"    <toolitem action='Extract'/>"
-"    <toolitem action='EjectToolBar'/>"
-"  </toolbar>"
-"  <popup name='ListPopupMenu'>"
-"    <menuitem action='PlaySelected'/>"
-"    <menuitem action='ExtractSelected'/>"
-"  </popup>"
-"  <popup name='TrayPopupMenu'>"
-"    <menuitem action='TogglePlay'/>"
-"    <menuitem action='Next'/>"
-"    <menuitem action='Eject'/>"
-"    <separator/>"
-"    <menuitem action='ToggleVisibility'/>"
-"    <separator/>"
-"    <menuitem action='Quit'/>"
-"  </popup>"
-"  <popup name='CoverPopupMenu'>"
-"    <menuitem action='PickCoverFromDisk'/>"
-"    <menuitem action='SearchCoverFromWeb'/>"
-"    <separator name='sep01'/>"
-"    <menuitem action='RemoveCover'/>"
-"  </popup>"
-"</ui>";
-
-
 #endif /* UI_H */
diff --git a/data/ui/.cvsignore b/src/ui/.cvsignore
similarity index 100%
rename from data/ui/.cvsignore
rename to src/ui/.cvsignore
diff --git a/data/ui/Makefile.am b/src/ui/Makefile.am
similarity index 64%
rename from data/ui/Makefile.am
rename to src/ui/Makefile.am
index d8399e5..5fe73da 100644
--- a/data/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -1,12 +1,11 @@
-gladedir = $(datadir)/goobox/ui
-glade_DATA = \
+EXTRA_DIST = 			\
+	app-menu.ui		\
 	cover-chooser.ui	\
 	extract.ui		\
 	format-options.ui	\
+	menu-toolbars.ui	\
 	preferences.ui		\
 	properties.ui		\
 	ripper.ui
 
-EXTRA_DIST = $(glade_DATA)
-
 -include $(top_srcdir)/git.mk
diff --git a/data/ui/cover-chooser.ui b/src/ui/cover-chooser.ui
similarity index 100%
rename from data/ui/cover-chooser.ui
rename to src/ui/cover-chooser.ui
diff --git a/data/ui/extract.ui b/src/ui/extract.ui
similarity index 100%
rename from data/ui/extract.ui
rename to src/ui/extract.ui
diff --git a/data/ui/format-options.ui b/src/ui/format-options.ui
similarity index 100%
rename from data/ui/format-options.ui
rename to src/ui/format-options.ui
diff --git a/src/ui/menu-toolbars.ui b/src/ui/menu-toolbars.ui
new file mode 100644
index 0000000..5587b91
--- /dev/null
+++ b/src/ui/menu-toolbars.ui
@@ -0,0 +1,70 @@
+<ui>
+  <menubar name="MenuBar">
+    <menu action="CDMenu">
+      <menuitem action="Extract"/>
+      <menuitem action="CopyDisc"/>
+      <menuitem action="Eject"/>
+      <separator />
+      <menuitem action="TogglePlay"/>
+      <menuitem action="Stop"/>
+      <menuitem action="Next"/>
+      <menuitem action="Prev"/>
+      <separator />
+      <menuitem action="Properties"/>
+      <separator />
+      <menuitem action="Quit"/>
+    </menu>
+    <menu action="EditMenu">
+      <menuitem action="PlayAll"/>
+      <menuitem action="Repeat"/>
+      <menuitem action="Shuffle"/>
+      <separator/>
+      <menu action="CDCoverMenu">
+        <menuitem action="PickCoverFromDisk"/>
+        <menuitem action="SearchCoverFromWeb"/>
+        <separator/>
+        <menuitem action="RemoveCover"/>
+      </menu>
+      <separator/>
+      <menuitem action="Preferences"/>
+    </menu>
+    <menu action="ViewMenu">
+      <menuitem action="ViewToolbar"/>
+      <menuitem action="ViewStatusbar"/>
+    </menu>
+    <menu action="HelpMenu">
+      <menuitem action="Contents"/>
+      <menuitem action="Shortcuts"/>
+      <separator name="sep01"/>
+      <menuitem action="About"/>
+    </menu>
+  </menubar>
+  <toolbar  name="ToolBar">
+    <toolitem action="TogglePlay"/>
+    <toolitem action="Play"/>
+    <toolitem action="Pause"/>
+    <toolitem action="Next"/>
+    <separator />
+    <toolitem action="Extract"/>
+    <toolitem action="EjectToolBar"/>
+  </toolbar>
+  <popup name="ListPopupMenu">
+    <menuitem action="PlaySelected"/>
+    <menuitem action="ExtractSelected"/>
+  </popup>
+  <popup name="TrayPopupMenu">
+    <menuitem action="TogglePlay"/>
+    <menuitem action="Next"/>
+    <menuitem action="Eject"/>
+    <separator/>
+    <menuitem action="ToggleVisibility"/>
+    <separator/>
+    <menuitem action="Quit"/>
+  </popup>
+  <popup name="CoverPopupMenu">
+    <menuitem action="PickCoverFromDisk"/>
+    <menuitem action="SearchCoverFromWeb"/>
+    <separator name="sep01"/>
+    <menuitem action="RemoveCover"/>
+  </popup>
+</ui>
\ No newline at end of file
diff --git a/data/ui/preferences.ui b/src/ui/preferences.ui
similarity index 100%
rename from data/ui/preferences.ui
rename to src/ui/preferences.ui
diff --git a/data/ui/properties.ui b/src/ui/properties.ui
similarity index 100%
rename from data/ui/properties.ui
rename to src/ui/properties.ui
diff --git a/data/ui/ripper.ui b/src/ui/ripper.ui
similarity index 100%
rename from data/ui/ripper.ui
rename to src/ui/ripper.ui



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