plugin-browser.c 30.3 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 "gimpprocbox.h"
37
38
#include "gimpprocview.h"

39
#include "libgimp/stdplugins-intl.h"
40

41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
enum
{
  LIST_NAME_COLUMN,
  LIST_DATE_COLUMN,
  LIST_PATH_COLUMN,
  LIST_IMAGE_TYPES_COLUMN,
  LIST_PINFO_COLUMN,
  LIST_N_COLUMNS
};

enum
{
  TREE_PATH_NAME_COLUMN,
  TREE_DATE_COLUMN,
  TREE_IMAGE_TYPES_COLUMN,
  TREE_MPATH_COLUMN,
  TREE_PINFO_COLUMN,
  TREE_N_COLUMNS
};

62
#define DBL_LIST_WIDTH  250
63
64
#define DBL_WIDTH       (DBL_LIST_WIDTH + 400)
#define DBL_HEIGHT      250
65

66
typedef struct
67
{
68
69
  GtkWidget   *dialog;

70
71
  GtkTreeView *list_view;
  GtkTreeView *tree_view;
72
73

  GtkWidget   *count_label;
74
  GtkWidget   *search_entry;
75
76
  GtkWidget   *proc_box;

77
  gint         num_plugins;
78
} PluginBrowser;
79
80
81
82
83
84
85
86
87
88
89

typedef struct
{
  gchar *menu;
  gchar *accel;
  gchar *prog;
  gchar *types;
  gchar *realname;
  gint  instime;
} PInfo;

90
91
92
93

/* Declare some local functions.
 */
static void   query      (void);
94
95
96
97
98
static void   run        (const gchar      *name,
                          gint              nparams,
                          const GimpParam  *param,
                          gint             *nreturn_vals,
                          GimpParam       **return_vals);
99

100

101
102
103
104
105
106
107
108
109
110
static GtkWidget * browser_dialog_new             (void);
static void        browser_dialog_response        (GtkWidget        *widget,
                                                   gint              response_id,
                                                   PluginBrowser    *browser);
static void        browser_list_selection_changed (GtkTreeSelection *selection,
                                                   PluginBrowser    *browser);
static void        browser_tree_selection_changed (GtkTreeSelection *selection,
                                                   PluginBrowser    *browser);
static void        browser_show_plugin            (PluginBrowser    *browser,
                                                   PInfo            *pinfo);
111

112
113
114
static gboolean    find_existing_mpath            (GtkTreeModel     *model,
                                                   gchar            *mpath,
                                                   GtkTreeIter      *return_iter);
115

116
117


118
static PluginBrowser *browser = NULL;
119

120
GimpPlugInInfo PLUG_IN_INFO =
121
{
122
123
124
125
  NULL,  /* init_proc  */
  NULL,  /* quit_proc  */
  query, /* query_proc */
  run,   /* run_proc   */
126
127
128
129
130
};


MAIN ()

131

132
static void
133
query (void)
134
{
135
  static GimpParamDef args[] =
136
  {
137
    { GIMP_PDB_INT32, "run_mode", "Interactive, [non-interactive]" }
138
  };
139

140
  gimp_install_procedure ("plug_in_plug_in_details",
Sven Neumann's avatar
Sven Neumann committed
141
142
143
                          "Displays plug-in details",
                          "Allows to browse the plug-in menus system. You can "
                          "search for plug-in names, sort by name or menu "
144
                          "location and you can view a tree representation "
Sven Neumann's avatar
Sven Neumann committed
145
146
147
                          "of the plug-in menus. Can also be of help to find "
                          "where new plug-ins have installed themselves in "
                          "the menus.",
148
149
150
                          "Andy Thomas",
                          "Andy Thomas",
                          "1999",
Sven Neumann's avatar
Sven Neumann committed
151
                          N_("_Plug-In Browser"),
152
                          "",
153
                          GIMP_PLUGIN,
154
                          G_N_ELEMENTS (args), 0,
155
                          args, NULL);
156
157

  gimp_plugin_menu_register ("plug_in_plug_in_details",
158
                             "<Toolbox>/Xtns/Extensions");
159
  gimp_plugin_icon_register ("plug_in_plug_in_details",
160
                             GIMP_ICON_TYPE_STOCK_ID, GIMP_STOCK_PLUGIN);
161
162
163
}

