Use list_store isf deprecated clist.
[obnox/wireshark/wip.git] / gtk / expert_comp_table.c
1 /* expert_comp_table.c
2  * expert_comp_table   2005 Greg Morris
3  * Portions copied from service_response_time_table.c by Ronnie Sahlberg
4  * Helper routines common to all composite expert statistics
5  * tap.
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  * 
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <string.h>
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <math.h>
36
37 #include <gtk/gtk.h>
38
39 #include "epan/packet_info.h"
40 #include "epan/strutil.h"
41
42 #include <epan/expert.h>
43
44 #include "../simple_dialog.h"
45 #include "../globals.h"
46 #include "../color.h"
47
48 #include "gtk/expert_comp_table.h"
49 #include "gtk/filter_utils.h"
50 #include "gtk/find_dlg.h"
51 #include "gtk/color_dlg.h"
52 #include "gtk/main.h"
53 #include "gtk/gui_utils.h"
54 #include "gtk/gtkglobals.h"
55 #include "gtk/webbrowser.h"
56
57 #if 0
58 #define SORT_ALPHABETICAL 0
59
60 static gint
61 sort_iter_compare_func (GtkTreeModel *model,
62                         GtkTreeIter *a,
63                         GtkTreeIter *b,
64                         gpointer userdata)
65 {
66     gint sortcol = GPOINTER_TO_INT(userdata);
67     gint ret = 0;
68     switch (sortcol)
69     {
70         case SORT_ALPHABETICAL:
71         {
72             gchar *name1, *name2;
73             gtk_tree_model_get(model, a, 0, &name1, -1);
74             gtk_tree_model_get(model, b, 0, &name2, -1);
75             if (name1 == NULL || name2 == NULL)
76             {
77                 if (name1 == NULL && name2 == NULL)
78                     break; /* both equal => ret = 0 */
79                 ret = (name1 == NULL) ? -1 : 1;
80             }
81             else
82             {
83                 ret = g_ascii_strcasecmp(name1,name2);
84             }
85             g_free(name1);
86             g_free(name2);
87         }
88         break;
89         default:
90             g_return_val_if_reached(0);
91     }
92     return ret;
93 }
94 #endif
95 enum
96 {
97    GROUP_COLUMN,
98    PROTOCOL_COLUMN,
99    SUMMARY_COLUMN,
100    COUNT_COLUMN,
101    N_COLUMNS
102 };
103
104 static gint find_summary_data(error_equiv_table *err, const expert_info_t *expert_data)
105 {
106     guint i;
107     error_procedure_t *procedure;
108     
109     /* First time thru values will be 0 */
110     if (err->num_procs==0) {
111         return -1;
112     }
113     for (i=0;i<err->num_procs;i++) {
114         procedure = &g_array_index(err->procs_array, error_procedure_t, i);
115         if (strcmp(procedure->entries[1], expert_data->protocol) == 0 &&
116             strcmp(procedure->entries[2], expert_data->summary) == 0) {
117             return i;
118         }
119     }
120     return -1;
121 }
122
123 static void
124 error_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint callback_action)
125 {
126     int action, type, selection;
127     error_equiv_table *err = (error_equiv_table *)callback_data;
128     char str[512];
129     const char *current_filter;
130     error_procedure_t *procedure;
131
132     GtkTreeIter iter;
133     GtkTreeModel *model;
134     expert_info_t expert_data;
135     gchar *grp;
136
137     action=FILTER_ACTION(callback_action);
138     type=FILTER_ACTYPE(callback_action);
139
140
141     gtk_tree_selection_get_selected(err->select, &model, &iter);
142
143     gtk_tree_model_get (model, &iter, 
144                         GROUP_COLUMN,    &grp,
145                         PROTOCOL_COLUMN, &expert_data.protocol,
146                         SUMMARY_COLUMN,  &expert_data.summary,
147                         -1);
148     
149     if (strcmp(grp, "Packet:")==0) {
150         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "You cannot filter or search for packet number. Click on a valid item header.");
151         g_free(grp);
152         g_free(expert_data.summary);
153         return;
154     }
155
156     g_free(grp);
157
158     /* XXX: find_summary_data doesn't (currently) reference expert_data.group.   */
159     /*      If "group" is required, then the message from GROUP_COLUMN will need */
160     /*       to be translated to the group number (or the actual group number    */
161     /*       will also need to be stored in the TreeModel).                      */
162     selection = find_summary_data(err, &expert_data);
163
164     g_free(expert_data.summary);
165
166     if(selection>=(int)err->num_procs){
167         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No items are selected");
168         return;
169     }
170     current_filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
171
172     /* Some expert data doesn't pass an expert item. Without this we cannot create a filter */
173     /* But allow for searching of internet for error string */
174     procedure = &g_array_index(err->procs_array, error_procedure_t, selection);
175
176     /* FIXME what is 7 ?*/
177     if (action != ACTION_WEB_LOOKUP && action != 7) {
178         char *msg;
179         if (0 /*procedure->fvalue_value==NULL*/) {
180             if (action != ACTION_FIND_FRAME && action != ACTION_FIND_NEXT && action != ACTION_FIND_PREVIOUS) {
181                 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Wireshark cannot create a filter on this item - %s, try using find instead.", 
182                               procedure->entries[2]);
183                 return;
184             }
185         }
186         msg = g_malloc(escape_string_len(procedure->entries[2]));
187         escape_string(msg, procedure->entries[2]);
188         switch(type){
189         case ACTYPE_SELECTED:
190             /* if no expert item was passed */
191             if (procedure->fvalue_value==NULL) {
192                 g_snprintf(str, sizeof(str), "expert.message==%s", msg);
193             }
194             else
195             {
196                 /* expert item exists. Use it. */
197                 g_strlcpy(str, procedure->fvalue_value, sizeof(str));
198             }
199             break;
200         case ACTYPE_NOT_SELECTED:
201             /* if no expert item was passed */
202             if (procedure->fvalue_value==NULL) {
203                 g_snprintf(str, sizeof(str), "!(expert.message==%s)", msg);
204             }
205             else
206             {
207                 /* expert item exists. Use it. */
208                 g_snprintf(str, sizeof(str), "!(%s)", procedure->fvalue_value);
209             }
210             break;
211             /* the remaining cases will only exist if the expert item exists so no need to check */
212         case ACTYPE_AND_SELECTED:
213             if ((!current_filter) || (0 == strlen(current_filter)))
214                 g_snprintf(str, sizeof(str), "expert.message==%s", msg);
215             else
216                 g_snprintf(str, sizeof(str), "(%s) && (expert.message==%s)", current_filter, msg);
217             break;
218         case ACTYPE_OR_SELECTED:
219             if ((!current_filter) || (0 == strlen(current_filter)))
220                 g_snprintf(str, sizeof(str), "expert.message==%s", msg);
221             else
222                 g_snprintf(str, sizeof(str), "(%s) || (expert.message==%s)", current_filter, msg);
223             break;
224         case ACTYPE_AND_NOT_SELECTED:
225             if ((!current_filter) || (0 == strlen(current_filter)))
226                 g_snprintf(str, sizeof(str), "!(expert.message==%s)", msg);
227             else
228                 g_snprintf(str, sizeof(str), "(%s) && !(expert.message==%s)", current_filter, msg);
229             break;
230         case ACTYPE_OR_NOT_SELECTED:
231             if ((!current_filter) || (0 == strlen(current_filter)))
232                 g_snprintf(str, sizeof(str), "!(expert.message==%s)", msg);
233             else
234                 g_snprintf(str, sizeof(str), "(%s) || !(expert.message==%s)", current_filter, msg);
235             break;
236         default:
237             simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't find menu type - %u", type);
238         }
239         g_free(msg);
240     }
241
242     switch(action){
243     case ACTION_MATCH:
244         main_filter_packets(&cfile, str, FALSE);
245         break;
246     case ACTION_PREPARE:
247         gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
248         break;
249     case ACTION_FIND_FRAME:
250         /* When trying to perform a find without expert item, we must pass
251          * the expert string to the find window. The user might need to modify
252          * the string and click on the text search to locate the packet in question.
253          * So regardless of the type we will just bring up the find window and allow
254          * the user to modify the search criteria and options.
255          */
256         find_frame_with_filter(str);
257         break;
258     case ACTION_FIND_NEXT:
259         /* In the case of find next, if there was no expert item, then most likely the expert
260          * string was modified to locate the text inside the message. So we can't just perform
261          * a find with the expert string or we will not really be performing a find next.
262          * In an effort to allow the user to modify the string and/or continue searching, we
263          * will just present the user with the find window again with the default expert string.
264          * A better aproach would be to attempt in capturing the last find string and utilize this 
265          * with a find next/previous. Also a better approach might be to just send a <Ctl-N> keystroke.
266          */
267         if (procedure->fvalue_value==NULL) {
268             find_frame_with_filter(str);
269         }
270         else
271         { 
272             /* We have an expert item so just continue search without find dialog. */
273             find_previous_next_frame_with_filter(str, FALSE);
274         }
275         break;
276     case ACTION_FIND_PREVIOUS:
277         /* In the case of find previous, if there was no expert item, then most likely the expert
278          * string was modified to locate the text inside the message. So we can't just perform
279          * a find with the expert string or we will not really be performing a find previous.
280          * In an effort to allow the user to modify the string and/or continue searching, we
281          * will just present the user with the find window again with the default expert string.
282          * A better aproach would be to attempt in capturing the last find string and utilize this 
283          * with a find next/previous. Also a better approach might be to just send a <Ctl-B> keystroke.
284          */
285         if (procedure->fvalue_value==NULL) {
286             find_frame_with_filter(str);
287         }
288         else
289         { 
290             /* We have an expert item so just continue search without find dialog. */
291             find_previous_next_frame_with_filter(str, TRUE);
292         }
293         break;
294     case ACTION_COLORIZE:
295         color_display_with_filter(str);
296         break;
297     case ACTION_WEB_LOOKUP:
298         /* Lookup expert string on internet. Default search via www.google.com */
299         g_snprintf(str, sizeof(str), "http://www.google.com/search?hl=en&q=%s+'%s'", procedure->entries[1], procedure->entries[2]);
300         browser_open_url(str);
301         break;
302     default:
303         simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't find menu action - %u", action);
304     }
305 }
306
307 static gint
308 error_show_popup_menu_cb(void *widg _U_, GdkEvent *event, error_equiv_table *err)
309 {
310         GdkEventButton *bevent = (GdkEventButton *)event;
311
312         if(event->type==GDK_BUTTON_PRESS && bevent->button==3){
313                 gtk_menu_popup(GTK_MENU(err->menu), NULL, NULL, NULL, NULL, 
314                         bevent->button, bevent->time);
315         }
316
317         return FALSE;
318 }
319
320 static GtkItemFactoryEntry error_list_menu_items[] =
321 {
322         /* Match */
323         {"/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL,},
324         {"/Apply as Filter/Selected", NULL,
325                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_SELECTED, 0),
326                 NULL, NULL,},
327         {"/Apply as Filter/... not Selected", NULL,
328                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_NOT_SELECTED, 0),
329                 NULL, NULL,},
330         {"/Apply as Filter/.. and Selected", NULL,
331                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_AND_SELECTED, 0),
332                 NULL, NULL,},
333         {"/Apply as Filter/... or Selected", NULL,
334                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_OR_SELECTED, 0),
335                 NULL, NULL,},
336         {"/Apply as Filter/... and not Selected", NULL,
337                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_AND_NOT_SELECTED, 0),
338                 NULL, NULL,},
339         {"/Apply as Filter/... or not Selected", NULL,
340                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_OR_NOT_SELECTED, 0),
341                 NULL, NULL,},
342
343         /* Prepare */
344         {"/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL,},
345         {"/Prepare a Filter/Selected", NULL,
346                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_SELECTED, 0),
347                 NULL, NULL,},
348         {"/Prepare a Filter/Not Selected", NULL,
349                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_NOT_SELECTED, 0),
350                 NULL, NULL,},
351         {"/Prepare a Filter/... and Selected", NULL,
352                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_AND_SELECTED, 0),
353                 NULL, NULL,},
354         {"/Prepare a Filter/... or Selected", NULL,
355                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_OR_SELECTED, 0),
356                 NULL, NULL,},
357         {"/Prepare a Filter/... and not Selected", NULL,
358                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_AND_NOT_SELECTED, 0),
359                 NULL, NULL,},
360         {"/Prepare a Filter/... or not Selected", NULL,
361                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_OR_NOT_SELECTED, 0),
362                 NULL, NULL,},
363
364         /* Find Frame */
365         {"/Find Frame", NULL, NULL, 0, "<Branch>", NULL,},
366         {"/Find Frame/Find Frame", NULL, NULL, 0, "<Branch>", NULL,},
367         {"/Find Frame/Find Frame/Selected", NULL,
368                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_FRAME(ACTYPE_SELECTED, 0),
369                 NULL, NULL,},
370         {"/Find Frame/Find Frame/Not Selected", NULL,
371                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_FRAME(ACTYPE_NOT_SELECTED, 0),
372                 NULL, NULL,},
373         /* Find Next */
374         {"/Find Frame/Find Next", NULL, NULL, 0, "<Branch>", NULL,},
375         {"/Find Frame/Find Next/Selected", NULL,
376                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_NEXT(ACTYPE_SELECTED, 0),
377                 NULL, NULL,},
378         {"/Find Frame/Find Next/Not Selected", NULL,
379                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_NEXT(ACTYPE_NOT_SELECTED, 0),
380                 NULL, NULL,},
381
382         /* Find Previous */
383         {"/Find Frame/Find Previous", NULL, NULL, 0, "<Branch>", NULL,},
384         {"/Find Frame/Find Previous/Selected", NULL,
385                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_PREVIOUS(ACTYPE_SELECTED, 0),
386                 NULL, NULL,},
387         {"/Find Frame/Find Previous/Not Selected", NULL,
388                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_PREVIOUS(ACTYPE_NOT_SELECTED, 0),
389                 NULL, NULL,},
390
391         /* Colorize Procedure */
392         {"/Colorize Procedure", NULL, NULL, 0, "<Branch>", NULL,},
393         {"/Colorize Procedure/Selected", NULL,
394                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_COLORIZE(ACTYPE_SELECTED, 0),
395                 NULL, NULL,},
396         {"/Colorize Procedure/Not Selected", NULL,
397                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_COLORIZE(ACTYPE_NOT_SELECTED, 0),
398                 NULL, NULL,},
399
400         /* Search Internet */
401         {"/Internet Search for Info Text", NULL,
402                 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_WEB_LOOKUP, NULL, NULL,}
403 };
404
405 static void
406 expert_goto_pkt_cb (GtkTreeSelection *selection, gpointer data _U_)
407 {
408         GtkTreeIter iter;
409         GtkTreeModel *model;
410         gchar *pkt;
411         gchar *grp;
412
413         if (gtk_tree_selection_get_selected (selection, &model, &iter))
414         {
415                 gtk_tree_model_get (model, &iter, 
416                                     PROTOCOL_COLUMN, &pkt,
417                                     GROUP_COLUMN,    &grp,
418                                     -1);
419
420                 if (strcmp(grp, "Packet:")==0) {
421                     cf_goto_frame(&cfile, atoi(pkt));
422                 }
423                 g_free (pkt);
424                 g_free (grp);
425         }
426 }
427
428 static void
429 error_create_popup_menu(error_equiv_table *err)
430 {
431     GtkItemFactory *item_factory;
432
433
434     err->select = gtk_tree_view_get_selection (GTK_TREE_VIEW (err->tree_view));
435     gtk_tree_selection_set_mode (err->select, GTK_SELECTION_SINGLE);
436     g_signal_connect (G_OBJECT (err->select), "changed",
437                   G_CALLBACK (expert_goto_pkt_cb),
438                   err);
439     item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
440
441     gtk_item_factory_create_items_ac(item_factory, sizeof(error_list_menu_items)/sizeof(error_list_menu_items[0]), error_list_menu_items, err, 2);
442
443     err->menu = gtk_item_factory_get_widget(item_factory, "<main>");
444     g_signal_connect(err->tree_view, "button_press_event", G_CALLBACK(error_show_popup_menu_cb), err);
445 }
446
447 void
448 init_error_table(error_equiv_table *err, guint num_procs, GtkWidget *vbox)
449 {
450     GtkTreeStore *store;
451     GtkWidget *tree;
452     GtkTreeViewColumn *column;
453     GtkCellRenderer *renderer;
454     GtkTreeSortable *sortable;
455
456     /* Create the store */
457     store = gtk_tree_store_new (4,       /* Total number of columns */
458 #if 0
459                                G_TYPE_POINTER,   /* Group              */
460                                G_TYPE_POINTER,   /* Protocol           */
461                                G_TYPE_POINTER,   /* Summary            */
462 #else
463                                G_TYPE_STRING,   /* Group              */
464                                G_TYPE_STRING,   /* Protocol           */
465                                G_TYPE_STRING,   /* Summary            */
466 #endif
467                                G_TYPE_INT);     /* Count              */
468
469     /* Create a view */
470     tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
471     err->tree_view = GTK_TREE_VIEW(tree);
472     sortable = GTK_TREE_SORTABLE(store);
473
474 #if GTK_CHECK_VERSION(2,6,0)
475         /* Speed up the list display */
476         gtk_tree_view_set_fixed_height_mode(err->tree_view, TRUE);
477 #endif
478
479     /* Setup the sortable columns */
480 #if 0
481     gtk_tree_sortable_set_sort_func(sortable, SORT_ALPHABETICAL, sort_iter_compare_func, GINT_TO_POINTER(SORT_ALPHABETICAL), NULL);
482     gtk_tree_sortable_set_sort_column_id(sortable, SORT_ALPHABETICAL, GTK_SORT_ASCENDING);
483 #endif
484     gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW (tree), FALSE);
485
486     /* The view now holds a reference.  We can get rid of our own reference */
487     g_object_unref (G_OBJECT (store));
488
489     /* Create a cell renderer */
490     renderer = gtk_cell_renderer_text_new ();
491
492     /* Create the first column, associating the "text" attribute of the
493      * cell_renderer to the first column of the model */
494     column = gtk_tree_view_column_new_with_attributes ("Group", renderer, "text", GROUP_COLUMN, NULL);
495     gtk_tree_view_column_set_sort_column_id(column, GROUP_COLUMN);
496     gtk_tree_view_column_set_resizable(column, TRUE);
497     gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
498     gtk_tree_view_column_set_min_width(column, 80);
499     /* Add the column to the view. */
500     gtk_tree_view_append_column (GTK_TREE_VIEW (err->tree_view), column);
501  
502     /* Second column.. Protocol. */
503     renderer = gtk_cell_renderer_text_new ();
504     column = gtk_tree_view_column_new_with_attributes ("Protocol", renderer, "text", PROTOCOL_COLUMN, NULL);
505     gtk_tree_view_column_set_sort_column_id(column, PROTOCOL_COLUMN);
506     gtk_tree_view_column_set_resizable(column, TRUE);
507     gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
508     gtk_tree_view_column_set_min_width(column, 80);
509     gtk_tree_view_append_column (GTK_TREE_VIEW (err->tree_view), column);
510  
511     /* Third column.. Summary. */
512     renderer = gtk_cell_renderer_text_new ();
513     column = gtk_tree_view_column_new_with_attributes ("Summary", renderer, "text", SUMMARY_COLUMN, NULL);
514     gtk_tree_view_column_set_sort_column_id(column, SUMMARY_COLUMN);
515     gtk_tree_view_column_set_resizable(column, TRUE);
516     gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
517     gtk_tree_view_column_set_min_width(column, 90);
518     gtk_tree_view_append_column (GTK_TREE_VIEW (err->tree_view), column);
519  
520     /* Last column.. Count. */
521     column = gtk_tree_view_column_new_with_attributes ("Count", renderer, "text", COUNT_COLUMN, NULL);
522     gtk_tree_view_column_set_sort_column_id(column, COUNT_COLUMN);
523     gtk_tree_view_column_set_resizable(column, TRUE);
524     gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
525     gtk_tree_view_column_set_min_width(column, 80);
526     gtk_tree_view_append_column (GTK_TREE_VIEW (err->tree_view), column);
527  
528     err->scrolled_window=scrolled_window_new(NULL, NULL);
529
530     gtk_container_add(GTK_CONTAINER(err->scrolled_window), GTK_WIDGET (err->tree_view));
531
532     gtk_box_pack_start(GTK_BOX(vbox), err->scrolled_window, TRUE, TRUE, 0);
533
534     gtk_tree_view_set_search_column (err->tree_view, SUMMARY_COLUMN); /* Allow searching the summary */
535     gtk_tree_view_set_reorderable (err->tree_view, TRUE);   /* Allow user to reorder data with drag n drop */
536     
537     /* Now enable the sorting of each column */
538     gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(err->tree_view), TRUE);
539     gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(err->tree_view), TRUE);
540
541     gtk_widget_show(err->scrolled_window);
542
543     err->num_procs=num_procs;
544
545     err->text = g_string_chunk_new(100);
546     err->procs_array = g_array_sized_new(FALSE, FALSE, sizeof(error_procedure_t), num_procs);
547
548     /* create popup menu for this table */
549     error_create_popup_menu(err);
550 }
551
552 void
553 init_error_table_row(error_equiv_table *err, const expert_info_t *expert_data)
554 {
555     guint old_num_procs=err->num_procs;
556     guint j;
557     gint row=0;
558     error_procedure_t *procedure;
559     GtkTreeStore *store;
560     GtkTreeIter   new_iter;
561
562     /* we have discovered a new procedure. Extend the table accordingly */
563     row = find_summary_data(err, expert_data);
564     if(row==-1){
565         error_procedure_t new_procedure;
566         /* First time we have seen this event so initialize memory table */
567         row = old_num_procs; /* Number of expert events since this is a new event */
568
569         new_procedure.count=0; /* count of events for this item */
570         new_procedure.fvalue_value = NULL; /* Filter string value */
571         for(j=0;j<4;j++){
572             new_procedure.entries[j]=NULL;
573         }
574         g_array_append_val(err->procs_array, new_procedure);
575         procedure = &g_array_index(err->procs_array, error_procedure_t, row);
576         
577         /* Create the item in our memory table */
578         procedure->entries[0]=(char *)g_string_chunk_insert(err->text, 
579                 val_to_str(expert_data->group, expert_group_vals,"Unknown group (%u)"));  /* Group */
580         procedure->entries[1]=(char *)g_string_chunk_insert(err->text, expert_data->protocol);    /* Protocol */
581         procedure->entries[2]=(char *)g_string_chunk_insert(err->text, expert_data->summary);     /* Summary */
582
583         /* Create a new item in our tree view */
584         store = GTK_TREE_STORE(gtk_tree_view_get_model(err->tree_view)); /* Get store */
585         gtk_tree_store_append (store, &procedure->iter, NULL);  /* Acquire an iterator */
586         
587         gtk_tree_store_set (store, &procedure->iter,
588                     GROUP_COLUMN, procedure->entries[0],
589                     PROTOCOL_COLUMN, procedure->entries[1],
590                     SUMMARY_COLUMN,  procedure->entries[2], -1);
591         
592         /* If an expert item was passed then build the filter string */
593         if (expert_data->pitem) {
594             char *filter;
595             
596             g_assert(PITEM_FINFO(expert_data->pitem));
597             filter = proto_construct_match_selected_string(PITEM_FINFO(expert_data->pitem), NULL);
598             if (filter != NULL)
599                 procedure->fvalue_value = g_string_chunk_insert(err->text, filter);
600         }
601         /* Store the updated count of events */
602         err->num_procs = ++old_num_procs;
603     }
604
605     /* Update our memory table with event data */
606     procedure = &g_array_index(err->procs_array, error_procedure_t, row);
607     procedure->count++; /* increment the count of events for this item */
608
609 #if 0
610     /* Store the updated count for this event item */
611     err->procedures[row].entries[3]=(char *)g_strdup_printf("%d", err->procedures[row].count);     /* Count */
612 #endif
613
614     /* Update the tree with new count for this event */
615     store = GTK_TREE_STORE(gtk_tree_view_get_model(err->tree_view));
616     gtk_tree_store_set(store, &procedure->iter, COUNT_COLUMN, procedure->count, -1);
617     gtk_tree_store_append(store, &new_iter, &procedure->iter);
618     gtk_tree_store_set(store, &new_iter,
619                        GROUP_COLUMN,    "Packet:",
620                        PROTOCOL_COLUMN, (char *)g_strdup_printf("%d", expert_data->packet_num),
621                        COUNT_COLUMN,    1,
622                        -1);
623 }
624
625 void
626 reset_error_table_data(error_equiv_table *err)
627 {
628     GtkTreeStore    *store;
629
630     store = GTK_TREE_STORE(gtk_tree_view_get_model(err->tree_view));
631     gtk_tree_store_clear(store);
632     err->num_procs = 0;
633     /* g_string_chunk_clear() is introduced in glib 2.14 */
634     g_string_chunk_free(err->text);
635     err->text = g_string_chunk_new(100);
636
637     g_array_set_size(err->procs_array, 0);
638 }
639
640 void
641 free_error_table_data(error_equiv_table *err)
642 {
643     err->num_procs=0;
644     g_string_chunk_free(err->text);
645     g_array_free(err->procs_array, TRUE);
646 }