gimpprocbrowser.c 22 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * 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
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
17
18
19
 */

/* 
20
21
22
23
24
 * dbbrowser_utils.c
 * 0.08  26th sept 97  by Thomas NOEL <thomas@minet.net>
 *
 * 98/12/13  Sven Neumann <sven@gimp.org> : added help display
 */
Elliot Lee's avatar
Elliot Lee committed
25

Sven Neumann's avatar
Sven Neumann committed
26
#include "config.h"
27

Daniel Egger's avatar
Daniel Egger committed
28
#include <string.h>
29

30
31
32
33
34
#include <gtk/gtk.h>

#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>

Elliot Lee's avatar
Elliot Lee committed
35
#include "dbbrowser_utils.h"
36

Sven Neumann's avatar
Sven Neumann committed
37
#include "libgimp/stdplugins-intl.h"
Elliot Lee's avatar
Elliot Lee committed
38

39
40

#define DBL_LIST_WIDTH 220
41
#define DBL_WIDTH      (DBL_LIST_WIDTH + 400)
42
#define DBL_HEIGHT     250
43

44
45
46

typedef struct
{
47
  GtkWidget        *dialog;
48

49
50
51
  GtkWidget        *search_entry;
  GtkWidget        *name_button;
  GtkWidget        *blurb_button;
52

53
  GtkWidget        *descr_vbox;
54
  GtkWidget        *description;
55

56
57
58
  GtkListStore     *store;
  GtkWidget        *tv;
  GtkTreeSelection *sel;
59
60

  /* the currently selected procedure */
61
62
63
64
65
66
67
68
69
70
71
72
  gchar            *selected_proc_name;
  gchar            *selected_scheme_proc_name;
  gchar            *selected_proc_blurb;
  gchar            *selected_proc_help;
  gchar            *selected_proc_author;
  gchar            *selected_proc_copyright;
  gchar            *selected_proc_date;
  GimpPDBProcType   selected_proc_type;
  gint              selected_nparams;
  gint              selected_nreturn_vals;
  GimpParamDef     *selected_params;
  GimpParamDef     *selected_return_vals; 
73

74
  GimpDBBrowserApplyCallback apply_callback;
75
76
77
78
} dbbrowser_t;

/* local functions */

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
static void         dialog_apply_callback        (GtkWidget         *widget,
						  dbbrowser_t       *dbbrowser);
static gint         procedure_select_callback    (GtkTreeSelection  *sel,
						  dbbrowser_t       *dbbrowser);
static void         procedure_activated_callback (GtkTreeView       *treeview,
						  GtkTreePath       *path,
						  GtkTreeViewColumn *column,
						  dbbrowser_t       *dbbrowser);
static void         dialog_search_callback       (GtkWidget         *widget, 
						  dbbrowser_t       *dbbrowser);
static void         dialog_select                (dbbrowser_t       *dbbrowser, 
						  gchar             *proc_name);
static void         dialog_close_callback        (GtkWidget         *widget, 
						  dbbrowser_t       *dbbrowser);
static void         convert_string               (gchar             *str);
static const gchar *GParamType2char              (GimpPDBArgType     t);
95
96
97
98
99

