[evince] [windows] Make evince relocatable on windows - GUI



commit 1c08234e07636f2276af6458bf478bd863ed537f
Author: Hib Eris <hib hiberis nl>
Date:   Tue Jun 9 15:10:50 2009 +0200

    [windows] Make evince relocatable on windows - GUI
---
 shell/ev-application.c |   29 +++++++++++++++++++++++++++--
 shell/ev-application.h |    1 +
 shell/ev-window.c      |   10 +++++++---
 3 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/shell/ev-application.c b/shell/ev-application.c
index 6a3367f..3d4afb1 100644
--- a/shell/ev-application.c
+++ b/shell/ev-application.c
@@ -57,6 +57,7 @@ struct _EvApplication {
 	GObject base_instance;
 
 	gchar *dot_dir;
+	gchar *data_dir;
 	gchar *accel_map_file;
 	gchar *toolbars_file;
 	gchar *crashed_file;
@@ -787,6 +788,8 @@ ev_application_shutdown (EvApplication *application)
 
         g_free (application->dot_dir);
         application->dot_dir = NULL;
+        g_free (application->data_dir);
+        application->data_dir = NULL;
 	g_free (application->filechooser_open_uri);
         application->filechooser_open_uri = NULL;
 	g_free (application->filechooser_save_uri);
@@ -808,6 +811,7 @@ ev_application_init (EvApplication *ev_application)
 {
 	gint i;
 	const gchar *home_dir;
+	gchar *toolbar_path;
 
         ev_application->dot_dir = g_build_filename (g_get_home_dir (),
                                                     ".gnome2",
@@ -818,6 +822,18 @@ ev_application_init (EvApplication *ev_application)
         if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700))
                 exit (1);
 
+#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 (DATADIR);
+#endif
+
 	ev_application_init_session (ev_application);
 
 	home_dir = g_get_home_dir ();
@@ -835,14 +851,17 @@ ev_application_init (EvApplication *ev_application)
 	ev_application->toolbars_file = g_build_filename
 			(ev_application->dot_dir, "evince_toolbar.xml", NULL);
 
+	toolbar_path = g_build_filename (ev_application->data_dir,
+					 "evince-toolbar.xml", NULL);
 	egg_toolbars_model_load_names (ev_application->toolbars_model,
-				       DATADIR "/evince-toolbar.xml");
+				       toolbar_path);
 
 	if (!egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
 					       ev_application->toolbars_file)) {
 		egg_toolbars_model_load_toolbars (ev_application->toolbars_model,
-						  DATADIR"/evince-toolbar.xml");
+						  toolbar_path);
 	}
+	g_free (toolbar_path);
 
 	/* Open item doesn't exist anymore,
 	 * convert it to OpenRecent for compatibility
@@ -1114,3 +1133,9 @@ 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 184927b..2ae2a8a 100644
--- a/shell/ev-application.h
+++ b/shell/ev-application.h
@@ -93,6 +93,7 @@ GtkPageSetup     *ev_application_get_page_setup      (EvApplication   *applicati
 void              ev_application_set_page_setup      (EvApplication   *application,
 						      GtkPageSetup    *page_setup);
 const gchar      *ev_application_get_dot_dir         (EvApplication   *application);
+const gchar      *ev_application_get_data_dir         (EvApplication   *application);
 
 G_END_DECLS
 
diff --git a/shell/ev-window.c b/shell/ev-window.c
index a1dadb7..7984cab 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -5883,6 +5883,7 @@ ev_window_init (EvWindow *ev_window)
 	GError *error = NULL;
 	GtkWidget *sidebar_widget;
 	GObject *mpkeys;
+	gchar *ui_path;
 
 	g_signal_connect (ev_window, "configure_event",
 			  G_CALLBACK (window_configure_event_cb), NULL);
@@ -5937,12 +5938,15 @@ ev_window_init (EvWindow *ev_window)
 	gtk_ui_manager_insert_action_group (ev_window->priv->ui_manager,
 					    action_group, 0);
 
-	if (!gtk_ui_manager_add_ui_from_file (ev_window->priv->ui_manager,
-					      DATADIR"/evince-ui.xml",
-					      &error)) {
+	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);
 	
 	ev_window->priv->recent_manager = gtk_recent_manager_get_default ();
 	ev_window->priv->recent_action_group = NULL;



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