static void
164
165
166
167
168
run (const gchar      *name,
     gint              nparams,
     const GimpParam  *param,
     gint             *nreturn_vals,
     GimpParam       **return_vals)
169
{
170
  static GimpParam  values[2];
171
  GimpRunMode       run_mode;
172
173
174
175

  run_mode = param[0].data.d_int32;

  *nreturn_vals = 1;
176
  *return_vals  = values;
177

178
179
  values[0].type          = GIMP_PDB_STATUS;
  values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
180

181
  INIT_I18N ();
182

183
  if (strcmp (name, "plug_in_plug_in_details") == 0)
184
    {
185
186
      GtkWidget *plugin_dialog;

187
188
      *nreturn_vals = 1;

189
      values[0].data.d_status = GIMP_PDB_SUCCESS;
190

191
      plugin_dialog = browser_dialog_new ();
192

193
194
195
196
      gtk_main ();
    }
}

197
#if 0
198
static void
199
pinfo_free (gpointer p)
200
{
201
  PInfo *pinfo = p;
202

203
204
205
206
207
208
  g_free (pinfo->menu);
  g_free (pinfo->accel);
  g_free (pinfo->prog);
  g_free (pinfo->types);
  g_free (pinfo->realname);
  g_free (pinfo);
209
}
210
#endif
211

212
213
214
215
216
217
static gboolean
find_existing_mpath_helper (GtkTreeModel *model,
                            GtkTreeIter  *iter,
                            GtkTreePath  *path,
                            gchar        *mpath,
                            GtkTreeIter  *return_iter)
218
{
219
220
221
222
  do
    {
      GtkTreeIter  child;
      gchar       *picked_mpath;
223

224
      gtk_tree_model_get (model, iter,
225
226
                          TREE_MPATH_COLUMN, &picked_mpath,
                          -1);
227
228
229
230
231
232
233

      if (! strcmp (mpath, picked_mpath))
        {
          *return_iter = *iter;
          g_free (picked_mpath);
          return TRUE;
        }
234
235
236
237

      if (gtk_tree_model_iter_children (model, &child, iter))
        {
          gtk_tree_path_down (path);
238

239
          if (find_existing_mpath_helper (model, &child, path,
240
241
242
243
244
245
                                          mpath, return_iter))
            {
              g_free (picked_mpath);
              return TRUE;
            }

246
247
          gtk_tree_path_up (path);
        }
248

249
250
251
252
      gtk_tree_path_next (path);
      g_free (picked_mpath);
    }
  while (gtk_tree_model_iter_next (model, iter));
253

254
255
256
257
258
259
260
261
262
263
264
265
  return FALSE;
}

static gboolean
find_existing_mpath (GtkTreeModel *model,
                     gchar        *mpath,
                     GtkTreeIter  *return_iter)
{
  GtkTreePath *path;
  GtkTreeIter  parent;

  path = gtk_tree_path_new_first ();
266

267
  if (gtk_tree_model_get_iter (model, &parent, path) == FALSE)
268
    {
269
270
      gtk_tree_path_free (path);
      return FALSE;
271
272
    }

273
274
275
276
277
278
  return find_existing_mpath_helper (model, &parent, path,
                                     mpath, return_iter);
  gtk_tree_path_free (path);
}

static void
279
280
281
get_parent (PluginBrowser *browser,
            gchar         *mpath,
            GtkTreeIter   *parent)
