diff options
-rw-r--r-- | e-util/e-table-config.c | 157 | ||||
-rw-r--r-- | e-util/e-table-state.c | 59 | ||||
-rw-r--r-- | e-util/e-table-state.h | 3 | ||||
-rw-r--r-- | e-util/e-table-utils.c | 19 | ||||
-rw-r--r-- | e-util/e-table.c | 24 | ||||
-rw-r--r-- | e-util/e-tree.c | 24 |
6 files changed, 170 insertions, 116 deletions
diff --git a/e-util/e-table-config.c b/e-util/e-table-config.c index 187dd601be..cf0c4e6511 100644 --- a/e-util/e-table-config.c +++ b/e-util/e-table-config.c @@ -487,11 +487,18 @@ setup_fields (ETableConfig *config) if (config->temp_state) { for (i = 0; i < config->temp_state->col_count; i++) { - gint j, idx; - for (j = 0, idx = 0; j < config->temp_state->columns[i]; j++) { + ETableColumnSpecification *target_column; + gint idx = 0; + guint jj; + + target_column = config->temp_state->column_specs[i]; + + for (jj = 0; jj < array->len; jj++) { ETableColumnSpecification *column; - column = g_ptr_array_index (array, j); + column = g_ptr_array_index (array, jj); + if (column == target_column) + break; if (!column->disabled) idx++; @@ -512,36 +519,24 @@ static void config_fields_info_update (ETableConfig *config) { GString *res = g_string_new (""); - GPtrArray *array; - gint i, j; - - array = e_table_specification_ref_columns (config->source_spec); - - for (i = 0; i < config->state->col_count; i++) { - for (j = 0; j < array->len; j++) { - ETableColumnSpecification *column; - const gchar *title; - - column = g_ptr_array_index (array, j); + gint ii; - if (column->disabled) - continue; + for (ii = 0; ii < config->state->col_count; ii++) { + ETableColumnSpecification *column; + const gchar *title; - if (config->state->columns[i] != j) - continue; + column = config->state->column_specs[ii]; - title = dgettext (config->domain, column->title); - g_string_append (res, title); + if (column->disabled) + continue; - if (i + 1 < config->state->col_count) - g_string_append (res, ", "); + title = dgettext (config->domain, column->title); + g_string_append (res, title); - break; - } + if (ii + 1 < config->state->col_count) + g_string_append (res, ", "); } - g_ptr_array_unref (array); - gtk_label_set_text (GTK_LABEL (config->fields_label), res->str); g_string_free (res, TRUE); } @@ -1113,34 +1108,36 @@ config_button_add (GtkWidget *widget, ETableConfig *config) { GPtrArray *array; - GList *columns = NULL; - GList *column; + GList *list = NULL; + GList *link; gint count; gint i; - e_table_selected_row_foreach (config->available, add_column, &columns); - columns = g_list_reverse (columns); + e_table_selected_row_foreach (config->available, add_column, &list); + list = g_list_reverse (list); - count = g_list_length (columns); + count = g_list_length (list); array = e_table_specification_ref_columns (config->source_spec); - config->temp_state->columns = g_renew ( - int, config->temp_state->columns, + config->temp_state->column_specs = g_renew ( + ETableColumnSpecification *, + config->temp_state->column_specs, config->temp_state->col_count + count); config->temp_state->expansions = g_renew ( - gdouble, config->temp_state->expansions, + gdouble, + config->temp_state->expansions, config->temp_state->col_count + count); i = config->temp_state->col_count; - for (column = columns; column; column = column->next) { + for (link = list; link != NULL; link = g_list_next (link)) { ETableColumnSpecification *col_spec; + gint index; - config->temp_state->columns[i] = - get_source_model_col_index ( - config, GPOINTER_TO_INT (column->data)); + index = get_source_model_col_index ( + config, GPOINTER_TO_INT (link->data)); + col_spec = g_ptr_array_index (array, index); - col_spec = g_ptr_array_index ( - array, config->temp_state->columns[i]); + config->temp_state->column_specs[i] = g_object_ref (col_spec); config->temp_state->expansions[i] = col_spec->expansion; i++; @@ -1149,7 +1146,7 @@ config_button_add (GtkWidget *widget, g_ptr_array_unref (array); - g_list_free (columns); + g_list_free (list); setup_fields (config); } @@ -1158,32 +1155,34 @@ static void config_button_remove (GtkWidget *widget, ETableConfig *config) { - GList *columns = NULL; - GList *column; + GList *list = NULL; + GList *link; - e_table_selected_row_foreach (config->shown, add_column, &columns); + e_table_selected_row_foreach (config->shown, add_column, &list); - for (column = columns; column; column = column->next) { - gint row = GPOINTER_TO_INT (column->data); + for (link = list; link != NULL; link = g_list_next (link)) { + gint row = GPOINTER_TO_INT (link->data); memmove ( - config->temp_state->columns + row, - config->temp_state->columns + row + 1, - sizeof (gint) * (config->temp_state->col_count - row - 1)); + config->temp_state->column_specs + row, + config->temp_state->column_specs + row + 1, + sizeof (gpointer) * (config->temp_state->col_count - row - 1)); memmove ( config->temp_state->expansions + row, config->temp_state->expansions + row + 1, sizeof (gdouble) * (config->temp_state->col_count - row - 1)); config->temp_state->col_count--; } - config->temp_state->columns = g_renew ( - int, config->temp_state->columns, + config->temp_state->column_specs = g_renew ( + ETableColumnSpecification *, + config->temp_state->column_specs, config->temp_state->col_count); config->temp_state->expansions = g_renew ( - gdouble, config->temp_state->expansions, + gdouble, + config->temp_state->expansions, config->temp_state->col_count); - g_list_free (columns); + g_list_free (list); setup_fields (config); } @@ -1194,9 +1193,9 @@ config_button_up (GtkWidget *widget, { GList *columns = NULL; GList *column; - gint *new_shown; + ETableColumnSpecification **new_column_specs; gdouble *new_expansions; - gint next_col; + ETableColumnSpecification *next_col; gdouble next_expansion; gint i; @@ -1208,35 +1207,38 @@ config_button_up (GtkWidget *widget, columns = g_list_reverse (columns); - new_shown = g_new (int, config->temp_state->col_count); - new_expansions = g_new (double, config->temp_state->col_count); + new_column_specs = g_new ( + ETableColumnSpecification *, config->temp_state->col_count); + new_expansions = g_new (gdouble, config->temp_state->col_count); column = columns; - next_col = config->temp_state->columns[0]; + next_col = config->temp_state->column_specs[0]; next_expansion = config->temp_state->expansions[0]; for (i = 1; i < config->temp_state->col_count; i++) { if (column && (GPOINTER_TO_INT (column->data) == i)) { - new_expansions[i - 1] = config->temp_state->expansions[i]; - new_shown[i - 1] = config->temp_state->columns[i]; + new_expansions[i - 1] = + config->temp_state->expansions[i]; + new_column_specs[i - 1] = + config->temp_state->column_specs[i]; column = column->next; } else { - new_shown[i - 1] = next_col; - next_col = config->temp_state->columns[i]; + new_column_specs[i - 1] = next_col; + next_col = config->temp_state->column_specs[i]; new_expansions[i - 1] = next_expansion; next_expansion = config->temp_state->expansions[i]; } } - new_shown[i - 1] = next_col; + new_column_specs[i - 1] = next_col; new_expansions[i - 1] = next_expansion; - g_free (config->temp_state->columns); + g_free (config->temp_state->column_specs); g_free (config->temp_state->expansions); - config->temp_state->columns = new_shown; + config->temp_state->column_specs = new_column_specs; config->temp_state->expansions = new_expansions; g_list_free (columns); @@ -1250,9 +1252,9 @@ config_button_down (GtkWidget *widget, { GList *columns = NULL; GList *column; - gint *new_shown; + ETableColumnSpecification **new_column_specs; gdouble *new_expansions; - gint next_col; + ETableColumnSpecification *next_col; gdouble next_expansion; gint i; @@ -1262,37 +1264,40 @@ config_button_down (GtkWidget *widget, if (columns == NULL) return; - new_shown = g_new (gint, config->temp_state->col_count); + new_column_specs = g_new ( + ETableColumnSpecification *, config->temp_state->col_count); new_expansions = g_new (gdouble, config->temp_state->col_count); column = columns; next_col = - config->temp_state->columns[config->temp_state->col_count - 1]; + config->temp_state->column_specs[config->temp_state->col_count - 1]; next_expansion = config->temp_state->expansions[config->temp_state->col_count - 1]; for (i = config->temp_state->col_count - 1; i > 0; i--) { if (column && (GPOINTER_TO_INT (column->data) == i - 1)) { - new_expansions[i] = config->temp_state->expansions[i - 1]; - new_shown[i] = config->temp_state->columns[i - 1]; + new_expansions[i] = + config->temp_state->expansions[i - 1]; + new_column_specs[i] = + config->temp_state->column_specs[i - 1]; column = column->next; } else { - new_shown[i] = next_col; - next_col = config->temp_state->columns[i - 1]; + new_column_specs[i] = next_col; + next_col = config->temp_state->column_specs[i - 1]; new_expansions[i] = next_expansion; next_expansion = config->temp_state->expansions[i - 1]; } } - new_shown[0] = next_col; + new_column_specs[0] = next_col; new_expansions[0] = next_expansion; - g_free (config->temp_state->columns); + g_free (config->temp_state->column_specs); g_free (config->temp_state->expansions); - config->temp_state->columns = new_shown; + config->temp_state->column_specs = new_column_specs; config->temp_state->expansions = new_expansions; g_list_free (columns); diff --git a/e-util/e-table-state.c b/e-util/e-table-state.c index 8dbe488f58..d37e7088c3 100644 --- a/e-util/e-table-state.c +++ b/e-util/e-table-state.c @@ -94,6 +94,11 @@ static void table_state_dispose (GObject *object) { ETableState *state = E_TABLE_STATE (object); + gint ii; + + for (ii = 0; ii < state->col_count; ii++) + g_clear_object (&state->column_specs[ii]); + state->col_count = 0; g_clear_object (&state->sort_info); g_weak_ref_set (&state->priv->specification, NULL); @@ -107,7 +112,7 @@ table_state_finalize (GObject *object) { ETableState *state = E_TABLE_STATE (object); - g_free (state->columns); + g_free (state->column_specs); g_free (state->expansions); /* Chain up to parent's finalize() method. */ @@ -263,8 +268,10 @@ void e_table_state_load_from_node (ETableState *state, const xmlNode *node) { + ETableSpecification *specification; xmlNode *children; GList *list = NULL, *iterator; + GPtrArray *columns; gdouble state_version; gint i; gboolean can_group = TRUE; @@ -272,6 +279,9 @@ e_table_state_load_from_node (ETableState *state, g_return_if_fail (E_IS_TABLE_STATE (state)); g_return_if_fail (node != NULL); + specification = e_table_state_ref_specification (state); + columns = e_table_specification_ref_columns (specification); + state_version = e_xml_get_double_prop_by_name_with_default ( node, (const guchar *)"state-version", STATE_VERSION); @@ -300,10 +310,15 @@ e_table_state_load_from_node (ETableState *state, state->sort_info, children, state_version); } } - g_free (state->columns); + + for (i = 0; i < state->col_count; i++) + g_clear_object (&state->column_specs[i]); + g_free (state->column_specs); g_free (state->expansions); + state->col_count = g_list_length (list); - state->columns = g_new (int, state->col_count); + state->column_specs = g_new ( + ETableColumnSpecification *, state->col_count); state->expansions = g_new (double, state->col_count); if (!state->sort_info) @@ -311,14 +326,22 @@ e_table_state_load_from_node (ETableState *state, e_table_sort_info_set_can_group (state->sort_info, can_group); for (iterator = list, i = 0; iterator; i++) { + ETableColumnSpecification *column_spec; int_and_double *column_info = iterator->data; - state->columns[i] = column_info->column; + column_spec = columns->pdata[column_info->column]; + + state->column_specs[i] = g_object_ref (column_spec); state->expansions[i] = column_info->expansion; + g_free (column_info); + iterator = g_list_next (iterator); } g_list_free (list); + + g_object_unref (specification); + g_ptr_array_unref (columns); } void @@ -367,11 +390,14 @@ xmlNode * e_table_state_save_to_node (ETableState *state, xmlNode *parent) { - gint i; + ETableSpecification *specification; xmlNode *node; + gint ii; g_return_val_if_fail (E_IS_TABLE_STATE (state), NULL); + specification = e_table_state_ref_specification (state); + if (parent) node = xmlNewChild ( parent, NULL, (const guchar *) "ETableState", NULL); @@ -379,25 +405,34 @@ e_table_state_save_to_node (ETableState *state, node = xmlNewNode (NULL, (const guchar *) "ETableState"); e_xml_set_double_prop_by_name ( - node, (const guchar *)"state-version", STATE_VERSION); + node, (const guchar *) "state-version", STATE_VERSION); - for (i = 0; i < state->col_count; i++) { - gint column = state->columns[i]; - gdouble expansion = state->expansions[i]; + for (ii = 0; ii < state->col_count; ii++) { xmlNode *new_node; + gint index; + + index = e_table_specification_get_column_index ( + specification, state->column_specs[ii]); + + if (index < 0) { + g_warn_if_reached (); + continue; + } new_node = xmlNewChild ( node, NULL, (const guchar *) "column", NULL); e_xml_set_integer_prop_by_name ( - new_node, (const guchar *) "source", column); - if (expansion >= -1) + new_node, (const guchar *) "source", index); + if (state->expansions[ii] >= -1) e_xml_set_double_prop_by_name ( new_node, (const guchar *) - "expansion", expansion); + "expansion", state->expansions[ii]); } e_table_sort_info_save_to_node (state->sort_info, node); + g_object_unref (specification); + return node; } diff --git a/e-util/e-table-state.h b/e-util/e-table-state.h index cd5d3e97fe..be7800163b 100644 --- a/e-util/e-table-state.h +++ b/e-util/e-table-state.h @@ -26,6 +26,7 @@ #include <libxml/tree.h> #include <e-util/e-table-sort-info.h> +#include <e-util/e-table-column-specification.h> /* Standard GObject macros */ #define E_TYPE_TABLE_STATE \ @@ -61,7 +62,7 @@ struct _ETableState { ETableSortInfo *sort_info; gint col_count; - gint *columns; + ETableColumnSpecification **column_specs; gdouble *expansions; }; diff --git a/e-util/e-table-utils.c b/e-util/e-table-utils.c index 3c598e38a9..040e5d3e07 100644 --- a/e-util/e-table-utils.c +++ b/e-util/e-table-utils.c @@ -39,8 +39,7 @@ e_table_state_to_header (GtkWidget *widget, ETableState *state) { ETableHeader *nh; - const gint max_cols = e_table_header_count (full_header); - gint column; + gint ii; GValue *val = g_new0 (GValue, 1); g_return_val_if_fail (widget, NULL); @@ -53,21 +52,17 @@ e_table_state_to_header (GtkWidget *widget, g_object_set_property (G_OBJECT (nh), "width_extras", val); g_free (val); - for (column = 0; column < state->col_count; column++) { - gint col; - gdouble expansion; + for (ii = 0; ii < state->col_count; ii++) { ETableCol *table_col; - col = state->columns[column]; - expansion = state->expansions[column]; + table_col = e_table_header_get_column_by_spec ( + full_header, state->column_specs[ii]); - if (col >= max_cols) + if (table_col == NULL) continue; - table_col = e_table_header_get_column (full_header, col); - - if (expansion >= -1) - table_col->expansion = expansion; + if (state->expansions[ii] >= -1) + table_col->expansion = state->expansions[ii]; e_table_header_add_column (nh, table_col, -1); } diff --git a/e-util/e-table.c b/e-util/e-table.c index 0aae2032b6..9b97c8b227 100644 --- a/e-util/e-table.c +++ b/e-util/e-table.c @@ -1677,31 +1677,39 @@ ETableState * e_table_get_state_object (ETable *e_table) { ETableState *state; + GPtrArray *columns; gint full_col_count; gint i, j; + columns = e_table_specification_ref_columns (e_table->spec); + state = e_table_state_new (e_table->spec); - if (state->sort_info) - g_object_unref (state->sort_info); - state->sort_info = e_table->sort_info; - g_object_ref (state->sort_info); + + g_clear_object (&state->sort_info); + state->sort_info = g_object_ref (e_table->sort_info); state->col_count = e_table_header_count (e_table->header); full_col_count = e_table_header_count (e_table->full_header); - state->columns = g_new (int, state->col_count); - state->expansions = g_new (double, state->col_count); + + state->column_specs = g_new ( + ETableColumnSpecification *, state->col_count); + state->expansions = g_new (gdouble, state->col_count); + for (i = 0; i < state->col_count; i++) { ETableCol *col = e_table_header_get_column (e_table->header, i); - state->columns[i] = -1; + state->column_specs[i] = NULL; for (j = 0; j < full_col_count; j++) { if (col->spec->model_col == e_table_header_index (e_table->full_header, j)) { - state->columns[i] = j; + state->column_specs[i] = + g_object_ref (columns->pdata[j]); break; } } state->expansions[i] = col->expansion; } + g_ptr_array_unref (columns); + return state; } diff --git a/e-util/e-tree.c b/e-util/e-tree.c index a8ccefcb5d..e6dc943b34 100644 --- a/e-util/e-tree.c +++ b/e-util/e-tree.c @@ -1382,30 +1382,40 @@ ETableState * e_tree_get_state_object (ETree *tree) { ETableState *state; + GPtrArray *columns; gint full_col_count; gint i, j; + columns = e_table_specification_ref_columns (tree->priv->spec); + state = e_table_state_new (tree->priv->spec); - state->sort_info = tree->priv->sort_info; - if (state->sort_info) - g_object_ref (state->sort_info); + + g_clear_object (&state->sort_info); + if (tree->priv->sort_info != NULL) + state->sort_info = g_object_ref (tree->priv->sort_info); state->col_count = e_table_header_count (tree->priv->header); full_col_count = e_table_header_count (tree->priv->full_header); - state->columns = g_new (int, state->col_count); - state->expansions = g_new (double, state->col_count); + + state->column_specs = g_new ( + ETableColumnSpecification *, state->col_count); + state->expansions = g_new (gdouble, state->col_count); + for (i = 0; i < state->col_count; i++) { ETableCol *col = e_table_header_get_column (tree->priv->header, i); - state->columns[i] = -1; + state->column_specs[i] = NULL; for (j = 0; j < full_col_count; j++) { if (col->spec->model_col == e_table_header_index (tree->priv->full_header, j)) { - state->columns[i] = j; + state->column_specs[i] = + g_object_ref (columns->pdata[j]); break; } } state->expansions[i] = col->expansion; } + g_ptr_array_unref (columns); + return state; } |