File: gimphelp.c

package info (click to toggle)
gimp 2.2.13-1etch4
  • links: PTS
  • area: main
  • in suites: etch
  • size: 94,832 kB
  • ctags: 47,113
  • sloc: ansic: 524,858; xml: 36,798; lisp: 9,870; sh: 9,409; makefile: 7,923; python: 2,674; perl: 2,589; yacc: 520; lex: 334
file content (354 lines) | stat: -rw-r--r-- 10,001 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * gimphelp.c
 * Copyright (C) 1999-2004 Michael Natterer <mitch@gimp.org>
 *                         Henrik Brix Andersen <brix@gimp.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include "config.h"

#include <string.h>

#include <gtk/gtk.h>

#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"

#include "widgets-types.h"

#include "config/gimpguiconfig.h"

#include "core/gimp.h"
#include "core/gimp-utils.h"

#include "pdb/procedural_db.h"

#include "plug-in/plug-ins.h"
#include "plug-in/plug-in-run.h"

#include "gimphelp.h"
#include "gimphelp-ids.h"
#include "gimpmessagebox.h"
#include "gimpmessagedialog.h"

#include "gimp-intl.h"


/*  #define GIMP_HELP_DEBUG  */


typedef struct _GimpIdleHelp GimpIdleHelp;

struct _GimpIdleHelp
{
  Gimp  *gimp;
  gchar *help_domain;
  gchar *help_locales;
  gchar *help_id;
};


/*  local function prototypes  */

static gint      gimp_idle_help          (gpointer       data);

static gboolean  gimp_help_browser       (Gimp          *gimp);
static void      gimp_help_browser_error (Gimp          *gimp,
                                          const gchar   *title,
                                          const gchar   *primary,
                                          const gchar   *text);

static void      gimp_help_call          (Gimp          *gimp,
                                          const gchar   *procedure,
                                          const gchar   *help_domain,
                                          const gchar   *help_locales,
                                          const gchar   *help_id);
static gchar *   gimp_help_get_locales   (GimpGuiConfig *config);


/*  public functions  */

void
gimp_help_show (Gimp        *gimp,
                const gchar *help_domain,
                const gchar *help_id)
{
  GimpGuiConfig *config;

  g_return_if_fail (GIMP_IS_GIMP (gimp));

  config = GIMP_GUI_CONFIG (gimp->config);

  if (config->use_help)
    {
      GimpIdleHelp *idle_help = g_new0 (GimpIdleHelp, 1);

      idle_help->gimp = gimp;

      if (help_domain && strlen (help_domain))
	idle_help->help_domain = g_strdup (help_domain);

      idle_help->help_locales = gimp_help_get_locales (config);

      if (help_id && strlen (help_id))
	idle_help->help_id = g_strdup (help_id);

      g_idle_add (gimp_idle_help, idle_help);

      if (gimp->be_verbose)
        g_print ("HELP: request for help-id '%s' from help-domain '%s'\n",
                 help_id     ? help_id      : "(null)",
                 help_domain ? help_domain  : "(null)");
    }
}


/*  private functions  */

static gboolean
gimp_idle_help (gpointer data)
{
  GimpIdleHelp  *idle_help = data;
  GimpGuiConfig *config    = GIMP_GUI_CONFIG (idle_help->gimp->config);
  const gchar   *procedure = NULL;

#ifdef GIMP_HELP_DEBUG
  g_printerr ("Help Domain: %s\n",
              idle_help->help_domain ? idle_help->help_domain : "NULL");
  g_printerr ("Help ID: %s\n\n",
              idle_help->help_id     ? idle_help->help_id     : "NULL");
#endif

  if (config->help_browser == GIMP_HELP_BROWSER_GIMP)
    {
      if (gimp_help_browser (idle_help->gimp))
        procedure = "extension_gimp_help_browser_temp";
    }

  if (config->help_browser == GIMP_HELP_BROWSER_WEB_BROWSER)
    {
      /*  FIXME: should check for procedure availability  */
      procedure = "plug_in_web_browser";
    }

  if (procedure)
    gimp_help_call (idle_help->gimp,
                    procedure,
                    idle_help->help_domain,
                    idle_help->help_locales,
                    idle_help->help_id);

  g_free (idle_help->help_domain);
  g_free (idle_help->help_locales);
  g_free (idle_help->help_id);
  g_free (idle_help);

  return FALSE;
}

