diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2020-07-14 19:04:00 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2020-07-15 03:57:01 +0000 |
commit | 3ff0a55d5c77702e946195efb5ea5253f6482032 (patch) | |
tree | 9e619892f4ea76f43706699448c62857670eb582 /ui | |
parent | 6037b401069186dbc47e9b87da633537f6d981f2 (diff) |
Qt: Check if "Apply as Column" column already exists
Use the existing (possible hidden) column when doing "Apply as Column"
on a field which is already used as a custom column. This will help
prevent having multiple equal custom columns, where all will be hidden
at startup and profile change when only one of them are configured as
hidden.
Multiple equal columns can always be manually configured using
"Preferences -> Appearance -> Columns" if this is intended.
Change-Id: Ib03893facfa3f194f3b3303645fb3f9313ec9e91
Reviewed-on: https://code.wireshark.org/review/37861
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui')
-rw-r--r-- | ui/preference_utils.c | 22 | ||||
-rw-r--r-- | ui/preference_utils.h | 8 | ||||
-rw-r--r-- | ui/qt/main_window_slots.cpp | 21 |
3 files changed, 49 insertions, 2 deletions
diff --git a/ui/preference_utils.c b/ui/preference_utils.c index 404c13c997..ef6ca14778 100644 --- a/ui/preference_utils.c +++ b/ui/preference_utils.c @@ -200,6 +200,28 @@ column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_fields return colnr; } +gint +column_prefs_has_custom(const gchar *custom_field) +{ + GList *clp; + fmt_data *cfmt; + gint colnr = -1; + + for (gint i = 0; i < prefs.num_cols; i++) { + clp = g_list_nth(prefs.col_list, i); + if (clp == NULL) /* Sanity check, invalid column requested */ + continue; + + cfmt = (fmt_data *) clp->data; + if (cfmt->fmt == COL_CUSTOM && strcmp(custom_field, cfmt->custom_fields) == 0) { + colnr = i; + break; + } + } + + return colnr; +} + void column_prefs_remove_link(GList *col_link) { diff --git a/ui/preference_utils.h b/ui/preference_utils.h index 0b9eb656b8..04e3bc7d85 100644 --- a/ui/preference_utils.h +++ b/ui/preference_utils.h @@ -71,6 +71,14 @@ gint column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_field, gint position); +/** Check if a custom column exists. + * + * @param custom_field column custom field + * + * @return The index of the column if existing, -1 if not existing + */ +gint column_prefs_has_custom(const gchar *custom_field); + /** Remove a column. * * @param col_link Column list entry diff --git a/ui/qt/main_window_slots.cpp b/ui/qt/main_window_slots.cpp index 20d8db22e0..26e0353ae2 100644 --- a/ui/qt/main_window_slots.cpp +++ b/ui/qt/main_window_slots.cpp @@ -2765,8 +2765,25 @@ void MainWindow::on_actionAnalyzeDisplayFilterMacros_triggered() void MainWindow::on_actionAnalyzeCreateAColumn_triggered() { if (capture_file_.capFile() != 0 && capture_file_.capFile()->finfo_selected != 0) { - insertColumn(QString(capture_file_.capFile()->finfo_selected->hfinfo->name), - QString(capture_file_.capFile()->finfo_selected->hfinfo->abbrev)); + header_field_info *hfinfo = capture_file_.capFile()->finfo_selected->hfinfo; + int col = column_prefs_has_custom(hfinfo->abbrev); + if (col == -1) { + insertColumn(hfinfo->name, hfinfo->abbrev); + } else { + QString status; + if (QString(hfinfo->name) == get_column_title(col)) { + status = tr("The \"%1\" column already exists.").arg(hfinfo->name); + } else { + status = tr("The \"%1\" column already exists as \"%2\".").arg(hfinfo->name).arg(get_column_title(col)); + } + wsApp->pushStatus(WiresharkApplication::TemporaryStatus, status); + + if (!get_column_visible(col)) { + packet_list_->setColumnHidden(col, false); + set_column_visible(col, TRUE); + prefs_main_write(); + } + } } } |