r19201 - gnucash/trunk - Implement help for OSX

John Ralls jralls at code.gnucash.org
Sat May 22 19:40:01 EDT 2010


Author: jralls
Date: 2010-05-22 19:40:01 -0400 (Sat, 22 May 2010)
New Revision: 19201
Trac: http://svn.gnucash.org/trac/changeset/19201

Modified:
   gnucash/trunk/configure.ac
   gnucash/trunk/src/bin/Makefile.am
   gnucash/trunk/src/gnc-ui.h
   gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
Log:
Implement help for OSX

Modified: gnucash/trunk/configure.ac
===================================================================
--- gnucash/trunk/configure.ac	2010-05-22 21:29:00 UTC (rev 19200)
+++ gnucash/trunk/configure.ac	2010-05-22 23:40:01 UTC (rev 19201)
@@ -244,12 +244,16 @@
 		_gdk_tgt=`$PKG_CONFIG --variable=target gdk-2.0`
 		if test "x$_gdk_tgt" = xquartz; then 
 		   platform=darwin/quartz
+		   AC_PROG_OBJC
 		   AC_MSG_RESULT(yes)
 		   AC_DEFINE(GDK_QUARTZ,,[Using GDK Quartz (not X11)])
-		   AC_MSG_CHECKING(For ige-mac-integration)   
-		   PKG_CHECK_MODULES(IGE_MAC, ige-mac-integration,
-				     AC_MSG_RESULT(yes),
-				     AC_MSG_RESULT(no))
+		   PKG_CHECK_MODULES([IGE_MAC], ige-mac-integration,
+				     [_ige_mac=yes], [_ige_mac=no])
+		   if test "x$_ige_mac" = xyes;	then
+		      IGE_MAC_LIBS="${IGE_MAC_LIBS} -lobjc"
+		      IGE_MAC_CFLAGS="${IGE_MAC_CFLAGS} -xobjective-c"
+		   fi
+		   AC_MSG_RESULT(${_ige_mac})
 		   AC_SUBST(IGE_MAC_LIBS)
 		   AC_SUBST(IGE_MAC_CFLAGS)
 		   GNUCASH_ENVIRONMENT="environment-osx"

Modified: gnucash/trunk/src/bin/Makefile.am
===================================================================
--- gnucash/trunk/src/bin/Makefile.am	2010-05-22 21:29:00 UTC (rev 19200)
+++ gnucash/trunk/src/bin/Makefile.am	2010-05-22 23:40:01 UTC (rev 19201)
@@ -99,7 +99,7 @@
 	rm -f $@.tmp
 	sed < $< > $@.tmp \
 	    -e 's#@-BIN_DIR-@#${bindir}#g' \
-	    -e 's#@-GNC_DBD_DIR-@#${GNC_DBD_DIR}#g' \ 
+	    -e 's#@-GNC_DBD_DIR-@#${GNC_DBD_DIR}#g' \
 	    -e 's#@-GNC_STANDARD_REPORTS_DIR-@#${GNC_SHAREDIR}/guile-modules/gnucash/report/standard-reports#g' \
 	    -e 's#@-GNC_GUILE_MODULE_DIR-@#${GNC_SHAREDIR}/guile-modules#g' \
 	    -e 's#@-GNC_SCM_INSTALL_DIR-@#${GNC_SCM_INSTALL_DIR}#g' \

Modified: gnucash/trunk/src/gnc-ui.h
===================================================================
--- gnucash/trunk/src/gnc-ui.h	2010-05-22 21:29:00 UTC (rev 19200)
+++ gnucash/trunk/src/gnc-ui.h	2010-05-22 23:40:01 UTC (rev 19201)
@@ -43,6 +43,9 @@
 #ifdef G_OS_WIN32
 #    define HF_GUIDE         "gnucash-guide.chm"
 #    define HF_HELP          "gnucash-help.chm"
+#elif defined MAC_INTEGRATION
+#    define HF_GUIDE         "Gnucash Guide"
+#    define HF_HELP          "Gnucash Help"
 #else
 #    define HF_GUIDE         "gnucash-guide.xml"
 #    define HF_HELP          "gnucash-help.xml"

Modified: gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c	2010-05-22 21:29:00 UTC (rev 19200)
+++ gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c	2010-05-22 23:40:01 UTC (rev 19201)
@@ -57,6 +57,9 @@
 #ifdef G_OS_WIN32
 #    include "gnc-help-utils.h"
 #endif
+#ifdef MAC_INTEGRATION
+#import <Cocoa/Cocoa.h>
+#endif
 
 static QofLogModule log_module = GNC_MOD_GUI;
 static GnomeProgram *gnucash_program = NULL;
@@ -271,28 +274,86 @@
     return;
 }
 
