plugin-browser.c 30.7 KB
Newer Older
1
2
3
4
5
6
7
/*
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This is a plug-in for the GIMP.
 *
 * Copyright (C) 1999 Andy Thomas  alt@picnic.demon.co.uk
 *
8
 * Note some portions of the UI comes from the dbbrowser plugin.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 * 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.
 */

24
25
#include "config.h"

26
27
28
29
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
30

31
32
33
34
35
#ifdef __GNUC__
#warning GTK_DISABLE_DEPRECATED
#endif
#undef GTK_DISABLE_DEPRECATED

36
37
#include <gtk/gtk.h>

38
39
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
40

41
#include "libgimp/stdplugins-intl.h"
42

43

44
45
46
#define DBL_LIST_WIDTH  250
#define DBL_WIDTH       (DBL_LIST_WIDTH + 300)
#define DBL_HEIGHT      200
47

48
static gchar *proc_type_str[] =
49
{
50
51
52
53
  N_("Internal GIMP procedure"),
  N_("GIMP Plug-In"),
  N_("GIMP Extension"),
  N_("Temporary Procedure")
54
55
56
57
58
59
};


/* Declare some local functions.
 */
static void   query      (void);
60
61
62
63
64
static void   run        (gchar      *name,
                          gint        nparams,
                          GimpParam  *param,
                          gint       *nreturn_vals,
                          GimpParam **return_vals);
65

66
67
68
69
70
71
72
73
74
75
76
static GtkWidget * gimp_plugin_desc (void);

static gint procedure_clist_select_callback (GtkWidget      *widget,
					     gint            row, 
					     gint            column, 
					     GdkEventButton *bevent,
					     gpointer        data);
static gint procedure_ctree_select_callback (GtkWidget      *widget,
					     GtkWidget      *row, 
					     gint            column, 
					     gpointer        data);
77

78
GimpPlugInInfo PLUG_IN_INFO =
79
{
80
81
82
83
  NULL,  /* init_proc  */
  NULL,  /* quit_proc  */
  query, /* query_proc */
  run,   /* run_proc   */
84
85
86
87
88
89
};


MAIN ()

static void
90
query (void)
91
{
92
  static GimpParamDef args[] =
93
  {
94
    { GIMP_PDB_INT32, "run_mode", "Interactive, [non-interactive]" }
95
  };
96

97
  gimp_install_procedure ("plug_in_details",
Marc Lehmann's avatar
Marc Lehmann committed
98
                          "Displays plugin details",
99
100
101
102
103
104
                          "Helps browse the plugin menus system. You can "
			  "search for plugin names, sort by name or menu "
			  "location and you can view a tree representation "
			  "of the plugin menus. Can also be of help to find "
			  "where new plugins have installed themselves in "
			  "the menuing system",
105
106
107
                          "Andy Thomas",
                          "Andy Thomas",
                          "1999",
108
			  N_("<Toolbox>/Xtns/Plugin Details..."),
109
			  "",
Sven Neumann's avatar
Sven Neumann committed
110
                          GIMP_EXTENSION,
111
			  G_N_ELEMENTS (args), 0,
112
113
114
115
                          args, NULL);
}

static void
116
117
118
119
120
run (gchar      *name,
     gint        nparams,
     GimpParam  *param,
     gint       *nreturn_vals,
     GimpParam **return_vals)
121
{
122
  static GimpParam  values[2];
123
  GimpRunMode   run_mode;
124
  GtkWidget        *plugin_dialog;
125
126
127
128

  run_mode = param[0].data.d_int32;

  *nreturn_vals = 1;
129
  *return_vals  = values;
130
131
  values[0].type          = GIMP_PDB_STATUS;
  values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
132

133
134
  INIT_I18N_UI();

135
136
137
138
  if (strcmp (name, "plug_in_details") == 0)
    {
      *nreturn_vals = 1;

139
      values[0].data.d_status = GIMP_PDB_SUCCESS;
140

141
142
      plugin_dialog = gimp_plugin_desc ();

143
144
145
146
147
148
149
150
      gtk_main ();
      gdk_flush ();
    }
}


typedef struct  
{
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
  GtkWidget *dlg;
  GtkWidget *clist;
  GtkWidget *ctree;
  GtkWidget *search_entry;
  GtkWidget *descr_scroll;
  GtkWidget *name_button;
  GtkWidget *blurb_button;
  GtkWidget *scrolled_win;
  GtkWidget *ctree_scrolled_win;
  GtkWidget *info_table;
  GtkWidget *paned;
  GtkWidget *left_paned;
  GtkWidget *info_align;
  gint       num_plugins;
  gint       ctree_row;
  gint       clist_row;
  gint       c1size;
  gboolean   details_showing;
169
} PDesc;
170