/* create the dialog box
 * console_entry != NULL => called from the script-fu-console
 */
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
100
gimp_db_browser (GimpDBBrowserApplyCallback apply_callback)
Elliot Lee's avatar
Elliot Lee committed
101
{
102
  dbbrowser_t *dbbrowser;
103
  GtkWidget   *hpaned;
104
105
106
107
  GtkWidget   *searchhbox;
  GtkWidget   *vbox;
  GtkWidget   *label;
  GtkWidget   *scrolled_window;
108

109
  dbbrowser = g_new0 (dbbrowser_t, 1);
Elliot Lee's avatar
Elliot Lee committed
110
111
112
113
  
  dbbrowser->apply_callback = apply_callback;
  
  /* the dialog box */
114

115
116
  if (apply_callback)
    {
117
118
      dbbrowser->dialog =
	gimp_dialog_new (_("DB Browser"), "dbbrowser",
119
			 gimp_standard_help_func, "filters/dbbrowser.html",
120
121
122
			 GTK_WIN_POS_MOUSE,
			 FALSE, TRUE, FALSE,

123
			 _("Search by _Name"), dialog_search_callback,
124
			 dbbrowser, NULL, &dbbrowser->name_button, TRUE, FALSE,
125
			 _("Search by _Blurb"), dialog_search_callback,
126
			 dbbrowser, NULL, &dbbrowser->blurb_button, FALSE, FALSE,
127
			 GTK_STOCK_APPLY, dialog_apply_callback,
128
			 dbbrowser, NULL, NULL, FALSE, FALSE,
129
			 GTK_STOCK_CLOSE, dialog_close_callback,
130
131
132
133
134
135
			 dbbrowser, NULL, NULL, FALSE, TRUE,

			 NULL);
    }
  else
    {
136
137
      dbbrowser->dialog =
	gimp_dialog_new (_("DB Browser"), "dbbrowser",
138
			 gimp_standard_help_func, "filters/dbbrowser.html",
139
140
141
			 GTK_WIN_POS_MOUSE,
			 FALSE, TRUE, FALSE,

142
			 _("Search by _Name"), dialog_search_callback,
143
			 dbbrowser, NULL, &dbbrowser->name_button, TRUE, FALSE,
144
			 _("Search by _Blurb"), dialog_search_callback,
145
			 dbbrowser, NULL, &dbbrowser->blurb_button, FALSE, FALSE,
146
			 GTK_STOCK_CLOSE, dialog_close_callback,
147
148
149
150
151
			 dbbrowser, NULL, NULL, FALSE, TRUE,

			 NULL);
    }

152
  g_signal_connect (dbbrowser->dialog, "destroy",
153
                    G_CALLBACK (dialog_close_callback), dbbrowser);
Elliot Lee's avatar
Elliot Lee committed
154
  
155
  /* hpaned : left=list ; right=description */
Michael Natterer's avatar
Michael Natterer committed
156

157
  hpaned = gtk_hpaned_new ();
158
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dbbrowser->dialog)->vbox), 
159
160
		      hpaned, TRUE, TRUE, 0);
  gtk_widget_show (hpaned);
161

Elliot Lee's avatar
Elliot Lee committed
162
163
  /* left = vbox : the list and the search entry */
  
Michael Natterer's avatar
Michael Natterer committed
164
  vbox = gtk_vbox_new (FALSE, 4);
165
  gtk_paned_pack1 (GTK_PANED (hpaned), vbox, FALSE, TRUE);
Michael Natterer's avatar
Michael Natterer committed
166
167
  gtk_widget_show (vbox);

Elliot Lee's avatar
Elliot Lee committed
168
169
  /* list : list in a scrolled_win */
  
170
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
171
172
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
				       GTK_SHADOW_IN);
173
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
Michael Natterer's avatar
Michael Natterer committed
174
175
				  GTK_POLICY_AUTOMATIC,
				  GTK_POLICY_ALWAYS);
176
177
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
  gtk_widget_show (scrolled_window);
178

179
  dbbrowser->tv = gtk_tree_view_new ();
180
181
182
183
184
185
186

  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (dbbrowser->tv),
					       -1, NULL,
					       gtk_cell_renderer_text_new (),
					       "text", 0, NULL);
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (dbbrowser->tv), FALSE);

187
188
189
190
  if (apply_callback)
    g_signal_connect (dbbrowser->tv, "row_activated",
                      G_CALLBACK (procedure_activated_callback), dbbrowser);

191
192
193
194
195
  gtk_widget_set_size_request (dbbrowser->tv, DBL_LIST_WIDTH, DBL_HEIGHT);
  gtk_container_add (GTK_CONTAINER (scrolled_window), dbbrowser->tv);
  gtk_widget_show (dbbrowser->tv);

  dbbrowser->sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (dbbrowser->tv));
196
  g_signal_connect (dbbrowser->sel, "changed",
197
		    G_CALLBACK (procedure_select_callback), dbbrowser);
Elliot Lee's avatar
Elliot Lee committed
198
199
200

  /* search entry */

201
202
  searchhbox = gtk_hbox_new (FALSE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), searchhbox, FALSE, FALSE, 2);
203
  gtk_widget_show (searchhbox);
Elliot Lee's avatar
Elliot Lee committed
204

