[gtk+/gtk-2-24] Bug 658772: Directory paths for resource directories are hard coded.



commit 0d0412bcc9b6cb3b326599599fb58355730c36ce
Author: John Ralls <jralls ceridwen us>
Date:   Sat Oct 8 18:08:29 2011 -0700

    Bug 658772: Directory paths for resource directories are hard coded.
    
    Provide dynamic path discovery functions as are provided for win32.

 configure.in     |    9 +++++++
 gtk/gtkprivate.h |    3 +-
 gtk/gtkquartz.c  |   68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 1 deletions(-)
---
diff --git a/configure.in b/configure.in
index 43105ab..c046834 100644
--- a/configure.in
+++ b/configure.in
@@ -1253,9 +1253,18 @@ else
   AM_CONDITIONAL(USE_WIN32, false)
 fi
 
+AC_ARG_ENABLE(quartz-relocation,
+              [AS_HELP_STRING([--enable-quartz-relocation],
+                              [enable bundle-based relocation functions])],
+                              [quartz_relocation=yes])
+
 if test "x$gdktarget" = "xquartz"; then
   GDK_EXTRA_LIBS="$GDK_EXTRA_LIBS -framework Cocoa"
   AM_CONDITIONAL(USE_QUARTZ, true)
+  if test "x$quartz_relocation" = xyes; then
+    AC_DEFINE([QUARTZ_RELOCATION], [1], [Use NSBundle functions to determine load paths for libraries, translations, etc.])
+  fi
+
 else
   AM_CONDITIONAL(USE_QUARTZ, false)
 fi
diff --git a/gtk/gtkprivate.h b/gtk/gtkprivate.h
index 0caade4..53afe0e 100644
--- a/gtk/gtkprivate.h
+++ b/gtk/gtkprivate.h
@@ -74,7 +74,8 @@ typedef enum
 #define GTK_PRIVATE_SET_FLAG(wid,flag)    G_STMT_START{ (GTK_PRIVATE_FLAGS (wid) |= (PRIVATE_ ## flag)); }G_STMT_END
 #define GTK_PRIVATE_UNSET_FLAG(wid,flag)  G_STMT_START{ (GTK_PRIVATE_FLAGS (wid) &= ~(PRIVATE_ ## flag)); }G_STMT_END
 
-#ifdef G_OS_WIN32
+#if defined G_OS_WIN32 \
+  || (defined GDK_WINDOWING_QUARTZ && defined QUARTZ_RELOCATION)
 
 const gchar *_gtk_get_datadir ();
 const gchar *_gtk_get_libdir ();
diff --git a/gtk/gtkquartz.c b/gtk/gtkquartz.c
index 5b28969..59c5327 100644
--- a/gtk/gtkquartz.c
+++ b/gtk/gtkquartz.c
@@ -323,3 +323,71 @@ _gtk_quartz_set_selection_data_for_pasteboard (NSPasteboard     *pasteboard,
                                        freeWhenDone:NO]
                                             forType:type];
 }
+
+/*
+ * Bundle-based functions for various directories. These almost work
+ * even when the application isn't in a bundle, becuase mainBundle
+ * paths point to the bin directory in that case. It's a simple matter
+ * to test for that and remove the last element.
+ */
+
+static gchar *
+get_bundle_path()
+{
+  gchar *base, *path;
+  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+  gchar *resource_path = g_strdup([[[NSBundle mainBundle] resourcePath] UTF8String]);
+  [pool drain];
+  base = g_path_get_basename(resource_path);
+  if (strcmp(base, "bin") == 0) 
+    path = g_path_get_dirname(resource_path);
+  else
+    path = strdup(resource_path);
+  g_free(resource_path);
+  g_free(base);
+  return path;
+}
+
+const gchar *
+_gtk_get_datadir (void)
+{
+  gchar *resource_dir = get_bundle_path();
+  gchar *retval = g_build_filename(resource_dir, "share", NULL);
+  g_free(resource_dir);
+  return retval;
+}
+
+const gchar *
+_gtk_get_libdir (void)
+{
+  gchar *resource_dir = get_bundle_path();
+  gchar *retval = g_build_filename(resource_dir, "lib", NULL);
+  g_free(resource_dir);
+  return retval;
+}
+
+const gchar *
+_gtk_get_localedir (void)
+{
+
+  gchar *resource_dir = get_bundle_path();
+  gchar *retval = g_build_filename(resource_dir, "share", "locale", NULL);
+  g_free(resource_dir);
+  return retval;
+}
+
+const gchar *
+_gtk_get_sysconfdir (void)
+{
+  gchar *resource_dir = get_bundle_path();
+  gchar *retval = g_build_filename(resource_dir, "etc", NULL);
+  g_free(resource_dir);
+  return retval;
+}
+
+const gchar *
+_gtk_get_data_prefix (void)
+{
+  return get_bundle_path();
+}
+



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