171
PDesc *plugindesc = NULL;
172
173
174
175
176
177
178
179
180

typedef struct
{
  gchar *menu;
  gchar *accel;
  gchar *prog;
  gchar *types;
  gchar *realname;
  gint  instime;
181
} PInfo;
182
183
184
185
186
187

static void
dialog_close_callback (GtkWidget *widget, 
		       gpointer   data)
     /* end of the dialog */
{
188
  PDesc *pdesc = data;
189
  gtk_widget_destroy (pdesc->dlg);
190
191
192
  gtk_main_quit ();
}

193
194
/* Bit of a fiddle but sorta has the effect I want... */

195
196
197
198
static void
details_callback (GtkWidget *widget, 
		  gpointer   data)
{
199
200
  /* Show or hide the details window */ 
  PDesc *pdesc = data;
201
  GtkLabel *lab = GTK_LABEL (GTK_BIN (widget)->child);
202

203
204
205
206
207
208
209
210
  /* This is a lame hack: 
     We add the description on the right on the first details_callback.
     Otherwise the window reacts quite weird on resizes */
  if (pdesc->descr_scroll == NULL)
    {
      pdesc->descr_scroll = gtk_scrolled_window_new (NULL, NULL);
      gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (pdesc->descr_scroll),
				      GTK_POLICY_ALWAYS, 
211
				      GTK_POLICY_ALWAYS);
212
213
      gtk_widget_set_size_request (pdesc->descr_scroll,
				   DBL_WIDTH - DBL_LIST_WIDTH, -1);
214
215
      gtk_paned_pack2 (GTK_PANED (pdesc->paned), pdesc->descr_scroll,
		       FALSE, TRUE);
216
217
218
      gtk_clist_select_row (GTK_CLIST(pdesc->clist), pdesc->clist_row, -1);
    }

219
  if (pdesc->details_showing == FALSE)
220
    {
221
222
      GTK_PANED (pdesc->paned)->child1_resize = FALSE;
      gtk_label_set_text (lab, _("Details <<"));
223
224
225
226
227
      gtk_widget_show (pdesc->descr_scroll);
      pdesc->details_showing = TRUE;
    }
  else
    {
228
229
230
      GtkWidget *p = GTK_WIDGET (pdesc->paned)->parent;
      GTK_PANED (pdesc->paned)->child1_resize = TRUE;
      GTK_PANED (pdesc->paned)->child2_resize = TRUE;
Hans Breuer's avatar
Hans Breuer committed
231

232
      gtk_label_set_text (lab, _("Details >>"));
233
      gtk_widget_hide (pdesc->descr_scroll);
234
235
      gtk_paned_set_position (GTK_PANED (pdesc->paned),
			      p->allocation.width);/*plugindesc->c1size);*/
236
237
238
239
240
      pdesc->details_showing = FALSE;
    }
}

static gchar *
241
format_menu_path (gchar *s)
242
{
243
244
  gchar **str_array;
  gchar  *newstr = NULL;
245

246
  if (!s)
247
248
    return s;

249
  str_array = g_strsplit (s, "/", 0);
250

251
  newstr = g_strjoinv ("->", str_array);
252

253
  g_strfreev (str_array);
254
255
256
257
258

  return newstr;
}

static gint
259
260
procedure_general_select_callback (PDesc *pdesc,
				   PInfo *pinfo)
261
{
262
263
264
265
266
267
268
269
270
271
  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;
272
273
  GtkWidget *label;
  GtkWidget *help;
Hans Breuer's avatar
Hans Breuer committed
274
275
  GtkWidget *text_view;
  GtkTextBuffer *text_buffer;
276
277
  GtkWidget *old_table;
  GtkWidget *old_align;
278
279
  gint       table_row = 0;
  gchar     *str;
280
281
282
283

  g_return_val_if_fail (pdesc != NULL, FALSE);
  g_return_val_if_fail (pinfo != NULL, FALSE);

284
285
286
  if (pdesc->descr_scroll == NULL)
    return FALSE;

287
288
289
  selected_proc_blurb     = NULL;
  selected_proc_help      = NULL;
  selected_proc_author    = NULL;
290
  selected_proc_copyright = NULL;
291
292
293
294
295
296
  selected_proc_date      = NULL;
  selected_proc_type      = 0;
  selected_nparams        = 0;
  selected_nreturn_vals   = 0;
  selected_params         = NULL;
  selected_return_vals    = NULL;
297

298
299
300
301
302
303
304
305
306
  gimp_procedural_db_proc_info (pinfo->realname, 
				&selected_proc_blurb, 
				&selected_proc_help, 
				&selected_proc_author,
				&selected_proc_copyright, 
				&selected_proc_date, 
				&selected_proc_type, 
				&selected_nparams, &selected_nreturn_vals, 
				&selected_params, &selected_return_vals);
307
308
309
310

  old_table = pdesc->info_table;
  old_align = pdesc->info_align;

311
  pdesc->info_table = gtk_table_new (10, 5, FALSE);
312
313
  pdesc->info_align = gtk_alignment_new (0.5, 0.5, 0, 0);

314
  gtk_table_set_col_spacings (GTK_TABLE (pdesc->info_table), 3);
315
316
317

  /* Number of plugins */

Sven Neumann's avatar
Sven Neumann committed
318
  str = g_strdup_printf (_("Number of Plugin Interfaces: %d"),
319
320
321
			 pdesc->num_plugins);
  label = gtk_label_new (str);
  g_free (str);
322
323
324
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 0, 0);
325
  gtk_widget_show (label);