205
206
  label = gtk_label_new_with_mnemonic (_("_Search:"));
  gtk_box_pack_start (GTK_BOX (searchhbox), label, FALSE, FALSE, 2);
207
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
208

209
  dbbrowser->search_entry = gtk_entry_new ();
210
  gtk_entry_set_activates_default (GTK_ENTRY (dbbrowser->search_entry), TRUE);
Michael Natterer's avatar
Michael Natterer committed
211
212
213
  gtk_box_pack_start (GTK_BOX (searchhbox), dbbrowser->search_entry,
		      TRUE, TRUE, 0);
  gtk_widget_show (dbbrowser->search_entry);
Elliot Lee's avatar
Elliot Lee committed
214

215
216
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), dbbrowser->search_entry);

Elliot Lee's avatar
Elliot Lee committed
217
218
  /* right = description */

Michael Natterer's avatar
Michael Natterer committed
219
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
220
  gtk_widget_set_size_request (scrolled_window, DBL_WIDTH - DBL_LIST_WIDTH, -1);
Michael Natterer's avatar
Michael Natterer committed
221
222
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
				  GTK_POLICY_AUTOMATIC, 
223
				  GTK_POLICY_ALWAYS);
224
  gtk_paned_pack2 (GTK_PANED (hpaned), scrolled_window, TRUE, TRUE);
Michael Natterer's avatar
Michael Natterer committed
225
226
227
228
229
230
231
  gtk_widget_show (scrolled_window);

  dbbrowser->descr_vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (dbbrowser->descr_vbox), 4);
  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window),
					 dbbrowser->descr_vbox);
  gtk_widget_show (dbbrowser->descr_vbox);
Elliot Lee's avatar
Elliot Lee committed
232
233
234

  /* now build the list */

235
  gtk_widget_show (dbbrowser->dialog);
Elliot Lee's avatar
Elliot Lee committed
236
237
238

  /* initialize the "return" value (for "apply") */

239
  dbbrowser->description               = NULL;
Michael Natterer's avatar
Michael Natterer committed
240
  dbbrowser->selected_proc_name        = NULL;
Elliot Lee's avatar
Elliot Lee committed
241
  dbbrowser->selected_scheme_proc_name = NULL;
Michael Natterer's avatar
Michael Natterer committed
242
243
244
245
246
247
248
249
250
251
  dbbrowser->selected_proc_blurb       = NULL;
  dbbrowser->selected_proc_help        = NULL;
  dbbrowser->selected_proc_author      = NULL;
  dbbrowser->selected_proc_copyright   = NULL;
  dbbrowser->selected_proc_date        = NULL;
  dbbrowser->selected_proc_type        = 0;
  dbbrowser->selected_nparams          = 0;
  dbbrowser->selected_nreturn_vals     = 0;
  dbbrowser->selected_params           = NULL;
  dbbrowser->selected_return_vals      = NULL;
Elliot Lee's avatar
Elliot Lee committed
252
253

  /* first search (all procedures) */
254
  dialog_search_callback (NULL, dbbrowser);
255

256
  return dbbrowser->dialog;
Elliot Lee's avatar
Elliot Lee committed
257
258
}

259
260
261
262
263
264
265
266
267
static void
procedure_activated_callback (GtkTreeView       *treeview,
			      GtkTreePath       *path,
			      GtkTreeViewColumn *column,
			      dbbrowser_t       *dbbrowser)
{
  dialog_apply_callback (NULL, dbbrowser);
}

Elliot Lee's avatar
Elliot Lee committed
268
static gint
269
270
procedure_select_callback (GtkTreeSelection *sel,
			   dbbrowser_t      *dbbrowser)
Elliot Lee's avatar
Elliot Lee committed
271
{
272
  GtkTreeIter  iter;
Michael Natterer's avatar
Michael Natterer committed
273
  gchar       *func;
Elliot Lee's avatar
Elliot Lee committed
274

275
  g_return_val_if_fail (sel != NULL, FALSE);
Elliot Lee's avatar
Elliot Lee committed
276
  g_return_val_if_fail (dbbrowser != NULL, FALSE);
277

278
279
  if (gtk_tree_selection_get_selected (sel, NULL, &iter))
    {
280
281
282
      gtk_tree_model_get (GTK_TREE_MODEL (dbbrowser->store), &iter,
			  1, &func,
			  -1);
283
284
285
286
      dialog_select (dbbrowser, func);
      g_free (func);
    }

Elliot Lee's avatar
Elliot Lee committed
287
288
289
  return FALSE;
}

