gimpprocview.c 22.5 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 75 76 77 78 79 80 81 82 83 84 85

  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);
86 87 88 89
} dbbrowser_t;

/* local functions */

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
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);
106 107 108 109 110

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

120
  dbbrowser = g_new0 (dbbrowser_t, 1);
Elliot Lee's avatar
Elliot Lee committed
121 122 123 124
  
  dbbrowser->apply_callback = apply_callback;
  
  /* the dialog box */
125

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

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

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

153
			 _("Search by _Name"), dialog_search_callback,
154
			 dbbrowser, NULL, &dbbrowser->name_button, TRUE, FALSE,
155
			 _("Search by _Blurb"), dialog_search_callback,
156
			 dbbrowser, NULL, &dbbrowser->blurb_button, FALSE, FALSE,
157
			 GTK_STOCK_CLOSE, dialog_close_callback,
158 159 160 161 162
			 dbbrowser, NULL, NULL, FALSE, TRUE,

			 NULL);
    }

163
  g_signal_connect (dbbrowser->dialog, "destroy",
164
                    G_CALLBACK (dialog_close_callback), dbbrowser);
Elliot Lee's avatar
Elliot Lee committed
165
  
166
  /* hpaned : left=list ; right=description */
167

168
  hpaned = gtk_hpaned_new ();
169
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dbbrowser->dialog)->vbox), 
170 171
		      hpaned, TRUE, TRUE, 0);
  gtk_widget_show (hpaned);
172

Elliot Lee's avatar
Elliot Lee committed
173 174
  /* left = vbox : the list and the search entry */
  
175
  vbox = gtk_vbox_new (FALSE, 4);
176
  gtk_paned_pack1 (GTK_PANED (hpaned), vbox, FALSE, TRUE);
177 178
  gtk_widget_show (vbox);

Elliot Lee's avatar
Elliot Lee committed
179 180
  /* list : list in a scrolled_win */
  
181
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
182 183
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
				       GTK_SHADOW_IN);
184
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
185 186
				  GTK_POLICY_AUTOMATIC,
				  GTK_POLICY_ALWAYS);
187 188
  gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
  gtk_widget_show (scrolled_window);
189

190
  dbbrowser->tv = gtk_tree_view_new ();
191 192 193 194 195 196 197

  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);

198 199 200 201
  if (apply_callback)
    g_signal_connect (dbbrowser->tv, "row_activated",
                      G_CALLBACK (procedure_activated_callback), dbbrowser);

202 203 204 205 206
  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));
207
  g_signal_connect (dbbrowser->sel, "changed",
208
		    G_CALLBACK (procedure_select_callback), dbbrowser);
Elliot Lee's avatar
Elliot Lee committed
209 210 211

  /* search entry */

212 213
  searchhbox = gtk_hbox_new (FALSE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), searchhbox, FALSE, FALSE, 2);
214
  gtk_widget_show (searchhbox);
Elliot Lee's avatar
Elliot Lee committed
215

216 217
  label = gtk_label_new_with_mnemonic (_("_Search:"));
  gtk_box_pack_start (GTK_BOX (searchhbox), label, FALSE, FALSE, 2);
218
  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
219

220
  dbbrowser->search_entry = gtk_entry_new ();
221
  gtk_entry_set_activates_default (GTK_ENTRY (dbbrowser->search_entry), TRUE);
222 223 224
  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
225

226 227
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), dbbrowser->search_entry);

Elliot Lee's avatar
Elliot Lee committed
228 229
  /* right = description */

230
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
231
  gtk_widget_set_size_request (scrolled_window, DBL_WIDTH - DBL_LIST_WIDTH, -1);
232 233
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
				  GTK_POLICY_AUTOMATIC, 
234
				  GTK_POLICY_ALWAYS);
235
  gtk_paned_pack2 (GTK_PANED (hpaned), scrolled_window, TRUE, TRUE);