282
283
284
285
286
287
288
289
290
291
{
  GtkTreeIter   last_parent;
  gchar        *tmp_ptr;
  gchar        *str_ptr;
  gchar        *leaf_ptr;
  GtkTreeStore *tree_store;

  if (mpath == NULL)
    return;

292
  tree_store = GTK_TREE_STORE (gtk_tree_view_get_model (browser->tree_view));
293
294
295
296
297

  /* Lookup for existing mpath */
  if (find_existing_mpath (GTK_TREE_MODEL (tree_store), mpath, parent))
    return;

298
  /* Next one up */
299
  tmp_ptr = g_strdup (mpath);
300

301
  str_ptr = strrchr (tmp_ptr,'/');
302

303
  if (str_ptr == NULL)
304
305
    {
      leaf_ptr = mpath;
306
307
308
309
310
      gtk_tree_store_append (tree_store, parent, NULL);
      gtk_tree_store_set (tree_store, parent,
                          TREE_MPATH_COLUMN, mpath,
                          TREE_PATH_NAME_COLUMN, mpath,
                          -1);
311
312
313
314
    }
  else
    {
      leaf_ptr = g_strdup(str_ptr+1);
315

316
      *str_ptr = '\000';
317

318
      get_parent (browser, tmp_ptr, &last_parent);
319
320
321
322
323
      gtk_tree_store_append (tree_store, parent, &last_parent);
      gtk_tree_store_set (tree_store, parent,
                          TREE_MPATH_COLUMN, mpath,
                          TREE_PATH_NAME_COLUMN, leaf_ptr,
                          -1);
324
325
326
327
    }
}

static void
328
329
330
331
332
333
insert_into_tree_view (PluginBrowser *browser,
                       gchar         *name,
                       gchar         *xtimestr,
                       gchar         *menu_str,
                       gchar         *types_str,
                       PInfo         *pinfo)
334
{
335
336
337
338
339
  gchar        *labels[3];
  gchar        *str_ptr;
  gchar        *tmp_ptr;
  gchar        *leaf_ptr;
  GtkTreeIter   parent, iter;
340
  GtkTreeStore *tree_store;
341
342
343
344

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

345
346
347
348
349
  tmp_ptr = g_strdup (menu_str);

  str_ptr = strrchr (tmp_ptr, '/');

  if (str_ptr == NULL)
350
351
    return; /* No node */

352
  leaf_ptr = g_strdup (str_ptr + 1);
353
354
355
356
357

  *str_ptr = '\000';

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

358
  get_parent (browser, tmp_ptr, &parent);
359
360
361

  /* Last was a leaf */
  /*   printf("found leaf %s parent = %p\n",leaf_ptr,parent); */
362
363
364
365
  labels[0] = g_strdup (name);
  labels[1] = g_strdup (xtimestr);
  labels[2] = g_strdup (types_str);

366
  tree_store = GTK_TREE_STORE (gtk_tree_view_get_model (browser->tree_view));
367
368
  gtk_tree_store_append (tree_store, &iter, &parent);
  gtk_tree_store_set (tree_store, &iter,
369
370
                      TREE_MPATH_COLUMN,       menu_str,
                      TREE_PATH_NAME_COLUMN,   name,
371
                      TREE_IMAGE_TYPES_COLUMN, types_str,
372
373
                      TREE_DATE_COLUMN,        xtimestr,
                      TREE_PINFO_COLUMN,       pinfo,
374
                      -1);
375
376
377
}

static void
378
379
get_plugin_info (PluginBrowser *browser,
                 const gchar   *search_text)
