[gimp] Bug 767830 - Help browser does not launch on OS X



commit 308efbb51401ef2a1032619c335e56150587f227
Author: Michael Natterer <mitch gimp org>
Date:   Tue Sep 6 20:51:47 2016 +0200

    Bug 767830 - Help browser does not launch on OS X
    
    Try harder to show help when webkit is missing or the help browser
    won't start:
    
    - offer to switch to the web browser when the help browser is
      present, but won't start for some reason
    - in prefs, don't bother showing the help browser GUI when webkit
      is missing, otherwise show a warning label if the help browser
      is not installed even though webkit is there. Switch to the web
      browser in both cases (modified patch from lisanet)
    - add OS X replacement for gtk_show_uri() in plug-in-web-browser
      (modified patch from lisanet)

 app/dialogs/preferences-dialog.c |  138 +++++++++++++++++++++++++-------------
 app/widgets/gimphelp.c           |   14 ++++-
 app/widgets/gimphelp.h           |    4 +
 plug-ins/common/Makefile.am      |    9 +++
 plug-ins/common/mkgen.pl         |   14 ++++
 plug-ins/common/plugin-defs.pl   |    2 +-
 plug-ins/common/web-browser.c    |   28 +++++++-
 7 files changed, 156 insertions(+), 53 deletions(-)
---
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index aa53173..cee01d6 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -293,6 +293,14 @@ prefs_response (GtkWidget *widget,
             config_copy = g_object_get_data (G_OBJECT (dialog), "config-copy");
 
             gimp_config_reset (config_copy);
+
+            /* don't use the default value if there is no help browser */
+            if (! gimp_help_browser_is_installed (gimp))
+              {
+                g_object_set (config_copy,
+                              "help-browser", GIMP_HELP_BROWSER_WEB_BROWSER,
+                              NULL);
+              }
           }
 
         gtk_widget_destroy (confirm);
@@ -799,6 +807,35 @@ prefs_table_new (gint          rows,
 }
 
 static GtkWidget *
+prefs_hint_box_new (const gchar  *icon_name,
+                    const gchar  *text)
+{
+  GtkWidget *hbox;
+  GtkWidget *image;
+  GtkWidget *label;
+
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+
+  image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
+  gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+  gtk_widget_show (image);
+
+  label = gtk_label_new (text);
+  gimp_label_set_attributes (GTK_LABEL (label),
+                             PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
+                             -1);
+  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+
+  gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+  gtk_widget_show (label);
+
+  gtk_widget_show (hbox);
+
+  return hbox;
+}
+
+static GtkWidget *
 prefs_button_add (const gchar *icon_name,
                   const gchar *label,
                   GtkBox      *box)
@@ -2191,59 +2228,64 @@ prefs_dialog_new (Gimp       *gimp,
                           _("Show help _buttons"),
                           GTK_BOX (vbox2));
 
-  {
-    GtkWidget   *combo;
-    GtkWidget   *hbox;
-    GtkWidget   *image;
-    GtkWidget   *label;
-    const gchar *icon;
-    const gchar *text;
-
-    table = prefs_table_new (2, GTK_CONTAINER (vbox2));
-    combo = prefs_boolean_combo_box_add (object, "user-manual-online",
-                                         _("Use the online version"),
-                                         _("Use a locally installed copy"),
-                                         _("User manual:"),
-                                         GTK_TABLE (table), 0, size_group);
-    gimp_help_set_help_data (combo, NULL, NULL);
-
-    if (gimp_help_user_manual_is_installed (gimp))
-      {
-        icon = GIMP_STOCK_INFO;
-        text = _("There's a local installation of the user manual.");
-      }
-    else
-      {
-        icon = GIMP_STOCK_WARNING;
-        text = _("The user manual is not installed locally.");
-      }
-
-    hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-    gtk_table_attach_defaults (GTK_TABLE (table), hbox, 1, 2, 1, 2);
-    gtk_widget_show (hbox);
-
-    image = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_BUTTON);
-    gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
-    gtk_widget_show (image);
-
-    label = gtk_label_new (text);
-    gimp_label_set_attributes (GTK_LABEL (label),
-                               PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
-                               -1);
-    gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
-    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+  table = prefs_table_new (2, GTK_CONTAINER (vbox2));
+  button = prefs_boolean_combo_box_add (object, "user-manual-online",
+                                        _("Use the online version"),
+                                        _("Use a locally installed copy"),
+                                        _("User manual:"),
+                                        GTK_TABLE (table), 0, size_group);
+  gimp_help_set_help_data (button, NULL, NULL);
+
+  if (gimp_help_user_manual_is_installed (gimp))
+    {
+      hbox = prefs_hint_box_new (GIMP_STOCK_INFO,
+                                 _("There's a local installation "
+                                   "of the user manual."));
+    }
+  else
+    {
+      hbox = prefs_hint_box_new (GIMP_STOCK_WARNING,
+                                 _("The user manual is not installed "
+                                   "locally."));
+    }
 