326
327
  table_row++;

328
  label = gtk_hseparator_new (); /* ok, not really a label ... :) */
329
330
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
331
  gtk_widget_show (label);
332
333
334
335
  table_row++;

  /* menu path */

336
  label = gtk_label_new (_("Menu Path:"));
337
338
339
340
341
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    0, 1, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 0);
  gtk_widget_show(label);

342
  label = gtk_label_new (format_menu_path (pinfo->menu));
343
344
345
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    1, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 0, 0);
346
  gtk_widget_show (label);
347
348
  table_row++;

349
  label = gtk_hseparator_new (); /* ok, not really a label ... :) */
350
351
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
352
  gtk_widget_show (label);
353
354
355
356
  table_row++;

  /* show the name */

357
  label = gtk_label_new (_("Name:"));
358
359
360
361
362
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    0, 1, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
  gtk_widget_show(label);

363
364
365
  label = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (label), pinfo->realname);
  gtk_entry_set_editable (GTK_ENTRY (label), FALSE);
366
367
  gtk_table_attach (GTK_TABLE(pdesc->info_table), label,
		    1, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 0, 0);
368
  gtk_widget_show (label);
369
370
  table_row++;

371
  label = gtk_hseparator_new (); /* ok, not really a label ... :) */
372
373
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
374
  gtk_widget_show (label);
375
376
377
378
  table_row++;

  /* show the description */

379
  label = gtk_label_new (_("Blurb:"));
380
381
382
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    0, 1, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 0);
383
  gtk_widget_show (label);
384

385
  label = gtk_label_new (selected_proc_blurb);
386
387
388
389
390
391
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    1, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 0, 0);
  gtk_widget_show(label);
  table_row++;

392
  label = gtk_hseparator_new (); /* ok, not really a label ... :) */
393
394
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
395
  gtk_widget_show (label);
396
397
398
399
400
  table_row++;

  /* show the help */
  if ((selected_proc_help) && (strlen(selected_proc_help) > 1))
    {
401
      label = gtk_label_new (_("Help:"));
402
403
404
405
      gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
      gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
			0, 1, table_row, table_row+1, 
			GTK_FILL, GTK_FILL, 3, 0);
406
      gtk_widget_show (label);
407
408
409
410
411
412
413
414
415
      
      help = gtk_table_new (2, 2, FALSE);
      gtk_table_set_row_spacing (GTK_TABLE (help), 0, 2);
      gtk_table_set_col_spacing (GTK_TABLE (help), 0, 2);
      gtk_table_attach (GTK_TABLE (pdesc->info_table), help,
			1, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 0);
      gtk_widget_show (help);
      table_row++;
      
Hans Breuer's avatar
Hans Breuer committed
416
417
418
419
420
421
422
423
424
      text_buffer = gtk_text_buffer_new  (NULL);
      gtk_text_buffer_set_text (text_buffer, selected_proc_help, -1);

      text_view = gtk_text_view_new_with_buffer (text_buffer);
      g_object_unref (G_OBJECT (text_buffer));

      gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE);
      gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD);

425
      gtk_widget_set_size_request (text_view, -1, 60);
Hans Breuer's avatar
Hans Breuer committed
426
      gtk_table_attach (GTK_TABLE (help), text_view, 0, 1, 0, 1,
427
428
			GTK_EXPAND | GTK_SHRINK | GTK_FILL,
			GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
Hans Breuer's avatar
Hans Breuer committed
429
      gtk_widget_show (text_view);
430
      
431
      label = gtk_hseparator_new (); /* ok, not really a label ... :) */
432
433
434
435
436
437
438
439
440
      gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
			0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
      gtk_widget_show(label);

      table_row++;
    }

  /* show the type */

441
  label = gtk_label_new (_("Type:"));