380
{
381
382
383
384
385
386
387
388
389
390
391
  GimpParam    *return_vals;
  gint          nreturn_vals;
  gchar       **menu_strs;
  gchar       **accel_strs;
  gchar       **prog_strs;
  gchar       **types_strs;
  gchar       **realname_strs;
  gint         *time_ints;
  GtkListStore *list_store;
  GtkTreeStore *tree_store;
  GtkTreeIter   iter;
392

393
  if (! search_text)
394
395
    search_text = "";

396
397
398
  gimp_proc_box_show_message (browser->proc_box,
                              _("Searching by name - please wait"));

399
400
  return_vals = gimp_run_procedure ("gimp_plugins_query",
                                    &nreturn_vals,
401
                                    GIMP_PDB_STRING, search_text,
Sven Neumann's avatar
Sven Neumann committed
402
                                    GIMP_PDB_END);
403

Sven Neumann's avatar
Sven Neumann committed
404
  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
405
    {
406
407
408
409
410
411
412
413
414
415
416
      gchar *str;
      gint   loop;

      browser->num_plugins = return_vals[1].data.d_int32;
      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;

417
418
419
420
421
422
      if (browser->num_plugins == 1)
        str = g_strdup (_("1 Plug-In Interface"));
      else
        str = g_strdup_printf (_("%d Plug-In Interfaces"),
                               browser->num_plugins);

423
424
425
426
      gtk_label_set_text (GTK_LABEL (browser->count_label), str);
      g_free (str);

      list_store = GTK_LIST_STORE (gtk_tree_view_get_model (browser->list_view));
427
428
      gtk_list_store_clear (list_store);

429
      tree_store = GTK_TREE_STORE (gtk_tree_view_get_model (browser->tree_view));
430
431
      gtk_tree_store_clear (tree_store);

432
      for (loop = 0; loop < return_vals[1].data.d_int32; loop++)
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
        {
          PInfo     *pinfo;
          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];

          pinfo = g_new0 (PInfo, 1);

          tx = time_ints[loop];
          if (tx)
            {
453
              const gchar *format = "%c";  /* gcc workaround to avoid warning */
454
              gchar       *utf8;
455

456
              x = localtime (&tx);
457
              ret = strftime (xtimestr, sizeof (xtimestr), format, x);
458
              xtimestr[ret] = 0;
459
460
461
462
463
464
465

              if ((utf8 = g_locale_to_utf8 (xtimestr, -1, NULL, NULL, NULL)))
                {
                  strncpy (xtimestr, utf8, sizeof (xtimestr));
                  xtimestr[sizeof (xtimestr) - 1] = 0;
                  g_free (utf8);
                }
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
            }
          else
            strcpy (xtimestr,"");

          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];
          pinfo->realname = g_strdup (realname_strs[loop]);

          gtk_list_store_append (list_store, &iter);
          gtk_list_store_set (list_store, &iter,
                              LIST_NAME_COLUMN,        name,
                              LIST_DATE_COLUMN,        xtimestr,
                              LIST_PATH_COLUMN,        menu_strs[loop],
                              LIST_IMAGE_TYPES_COLUMN, types_strs[loop],
                              LIST_PINFO_COLUMN,       pinfo,
                              -1);

          /* Now do the tree view.... */
487
          insert_into_tree_view (browser,
488
489
490
491
492
493
                                 name,
                                 xtimestr,
                                 menu_strs[loop],
                                 types_strs[loop],
                                 pinfo);
        }
494
495
496
497

      gtk_tree_view_columns_autosize (GTK_TREE_VIEW (browser->list_view));
      gtk_tree_view_columns_autosize (GTK_TREE_VIEW (browser->tree_view));

498
499
500
      gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_store),
                                            LIST_NAME_COLUMN,
                                            GTK_SORT_ASCENDING);
501
502
503
      gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (tree_store),
                                            TREE_PATH_NAME_COLUMN,
                                            GTK_SORT_ASCENDING);
504

505
506
507
508
      if (browser->num_plugins)
        {
          GtkTreeSelection *sel =
            gtk_tree_view_get_selection (GTK_TREE_VIEW (browser->list_view));
509

510
511
          gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store),
                                         &iter);
512
513
          gtk_tree_selection_select_iter (sel, &iter);
        }
514
      else
