]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkquartz.c
Bug 658772: Directory paths for resource directories are hard coded.
[~andy/gtk] / gtk / gtkquartz.c
index b9ea2ec1ff119c3cb70dd416b897338a128a3ea4..e15890e7ed5d4ca1fb84ef75b90b2ae4a187adfd 100644 (file)
@@ -310,3 +310,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();
+}
+