From d40e5a8ba1e7d362415be17d0ccde4477243839d Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 28 Jun 2013 12:05:01 -0400 Subject: Add e_table_specification_get_column_index(). Lookups up the column index of an ETableColumnSpecification, returns a negative value if no match found. --- .../evolution-util/evolution-util-sections.txt | 1 + e-util/e-table-specification.c | 41 ++++++++++++++++++++++ e-util/e-table-specification.h | 3 ++ 3 files changed, 45 insertions(+) diff --git a/doc/reference/evolution-util/evolution-util-sections.txt b/doc/reference/evolution-util/evolution-util-sections.txt index 039667a3b0..6555f5b1dd 100644 --- a/doc/reference/evolution-util/evolution-util-sections.txt +++ b/doc/reference/evolution-util/evolution-util-sections.txt @@ -3915,6 +3915,7 @@ e_table_sorting_utils_lookup_cmp_cache ETableSpecification e_table_specification_new e_table_specification_ref_columns +e_table_specification_get_column_index e_table_specification_load_from_file e_table_specification_load_from_string e_table_specification_load_from_node diff --git a/e-util/e-table-specification.c b/e-util/e-table-specification.c index d6ca13bec4..40d4a54d63 100644 --- a/e-util/e-table-specification.c +++ b/e-util/e-table-specification.c @@ -142,6 +142,47 @@ e_table_specification_ref_columns (ETableSpecification *specification) return g_ptr_array_ref (specification->priv->columns); } +/** + * e_table_specification_get_column_index: + * @specification: an #ETableSpecification + * @column_spec: an #ETableColumnSpecification + * + * Returns the zero-based index of @column_spec within @specification, + * or a negative value if @column_spec is not defined by @specification. + * + * Returns: the column index of @column_spec, or a negative value + **/ +gint +e_table_specification_get_column_index (ETableSpecification *specification, + ETableColumnSpecification *column_spec) +{ + GPtrArray *columns; + gint column_index = -1; + guint ii; + + g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), -1); + g_return_val_if_fail (E_IS_TABLE_COLUMN_SPECIFICATION (column_spec), -1); + + columns = e_table_specification_ref_columns (specification); + + for (ii = 0; ii < columns->len; ii++) { + gboolean column_specs_equal; + + column_specs_equal = + e_table_column_specification_equal ( + column_spec, columns->pdata[ii]); + + if (column_specs_equal) { + column_index = (gint) ii; + break; + } + } + + g_ptr_array_unref (columns); + + return column_index; +} + /** * e_table_specification_load_from_file: * @specification: an #ETableSpecification diff --git a/e-util/e-table-specification.h b/e-util/e-table-specification.h index 79484aa92e..09b86c3791 100644 --- a/e-util/e-table-specification.h +++ b/e-util/e-table-specification.h @@ -87,6 +87,9 @@ ETableSpecification * e_table_specification_new (void); GPtrArray * e_table_specification_ref_columns (ETableSpecification *specification); +gint e_table_specification_get_column_index + (ETableSpecification *specification, + ETableColumnSpecification *column_spec); gboolean e_table_specification_load_from_file (ETableSpecification *specification, const gchar *filename); -- cgit v1.2.3