290
/* update the description box (right) */
Elliot Lee's avatar
Elliot Lee committed
291
292
293
294
static void 
dialog_select (dbbrowser_t *dbbrowser, 
	       gchar       *proc_name)
{
295
  GtkWidget   *old_description;
296
297
298
299
300
  GtkWidget   *label;
  GtkWidget   *sep;
  gint         i;
  gint         row = 0;
  const gchar *type;
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315

  g_free (dbbrowser->selected_proc_name);
  dbbrowser->selected_proc_name = g_strdup (proc_name);

  g_free (dbbrowser->selected_scheme_proc_name);
  dbbrowser->selected_scheme_proc_name = g_strdup (proc_name);
  convert_string (dbbrowser->selected_scheme_proc_name);

  g_free (dbbrowser->selected_proc_blurb);
  g_free (dbbrowser->selected_proc_help);
  g_free (dbbrowser->selected_proc_author);
  g_free (dbbrowser->selected_proc_copyright);
  g_free (dbbrowser->selected_proc_date);
  g_free (dbbrowser->selected_params);
  g_free (dbbrowser->selected_return_vals);
Elliot Lee's avatar
Elliot Lee committed
316

317
  gimp_procedural_db_proc_info (proc_name, 
318
319
320
321
322
323
324
325
326
327
				&dbbrowser->selected_proc_blurb,
				&dbbrowser->selected_proc_help,
				&dbbrowser->selected_proc_author,
				&dbbrowser->selected_proc_copyright,
				&dbbrowser->selected_proc_date,
				&dbbrowser->selected_proc_type,
				&dbbrowser->selected_nparams,
				&dbbrowser->selected_nreturn_vals,
				&dbbrowser->selected_params,
				&dbbrowser->selected_return_vals);
Michael Natterer's avatar
Michael Natterer committed
328

Elliot Lee's avatar
Elliot Lee committed
329
  /* save the "old" table */
330
  old_description = dbbrowser->description;
Elliot Lee's avatar
Elliot Lee committed
331

332
  dbbrowser->description = gtk_table_new (10 +
Michael Natterer's avatar
Michael Natterer committed
333
334
335
					  dbbrowser->selected_nparams +
					  dbbrowser->selected_nreturn_vals,
					  5, FALSE);
Elliot Lee's avatar
Elliot Lee committed
336

337
338
  gtk_table_set_col_spacings (GTK_TABLE (dbbrowser->description), 6);
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->description), 0, 2);
Elliot Lee's avatar
Elliot Lee committed
339
340
341

  /* show the name */

342
343
344
  label = gtk_label_new (dbbrowser->selected_scheme_proc_name);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_label_set_selectable (GTK_LABEL (label), TRUE);
Elliot Lee's avatar
Elliot Lee committed
345

346
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->description), 0, row++,
Michael Natterer's avatar
Michael Natterer committed
347
			     _("Name:"), 1.0, 0.5,
348
			     label, 3, FALSE);
Elliot Lee's avatar
Elliot Lee committed
349
350
351

  /* show the description */

352
  label = gtk_label_new (dbbrowser->selected_proc_blurb);
Elliot Lee's avatar
Elliot Lee committed
353
354
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

355
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->description), 0, row++,
Michael Natterer's avatar
Michael Natterer committed
356
357
358
359
			     _("Blurb:"), 1.0, 0.5,
			     label, 3, FALSE);

  sep = gtk_hseparator_new ();
360
  gtk_table_attach (GTK_TABLE (dbbrowser->description), sep,
361
		    0, 4, row, row + 1, GTK_FILL, GTK_FILL, 0, 6);
Michael Natterer's avatar
Michael Natterer committed
362
  gtk_widget_show (sep);
