recent: Don't use format info at all

We don't need to read or use the column format string in
the recent settings column width info, because now they're
in sync with the indices used in prefs.col_list.

Continue to write it when writing out the recent settings for
backwards compatibility with older version.

We can also remove the workaround for #14177 from
commit c62dadd31f as it's
not needed.

This solves the width and alignment part of #15529. Hidden
states are still to do.
This commit is contained in:
John Thacker 2024-02-09 06:49:20 -05:00
parent 07b8a53361
commit f2fae54a58
3 changed files with 15 additions and 162 deletions

View File

@ -146,12 +146,8 @@ void ColumnEditorFrame::on_buttonBox_accepted()
set_column_title(cur_column_, col_str.constData());
set_column_format(cur_column_, ui->typeComboBox->currentIndex());
if (ui->typeComboBox->currentIndex() == COL_CUSTOM) {
gint width = recent_get_column_width(cur_column_);
gchar xalign = recent_get_column_xalign(cur_column_);
col_str = ui->fieldsNameLineEdit->text().toUtf8();
set_column_custom_fields(cur_column_, col_str.constData());
recent_set_column_width(cur_column_, width);
recent_set_column_xalign(cur_column_, xalign);
if (!ui->occurrenceLineEdit->text().isEmpty()) {
set_column_custom_occurrence(cur_column_, ui->occurrenceLineEdit->text().toInt());
}

View File

@ -211,7 +211,6 @@ static void
free_col_width_data(gpointer data)
{
col_width_data *cfmt = (col_width_data *)data;
g_free(cfmt->cfield);
g_free(cfmt);
}
@ -1311,8 +1310,6 @@ read_set_recent_pair_static(gchar *key, const gchar *value,
char *p;
GList *col_l, *col_l_elt;
col_width_data *cfmt;
const gchar *cust_format = col_format_to_string(COL_CUSTOM);
int cust_format_len = (int) strlen(cust_format);
if (strcmp(key, RECENT_KEY_MAIN_TOOLBAR_SHOW) == 0) {
parse_recent_boolean(value, &recent.main_toolbar_show);
@ -1439,63 +1436,18 @@ read_set_recent_pair_static(gchar *key, const gchar *value,
prefs_clear_string_list(col_l);
return PREFS_SET_SYNTAX_ERR;
}
/* Check to make sure all column formats are valid. */
col_l_elt = g_list_first(col_l);
while (col_l_elt) {
fmt_data cfmt_check;
/* Make sure the format isn't empty. */
if (strcmp((const char *)col_l_elt->data, "") == 0) {
/* It is. */
prefs_clear_string_list(col_l);
return PREFS_SET_SYNTAX_ERR;
}
/* Some predefined columns have been migrated to use custom
* columns. We'll convert these silently here */
try_convert_to_custom_column((char **)&col_l_elt->data);
/* Check the format. */
if (!parse_column_format(&cfmt_check, (char *)col_l_elt->data)) {
/* It's not a valid column format. */
prefs_clear_string_list(col_l);
return PREFS_SET_SYNTAX_ERR;
}
if (cfmt_check.fmt == COL_CUSTOM) {
/* We don't need the custom column field on this pass. */
g_free(cfmt_check.custom_fields);
}
/* Go past the format. */
col_l_elt = col_l_elt->next;
/* Go past the width. */
col_l_elt = col_l_elt->next;
}
recent_free_column_width_info(&recent);
recent.col_width_list = NULL;
col_l_elt = g_list_first(col_l);
while (col_l_elt) {
gchar *fmt = g_strdup((const gchar *)col_l_elt->data);
cfmt = g_new(col_width_data, 1);
if (strncmp(fmt, cust_format, cust_format_len) != 0) {
cfmt->cfmt = get_column_format_from_str(fmt);
cfmt->cfield = NULL;
} else {
cfmt->cfmt = COL_CUSTOM;
cfmt->cfield = g_strdup(&fmt[cust_format_len+1]); /* add 1 for ':' */
}
g_free (fmt);
if (cfmt->cfmt == -1) {
g_free(cfmt->cfield);
g_free(cfmt);
return PREFS_SET_SYNTAX_ERR; /* string was bad */
}
/* Skip the column format, we don't use it anymore because the
* column indices are in sync and the key since 4.4. Format is
* still written for backwards compatibility.
*/
col_l_elt = col_l_elt->next;
cfmt->width = (gint)strtol((const char *)col_l_elt->data, &p, 0);
if (p == col_l_elt->data || (*p != '\0' && *p != ':')) {
g_free(cfmt->cfield);
g_free(cfmt);
return PREFS_SET_SYNTAX_ERR; /* number was bad */
}
@ -1804,17 +1756,8 @@ 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);
@ -1840,27 +1783,11 @@ recent_remove_column(int col)
gint
recent_get_column_width(gint col)
{
GList *col_l;
col_width_data *col_w;
gint cfmt;
const gchar *cfield = NULL;
cfmt = get_column_format(col);
if (cfmt == COL_CUSTOM) {
cfield = get_column_custom_fields(col);
}
col_l = g_list_first(recent.col_width_list);
while (col_l) {
col_w = (col_width_data *) col_l->data;
if (col_w->cfmt == cfmt) {
if (cfmt != COL_CUSTOM) {
return col_w->width;
} else if (cfield && strcmp (cfield, col_w->cfield) == 0) {
return col_w->width;
}
}
col_l = col_l->next;
col_w = g_list_nth_data(recent.col_width_list, col);
if (col_w) {
return col_w->width;
}
return -1;
@ -1869,103 +1796,35 @@ recent_get_column_width(gint col)
void
recent_set_column_width(gint col, gint width)
{
GList *col_l;
col_width_data *col_w;
gint cfmt;
const gchar *cfield = NULL;
gboolean found = FALSE;
cfmt = get_column_format(col);
if (cfmt == COL_CUSTOM) {
cfield = get_column_custom_fields(col);
}
col_l = g_list_first(recent.col_width_list);
while (col_l) {
col_w = (col_width_data *) col_l->data;
if (col_w->cfmt == cfmt) {
if (cfmt != COL_CUSTOM || strcmp (cfield, col_w->cfield) == 0) {
col_w->width = width;
found = TRUE;
break;
}
}
col_l = col_l->next;
}
if (!found) {
col_w = g_new(col_width_data, 1);
col_w->cfmt = cfmt;
col_w->cfield = g_strdup(cfield);
col_w = g_list_nth_data(recent.col_width_list, col);
if (col_w) {
col_w->width = width;
col_w->xalign = COLUMN_XALIGN_DEFAULT;
recent.col_width_list = g_list_append(recent.col_width_list, col_w);
}
}
gchar
recent_get_column_xalign(gint col)
{
GList *col_l;
col_width_data *col_w;
gint cfmt;
const gchar *cfield = NULL;
cfmt = get_column_format(col);
if (cfmt == COL_CUSTOM) {
cfield = get_column_custom_fields(col);
col_w = g_list_nth_data(recent.col_width_list, col);
if (col_w) {
return col_w->xalign;
}
col_l = g_list_first(recent.col_width_list);
while (col_l) {
col_w = (col_width_data *) col_l->data;
if (col_w->cfmt == cfmt) {
if (cfmt != COL_CUSTOM) {
return col_w->xalign;
} else if (cfield && strcmp (cfield, col_w->cfield) == 0) {
return col_w->xalign;
}
}
col_l = col_l->next;
}
return 0;
return COLUMN_XALIGN_DEFAULT;
}
void
recent_set_column_xalign(gint col, gchar xalign)
{
GList *col_l;
col_width_data *col_w;
gint cfmt;
const gchar *cfield = NULL;
gboolean found = FALSE;
cfmt = get_column_format(col);
if (cfmt == COL_CUSTOM) {
cfield = get_column_custom_fields(col);
}
col_l = g_list_first(recent.col_width_list);
while (col_l) {
col_w = (col_width_data *) col_l->data;
if (col_w->cfmt == cfmt) {
if (cfmt != COL_CUSTOM || strcmp (cfield, col_w->cfield) == 0) {
col_w->xalign = xalign;
found = TRUE;
break;
}
}
col_l = col_l->next;
}
if (!found) {
col_w = g_new(col_width_data, 1);
col_w->cfmt = cfmt;
col_w->cfield = g_strdup(cfield);
col_w->width = 40;
col_w = g_list_nth_data(recent.col_width_list, col);
if (col_w) {
col_w->xalign = xalign;
recent.col_width_list = g_list_append(recent.col_width_list, col_w);
}
}

View File

@ -41,8 +41,6 @@ extern "C" {
#define RECENT_KEY_REMOTE_HOST "recent.remote_host"
typedef struct _col_width_data {
gint cfmt;
gchar *cfield;
gint width;
gchar xalign;
} col_width_data;