[gimp] plug-ins: darktable: implement support for locating darktable on macOS



commit 002e7fc98f107f935ca9fa1ddc8713e3dfa6ead9
Author: Kristian Rietveld <kris loopnest org>
Date:   Mon May 15 14:35:19 2017 +0200

    plug-ins: darktable: implement support for locating darktable on macOS

 plug-ins/file-darktable/file-darktable.c |   47 ++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)
---
diff --git a/plug-ins/file-darktable/file-darktable.c b/plug-ins/file-darktable/file-darktable.c
index 4577e2b..cd66ff1 100644
--- a/plug-ins/file-darktable/file-darktable.c
+++ b/plug-ins/file-darktable/file-darktable.c
@@ -33,6 +33,9 @@
 
 #include "file-formats.h"
 
+#ifdef GDK_WINDOWING_QUARTZ
+#include <CoreServices/CoreServices.h>
+#endif
 
 #define LOAD_THUMB_PROC "file-darktable-load-thumb"
 
@@ -72,6 +75,50 @@ get_executable_path (const gchar *suffix,
   /* TODO: allow setting the location of the executable in preferences
    */
 
+#ifdef GDK_WINDOWING_QUARTZ
+  OSStatus status;
+  CFURLRef bundle_url = NULL;
+
+  /* For macOS, attempt searching for a darktable app bundle first. */
+  status = LSFindApplicationForInfo (kLSUnknownCreator,
+                                     CFSTR ("org.darktable"),
+                                     NULL, NULL, &bundle_url);
+
+  if (status >= 0)
+    {
+      CFBundleRef bundle;
+      CFURLRef exec_url, absolute_url;
+      CFStringRef path;
+      gchar *ret;
+      CFIndex len;
+
+      bundle = CFBundleCreate (kCFAllocatorDefault, bundle_url);
+      CFRelease (bundle_url);
+
+      exec_url = CFBundleCopyExecutableURL (bundle);
+      absolute_url = CFURLCopyAbsoluteURL (exec_url);
+      path = CFURLCopyFileSystemPath (absolute_url, kCFURLPOSIXPathStyle);
+
+      /* This gets us the length in UTF16 characters, we multiply by 2
+       * to make sure we have a buffer big enough to fit the UTF8 string.
+       */
+      len = CFStringGetLength (path);
+      ret = g_malloc0 (len * 2 * sizeof (gchar));
+      if (!CFStringGetCString (path, ret, 2 * len * sizeof (gchar),
+                               kCFStringEncodingUTF8))
+        ret = NULL;
+
+      CFRelease (path);
+      CFRelease (absolute_url);
+      CFRelease (exec_url);
+      CFRelease (bundle);
+
+      if (ret)
+        return ret;
+    }
+  /* else, app bundle was not found, try path search as last resort. */
+#endif
+
   *search_path = TRUE;
   if (suffix)
     return g_strconcat ("darktable", suffix, NULL);


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