-#ifndef G_OS_WIN32
+#ifdef MAC_INTEGRATION
+
+/* Don't be alarmed if this function looks strange to you: It's
+ * written in Objective-C, the native language of the OSX Cocoa
+ * toolkit.
+ */
 void
-gnc_gnome_help (const char *file_name, const char *anchor)
+gnc_gnome_help (const char *dir, const char *detail)
 {
-    GError *error = NULL;
+  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+  NSString *subdir = [NSString stringWithUTF8String: dir];
+  NSString *help_dir = [NSString stringWithUTF8String: HF_HELP];
+  NSString *tag;
+  NSURL *url = NULL;
 
-    DEBUG ("Attempting to opening help file %s", file_name);
-    if (gnome_help_display (file_name, anchor, &error))
-        return;
+  if (detail)
+      tag  = [NSString stringWithUTF8String: detail];
+  else if ([subdir compare: help_dir] == NSOrderedSame)
+      tag = @"help";
+  else
+      tag = @"index";
 
-    g_assert(error != NULL);
-    {
+  if (![[NSBundle mainBundle] bundleIdentifier]) {
+/* If bundleIdentifier is NULL, then we're running from the
+ * commandline and must construct a file path to the resource. We can
+ * still get the resource path, but it will point to the "bin"
+ * directory so we chop that off, break up what's left into pieces,
+ * add some more pieces, and put it all back together again. Then,
+ * because the gettext way of handling localizations is different from
+ * OSX's, we have to figure out which translation to use. */
+      NSArray *components = [NSArray arrayWithObjects: @"share", @"gnome", @"help", @"gnucash", nil ];
+      NSString *prefix = [[[NSBundle mainBundle] resourcePath]
+			   stringByDeletingLastPathComponent];
+      NSArray *prefix_comps = [[prefix pathComponents]
+			       arrayByAddingObjectsFromArray: components];
+      NSString *docs_dir = [NSString pathWithComponents: prefix_comps];
+      NSString * cur_locale = [[NSLocale currentLocale] localeIdentifier] ;
+      BOOL dir, exists;
+      subdir = [[[subdir lowercaseString] componentsSeparatedByString: @" "] 
+		componentsJoinedByString: @"-"];
+      if (![[NSFileManager defaultManager] fileExistsAtPath: docs_dir]) {
         const gchar *message =
             _("GnuCash could not find the files for the help documentation.  "
               "This is likely because the 'gnucash-docs' package is not installed.");
         gnc_error_dialog(NULL, "%s", message);
-    }
-    PERR ("%s", error->message);
-    g_error_free(error);
+	[pool release];
+	return;
+      }
+      exists = [[NSFileManager defaultManager]
+		fileExistsAtPath: [docs_dir
+				   stringByAppendingPathComponent: cur_locale]
+		isDirectory: &dir];
+      if (exists && dir)
+	  url = [NSURL 
+		 fileURLWithPath: [[[[docs_dir
+				      stringByAppendingPathComponent: cur_locale]
+				     stringByAppendingPathComponent: subdir]
+				    stringByAppendingPathComponent: tag]
+				   stringByAppendingPathExtension: @"html"]];
+      if (!url)
+	  url = [NSURL 
+		 fileURLWithPath: [[[[docs_dir
+				      stringByAppendingPathComponent: @"C"]
+				     stringByAppendingPathComponent: subdir]
+				    stringByAppendingPathComponent: tag]
+				   stringByAppendingPathExtension: @"html"]];
+
+  }
+/* It's a lot easier in a bundle! */
+  else   
+      url = [NSURL fileURLWithPath: [[NSBundle mainBundle] 
+				     pathForResource: tag
+				     ofType: @"html"
+				     inDirectory: subdir ]];
+
+/* Now just open the URL in the default app for opening URLs */
+  [[NSWorkspace sharedWorkspace] openURL: url];
+  [pool release];
 }
-
-#else /* G_OS_WIN32 */
+#elif defined G_OS_WIN32 /* G_OS_WIN32 */
 void
 gnc_gnome_help (const char *file_name, const char *anchor)
 {
@@ -326,6 +387,28 @@
     }
     g_free (found);
 }
+#else
+void
+gnc_gnome_help (const char *file_name, const char *anchor)
+{
+    GError *error = NULL;
+
+    DEBUG ("Attempting to opening help file %s", file_name);
+    if (gnome_help_display (file_name, anchor, &error))
+        return;
+
+    g_assert(error != NULL);
+    {
+        const gchar *message =
+            _("GnuCash could not find the files for the help documentation.  "
+              "This is likely because the 'gnucash-docs' package is not installed.");
+        gnc_error_dialog(NULL, "%s", message);
+    }
+    PERR ("%s", error->message);
+    g_error_free(error);
+}
+
+
 #endif
 
 /********************************************************************\



More information about the gnucash-changes mailing list