From 57716e13659a8c9c26124e249a86fce9577d609f Mon Sep 17 00:00:00 2001 From: Roland Knall Date: Mon, 9 Mar 2015 08:11:13 +0100 Subject: Qt: Implement "Apply as Column" for packet context Implement the same functionality for "Apply as Column" as it exists in the GTK version of Wireshark. Especially for the context menu in the packet view panel. Change-Id: Id25b7797616ff3b3acf7aa920395516c8a4e9bf9 Reviewed-on: https://code.wireshark.org/review/7604 Reviewed-by: Roland Knall Petri-Dish: Alexis La Goutte Petri-Dish: Pascal Quantin Tested-by: Petri Dish Buildbot Reviewed-by: Michal Labedzki Tested-by: Michal Labedzki --- ui/preference_utils.c | 10 ++++++++-- ui/preference_utils.h | 4 +++- ui/qt/main_window.h | 1 + ui/qt/main_window.ui | 5 +---- ui/qt/main_window_slots.cpp | 23 ++++++++++++++++++++--- ui/qt/proto_tree.cpp | 7 ++++++- 6 files changed, 39 insertions(+), 11 deletions(-) (limited to 'ui') diff --git a/ui/preference_utils.c b/ui/preference_utils.c index 1bed39bd2f..1e358bd7d0 100644 --- a/ui/preference_utils.c +++ b/ui/preference_utils.c @@ -273,11 +273,12 @@ prefs_main_write(void) } } -void +gint column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_field, gint custom_occurrence) { GList *clp; fmt_data *cfmt, *last_cfmt; + gint colnr; cfmt = (fmt_data *) g_malloc(sizeof(fmt_data)); /* @@ -291,13 +292,16 @@ column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_field, cfmt->custom_occurrence = custom_occurrence; cfmt->resolved = TRUE; + colnr = g_list_length(prefs.col_list); + if (custom_field) { cfmt->visible = TRUE; clp = g_list_last(prefs.col_list); last_cfmt = (fmt_data *) clp->data; if (last_cfmt->fmt == COL_INFO) { /* Last column is COL_INFO, add custom column before this */ - prefs.col_list = g_list_insert(prefs.col_list, cfmt, g_list_length(prefs.col_list)-1); + colnr -= 1; + prefs.col_list = g_list_insert(prefs.col_list, cfmt, colnr); } else { prefs.col_list = g_list_append(prefs.col_list, cfmt); } @@ -305,6 +309,8 @@ column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_field, cfmt->visible = FALSE; /* Will be set to TRUE in visible_toggled() when added to list */ prefs.col_list = g_list_append(prefs.col_list, cfmt); } + + return colnr; } void diff --git a/ui/preference_utils.h b/ui/preference_utils.h index e4117d682e..882555d70a 100644 --- a/ui/preference_utils.h +++ b/ui/preference_utils.h @@ -86,8 +86,10 @@ extern void prefs_main_write(void); * @param title column title * @param custom_field column custom field * @param custom_occurrence custom occurrence + * + * @return The index of the inserted column */ -void column_prefs_add_custom(gint fmt, const gchar *title, +gint column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_field, gint custom_occurrence); diff --git a/ui/qt/main_window.h b/ui/qt/main_window.h index e4becaf39e..1d379079ce 100644 --- a/ui/qt/main_window.h +++ b/ui/qt/main_window.h @@ -356,6 +356,7 @@ private slots: #endif void matchFieldFilter(FilterAction::Action action, FilterAction::ActionType filter_type); + void on_actionAnalyzeCreateAColumn_triggered(); void on_actionAnalyzeAAFSelected_triggered(); void on_actionAnalyzeAAFNotSelected_triggered(); void on_actionAnalyzeAAFAndSelected_triggered(); diff --git a/ui/qt/main_window.ui b/ui/qt/main_window.ui index d62d46c1aa..d05587f108 100644 --- a/ui/qt/main_window.ui +++ b/ui/qt/main_window.ui @@ -1206,11 +1206,8 @@ - - false - - Create a Column + Apply as Column Create a packet list column from the selected field. diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 41b8371d1d..354f0b8dce 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -1233,8 +1233,8 @@ void MainWindow::setMenusForSelectedTreeRow(field_info *fi) { // set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/EditMenu/Copy/AsFilter", // proto_can_match_selected(cf->finfo_selected, cf->edt)); -// set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/CreateAColumn", -// hfinfo->type != FT_NONE); + main_ui_->actionAnalyzeCreateAColumn->setEnabled(can_match_selected); + main_ui_->actionAnalyzeAAFSelected->setEnabled(can_match_selected); main_ui_->actionAnalyzeAAFNotSelected->setEnabled(can_match_selected); main_ui_->actionAnalyzeAAFAndSelected->setEnabled(can_match_selected); @@ -1287,7 +1287,8 @@ void MainWindow::setMenusForSelectedTreeRow(field_info *fi) { main_ui_->actionEditCopyFieldName->setEnabled(false); main_ui_->actionEditCopyValue->setEnabled(false); main_ui_->actionEditCopyAsFilter->setEnabled(false); -// set_menu_sensitivity(ui_manager_main_menubar, "/Menubar/AnalyzeMenu/CreateAColumn", FALSE); + + main_ui_->actionAnalyzeCreateAColumn->setEnabled(false); main_ui_->actionAnalyzeAAFSelected->setEnabled(false); main_ui_->actionAnalyzeAAFNotSelected->setEnabled(false); @@ -2192,6 +2193,22 @@ void MainWindow::matchFieldFilter(FilterAction::Action action, FilterAction::Act filterAction(field_filter, action, filter_type); } +void MainWindow::on_actionAnalyzeCreateAColumn_triggered() +{ + gint colnr = 0; + + if ( capture_file_.capFile() != 0 && capture_file_.capFile()->finfo_selected != 0 ) + { + colnr = column_prefs_add_custom(COL_CUSTOM, capture_file_.capFile()->finfo_selected->hfinfo->name, + capture_file_.capFile()->finfo_selected->hfinfo->abbrev,0); + + packet_list_->redrawVisiblePackets(); + packet_list_->resizeColumnToContents(colnr); + + prefs_main_write(); + } +} + // XXX We could probably create the analyze and prepare actions // dynamically using FilterActions and consolidate the methods // below into one callback. diff --git a/ui/qt/proto_tree.cpp b/ui/qt/proto_tree.cpp index c12b2dc48d..ac2dac3a52 100644 --- a/ui/qt/proto_tree.cpp +++ b/ui/qt/proto_tree.cpp @@ -167,8 +167,13 @@ ProtoTree::ProtoTree(QWidget *parent) : ctx_menu_.addAction(window()->findChild("actionViewExpandAll")); ctx_menu_.addAction(window()->findChild("actionViewCollapseAll")); ctx_menu_.addSeparator(); -// " \n" + + action = window()->findChild("actionAnalyzeCreateAColumn"); + ctx_menu_.addAction(action); + ctx_menu_.addSeparator(); + action = window()->findChild("actionApply_as_Filter"); + submenu = new QMenu(); action->setMenu(submenu); ctx_menu_.addAction(action); -- cgit v1.2.3