Elliot Lee's avatar
Elliot Lee committed
363
364
365
366
367
  row++;

  /* in parameters */
  if (dbbrowser->selected_nparams) 
    {
368
      label = gtk_label_new (_("In:"));
Elliot Lee's avatar
Elliot Lee committed
369
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
370
      gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
Michael Natterer's avatar
Michael Natterer committed
371
372
			0, 1, row, row + (dbbrowser->selected_nparams), 
			GTK_FILL, GTK_FILL, 0, 0);
373
      gtk_widget_show (label);
Michael Natterer's avatar
Michael Natterer committed
374

375
      for (i = 0; i < dbbrowser->selected_nparams; i++) 
Elliot Lee's avatar
Elliot Lee committed
376
377
	{
	  /* name */
378
	  label = gtk_label_new ((dbbrowser->selected_params[i]).name);
Elliot Lee's avatar
Elliot Lee committed
379
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
380
	  gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
381
			    1, 2, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
382
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
383
384

	  /* type */
385
386
	  type = GParamType2char ((dbbrowser->selected_params[i]).type);
	  label = gtk_label_new (type);
Elliot Lee's avatar
Elliot Lee committed
387
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
388
	  gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
389
			    2, 3, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
390
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
391
392

	  /* description */
393
	  label = gtk_label_new ((dbbrowser->selected_params[i]).description);
Elliot Lee's avatar
Elliot Lee committed
394
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
395
	  gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
396
			    3, 4, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
397
	  gtk_widget_show (label);
Michael Natterer's avatar
Michael Natterer committed
398

Elliot Lee's avatar
Elliot Lee committed
399
400
401
	  row++;
	}
    }
402

Elliot Lee's avatar
Elliot Lee committed
403
  if ((dbbrowser->selected_nparams) && 
404
405
      (dbbrowser->selected_nreturn_vals))
    {
Michael Natterer's avatar
Michael Natterer committed
406
      sep = gtk_hseparator_new ();
407
      gtk_table_attach (GTK_TABLE (dbbrowser->description), sep,
408
			0, 4, row, row + 1, GTK_FILL, GTK_FILL, 0, 6);
Michael Natterer's avatar
Michael Natterer committed
409
      gtk_widget_show (sep);
410
411
      row++;
    }
Elliot Lee's avatar
Elliot Lee committed
412
413
414
415

  /* out parameters */
  if (dbbrowser->selected_nreturn_vals)
    {
416
      label = gtk_label_new (_("Out:"));
Elliot Lee's avatar
Elliot Lee committed
417
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
418
      gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
Michael Natterer's avatar
Michael Natterer committed
419
420
			0, 1, row, row + (dbbrowser->selected_nreturn_vals), 
			GTK_FILL, GTK_FILL, 0, 0);
421
      gtk_widget_show (label);
Michael Natterer's avatar
Michael Natterer committed
422

423
      for (i = 0; i < dbbrowser->selected_nreturn_vals; i++) 
Elliot Lee's avatar
Elliot Lee committed
424
425
	{
	  /* name */
426
	  label = gtk_label_new ((dbbrowser->selected_return_vals[i]).name);
Elliot Lee's avatar
Elliot Lee committed
427
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
428
	  gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
429
			    1, 2, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
430
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
431
432

	  /* type */
433
434
	  type = GParamType2char (dbbrowser->selected_return_vals[i].type);
	  label = gtk_label_new (type);
Elliot Lee's avatar
Elliot Lee committed
435
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
436
	  gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
437
			    2, 3, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
438
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
439
440

	  /* description */
Michael Natterer's avatar
Michael Natterer committed
441
	  label = gtk_label_new (dbbrowser->selected_return_vals[i].description);
Elliot Lee's avatar
Elliot Lee committed
442
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
443
	  gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
444
			    3, 4, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
445
	  gtk_widget_show (label);
Michael Natterer's avatar
Michael Natterer committed
446

Elliot Lee's avatar
Elliot Lee committed
447
448
449
450
	  row++;
	}
    }

Michael Natterer's avatar
Michael Natterer committed
451
452
  if (dbbrowser->selected_nparams || 
      dbbrowser->selected_nreturn_vals)