static gboolean
gimp_help_browser (Gimp *gimp)
{
  static gboolean  busy = FALSE;
  ProcRecord      *proc_rec;

  if (busy)
    return TRUE;

  busy = TRUE;

  /*  Check if a help browser is already running  */
  proc_rec = procedural_db_lookup (gimp, "extension_gimp_help_browser_temp");

  if (! proc_rec)
    {
      Argument *args = NULL;

      proc_rec = procedural_db_lookup (gimp, "extension_gimp_help_browser");

      if (! proc_rec)
	{
          gimp_help_browser_error (gimp,
                                   _("Help browser not found"),
                                   _("Could not find GIMP help browser."),
                                   _("The GIMP help browser plug-in appears "
                                     "to be missing from your installation."));
          busy = FALSE;

	  return FALSE;
	}

      args = g_new (Argument, 1);

      args[0].arg_type      = GIMP_PDB_INT32;
      args[0].value.pdb_int = GIMP_RUN_INTERACTIVE;

      plug_in_run (gimp, gimp_get_user_context (gimp), NULL,
                   proc_rec, args, 1, FALSE, TRUE, -1);

      procedural_db_destroy_args (args, 1);
    }

  /*  Check if the help browser started properly  */
  proc_rec = procedural_db_lookup (gimp, "extension_gimp_help_browser_temp");

  if (! proc_rec)
    {
      gimp_help_browser_error (gimp,
                               _("Help browser doesn't start"),
                               _("Could not start the GIMP help browser plug-in."),
                               NULL);
      busy = FALSE;

      return FALSE;
    }

  busy = FALSE;

  return TRUE;
}

static void
gimp_help_browser_error (Gimp        *gimp,
                         const gchar *title,
                         const gchar *primary,
                         const gchar *text)
{
  GtkWidget *dialog;

  dialog =
    gimp_message_dialog_new (title, GIMP_STOCK_WARNING,
                             NULL, 0,
                             NULL, NULL,

                             GTK_STOCK_CANCEL,              GTK_RESPONSE_CANCEL,
                             _("Use _web browser instead"), GTK_RESPONSE_OK,

                             NULL);

  gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (dialog)->box, primary);
  gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (dialog)->box, text);

  if (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK)
    g_object_set (gimp->config,
		  "help-browser", GIMP_HELP_BROWSER_WEB_BROWSER,
		  NULL);

  gtk_widget_destroy (dialog);
}

static void
gimp_help_call (Gimp        *gimp,
                const gchar *procedure,
                const gchar *help_domain,
                const gchar *help_locales,
                const gchar *help_id)
{
  ProcRecord *proc_rec;

  /*  Check if a help parser is already running  */
  proc_rec = procedural_db_lookup (gimp, "extension_gimp_help_temp");

  if (! proc_rec)
    {
      Argument  *args         = NULL;
      gint       n_domains    = 0;
      gchar    **help_domains = NULL;
      gchar    **help_uris    = NULL;

      proc_rec = procedural_db_lookup (gimp, "extension_gimp_help");

      if (! proc_rec)
        /*  FIXME: error msg  */
        return;

      n_domains = plug_ins_help_domains (gimp, &help_domains, &help_uris);

      args = g_new (Argument, 4);

      args[0].arg_type          = GIMP_PDB_INT32;
      args[0].value.pdb_int     = n_domains;
      args[1].arg_type          = GIMP_PDB_STRINGARRAY;
      args[1].value.pdb_pointer = help_domains;
      args[2].arg_type          = GIMP_PDB_INT32;
      args[2].value.pdb_int     = n_domains;
      args[3].arg_type          = GIMP_PDB_STRINGARRAY;
      args[3].value.pdb_pointer = help_uris;

      plug_in_run (gimp, gimp_get_user_context (gimp), NULL,
                   proc_rec, args, 4, FALSE, TRUE, -1);

      procedural_db_destroy_args (args, 4);
    }

  /*  Check if the help parser started properly  */
  proc_rec = procedural_db_lookup (gimp, "extension_gimp_help_temp");

  if (proc_rec)
    {
      Argument *return_vals;
      gint      n_return_vals;

#ifdef GIMP_HELP_DEBUG
      g_printerr ("Calling help via %s: %s %s %s\n",
                  procedure,
                  help_domain  ? help_domain  : "(null)",
                  help_locales ? help_locales : "(null)",
                  help_id      ? help_id      : "(null)");
#endif

      return_vals =
        procedural_db_run_proc (gimp,
                                gimp_get_user_context (gimp),
                                NULL,
				"extension_gimp_help_temp",
                                &n_return_vals,
                                GIMP_PDB_STRING, procedure,
				GIMP_PDB_STRING, help_domain,
				GIMP_PDB_STRING, help_locales,
                                GIMP_PDB_STRING, help_id,
                                GIMP_PDB_END);

      procedural_db_destroy_args (return_vals, n_return_vals);
    }
}

static gchar *
gimp_help_get_locales (GimpGuiConfig *config)
{
  const gchar *language;
  gchar       *locale;

  if (config->help_locales && strlen (config->help_locales))
    return g_strdup (config->help_locales);

  locale = gimp_get_default_language ("LC_MESSAGES");

  /*  Simulate the behaviour of GNU gettext() and look
   *  at LANGUAGE if the locale is not the "C" locale.
   */
  language = g_getenv ("LANGUAGE");
  if (language && (locale == NULL || strcmp (locale, "C")))
    {
      g_free (locale);
      locale = g_strdup (language);
    }

  return locale;
}