[evince/wip/app: 19/23] shell: Use GResource for data files



commit fa3eab6a7b16d7531cec204b3350067ea48d75f0
Author: Christian Persch <chpe gnome org>
Date:   Tue Jun 12 20:02:34 2012 +0200

    shell: Use GResource for data files

 data/Makefile.am                   |    2 --
 shell/Makefile.am                  |   16 ++++++++++++++--
 shell/ev-application.c             |   21 ---------------------
 shell/ev-application.h             |    1 -
 shell/ev-window.c                  |   24 ++++++++----------------
 {data => shell}/evince-toolbar.xml |    0
 {data => shell}/evince-ui.xml      |    0
 shell/evince.gresource.xml         |   23 +++++++++++++++++++++++
 8 files changed, 45 insertions(+), 42 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 33eac55..06061f6 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -15,8 +15,6 @@ man_MANS=evince.1
 
 uidir = $(pkgdatadir)
 ui_DATA =				\
-	evince-ui.xml			\
-	evince-toolbar.xml		\
 	hand-open.png
 
 #
diff --git a/shell/Makefile.am b/shell/Makefile.am
index c976f42..e1f816a 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -67,6 +67,8 @@ evince_SOURCES=				\
 	ev-properties-license.h		\
 	ev-open-recent-action.c		\
 	ev-open-recent-action.h		\
+	ev-resources.c			\
+	ev-resources.h			\
 	ev-utils.c			\
 	ev-utils.h			\
 	ev-window.c			\
@@ -127,7 +129,11 @@ evince-icon.o: $(srcdir)/evince-icon.rc $(top_srcdir)/data/evince.ico
 	$(AM_V_GEN)$(WINDRES) $(srcdir)/evince-icon.rc -I $(top_srcdir)/data evince-icon.o
 endif
 
-BUILT_SOURCES = ev-marshal.h ev-marshal.c 
+BUILT_SOURCES = \
+	ev-marshal.c \
+	ev-marshal.h \
+	ev-resources.c \
+	ev-resources.h
 if ENABLE_DBUS
 BUILT_SOURCES += \
 	ev-gdbus-generated.c \
@@ -161,7 +167,10 @@ EXTRA_DIST = \
 	ev-marshal.list \
 	evince-icon.rc \
 	ev-gdbus.xml \
-	ev-daemon-gdbus.xml
+	ev-daemon-gdbus.xml \
+	evince-ui.xml \
+	evince-toolbar.xml \
+	evince.gresource.xml
 
 ev-marshal.h: $(srcdir)/ev-marshal.list
 	$(AM_V_GEN)$(GLIB_GENMARSHAL) --prefix=ev_marshal $(srcdir)/ev-marshal.list --header > ev-marshal.h
@@ -186,6 +195,9 @@ ev-daemon-gdbus-generated.c ev-daemon-gdbus-generated.h: ev-daemon-gdbus.xml Mak
 			--generate-c-code ev-daemon-gdbus-generated \
 			$<
 
+ev-resources.h ev-resources.c: evince.gresource.xml Makefile $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies --sourcedir $(srcdir) $(srcdir)/evince.gresource.xml)
+	$(AM_V_GEN) XMLLINT=$(XMLLINT) $(GLIB_COMPILE_RESOURCES) --target $@ --sourcedir $(srcdir) --generate --c-name ev $<
+
 DISTCLEANFILES =
 
 -include $(top_srcdir)/git.mk
diff --git a/shell/ev-application.c b/shell/ev-application.c
index 11fde65..e8bdbb8 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -56,7 +56,6 @@ struct _EvApplication {
 	gchar *uri;
 
 	gchar *dot_dir;
-	gchar *data_dir;
 
 #ifdef ENABLE_DBUS
         EvEvinceApplicationImpl *impl;
@@ -927,8 +926,6 @@ ev_application_shutdown (GApplication *gapplication)
 
         g_free (application->dot_dir);
         application->dot_dir = NULL;
-        g_free (application->data_dir);
-        application->data_dir = NULL;
 
         G_APPLICATION_CLASS (ev_application_parent_class)->shutdown (gapplication);
 }