453
    {
Michael Natterer's avatar
Michael Natterer committed
454
      sep = gtk_hseparator_new ();
455
      gtk_table_attach (GTK_TABLE (dbbrowser->description), sep,
456
			0, 4, row, row + 1, GTK_FILL, GTK_FILL, 0, 6);
Michael Natterer's avatar
Michael Natterer committed
457
458
459
      gtk_widget_show (sep);
      row++;
    }
Elliot Lee's avatar
Elliot Lee committed
460

Sven Neumann's avatar
Sven Neumann committed
461
  /* show the help */
Michael Natterer's avatar
Michael Natterer committed
462
  if (dbbrowser->selected_proc_help &&
463
      (strlen (dbbrowser->selected_proc_help) > 1))
Sven Neumann's avatar
Sven Neumann committed
464
    {
465
466
467
      label = gtk_label_new (dbbrowser->selected_proc_help);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
Michael Natterer's avatar
Michael Natterer committed
468

469
      gimp_table_attach_aligned (GTK_TABLE (dbbrowser->description), 0, row++,
Michael Natterer's avatar
Michael Natterer committed
470
				 _("Help:"), 1.0, 0.5,
471
				 label, 3, FALSE);
Michael Natterer's avatar
Michael Natterer committed
472
473

      sep = gtk_hseparator_new ();
474
      gtk_table_attach (GTK_TABLE (dbbrowser->description), sep,
475
			0, 4, row, row + 1, GTK_FILL, GTK_FILL, 0, 6);
Michael Natterer's avatar
Michael Natterer committed
476
      gtk_widget_show (sep);
477

Sven Neumann's avatar
Sven Neumann committed
478
479
480
481
482
      row++;
    }

  /* show the author & the copyright */

483
  label = gtk_label_new (dbbrowser->selected_proc_author);
Elliot Lee's avatar
Elliot Lee committed
484
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
485

486
487
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->description), row, 2);
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->description), 0, row++,
Michael Natterer's avatar
Michael Natterer committed
488
489
			     _("Author:"), 1.0, 0.5,
			     label, 3, FALSE);
Elliot Lee's avatar
Elliot Lee committed
490

491
  label = gtk_label_new (dbbrowser->selected_proc_date);
Elliot Lee's avatar
Elliot Lee committed
492
493
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

494
495
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->description), row, 2);
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->description), 0, row++,
Michael Natterer's avatar
Michael Natterer committed
496
497
			     _("Date:"), 1.0, 0.5,
			     label, 3, FALSE);
Elliot Lee's avatar
Elliot Lee committed
498

499
  label = gtk_label_new (dbbrowser->selected_proc_copyright);
Elliot Lee's avatar
Elliot Lee committed
500
501
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

502
503
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->description), row, 2);
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->description), 0, row++,
Michael Natterer's avatar
Michael Natterer committed
504
505
			     _("Copyright:"), 1.0, 0.5,
			     label, 3, FALSE);
Elliot Lee's avatar
Elliot Lee committed
506

507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
  if (old_description)
    gtk_container_remove (GTK_CONTAINER (dbbrowser->descr_vbox),
                          old_description);

  gtk_box_pack_start (GTK_BOX (dbbrowser->descr_vbox),
                      dbbrowser->description, FALSE, FALSE, 0);
  gtk_widget_show (dbbrowser->description);
}

static void
dialog_show_message (dbbrowser_t *dbbrowser,
                     const gchar *message)
{
  if (dbbrowser->description && GTK_IS_LABEL (dbbrowser->description))
    {
      gtk_label_set_text (GTK_LABEL (dbbrowser->description), message);
    }
  else
    {
      if (dbbrowser->description)
        gtk_container_remove (GTK_CONTAINER (dbbrowser->descr_vbox),
                              dbbrowser->description);
529

530
531
532
533
534
      dbbrowser->description = gtk_label_new (message);
      gtk_box_pack_start (GTK_BOX (dbbrowser->descr_vbox),
                          dbbrowser->description, FALSE, FALSE, 0);
      gtk_widget_show (dbbrowser->description);
    }
Sven Neumann's avatar
Sven Neumann committed
535

536
537
  while (gtk_events_pending ())
    gtk_main_iteration ();
Elliot Lee's avatar
Elliot Lee committed
538
539
}

540
/* end of the dialog */
Elliot Lee's avatar
Elliot Lee committed
541
static void
542
543
dialog_close_callback (GtkWidget   *widget, 
		       dbbrowser_t *dbbrowser)
