home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / common / plugindetails.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-28  |  32.2 KB  |  1,149 lines

  1. /*
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  4.  * This is a plug-in for the GIMP.
  5.  *
  6.  * Copyright (C) 1999 Andy Thomas  alt@picnic.demon.co.uk
  7.  *
  8.  * Note some portions of the UI comes from the dbbrowser plugin.
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22.  */
  23.  
  24. #include "config.h"
  25.  
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <time.h>
  30.  
  31. #include <gtk/gtk.h>
  32.  
  33. #include <libgimp/gimp.h>
  34. #include <libgimp/gimpui.h>
  35.  
  36. #include "libgimp/stdplugins-intl.h"
  37.  
  38.  
  39. #define DBL_LIST_WIDTH  250
  40. #define DBL_WIDTH       (DBL_LIST_WIDTH + 300)
  41. #define DBL_HEIGHT      200
  42.  
  43. static gchar *proc_type_str[] =
  44. {
  45.   N_("Internal GIMP procedure"),
  46.   N_("GIMP Plug-In"),
  47.   N_("GIMP Extension"),
  48.   N_("Temporary Procedure")
  49. };
  50.  
  51.  
  52. /* Declare some local functions.
  53.  */
  54. static void   query      (void);
  55. static void   run        (gchar      *name,
  56.                           gint        nparams,
  57.                           GimpParam  *param,
  58.                           gint       *nreturn_vals,
  59.                           GimpParam **return_vals);
  60.  
  61. static GtkWidget * gimp_plugin_desc (void);
  62.  
  63. static gint procedure_clist_select_callback (GtkWidget      *widget,
  64.                          gint            row, 
  65.                          gint            column, 
  66.                          GdkEventButton *bevent,
  67.                          gpointer        data);
  68. static gint procedure_ctree_select_callback (GtkWidget      *widget,
  69.                          GtkWidget      *row, 
  70.                          gint            column, 
  71.                          gpointer        data);
  72.  
  73. GimpPlugInInfo PLUG_IN_INFO =
  74. {
  75.   NULL,  /* init_proc  */
  76.   NULL,  /* quit_proc  */
  77.   query, /* query_proc */
  78.   run,   /* run_proc   */
  79. };
  80.  
  81.  
  82. MAIN ()
  83.  
  84. 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",
  94.                           "Displays plugin details",
  95.                           "Helps browse the plugin menus system. You can "
  96.               "search for plugin names, sort by name or menu "
  97.               "location and you can view a tree representation "
  98.               "of the plugin menus. Can also be of help to find "
  99.               "where new plugins have installed themselves in "
  100.               "the menuing system",
  101.                           "Andy Thomas",
  102.                           "Andy Thomas",
  103.                           "1999",
  104.               N_("<Toolbox>/Xtns/Plugin Details..."),
  105.               "",
  106.                           GIMP_EXTENSION,
  107.               nargs, 0,
  108.                           args, NULL);
  109. }
  110.  
  111. static void
  112. run (gchar      *name,
  113.      gint        nparams,
  114.      GimpParam  *param,
  115.      gint       *nreturn_vals,
  116.      GimpParam **return_vals)
  117. {
  118.   static GimpParam  values[2];
  119.   GimpRunModeType   run_mode;
  120.   GtkWidget        *plugin_dialog;
  121.  
  122.   run_mode = param[0].data.d_int32;
  123.  
  124.   *nreturn_vals = 1;
  125.   *return_vals  = values;
  126.   values[0].type          = GIMP_PDB_STATUS;
  127.   values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
  128.  
  129.   INIT_I18N_UI();
  130.  
  131.   if (strcmp (name, "plug_in_details") == 0)
  132.     {
  133.       *nreturn_vals = 1;
  134.  
  135.       values[0].data.d_status = GIMP_PDB_SUCCESS;
  136.  
  137.       plugin_dialog = gimp_plugin_desc ();
  138.  
  139.       gtk_main ();
  140.       gdk_flush ();
  141.     }
  142. }
  143.  
  144.  
  145. typedef struct  
  146. {
  147.   GtkWidget *dlg;
  148.   GtkWidget *clist;
  149.   GtkWidget *ctree;
  150.   GtkWidget *search_entry;
  151.   GtkWidget *descr_scroll;
  152.   GtkWidget *name_button;
  153.   GtkWidget *blurb_button;
  154.   GtkWidget *scrolled_win;
  155.   GtkWidget *ctree_scrolled_win;
  156.   GtkWidget *info_table;
  157.   GtkWidget *paned;
  158.   GtkWidget *left_paned;
  159.   GtkWidget *info_align;
  160.   gint       num_plugins;
  161.   gint       ctree_row;
  162.   gint       clist_row;
  163.   gint       c1size;
  164.   gboolean   details_showing;
  165. } PDesc;
  166.  
  167. PDesc *plugindesc = NULL;
  168.  
  169. typedef struct
  170. {
  171.   gchar *menu;
  172.   gchar *accel;
  173.   gchar *prog;
  174.   gchar *types;
  175.   gchar *realname;
  176.   gint  instime;
  177. } PInfo;
  178.  
  179. static void
  180. dialog_close_callback (GtkWidget *widget, 
  181.                gpointer   data)
  182.      /* end of the dialog */
  183. {
  184.   PDesc *pdesc = data;
  185.   gtk_widget_destroy (pdesc->dlg);
  186.   gtk_main_quit ();
  187. }
  188.  
  189. /* Bit of a fiddle but sorta has the effect I want... */
  190.  
  191. static void
  192. details_callback (GtkWidget *widget, 
  193.           gpointer   data)
  194. {
  195.   /* Show or hide the details window */ 
  196.   PDesc *pdesc = data;
  197.   GtkLabel *lab = GTK_LABEL (GTK_BIN (widget)->child);
  198.  
  199.   /* This is a lame hack: 
  200.      We add the description on the right on the first details_callback.
  201.      Otherwise the window reacts quite weird on resizes */
  202.   if (pdesc->descr_scroll == NULL)
  203.     {
  204.       pdesc->descr_scroll = gtk_scrolled_window_new (NULL, NULL);
  205.       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (pdesc->descr_scroll),
  206.                       GTK_POLICY_ALWAYS, 
  207.                       GTK_POLICY_ALWAYS);
  208.       gtk_widget_set_usize (pdesc->descr_scroll, DBL_WIDTH - DBL_LIST_WIDTH, -1);
  209.       gtk_paned_pack2 (GTK_PANED (pdesc->paned), pdesc->descr_scroll,
  210.                FALSE, TRUE);
  211.       gtk_clist_select_row (GTK_CLIST(pdesc->clist), pdesc->clist_row, -1);
  212.     }
  213.  
  214.   if (pdesc->details_showing == FALSE)
  215.     {
  216.       GTK_PANED (pdesc->paned)->child1_resize = FALSE;
  217.       gtk_paned_set_handle_size (GTK_PANED (pdesc->paned), 10);
  218.       gtk_paned_set_gutter_size (GTK_PANED (pdesc->paned), 6);
  219.       gtk_label_set_text (lab, _("Details <<"));
  220.       gtk_widget_show (pdesc->descr_scroll);
  221.       pdesc->details_showing = TRUE;
  222.     }
  223.   else
  224.     {
  225.       GtkWidget *p = GTK_WIDGET (pdesc->paned)->parent;
  226.       GTK_PANED (pdesc->paned)->child1_resize = TRUE;
  227.       GTK_PANED (pdesc->paned)->child2_resize = TRUE;
  228.       gtk_paned_set_handle_size (GTK_PANED (pdesc->paned), 0);
  229.       gtk_paned_set_gutter_size (GTK_PANED (pdesc->paned), 0);
  230.       gtk_label_set_text (lab, _("Details >>"));
  231.       gtk_widget_hide (pdesc->descr_scroll);
  232.       gtk_paned_set_position (GTK_PANED (pdesc->paned),
  233.                   p->allocation.width);/*plugindesc->c1size);*/
  234.       pdesc->details_showing = FALSE;
  235.     }
  236. }
  237.  
  238. static gchar *
  239. format_menu_path (gchar *s)
  240. {
  241.   gchar **str_array;
  242.   gchar  *newstr = NULL;
  243.  
  244.   if (!s)
  245.     return s;
  246.  
  247.   str_array = g_strsplit (s, "/", 0);
  248.  
  249.   newstr = g_strjoinv ("->", str_array);
  250.  
  251.   g_strfreev (str_array);
  252.  
  253.   return newstr;
  254. }
  255.  
  256. static gint
  257. procedure_general_select_callback (PDesc *pdesc,
  258.                    PInfo *pinfo)
  259. {
  260.   gchar           *selected_proc_blurb;
  261.   gchar           *selected_proc_help; 
  262.   gchar           *selected_proc_author;
  263.   gchar           *selected_proc_copyright;
  264.   gchar           *selected_proc_date;
  265.   GimpPDBProcType  selected_proc_type; 
  266.   gint             selected_nparams;
  267.   gint             selected_nreturn_vals;
  268.   GimpParamDef    *selected_params;
  269.   GimpParamDef    *selected_return_vals;
  270.   GtkWidget *label;
  271.   GtkWidget *help;
  272.   GtkWidget *text;
  273.   GtkWidget *vscrollbar;
  274.   GtkWidget *old_table;
  275.   GtkWidget *old_align;
  276.   gint       table_row = 0;
  277.   gchar     *str;
  278.  
  279.   g_return_val_if_fail (pdesc != NULL, FALSE);
  280.   g_return_val_if_fail (pinfo != NULL, FALSE);
  281.  
  282.   if (pdesc->descr_scroll == NULL)
  283.     return FALSE;
  284.  
  285.   selected_proc_blurb     = NULL;
  286.   selected_proc_help      = NULL;
  287.   selected_proc_author    = NULL;
  288.   selected_proc_copyright = NULL;
  289.   selected_proc_date      = NULL;
  290.   selected_proc_type      = 0;
  291.   selected_nparams        = 0;
  292.   selected_nreturn_vals   = 0;
  293.   selected_params         = NULL;
  294.   selected_return_vals    = NULL;
  295.  
  296.   gimp_procedural_db_proc_info (pinfo->realname, 
  297.                 &selected_proc_blurb, 
  298.                 &selected_proc_help, 
  299.                 &selected_proc_author,
  300.                 &selected_proc_copyright, 
  301.                 &selected_proc_date, 
  302.                 &selected_proc_type, 
  303.                 &selected_nparams, &selected_nreturn_vals, 
  304.                 &selected_params, &selected_return_vals);
  305.  
  306.   old_table = pdesc->info_table;
  307.   old_align = pdesc->info_align;
  308.  
  309.   pdesc->info_table = gtk_table_new (10, 5, FALSE);
  310.   pdesc->info_align = gtk_alignment_new (0.5, 0.5, 0, 0);
  311.  
  312.   gtk_table_set_col_spacings (GTK_TABLE (pdesc->info_table), 3);
  313.  
  314.   /* Number of plugins */
  315.  
  316.   str = g_strdup_printf (_("Number of Plugin Interfaces: %d"),
  317.              pdesc->num_plugins);
  318.   label = gtk_label_new (str);
  319.   g_free (str);
  320.   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  321.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  322.             0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 0, 0);
  323.   gtk_widget_show (label);
  324.   table_row++;
  325.  
  326.   label = gtk_hseparator_new (); /* ok, not really a label ... :) */
  327.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  328.             0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
  329.   gtk_widget_show (label);
  330.   table_row++;
  331.  
  332.   /* menu path */
  333.  
  334.   label = gtk_label_new (_("Menu Path:"));
  335.   gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  336.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  337.             0, 1, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 0);
  338.   gtk_widget_show(label);
  339.  
  340.   label = gtk_label_new (format_menu_path (pinfo->menu));
  341.   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  342.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  343.             1, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 0, 0);
  344.   gtk_widget_show (label);
  345.   table_row++;
  346.  
  347.   label = gtk_hseparator_new (); /* ok, not really a label ... :) */
  348.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  349.             0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
  350.   gtk_widget_show (label);
  351.   table_row++;
  352.  
  353.   /* show the name */
  354.  
  355.   label = gtk_label_new (_("Name:"));
  356.   gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  357.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  358.             0, 1, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
  359.   gtk_widget_show(label);
  360.  
  361.   label = gtk_entry_new ();
  362.   gtk_entry_set_text (GTK_ENTRY (label), pinfo->realname);
  363.   gtk_entry_set_editable (GTK_ENTRY (label), FALSE);
  364.   gtk_table_attach (GTK_TABLE(pdesc->info_table), label,
  365.             1, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 0, 0);
  366.   gtk_widget_show (label);
  367.   table_row++;
  368.  
  369.   label = gtk_hseparator_new (); /* ok, not really a label ... :) */
  370.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  371.             0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
  372.   gtk_widget_show (label);
  373.   table_row++;
  374.  
  375.   /* show the description */
  376.  
  377.   label = gtk_label_new (_("Blurb:"));
  378.   gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  379.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  380.             0, 1, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 0);
  381.   gtk_widget_show (label);
  382.  
  383.   label = gtk_label_new (selected_proc_blurb);
  384.   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  385.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  386.             1, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 0, 0);
  387.   gtk_widget_show(label);
  388.   table_row++;
  389.  
  390.   label = gtk_hseparator_new (); /* ok, not really a label ... :) */
  391.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  392.             0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
  393.   gtk_widget_show (label);
  394.   table_row++;
  395.  
  396.   /* show the help */
  397.   if ((selected_proc_help) && (strlen(selected_proc_help) > 1))
  398.     {
  399.       label = gtk_label_new (_("Help:"));
  400.       gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  401.       gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  402.             0, 1, table_row, table_row+1, 
  403.             GTK_FILL, GTK_FILL, 3, 0);
  404.       gtk_widget_show (label);
  405.       
  406.       help = gtk_table_new (2, 2, FALSE);
  407.       gtk_table_set_row_spacing (GTK_TABLE (help), 0, 2);
  408.       gtk_table_set_col_spacing (GTK_TABLE (help), 0, 2);
  409.       gtk_table_attach (GTK_TABLE (pdesc->info_table), help,
  410.             1, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 0);
  411.       gtk_widget_show (help);
  412.       table_row++;
  413.       
  414.       text = gtk_text_new (NULL, NULL);
  415.       gtk_text_set_editable (GTK_TEXT (text), FALSE);
  416.       gtk_text_set_word_wrap(GTK_TEXT(text), TRUE);
  417.       gtk_widget_set_usize (text, -1, 60);
  418.       gtk_table_attach (GTK_TABLE (help), text, 0, 1, 0, 1,
  419.             GTK_EXPAND | GTK_SHRINK | GTK_FILL,
  420.             GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
  421.       gtk_widget_show (text);
  422.       
  423.       vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
  424.       gtk_table_attach (GTK_TABLE (help), vscrollbar, 1, 2, 0, 1,
  425.             GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
  426.       gtk_widget_show (vscrollbar);
  427.             
  428.       label = gtk_hseparator_new (); /* ok, not really a label ... :) */
  429.       gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  430.             0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
  431.       gtk_widget_show(label);
  432.  
  433.       gtk_text_freeze (GTK_TEXT (text));
  434.       gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL,
  435.                selected_proc_help, -1);
  436.       gtk_text_thaw (GTK_TEXT (text));
  437.  
  438.       table_row++;
  439.     }
  440.  
  441.   /* show the type */
  442.  
  443.   label = gtk_label_new (_("Type:"));
  444.   gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); 
  445.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  446.             0, 1, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
  447.   gtk_widget_show(label);
  448.  
  449.   label = gtk_label_new (gettext (proc_type_str[selected_proc_type]));
  450.   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  451.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  452.             1, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 0, 0);
  453.   gtk_widget_show (label);
  454.   table_row++;
  455.  
  456.   label = gtk_hseparator_new (); /* ok, not really a label ... :) */
  457.   gtk_table_attach (GTK_TABLE (pdesc->info_table), label,
  458.             0, 4, table_row, table_row+1, GTK_FILL, GTK_FILL, 3, 6);
  459.   gtk_widget_show (label);
  460.   table_row++;
  461.  
  462.   /* Remove old and replace with new */
  463.  
  464.   if (old_table)
  465.     gtk_widget_destroy (old_table);
  466.  
  467.   if (old_align)
  468.     gtk_widget_destroy (old_align);
  469.  
  470.   gtk_container_add (GTK_CONTAINER (pdesc->info_align),pdesc->info_table);
  471.  
  472.   gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (pdesc->descr_scroll), 
  473.                      pdesc->info_align);
  474.  
  475.   gtk_widget_show (pdesc->info_table);
  476.   gtk_widget_show (pdesc->info_align);
  477.  
  478.   if (selected_proc_blurb)
  479.     g_free (selected_proc_blurb);
  480.   if (selected_proc_help)
  481.     g_free (selected_proc_help); 
  482.   if (selected_proc_author)
  483.     g_free (selected_proc_author);
  484.   if (selected_proc_copyright)
  485.     g_free (selected_proc_copyright);
  486.   if (selected_proc_date)
  487.     g_free (selected_proc_date);
  488.   if (selected_params)
  489.     g_free (selected_params);
  490.   if (selected_return_vals)
  491.     g_free (selected_return_vals);
  492.  
  493.   return FALSE;
  494. }
  495.  
  496. static void 
  497. expand_to (PDesc        *pdesc,
  498.        GtkCTreeNode *parent)
  499. {
  500.   if(parent)
  501.     {
  502.       expand_to (pdesc, (GTK_CTREE_ROW (parent))->parent);
  503.       gtk_ctree_expand (GTK_CTREE (pdesc->ctree), parent);      
  504.     }
  505. }
  506.  
  507. static gint
  508. procedure_clist_select_callback (GtkWidget      *widget,
  509.                  gint            row, 
  510.                  gint            column, 
  511.                  GdkEventButton *bevent,
  512.                  gpointer        data)
  513. {
  514.   PInfo *pinfo;
  515.   GtkCTreeNode * found_node; 
  516.   PDesc *pdesc = data;
  517.  
  518.   g_return_val_if_fail (pdesc != NULL, FALSE);
  519.  
  520.   pinfo = (PInfo *) gtk_clist_get_row_data (GTK_CLIST (widget), row);
  521.  
  522.   if (!pinfo)
  523.     return FALSE;
  524.  
  525.   /* Must select the correct one in the ctree structure */
  526.  
  527.   found_node = gtk_ctree_find_by_row_data (GTK_CTREE (pdesc->ctree),
  528.                        NULL, pinfo);
  529.   
  530.   if (found_node)
  531.     {
  532.       GtkCTreeRow   *ctr;
  533.       GtkCTreeNode  *parent;
  534.       gint sel_row;
  535.  
  536.       /* Make sure this is expanded */
  537.  
  538.       ctr = GTK_CTREE_ROW (found_node);
  539.  
  540.       parent = GTK_CTREE_NODE (ctr->parent);
  541.  
  542.       expand_to (pdesc, parent);
  543.  
  544.       sel_row = gtk_clist_find_row_from_data (GTK_CLIST (pdesc->ctree), pinfo);
  545.  
  546.       gtk_widget_hide (pdesc->ctree); 
  547.       gtk_widget_show (pdesc->ctree); 
  548.  
  549.       gtk_signal_handler_block_by_func (GTK_OBJECT(pdesc->ctree),
  550.                     GTK_SIGNAL_FUNC (procedure_ctree_select_callback),
  551.                     pdesc);
  552.  
  553.       gtk_clist_select_row (GTK_CLIST (pdesc->ctree), sel_row, -1);  
  554.       gtk_ctree_select (GTK_CTREE (pdesc->ctree), found_node);
  555.  
  556.       gtk_clist_moveto (GTK_CLIST (pdesc->ctree),
  557.             sel_row,
  558.             0,
  559.             0.5, 0.5);
  560.  
  561.       gtk_signal_handler_unblock_by_func (GTK_OBJECT (pdesc->ctree),
  562.                       GTK_SIGNAL_FUNC (procedure_ctree_select_callback),
  563.                       pdesc);
  564.  
  565.       pdesc->ctree_row = sel_row;
  566.     }
  567.   else
  568.     {
  569.       g_warning ("Failed to find node in ctree");
  570.     }
  571.  
  572.   return procedure_general_select_callback (pdesc, pinfo);
  573. }
  574.  
  575. /* This was an attempt to get around a problem in gtk 
  576.  * where the scroll windows that contain ctree and clist
  577.  * refuse to respond to the moveto funcions unless the
  578.  * widgets are visible.
  579.  * Still did not work 100% even after this.
  580.  * Note the scrollbars are in the correct position but the
  581.  * widget needs to be redrawn at the correct location.
  582.  */
  583.  
  584. static gint
  585. page_select_callback (GtkNotebook     *notebook,
  586.               GtkNotebookPage *page,
  587.               guint            page_num,
  588.               gpointer         data)
  589. {
  590.   PDesc *pdesc = data;
  591.  
  592.   if (page_num == 0)
  593.     {
  594.       gtk_clist_select_row (GTK_CLIST (pdesc->clist), pdesc->clist_row, -1);  
  595.       gtk_clist_moveto (GTK_CLIST (pdesc->clist),
  596.             pdesc->clist_row,
  597.             0,
  598.             0.5, 0.0);
  599.     }
  600.   else
  601.     {
  602.       gtk_clist_select_row (GTK_CLIST (pdesc->ctree), pdesc->ctree_row, -1);  
  603.       gtk_clist_moveto (GTK_CLIST (pdesc->ctree),
  604.             pdesc->ctree_row,
  605.             0,
  606.             0.5, 0.0);
  607.     }
  608.  
  609.   return FALSE;
  610. }
  611.  
  612. static gint
  613. procedure_ctree_select_callback (GtkWidget *widget,
  614.                  GtkWidget *row, 
  615.                  gint       column, 
  616.                  gpointer   data)
  617. {
  618.   PInfo *pinfo;
  619.   PDesc *pdesc;
  620.   gboolean is_leaf;
  621.   gint sel_row;
  622.  
  623.   /* row is not a leaf the we have no interest in it */
  624.  
  625.   gtk_ctree_get_node_info (GTK_CTREE (widget),
  626.                GTK_CTREE_NODE (row),
  627.                NULL,
  628.                NULL,
  629.                NULL,
  630.                NULL,
  631.                NULL,
  632.                NULL,
  633.                &is_leaf,
  634.                NULL);
  635.  
  636.   if (!is_leaf)
  637.     return FALSE;
  638.  
  639.   pdesc = data;
  640.  
  641.   pinfo = (PInfo *) gtk_ctree_node_get_row_data (GTK_CTREE (widget),
  642.                          GTK_CTREE_NODE (row));
  643.  
  644.   /* Must set clist to this one */
  645.   /* Block signals */
  646.  
  647.   gtk_signal_handler_block_by_func (GTK_OBJECT (pdesc->clist),
  648.                     GTK_SIGNAL_FUNC (procedure_clist_select_callback),
  649.                     pdesc);
  650.  
  651.   sel_row = gtk_clist_find_row_from_data (GTK_CLIST (pdesc->clist), pinfo);
  652.   gtk_clist_select_row (GTK_CLIST (pdesc->clist), sel_row, -1);  
  653.   gtk_clist_moveto (GTK_CLIST (pdesc->clist),
  654.             sel_row,
  655.             0,
  656.             0.5, 0.5);
  657.  
  658.   gtk_signal_handler_unblock_by_func (GTK_OBJECT (pdesc->clist),
  659.                       GTK_SIGNAL_FUNC (procedure_clist_select_callback),
  660.                       pdesc);
  661.  
  662.   pdesc->clist_row = sel_row;
  663.   
  664.   return procedure_general_select_callback (pdesc, pinfo);
  665. }
  666.  
  667. static void
  668. pinfo_free (gpointer p)
  669. {
  670.   PInfo *pinfo = p;
  671.  
  672.   g_free (pinfo->menu);
  673.   g_free (pinfo->accel);
  674.   g_free (pinfo->prog);
  675.   g_free (pinfo->types);
  676.   g_free (pinfo->realname);
  677.   g_free (pinfo);
  678. }
  679.  
  680. static GtkCTreeNode *
  681. get_parent (PDesc       *pdesc,
  682.         GHashTable  *ghash,
  683.         gchar       *mpath)
  684. {
  685.   GtkCTreeNode *parent;
  686.   GtkCTreeNode *last_parent;
  687.   gchar *tmp_ptr;
  688.   gchar *str_ptr;
  689.   gchar *leaf_ptr;
  690.   gchar *labels[3];
  691.   
  692.   if (mpath == NULL)
  693.     return NULL; /* Parent is root */
  694.  
  695.   parent = g_hash_table_lookup (ghash, mpath);
  696.  
  697.   if (parent)
  698.     {
  699.       /* found node */
  700.       return parent;
  701.     }
  702.  
  703.   /* Next one up */
  704.   tmp_ptr = g_strdup (mpath);
  705.  
  706.   str_ptr = strrchr (tmp_ptr,'/');
  707.  
  708.   if (str_ptr == NULL)
  709.     {
  710.       /*       printf("Root node for %s\n",mpath); */
  711.       leaf_ptr = mpath;
  712.       tmp_ptr = "<root>";
  713.       last_parent = NULL;
  714.     }
  715.   else
  716.     {
  717.       leaf_ptr = g_strdup(str_ptr+1);
  718.  
  719.       *str_ptr = '\000';
  720.  
  721.       last_parent = get_parent (pdesc, ghash, tmp_ptr);
  722.     }
  723.  
  724.   labels[0] = g_strdup (leaf_ptr); 
  725.   labels[1] = g_strdup (""); 
  726.   labels[2] = g_strdup (""); 
  727.  
  728.   /*   printf("get_parent::creating node %s under %s\n",leaf_ptr,tmp_ptr); */
  729.  
  730.   parent = gtk_ctree_insert_node (GTK_CTREE (pdesc->ctree),
  731.                   last_parent,
  732.                   NULL,
  733.                   labels,
  734.                   4,
  735.                   NULL,
  736.                   NULL,
  737.                   NULL,
  738.                   NULL,
  739.                   FALSE,
  740.                   FALSE);
  741.  
  742.   g_hash_table_insert (ghash, mpath, parent); 
  743.  
  744.   return parent;
  745. }
  746.  
  747. static void
  748. insert_into_ctree (PDesc      *pdesc,
  749.            gchar      *name,
  750.            gchar      *xtimestr,
  751.            gchar      *menu_str,
  752.            gchar      *types_str,
  753.            GHashTable *ghash,
  754.            PInfo      *pinfo)
  755. {
  756.   gchar *labels[3];
  757.   gchar *str_ptr;
  758.   gchar *tmp_ptr;
  759.   gchar *leaf_ptr;
  760.   GtkCTreeNode *parent = NULL;
  761.   GtkCTreeNode *leaf_node = NULL;
  762.  
  763.   /* Find all nodes */
  764.   /* Last one is the leaf part */
  765.  
  766.   tmp_ptr = g_strdup (menu_str);
  767.  
  768.   str_ptr = strrchr (tmp_ptr, '/');
  769.  
  770.   if (str_ptr == NULL)
  771.     return; /* No node */
  772.  
  773.   leaf_ptr = g_strdup (str_ptr + 1);
  774.  
  775.   *str_ptr = '\000';
  776.  
  777.   /*   printf("inserting %s...\n",menu_str); */
  778.  
  779.   parent = get_parent (pdesc, ghash, tmp_ptr);
  780.  
  781.   /* Last was a leaf */
  782.   /*   printf("found leaf %s parent = %p\n",leaf_ptr,parent); */
  783.   labels[0] = g_strdup (name);
  784.   labels[1] = g_strdup (xtimestr);
  785.   labels[2] = g_strdup (types_str);
  786.  
  787.   leaf_node = gtk_ctree_insert_node (GTK_CTREE (pdesc->ctree),
  788.                      parent,
  789.                      NULL,
  790.                      labels,
  791.                      4,
  792.                      NULL,
  793.                      NULL,
  794.                      NULL,
  795.                      NULL,
  796.                      TRUE,
  797.                      FALSE);
  798.  
  799.   gtk_ctree_node_set_row_data (GTK_CTREE (pdesc->ctree), leaf_node, pinfo);
  800. }
  801.  
  802. static void
  803. get_plugin_info (PDesc *pdesc,
  804.          gchar *search_text)
  805. {
  806.   GimpParam *return_vals;
  807.   gint nreturn_vals;
  808.   gint  row_count = 0;
  809.   gchar **menu_strs;
  810.   gchar **accel_strs;
  811.   gchar **prog_strs;
  812.   gchar **types_strs;
  813.   gchar **realname_strs;
  814.   gint  *time_ints;
  815.  
  816.   GHashTable* ghash = g_hash_table_new (g_str_hash, g_str_equal);
  817.  
  818.   if (!search_text)
  819.     search_text = "";
  820.  
  821.   return_vals = gimp_run_procedure ("gimp_plugins_query",
  822.                                     &nreturn_vals,
  823.                     GIMP_PDB_STRING,search_text,
  824.                                     GIMP_PDB_END);
  825.  
  826.   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
  827.     {
  828.       int loop;
  829.       pdesc->num_plugins = return_vals[1].data.d_int32;
  830.       menu_strs          = return_vals[2].data.d_stringarray;
  831.       accel_strs         = return_vals[4].data.d_stringarray;
  832.       prog_strs          = return_vals[6].data.d_stringarray;
  833.       types_strs         = return_vals[8].data.d_stringarray;
  834.       time_ints          = return_vals[10].data.d_int32array;
  835.       realname_strs      = return_vals[12].data.d_stringarray;
  836.  
  837.       for (loop = 0; loop < return_vals[1].data.d_int32; loop++)
  838.     {
  839.       PInfo *pinfo;
  840.       gchar *labels[4];
  841.       gchar *name;
  842.       gchar xtimestr[50];
  843.       struct tm * x;
  844.       time_t tx;
  845.       int ret;
  846.  
  847.       name = strrchr (menu_strs[loop], '/');
  848.  
  849.       if (name)
  850.         name = name + 1;
  851.       else
  852.         name = menu_strs[loop];
  853.  
  854.       pinfo = g_new0 (PInfo, 1);
  855.  
  856.       tx = time_ints[loop];
  857.       if (tx)
  858.         {
  859.           x = localtime (&tx);
  860.           ret = strftime (xtimestr, sizeof (xtimestr), "%c", x);
  861.           xtimestr[ret] = 0;
  862.         }
  863.       else
  864.         strcpy (xtimestr,"");
  865.  
  866.       pinfo->menu     = g_strdup (menu_strs[loop]);
  867.       pinfo->accel    = g_strdup (accel_strs[loop]);
  868.       pinfo->prog     = g_strdup (prog_strs[loop]);
  869.       pinfo->types    = g_strdup (types_strs[loop]);
  870.       pinfo->instime  = time_ints[loop];
  871.       pinfo->realname = g_strdup (realname_strs[loop]);
  872.  
  873.       labels[0] = g_strdup (name);
  874.       labels[1] = g_strdup (xtimestr);
  875.       labels[2] = g_strdup (menu_strs[loop]);
  876.       labels[3] = g_strdup (types_strs[loop]);
  877.  
  878.       gtk_clist_insert (GTK_CLIST (pdesc->clist), row_count, labels);
  879.  
  880.       gtk_clist_set_row_data_full (GTK_CLIST (pdesc->clist), row_count,
  881.                        pinfo, pinfo_free);
  882.  
  883.       row_count++;
  884.  
  885.       /* Now do the tree view.... */
  886.       gtk_signal_handler_block_by_func (GTK_OBJECT(pdesc->ctree),
  887.                         GTK_SIGNAL_FUNC (procedure_ctree_select_callback),
  888.                         pdesc);
  889.       insert_into_ctree (pdesc,
  890.                  name,
  891.                  xtimestr,
  892.                  menu_strs[loop],
  893.                  types_strs[loop],
  894.                  ghash,
  895.                  pinfo);
  896.       gtk_signal_handler_unblock_by_func (GTK_OBJECT (pdesc->ctree),
  897.                           GTK_SIGNAL_FUNC (procedure_ctree_select_callback),
  898.                           pdesc);
  899.     }
  900.     }
  901.  
  902.   gimp_destroy_params (return_vals, nreturn_vals);
  903. }
  904.  
  905. static void 
  906. dialog_search_callback (GtkWidget *widget, 
  907.             gpointer   data)
  908. {
  909.   PDesc *pdesc = data;
  910.   gchar *search_text = NULL;
  911.  
  912.   if (widget != NULL)
  913.     {
  914.       /* The result of a button press... read entry data */
  915.       search_text = gtk_entry_get_text (GTK_ENTRY (plugindesc->search_entry));
  916.     }
  917.  
  918.   gtk_clist_freeze (GTK_CLIST (pdesc->ctree));
  919.   gtk_clist_clear (GTK_CLIST (pdesc->ctree));
  920.   gtk_clist_freeze (GTK_CLIST (pdesc->clist));
  921.   gtk_clist_clear (GTK_CLIST (pdesc->clist));
  922.  
  923.   get_plugin_info (pdesc, search_text);
  924.  
  925.   gtk_clist_columns_autosize (GTK_CLIST (plugindesc->clist));
  926.  
  927.   gtk_clist_sort (GTK_CLIST (pdesc->clist));
  928.   gtk_clist_thaw (GTK_CLIST (pdesc->clist));
  929.   gtk_ctree_sort_recursive (GTK_CTREE (pdesc->ctree), NULL);
  930.   gtk_clist_thaw (GTK_CLIST (pdesc->ctree));
  931. }
  932.  
  933. static gint
  934. date_sort (GtkCList      *clist,
  935.        gconstpointer  ptr1,
  936.        gconstpointer  ptr2)
  937. {
  938.   GtkCListRow *row1 = (GtkCListRow *) ptr1;
  939.   GtkCListRow *row2 = (GtkCListRow *) ptr2;
  940.  
  941.   /* Get the data for the row */
  942.   PInfo *row1_pinfo = row1->data;
  943.   PInfo *row2_pinfo = row2->data;
  944.  
  945.   /* Want to sort on the date field */
  946.  
  947.   if (row2_pinfo->instime < row1_pinfo->instime)
  948.     {
  949.       return -1;
  950.     }
  951.  
  952.   if (row2_pinfo->instime > row1_pinfo->instime)
  953.     {
  954.       return 1;
  955.     }
  956.  
  957.   return 0;
  958. }
  959.  
  960. static void 
  961. clist_click_column (GtkCList *clist, 
  962.             gint      column, 
  963.             gpointer  data)
  964. {
  965.   if (column == 1)
  966.     {
  967.       gtk_clist_set_compare_func (clist, date_sort);
  968.     }
  969.   else
  970.     {
  971.       gtk_clist_set_compare_func (clist, NULL); /* Set back to default */
  972.     }
  973.  
  974.   if (column == clist->sort_column)
  975.     {
  976.       if (clist->sort_type == GTK_SORT_ASCENDING)
  977.     clist->sort_type = GTK_SORT_DESCENDING;
  978.       else
  979.     clist->sort_type = GTK_SORT_ASCENDING;
  980.     }
  981.   else
  982.     gtk_clist_set_sort_column (clist, column);
  983.   
  984.   gtk_clist_sort (clist);
  985. }
  986.  
  987.  
  988. static GtkWidget *
  989. gimp_plugin_desc (void)
  990. {
  991.   GtkWidget  *button;
  992.   GtkWidget  *hbox, *searchhbox, *vbox;
  993.   GtkWidget  *label, *notebook, *swindow;
  994.   gchar      *clabels[4];
  995.  
  996.   gimp_ui_init ("plugindetails", FALSE);
  997.  
  998.   plugindesc = g_new0 (PDesc, 1);
  999.  
  1000.   /* the dialog box */
  1001.   plugindesc->dlg =
  1002.     gimp_dialog_new (_("Plugin Descriptions"), "plugindetails",
  1003.              gimp_standard_help_func, "filters/plugindetails.html",
  1004.              GTK_WIN_POS_MOUSE,
  1005.              FALSE, TRUE, TRUE,
  1006.  
  1007.              _("Search by Name"), dialog_search_callback,
  1008.              plugindesc, NULL, NULL, FALSE, FALSE,
  1009.              _("Close"), dialog_close_callback,
  1010.              plugindesc, NULL, NULL, TRUE, TRUE,
  1011.  
  1012.              NULL);
  1013.  
  1014.   plugindesc->details_showing = FALSE;
  1015.  
  1016.   gtk_signal_connect (GTK_OBJECT (plugindesc->dlg), "destroy",
  1017.                       GTK_SIGNAL_FUNC (dialog_close_callback),
  1018.               plugindesc);
  1019.  
  1020.   /* hbox : left=notebook ; right=description */
  1021.   
  1022.   plugindesc->paned = hbox = gtk_hpaned_new ();
  1023.   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (plugindesc->dlg)->vbox), 
  1024.               hbox, TRUE, TRUE, 0);
  1025.   gtk_widget_show (hbox);
  1026.  
  1027.   gtk_paned_set_handle_size (GTK_PANED (hbox), 0);
  1028.   gtk_paned_set_gutter_size (GTK_PANED (hbox), 0);
  1029.  
  1030.   /* left = vbox : the list and the search entry */
  1031.   
  1032.   plugindesc->left_paned = vbox = gtk_vbox_new (FALSE, 0);
  1033.   gtk_container_set_border_width (GTK_CONTAINER (vbox), 3); 
  1034.   gtk_paned_pack1 (GTK_PANED (hbox), vbox, FALSE, FALSE);
  1035.   gtk_widget_show (vbox);
  1036.  
  1037.   /* left = notebook */
  1038.  
  1039.   notebook = gtk_notebook_new ();
  1040.   gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);
  1041.  
  1042.   /* list : list in a scrolled_win */
  1043.   
  1044.   clabels[0] = g_strdup (_("Name")); 
  1045.   clabels[1] = g_strdup (_("Ins Date")); 
  1046.   clabels[2] = g_strdup (_("Menu Path")); 
  1047.   clabels[3] = g_strdup (_("Image Types")); 
  1048.   plugindesc->clist = gtk_clist_new_with_titles (4, clabels); 
  1049.  
  1050.   gtk_signal_connect (GTK_OBJECT (plugindesc->clist), "click_column",
  1051.               GTK_SIGNAL_FUNC (clist_click_column),
  1052.               NULL);
  1053.   gtk_clist_column_titles_show (GTK_CLIST (plugindesc->clist));
  1054.   swindow = gtk_scrolled_window_new (NULL, NULL);
  1055.   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
  1056.                   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  1057.   gtk_clist_set_selection_mode (GTK_CLIST (plugindesc->clist),
  1058.                     GTK_SELECTION_BROWSE);
  1059.  
  1060.   gtk_widget_set_usize (plugindesc->clist, DBL_LIST_WIDTH, DBL_HEIGHT);
  1061.   gtk_signal_connect (GTK_OBJECT (plugindesc->clist), "select_row",
  1062.               GTK_SIGNAL_FUNC (procedure_clist_select_callback),
  1063.               plugindesc);
  1064.   
  1065.   label = gtk_label_new (_("List View"));
  1066.   gtk_notebook_append_page (GTK_NOTEBOOK (notebook), swindow, label);
  1067.   gtk_container_add (GTK_CONTAINER (swindow), plugindesc->clist);
  1068.   gtk_widget_show (plugindesc->clist);
  1069.   gtk_widget_show (swindow);
  1070.  
  1071.   /* notebook->ctree */
  1072.   clabels[0] = g_strdup (_("Menu Path/Name")); 
  1073.   clabels[1] = g_strdup (_("Ins Date")); 
  1074.   clabels[2] = g_strdup (_("Image Types")); 
  1075.   plugindesc->ctree = gtk_ctree_new_with_titles (3, 0, clabels);  
  1076.   plugindesc->ctree_scrolled_win =
  1077.     swindow = gtk_scrolled_window_new (NULL, NULL);
  1078.   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
  1079.                   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  1080.   gtk_widget_set_usize (plugindesc->ctree, DBL_LIST_WIDTH, DBL_HEIGHT);
  1081.   gtk_signal_connect (GTK_OBJECT (plugindesc->ctree), "tree_select_row",
  1082.               GTK_SIGNAL_FUNC (procedure_ctree_select_callback),
  1083.               plugindesc);
  1084.   gtk_clist_set_column_auto_resize (GTK_CLIST (plugindesc->ctree), 0, TRUE);
  1085.   gtk_clist_set_column_auto_resize (GTK_CLIST (plugindesc->ctree), 1, TRUE);
  1086.   gtk_clist_set_column_auto_resize (GTK_CLIST (plugindesc->ctree), 2, TRUE);
  1087.   gtk_clist_column_titles_passive (GTK_CLIST (plugindesc->ctree));
  1088.  
  1089.   label = gtk_label_new (_("Tree View"));
  1090.   gtk_notebook_append_page (GTK_NOTEBOOK (notebook), swindow, label);
  1091.   gtk_container_add (GTK_CONTAINER (swindow), plugindesc->ctree);
  1092.  
  1093.   gtk_widget_show (plugindesc->ctree);
  1094.   gtk_widget_show (swindow);
  1095.  
  1096.   gtk_signal_connect_after (GTK_OBJECT (notebook), "switch_page",
  1097.                 GTK_SIGNAL_FUNC (page_select_callback),
  1098.                 plugindesc);
  1099.   
  1100.   gtk_widget_show (notebook);
  1101.  
  1102.   /* search entry & details button */
  1103.  
  1104.   searchhbox = gtk_hbox_new (FALSE, 4);
  1105.   gtk_box_pack_start (GTK_BOX (vbox),
  1106.               searchhbox, FALSE, FALSE, 0);
  1107.   gtk_widget_show (searchhbox);
  1108.  
  1109.   label = gtk_label_new (_("Search:"));
  1110.   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  1111.   gtk_box_pack_start (GTK_BOX (searchhbox), 
  1112.               label, FALSE, FALSE, 0);
  1113.   gtk_widget_show(label);
  1114.  
  1115.   plugindesc->search_entry = gtk_entry_new ();
  1116.   gtk_box_pack_start (GTK_BOX (searchhbox), 
  1117.               plugindesc->search_entry, TRUE, TRUE, 0);
  1118.   gtk_widget_show (plugindesc->search_entry);
  1119.  
  1120.   button = gtk_button_new_with_label (_("Details >>"));
  1121.   gtk_misc_set_padding (GTK_MISC (GTK_BIN (button)->child), 2, 0);
  1122.   gtk_signal_connect (GTK_OBJECT (button), "clicked",
  1123.               GTK_SIGNAL_FUNC (details_callback),
  1124.               plugindesc);
  1125.   gtk_box_pack_start (GTK_BOX (searchhbox), button,
  1126.               FALSE, FALSE, 0);
  1127.   gtk_widget_show (button);
  1128.  
  1129.   /* right = description */
  1130.   /* the right description is build on first click of the Details button */
  1131.  
  1132.   /* now build the list */
  1133.   dialog_search_callback (NULL, (gpointer) plugindesc);
  1134.  
  1135.   gtk_clist_set_selection_mode (GTK_CLIST (plugindesc->ctree),
  1136.                 GTK_SELECTION_BROWSE);
  1137.  
  1138.   gtk_widget_show (plugindesc->clist); 
  1139.   gtk_widget_show (plugindesc->dlg);
  1140.   
  1141.   gtk_clist_select_row (GTK_CLIST (plugindesc->clist), 0, 0);
  1142.   gtk_clist_moveto (GTK_CLIST (plugindesc->clist), 0, 0, 0.0, 0.0);
  1143.  
  1144.   plugindesc->c1size = GTK_PANED (plugindesc->paned)->child1_size;
  1145.   GTK_PANED (plugindesc->paned)->child1_resize = TRUE;
  1146.  
  1147.   return plugindesc->dlg;
  1148. }
  1149.