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



commit 03d99ae2e3cbc9d0c7fd805f469b73fba89c5465
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)
    
    (cherry picked and quite modified from commit
     308efbb51401ef2a1032619c335e56150587f227)
    
    This partly revert commit 863bd791ae94c4abbf29c50f1bec79d71e2d7fd1
    which should not have gone in as-is.

 app/dialogs/preferences-dialog.c |  147 ++++++++++++++++++++++++--------------
 app/widgets/gimphelp.c           |   14 ++++-
 app/widgets/gimphelp.h           |    4 +
 plug-ins/common/Makefile.am      |   11 +++
 plug-ins/common/mkgen.pl         |   16 ++++-
 plug-ins/common/plugin-defs.pl   |    2 +-
 plug-ins/common/web-browser.c    |   28 +++++++-
 7 files changed, 161 insertions(+), 61 deletions(-)
---
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index d409709..9b95c2b 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -34,8 +34,6 @@
 #include "core/gimplist.h"
 #include "core/gimptemplate.h"
 
-#include "pdb/gimppdb.h"
-
 #include "widgets/gimpcolorpanel.h"
 #include "widgets/gimpcontainercombobox.h"
 #include "widgets/gimpcontainerview.h"
@@ -293,6 +291,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);
@@ -1034,6 +1040,35 @@ prefs_profile_combo_box_new (Gimp         *gimp,
 }
 
 static GtkWidget *
+prefs_hint_box_new (const gchar  *stock_id,
+                    const gchar  *text)
+{
+  GtkWidget *hbox;
+  GtkWidget *image;
+  GtkWidget *label;
+
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+
+  image = gtk_image_new_from_stock (stock_id, 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 *stock_id,
                   const gchar *label,
                   GtkBox      *box)
@@ -1792,62 +1827,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_stock (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  */
-  if (gimp_pdb_lookup_procedure (gimp->pdb,
-                                 "extension-gimp-help-browser")) {
-    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);
-  }
+#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);
+
+  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 */
 
   g_object_unref (size_group);
   size_group = NULL;
diff --git a/app/widgets/gimphelp.c b/app/widgets/gimphelp.c
index a995706..229cd65 100644
--- a/app/widgets/gimphelp.c
+++ b/app/widgets/gimphelp.c
@@ -141,6 +141,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)
 {
   gchar    *basedir;
@@ -340,7 +351,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 ac40506..15512df 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
@@ -2599,6 +2604,7 @@ warp_LDADD = \
        $(INTLLIBS)             \
        $(warp_RC)
 
+<<<<<<< HEAD
 waves_SOURCES = \
        waves.c
 
@@ -2615,6 +2621,11 @@ waves_LDADD = \
        $(RT_LIBS)              \
        $(INTLLIBS)             \
        $(waves_RC)
+=======
+web_browser_LDFLAGS = $(framework_cocoa)
+
+web_browser_CFLAGS = $(xobjective_c)
+>>>>>>> 308efbb... Bug 767830 - Help browser does not launch on OS X
 
 web_browser_SOURCES = \
        web-browser.c
diff --git a/plug-ins/common/mkgen.pl b/plug-ins/common/mkgen.pl
index 060e741..cee5033 100755
--- a/plug-ins/common/mkgen.pl
+++ b/plug-ins/common/mkgen.pl
@@ -18,7 +18,7 @@ open MK, "> $outmk";
 open IGNORE, "> $outignore";
 open RC, "> $outrc";
 
-require 'plugin-defs.pl';
+require './plugin-defs.pl';
 
 $bins = ""; $opts = "";
 
@@ -61,6 +61,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
@@ -150,6 +155,15 @@ foreach (sort keys %plugins) {
        }
     }
 
+    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 f623235..d1e0356 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -140,7 +140,7 @@
     'video' => { ui => 1 },
     'warp' => { ui => 1 },
     'waves' => { 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' },
     'whirl-pinch' => { ui => 1 },
     'wind' => { ui => 1 }
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]