442
443
444
445
446
  gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    0, 1, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
  gtk_widget_show(label);

447
  label = gtk_label_new (gettext (proc_type_str[selected_proc_type]));
448
449
450
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    1, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 0, 0);
451
  gtk_widget_show (label);
452
453
  table_row++;

454
  label = gtk_hseparator_new (); /* ok, not really a label ... :) */
455
456
  gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
		    0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
457
  gtk_widget_show (label);
458
459
460
461
  table_row++;

  /* Remove old and replace with new */

462
463
  if (old_table)
    gtk_widget_destroy (old_table);
464

465
466
  if (old_align)
    gtk_widget_destroy (old_align);
467
468
469
470
471
472

  gtk_container_add (GTK_CONTAINER (pdesc->info_align),pdesc->info_table);

  gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (pdesc->descr_scroll), 
					 pdesc->info_align);

473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
  gtk_widget_show (pdesc->info_table);
  gtk_widget_show (pdesc->info_align);

  if (selected_proc_blurb)
    g_free (selected_proc_blurb);
  if (selected_proc_help)
    g_free (selected_proc_help); 
  if (selected_proc_author)
    g_free (selected_proc_author);
  if (selected_proc_copyright)
    g_free (selected_proc_copyright);
  if (selected_proc_date)
    g_free (selected_proc_date);
  if (selected_params)
    g_free (selected_params);
  if (selected_return_vals)
    g_free (selected_return_vals);
490

491
492
493
494
  return FALSE;
}

static void 
495
496
expand_to (PDesc        *pdesc,
	   GtkCTreeNode *parent)
497
498
499
{
  if(parent)
    {
500
501
      expand_to (pdesc, (GTK_CTREE_ROW (parent))->parent);
      gtk_ctree_expand (GTK_CTREE (pdesc->ctree), parent);      
502
503
504
505
    }
}

static gint
506
507
508
509
510
procedure_clist_select_callback (GtkWidget      *widget,
				 gint            row, 
				 gint            column, 
				 GdkEventButton *bevent,
				 gpointer        data)
511
{
512
  PInfo *pinfo;
513
  GtkCTreeNode * found_node; 
514
  PDesc *pdesc = data;
515
516
517

  g_return_val_if_fail (pdesc != NULL, FALSE);

518
  pinfo = (PInfo *) gtk_clist_get_row_data (GTK_CLIST (widget), row);
519

520
  if (!pinfo)
521
522
523
524
    return FALSE;

  /* Must select the correct one in the ctree structure */

525
526
  found_node = gtk_ctree_find_by_row_data (GTK_CTREE (pdesc->ctree),
					   NULL, pinfo);
527
  
528
  if (found_node)
529
530
531
    {
      GtkCTreeRow   *ctr;
      GtkCTreeNode  *parent;
532
      gint sel_row;
533
534
535

      /* Make sure this is expanded */

536
      ctr = GTK_CTREE_ROW (found_node);
537

538
      parent = GTK_CTREE_NODE (ctr->parent);
539

540
      expand_to (pdesc, parent);
541

542
      sel_row = gtk_clist_find_row_from_data (GTK_CLIST (pdesc->ctree), pinfo);
543

544
545
      gtk_widget_hide (pdesc->ctree); 
      gtk_widget_show (pdesc->ctree); 
546

547
      gtk_signal_handler_block_by_func (GTK_OBJECT(pdesc->ctree),
548
549
					GTK_SIGNAL_FUNC (procedure_ctree_select_callback),
					pdesc);
550

551
552
      gtk_clist_select_row (GTK_CLIST (pdesc->ctree), sel_row, -1);  
      gtk_ctree_select (GTK_CTREE (pdesc->ctree), found_node);
553

554
555
556
557
      gtk_clist_moveto (GTK_CLIST (pdesc->ctree),
			sel_row,
			0,
			0.5, 0.5);
558

559
      gtk_signal_handler_unblock_by_func (GTK_OBJECT (pdesc->ctree),
560
561
					  GTK_SIGNAL_FUNC (procedure_ctree_select_callback),
					  pdesc);
562
563
564
565
566

      pdesc->ctree_row = sel_row;
    }
  else
    {
567
      g_warning ("Failed to find node in ctree");
568
569
    }

570
  return procedure_general_select_callback (pdesc, pinfo);
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
}

/* This was an attempt to get around a problem in gtk 
 * where the scroll windows that contain ctree and clist
 * refuse to respond to the moveto funcions unless the
 * widgets are visible.
 * Still did not work 100% even after this.
 * Note the scrollbars are in the correct position but the
 * widget needs to be redrawn at the correct location.
 */

static gint
page_select_callback (GtkNotebook     *notebook,
		      GtkNotebookPage *page,
		      guint            page_num,
586
		      gpointer         data)