515
        {
516
          gimp_proc_box_show_message (browser->proc_box, _("No matches"));
517
        }
518
    }
519
520

  gimp_destroy_params (return_vals, nreturn_vals);
521
}
522
523

static GtkWidget *
524
browser_dialog_new (void)
525
{
526
527
  GtkWidget         *paned;
  GtkWidget         *hbox, *vbox;
528
529
530
531
532
533
534
535
536
  GtkWidget         *label, *notebook, *swindow;
  GtkListStore      *list_store;
  GtkTreeStore      *tree_store;
  GtkWidget         *list_view;
  GtkWidget         *tree_view;
  GtkTreeViewColumn *column;
  GtkCellRenderer   *renderer;
  GtkTreeSelection  *selection;
  GtkTreeIter        iter;
537

538
  gimp_ui_init ("plugindetails", FALSE);
539

540
  browser = g_new0 (PluginBrowser, 1);
541
542

  /* the dialog box */
543
  browser->dialog =
Sven Neumann's avatar
Sven Neumann committed
544
    gimp_dialog_new (_("Plug-In Browser"), "plugindetails",
545
                     NULL, 0,
546
                     gimp_standard_help_func, "plug-in-plug-in-details",
547

548
549
                     _("Search by _Name"), GTK_RESPONSE_OK,
                     GTK_STOCK_CLOSE,      GTK_RESPONSE_CLOSE,
550

551
                     NULL);
552

553
  g_signal_connect (browser->dialog, "response",
554
                    G_CALLBACK (browser_dialog_response),
555
                    browser);
556

557
  /* paned : left=notebook ; right=description */
558

559
560
561
562
563
  paned = gtk_hpaned_new ();
  gtk_container_set_border_width (GTK_CONTAINER (paned), 12);
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (browser->dialog)->vbox),
                     paned);
  gtk_widget_show (paned);
564

565
  /* left = vbox : the list and the search entry */
566

567
  vbox = gtk_vbox_new (FALSE, 6);
568
  gtk_paned_pack1 (GTK_PANED (paned), vbox, FALSE, TRUE);
569
  gtk_widget_show (vbox);
570

Sven Neumann's avatar
Sven Neumann committed
571
  browser->count_label = gtk_label_new ("0 Plug-In Interfaces");
572
573
574
575
  gtk_misc_set_alignment (GTK_MISC (browser->count_label), 0.0, 0.5);
  gtk_box_pack_start (GTK_BOX (vbox), browser->count_label, FALSE, FALSE, 0);
  gtk_widget_show (browser->count_label);

576
577
  /* left = notebook */

578
  notebook = gtk_notebook_new ();
579
580
581
  gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);

  /* list : list in a scrolled_win */
582
583
584
585
586
587
588
589
590
591
  list_store = gtk_list_store_new (LIST_N_COLUMNS,
                                   G_TYPE_STRING,
                                   G_TYPE_STRING,
                                   G_TYPE_STRING,
                                   G_TYPE_STRING,
                                   G_TYPE_POINTER);

  list_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
  g_object_unref (list_store);

592
  browser->list_view = GTK_TREE_VIEW (list_view);
593
594

  renderer = gtk_cell_renderer_text_new ();
595
596
  column = gtk_tree_view_column_new_with_attributes (_("Name"),
                                                     renderer,
597
                                                     "text", LIST_NAME_COLUMN,
598
                                                     NULL);
599
  gtk_tree_view_column_set_sort_column_id  (column, LIST_NAME_COLUMN);
600
601
602
  gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);

  renderer = gtk_cell_renderer_text_new ();
603
  column = gtk_tree_view_column_new_with_attributes (_("Insertion Date"),
604
                                                     renderer,
605
                                                     "text", LIST_DATE_COLUMN,
606
                                                     NULL);
607
  gtk_tree_view_column_set_sort_column_id  (column, LIST_DATE_COLUMN);
608
609
610
  gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);

  renderer = gtk_cell_renderer_text_new ();