Elliot Lee's avatar
Elliot Lee committed
544
{
545
546
  if (dbbrowser->apply_callback)
    {
547
548
      /* we are called by another application : just destroy the dialog box */
      gtk_widget_destroy (dbbrowser->dialog);
549
550
551
552
553
554
    }
  else
    {
      /* we are in the plug_in : kill the gtk application */
      gtk_main_quit ();
    }
Manish Singh's avatar
Manish Singh committed
555
}
Elliot Lee's avatar
Elliot Lee committed
556

557
/* end of the dialog */
Elliot Lee's avatar
Elliot Lee committed
558
static void 
559
560
dialog_apply_callback (GtkWidget   *widget, 
		       dbbrowser_t *dbbrowser)
Elliot Lee's avatar
Elliot Lee committed
561
{
562
  (dbbrowser->apply_callback) (dbbrowser->selected_proc_name,
Elliot Lee's avatar
Elliot Lee committed
563
564
565
566
567
568
569
570
571
572
			       dbbrowser->selected_scheme_proc_name,
			       dbbrowser->selected_proc_blurb,
			       dbbrowser->selected_proc_help,
			       dbbrowser->selected_proc_author,
			       dbbrowser->selected_proc_copyright,
			       dbbrowser->selected_proc_date,
			       dbbrowser->selected_proc_type,
			       dbbrowser->selected_nparams,
			       dbbrowser->selected_nreturn_vals,
			       dbbrowser->selected_params,
573
			       dbbrowser->selected_return_vals);
Elliot Lee's avatar
Elliot Lee committed
574
575
}

576
/* search in the whole db */
Elliot Lee's avatar
Elliot Lee committed
577
static void 
578
579
dialog_search_callback (GtkWidget   *widget, 
		        dbbrowser_t *dbbrowser)
Elliot Lee's avatar
Elliot Lee committed
580
{
Michael Natterer's avatar
Michael Natterer committed
581
582
  gchar       **proc_list;
  gint          num_procs;
583
  gint          i;
Michael Natterer's avatar
Michael Natterer committed
584
  gchar        *label;
585
  const gchar  *query_text;
Michael Natterer's avatar
Michael Natterer committed
586
  GString      *query;
587
  GtkTreeIter   iter;
Elliot Lee's avatar
Elliot Lee committed
588

589
  gtk_tree_view_set_model (GTK_TREE_VIEW (dbbrowser->tv), NULL);
Elliot Lee's avatar
Elliot Lee committed
590
591
592

  /* search */

593
  if (widget == dbbrowser->name_button)
Elliot Lee's avatar
Elliot Lee committed
594
    {
595
      dialog_show_message (dbbrowser, _("Searching by name - please wait"));
596
597

      query = g_string_new ("");
598
      query_text = gtk_entry_get_text (GTK_ENTRY (dbbrowser->search_entry));
599
600
601
602
603
604
605
606
607
608
609

      while (*query_text)
	{
	  if ((*query_text == '_') || (*query_text == '-'))
	    g_string_append (query, "[-_]");
	  else
	    g_string_append_c (query, *query_text);

	  query_text++;
	}

Daniel Egger's avatar
Daniel Egger committed
610
611
612
      gimp_procedural_db_query (query->str,
			        ".*", ".*", ".*", ".*", ".*", ".*", 
			        &num_procs, &proc_list);
613
614

      g_string_free (query, TRUE);
Elliot Lee's avatar
Elliot Lee committed
615
    }
616
  else if (widget == dbbrowser->blurb_button)
Elliot Lee's avatar
Elliot Lee committed
617
    {
618
619
      dialog_show_message (dbbrowser, _("Searching by blurb - please wait"));

Daniel Egger's avatar
Daniel Egger committed
620
      gimp_procedural_db_query (".*", 
621
622
			        (gchar *) gtk_entry_get_text
				  (GTK_ENTRY (dbbrowser->search_entry)),
Daniel Egger's avatar
Daniel Egger committed
623
624
			        ".*", ".*", ".*", ".*", ".*",
			        &num_procs, &proc_list);
Elliot Lee's avatar
Elliot Lee committed
625
    }
626
627
  else
    {
628
      dialog_show_message (dbbrowser, _("Searching - please wait"));
629

Daniel Egger's avatar
Daniel Egger committed
630
631
      gimp_procedural_db_query (".*", ".*", ".*", ".*", ".*", ".*", ".*", 
			        &num_procs, &proc_list);
632
    }
Elliot Lee's avatar
Elliot Lee committed
633

634
635
636
637
  dbbrowser->store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
  gtk_tree_view_set_model (GTK_TREE_VIEW (dbbrowser->tv),
                           GTK_TREE_MODEL (dbbrowser->store));
  g_object_unref (dbbrowser->store);
638

639
640
641
642
  for (i = 0; i < num_procs; i++)
    {
      label = g_strdup (proc_list[i]);
      convert_string (label);
643
644
645
646
647
648
649
      gtk_list_store_append (dbbrowser->store, &iter);
      gtk_list_store_set (dbbrowser->store, &iter,
			  0, label,
			  1, proc_list[i],
			  -1);
      g_free (label);
      g_free (proc_list[i]);
650
    }
651

652
  g_free (proc_list);
Elliot Lee's avatar
Elliot Lee committed
653

654
  /* now sort the store */ 
655
656
  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dbbrowser->store),
                                        0, GTK_SORT_ASCENDING);
