plugin-browser.c 30.6 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

#include <gtk/gtk.h>

33
34
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
35

36
#include "libgimp/stdplugins-intl.h"
37

38

39
40
41
#define DBL_LIST_WIDTH  250
#define DBL_WIDTH       (DBL_LIST_WIDTH + 300)
#define DBL_HEIGHT      200
42

43
static gchar *proc_type_str[] =
44
{
45
46
47
48
  N_("Internal GIMP procedure"),
  N_("GIMP Plug-In"),
  N_("GIMP Extension"),
  N_("Temporary Procedure")
49
50
51
52
53
54
};


/* Declare some local functions.
 */
static void   query      (void);
55
56
57
58
59
static void   run        (gchar      *name,
                          gint        nparams,
                          GimpParam  *param,
                          gint       *nreturn_vals,
                          GimpParam **return_vals);
60

61
62
63
64
65
66
67
68
69
70
71
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);
72

73
GimpPlugInInfo PLUG_IN_INFO =
74
{
75
76
77
78
  NULL,  /* init_proc  */
  NULL,  /* quit_proc  */
  query, /* query_proc */
  run,   /* run_proc   */
79
80
81
82
83
84
};


MAIN ()

static void
85
query (void)
86
{
87
  static GimpParamDef args[] =
88
  {
89
    { GIMP_PDB_INT32, "run_mode", "Interactive, [non-interactive]" }
90
  };
91
  static gint nargs = sizeof (args) / sizeof (args[0]);
92

93
  gimp_install_procedure ("plug_in_details",
Marc Lehmann's avatar
Marc Lehmann committed
94
                          "Displays plugin details",
95
96
97
98
99
100
                          "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",
101
102
103
                          "Andy Thomas",
                          "Andy Thomas",
                          "1999",
104
			  N_("<Toolbox>/Xtns/Plugin Details..."),
105
			  "",
Sven Neumann's avatar
Sven Neumann committed
106
                          GIMP_EXTENSION,
107
108
109
110
111
			  nargs, 0,
                          args, NULL);
}

static void
112
113
114
115
116
run (gchar      *name,
     gint        nparams,
     GimpParam  *param,
     gint       *nreturn_vals,
     GimpParam **return_vals)
117
{
118
119
120
  static GimpParam  values[2];
  GimpRunModeType   run_mode;
  GtkWidget        *plugin_dialog;
121
122
123
124

  run_mode = param[0].data.d_int32;

  *nreturn_vals = 1;
125
  *return_vals  = values;
126
127
  values[0].type          = GIMP_PDB_STATUS;
  values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
128

129
130
  INIT_I18N_UI();

131
132
133
134
  if (strcmp (name, "plug_in_details") == 0)
    {
      *nreturn_vals = 1;

135
      values[0].data.d_status = GIMP_PDB_SUCCESS;
136

137
138
      plugin_dialog = gimp_plugin_desc ();

139
140
141
142
143
144
145
146
      gtk_main ();
      gdk_flush ();
    }
}


typedef struct  
{
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
  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;
165
} PDesc;
166

167
PDesc *plugindesc = NULL;
168
169
170
171
172
173
174
175
176

typedef struct
{
  gchar *menu;
  gchar *accel;
  gchar *prog;
  gchar *types;
  gchar *realname;
  gint  instime;
177
} PInfo;
178
179
180
181
182
183

static void
dialog_close_callback (GtkWidget *widget, 
		       gpointer   data)
     /* end of the dialog */
{
184
  PDesc *pdesc = data;
185
  gtk_widget_destroy (pdesc->dlg);
186
187
188
  gtk_main_quit ();
}

189
190
/* Bit of a fiddle but sorta has the effect I want... */

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

