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
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
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.
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.
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.
39 #include "epan/packet_info.h"
40 #include "epan/strutil.h"
42 #include <epan/expert.h>
44 #include "../simple_dialog.h"
45 #include "../globals.h"
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"
53 #include "gtk/gui_utils.h"
54 #include "gtk/gtkglobals.h"
55 #include "gtk/webbrowser.h"
57 const char *packet = "Packet:";
69 proto_data_func (GtkTreeViewColumn *column _U_,
70 GtkCellRenderer *renderer,
76 gchar *grp = NULL; /* type pointer, don't free */
78 /* The col to get data from is in userdata */
79 gint data_column = GPOINTER_TO_INT(user_data);
81 gtk_tree_model_get(model, iter, data_column, &str, -1);
82 gtk_tree_model_get(model, iter, GROUP_COLUMN, &grp, -1);
83 /* XXX should we check that str is non NULL and print a warning or do assert? */
85 g_object_set(renderer, "text", str, NULL);
87 /* it's a number right align */
88 g_object_set(renderer, "xalign", 1.0, NULL);
91 g_object_set(renderer, "xalign", 0.0, NULL);
97 proto_sort_func(GtkTreeModel *model,
104 gchar *grp = NULL; /* type pointer, don't free */
107 /* The col to get data from is in userdata */
108 gint data_column = GPOINTER_TO_INT(user_data);
110 gtk_tree_model_get(model, a, data_column, &str_a, -1);
111 gtk_tree_model_get(model, b, data_column, &str_b, -1);
112 gtk_tree_model_get(model, a, GROUP_COLUMN, &grp, -1);
114 if (str_a == str_b) {
117 else if (str_a == NULL || str_b == NULL) {
118 ret = (str_a == NULL) ? -1 : 1;
122 gint int_a = atoi(str_a);
123 gint int_b = atoi(str_b);
126 else if (int_a < int_b)
132 ret = g_ascii_strcasecmp(str_a,str_b);
139 static gint find_summary_data(error_equiv_table *err, const expert_info_t *expert_data)
142 error_procedure_t *procedure;
144 /* First time thru values will be 0 */
145 if (err->num_procs==0) {
148 for (i=0;i<err->num_procs;i++) {
149 procedure = &g_array_index(err->procs_array, error_procedure_t, i);
150 if (strcmp(procedure->entries[0], expert_data->protocol) == 0 &&
151 strcmp(procedure->entries[1], expert_data->summary) == 0) {
159 error_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint callback_action)
161 int action, type, selection;
162 error_equiv_table *err = (error_equiv_table *)callback_data;
164 const char *current_filter;
165 error_procedure_t *procedure;
169 expert_info_t expert_data;
172 action=FILTER_ACTION(callback_action);
173 type=FILTER_ACTYPE(callback_action);
176 gtk_tree_selection_get_selected(err->select, &model, &iter);
178 gtk_tree_model_get (model, &iter,
180 PROTOCOL_COLUMN, &expert_data.protocol,
181 SUMMARY_COLUMN, &expert_data.summary,
184 if (strcmp(grp, packet)==0) {
185 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "You cannot filter or search for packet number. Click on a valid item header.");
186 g_free(expert_data.summary);
190 /* XXX: find_summary_data doesn't (currently) reference expert_data.group. */
191 /* If "group" is required, then the message from GROUP_COLUMN will need */
192 /* to be translated to the group number (or the actual group number */
193 /* will also need to be stored in the TreeModel). */
194 selection = find_summary_data(err, &expert_data);
195 /* g_free(expert_data.protocol); - const */
196 g_free(expert_data.summary);
198 if(selection>=(int)err->num_procs){
199 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No items are selected");
202 current_filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
204 /* Some expert data doesn't pass an expert item. Without this we cannot create a filter */
205 /* But allow for searching of internet for error string */
206 procedure = &g_array_index(err->procs_array, error_procedure_t, selection);
208 /* FIXME what is 7 ?*/
209 if (action != ACTION_WEB_LOOKUP && action != 7) {
211 if (0 /*procedure->fvalue_value==NULL*/) {
212 if (action != ACTION_FIND_FRAME && action != ACTION_FIND_NEXT && action != ACTION_FIND_PREVIOUS) {
213 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Wireshark cannot create a filter on this item - %s, try using find instead.",
214 procedure->entries[1]);
218 msg = g_malloc(escape_string_len(procedure->entries[1]));
219 escape_string(msg, procedure->entries[1]);
221 case ACTYPE_SELECTED:
222 /* if no expert item was passed */
223 if (procedure->fvalue_value==NULL) {
224 g_snprintf(str, sizeof(str), "expert.message==%s", msg);
228 /* expert item exists. Use it. */
229 g_strlcpy(str, procedure->fvalue_value, sizeof(str));
232 case ACTYPE_NOT_SELECTED:
233 /* if no expert item was passed */
234 if (procedure->fvalue_value==NULL) {
235 g_snprintf(str, sizeof(str), "!(expert.message==%s)", msg);
239 /* expert item exists. Use it. */
240 g_snprintf(str, sizeof(str), "!(%s)", procedure->fvalue_value);
243 /* the remaining cases will only exist if the expert item exists so no need to check */
244 case ACTYPE_AND_SELECTED:
245 if ((!current_filter) || (0 == strlen(current_filter)))
246 g_snprintf(str, sizeof(str), "expert.message==%s", msg);
248 g_snprintf(str, sizeof(str), "(%s) && (expert.message==%s)", current_filter, msg);
250 case ACTYPE_OR_SELECTED:
251 if ((!current_filter) || (0 == strlen(current_filter)))
252 g_snprintf(str, sizeof(str), "expert.message==%s", msg);
254 g_snprintf(str, sizeof(str), "(%s) || (expert.message==%s)", current_filter, msg);
256 case ACTYPE_AND_NOT_SELECTED:
257 if ((!current_filter) || (0 == strlen(current_filter)))
258 g_snprintf(str, sizeof(str), "!(expert.message==%s)", msg);
260 g_snprintf(str, sizeof(str), "(%s) && !(expert.message==%s)", current_filter, msg);
262 case ACTYPE_OR_NOT_SELECTED:
263 if ((!current_filter) || (0 == strlen(current_filter)))
264 g_snprintf(str, sizeof(str), "!(expert.message==%s)", msg);
266 g_snprintf(str, sizeof(str), "(%s) || !(expert.message==%s)", current_filter, msg);
269 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't find menu type - %u", type);
276 main_filter_packets(&cfile, str, FALSE);
279 gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
281 case ACTION_FIND_FRAME:
282 /* When trying to perform a find without expert item, we must pass
283 * the expert string to the find window. The user might need to modify
284 * the string and click on the text search to locate the packet in question.
285 * So regardless of the type we will just bring up the find window and allow
286 * the user to modify the search criteria and options.
288 find_frame_with_filter(str);
290 case ACTION_FIND_NEXT:
291 /* In the case of find next, if there was no expert item, then most likely the expert
292 * string was modified to locate the text inside the message. So we can't just perform
293 * a find with the expert string or we will not really be performing a find next.
294 * In an effort to allow the user to modify the string and/or continue searching, we
295 * will just present the user with the find window again with the default expert string.
296 * A better aproach would be to attempt in capturing the last find string and utilize this
297 * with a find next/previous. Also a better approach might be to just send a <Ctl-N> keystroke.
299 if (procedure->fvalue_value==NULL) {
300 find_frame_with_filter(str);
304 /* We have an expert item so just continue search without find dialog. */
305 find_previous_next_frame_with_filter(str, FALSE);
308 case ACTION_FIND_PREVIOUS:
309 /* In the case of find previous, if there was no expert item, then most likely the expert
310 * string was modified to locate the text inside the message. So we can't just perform
311 * a find with the expert string or we will not really be performing a find previous.
312 * In an effort to allow the user to modify the string and/or continue searching, we
313 * will just present the user with the find window again with the default expert string.
314 * A better aproach would be to attempt in capturing the last find string and utilize this
315 * with a find next/previous. Also a better approach might be to just send a <Ctl-B> keystroke.
317 if (procedure->fvalue_value==NULL) {
318 find_frame_with_filter(str);
322 /* We have an expert item so just continue search without find dialog. */
323 find_previous_next_frame_with_filter(str, TRUE);
326 case ACTION_COLORIZE:
327 color_display_with_filter(str);
329 case ACTION_WEB_LOOKUP:
330 /* Lookup expert string on internet. Default search via www.google.com */
331 g_snprintf(str, sizeof(str), "http://www.google.com/search?hl=en&q=%s+'%s'", procedure->entries[0], procedure->entries[1]);
332 browser_open_url(str);
335 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Can't find menu action - %u", action);
340 error_show_popup_menu_cb(void *widg _U_, GdkEvent *event, error_equiv_table *err)
342 GdkEventButton *bevent = (GdkEventButton *)event;
344 if(event->type==GDK_BUTTON_PRESS && bevent->button==3){
345 gtk_menu_popup(GTK_MENU(err->menu), NULL, NULL, NULL, NULL,
346 bevent->button, bevent->time);
352 static GtkItemFactoryEntry error_list_menu_items[] =
355 {"/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL,},
356 {"/Apply as Filter/Selected", NULL,
357 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_SELECTED, 0),
359 {"/Apply as Filter/... not Selected", NULL,
360 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_NOT_SELECTED, 0),
362 {"/Apply as Filter/.. and Selected", NULL,
363 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_AND_SELECTED, 0),
365 {"/Apply as Filter/... or Selected", NULL,
366 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_OR_SELECTED, 0),
368 {"/Apply as Filter/... and not Selected", NULL,
369 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_AND_NOT_SELECTED, 0),
371 {"/Apply as Filter/... or not Selected", NULL,
372 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_MATCH(ACTYPE_OR_NOT_SELECTED, 0),
376 {"/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL,},
377 {"/Prepare a Filter/Selected", NULL,
378 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_SELECTED, 0),
380 {"/Prepare a Filter/Not Selected", NULL,
381 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_NOT_SELECTED, 0),
383 {"/Prepare a Filter/... and Selected", NULL,
384 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_AND_SELECTED, 0),
386 {"/Prepare a Filter/... or Selected", NULL,
387 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_OR_SELECTED, 0),
389 {"/Prepare a Filter/... and not Selected", NULL,
390 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_AND_NOT_SELECTED, 0),
392 {"/Prepare a Filter/... or not Selected", NULL,
393 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_PREPARE(ACTYPE_OR_NOT_SELECTED, 0),
397 {"/Find Frame", NULL, NULL, 0, "<Branch>", NULL,},
398 {"/Find Frame/Find Frame", NULL, NULL, 0, "<Branch>", NULL,},
399 {"/Find Frame/Find Frame/Selected", NULL,
400 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_FRAME(ACTYPE_SELECTED, 0),
402 {"/Find Frame/Find Frame/Not Selected", NULL,
403 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_FRAME(ACTYPE_NOT_SELECTED, 0),
406 {"/Find Frame/Find Next", NULL, NULL, 0, "<Branch>", NULL,},
407 {"/Find Frame/Find Next/Selected", NULL,
408 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_NEXT(ACTYPE_SELECTED, 0),
410 {"/Find Frame/Find Next/Not Selected", NULL,
411 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_NEXT(ACTYPE_NOT_SELECTED, 0),
415 {"/Find Frame/Find Previous", NULL, NULL, 0, "<Branch>", NULL,},
416 {"/Find Frame/Find Previous/Selected", NULL,
417 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_PREVIOUS(ACTYPE_SELECTED, 0),
419 {"/Find Frame/Find Previous/Not Selected", NULL,
420 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_FIND_PREVIOUS(ACTYPE_NOT_SELECTED, 0),
423 /* Colorize Procedure */
424 {"/Colorize Procedure", NULL, NULL, 0, "<Branch>", NULL,},
425 {"/Colorize Procedure/Selected", NULL,
426 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_COLORIZE(ACTYPE_SELECTED, 0),
428 {"/Colorize Procedure/Not Selected", NULL,
429 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_COLORIZE(ACTYPE_NOT_SELECTED, 0),
432 /* Search Internet */
433 {"/Internet Search for Info Text", NULL,
434 GTK_MENU_FUNC(error_select_filter_cb), CALLBACK_WEB_LOOKUP, NULL, NULL,}
438 /* Prepare to change GtkItemFactory to GtkUIManager */
440 apply_as_selected_cb(GtkAction *action)
444 apply_as_not_selected_cb(GtkAction *action)
448 apply_as_and_selected_cb(GtkAction *action)
452 apply_as_or_selected_cb(GtkAction *action)
456 apply_as_and_not_selected_cb(GtkAction *action)
460 apply_as_or_not_selected_cb(GtkAction *action)
465 prep_as_selected_cb(GtkAction *action)
469 prep_as_not_selected_cb(GtkAction *action)
473 prep_as_and_selected_cb(GtkAction *action)
477 prep_as_or_selected_cb(GtkAction *action)
481 prep_as_and_not_selected_cb(GtkAction *action)
485 prep_as_or_not_selected_cb(GtkAction *action)
490 find_selected_cb(GtkAction *action)
494 find_not_selected_cb(GtkAction *action)
498 find_prev_selected_cb(GtkAction *action)
502 find_prev_not_selected_cb(GtkAction *action)
506 find_next_selected_cb(GtkAction *action)
510 find_next_not_selected_cb(GtkAction *action)
514 color_next_selected_cb(GtkAction *action)
518 color_next_not_selected_cb(GtkAction *action)
521 static const char *ui_description =
523 " <popup name='MainMenu'>"
524 " <menu action='/Apply as Filter'>"
525 " <menuitem action='/Apply as Filter/Selected'/>"
526 " <menuitem action='/Apply as Filter/... not Selected'/>"
527 " <menuitem action='/Apply as Filter/... and Selected'/>"
528 " <menuitem action='/Apply as Filter/... or Selected'/>"
529 " <menuitem action='/Apply as Filter/... and not Selected'/>"
530 " <menuitem action='/Apply as Filter/... or not Selected'/>"
532 " <menu action='/Prepare a Filter'>"
533 " <menuitem action='/Prepare a Filter/Selected'/>"
534 " <menuitem action='/Prepare a Filter/... not Selected'/>"
535 " <menuitem action='/Prepare a Filter/... and Selected'/>"
536 " <menuitem action='/Prepare a Filter/... or Selected'/>"
537 " <menuitem action='/Prepare a Filter/... and not Selected'/>"
538 " <menuitem action='/Prepare a Filter/... or not Selected'/>"
540 " <menu action='/Find Frame'>"
541 " <menu action='/Find Frame/Find Frame'>"
542 " <menuitem action='/Find Frame/Selected'/>"
543 " <menuitem action='/Find Frame/Not Selected'/>"
545 " <menu action='/Find Frame/Find Next'>"
546 " <menuitem action='/Find Next/Selected'/>"
547 " <menuitem action='/Find Next/Not Selected'/>"
549 " <menu action='/Find Frame/Find Previous'>"
550 " <menuitem action='/Find Previous/Selected'/>"
551 " <menuitem action='/Find Previous/Not Selected'/>"
554 " <menu action='/Colorize Procedure'>"
555 " <menuitem action='/Colorize Procedure/Selected'/>"
556 " <menuitem action='/Colorize Procedure/Not Selected'/>"
563 static const GtkActionEntry entries[] = {
564 { "/Apply as Filter", NULL, "Apply as Filter" },
565 { "/Prepare a Filter", NULL, "Prepare a Filter" },
566 { "/Find Frame", NULL, "Find Frame" },
567 { "/Find Frame/Find Frame", NULL, "Find Frame" },
568 { "/Find Frame/Find Next", NULL, "Find Next" },
569 { "/Find Frame/Find Previous", NULL, "Find Previous" },
570 { "/Colorize Procedure", NULL, "Colorize Procedure" },
571 { "/Apply as Filter/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(apply_as_selected_cb) },
572 { "/Apply as Filter/... not Selected", NULL, "... not Selected", NULL, "... not Selected", G_CALLBACK(apply_as_not_selected_cb) },
573 { "/Apply as Filter/... and Selected", NULL, "... and Selected", NULL, "... and Selected", G_CALLBACK(apply_as_and_selected_cb) },
574 { "/Apply as Filter/... or Selected", NULL, "... or Selected", NULL, "... or Selected", G_CALLBACK(apply_as_or_selected_cb) },
575 { "/Apply as Filter/... and not Selected", NULL, "... and not Selected", NULL, "... and not Selected", G_CALLBACK(apply_as_and_not_selected_cb) },
576 { "/Apply as Filter/... or not Selected", NULL, "... or not Selected", NULL, "... or not Selected", G_CALLBACK(apply_as_or_not_selected_cb) },
577 { "/Prepare a Filter/Selected", NULL, "Selected", NULL, "selcted", G_CALLBACK(prep_as_selected_cb) },
578 { "/Prepare a Filter/... not Selected", NULL, "... not Selected", NULL, "... not Selected", G_CALLBACK(prep_as_not_selected_cb) },
579 { "/Prepare a Filter/... and Selected", NULL, "... and Selected", NULL, "... and Selected", G_CALLBACK(prep_as_and_selected_cb) },
580 { "/Prepare a Filter/... or Selected", NULL, "... or Selected", NULL, "... or Selected", G_CALLBACK(prep_as_or_selected_cb) },
581 { "/Prepare a Filter/... and not Selected", NULL, "... and not Selected", NULL, "... and not Selected", G_CALLBACK(prep_as_and_not_selected_cb) },
582 { "/Prepare a Filter/... or not Selected", NULL, "... or not Selected", NULL, "... or not Selected", G_CALLBACK(prep_as_or_not_selected_cb) },
583 { "/Find Frame/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(find_selected_cb) },
584 { "/Find Frame/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(find_not_selected_cb) },
585 { "/Find Previous/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(find_prev_selected_cb) },
586 { "/Find Previous/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(find_prev_not_selected_cb) },
587 { "/Find Next/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(find_next_selected_cb) },
588 { "/Find Next/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(find_next_not_selected_cb) },
589 { "/Colorize Procedure/Selected", NULL, "Selected", NULL, "Selected", G_CALLBACK(color_next_selected_cb) },
590 { "/Colorize Procedure/Not Selected", NULL, "Not Selected", NULL, "Not Selected", G_CALLBACK(color_next_not_selected_cb) },
594 expert_goto_pkt_cb (GtkTreeSelection *selection, gpointer data _U_)
601 if (gtk_tree_selection_get_selected (selection, &model, &iter))
603 gtk_tree_model_get (model, &iter,
604 PROTOCOL_COLUMN, &pkt,
608 if (strcmp(grp, packet)==0) {
609 cf_goto_frame(&cfile, atoi(pkt));
616 error_create_popup_menu(error_equiv_table *err)
618 GtkItemFactory *item_factory;
621 err->select = gtk_tree_view_get_selection (GTK_TREE_VIEW (err->tree_view));
622 gtk_tree_selection_set_mode (err->select, GTK_SELECTION_SINGLE);
623 g_signal_connect (G_OBJECT (err->select), "changed",
624 G_CALLBACK (expert_goto_pkt_cb),
626 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
628 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);
630 err->menu = gtk_item_factory_get_widget(item_factory, "<main>");
631 g_signal_connect(err->tree_view, "button_press_event", G_CALLBACK(error_show_popup_menu_cb), err);
635 init_error_table(error_equiv_table *err, guint num_procs, GtkWidget *vbox)
639 GtkTreeViewColumn *column;
640 GtkCellRenderer *renderer;
641 GtkTreeSortable *sortable;
643 /* Create the store */
644 store = gtk_tree_store_new (4, /* Total number of columns */
645 G_TYPE_POINTER, /* Group */
646 G_TYPE_STRING, /* Protocol */
647 G_TYPE_STRING, /* Summary */
648 G_TYPE_INT); /* Count */
651 tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
652 err->tree_view = GTK_TREE_VIEW(tree);
653 sortable = GTK_TREE_SORTABLE(store);
655 #if GTK_CHECK_VERSION(2,6,0)
656 /* Speed up the list display */
657 gtk_tree_view_set_fixed_height_mode(err->tree_view, TRUE);
660 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW (tree), FALSE);
662 /* The view now holds a reference. We can get rid of our own reference */
663 g_object_unref (G_OBJECT (store));
665 /* Create a cell renderer */
666 renderer = gtk_cell_renderer_text_new ();
668 /* Create the first column, associating the "text" attribute of the
669 * cell_renderer to the first column of the model */
670 column = gtk_tree_view_column_new_with_attributes ("Group", renderer, NULL);
671 gtk_tree_view_column_set_sort_column_id(column, GROUP_COLUMN);
672 gtk_tree_view_column_set_resizable(column, TRUE);
673 gtk_tree_view_column_set_cell_data_func(column, renderer, str_ptr_data_func,
674 GINT_TO_POINTER(GROUP_COLUMN), NULL);
676 gtk_tree_sortable_set_sort_func(sortable, GROUP_COLUMN, str_ptr_sort_func,
677 GINT_TO_POINTER(GROUP_COLUMN), NULL);
679 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
680 gtk_tree_view_column_set_min_width(column, 80);
681 /* Add the column to the view. */
682 gtk_tree_view_append_column (GTK_TREE_VIEW (err->tree_view), column);
684 /* Second column.. Protocol. */
685 renderer = gtk_cell_renderer_text_new ();
686 column = gtk_tree_view_column_new_with_attributes ("Protocol", renderer, "text", PROTOCOL_COLUMN, NULL);
687 gtk_tree_view_column_set_sort_column_id(column, PROTOCOL_COLUMN);
688 gtk_tree_view_column_set_resizable(column, TRUE);
689 gtk_tree_view_column_set_cell_data_func(column, renderer, proto_data_func,
690 GINT_TO_POINTER(PROTOCOL_COLUMN), NULL);
692 gtk_tree_sortable_set_sort_func(sortable, PROTOCOL_COLUMN, proto_sort_func,
693 GINT_TO_POINTER(PROTOCOL_COLUMN), NULL);
695 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
696 gtk_tree_view_column_set_min_width(column, 40);
697 gtk_tree_view_column_set_fixed_width(column, 100);
698 gtk_tree_view_append_column (GTK_TREE_VIEW (err->tree_view), column);
700 /* Third column.. Summary. */
701 renderer = gtk_cell_renderer_text_new ();
702 column = gtk_tree_view_column_new_with_attributes ("Summary", renderer, "text", SUMMARY_COLUMN, NULL);
703 gtk_tree_view_column_set_sort_column_id(column, SUMMARY_COLUMN);
704 gtk_tree_view_column_set_resizable(column, TRUE);
705 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
706 gtk_tree_view_column_set_min_width(column, 80);
707 gtk_tree_view_column_set_fixed_width(column, 230);
708 gtk_tree_view_append_column (GTK_TREE_VIEW (err->tree_view), column);
710 /* Last column.. Count. */
711 renderer = gtk_cell_renderer_text_new ();
713 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
714 column = gtk_tree_view_column_new_with_attributes ("Count", renderer, "text", COUNT_COLUMN, NULL);
715 gtk_tree_view_column_set_sort_column_id(column, COUNT_COLUMN);
716 gtk_tree_view_column_set_resizable(column, TRUE);
717 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
718 gtk_tree_view_column_set_min_width(column, 80);
719 gtk_tree_view_append_column (GTK_TREE_VIEW (err->tree_view), column);
721 err->scrolled_window=scrolled_window_new(NULL, NULL);
723 gtk_container_add(GTK_CONTAINER(err->scrolled_window), GTK_WIDGET (err->tree_view));
725 gtk_box_pack_start(GTK_BOX(vbox), err->scrolled_window, TRUE, TRUE, 0);
727 gtk_tree_view_set_search_column (err->tree_view, SUMMARY_COLUMN); /* Allow searching the summary */
728 gtk_tree_view_set_reorderable (err->tree_view, TRUE); /* Allow user to reorder data with drag n drop */
730 /* Now enable the sorting of each column */
731 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(err->tree_view), TRUE);
732 gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(err->tree_view), TRUE);
734 gtk_widget_show(err->scrolled_window);
736 err->num_procs=num_procs;
738 err->text = g_string_chunk_new(100);
739 err->procs_array = g_array_sized_new(FALSE, FALSE, sizeof(error_procedure_t), num_procs);
741 /* create popup menu for this table */
742 error_create_popup_menu(err);
746 init_error_table_row(error_equiv_table *err, const expert_info_t *expert_data)
748 guint old_num_procs=err->num_procs;
750 error_procedure_t *procedure;
752 GtkTreeIter new_iter;
755 /* we have discovered a new procedure. Extend the table accordingly */
756 row = find_summary_data(err, expert_data);
758 error_procedure_t new_procedure;
759 /* First time we have seen this event so initialize memory table */
760 row = old_num_procs; /* Number of expert events since this is a new event */
762 new_procedure.count=0; /* count of events for this item */
763 new_procedure.fvalue_value = NULL; /* Filter string value */
765 g_array_append_val(err->procs_array, new_procedure);
766 procedure = &g_array_index(err->procs_array, error_procedure_t, row);
768 /* Create the item in our memory table */
769 procedure->entries[0]=(char *)g_string_chunk_insert_const(err->text, expert_data->protocol); /* Protocol */
770 procedure->entries[1]=(char *)g_string_chunk_insert_const(err->text, expert_data->summary); /* Summary */
772 /* Create a new item in our tree view */
773 store = GTK_TREE_STORE(gtk_tree_view_get_model(err->tree_view)); /* Get store */
774 gtk_tree_store_append (store, &procedure->iter, NULL); /* Acquire an iterator */
776 /* match_strval return a static constant or null */
777 gtk_tree_store_set (store, &procedure->iter,
778 GROUP_COLUMN, match_strval(expert_data->group, expert_group_vals),
779 PROTOCOL_COLUMN, procedure->entries[0],
780 SUMMARY_COLUMN, procedure->entries[1], -1);
782 /* If an expert item was passed then build the filter string */
783 if (expert_data->pitem) {
786 g_assert(PITEM_FINFO(expert_data->pitem));
787 filter = proto_construct_match_selected_string(PITEM_FINFO(expert_data->pitem), NULL);
789 procedure->fvalue_value = g_string_chunk_insert_const(err->text, filter);
791 /* Store the updated count of events */
792 err->num_procs = ++old_num_procs;
795 /* Update our memory table with event data */
796 procedure = &g_array_index(err->procs_array, error_procedure_t, row);
797 procedure->count++; /* increment the count of events for this item */
799 /* Update the tree with new count for this event */
800 store = GTK_TREE_STORE(gtk_tree_view_get_model(err->tree_view));
801 gtk_tree_store_set(store, &procedure->iter,
802 COUNT_COLUMN, procedure->count,
805 g_snprintf(num, sizeof(num), "%d", expert_data->packet_num);
807 This does not have a big performance improvment :(
808 if GTK_CHECK_VERSION(2,10,0)
809 gtk_tree_store_insert_with_values (store,
810 &new_iter, /* *iter */
811 &procedure->iter, /* *parent*/
812 G_MAXINT, /* position */
816 /* FIXME gtk is plagued with slow algorithms
817 gtk_tree_store_append call new_path and its nice recursive linear search....
819 if (procedure->count > 1000) {
820 /* If there's more than 1000 sub rows give up and prepend new rows, at least
821 it will end in a reasonable time. Anyway with so many rows it's not
822 very useful and if sorted the right order is restored.
824 gtk_tree_store_prepend(store, &new_iter, &procedure->iter);
827 gtk_tree_store_append(store, &new_iter, &procedure->iter);
829 gtk_tree_store_set(store, &new_iter,
831 GROUP_COLUMN, packet,
832 PROTOCOL_COLUMN, num,
838 reset_error_table_data(error_equiv_table *err)
842 store = GTK_TREE_STORE(gtk_tree_view_get_model(err->tree_view));
843 gtk_tree_store_clear(store);
845 /* g_string_chunk_clear() is introduced in glib 2.14 */
846 g_string_chunk_free(err->text);
847 err->text = g_string_chunk_new(100);
849 g_array_set_size(err->procs_array, 0);
853 free_error_table_data(error_equiv_table *err)
856 g_string_chunk_free(err->text);
857 g_array_free(err->procs_array, TRUE);