657
  
658
  if (num_procs > 0)
659
    {
660
      gtk_tree_model_get_iter_root (GTK_TREE_MODEL (dbbrowser->store), &iter);
661
      gtk_tree_selection_select_iter (dbbrowser->sel, &iter);
662
    }
663
664
665
666
  else
    {
      dialog_show_message (dbbrowser, _("No matches"));
    }
Elliot Lee's avatar
Elliot Lee committed
667
668
669
670
671
}

/* utils ... */

static void 
672
convert_string (gchar *str)
Elliot Lee's avatar
Elliot Lee committed
673
674
675
{
  while (*str)
    {
676
677
678
      if (*str == '_')
	*str = '-';

Elliot Lee's avatar
Elliot Lee committed
679
680
681
682
      str++;
    }
}

683
static const gchar * 
Daniel Egger's avatar
Daniel Egger committed
684
GParamType2char (GimpPDBArgType t)
Elliot Lee's avatar
Elliot Lee committed
685
{
686
687
  switch (t)
    {
688
689
690
691
692
693
694
695
696
    case GIMP_PDB_INT32:       return "INT32";
    case GIMP_PDB_INT16:       return "INT16";
    case GIMP_PDB_INT8:        return "INT8";
    case GIMP_PDB_FLOAT:       return "FLOAT";
    case GIMP_PDB_STRING:      return "STRING";
    case GIMP_PDB_INT32ARRAY:  return "INT32ARRAY";
    case GIMP_PDB_INT16ARRAY:  return "INT16ARRAY";
    case GIMP_PDB_INT8ARRAY:   return "INT8ARRAY";
    case GIMP_PDB_FLOATARRAY:  return "FLOATARRAY";
Daniel Egger's avatar
Daniel Egger committed
697
    case GIMP_PDB_STRINGARRAY: return "STRINGARRAY";
698
699
700
701
702
703
704
705
706
707
708
709
710
711
    case GIMP_PDB_COLOR:       return "COLOR";
    case GIMP_PDB_REGION:      return "REGION";
    case GIMP_PDB_DISPLAY:     return "DISPLAY";
    case GIMP_PDB_IMAGE:       return "IMAGE";
    case GIMP_PDB_LAYER:       return "LAYER";
    case GIMP_PDB_CHANNEL:     return "CHANNEL";
    case GIMP_PDB_DRAWABLE:    return "DRAWABLE";
    case GIMP_PDB_SELECTION:   return "SELECTION";
    case GIMP_PDB_BOUNDARY:    return "BOUNDARY";
    case GIMP_PDB_PATH:        return "PATH";
    case GIMP_PDB_PARASITE:    return "PARASITE";
    case GIMP_PDB_STATUS:      return "STATUS";
    case GIMP_PDB_END:         return "END";
    default:                   return "UNKNOWN?";
712
    }
Elliot Lee's avatar
Elliot Lee committed
713
}