611
  column = gtk_tree_view_column_new_with_attributes (_("Menu Path"),
612
                                                     renderer,
613
                                                     "text", LIST_PATH_COLUMN,
614
                                                     NULL);
615
  gtk_tree_view_column_set_sort_column_id  (column, LIST_PATH_COLUMN);
616
617
618
  gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);

  renderer = gtk_cell_renderer_text_new ();
619
  column = gtk_tree_view_column_new_with_attributes (_("Image Types"),
620
621
622
623
                                                     renderer,
                                                     "text",
                                                     LIST_IMAGE_TYPES_COLUMN,
                                                     NULL);
624
  gtk_tree_view_column_set_sort_column_id  (column, LIST_IMAGE_TYPES_COLUMN);
625
626
  gtk_tree_view_append_column (GTK_TREE_VIEW (list_view), column);

627
  swindow = gtk_scrolled_window_new (NULL, NULL);
628
629
630
  gtk_container_set_border_width (GTK_CONTAINER (swindow), 2);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow),
                                       GTK_SHADOW_IN);
631
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
632
633
634
                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

  gtk_widget_set_size_request (list_view, DBL_LIST_WIDTH, DBL_HEIGHT);
635

636
637
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list_view));
  gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
638

639
  g_signal_connect (selection, "changed",
640
                    G_CALLBACK (browser_list_selection_changed),
641
                    browser);
642

643
  label = gtk_label_new (_("List View"));
644
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), swindow, label);
645
646
  gtk_container_add (GTK_CONTAINER (swindow), list_view);
  gtk_widget_show (list_view);
647
  gtk_widget_show (swindow);
648
649

  /* notebook->ctree */
650
651
652
653
654
655
656
657
658
659
  tree_store = gtk_tree_store_new (LIST_N_COLUMNS,
                                   G_TYPE_STRING,
                                   G_TYPE_STRING,
                                   G_TYPE_STRING,
                                   G_TYPE_STRING,
                                   G_TYPE_POINTER);

  tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (tree_store));
  g_object_unref (tree_store);

660
  browser->tree_view = GTK_TREE_VIEW (tree_view);
661
662

  renderer = gtk_cell_renderer_text_new ();
663
  column = gtk_tree_view_column_new_with_attributes (_("Menu Path/Name"),
664
665
666
667
                                                     renderer,
                                                     "text",
                                                     TREE_PATH_NAME_COLUMN,
                                                     NULL);
668
  gtk_tree_view_column_set_sort_column_id  (column, TREE_PATH_NAME_COLUMN);
669
670
671
  gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);

  renderer = gtk_cell_renderer_text_new ();
672
  column = gtk_tree_view_column_new_with_attributes (_("Insertion Date"),
673
674
675
676
                                                     renderer,
                                                     "text",
                                                     TREE_DATE_COLUMN,
                                                     NULL);
677
  gtk_tree_view_column_set_sort_column_id  (column, TREE_DATE_COLUMN);
678
679
680
  gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);

  renderer = gtk_cell_renderer_text_new ();
681
  column = gtk_tree_view_column_new_with_attributes (_("Image Types"),
682
683
684
685
                                                     renderer,
                                                     "text",
                                                     TREE_IMAGE_TYPES_COLUMN,
                                                     NULL);
686
  gtk_tree_view_column_set_sort_column_id  (column, TREE_IMAGE_TYPES_COLUMN);
687
688
689
  gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);

  swindow = gtk_scrolled_window_new (NULL, NULL);
690
691
692
  gtk_container_set_border_width (GTK_CONTAINER (swindow), 2);
  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow),
                                       GTK_SHADOW_IN);
693
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
694
695
696
697
698
                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_widget_set_size_request (tree_view, DBL_LIST_WIDTH, DBL_HEIGHT);

  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
  gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
699

