aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2013-06-27 01:05:02 +0800
committerMatthew Barnes <mbarnes@redhat.com>2013-07-02 22:34:08 +0800
commit37aae129f397e5973910ff227a0f18efb1b5d2fe (patch)
tree94d9a557c3ea44dc1892df1f3931e6f7ca7c60cc
parente663dec920f8359f07c6047f2ef3eb10f052f1e8 (diff)
downloadgsoc2013-evolution-37aae129f397e5973910ff227a0f18efb1b5d2fe.tar
gsoc2013-evolution-37aae129f397e5973910ff227a0f18efb1b5d2fe.tar.gz
gsoc2013-evolution-37aae129f397e5973910ff227a0f18efb1b5d2fe.tar.bz2
gsoc2013-evolution-37aae129f397e5973910ff227a0f18efb1b5d2fe.tar.lz
gsoc2013-evolution-37aae129f397e5973910ff227a0f18efb1b5d2fe.tar.xz
gsoc2013-evolution-37aae129f397e5973910ff227a0f18efb1b5d2fe.tar.zst
gsoc2013-evolution-37aae129f397e5973910ff227a0f18efb1b5d2fe.zip
ETableSpecification: Make the columns array private.
Use e_table_specification_ref_columns() to access column specs.
-rw-r--r--e-util/e-table-config.c135
-rw-r--r--e-util/e-table-specification.c49
-rw-r--r--e-util/e-table-specification.h1
-rw-r--r--e-util/e-table-state.c10
-rw-r--r--e-util/e-table-utils.c18
5 files changed, 133 insertions, 80 deletions
diff --git a/e-util/e-table-config.c b/e-util/e-table-config.c
index 1c7f5563d5..187dd601be 100644
--- a/e-util/e-table-config.c
+++ b/e-util/e-table-config.c
@@ -241,34 +241,58 @@ static ETableColumnSpecification *
find_column_in_spec (ETableSpecification *spec,
gint model_col)
{
- ETableColumnSpecification **column;
+ ETableColumnSpecification *column = NULL;
+ GPtrArray *array;
+ guint ii;
- for (column = spec->columns; *column; column++) {
- if ((*column)->disabled)
- continue;
- if ((*column)->model_col != model_col)
+ array = e_table_specification_ref_columns (spec);
+
+ for (ii = 0; ii < array->len; ii++) {
+ ETableColumnSpecification *candidate;
+
+ candidate = g_ptr_array_index (array, ii);
+
+ if (candidate->disabled)
continue;
- return *column;
+ if (candidate->model_col == model_col) {
+ column = candidate;
+ break;
+ }
}
- return NULL;
+ g_ptr_array_unref (array);
+
+ return column;
}
static gint
find_model_column_by_name (ETableSpecification *spec,
const gchar *s)
{
- ETableColumnSpecification **column;
+ GPtrArray *array;
+ gint model_col = -1;
+ guint ii;
+
+ array = e_table_specification_ref_columns (spec);
- for (column = spec->columns; *column; column++) {
+ for (ii = 0; ii < array->len; ii++) {
+ ETableColumnSpecification *candidate;
- if ((*column)->disabled)
+ candidate = g_ptr_array_index (array, ii);
+
+ if (candidate->disabled)
continue;
- if (g_ascii_strcasecmp ((*column)->title, s) == 0)
- return (*column)->model_col;
+
+ if (g_ascii_strcasecmp (candidate->title, s) == 0) {
+ model_col = candidate->model_col;
+ break;
+ }
}
- return -1;
+
+ g_ptr_array_unref (array);
+
+ return model_col;
}
static void
@@ -451,6 +475,7 @@ config_group_info_update (ETableConfig *config)
static void
setup_fields (ETableConfig *config)
{
+ GPtrArray *array;
gint i;
e_table_model_freeze ((ETableModel *) config->available_model);
@@ -458,17 +483,27 @@ setup_fields (ETableConfig *config)
e_table_without_show_all (config->available_model);
e_table_subset_variable_clear (config->shown_model);
+ array = e_table_specification_ref_columns (config->source_spec);
+
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++)
- if (!config->source_spec->columns[j]->disabled)
+ for (j = 0, idx = 0; j < config->temp_state->columns[i]; j++) {
+ ETableColumnSpecification *column;
+
+ column = g_ptr_array_index (array, j);
+
+ if (!column->disabled)
idx++;
+ }
e_table_subset_variable_add (config->shown_model, idx);
e_table_without_hide (config->available_model, GINT_TO_POINTER (idx));
}
}
+
+ g_ptr_array_unref (array);
+
e_table_model_thaw ((ETableModel *) config->available_model);
e_table_model_thaw ((ETableModel *) config->shown_model);
}
@@ -476,20 +511,28 @@ setup_fields (ETableConfig *config)
static void
config_fields_info_update (ETableConfig *config)
{
- ETableColumnSpecification **column;
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, column = config->source_spec->columns; *column; column++, j++) {
+ for (j = 0; j < array->len; j++) {
+ ETableColumnSpecification *column;
+ const gchar *title;
+
+ column = g_ptr_array_index (array, j);
- if ((*column)->disabled)
+ if (column->disabled)
continue;
if (config->state->columns[i] != j)
continue;
- g_string_append (res, dgettext (config->domain, (*column)->title));
+ title = dgettext (config->domain, column->title);
+ g_string_append (res, title);
+
if (i + 1 < config->state->col_count)
g_string_append (res, ", ");
@@ -497,6 +540,8 @@ config_fields_info_update (ETableConfig *config)
}
}
+ g_ptr_array_unref (array);
+
gtk_label_set_text (GTK_LABEL (config->fields_label), res->str);
g_string_free (res, TRUE);
}
@@ -623,24 +668,30 @@ static ETableMemoryStoreColumnInfo store_columns[] = {
static ETableModel *
create_store (ETableConfig *config)
{
- gint i;
ETableModel *store;
+ GPtrArray *array;
+ guint ii;
store = e_table_memory_store_new (store_columns);
- for (i = 0; config->source_spec->columns[i]; i++) {
+ array = e_table_specification_ref_columns (config->source_spec);
+
+ for (ii = 0; ii < array->len; ii++) {
+ ETableColumnSpecification *column;
gchar *text;
- if (config->source_spec->columns[i]->disabled)
+ column = g_ptr_array_index (array, ii);
+
+ if (column->disabled)
continue;
- text = g_strdup (dgettext (
- config->domain,
- config->source_spec->columns[i]->title));
+ text = g_strdup (dgettext (config->domain, column->title));
e_table_memory_store_insert_adopt (
- E_TABLE_MEMORY_STORE (store), -1, NULL, text, i);
+ E_TABLE_MEMORY_STORE (store), -1, NULL, text, ii);
}
+ g_ptr_array_unref (array);
+
return store;
}
@@ -1061,6 +1112,7 @@ static void
config_button_add (GtkWidget *widget,
ETableConfig *config)
{
+ GPtrArray *array;
GList *columns = NULL;
GList *column;
gint count;
@@ -1071,6 +1123,8 @@ config_button_add (GtkWidget *widget,
count = g_list_length (columns);
+ array = e_table_specification_ref_columns (config->source_spec);
+
config->temp_state->columns = g_renew (
int, config->temp_state->columns,
config->temp_state->col_count + count);
@@ -1079,16 +1133,22 @@ config_button_add (GtkWidget *widget,
config->temp_state->col_count + count);
i = config->temp_state->col_count;
for (column = columns; column; column = column->next) {
+ ETableColumnSpecification *col_spec;
+
config->temp_state->columns[i] =
get_source_model_col_index (
config, GPOINTER_TO_INT (column->data));
- config->temp_state->expansions[i] =
- config->source_spec->columns
- [config->temp_state->columns[i]]->expansion;
+
+ col_spec = g_ptr_array_index (
+ array, config->temp_state->columns[i]);
+ config->temp_state->expansions[i] = col_spec->expansion;
+
i++;
}
config->temp_state->col_count += count;
+ g_ptr_array_unref (array);
+
g_list_free (columns);
setup_fields (config);
@@ -1382,7 +1442,8 @@ e_table_config_construct (ETableConfig *config,
ETableState *state,
GtkWindow *parent_window)
{
- ETableColumnSpecification **column;
+ GPtrArray *array;
+ guint ii;
g_return_val_if_fail (config != NULL, NULL);
g_return_val_if_fail (header != NULL, NULL);
@@ -1400,16 +1461,22 @@ e_table_config_construct (ETableConfig *config,
config->domain = g_strdup (spec->domain);
- for (column = config->source_spec->columns; *column; column++) {
- gchar *label = (*column)->title;
+ array = e_table_specification_ref_columns (spec);
- if ((*column)->disabled)
+ for (ii = 0; ii < array->len; ii++) {
+ ETableColumnSpecification *column;
+
+ column = g_ptr_array_index (array, ii);
+
+ if (column->disabled)
continue;
config->column_names = g_slist_append (
- config->column_names, label);
+ config->column_names, column->title);
}
+ g_ptr_array_unref (array);
+
setup_gui (config);
gtk_window_set_transient_for (GTK_WINDOW (config->dialog_toplevel),
diff --git a/e-util/e-table-specification.c b/e-util/e-table-specification.c
index 3dbff96c8a..d6ca13bec4 100644
--- a/e-util/e-table-specification.c
+++ b/e-util/e-table-specification.c
@@ -34,7 +34,7 @@
((obj), E_TYPE_TABLE_SPECIFICATION, ETableSpecificationPrivate))
struct _ETableSpecificationPrivate {
- gint placeholder;
+ GPtrArray *columns;
};
G_DEFINE_TYPE (
@@ -46,19 +46,13 @@ static void
table_specification_dispose (GObject *object)
{
ETableSpecification *specification;
- gint ii;
specification = E_TABLE_SPECIFICATION (object);
- if (specification->columns != NULL) {
- for (ii = 0; specification->columns[ii] != NULL; ii++)
- g_object_unref (specification->columns[ii]);
- g_free (specification->columns);
- specification->columns = NULL;
- }
-
g_clear_object (&specification->state);
+ g_ptr_array_set_size (specification->priv->columns, 0);
+
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_table_specification_parent_class)->dispose (object);
}
@@ -73,6 +67,8 @@ table_specification_finalize (GObject *object)
g_free (specification->click_to_add_message);
g_free (specification->domain);
+ g_ptr_array_unref (specification->priv->columns);
+
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (e_table_specification_parent_class)->finalize (object);
}
@@ -94,6 +90,9 @@ e_table_specification_init (ETableSpecification *specification)
{
specification->priv =
E_TABLE_SPECIFICATION_GET_PRIVATE (specification);
+ specification->priv->columns =
+ g_ptr_array_new_with_free_func (
+ (GDestroyNotify) g_object_unref);
specification->alternating_row_colors = TRUE;
specification->no_headers = FALSE;
@@ -138,18 +137,9 @@ e_table_specification_new (void)
GPtrArray *
e_table_specification_ref_columns (ETableSpecification *specification)
{
- GPtrArray *array;
- guint ii;
-
g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), NULL);
- g_return_val_if_fail (specification->columns != NULL, NULL);
-
- array = g_ptr_array_new ();
- for (ii = 0; specification->columns[ii] != NULL; ii++)
- g_ptr_array_add (array, specification->columns[ii]);
-
- return array;
+ return g_ptr_array_ref (specification->priv->columns);
}
/**
@@ -228,8 +218,6 @@ e_table_specification_load_from_node (ETableSpecification *specification,
{
gchar *temp;
xmlNode *children;
- GQueue columns = G_QUEUE_INIT;
- guint ii = 0;
specification->no_headers = e_xml_get_bool_prop_by_name (node, (const guchar *)"no-headers");
specification->click_to_add = e_xml_get_bool_prop_by_name (node, (const guchar *)"click-to-add");
@@ -284,20 +272,15 @@ e_table_specification_load_from_node (ETableSpecification *specification,
if (specification->state)
g_object_unref (specification->state);
specification->state = NULL;
- if (specification->columns) {
- for (ii = 0; specification->columns[ii] != NULL; ii++) {
- g_object_unref (specification->columns[ii]);
- }
- g_free (specification->columns);
- }
- specification->columns = NULL;
+
+ g_ptr_array_set_size (specification->priv->columns, 0);
for (children = node->xmlChildrenNode; children; children = children->next) {
if (!strcmp ((gchar *) children->name, "ETableColumn")) {
ETableColumnSpecification *col_spec = e_table_column_specification_new ();
e_table_column_specification_load_from_node (col_spec, children);
- g_queue_push_tail (&columns, col_spec);
+ g_ptr_array_add (specification->priv->columns, col_spec);
} else if (specification->state == NULL && !strcmp ((gchar *) children->name, "ETableState")) {
specification->state = e_table_state_new (specification);
e_table_state_load_from_node (specification->state, children);
@@ -305,14 +288,6 @@ e_table_specification_load_from_node (ETableSpecification *specification,
}
}
- ii = 0;
- specification->columns = g_new0 (
- ETableColumnSpecification *,
- g_queue_get_length (&columns) + 1);
- while (!g_queue_is_empty (&columns))
- specification->columns[ii++] = g_queue_pop_head (&columns);
-
- /* e_table_state_vanilla() uses the columns array we just created. */
if (specification->state == NULL)
specification->state = e_table_state_vanilla (specification);
}
diff --git a/e-util/e-table-specification.h b/e-util/e-table-specification.h
index 2fec4b8e40..79484aa92e 100644
--- a/e-util/e-table-specification.h
+++ b/e-util/e-table-specification.h
@@ -59,7 +59,6 @@ struct _ETableSpecification {
GObject parent;
ETableSpecificationPrivate *priv;
- ETableColumnSpecification **columns;
ETableState *state;
guint alternating_row_colors : 1;
diff --git a/e-util/e-table-state.c b/e-util/e-table-state.c
index 77903c7ac8..8dbe488f58 100644
--- a/e-util/e-table-state.c
+++ b/e-util/e-table-state.c
@@ -173,18 +173,22 @@ ETableState *
e_table_state_vanilla (ETableSpecification *specification)
{
ETableState *state;
+ GPtrArray *columns;
GString *str;
- gint ii;
+ guint ii;
g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), NULL);
- g_return_val_if_fail (specification->columns != NULL, NULL);
+
+ columns = e_table_specification_ref_columns (specification);
str = g_string_new ("<ETableState>\n");
- for (ii = 0; specification->columns[ii] != NULL; ii++)
+ for (ii = 0; ii < columns->len; ii++)
g_string_append_printf (str, " <column source=\"%d\"/>\n", ii);
g_string_append (str, " <grouping></grouping>\n");
g_string_append (str, "</ETableState>\n");
+ g_ptr_array_unref (columns);
+
state = e_table_state_new (specification);
e_table_state_load_from_string (state, str->str);
diff --git a/e-util/e-table-utils.c b/e-util/e-table-utils.c
index b914e595b4..1bd16a928e 100644
--- a/e-util/e-table-utils.c
+++ b/e-util/e-table-utils.c
@@ -148,23 +148,31 @@ e_table_spec_to_full_header (ETableSpecification *spec,
ETableExtras *ete)
{
ETableHeader *nh;
- gint column;
+ GPtrArray *columns;
+ guint ii;
g_return_val_if_fail (spec, NULL);
g_return_val_if_fail (ete, NULL);
nh = e_table_header_new ();
- for (column = 0; spec->columns[column]; column++) {
- ETableCol *col = et_col_spec_to_col (
- spec->columns[column], ete, spec->domain);
+ columns = e_table_specification_ref_columns (spec);
- if (col) {
+ for (ii = 0; ii < columns->len; ii++) {
+ ETableColumnSpecification *col_spec;
+ ETableCol *col;
+
+ col_spec = g_ptr_array_index (columns, ii);
+ col = et_col_spec_to_col (col_spec, ete, spec->domain);
+
+ if (col != NULL) {
e_table_header_add_column (nh, col, -1);
g_object_unref (col);
}
}
+ g_ptr_array_unref (columns);
+
return nh;
}