236 237 238 239 240 241 242
  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

  /* now build the list */

246
  gtk_widget_show (dbbrowser->dialog);
Elliot Lee's avatar
Elliot Lee committed
247 248 249

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

250
  dbbrowser->description               = NULL;
251
  dbbrowser->selected_proc_name        = NULL;
Elliot Lee's avatar
Elliot Lee committed
252
  dbbrowser->selected_scheme_proc_name = NULL;
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->dialog;
Elliot Lee's avatar
Elliot Lee committed
268 269
}

270 271 272 273 274 275 276 277 278
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
279
static gint
280 281
procedure_select_callback (GtkTreeSelection *sel,
			   dbbrowser_t      *dbbrowser)
Elliot Lee's avatar
Elliot Lee committed
282
{
283
  GtkTreeIter  iter;
284
  gchar       *func;
Elliot Lee's avatar
Elliot Lee committed
285

286
  g_return_val_if_fail (sel != NULL, FALSE);
Elliot Lee's avatar
Elliot Lee committed
287
  g_return_val_if_fail (dbbrowser != NULL, FALSE);
288

289 290
  if (gtk_tree_selection_get_selected (sel, NULL, &iter))
    {
291 292 293
      gtk_tree_model_get (GTK_TREE_MODEL (dbbrowser->store), &iter,
			  1, &func,
			  -1);
294 295 296 297
      dialog_select (dbbrowser, func);
      g_free (func);
    }

Elliot Lee's avatar
Elliot Lee committed
298 299 300
  return FALSE;
}

301
/* update the description box (right) */
Elliot Lee's avatar
Elliot Lee committed
302 303 304 305
static void 
dialog_select (dbbrowser_t *dbbrowser, 
	       gchar       *proc_name)
{
306
  GtkWidget   *old_description;
307 308 309 310 311
  GtkWidget   *label;
  GtkWidget   *sep;
  gint         i;
  gint         row = 0;
  const gchar *type;
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326

  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
327

328 329 330 331 332 333 334 335 336 337 338
  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));
339

Elliot Lee's avatar
Elliot Lee committed
340
  /* save the "old" table */
341
  old_description = dbbrowser->description;
Elliot Lee's avatar
Elliot Lee committed
342

343
  dbbrowser->description = gtk_table_new (10 +
344 345 346
					  dbbrowser->selected_nparams +
					  dbbrowser->selected_nreturn_vals,
					  5, FALSE);
Elliot Lee's avatar
Elliot Lee committed
347

348 349
  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
350 351 352

  /* show the name */

353 354 355
  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
356

357
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->description), 0, row++,
358
			     _("Name:"), 1.0, 0.5,
359
			     label, 3, FALSE);
Elliot Lee's avatar
Elliot Lee committed
360 361 362

  /* show the description */

363
  label = gtk_label_new (dbbrowser->selected_proc_blurb);
Elliot Lee's avatar
Elliot Lee committed
364 365
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

366
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->description), 0, row++,
367 368 369 370
			     _("Blurb:"), 1.0, 0.5,
			     label, 3, FALSE);

  sep = gtk_hseparator_new ();
371
  gtk_table_attach (GTK_TABLE (dbbrowser->description), sep,
372
		    0, 4, row, row + 1, GTK_FILL, GTK_FILL, 0, 6);
373
  gtk_widget_show (sep);
Elliot Lee's avatar
Elliot Lee committed
374 375 376 377 378
  row++;

  /* in parameters */
  if (dbbrowser->selected_nparams) 
    {
379
      label = gtk_label_new (_("In:"));
Elliot Lee's avatar
Elliot Lee committed
380
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
381
      gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
382 383
			0, 1, row, row + (dbbrowser->selected_nparams), 
			GTK_FILL, GTK_FILL, 0, 0);
384
      gtk_widget_show (label);
385