199
200
201
202
203
204
205
206
  /* 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, 
207
				      GTK_POLICY_ALWAYS);
208
209
      gtk_widget_set_size_request (pdesc->descr_scroll,
				   DBL_WIDTH - DBL_LIST_WIDTH, -1);
210
211
      gtk_paned_pack2 (GTK_PANED (pdesc->paned), pdesc->descr_scroll,
		       FALSE, TRUE);
212
213
214
      gtk_clist_select_row (GTK_CLIST(pdesc->clist), pdesc->clist_row, -1);
    }

215
  if (pdesc->details_showing == FALSE)
216
    {
217
218
      GTK_PANED (pdesc->paned)->child1_resize = FALSE;
      gtk_label_set_text (lab, _("Details <<"));
219
220
221
222
223
      gtk_widget_show (pdesc->descr_scroll);
      pdesc->details_showing = TRUE;
    }
  else
    {
224
225
226
      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
227

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

static gchar *
237
format_menu_path (gchar *s)
238
{
239
240
  gchar **str_array;
  gchar  *newstr = NULL;
241

242
  if (!s)
243
244
    return s;

245
  str_array = g_strsplit (s, "/", 0);
246

247
  newstr = g_strjoinv ("->", str_array);
248

249
  g_strfreev (str_array);
250
251
252
253
254

  return newstr;
}

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

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

280
281
282
  if (pdesc->descr_scroll == NULL)
    return FALSE;

283
284
285
  selected_proc_blurb     = NULL;
  selected_proc_help      = NULL;
  selected_proc_author    = NULL;
286
  selected_proc_copyright = NULL;
287
288
289
290
291
292
  selected_proc_date      = NULL;
  selected_proc_type      = 0;
  selected_nparams        = 0;
  selected_nreturn_vals   = 0;
  selected_params         = NULL;
  selected_return_vals    = NULL;
293

294
295
296
297
298
299
300
301
302
  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);
303
304
305
306

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

307
  pdesc->info_table = gtk_table_new (10, 5, FALSE);
308
309
  pdesc->info_align = gtk_alignment_new (0.5, 0.5, 0, 0);

310
  gtk_table_set_col_spacings (GTK_TABLE (pdesc->info_table), 3);
311
312
313

  /* Number of plugins */

Sven Neumann's avatar
Sven Neumann committed
314
  str = g_strdup_printf (_("Number of Plugin Interfaces: %d"),
315
316
317
			 pdesc->num_plugins);
  label = gtk_label_new (str);
  g_free (str);
318
319
320
  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);
321
  gtk_widget_show (label);
322
323
  table_row++;

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

  /* menu path */

332
  label = gtk_label_new (_("Menu Path:"));
333
334
335
336
337
  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);

338
  label = gtk_label_new (format_menu_path (pinfo->menu));
339
340
341
  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);
342
  gtk_widget_show (label);
343
344
  table_row++;

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

  /* show the name */

353
  label = gtk_label_new (_("Name:"));
354
355
356
357
358
  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);

359
360
361
  label = gtk_entry_new ();
  gtk_entry_set_text (GTK_ENTRY (label), pinfo->realname);
  gtk_entry_set_editable (GTK_ENTRY (label), FALSE);
362
363
  gtk_table_attach (GTK_TABLE(pdesc->info_table), label,
		    1, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 0, 0);
364
  gtk_widget_show (label);
365
366
  table_row++;

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

  /* show the description */

375
  label = gtk_label_new (_("Blurb:"));
376
377
378
  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);
379
  gtk_widget_show (label);
380

381
  label = gtk_label_new (selected_proc_blurb);
382
383
384
385
386
387
  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++;

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

  /* show the help */
  if ((selected_proc_help) && (strlen(selected_proc_help) > 1))
    {
397
      label = gtk_label_new (_("Help:"));
398
399
400
401
      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);
402
      gtk_widget_show (label);
403
404
405
406
407
408
409
410
411
      
      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
412
413
414
415
416
417
418
419
420
      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);

421
      gtk_widget_set_size_request (text_view, -1, 60);
Hans Breuer's avatar
Hans Breuer committed
422
      gtk_table_attach (GTK_TABLE (help), text_view, 0, 1, 0, 1,
423
424
			GTK_EXPAND | GTK_SHRINK | GTK_FILL,
			GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
Hans Breuer's avatar
Hans Breuer committed
425
      gtk_widget_show (text_view);
426
      
427
      label = gtk_hseparator_new (); /* ok, not really a label ... :) */
428
429
430
431
432
433
434
435
436
      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 */

437
  label = gtk_label_new (_("Type:"));
438
439
440
441
442
  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);

443
  label = gtk_label_new (gettext (proc_type_str[selected_proc_type]));
444
445
446
  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);
447
  gtk_widget_show (label);
448
449
  table_row++;

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

  /* Remove old and replace with new */

458
459
  if (old_table)
    gtk_widget_destroy (old_table);
460

461
462
  if (old_align)
    gtk_widget_destroy (old_align);
463
464
465
466
467
468

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

469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
  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);
486

487
488
489
490
  return FALSE;
}

static void 
491
492
expand_to (PDesc        *pdesc,
	   GtkCTreeNode *parent)
