gimpprocbrowser.c 21.2 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    *dlg;
48

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

53
54
  GtkWidget        *descr_vbox;
  GtkWidget        *descr_table;
55

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

  /* the currently selected procedure */
62
63
64
65
66
67
68
69
70
71
72
73
  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; 
74
75
76
77
78
79
80
81
82
83
84
85
86

  void (* apply_callback) (gchar           *proc_name,
			   gchar           *scheme_proc_name,
			   gchar           *proc_blurb,
			   gchar           *proc_help,
			   gchar           *proc_author,
			   gchar           *proc_copyright,
			   gchar           *proc_date,
			   GimpPDBProcType  proc_type,
			   gint             nparams,
			   gint             nreturn_vals,
			   GimpParamDef    *params,
			   GimpParamDef    *return_vals);
87
88
89
90
} dbbrowser_t;

/* local functions */

91
92
93
94
95
96
97
98
99
100
101
102
static void         dialog_apply_callback     (GtkWidget        *widget,
					       dbbrowser_t      *dbbrowser);
static gint         procedure_select_callback (GtkTreeSelection *sel,
					       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);
103
104
105
106
107

/* create the dialog box
 * console_entry != NULL => called from the script-fu-console
 */
GtkWidget *
Michael Natterer's avatar
Michael Natterer committed
108
gimp_db_browser (GimpDBBrowserApplyCallback apply_callback)
Elliot Lee's avatar
Elliot Lee committed
109
{
110
111
112
113
114
115
  dbbrowser_t *dbbrowser;
  GtkWidget   *hbox;
  GtkWidget   *searchhbox;
  GtkWidget   *vbox;
  GtkWidget   *label;
  GtkWidget   *scrolled_window;
116

117
  dbbrowser = g_new (dbbrowser_t, 1);
Elliot Lee's avatar
Elliot Lee committed
118
119
120
121
  
  dbbrowser->apply_callback = apply_callback;
  
  /* the dialog box */
122

123
124
125
126
  if (apply_callback)
    {
      dbbrowser->dlg =
	gimp_dialog_new (_("DB Browser (init...)"), "dbbrowser",
127
			 gimp_standard_help_func, "filters/dbbrowser.html",
128
129
130
131
132
133
134
			 GTK_WIN_POS_MOUSE,
			 FALSE, TRUE, FALSE,

			 _("Search by Name"), dialog_search_callback,
			 dbbrowser, NULL, &dbbrowser->name_button, TRUE, FALSE,
			 _("Search by Blurb"), dialog_search_callback,
			 dbbrowser, NULL, &dbbrowser->blurb_button, FALSE, FALSE,
135
			 GTK_STOCK_APPLY, dialog_apply_callback,
136
			 dbbrowser, NULL, NULL, FALSE, FALSE,
137
			 GTK_STOCK_CLOSE, dialog_close_callback,
138
139
140
141
142
143
144
145
			 dbbrowser, NULL, NULL, FALSE, TRUE,

			 NULL);
    }
  else
    {
      dbbrowser->dlg =
	gimp_dialog_new (_("DB Browser (init...)"), "dbbrowser",
146
			 gimp_standard_help_func, "filters/dbbrowser.html",
147
148
149
150
151
152
153
			 GTK_WIN_POS_MOUSE,
			 FALSE, TRUE, FALSE,

			 _("Search by Name"), dialog_search_callback,
			 dbbrowser, NULL, &dbbrowser->name_button, TRUE, FALSE,
			 _("Search by Blurb"), dialog_search_callback,
			 dbbrowser, NULL, &dbbrowser->blurb_button, FALSE, FALSE,
154
			 GTK_STOCK_CLOSE, dialog_close_callback,
155
156
157
158
159
			 dbbrowser, NULL, NULL, FALSE, TRUE,

			 NULL);
    }

160
161
  g_signal_connect (G_OBJECT (dbbrowser->dlg), "destroy",
                    G_CALLBACK (dialog_close_callback), dbbrowser);
Elliot Lee's avatar
Elliot Lee committed
162
163
  
  /* hbox : left=list ; right=description */
Michael Natterer's avatar
Michael Natterer committed
164
165
166

  hbox = gtk_hbox_new (FALSE, 4);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
Elliot Lee's avatar
Elliot Lee committed
167
168
169
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dbbrowser->dlg)->vbox), 
		      hbox, TRUE, TRUE, 0);
  gtk_widget_show (hbox);