386
      for (i = 0; i < dbbrowser->selected_nparams; i++) 
Elliot Lee's avatar
Elliot Lee committed
387 388
	{
	  /* name */
389
	  label = gtk_label_new ((dbbrowser->selected_params[i]).name);
Elliot Lee's avatar
Elliot Lee committed
390
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
391
	  gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
392
			    1, 2, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
393
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
394 395

	  /* type */
396 397
	  type = GParamType2char ((dbbrowser->selected_params[i]).type);
	  label = gtk_label_new (type);
Elliot Lee's avatar
Elliot Lee committed
398
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
399
	  gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
400
			    2, 3, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
401
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
402 403

	  /* description */
404
	  label = gtk_label_new ((dbbrowser->selected_params[i]).description);
Elliot Lee's avatar
Elliot Lee committed
405
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
406
	  gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
407
			    3, 4, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
408
	  gtk_widget_show (label);
409

Elliot Lee's avatar
Elliot Lee committed
410 411 412
	  row++;
	}
    }
413

Elliot Lee's avatar
Elliot Lee committed
414
  if ((dbbrowser->selected_nparams) && 
415 416
      (dbbrowser->selected_nreturn_vals))
    {
417
      sep = gtk_hseparator_new ();
418
      gtk_table_attach (GTK_TABLE (dbbrowser->description), sep,
419
			0, 4, row, row + 1, GTK_FILL, GTK_FILL, 0, 6);
420
      gtk_widget_show (sep);
421 422
      row++;
    }
Elliot Lee's avatar
Elliot Lee committed
423 424 425 426

  /* out parameters */
  if (dbbrowser->selected_nreturn_vals)
    {
427
      label = gtk_label_new (_("Out:"));
Elliot Lee's avatar
Elliot Lee committed
428
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
429
      gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
430 431
			0, 1, row, row + (dbbrowser->selected_nreturn_vals), 
			GTK_FILL, GTK_FILL, 0, 0);
432
      gtk_widget_show (label);
433

434
      for (i = 0; i < dbbrowser->selected_nreturn_vals; i++) 
Elliot Lee's avatar
Elliot Lee committed
435 436
	{
	  /* name */
437
	  label = gtk_label_new ((dbbrowser->selected_return_vals[i]).name);
Elliot Lee's avatar
Elliot Lee committed
438
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
439
	  gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
440
			    1, 2, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
441
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
442 443

	  /* type */
444 445
	  type = GParamType2char (dbbrowser->selected_return_vals[i].type);
	  label = gtk_label_new (type);
Elliot Lee's avatar
Elliot Lee committed
446
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
447
	  gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
448
			    2, 3, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
449
	  gtk_widget_show (label);
Elliot Lee's avatar
Elliot Lee committed
450 451

	  /* description */
452
	  label = gtk_label_new (dbbrowser->selected_return_vals[i].description);
Elliot Lee's avatar
Elliot Lee committed
453
	  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); 
454
	  gtk_table_attach (GTK_TABLE (dbbrowser->description), label,
455
			    3, 4, row, row + 1, GTK_FILL, GTK_FILL, 0, 0);
456
	  gtk_widget_show (label);
457

Elliot Lee's avatar
Elliot Lee committed
458 459 460 461
	  row++;
	}
    }

462 463
  if (dbbrowser->selected_nparams || 
      dbbrowser->selected_nreturn_vals)
464
    {
465
      sep = gtk_hseparator_new ();
466
      gtk_table_attach (GTK_TABLE (dbbrowser->description), sep,
467
			0, 4, row, row + 1, GTK_FILL, GTK_FILL, 0, 6);
468 469 470
      gtk_widget_show (sep);
      row++;
    }
Elliot Lee's avatar
Elliot Lee committed
471

Sven Neumann's avatar
Sven Neumann committed
472
  /* show the help */
473
  if (dbbrowser->selected_proc_help &&
474
      (strlen (dbbrowser->selected_proc_help) > 1))