493
494
495
{
  if(parent)
    {
496
497
      expand_to (pdesc, (GTK_CTREE_ROW (parent))->parent);
      gtk_ctree_expand (GTK_CTREE (pdesc->ctree), parent);      
498
499
500
501
    }
}

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

  g_return_val_if_fail (pdesc != NULL, FALSE);

514
  pinfo = (PInfo *) gtk_clist_get_row_data (GTK_CLIST (widget), row);
515

516
  if (!pinfo)
517
518
519
520
    return FALSE;

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

521
522
  found_node = gtk_ctree_find_by_row_data (GTK_CTREE (pdesc->ctree),
					   NULL, pinfo);
523
  
524
  if (found_node)
525
526
527
    {
      GtkCTreeRow   *ctr;
      GtkCTreeNode  *parent;
528
      gint sel_row;
529
530
531

      /* Make sure this is expanded */

532
      ctr = GTK_CTREE_ROW (found_node);
533

534
      parent = GTK_CTREE_NODE (ctr->parent);
535

536
      expand_to (pdesc, parent);
537

538
      sel_row = gtk_clist_find_row_from_data (GTK_CLIST (pdesc->ctree), pinfo);
539

540
541
      gtk_widget_hide (pdesc->ctree); 
      gtk_widget_show (pdesc->ctree); 
542

543
      gtk_signal_handler_block_by_func (GTK_OBJECT(pdesc->ctree),
544
545
					GTK_SIGNAL_FUNC (procedure_ctree_select_callback),
					pdesc);
546

547
548
      gtk_clist_select_row (GTK_CLIST (pdesc->ctree), sel_row, -1);  
      gtk_ctree_select (GTK_CTREE (pdesc->ctree), found_node);
549

550
551
552
553
      gtk_clist_moveto (GTK_CLIST (pdesc->ctree),
			sel_row,
			0,
			0.5, 0.5);
554

555
      gtk_signal_handler_unblock_by_func (GTK_OBJECT (pdesc->ctree),
556
557
					  GTK_SIGNAL_FUNC (procedure_ctree_select_callback),
					  pdesc);
558
559
560
561
562

      pdesc->ctree_row = sel_row;
    }
  else
    {
563
      g_warning ("Failed to find node in ctree");
564
565
    }

566
  return procedure_general_select_callback (pdesc, pinfo);
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
}

/* 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,
582
		      gpointer         data)
583
{
584
  PDesc *pdesc = data;
585

586
  if (page_num == 0)
587
    {
588
589
590
591
592
      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);
593
594
595
    }
  else
    {
596
597
598
599
600
      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);
601
    }
602

603
604
605
606
607
608
  return FALSE;
}

static gint
procedure_ctree_select_callback (GtkWidget *widget,
				 GtkWidget *row, 
609
610
				 gint       column, 
				 gpointer   data)
611
{
612
613
614
615
  PInfo *pinfo;
  PDesc *pdesc;
  gboolean is_leaf;
  gint sel_row;
616
617
618

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

619
620
621
622
623
624
625
626
627
628
  gtk_ctree_get_node_info (GTK_CTREE (widget),
			   GTK_CTREE_NODE (row),
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   NULL,
			   &is_leaf,
			   NULL);
629

630
631
  if (!is_leaf)
    return FALSE;
632
633
634

  pdesc = data;

635
636
  pinfo = (PInfo *) gtk_ctree_node_get_row_data (GTK_CTREE (widget),
						 GTK_CTREE_NODE (row));
637
638
639
640

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

641
  gtk_signal_handler_block_by_func (GTK_OBJECT (pdesc->clist),
642
643
				    GTK_SIGNAL_FUNC (procedure_clist_select_callback),
				    pdesc);
644

645
646
647
648
649
650
  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);
651

652
  gtk_signal_handler_unblock_by_func (GTK_OBJECT (pdesc->clist),
653
654
				      GTK_SIGNAL_FUNC (procedure_clist_select_callback),
				      pdesc);
655
656
657

  pdesc->clist_row = sel_row;
  
658
  return procedure_general_select_callback (pdesc, pinfo);
659
660
661
}

static void
662
pinfo_free (gpointer p)
663
{
664
  PInfo *pinfo = p;
665

666
667
668
669
670
671
  g_free (pinfo->menu);
  g_free (pinfo->accel);
  g_free (pinfo->prog);
  g_free (pinfo->types);
  g_free (pinfo->realname);
  g_free (pinfo);
672
673
}

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

689
  parent = g_hash_table_lookup (ghash, mpath);
690

691
  if (parent)
692
693
    {
      /* found node */