587
{
588
  PDesc *pdesc = data;
589

590
  if (page_num == 0)
591
    {
592
593
594
595
596
      gtk_clist_select_row (GTK_CLIST (pdesc->clist), pdesc->clist_row, -1);  
      gtk_clist_moveto (GTK_CLIST (pdesc->clist),
			pdesc->clist_row,
			0,
			0.5, 0.0);
597
598
599
    }
  else
    {
600
601
602
603
604
      gtk_clist_select_row (GTK_CLIST (pdesc->ctree), pdesc->ctree_row, -1);  
      gtk_clist_moveto (GTK_CLIST (pdesc->ctree),
			pdesc->ctree_row,
			0,
			0.5, 0.0);
605
    }
606

607
608
609
610
611
612
  return FALSE;
}

static gint
procedure_ctree_select_callback (GtkWidget *widget,
				 GtkWidget *row, 
613
614
				 gint       column, 
				 gpointer   data)
615
{
616
617
618
619
  PInfo *pinfo;
  PDesc *pdesc;
  gboolean is_leaf;
  gint sel_row;
620
621
622

  /* row is not a leaf the we have no interest in it */

623
624
625
626
627
628
629
630
631
632
  gtk_ctree_get_node_info (GTK_CTREE (widget),
			   GTK_CTREE_NODE (row),
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   &is_leaf,
			   NULL);
633

634
635
  if (!is_leaf)
    return FALSE;
636
637
638

  pdesc = data;

639
640
  pinfo = (PInfo *) gtk_ctree_node_get_row_data (GTK_CTREE (widget),
						 GTK_CTREE_NODE (row));
641
642
643
644

  /* Must set clist to this one */
  /* Block signals */

645
  gtk_signal_handler_block_by_func (GTK_OBJECT (pdesc->clist),
646
647
				    GTK_SIGNAL_FUNC (procedure_clist_select_callback),
				    pdesc);
648

649
650
651
652
653
654
  sel_row = gtk_clist_find_row_from_data (GTK_CLIST (pdesc->clist), pinfo);
  gtk_clist_select_row (GTK_CLIST (pdesc->clist), sel_row, -1);  
  gtk_clist_moveto (GTK_CLIST (pdesc->clist),
		    sel_row,
		    0,
		    0.5, 0.5);
655

656
  gtk_signal_handler_unblock_by_func (GTK_OBJECT (pdesc->clist),
657
658
				      GTK_SIGNAL_FUNC (procedure_clist_select_callback),
				      pdesc);
659
660
661

  pdesc->clist_row = sel_row;
  
662
  return procedure_general_select_callback (pdesc, pinfo);
663
664
665
}

static void
666
pinfo_free (gpointer p)
667
{
668
  PInfo *pinfo = p;
669

670
671
672
673
674
675
  g_free (pinfo->menu);
  g_free (pinfo->accel);
  g_free (pinfo->prog);
  g_free (pinfo->types);
  g_free (pinfo->realname);
  g_free (pinfo);
676
677
}

678
static GtkCTreeNode *
679
680
681
get_parent (PDesc       *pdesc,
	    GHashTable  *ghash,
	    gchar       *mpath)
682
683
684
685
686
687
688
689
{
  GtkCTreeNode *parent;
  GtkCTreeNode *last_parent;
  gchar *tmp_ptr;
  gchar *str_ptr;
  gchar *leaf_ptr;
  gchar *labels[3];
  
690
  if (mpath == NULL)
691
692
    return NULL; /* Parent is root */

693
  parent = g_hash_table_lookup (ghash, mpath);
694

695
  if (parent)
696
697
    {
      /* found node */
698
      return parent;
699
700
701
    }

  /* Next one up */
702
  tmp_ptr = g_strdup (mpath);
703

704
  str_ptr = strrchr (tmp_ptr,'/');
705

706
  if (str_ptr == NULL)
707
708
709
710
711
712
713
714
715
    {
      /*       printf("Root node for %s\n",mpath); */
      leaf_ptr = mpath;
      tmp_ptr = "<root>";
      last_parent = NULL;
    }
  else
    {
      leaf_ptr = g_strdup(str_ptr+1);
716

717
      *str_ptr = '\000';
718
719

      last_parent = get_parent (pdesc, ghash, tmp_ptr);
720
721
    }

722
723
724
  labels[0] = g_strdup (leaf_ptr); 
  labels[1] = g_strdup (""); 
  labels[2] = g_strdup (""); 
725
726
727

  /*   printf("get_parent::creating node %s under %s\n",leaf_ptr,tmp_ptr); */

728
729
730
731
732
733
734
735
736
737
738
739
740
  parent = gtk_ctree_insert_node (GTK_CTREE (pdesc->ctree),
				  last_parent,
				  NULL,
				  labels,
				  4,
				  NULL,
				  NULL,
				  NULL,
				  NULL,
				  FALSE,
				  FALSE);

  g_hash_table_insert (ghash, mpath, parent); 
741
742
743
744
745

  return parent;
}