-    gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
-    gtk_widget_show (label);
-  }
+  gtk_table_attach_defaults (GTK_TABLE (table), hbox, 1, 2, 1, 2);
+  gtk_widget_show (hbox);
 
   /*  Help Browser  */
+#ifdef HAVE_WEBKIT
+  /*  If there is no webkit available, assume we are on a platform
+   *  that doesn't use the help browser, so don't bother showing
+   *  the combo.
+   */
   vbox2 = prefs_frame_new (_("Help Browser"), GTK_CONTAINER (vbox), FALSE);
-  table = prefs_table_new (1, GTK_CONTAINER (vbox2));
 
-  prefs_enum_combo_box_add (object, "help-browser", 0, 0,
-                            _("H_elp browser to use:"),
-                            GTK_TABLE (table), 0, size_group);
+  if (gimp_help_browser_is_installed (gimp))
+    {
+      table = prefs_table_new (1, GTK_CONTAINER (vbox2));
+
+      button = prefs_enum_combo_box_add (object, "help-browser", 0, 0,
+                                         _("H_elp browser to use:"),
+                                         GTK_TABLE (table), 0, size_group);
+    }
+  else
+    {
+      hbox = prefs_hint_box_new (GIMP_STOCK_WARNING,
+                                 _("The GIMP help browser doesn't seem to "
+                                   "be installed. Using the web browser "
+                                   "instead."));
+      gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
+      gtk_widget_show (hbox);
+
+      g_object_set (config,
+                    "help-browser", GIMP_HELP_BROWSER_WEB_BROWSER,
+                    NULL);
+    }
+#else
+  g_object_set (config,
+                "help-browser", GIMP_HELP_BROWSER_WEB_BROWSER,
+                NULL);
+#endif /* HAVE_WEBKIT */
 
   /* Action Search */
   vbox2 = prefs_frame_new (_("Action Search"), GTK_CONTAINER (vbox), FALSE);
diff --git a/app/widgets/gimphelp.c b/app/widgets/gimphelp.c
index 5a9a805..82afa85 100644
--- a/app/widgets/gimphelp.c
+++ b/app/widgets/gimphelp.c
@@ -138,6 +138,17 @@ gimp_help_show (Gimp         *gimp,
 }
 
 gboolean
+gimp_help_browser_is_installed (Gimp *gimp)
+{
+  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
+
+  if (gimp_pdb_lookup_procedure (gimp->pdb, "extension-gimp-help-browser"))
+    return TRUE;
+
+  return FALSE;
+}
+
+gboolean
 gimp_help_user_manual_is_installed (Gimp *gimp)
 {
   GFile    *basedir;
@@ -347,7 +358,8 @@ gimp_help_browser (Gimp         *gimp,
                                _("Help browser doesn't start"),
                                _("Could not start the GIMP help browser "
                                  "plug-in."),
-                               NULL);
+                               _("You may instead use the web browser "
+                                 "for reading the help pages."));
       busy = FALSE;
 
       return FALSE;
diff --git a/app/widgets/gimphelp.h b/app/widgets/gimphelp.h
index 4d505ec..142fb05 100644
--- a/app/widgets/gimphelp.h
+++ b/app/widgets/gimphelp.h
@@ -32,6 +32,10 @@ void       gimp_help_show (Gimp         *gimp,
                            const gchar  *help_id);
 
 
+/*  checks if the help browser is available
+ */
+gboolean   gimp_help_browser_is_installed     (Gimp *gimp);
+
 /*  checks if the user manual is installed locally
  */
 gboolean   gimp_help_user_manual_is_installed (Gimp *gimp);
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 5bed4ba..be71353 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -13,6 +13,11 @@ else
 libm = -lm
 endif
 