700
  g_signal_connect (selection, "changed",
701
                    G_CALLBACK (browser_tree_selection_changed),
702
                    browser);
703

704
  label = gtk_label_new (_("Tree View"));
705
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), swindow, label);
706
  gtk_container_add (GTK_CONTAINER (swindow), tree_view);
707

708
  gtk_widget_show (tree_view);
709
710
  gtk_widget_show (swindow);
  gtk_widget_show (notebook);
711
712
713

  /* search entry & details button */

714
715
716
717
718
719
720
721
722
723
724
725
726
727
  hbox = gtk_hbox_new (FALSE, 6);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  label = gtk_label_new_with_mnemonic (_("_Search:"));
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  browser->search_entry = gtk_entry_new ();
  gtk_entry_set_activates_default (GTK_ENTRY (browser->search_entry), TRUE);
  gtk_box_pack_start (GTK_BOX (hbox), browser->search_entry, TRUE, TRUE, 0);
  gtk_widget_show (browser->search_entry);

  gtk_label_set_mnemonic_widget (GTK_LABEL (label), browser->search_entry);
728
729

  /* right = description */
730

731
732
  browser->proc_box = gimp_proc_box_new ();
  gtk_widget_set_size_request (browser->proc_box,
733
                               DBL_WIDTH - DBL_LIST_WIDTH, -1);
734
735
  gtk_paned_pack2 (GTK_PANED (paned), browser->proc_box, TRUE, TRUE);
  gtk_widget_show (browser->proc_box);
736

737
  /* now build the list */
738
  browser_dialog_response (NULL, GTK_RESPONSE_OK, browser);
739

740
  gtk_widget_show (browser->dialog);
741

742
  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list_store), &iter))
743
744
    gtk_tree_selection_select_iter (gtk_tree_view_get_selection (GTK_TREE_VIEW (list_view)),
                                    &iter);
745

746
  gtk_widget_grab_focus (browser->search_entry);
747

748
  return browser->dialog;
749
}
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904

static void
browser_dialog_response (GtkWidget     *widget,
                         gint           response_id,
                         PluginBrowser *browser)
{
  const gchar *search_text = NULL;

  switch (response_id)
    {
    case GTK_RESPONSE_OK:
      search_text = gtk_entry_get_text (GTK_ENTRY (browser->search_entry));
      get_plugin_info (browser, search_text);
      break;

    default:
      gtk_widget_destroy (browser->dialog);
      gtk_main_quit ();
      break;
    }
}

static void
browser_list_selection_changed (GtkTreeSelection *selection,
                                PluginBrowser    *browser)
{
  PInfo        *pinfo = NULL;
  GtkTreeIter   iter;
  GtkTreeModel *model;
  gchar        *mpath = NULL;

  g_return_if_fail (browser != NULL);

  if (gtk_tree_selection_get_selected (selection, &model, &iter))
    {
      gtk_tree_model_get (model, &iter,
                          LIST_PINFO_COLUMN, &pinfo,
                          LIST_PATH_COLUMN,  &mpath,
                          -1);
    }

  if (!pinfo || !mpath)
    return;

  model = gtk_tree_view_get_model (browser->tree_view);

  if (find_existing_mpath (model, mpath, &iter))
    {
      GtkTreeSelection *tree_selection;
      GtkTreePath      *tree_path;

      tree_path = gtk_tree_model_get_path (model, &iter);
      gtk_tree_view_expand_to_path (browser->tree_view, tree_path);
      tree_selection = gtk_tree_view_get_selection (browser->tree_view);

      g_signal_handlers_block_by_func (tree_selection,
                                       browser_tree_selection_changed,
                                       browser);
      gtk_tree_selection_select_iter (tree_selection, &iter);
      g_signal_handlers_unblock_by_func (tree_selection,
                                         browser_tree_selection_changed,
                                         browser);

      gtk_tree_view_scroll_to_cell (browser->tree_view,
                                    tree_path, NULL,
                                    TRUE, 0.5, 0.0);
    }
  else
    {
      g_warning ("Failed to find node in tree");
    }

  g_free (mpath);

  browser_show_plugin (browser, pinfo);
}