Sven Neumann's avatar
Sven Neumann committed
475
    {
476 477 478
      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);
479

480
      gimp_table_attach_aligned (GTK_TABLE (dbbrowser->description), 0, row++,
481
				 _("Help:"), 1.0, 0.5,
482
				 label, 3, FALSE);
483 484

      sep = gtk_hseparator_new ();
485
      gtk_table_attach (GTK_TABLE (dbbrowser->description), sep,
486
			0, 4, row, row + 1, GTK_FILL, GTK_FILL, 0, 6);
487
      gtk_widget_show (sep);
488

Sven Neumann's avatar
Sven Neumann committed
489 490 491 492 493
      row++;
    }

  /* show the author & the copyright */

494
  label = gtk_label_new (dbbrowser->selected_proc_author);
Elliot Lee's avatar
Elliot Lee committed
495
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
496

497 498
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->description), row, 2);
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->description), 0, row++,
499 500
			     _("Author:"), 1.0, 0.5,
			     label, 3, FALSE);
Elliot Lee's avatar
Elliot Lee committed
501

502
  label = gtk_label_new (dbbrowser->selected_proc_date);
Elliot Lee's avatar
Elliot Lee committed
503 504
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

505 506
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->description), row, 2);
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->description), 0, row++,
507 508
			     _("Date:"), 1.0, 0.5,
			     label, 3, FALSE);
Elliot Lee's avatar
Elliot Lee committed
509

510
  label = gtk_label_new (dbbrowser->selected_proc_copyright);
Elliot Lee's avatar
Elliot Lee committed
511 512
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

513 514
  gtk_table_set_row_spacing (GTK_TABLE (dbbrowser->description), row, 2);
  gimp_table_attach_aligned (GTK_TABLE (dbbrowser->description), 0, row++,
515 516
			     _("Copyright:"), 1.0, 0.5,
			     label, 3, FALSE);
Elliot Lee's avatar
Elliot Lee committed
517

518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
  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);
      
      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
546

547 548
  while (gtk_events_pending ())
    gtk_main_iteration ();
Elliot Lee's avatar
Elliot Lee committed
549 550
}

551
/* end of the dialog */
Elliot Lee's avatar
Elliot Lee committed
552
static void
553 554
dialog_close_callback (GtkWidget   *widget, 
		       dbbrowser_t *dbbrowser)
Elliot Lee's avatar
Elliot Lee committed
555
{
556 557
  if (dbbrowser->apply_callback)
    {
558 559
      /* we are called by another application : just destroy the dialog box */
      gtk_widget_destroy (dbbrowser->dialog);
560 561 562 563 564 565
    }
  else
    {
      /* we are in the plug_in : kill the gtk application */
      gtk_main_quit ();
    }
Manish Singh's avatar
Manish Singh committed
566
}
Elliot Lee's avatar
Elliot Lee committed
567

568
/* end of the dialog */
Elliot Lee's avatar
Elliot Lee committed
569
static void 
570 571
dialog_apply_callback (GtkWidget   *widget, 
		       dbbrowser_t *dbbrowser)
Elliot Lee's avatar
Elliot Lee committed
572
{
573
  (dbbrowser->apply_callback) (dbbrowser->selected_proc_name,
Elliot Lee's avatar
Elliot Lee committed
574 575 576 577 578 579 580 581 582 583
			       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,
584
			       dbbrowser->selected_return_vals);
Elliot Lee's avatar
Elliot Lee committed
585 586
}

587
/* search in the whole db */
Elliot Lee's avatar
Elliot Lee committed
588
static void 
589 590
dialog_search_callback (GtkWidget   *widget, 
		        dbbrowser_t *dbbrowser)
