process-tree-view: Reset /columns/positions at startup if invalid

This can happen if from one version to the next the number of columns
has changed, and of course if invalid data is somehow put into the
xfconf property.
This commit is contained in:
Gaël Bonithon
2024-04-09 23:02:10 +02:00
parent aaca7e94a4
commit d21b73e5ff

View File

@@ -320,24 +320,46 @@ columns_changed (XtmProcessTreeView *treeview)
static void static void
read_columns_positions (XtmProcessTreeView *treeview) read_columns_positions (XtmProcessTreeView *treeview)
{ {
gushort i;
gchar *columns_positions; gchar *columns_positions;
gchar **columns_positions_split; gboolean valid_setting;
g_object_get (treeview->settings, "columns-positions", &columns_positions, NULL); g_object_get (treeview->settings, "columns-positions", &columns_positions, NULL);
valid_setting = columns_positions != NULL;
if (columns_positions == NULL) if (valid_setting)
{ {
for (i = 0; i < N_COLUMNS; i++) gchar **columns_positions_split = g_strsplit (columns_positions, ";", -1);
treeview->columns_positions[i] = i; valid_setting = g_strv_length (columns_positions_split) == N_COLUMNS + 1;
} if (valid_setting)
else {
{ for (gint i = 0; i < N_COLUMNS; i++)
columns_positions_split = g_strsplit (columns_positions, ";", N_COLUMNS + 1); {
for (i = 0; i < N_COLUMNS && columns_positions_split[i] != NULL; i++) gchar *end;
treeview->columns_positions[i] = (gushort)g_ascii_strtoll (columns_positions_split[i], NULL, 10); gushort position = g_ascii_strtoull (columns_positions_split[i], &end, 10);
if (*end != '\0' || position >= N_COLUMNS)
{
valid_setting = FALSE;
break;
}
treeview->columns_positions[i] = position;
}
}
g_strfreev (columns_positions_split); g_strfreev (columns_positions_split);
g_free (columns_positions); g_free (columns_positions);
if (!valid_setting)
{
XfconfChannel *channel = xfconf_channel_get (CHANNEL);
g_warning ("Invalid list of column positions, reset Xfconf property /columns/positions");
xfconf_channel_reset_property (channel, "/columns/positions", TRUE);
}
}
if (!valid_setting)
{
for (gint i = 0; i < N_COLUMNS; i++)
treeview->columns_positions[i] = i;
} }
} }