static void
746
747
748
749
750
751
752
insert_into_ctree (PDesc      *pdesc,
		   gchar      *name,
		   gchar      *xtimestr,
		   gchar      *menu_str,
		   gchar      *types_str,
		   GHashTable *ghash,
		   PInfo      *pinfo)
753
754
755
756
757
758
759
760
761
762
763
{
  gchar *labels[3];
  gchar *str_ptr;
  gchar *tmp_ptr;
  gchar *leaf_ptr;
  GtkCTreeNode *parent = NULL;
  GtkCTreeNode *leaf_node = NULL;

  /* Find all nodes */
  /* Last one is the leaf part */

764
765
766
767
768
  tmp_ptr = g_strdup (menu_str);

  str_ptr = strrchr (tmp_ptr, '/');

  if (str_ptr == NULL)
769
770
    return; /* No node */

771
  leaf_ptr = g_strdup (str_ptr + 1);
772
773
774
775
776

  *str_ptr = '\000';

  /*   printf("inserting %s...\n",menu_str); */

777
  parent = get_parent (pdesc, ghash, tmp_ptr);
778
779
780

  /* Last was a leaf */
  /*   printf("found leaf %s parent = %p\n",leaf_ptr,parent); */
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
  labels[0] = g_strdup (name);
  labels[1] = g_strdup (xtimestr);
  labels[2] = g_strdup (types_str);

  leaf_node = gtk_ctree_insert_node (GTK_CTREE (pdesc->ctree),
				     parent,
				     NULL,
				     labels,
				     4,
				     NULL,
				     NULL,
				     NULL,
				     NULL,
				     TRUE,
				     FALSE);

  gtk_ctree_node_set_row_data (GTK_CTREE (pdesc->ctree), leaf_node, pinfo);
798
799
800
}

static void
801
802
get_plugin_info (PDesc       *pdesc,
		 const gchar *search_text)
803
{
Sven Neumann's avatar
Sven Neumann committed
804
  GimpParam *return_vals;
805
  gint nreturn_vals;
806
807
808
809
810
811
812
813
  gint  row_count = 0;
  gchar **menu_strs;
  gchar **accel_strs;
  gchar **prog_strs;
  gchar **types_strs;
  gchar **realname_strs;
  gint  *time_ints;

814
  GHashTable* ghash = g_hash_table_new (g_str_hash, g_str_equal);
815

816
  if (!search_text)
817
818
819
820
    search_text = "";

  return_vals = gimp_run_procedure ("gimp_plugins_query",
                                    &nreturn_vals,
Sven Neumann's avatar
Sven Neumann committed
821
822
				    GIMP_PDB_STRING,search_text,
                                    GIMP_PDB_END);
823

Sven Neumann's avatar
Sven Neumann committed
824
  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
825
826
827
    {
      int loop;
      pdesc->num_plugins = return_vals[1].data.d_int32;
828
829
830
831
832
833
      menu_strs          = return_vals[2].data.d_stringarray;
      accel_strs         = return_vals[4].data.d_stringarray;
      prog_strs          = return_vals[6].data.d_stringarray;
      types_strs         = return_vals[8].data.d_stringarray;
      time_ints          = return_vals[10].data.d_int32array;
      realname_strs      = return_vals[12].data.d_stringarray;
834
835
836

      for (loop = 0; loop < return_vals[1].data.d_int32; loop++)
	{
837
	  PInfo *pinfo;
838
839
840
841
842
843
844
845
846
847
848
849
850
851
	  gchar *labels[4];
	  gchar *name;
	  gchar xtimestr[50];
	  struct tm * x;
	  time_t tx;
	  int ret;

	  name = strrchr (menu_strs[loop], '/');

	  if (name)
	    name = name + 1;
	  else
	    name = menu_strs[loop];

852
	  pinfo = g_new0 (PInfo, 1);
853
854

	  tx = time_ints[loop];
855
	  if (tx)
856
	    {
857
858
	      x = localtime (&tx);
	      ret = strftime (xtimestr, sizeof (xtimestr), "%c", x);
859
860
861
	      xtimestr[ret] = 0;
	    }
	  else
862
	    strcpy (xtimestr,"");
863

864
865
866
867
868
	  pinfo->menu     = g_strdup (menu_strs[loop]);
	  pinfo->accel    = g_strdup (accel_strs[loop]);
	  pinfo->prog     = g_strdup (prog_strs[loop]);
	  pinfo->types    = g_strdup (types_strs[loop]);
	  pinfo->instime  = time_ints[loop];
869
	  pinfo->realname = g_strdup (realname_strs[loop]);
870

871
872
873
874
	  labels[0] = g_strdup (name);
	  labels[1] = g_strdup (xtimestr);
	  labels[2] = g_strdup (menu_strs[loop]);
	  labels[3] = g_strdup (types_strs[loop]);
875

876
	  gtk_clist_insert (GTK_CLIST (pdesc->clist), row_count, labels);
877

878
879
	  gtk_clist_set_row_data_full (GTK_CLIST (pdesc->clist), row_count,
				       pinfo, pinfo_free);
880
881
882
883

	  row_count++;

	  /* Now do the tree view.... */
884
885
886
	  gtk_signal_handler_block_by_func (GTK_OBJECT(pdesc->ctree),
					    GTK_SIGNAL_FUNC (procedure_ctree_select_callback),
					    pdesc);
887
888
889
890
891
892
893
	  insert_into_ctree (pdesc,
			     name,
			     xtimestr,
			     menu_strs[loop],
			     types_strs[loop],
			     ghash,
			     pinfo);
894
895
896
	  gtk_signal_handler_unblock_by_func (GTK_OBJECT (pdesc->ctree),
					      GTK_SIGNAL_FUNC (procedure_ctree_select_callback),
					      pdesc);
897
898
899
900
901
902
903
904
905
906
	}
    }

  gimp_destroy_params (return_vals, nreturn_vals);
}