Elliot Lee's avatar
Elliot Lee committed
591
{
592 593
  gchar       **proc_list;
  gint          num_procs;
594
  gint          i;
595
  gchar        *label;
596
  const gchar  *query_text;
597
  GString      *query;
598
  GtkTreeIter   iter;
Elliot Lee's avatar
Elliot Lee committed
599

600
  gtk_tree_view_set_model (GTK_TREE_VIEW (dbbrowser->tv), NULL);
Elliot Lee's avatar
Elliot Lee committed
601 602 603

  /* search */

604
  if (widget == (dbbrowser->name_button))
Elliot Lee's avatar
Elliot Lee committed
605
    {
606
      dialog_show_message (dbbrowser, _("Searching by name - please wait"));
607 608

      query = g_string_new ("");
609
      query_text = gtk_entry_get_text (GTK_ENTRY (dbbrowser->search_entry));
610 611 612 613 614 615 616 617 618 619 620

      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
621 622 623
      gimp_procedural_db_query (query->str,
			        ".*", ".*", ".*", ".*", ".*", ".*", 
			        &num_procs, &proc_list);
624 625

      g_string_free (query, TRUE);
Elliot Lee's avatar
Elliot Lee committed
626
    }
627
  else if (widget == (dbbrowser->blurb_button))
Elliot Lee's avatar
Elliot Lee committed
628
    {
629 630
      dialog_show_message (dbbrowser, _("Searching by blurb - please wait"));

Daniel Egger's avatar
Daniel Egger committed
631
      gimp_procedural_db_query (".*", 
632 633
			        (gchar *) gtk_entry_get_text
				  (GTK_ENTRY (dbbrowser->search_entry)),
Daniel Egger's avatar
Daniel Egger committed
634 635
			        ".*", ".*", ".*", ".*", ".*",
			        &num_procs, &proc_list);
Elliot Lee's avatar
Elliot Lee committed
636
    }
637 638
  else
    {
639
      dialog_show_message (dbbrowser, _("Searching - please wait"));
Daniel Egger's avatar
Daniel Egger committed
640 641
      gimp_procedural_db_query (".*", ".*", ".*", ".*", ".*", ".*", ".*", 
			        &num_procs, &proc_list);
642
    }
Elliot Lee's avatar
Elliot Lee committed
643

644 645 646 647
  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);
648

649 650 651 652
  for (i = 0; i < num_procs; i++)
    {
      label = g_strdup (proc_list[i]);
      convert_string (label);
653 654 655 656 657 658 659
      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]);
660
    }
661

662
  g_free (proc_list);
Elliot Lee's avatar
Elliot Lee committed
663

664
  /* now sort the store */ 
665 666
  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dbbrowser->store),
                                        0, GTK_SORT_ASCENDING);
667
  
668
  if (num_procs > 0)
669
    {
670
      gtk_tree_model_get_iter_root (GTK_TREE_MODEL (dbbrowser->store), &iter);
671
      gtk_tree_selection_select_iter (dbbrowser->sel, &iter);
672
    }
673 674 675 676
  else
    {
      dialog_show_message (dbbrowser, _("No matches"));
    }
Elliot Lee's avatar
Elliot Lee committed
677 678 679 680 681
}

/* utils ... */

static void 
682
convert_string (gchar *str)
Elliot Lee's avatar
Elliot Lee committed
683 684 685
{
  while (*str)
    {
686 687 688
      if (*str == '_')
	*str = '-';

Elliot Lee's avatar
Elliot Lee committed
689 690 691 692
      str++;
    }
}

693
static const gchar * 
694
GParamType2char (GimpPDBArgType t)
Elliot Lee's avatar
Elliot Lee committed
695
{
696 697
  switch (t)
    {
698 699 700 701 702 703 704 705 706
    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";
707
    case GIMP_PDB_STRINGARRAY: return "STRINGARRAY";
708 709 710 711 712 713 714 715 716 717 718 719 720 721
    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?";
722
    }
Elliot Lee's avatar
Elliot Lee committed
723
}