170

Elliot Lee's avatar
Elliot Lee committed
171
172
  /* left = vbox : the list and the search entry */
  
Michael Natterer's avatar
Michael Natterer committed
173
174
175
176
  vbox = gtk_vbox_new (FALSE, 4);
  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
  gtk_widget_show (vbox);

Elliot Lee's avatar
Elliot Lee committed
177
178
  /* list : list in a scrolled_win */
  
179
180
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
Michael Natterer's avatar
Michael Natterer committed
181
182
				  GTK_POLICY_AUTOMATIC,
				  GTK_POLICY_ALWAYS);
183
184
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
  gtk_widget_show (scrolled_window);
185

186
187
188
189
  dbbrowser->store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
  dbbrowser->smodel =
    gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (dbbrowser->store));
  g_object_unref (G_OBJECT (dbbrowser->store));
Michael Natterer's avatar
Michael Natterer committed
190

191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  dbbrowser->tv =
    gtk_tree_view_new_with_model (GTK_TREE_MODEL (dbbrowser->smodel));
  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dbbrowser->smodel),
					0, GTK_SORT_ASCENDING);
  g_object_unref (G_OBJECT (dbbrowser->smodel));

  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);
  /* gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (dbbrowser->tv), TRUE); */

  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));
  g_signal_connect (G_OBJECT (dbbrowser->sel), "changed",
		    G_CALLBACK (procedure_select_callback), dbbrowser);
Elliot Lee's avatar
Elliot Lee committed
211
212
213

  /* search entry */

214
  searchhbox = gtk_hbox_new (FALSE, 4);
Michael Natterer's avatar
Michael Natterer committed
215
  gtk_box_pack_start (GTK_BOX (vbox), searchhbox, FALSE, FALSE, 0);
216
  gtk_widget_show (searchhbox);
Elliot Lee's avatar
Elliot Lee committed
217

218
  label = gtk_label_new (_("Search:"));
Michael Natterer's avatar
Michael Natterer committed
219
220
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_box_pack_start (GTK_BOX (searchhbox), label, FALSE, FALSE, 0);
221
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
222

223
  dbbrowser->search_entry = gtk_entry_new ();
Michael Natterer's avatar
Michael Natterer committed
224
225
226
  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
227
228
229

  /* right = description */

Michael Natterer's avatar
Michael Natterer committed
230
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
231
  gtk_widget_set_size_request (scrolled_window, DBL_WIDTH - DBL_LIST_WIDTH, -1);
Michael Natterer's avatar
Michael Natterer committed
232
233
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
				  GTK_POLICY_AUTOMATIC, 
234
				  GTK_POLICY_ALWAYS);
Michael Natterer's avatar
Michael Natterer committed
235
236
237
238
239
240
241
242
  gtk_box_pack_start (GTK_BOX (hbox), scrolled_window, TRUE, TRUE, 0);
  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
243
244
245
246
247
248
249

  /* now build the list */

  gtk_widget_show (dbbrowser->dlg);

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

Michael Natterer's avatar
Michael Natterer committed
250
251
  dbbrowser->descr_table               = NULL;
  dbbrowser->selected_proc_name        = NULL;
Elliot Lee's avatar
Elliot Lee committed
252
  dbbrowser->selected_scheme_proc_name = NULL;
Michael Natterer's avatar
Michael Natterer committed
253
254
255
256
257
258
259
260
261
262
  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
263
264

  /* first search (all procedures) */
265
  dialog_search_callback (NULL, dbbrowser);
266
267

  return dbbrowser->dlg;
Elliot Lee's avatar
Elliot Lee committed
268
269
270
}

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

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