static void 
dialog_search_callback (GtkWidget *widget, 
			gpointer   data)
{
907
908
  PDesc       *pdesc = data;
  const gchar *search_text = NULL;
909
 
910
  if (widget != NULL)
911
912
    {
      /* The result of a button press... read entry data */
913
      search_text = gtk_entry_get_text (GTK_ENTRY (plugindesc->search_entry));
914
915
    }

916
917
918
919
  gtk_clist_freeze (GTK_CLIST (pdesc->ctree));
  gtk_clist_clear (GTK_CLIST (pdesc->ctree));
  gtk_clist_freeze (GTK_CLIST (pdesc->clist));
  gtk_clist_clear (GTK_CLIST (pdesc->clist));
920

921
  get_plugin_info (pdesc, search_text);
922

923
  gtk_clist_columns_autosize (GTK_CLIST (plugindesc->clist));
924

925
926
927
928
  gtk_clist_sort (GTK_CLIST (pdesc->clist));
  gtk_clist_thaw (GTK_CLIST (pdesc->clist));
  gtk_ctree_sort_recursive (GTK_CTREE (pdesc->ctree), NULL);
  gtk_clist_thaw (GTK_CLIST (pdesc->ctree));
929
930
931
}

static gint
932
933
934
date_sort (GtkCList      *clist,
	   gconstpointer  ptr1,
	   gconstpointer  ptr2)
935
936
937
938
939
{
  GtkCListRow *row1 = (GtkCListRow *) ptr1;
  GtkCListRow *row2 = (GtkCListRow *) ptr2;

  /* Get the data for the row */
940
941
  PInfo *row1_pinfo = row1->data;
  PInfo *row2_pinfo = row2->data;
942
943
944

  /* Want to sort on the date field */

945
  if (row2_pinfo->instime < row1_pinfo->instime)
946
    {
947
      return -1;
948
    }
949
950

  if (row2_pinfo->instime > row1_pinfo->instime)
951
    {
952
      return 1;
953
954
    }

955
  return 0;
956
957
958
}

static void 
959
960
961
clist_click_column (GtkCList *clist, 
		    gint      column, 
		    gpointer  data)
962
963
964
{
  if (column == 1)
    {
965
      gtk_clist_set_compare_func (clist, date_sort);
966
967
968
    }
  else
    {
969
      gtk_clist_set_compare_func (clist, NULL); /* Set back to default */
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
    }

  if (column == clist->sort_column)
    {
      if (clist->sort_type == GTK_SORT_ASCENDING)
	clist->sort_type = GTK_SORT_DESCENDING;
      else
	clist->sort_type = GTK_SORT_ASCENDING;
    }
  else
    gtk_clist_set_sort_column (clist, column);
  
  gtk_clist_sort (clist);
}


