void ColumnPreferencesFrame::on_columnTreeWidget_currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *previous) { if (previous) { if (ui->columnTreeWidget->itemWidget(previous, title_col_)) { ui->columnTreeWidget->removeItemWidget(previous, title_col_); } if (ui->columnTreeWidget->itemWidget(previous, type_col_)) { ui->columnTreeWidget->removeItemWidget(previous, type_col_); previous->setText(type_col_, col_format_desc(previous->data(type_col_, Qt::UserRole).toInt())); } if (ui->columnTreeWidget->itemWidget(previous, custom_fields_col_)) { ui->columnTreeWidget->removeItemWidget(previous, custom_fields_col_); } if (ui->columnTreeWidget->itemWidget(previous, custom_occurrence_col_)) { ui->columnTreeWidget->removeItemWidget(previous, custom_occurrence_col_); } // If the custom column auto-changed the Column type, change it back if // there isn't any text in the field columns if ((previous->text(custom_fields_col_) == "") && (previous->text(custom_occurrence_col_) == "") && (saved_custom_combo_idx_ >= 0)) { previous->setText(type_col_, col_format_desc(saved_custom_combo_idx_)); previous->setData(type_col_, Qt::UserRole, QVariant(saved_custom_combo_idx_)); saved_custom_combo_idx_ = -1; } } updateWidgets(); }
void ColumnPreferencesFrame::columnTypeCurrentIndexChanged(int index) { QTreeWidgetItem *item = ui->columnTreeWidget->currentItem(); if (!item || index < 0) return; item->setData(type_col_, Qt::UserRole, QVariant(index)); item->setText(type_col_, col_format_desc(index)); if (index != COL_CUSTOM) { item->setText(custom_field_col_, ""); item->setText(custom_occurrence_col_, ""); } }
void ColumnPreferencesFrame::addColumn(bool visible, const char *title, int fmt, const char *custom_field, int custom_occurrence) { QTreeWidgetItem *item = new QTreeWidgetItem(ui->columnTreeWidget); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled)); item->setCheckState(visible_col_, visible ? Qt::Checked : Qt::Unchecked); item->setText(title_col_, title); item->setText(type_col_, col_format_desc(fmt)); item->setData(type_col_, Qt::UserRole, QVariant(fmt)); if (fmt == COL_CUSTOM) { item->setText(custom_field_col_, custom_field); item->setText(custom_occurrence_col_, QString::number(custom_occurrence)); } }
void ColumnPreferencesFrame::on_columnTreeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) { ui->deleteToolButton->setEnabled(current ? true : false); if (previous && ui->columnTreeWidget->itemWidget(previous, title_col_)) { ui->columnTreeWidget->removeItemWidget(previous, title_col_); } if (previous && ui->columnTreeWidget->itemWidget(previous, type_col_)) { ui->columnTreeWidget->removeItemWidget(previous, type_col_); previous->setText(type_col_, col_format_desc(previous->data(type_col_, Qt::UserRole).toInt())); } if (previous && ui->columnTreeWidget->itemWidget(previous, custom_field_col_)) { ui->columnTreeWidget->removeItemWidget(previous, custom_field_col_); } if (previous && ui->columnTreeWidget->itemWidget(previous, custom_occurrence_col_)) { ui->columnTreeWidget->removeItemWidget(previous, custom_occurrence_col_); } }
void ColumnPreferencesFrame::on_columnTreeWidget_currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *previous) { if (previous && ui->columnTreeWidget->itemWidget(previous, title_col_)) { ui->columnTreeWidget->removeItemWidget(previous, title_col_); } if (previous && ui->columnTreeWidget->itemWidget(previous, type_col_)) { ui->columnTreeWidget->removeItemWidget(previous, type_col_); previous->setText(type_col_, col_format_desc(previous->data(type_col_, Qt::UserRole).toInt())); } if (previous && ui->columnTreeWidget->itemWidget(previous, custom_fields_col_)) { ui->columnTreeWidget->removeItemWidget(previous, custom_fields_col_); } if (previous && ui->columnTreeWidget->itemWidget(previous, custom_occurrence_col_)) { ui->columnTreeWidget->removeItemWidget(previous, custom_occurrence_col_); } updateWidgets(); }
void ColumnPreferencesFrame::on_columnTreeWidget_itemActivated(QTreeWidgetItem *item, int column) { if (!item || cur_line_edit_ || cur_combo_box_) return; QWidget *editor = NULL; cur_column_ = column; saved_combo_idx_ = item->data(type_col_, Qt::UserRole).toInt(); switch (column) { case title_col_: { cur_line_edit_ = new QLineEdit(); cur_column_ = column; saved_col_string_ = item->text(title_col_); connect(cur_line_edit_, SIGNAL(editingFinished()), this, SLOT(columnTitleEditingFinished())); editor = cur_line_edit_; break; } case type_col_: { cur_combo_box_ = new QComboBox(); for (int i = 0; i < NUM_COL_FMTS; i++) { cur_combo_box_->addItem(col_format_desc(i), QVariant(i)); if (i == saved_combo_idx_) { cur_combo_box_->setCurrentIndex(i); } } connect(cur_combo_box_, SIGNAL(currentIndexChanged(int)), this, SLOT(columnTypeCurrentIndexChanged(int))); editor = cur_combo_box_; break; } case custom_field_col_: { SyntaxLineEdit *syntax_edit = new SyntaxLineEdit(); saved_col_string_ = item->text(custom_field_col_); connect(syntax_edit, SIGNAL(textChanged(QString)), syntax_edit, SLOT(checkFieldName(QString))); connect(syntax_edit, SIGNAL(editingFinished()), this, SLOT(customFieldEditingFinished())); editor = cur_line_edit_ = syntax_edit; saved_combo_idx_ = item->data(type_col_, Qt::UserRole).toInt(); item->setText(type_col_, col_format_desc(COL_CUSTOM)); item->setData(type_col_, Qt::UserRole, QVariant(COL_CUSTOM)); break; } case custom_occurrence_col_: { SyntaxLineEdit *syntax_edit = new SyntaxLineEdit(); saved_col_string_ = item->text(custom_occurrence_col_); connect(syntax_edit, SIGNAL(textChanged(QString)), this, SLOT(customOccurrenceTextChanged(QString))); connect(syntax_edit, SIGNAL(editingFinished()), this, SLOT(customOccurrenceEditingFinished())); editor = cur_line_edit_ = syntax_edit; saved_combo_idx_ = item->data(type_col_, Qt::UserRole).toInt(); item->setText(type_col_, col_format_desc(COL_CUSTOM)); item->setData(type_col_, Qt::UserRole, QVariant(COL_CUSTOM)); break; } default: return; } if (cur_line_edit_) { cur_line_edit_->setText(saved_col_string_); cur_line_edit_->selectAll(); connect(cur_line_edit_, SIGNAL(destroyed()), this, SLOT(lineEditDestroyed())); } if (cur_combo_box_) { connect(cur_combo_box_, SIGNAL(destroyed()), this, SLOT(comboDestroyed())); } if (editor) { QFrame *edit_frame = new QFrame(); QHBoxLayout *hb = new QHBoxLayout(); QSpacerItem *spacer = new QSpacerItem(5, 10); hb->addWidget(editor, 0); hb->addSpacerItem(spacer); hb->setStretch(1, 1); hb->setContentsMargins(0, 0, 0, 0); edit_frame->setLineWidth(0); edit_frame->setFrameStyle(QFrame::NoFrame); // The documentation suggests setting autoFillbackground. That looks silly // so we clear the item text instead. item->setText(cur_column_, ""); edit_frame->setLayout(hb); ui->columnTreeWidget->setItemWidget(item, cur_column_, edit_frame); editor->setFocus(); } }
/* * Create and display the column selection widgets. * Called as part of the creation of the Preferences notebook ( Edit ! Preferences ) */ GtkWidget * column_prefs_show(GtkWidget *prefs_window) { GtkWidget *main_vb, *bottom_hb, *column_l, *add_bt, *tb, *lb; GtkWidget *list_vb, *list_lb, *list_sc; GtkWidget *add_remove_vb; GtkWidget *props_fr, *props_hb; GList *clp; fmt_data *cfmt; gint i; gchar *fmt; gint cur_fmt; const gchar *column_titles[] = {"Title", "Field type"}; GtkListStore *store; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkTreeSelection *sel; GtkTreeIter iter; GtkTreeIter first_iter; gint first_row = TRUE; GtkTooltips *tooltips = gtk_tooltips_new(); /* Container for each row of widgets */ main_vb = gtk_vbox_new(FALSE, 5); gtk_container_set_border_width(GTK_CONTAINER(main_vb), 5); gtk_widget_show(main_vb); list_vb = gtk_vbox_new (FALSE, 0); gtk_container_set_border_width (GTK_CONTAINER (list_vb), 5); gtk_widget_show (list_vb); gtk_box_pack_start (GTK_BOX (main_vb), list_vb, TRUE, TRUE, 0); list_lb = gtk_label_new (("[The first list entry will be displayed as the leftmost column]")); gtk_widget_show (list_lb); gtk_box_pack_start (GTK_BOX (list_vb), list_lb, FALSE, FALSE, 0); list_sc = scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_sc), GTK_SHADOW_IN); gtk_container_add(GTK_CONTAINER(list_vb), list_sc); gtk_widget_show(list_sc); store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); column_row_deleted_handler_id = g_signal_connect(GTK_TREE_MODEL(store), "row-deleted", G_CALLBACK(column_dnd_row_deleted_cb), NULL); column_l = tree_view_new(GTK_TREE_MODEL(store)); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(column_l), TRUE); gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(column_l), FALSE); gtk_tree_view_set_reorderable(GTK_TREE_VIEW(column_l), TRUE); gtk_tooltips_set_tip (tooltips, column_l, "Click on a title to change its name.\nDrag an item to change its order.", NULL); renderer = gtk_cell_renderer_text_new(); g_object_set(G_OBJECT(renderer), "editable", TRUE, NULL); g_signal_connect (renderer, "edited", G_CALLBACK(column_title_changed_cb), GTK_TREE_MODEL(store)); column = gtk_tree_view_column_new_with_attributes(column_titles[0], renderer, "text", 0, NULL); gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_append_column(GTK_TREE_VIEW(column_l), column); renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes(column_titles[1], renderer, "text", 1, NULL); gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); gtk_tree_view_append_column(GTK_TREE_VIEW(column_l), column); /* XXX - make this match the packet list prefs? */ sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(column_l)); gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE); g_signal_connect(sel, "changed", G_CALLBACK(column_list_select_cb), NULL); gtk_container_add(GTK_CONTAINER(list_sc), column_l); gtk_widget_show(column_l); clp = g_list_first(prefs.col_list); while (clp) { cfmt = (fmt_data *) clp->data; cur_fmt = get_column_format_from_str(cfmt->fmt); if (cur_fmt == COL_CUSTOM) { fmt = g_strdup_printf("%s (%s)", col_format_desc(cur_fmt), cfmt->custom_field); } else { if (cfmt->custom_field) { /* Delete custom_field from previous changes */ g_free (cfmt->custom_field); cfmt->custom_field = NULL; } fmt = g_strdup_printf("%s", col_format_desc(cur_fmt)); } gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, cfmt->title, 1, fmt, 2, clp, -1); if (first_row) { first_iter = iter; first_row = FALSE; } clp = clp->next; g_free (fmt); } g_object_unref(G_OBJECT(store)); /* Bottom row: Add/remove buttons and properties */ bottom_hb = gtk_hbox_new(FALSE, 5); gtk_box_pack_start (GTK_BOX (main_vb), bottom_hb, FALSE, TRUE, 0); gtk_widget_show(bottom_hb); /* Add / remove buttons */ add_remove_vb = gtk_vbox_new (TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (add_remove_vb), 5); gtk_box_pack_start (GTK_BOX (bottom_hb), add_remove_vb, FALSE, FALSE, 0); gtk_widget_show(add_remove_vb); add_bt = gtk_button_new_from_stock(GTK_STOCK_ADD); g_signal_connect(add_bt, "clicked", G_CALLBACK(column_list_new_cb), column_l); gtk_box_pack_start (GTK_BOX (add_remove_vb), add_bt, FALSE, FALSE, 0); gtk_tooltips_set_tip (tooltips, add_bt, "Add a new column at the end of the list.", NULL); gtk_widget_show(add_bt); remove_bt = gtk_button_new_from_stock(GTK_STOCK_REMOVE); gtk_widget_set_sensitive(remove_bt, FALSE); g_signal_connect(remove_bt, "clicked", G_CALLBACK(column_list_delete_cb), column_l); gtk_box_pack_start (GTK_BOX (add_remove_vb), remove_bt, FALSE, FALSE, 0); gtk_tooltips_set_tip (tooltips, remove_bt, "Remove the selected column.", NULL); gtk_widget_show(remove_bt); /* properties frame */ props_fr = gtk_frame_new("Properties"); gtk_box_pack_start (GTK_BOX (bottom_hb), props_fr, TRUE, TRUE, 0); gtk_widget_show(props_fr); /* Column name entry and format selection */ tb = gtk_table_new(2, 2, FALSE); gtk_container_set_border_width(GTK_CONTAINER(tb), 5); gtk_container_add(GTK_CONTAINER(props_fr), tb); gtk_table_set_row_spacings(GTK_TABLE(tb), 10); gtk_table_set_col_spacings(GTK_TABLE(tb), 15); gtk_widget_show(tb); lb = gtk_label_new("Field type:"); gtk_misc_set_alignment(GTK_MISC(lb), 1.0f, 0.5f); gtk_table_attach_defaults(GTK_TABLE(tb), lb, 0, 1, 0, 1); gtk_tooltips_set_tip (tooltips, lb, "Select which packet information to present in the column.", NULL); gtk_widget_show(lb); props_hb = gtk_hbox_new(FALSE, 5); gtk_table_attach(GTK_TABLE(tb), props_hb, 1, 2, 0, 1, GTK_FILL, GTK_SHRINK, 0, 0); gtk_tooltips_set_tip (tooltips, props_hb, "Select which packet information to present in the column.", NULL); gtk_widget_show(props_hb); field_lb = gtk_label_new("Field name:"); gtk_misc_set_alignment(GTK_MISC(field_lb), 1.0f, 0.5f); gtk_table_attach_defaults(GTK_TABLE(tb), field_lb, 0, 1, 1, 2); gtk_widget_set_sensitive(field_lb, FALSE); gtk_tooltips_set_tip (tooltips, field_lb, "Field name used when field type is \"Custom\". " "This string has the same syntax as a display filter string.", NULL); gtk_widget_show(field_lb); field_te = gtk_entry_new(); g_object_set_data (G_OBJECT(field_te), E_FILT_FIELD_NAME_ONLY_KEY, ""); g_signal_connect(field_te, "changed", G_CALLBACK(filter_te_syntax_check_cb), NULL); /* XXX: column_field_changed_cb will be called for every character entered in the entry box. */ /* Consider Changing logic so that the field is "accepted" only when a return is entered ?? */ /* Also: entry shouldn't be accepted if it's not a valid filter ? */ column_field_changed_handler_id = g_signal_connect(field_te, "changed", G_CALLBACK(column_field_changed_cb), column_l); g_object_set_data(G_OBJECT(main_vb), E_FILT_AUTOCOMP_PTR_KEY, NULL); g_signal_connect(field_te, "key-press-event", G_CALLBACK (filter_string_te_key_pressed_cb), NULL); g_signal_connect(prefs_window, "key-press-event", G_CALLBACK (filter_parent_dlg_key_pressed_cb), NULL); colorize_filter_te_as_empty(field_te); gtk_table_attach_defaults(GTK_TABLE(tb), field_te, 1, 2, 1, 2); gtk_widget_set_sensitive(field_te, FALSE); gtk_tooltips_set_tip (tooltips, field_te, "Field name used when field type is \"Custom\". " "This string has the same syntax as a display filter string.", NULL); gtk_widget_show(field_te); fmt_cmb = gtk_combo_box_new_text(); for (i = 0; i < NUM_COL_FMTS; i++) gtk_combo_box_append_text(GTK_COMBO_BOX(fmt_cmb), col_format_desc(i)); column_menu_changed_handler_id = g_signal_connect(fmt_cmb, "changed", G_CALLBACK(column_menu_changed_cb), column_l); gtk_widget_set_sensitive(fmt_cmb, FALSE); gtk_box_pack_start(GTK_BOX(props_hb), fmt_cmb, FALSE, FALSE, 0); gtk_widget_show(fmt_cmb); /* select the first menu list row. */ /* Triggers call to column_list_select_cb(). */ gtk_tree_selection_select_iter(sel, &first_iter); return(main_vb); }
GtkTreeIter iter; GtkTreePath *path; GtkTreeViewColumn *title_column; cur_fmt = COL_NUMBER; cfmt = (fmt_data *) g_malloc(sizeof(fmt_data)); cfmt->title = g_strdup(title); cfmt->fmt = g_strdup(col_format_to_string(cur_fmt)); cfmt->custom_field = NULL; prefs.col_list = g_list_append(prefs.col_list, cfmt); model = gtk_tree_view_get_model(column_l); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, title, 1, col_format_desc(cur_fmt), 2, g_list_last(prefs.col_list), -1); /* Triggers call to column_list_select_cb() */ gtk_tree_selection_select_iter(gtk_tree_view_get_selection(column_l), &iter); /* Set the cursor to the 'Title' column of the newly added row and enable editing */ /* XXX: If displaying the new title ["New column"] widens the title column of the */ /* treeview, then the set_cursor below doesn't properly generate an entry */ /* box around the title text. The width of the box appears to be the column */ /* width before the treeview title column was widened. Seems like a bug... */ /* I haven't found a work-around. */ path = gtk_tree_model_get_path(model, &iter); title_column = gtk_tree_view_get_column(column_l, 0); gtk_tree_view_set_cursor(column_l, path, title_column, TRUE);