280
281
282
283
284
285
286
  if (gtk_tree_selection_get_selected (sel, NULL, &iter))
    {
      gtk_tree_model_get (dbbrowser->smodel, &iter, 1, &func, -1);
      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
296
297
298
299
300
  GtkWidget   *old_table;
  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
318
319
320
321
322
323
324
325
326
327
  gimp_procedural_db_proc_info (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), 
				&(dbbrowser->selected_return_vals));
Michael Natterer's avatar
Michael Natterer committed
328

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

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

Michael Natterer's avatar
Michael Natterer committed
337
338
  gtk_table_set_col_spacings (GTK_TABLE (dbbrowser->descr_table), 6);
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->descr_table), 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

Michael Natterer's avatar
Michael Natterer committed
346
347
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->descr_table), 0, row++,
			     _("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);

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

  sep = gtk_hseparator_new ();
  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), 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
370
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), 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
380
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), 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
388
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), 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
395
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), 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
407
      sep = gtk_hseparator_new ();
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), 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
418
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), 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
428
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), 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
436
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), 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
443
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
	  gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), 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
455
      sep = gtk_hseparator_new ();
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), 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
470

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

      sep = gtk_hseparator_new ();
      gtk_table_attach (GTK_TABLE (dbbrowser->descr_table), 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

Michael Natterer's avatar
Michael Natterer committed
486
487
488
489
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->descr_table), row, 2);
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->descr_table), 0, row++,
			     _("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);

Michael Natterer's avatar
Michael Natterer committed
494
495
496
497
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->descr_table), row, 2);
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->descr_table), 0, row++,
			     _("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);

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

Michael Natterer's avatar
Michael Natterer committed
507
508
  if (old_table)
    gtk_container_remove (GTK_CONTAINER (dbbrowser->descr_vbox), old_table);
Sven Neumann's avatar
Sven Neumann committed
509

Michael Natterer's avatar
Michael Natterer committed
510
511
  gtk_box_pack_start (GTK_BOX (dbbrowser->descr_vbox), dbbrowser->descr_table,
		      FALSE, FALSE, 0);
512
  gtk_widget_show (dbbrowser->descr_table);
Elliot Lee's avatar
Elliot Lee committed
513
514
}

515
/* end of the dialog */
Elliot Lee's avatar
Elliot Lee committed
516
static void
517
518
dialog_close_callback (GtkWidget   *widget, 
		       dbbrowser_t *dbbrowser)
Elliot Lee's avatar
Elliot Lee committed
519
{
520
521
522
523
524
525
526
527
528
529
530
531
  if (dbbrowser->apply_callback)
    {
      /* we are called by another application : just kill the dialog box */
      gtk_widget_hide (dbbrowser->dlg);
      gtk_widget_destroy (dbbrowser->dlg);
    }
  else
    {
      /* we are in the plug_in : kill the gtk application */
      gtk_widget_destroy (dbbrowser->dlg);
      gtk_main_quit ();
    }
Manish Singh's avatar
Manish Singh committed
532
}
Elliot Lee's avatar
Elliot Lee committed
533

534
/* end of the dialog */
Elliot Lee's avatar
Elliot Lee committed
535
static void 
536
537
dialog_apply_callback (GtkWidget   *widget, 
		       dbbrowser_t *dbbrowser)
Elliot Lee's avatar
Elliot Lee committed
538
{
539
  (dbbrowser->apply_callback) (dbbrowser->selected_proc_name,
Elliot Lee's avatar
Elliot Lee committed
540
541
542
543
544
545
546
547
548
549
			       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,
550
			       dbbrowser->selected_return_vals);
Elliot Lee's avatar
Elliot Lee committed
551
552
}

553
/* search in the whole db */
Elliot Lee's avatar
Elliot Lee committed
554
static void 
555
556
dialog_search_callback (GtkWidget   *widget, 
		        dbbrowser_t *dbbrowser)