694
      return parent;
695
696
697
    }

  /* Next one up */
698
  tmp_ptr = g_strdup (mpath);
699

700
  str_ptr = strrchr (tmp_ptr,'/');
701

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

713
      *str_ptr = '\000';
714
715

      last_parent = get_parent (pdesc, ghash, tmp_ptr);
716
717
    }

718
719
720
  labels[0] = g_strdup (leaf_ptr); 
  labels[1] = g_strdup (""); 
  labels[2] = g_strdup (""); 
721
722
723

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

724
725
726
727
728
729
730
731
732
733
734
735
736
  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); 
737
738
739
740
741

  return parent;
}

static void
742
743
744
745
746
747
748
insert_into_ctree (PDesc      *pdesc,
		   gchar      *name,
		   gchar      *xtimestr,
		   gchar      *menu_str,
		   gchar      *types_str,
		   GHashTable *ghash,
		   PInfo      *pinfo)
749
750
751
752
753
754
755
756
757
758
759
{
  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 */

760
761
762
763
764
  tmp_ptr = g_strdup (menu_str);

  str_ptr = strrchr (tmp_ptr, '/');

  if (str_ptr == NULL)
765
766
    return; /* No node */

767
  leaf_ptr = g_strdup (str_ptr + 1);
768
769
770
771
772

  *str_ptr = '\000';

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

773
  parent = get_parent (pdesc, ghash, tmp_ptr);
774
775
776

  /* Last was a leaf */
  /*   printf("found leaf %s parent = %p\n",leaf_ptr,parent); */
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
  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);
794
795
796
}

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

810
  GHashTable* ghash = g_hash_table_new (g_str_hash, g_str_equal);
811

812
  if (!search_text)
813
814
815
816
    search_text = "";

  return_vals = gimp_run_procedure ("gimp_plugins_query",
                                    &nreturn_vals,
Sven Neumann's avatar
Sven Neumann committed
817
818
				    GIMP_PDB_STRING,search_text,
                                    GIMP_PDB_END);
819

Sven Neumann's avatar
Sven Neumann committed
820
  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
821
822
823
    {
      int loop;
      pdesc->num_plugins = return_vals[1].data.d_int32;
824
825
826
827
828
829
      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;
830
831
832

      for (loop = 0; loop < return_vals[1].data.d_int32; loop++)
	{
833
	  PInfo *pinfo;
834
835
836
837
838
839
840
841
842
843
844
845
846
847
	  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];

848
	  pinfo = g_new0 (PInfo, 1);
849
850

	  tx = time_ints[loop];
851
	  if (tx)
852
	    {
853
854
	      x = localtime (&tx);
	      ret = strftime (xtimestr, sizeof (xtimestr), "%c", x);
855
856
857
	      xtimestr[ret] = 0;
	    }
	  else
858
	    strcpy (xtimestr,"");
859

860
861
862
863
864
	  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];
865
	  pinfo->realname = g_strdup (realname_strs[loop]);
866

867
868
869
870
	  labels[0] = g_strdup (name);
	  labels[1] = g_strdup (xtimestr);
	  labels[2] = g_strdup (menu_strs[loop]);
	  labels[3] = g_strdup (types_strs[loop]);
871

872
	  gtk_clist_insert (GTK_CLIST (pdesc->clist), row_count, labels);
873

874
875
	  gtk_clist_set_row_data_full (GTK_CLIST (pdesc->clist), row_count,
				       pinfo, pinfo_free);
876
877
878
879

	  row_count++;

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

  gimp_destroy_params (return_vals, nreturn_vals);
}

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

912
913
914
915
  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));
916

917
  get_plugin_info (pdesc, search_text);
918

919
  gtk_clist_columns_autosize (GTK_CLIST (plugindesc->clist));
920

921
922
923
924
  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));
925
926
927
}

static gint
928
929
930
date_sort (GtkCList      *clist,
	   gconstpointer  ptr1,
	   gconstpointer  ptr2)
931
932
933
934
935
{
  GtkCListRow *row1 = (GtkCListRow *) ptr1;
  GtkCListRow *row2 = (GtkCListRow *) ptr2;

  /* Get the data for the row */
936
937
  PInfo *row1_pinfo = row1->data;
  PInfo *row2_pinfo = row2->data;
938
939
940

  /* Want to sort on the date field */

941
  if (row2_pinfo->instime < row1_pinfo->instime)
942
    {
943
      return -1;
944
    }
945
946

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

951
  return 0;
952
953
954
}

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

  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 *