static GtkWidget *
987
gimp_plugin_desc (void)
988
{
989
990
991
992
  GtkWidget  *button;
  GtkWidget  *hbox, *searchhbox, *vbox;
  GtkWidget  *label, *notebook, *swindow;
  gchar      *clabels[4];
993

994
  gimp_ui_init ("plugindetails", FALSE);
995

996
  plugindesc = g_new0 (PDesc, 1);
997
998

  /* the dialog box */
999
  plugindesc->dlg =
1000
    gimp_dialog_new (_("Plugin Descriptions"), "plugindetails",
1001
		     gimp_standard_help_func, "filters/plugindetails.html",
1002
1003
1004
		     GTK_WIN_POS_MOUSE,
		     FALSE, TRUE, TRUE,

1005
		     GTK_STOCK_CLOSE, dialog_close_callback,
1006
		     plugindesc, NULL, NULL, TRUE, TRUE,
Sven Neumann's avatar
Sven Neumann committed
1007
1008
		     _("Search by Name"), dialog_search_callback,
		     plugindesc, NULL, NULL, FALSE, FALSE,
1009
1010

		     NULL);
1011
1012
1013

  plugindesc->details_showing = FALSE;

1014
1015
1016
  g_signal_connect (plugindesc->dlg, "destroy",
                    G_CALLBACK (dialog_close_callback),
                    plugindesc);
1017

1018
1019
  /* hbox : left=notebook ; right=description */
  
1020
  plugindesc->paned = hbox = gtk_hpaned_new ();
1021
1022
1023
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (plugindesc->dlg)->vbox), 
		      hbox, TRUE, TRUE, 0);
  gtk_widget_show (hbox);
1024

1025
1026
  /* left = vbox : the list and the search entry */
  
1027
  plugindesc->left_paned = vbox = gtk_vbox_new (FALSE, 0);
1028
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 3); 
1029
1030
  gtk_paned_pack1 (GTK_PANED (hbox), vbox, FALSE, FALSE);
  gtk_widget_show (vbox);
1031
1032
1033

  /* left = notebook */

1034
  notebook = gtk_notebook_new ();
1035
1036
1037
1038
  gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);

  /* list : list in a scrolled_win */
  
1039
1040
1041
1042
1043
  clabels[0] = g_strdup (_("Name")); 
  clabels[1] = g_strdup (_("Ins Date")); 
  clabels[2] = g_strdup (_("Menu Path")); 
  clabels[3] = g_strdup (_("Image Types")); 
  plugindesc->clist = gtk_clist_new_with_titles (4, clabels); 
1044

1045
1046
1047
  g_signal_connect (plugindesc->clist, "click_column",
                    G_CALLBACK (clist_click_column),
                    NULL);
1048
  gtk_clist_column_titles_show (GTK_CLIST (plugindesc->clist));
1049
1050
1051
1052
1053
1054
  swindow = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
				  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_clist_set_selection_mode (GTK_CLIST (plugindesc->clist),
			        GTK_SELECTION_BROWSE);

1055
  gtk_widget_set_size_request (plugindesc->clist, DBL_LIST_WIDTH, DBL_HEIGHT);
1056
1057
1058
  g_signal_connect (plugindesc->clist, "select_row",
                    G_CALLBACK (procedure_clist_select_callback),
                    plugindesc);
1059
  
1060
  label = gtk_label_new (_("List View"));
1061
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), swindow, label);
1062
  gtk_container_add (GTK_CONTAINER (swindow), plugindesc->clist);
1063
1064
  gtk_widget_show (plugindesc->clist);
  gtk_widget_show (swindow);
1065
1066

  /* notebook->ctree */
1067
1068
1069
1070
  clabels[0] = g_strdup (_("Menu Path/Name")); 
  clabels[1] = g_strdup (_("Ins Date")); 
  clabels[2] = g_strdup (_("Image Types")); 
  plugindesc->ctree = gtk_ctree_new_with_titles (3, 0, clabels);  
1071
1072
1073
1074
  plugindesc->ctree_scrolled_win =
    swindow = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
				  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1075
  gtk_widget_set_size_request (plugindesc->ctree, DBL_LIST_WIDTH, DBL_HEIGHT);
1076
1077
1078
  g_signal_connect (plugindesc->ctree, "tree_select_row",
                    G_CALLBACK (procedure_ctree_select_callback),
                    plugindesc);
1079
1080
1081
  gtk_clist_set_column_auto_resize (GTK_CLIST (plugindesc->ctree), 0, TRUE);
  gtk_clist_set_column_auto_resize (GTK_CLIST (plugindesc->ctree), 1, TRUE);
  gtk_clist_set_column_auto_resize (GTK_CLIST (plugindesc->ctree), 2, TRUE);
1082
1083
1084
  gtk_clist_column_titles_passive (GTK_CLIST (plugindesc->ctree));

  label = gtk_label_new (_("Tree View"));
1085
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), swindow, label);
1086
  gtk_container_add (GTK_CONTAINER (swindow), plugindesc->ctree);
1087