Elliot Lee's avatar
Elliot Lee committed
557
{
Michael Natterer's avatar
Michael Natterer committed
558
559
  gchar       **proc_list;
  gint          num_procs;
560
  gint          i;
Michael Natterer's avatar
Michael Natterer committed
561
  gchar        *label;
562
  const gchar  *query_text;
Michael Natterer's avatar
Michael Natterer committed
563
  GString      *query;
564
  GtkTreeIter   iter;
Elliot Lee's avatar
Elliot Lee committed
565

566
  gtk_list_store_clear (dbbrowser->store);
Elliot Lee's avatar
Elliot Lee committed
567
568
569

  /* search */

570
  if (widget == (dbbrowser->name_button))
Elliot Lee's avatar
Elliot Lee committed
571
572
    {
      gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), 
Sven Neumann's avatar
Sven Neumann committed
573
			    _("DB Browser (by name - please wait)"));
574
575

      query = g_string_new ("");
576
      query_text = gtk_entry_get_text (GTK_ENTRY (dbbrowser->search_entry));
577
578
579
580
581
582
583
584
585
586
587

      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
588
589
590
      gimp_procedural_db_query (query->str,
			        ".*", ".*", ".*", ".*", ".*", ".*", 
			        &num_procs, &proc_list);
591
592

      g_string_free (query, TRUE);
Elliot Lee's avatar
Elliot Lee committed
593
    }
594
  else if (widget == (dbbrowser->blurb_button))
Elliot Lee's avatar
Elliot Lee committed
595
596
    {
      gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), 
Sven Neumann's avatar
Sven Neumann committed
597
			    _("DB Browser (by blurb - please wait)"));
Daniel Egger's avatar
Daniel Egger committed
598
      gimp_procedural_db_query (".*", 
599
600
			        (gchar *) gtk_entry_get_text
				  (GTK_ENTRY (dbbrowser->search_entry)),
Daniel Egger's avatar
Daniel Egger committed
601
602
			        ".*", ".*", ".*", ".*", ".*",
			        &num_procs, &proc_list);
Elliot Lee's avatar
Elliot Lee committed
603
    }
604
605
  else
    {
Elliot Lee's avatar
Elliot Lee committed
606
      gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), 
Sven Neumann's avatar
Sven Neumann committed
607
			    _("DB Browser (please wait)"));
Daniel Egger's avatar
Daniel Egger committed
608
609
      gimp_procedural_db_query (".*", ".*", ".*", ".*", ".*", ".*", ".*", 
			        &num_procs, &proc_list);
610
    }
Elliot Lee's avatar
Elliot Lee committed
611

612
613
614
615
  for (i = 0; i < num_procs; i++)
    {
      label = g_strdup (proc_list[i]);
      convert_string (label);
616
617
618
619
620
621
622
      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]);
623
    }
624
  
625
  g_free (proc_list);
Elliot Lee's avatar
Elliot Lee committed
626

627
  if (num_procs > 0)
628
    {
629
630
      gtk_tree_model_get_iter_root (dbbrowser->smodel, &iter);
      gtk_tree_selection_select_iter (dbbrowser->sel, &iter);
631
    }
Elliot Lee's avatar
Elliot Lee committed
632

Sven Neumann's avatar
Sven Neumann committed
633
  gtk_window_set_title (GTK_WINDOW (dbbrowser->dlg), _("DB Browser"));
Elliot Lee's avatar
Elliot Lee committed
634
635
636
637
638
}

/* utils ... */

static void 
639
convert_string (gchar *str)
Elliot Lee's avatar
Elliot Lee committed
640
641
642
{
  while (*str)
    {
643
644
645
      if (*str == '_')
	*str = '-';

Elliot Lee's avatar
Elliot Lee committed
646
647
648
649
      str++;
    }
}

650
static const gchar * 
Daniel Egger's avatar
Daniel Egger committed
651
GParamType2char (GimpPDBArgType t)
Elliot Lee's avatar
Elliot Lee committed
652
{
653
654
  switch (t)
    {
655
656
657
658
659
660
661
662
663
    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
664
    case GIMP_PDB_STRINGARRAY: return "STRINGARRAY";
665
666
667
668
669
670
671
672
673
674
675
676
677
678
    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?";
679
    }
Elliot Lee's avatar
Elliot Lee committed
680
}