+if PLATFORM_OSX
+xobjective_c = "-xobjective-c"
+framework_cocoa = -framework Cocoa
+endif
+
 if HAVE_WINDRES
 include $(top_srcdir)/build/windows/gimprc-plug-ins.rule
 include gimprc.common
@@ -1762,6 +1767,10 @@ warp_LDADD = \
        $(INTLLIBS)             \
        $(warp_RC)
 
+web_browser_LDFLAGS = $(framework_cocoa)
+
+web_browser_CFLAGS = $(xobjective_c)
+
 web_browser_SOURCES = \
        web-browser.c
 
diff --git a/plug-ins/common/mkgen.pl b/plug-ins/common/mkgen.pl
index 82d89ce..d612cd7 100755
--- a/plug-ins/common/mkgen.pl
+++ b/plug-ins/common/mkgen.pl
@@ -64,6 +64,11 @@ else
 libm = -lm
 endif
 
+if PLATFORM_OSX
+xobjective_c = "-xobjective-c"
+framework_cocoa = -framework Cocoa
+endif
+
 if HAVE_WINDRES
 include \$(top_srcdir)/build/windows/gimprc-plug-ins.rule
 include $rcfile
@@ -161,6 +166,15 @@ foreach (sort keys %plugins) {
                $optlib = "\n\t\$(" . $plugins{$_}->{libs} . ")\t\t\\";
     }
 
+    if (exists $plugins{$_}->{ldflags}) {
+       my $ldflags = $plugins{$_}->{ldflags};
+
+       print MK <<EOT;
+
+${makename}_LDFLAGS = $ldflags
+EOT
+    }
+
     if (exists $plugins{$_}->{cflags}) {
        my $cflags = $plugins{$_}->{cflags};
        my $cflagsvalue = $cflags =~ /FLAGS/ ? "\$($cflags)" : $cflags;
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index 5346f87..6183faf 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -90,6 +90,6 @@
     'unsharp-mask' => { ui => 1 },
     'van-gogh-lic' => { ui => 1 },
     'warp' => { ui => 1 },
-    'web-browser' => { ui => 1 },
+    'web-browser' => { ui => 1, ldflags => '$(framework_cocoa)', cflags => '$(xobjective_c)' },
     'web-page' => { ui => 1, optional => 1, libs => 'WEBKIT_LIBS', cflags => 'WEBKIT_CFLAGS' }
 );
diff --git a/plug-ins/common/web-browser.c b/plug-ins/common/web-browser.c
index d03c1f7..d26720b 100644
--- a/plug-ins/common/web-browser.c
+++ b/plug-ins/common/web-browser.c
@@ -24,14 +24,19 @@
 
 #include <gtk/gtk.h>
 
+#ifdef PLATFORM_OSX
+#import <Cocoa/Cocoa.h>
+#endif
+
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
 #include <libgimp/gimp.h>
 #include <libgimp/gimpui.h>
 
 #include "libgimp/stdplugins-intl.h"
 
-#ifdef G_OS_WIN32
-#include <windows.h>
-#endif
 
 #define PLUG_IN_PROC   "plug-in-web-browser"
 #define PLUG_IN_BINARY "web-browser"
@@ -122,6 +127,7 @@ browser_open_url (const gchar  *url,
                   GError      **error)
 {
 #ifdef G_OS_WIN32
+
   HINSTANCE hinst = ShellExecute (GetDesktopWindow(),
                                   "open", url, NULL, NULL, SW_SHOW);
 
@@ -180,12 +186,28 @@ browser_open_url (const gchar  *url,
     }
 
   return TRUE;
+
+#elif defined(PLATFORM_OSX)
+
+  NSURL    *ns_url;
+  gboolean  retval;
+
+  @autoreleasepool
+    {
+      ns_url = [NSURL URLWithString: [NSString stringWithUTF8String: url]];
+      retval = [[NSWorkspace sharedWorkspace] openURL: ns_url];
+    }
+
+  return retval;
+
 #else
+
   gimp_ui_init (PLUG_IN_BINARY, FALSE);
 
   return gtk_show_uri (gdk_screen_get_default (),
                        url,
                        gtk_get_current_event_time(),
                        error);
+
 #endif
 }


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