983
gimp_plugin_desc (void)
984
{
985
986
987
988
  GtkWidget  *button;
  GtkWidget  *hbox, *searchhbox, *vbox;
  GtkWidget  *label, *notebook, *swindow;
  gchar      *clabels[4];
989

990
  gimp_ui_init ("plugindetails", FALSE);
991

992
  plugindesc = g_new0 (PDesc, 1);
993
994

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

		     _("Search by Name"), dialog_search_callback,
		     plugindesc, NULL, NULL, FALSE, FALSE,
1003
		     GTK_STOCK_CLOSE, dialog_close_callback,
1004
1005
1006
		     plugindesc, NULL, NULL, TRUE, TRUE,

		     NULL);
1007
1008
1009
1010

  plugindesc->details_showing = FALSE;

  gtk_signal_connect (GTK_OBJECT (plugindesc->dlg), "destroy",
1011
                      GTK_SIGNAL_FUNC (dialog_close_callback),
1012
		      plugindesc);
1013

1014
1015
  /* hbox : left=notebook ; right=description */
  
1016
  plugindesc->paned = hbox = gtk_hpaned_new ();
1017
1018
1019
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (plugindesc->dlg)->vbox), 
		      hbox, TRUE, TRUE, 0);
  gtk_widget_show (hbox);
1020

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

  /* left = notebook */

1030
  notebook = gtk_notebook_new ();
1031
1032
1033
1034
  gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);

  /* list : list in a scrolled_win */
  
1035
1036
1037
1038
1039
  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); 
1040
1041

  gtk_signal_connect (GTK_OBJECT (plugindesc->clist), "click_column",
1042
1043
		      GTK_SIGNAL_FUNC (clist_click_column),
		      NULL);
1044
  gtk_clist_column_titles_show (GTK_CLIST (plugindesc->clist));
1045
1046
1047
1048
1049
1050
  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);

1051
  gtk_widget_set_size_request (plugindesc->clist, DBL_LIST_WIDTH, DBL_HEIGHT);
1052
  gtk_signal_connect (GTK_OBJECT (plugindesc->clist), "select_row",
1053
		      GTK_SIGNAL_FUNC (procedure_clist_select_callback),
1054
1055
		      plugindesc);
  
1056
  label = gtk_label_new (_("List View"));
1057
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), swindow, label);
1058
  gtk_container_add (GTK_CONTAINER (swindow), plugindesc->clist);
1059
1060
  gtk_widget_show (plugindesc->clist);
  gtk_widget_show (swindow);
1061
1062

  /* notebook->ctree */
1063
1064
1065
1066
  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);  
1067
1068
1069
1070
  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);
1071
  gtk_widget_set_size_request (plugindesc->ctree, DBL_LIST_WIDTH, DBL_HEIGHT);
1072
  gtk_signal_connect (GTK_OBJECT (plugindesc->ctree), "tree_select_row",
1073
		      GTK_SIGNAL_FUNC (procedure_ctree_select_callback),
1074
1075
1076
1077
		      plugindesc);
  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);
1078
1079
1080
  gtk_clist_column_titles_passive (GTK_CLIST (plugindesc->ctree));

  label = gtk_label_new (_("Tree View"));
1081
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), swindow, label);
1082
  gtk_container_add (GTK_CONTAINER (swindow), plugindesc->ctree);
1083

1084
1085
  gtk_widget_show (plugindesc->ctree);
  gtk_widget_show (swindow);
1086
1087

  gtk_signal_connect_after (GTK_OBJECT (notebook), "switch_page",
1088
			    GTK_SIGNAL_FUNC (page_select_callback),
1089
1090
			    plugindesc);
  
1091
  gtk_widget_show (notebook);
1092
1093
1094

  /* search entry & details button */

1095
  searchhbox = gtk_hbox_new (FALSE, 4);
1096
  gtk_box_pack_start (GTK_BOX (vbox),
1097
		      searchhbox, FALSE, FALSE, 0);
1098
  gtk_widget_show (searchhbox);
1099

1100
1101
  label = gtk_label_new (_("Search:"));
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
1102
  gtk_box_pack_start (GTK_BOX (searchhbox), 
1103
		      label, FALSE, FALSE, 0);
1104
1105
  gtk_widget_show(label);

1106
  plugindesc->search_entry = gtk_entry_new ();
1107
1108
  gtk_box_pack_start (GTK_BOX (searchhbox), 
		      plugindesc->search_entry, TRUE, TRUE, 0);