@@ -1027,18 +1024,6 @@ ev_application_init (EvApplication *ev_application)
         if (!g_file_test (ev_application->dot_dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
                 ev_application_migrate_config_dir (ev_application);
 
-#ifdef G_OS_WIN32
-{
-	gchar *dir;
-
-	dir = g_win32_get_package_installation_directory_of_module (NULL);
-	ev_application->data_dir = g_build_filename (dir, "share", "evince", NULL);
-	g_free (dir);
-}
-#else
-	ev_application->data_dir = g_strdup (EVINCEDATADIR);
-#endif
-
 	ev_application_init_session (ev_application);
 
 	ev_application_accel_map_load (ev_application);
@@ -1127,9 +1112,3 @@ ev_application_get_dot_dir (EvApplication *application,
 
 	return application->dot_dir;
 }
-
-const gchar *
-ev_application_get_data_dir (EvApplication   *application)
-{
-	return application->data_dir;
-}
diff --git a/shell/ev-application.h b/shell/ev-application.h
index 7780853..b631127 100644
--- a/shell/ev-application.h
+++ b/shell/ev-application.h
@@ -82,7 +82,6 @@ void		  ev_application_screensaver_enable  (EvApplication   *application);
 void		  ev_application_screensaver_disable (EvApplication   *application);
 const gchar      *ev_application_get_dot_dir         (EvApplication   *application,
                                                       gboolean         create);
-const gchar      *ev_application_get_data_dir        (EvApplication   *application);
 
 GdkDisplay       *ev_display_open_if_needed          (const gchar *name);
 
diff --git a/shell/ev-window.c b/shell/ev-window.c
index a69c6c0..f67b5a2 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -275,6 +275,8 @@ struct _EvWindowPrivate {
 #define EV_HELP_TOOLBAR "http://library.gnome.org/users/evince/stable/toolbar.html";
 #endif
 
+#define TOOLBAR_RESOURCE_PATH "/org/gnome/evince/shell/ui/toolbar.xml"
+
 static const gchar *document_print_settings[] = {
 	GTK_PRINT_SETTINGS_N_COPIES,
 	GTK_PRINT_SETTINGS_COLLATE,
@@ -6928,19 +6930,16 @@ get_toolbars_model (void)
 {
 	EggToolbarsModel *toolbars_model;
 	gchar            *toolbars_file;
-	gchar            *toolbars_path;
 	gint              i;
 
 	toolbars_model = egg_toolbars_model_new ();
 
 	toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE),
 					  "evince_toolbar.xml", NULL);
-	toolbars_path = g_build_filename (ev_application_get_data_dir (EV_APP),
-					 "evince-toolbar.xml", NULL);
-	egg_toolbars_model_load_names (toolbars_model, toolbars_path);
+	egg_toolbars_model_load_names_from_resource (toolbars_model, TOOLBAR_RESOURCE_PATH);
 
 	if (!egg_toolbars_model_load_toolbars (toolbars_model, toolbars_file)) {
-		egg_toolbars_model_load_toolbars (toolbars_model, toolbars_path);
+		egg_toolbars_model_load_toolbars_from_resource (toolbars_model, TOOLBAR_RESOURCE_PATH);
                 goto skip_conversion;
 	}
 
@@ -6962,7 +6961,6 @@ get_toolbars_model (void)
 
     skip_conversion:
 	g_free (toolbars_file);
-	g_free (toolbars_path);
 
 	egg_toolbars_model_set_flags (toolbars_model, 0, EGG_TB_MODEL_NOT_REMOVABLE);
 
@@ -7057,7 +7055,6 @@ ev_window_init (EvWindow *ev_window)
 	GtkWidget *menuitem;
 	EggToolbarsModel *toolbars_model;
 	GObject *mpkeys;
-	gchar *ui_path;
 #ifdef ENABLE_DBUS
 	GDBusConnection *connection;
 	static gint window_id = 0;
@@ -7147,15 +7144,10 @@ ev_window_init (EvWindow *ev_window)
 	gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
 					    action_group, 0);
 
-	ui_path = g_build_filename (ev_application_get_data_dir (EV_APP),
-				    "evince-ui.xml", NULL);
-	if (!gtk_ui_manager_add_ui_from_file (
-		ev_window->priv->ui_manager, ui_path, &error))
-	{
-		g_warning ("building menus failed: %s", error->message);
-		g_error_free (error);
-	}
-	g_free (ui_path);
+        gtk_ui_manager_add_ui_from_resource (ev_window->priv->ui_manager,
+                                             "/org/gnome/evince/shell/ui/evince.xml",
+                                             &error);
+        g_assert_no_error (error);
 
 	ev_window->priv->recent_manager = gtk_recent_manager_get_default ();
 	ev_window->priv->recent_action_group = NULL;
diff --git a/data/evince-toolbar.xml b/shell/evince-toolbar.xml
similarity index 100%
rename from data/evince-toolbar.xml
rename to shell/evince-toolbar.xml
diff --git a/data/evince-ui.xml b/shell/evince-ui.xml
similarity index 100%
rename from data/evince-ui.xml
rename to shell/evince-ui.xml
diff --git a/shell/evince.gresource.xml b/shell/evince.gresource.xml
new file mode 100644
index 0000000..2fac911
--- /dev/null
+++ b/shell/evince.gresource.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright  2012 Christian Persch
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3, or (at your option)
+  any later version.
+
+  This program is distributed in the hope conf it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<gresources>
+  <gresource prefix="/org/gnome/evince/shell">
+    <file alias="ui/evince.xml" compressed="true" preprocess="xml-stripblanks">evince-ui.xml</file>
+    <file alias="ui/toolbar.xml" compressed="true" preprocess="xml-stripblanks">evince-toolbar.xml</file>
+  </gresource>
+</gresources>



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