diff --git a/ui/preference_utils.c b/ui/preference_utils.c index e8c1c16727..6ecada4fc2 100644 --- a/ui/preference_utils.c +++ b/ui/preference_utils.c @@ -187,7 +187,8 @@ column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_fields last_cfmt = (fmt_data *) clp->data; if (position > 0 && position <= colnr) { /* Custom fields may be added at any position, depending on the given argument */ - prefs.col_list = g_list_insert(prefs.col_list, cfmt, position); + colnr = position; + prefs.col_list = g_list_insert(prefs.col_list, cfmt, colnr); } else if (last_cfmt->fmt == COL_INFO) { /* Last column is COL_INFO, add custom column before this */ colnr -= 1; @@ -199,6 +200,7 @@ column_prefs_add_custom(gint fmt, const gchar *title, const gchar *custom_fields 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); } + recent_insert_column(colnr); return colnr; } @@ -274,6 +276,7 @@ void column_prefs_remove_nth(gint col) { column_prefs_remove_link(g_list_nth(prefs.col_list, col)); + recent_remove_column(col); } void save_migrated_uat(const char *uat_name, gboolean *old_pref) diff --git a/ui/qt/models/column_list_model.cpp b/ui/qt/models/column_list_model.cpp index 56e7d0fca7..681a60c0e7 100644 --- a/ui/qt/models/column_list_model.cpp +++ b/ui/qt/models/column_list_model.cpp @@ -563,10 +563,12 @@ void ColumnListModel::saveColumns() prefs.col_list = new_col_list; + recent_free_column_width_info(&recent); for (int row = 0; row < store_.count(); row++) { ListElement elem = store_.at(row); + recent_insert_column(row); recent_set_column_width(row, elem.width); recent_set_column_xalign(row, elem.xalign); } diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index d5c9d3e20a..6193cb8a2c 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -1823,6 +1823,7 @@ void PacketList::sectionResized(int col, int, int new_width) void PacketList::sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex) { GList *new_col_list = NULL; + GList *new_recent_col_list = NULL; QList saved_sizes; int sort_idx; @@ -1847,9 +1848,14 @@ void PacketList::sectionMoved(int logicalIndex, int oldVisualIndex, int newVisua saved_sizes << header()->sectionSize(log_idx); void *pref_data = g_list_nth_data(prefs.col_list, log_idx); - if (!pref_data) continue; + if (pref_data) { + new_col_list = g_list_append(new_col_list, pref_data); + } - new_col_list = g_list_append(new_col_list, pref_data); + pref_data = g_list_nth_data(recent.col_width_list, log_idx); + if (pref_data) { + new_recent_col_list = g_list_append(new_recent_col_list, pref_data); + } } // Undo move to ensure that the logical indices map to the visual indices, @@ -1867,6 +1873,8 @@ void PacketList::sectionMoved(int logicalIndex, int oldVisualIndex, int newVisua g_list_free(prefs.col_list); prefs.col_list = new_col_list; + g_list_free(recent.col_width_list); + recent.col_width_list = new_recent_col_list; thaw(true); diff --git a/ui/recent.c b/ui/recent.c index 7fa6597791..dd6161dfb2 100644 --- a/ui/recent.c +++ b/ui/recent.c @@ -208,18 +208,17 @@ static const value_string show_bytes_decode_values[] = { }; static void -free_col_width_data(gpointer data, gpointer user_data _U_) +free_col_width_data(gpointer data) { col_width_data *cfmt = (col_width_data *)data; g_free(cfmt->cfield); g_free(cfmt); } -static void -free_col_width_info(recent_settings_t *rs) +void +recent_free_column_width_info(recent_settings_t *rs) { - g_list_foreach(rs->col_width_list, free_col_width_data, NULL); - g_list_free(rs->col_width_list); + g_list_free_full(rs->col_width_list, free_col_width_data); rs->col_width_list = NULL; } @@ -1473,7 +1472,7 @@ read_set_recent_pair_static(gchar *key, const gchar *value, /* Go past the width. */ col_l_elt = col_l_elt->next; } - free_col_width_info(&recent); + recent_free_column_width_info(&recent); recent.col_width_list = NULL; col_l_elt = g_list_first(col_l); while (col_l_elt) { @@ -1696,7 +1695,7 @@ recent_read_profile_static(char **rf_path_return, int *rf_errno_return) } if (recent.col_width_list) { - free_col_width_info(&recent); + recent_free_column_width_info(&recent); } if (recent.gui_fileopen_remembered_dir) { @@ -1801,6 +1800,43 @@ recent_read_dynamic(char **rf_path_return, int *rf_errno_return) return TRUE; } +void +recent_insert_column(int col) +{ + col_width_data *col_w; + int cfmt; + const char *cfield = NULL; + + cfmt = get_column_format(col); + if (cfmt == COL_CUSTOM) { + cfield = get_column_custom_fields(col); + } + + col_w = g_new(col_width_data, 1); + col_w->cfmt = cfmt; + col_w->cfield = g_strdup(cfield); + col_w->width = -1; + col_w->xalign = COLUMN_XALIGN_DEFAULT; + recent.col_width_list = g_list_insert(recent.col_width_list, col_w, col); +} + +void +recent_remove_column(int col) +{ + GList *col_l = g_list_nth(recent.col_width_list, col); + col_width_data *col_w; + + if (!col_l) return; + + col_w = (col_width_data*)col_l->data; + + if (col_w) { + free_col_width_data(col_w); + } + + recent.col_width_list = g_list_delete_link(recent.col_width_list, col_l); +} + gint recent_get_column_width(gint col) { @@ -1942,7 +1978,7 @@ recent_init(void) void recent_cleanup(void) { - free_col_width_info(&recent); + recent_free_column_width_info(&recent); g_free(recent.gui_geometry_main); g_free(recent.gui_geometry_main_master_split); g_free(recent.gui_geometry_main_extra_split); diff --git a/ui/recent.h b/ui/recent.h index 0ab08b2a60..14c0dcd3f9 100644 --- a/ui/recent.h +++ b/ui/recent.h @@ -232,6 +232,28 @@ extern gboolean recent_read_dynamic(char **rf_path_return, int *rf_errno_return) */ extern int recent_set_arg(char *prefarg); +/** Free the recent settings list of column width information + * + * @param rs the recent settings (currently a global) + */ +extern void recent_free_column_width_info(recent_settings_t *rs); + +/** Insert an entry in the recent column width setting for + * the given column, which should have been just added to + * the column list preference. (This keeps them in sync.) + * + * @param col column number + */ +extern void recent_insert_column(int col); + +/** Remove an entry in the recent column width setting for + * the given column, which should have been just removed to + * the column list preference. (This keeps them in sync.) + * + * @param col column number + */ +extern void recent_remove_column(int col); + /** Get the column width for the given column * * @param col column number