static void
browser_tree_selection_changed (GtkTreeSelection *selection,
                                PluginBrowser    *browser)
{
  PInfo        *pinfo = NULL;
  GtkTreeIter   iter;
  GtkTreeModel *model;
  gchar        *mpath = NULL;
  gboolean      valid, found;

  g_return_if_fail (browser != NULL);

  if (gtk_tree_selection_get_selected (selection, &model, &iter))
    {
      gtk_tree_model_get (model, &iter,
                          TREE_PINFO_COLUMN, &pinfo,
                          TREE_MPATH_COLUMN, &mpath,
                          -1);
    }

  if (!pinfo || !mpath)
    return;

  /* Get the first iter in the list */
  model = gtk_tree_view_get_model (browser->list_view);
  valid = gtk_tree_model_get_iter_first (model, &iter);
  found = FALSE;

  while (valid)
    {
      /* Walk through the list, reading each row */
      gchar *picked_mpath;

      gtk_tree_model_get (model, &iter,
                          LIST_PATH_COLUMN, &picked_mpath,
                          -1);
      if (picked_mpath && !strcmp (mpath, picked_mpath))
        {
          found = TRUE;
          break;
        }
      g_free (picked_mpath);
      valid = gtk_tree_model_iter_next (model, &iter);
    }
  g_free (mpath);

  if (found)
    {
      GtkTreeSelection *list_selection;
      GtkTreePath      *tree_path;

      tree_path = gtk_tree_model_get_path (model, &iter);
      list_selection = gtk_tree_view_get_selection (browser->list_view);

      g_signal_handlers_block_by_func (list_selection,
                                       browser_list_selection_changed,
                                       browser);
      gtk_tree_selection_select_iter (list_selection, &iter);
      g_signal_handlers_unblock_by_func (list_selection,
                                         browser_list_selection_changed,
                                         browser);

      gtk_tree_view_scroll_to_cell (browser->list_view,
                                    tree_path, NULL,
                                    TRUE, 0.5, 0.0);
    }
  else
    {
      g_warning ("Failed to find node in list");
    }

  browser_show_plugin (browser, pinfo);
}

static void
browser_show_plugin (PluginBrowser *browser,
                     PInfo         *pinfo)
{
905
906
907
908
909
910
911
912
913
914
  gchar           *blurb         = NULL;
  gchar           *help          = NULL;
  gchar           *author        = NULL;
  gchar           *copyright     = NULL;
  gchar           *date          = NULL;
  GimpPDBProcType  type          = 0;
  gint             n_params      = 0;
  gint             n_return_vals = 0;
  GimpParamDef    *params        = NULL;
  GimpParamDef    *return_vals   = NULL;
915
916
917
918
919

  g_return_if_fail (browser != NULL);
  g_return_if_fail (pinfo != NULL);

  gimp_procedural_db_proc_info (pinfo->realname,
920
921
922
923
924
925
926
927
928
929
                                &blurb,
                                &help,
                                &author,
                                &copyright,
                                &date,
                                &type,
                                &n_params,
                                &n_return_vals,
                                &params,
                                &return_vals);
930
931
932
933

  gimp_proc_box_set_widget (browser->proc_box,
                            gimp_proc_view_new (pinfo->realname,
                                                pinfo->menu,
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
                                                blurb,
                                                help,
                                                author,
                                                copyright,
                                                date,
                                                type,
                                                n_params,
                                                n_return_vals,
                                                params,
                                                return_vals));

  g_free (blurb);
  g_free (help);
  g_free (author);
  g_free (copyright);
  g_free (date);

  gimp_destroy_paramdefs (params,      n_params);
  gimp_destroy_paramdefs (return_vals, n_return_vals);
953
}