home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / app / gimphelp.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-19  |  6.9 KB  |  287 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  4.  * gimphelp.c
  5.  * Copyright (C) 1999-2000 Michael Natterer <mitch@gimp.org>
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20.  */
  21. #include "config.h"
  22.  
  23. #ifdef HAVE_UNISTD_H
  24. #include <unistd.h>
  25. #endif
  26. #ifdef HAVE_STRING_H
  27. #include <string.h>
  28. #endif
  29.  
  30. #include <gtk/gtk.h>
  31.  
  32. #include "gimphelp.h"
  33. #include "gimprc.h"
  34. #include "gimpui.h"
  35. #include "plug_in.h"
  36. #include "procedural_db.h"
  37.  
  38. #include "libgimp/gimpenv.h"
  39.  
  40. #include "libgimp/gimpintl.h"
  41.  
  42.  
  43. #ifndef G_OS_WIN32
  44. #define DEBUG_HELP
  45. #endif
  46.  
  47. typedef struct _GimpIdleHelp GimpIdleHelp;
  48.  
  49. struct _GimpIdleHelp
  50. {
  51.   gchar *help_path;
  52.   gchar *help_data;
  53. };
  54.  
  55. /*  local function prototypes  */
  56. static gint      gimp_idle_help     (gpointer     data);
  57. static gboolean  gimp_help_internal (const gchar *help_path,
  58.                      const gchar *current_locale,
  59.                      const gchar *help_data);
  60. static void      gimp_help_netscape (const gchar *help_path,
  61.                      const gchar *current_locale,
  62.                      const gchar *help_data);
  63.  
  64. /**********************/
  65. /*  public functions  */
  66. /**********************/
  67.  
  68. /*  The standard help function  */
  69. void
  70. gimp_standard_help_func (const gchar *help_data)
  71. {
  72.   gimp_help (NULL, help_data);
  73. }
  74.  
  75. /*  the main help function  */
  76. void
  77. gimp_help (const gchar *help_path,
  78.        const gchar *help_data)
  79. {
  80.   if (use_help)
  81.     {
  82.       GimpIdleHelp *idle_help;
  83.  
  84.       idle_help = g_new0 (GimpIdleHelp, 1);
  85.  
  86.       if (help_path && strlen (help_path))
  87.     idle_help->help_path = g_strdup (help_path);
  88.  
  89.       if (help_data && strlen (help_data))
  90.     idle_help->help_data = g_strdup (help_data);
  91.  
  92.       gtk_idle_add ((GtkFunction) gimp_idle_help, (gpointer) idle_help);
  93.     }
  94. }
  95.  
  96. /*********************/
  97. /*  local functions  */
  98. /*********************/
  99.  
  100. static gint
  101. gimp_idle_help (gpointer data)
  102. {
  103.   GimpIdleHelp *idle_help;
  104.   static gchar *current_locale = "C";
  105.  
  106.   idle_help = (GimpIdleHelp *) data;
  107.  
  108.   if (idle_help->help_data == NULL && help_browser != HELP_BROWSER_GIMP)
  109.     idle_help->help_data = g_strdup ("welcome.html");
  110.  
  111. #ifdef DEBUG_HELP
  112.   if (idle_help->help_path)
  113.     g_print ("Help Path: %s\n", idle_help->help_path);
  114.   else
  115.     g_print ("Help Path: NULL\n");
  116.  
  117.   if (idle_help->help_data)
  118.     g_print ("Help Page: %s\n", idle_help->help_data);
  119.   else
  120.     g_print ("Help Page: NULL\n");
  121.  
  122.   g_print ("\n");
  123. #endif  /*  DEBUG_HELP  */
  124.  
  125.   switch (help_browser)
  126.     {
  127.     case HELP_BROWSER_GIMP:
  128.       if (gimp_help_internal (idle_help->help_path,
  129.                   current_locale,
  130.                   idle_help->help_data))
  131.     break;
  132.  
  133.     case HELP_BROWSER_NETSCAPE:
  134.       gimp_help_netscape (idle_help->help_path,
  135.               current_locale,
  136.               idle_help->help_data);
  137.       break;
  138.  
  139.     default:
  140.       break;
  141.     }
  142.  
  143.   if (idle_help->help_path)
  144.     g_free (idle_help->help_path);
  145.   if (idle_help->help_data)
  146.     g_free (idle_help->help_data);
  147.   g_free (idle_help);
  148.  
  149.   return FALSE;
  150. }
  151.  
  152. static void
  153. gimp_help_internal_not_found_callback (GtkWidget *widget,
  154.                        gboolean   use_netscape,
  155.                        gpointer   data)
  156. {
  157.   GList *update = NULL;
  158.   GList *remove = NULL;
  159.  
  160.   if (use_netscape)
  161.     {
  162.       help_browser = HELP_BROWSER_NETSCAPE;
  163.  
  164.       update = g_list_append (update, "help-browser");
  165.       save_gimprc (&update, &remove);
  166.     }
  167.   
  168.   gtk_main_quit ();
  169. }
  170.  
  171. static gboolean
  172. gimp_help_internal (const gchar *help_path,
  173.             const gchar *current_locale,
  174.             const gchar *help_data)
  175. {
  176.   ProcRecord *proc_rec;
  177.  
  178.   /*  Check if a help browser is already running  */
  179.   proc_rec = procedural_db_lookup ("extension_gimp_help_browser_temp");
  180.  
  181.   if (proc_rec == NULL)
  182.     {
  183.       Argument *args = NULL;
  184.  
  185.       proc_rec = procedural_db_lookup ("extension_gimp_help_browser");
  186.  
  187.       if (proc_rec == NULL)
  188.     {
  189.       GtkWidget *not_found =
  190.         gimp_query_boolean_box (_("Could not find GIMP Help Browser"),
  191.                     NULL, NULL, FALSE,
  192.                     _("Could not find the GIMP Help Browser procedure.\n"
  193.                       "It probably was not compiled because\n"
  194.                       "you don't have GtkXmHTML installed."),
  195.                     _("Use Netscape instead"),
  196.                     _("Cancel"), 
  197.                     NULL, NULL,
  198.                     gimp_help_internal_not_found_callback,
  199.                     NULL);
  200.       gtk_widget_show (not_found);
  201.       gtk_main ();
  202.       
  203.       return (help_browser != HELP_BROWSER_NETSCAPE);
  204.     }
  205.  
  206.       args = g_new (Argument, 4);
  207.       args[0].arg_type = PDB_INT32;
  208.       args[0].value.pdb_int = RUN_INTERACTIVE;
  209.       args[1].arg_type = PDB_STRING;
  210.       args[1].value.pdb_pointer = (gpointer) help_path;
  211.       args[2].arg_type = PDB_STRING;
  212.       args[2].value.pdb_pointer = (gpointer) current_locale;
  213.       args[3].arg_type = PDB_STRING;
  214.       args[3].value.pdb_pointer = (gpointer) help_data;
  215.  
  216.       plug_in_run (proc_rec, args, 4, FALSE, TRUE, 0);
  217.  
  218.       g_free (args);
  219.     }
  220.   else
  221.     {
  222.       Argument *return_vals;
  223.       gint      nreturn_vals;
  224.  
  225.       return_vals =
  226.         procedural_db_run_proc ("extension_gimp_help_browser_temp",
  227.                                 &nreturn_vals,
  228.                 PDB_STRING, help_path,
  229.                 PDB_STRING, current_locale,
  230.                                 PDB_STRING, help_data,
  231.                                 PDB_END);
  232.  
  233.       procedural_db_destroy_args (return_vals, nreturn_vals);
  234.     }
  235.  
  236.   return TRUE;
  237. }
  238.  
  239. static void
  240. gimp_help_netscape (const gchar *help_path,
  241.             const gchar *current_locale,
  242.             const gchar *help_data)
  243. {
  244.   Argument *return_vals;
  245.   gint      nreturn_vals;
  246.   gchar    *url;
  247.  
  248.   if (help_data[0] == '/')  /* _not_ g_path_is_absolute() */
  249.     {
  250.       url = g_strconcat ("file:",
  251.              help_data,
  252.              NULL);
  253.     }
  254.   else
  255.     {
  256.       if (!help_path)
  257.     {
  258.       url = g_strconcat ("file:",
  259.                  gimp_data_directory (),
  260.                  "/help/",
  261.                  current_locale, "/",
  262.                  help_data,
  263.                  NULL);
  264.     }
  265.       else
  266.     {
  267.       url = g_strconcat ("file:",
  268.                  help_path, "/",
  269.                  current_locale, "/",
  270.                  help_data,
  271.                  NULL);
  272.     }
  273.     }
  274.  
  275.   return_vals =
  276.     procedural_db_run_proc ("extension_web_browser",
  277.                 &nreturn_vals,
  278.                 PDB_INT32,  RUN_NONINTERACTIVE,
  279.                 PDB_STRING, url,
  280.                 PDB_INT32,  FALSE,
  281.                 PDB_END);
  282.  
  283.   procedural_db_destroy_args (return_vals, nreturn_vals);
  284.  
  285.   g_free (url);
  286. }
  287.