[gnome-keyring: 5/12] gcr: gcr_collection_model_set_columns() now returns number of columns
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring: 5/12] gcr: gcr_collection_model_set_columns() now returns number of columns
- Date: Mon, 19 Sep 2011 07:39:01 +0000 (UTC)
commit c51050d81eae663e949f8794758931237a7f0b30
Author: Stef Walter <stefw collabora co uk>
Date: Mon Sep 5 16:08:58 2011 +0200
gcr: gcr_collection_model_set_columns() now returns number of columns
* Return the number of real columns added (not including the
possible selected column).
* Fix several crashers in GcrCollectionModel as well.
gcr/gcr-collection-model.c | 23 +++++++++++++++++------
gcr/gcr-collection-model.h | 2 +-
2 files changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/gcr/gcr-collection-model.c b/gcr/gcr-collection-model.c
index 54b5ee5..78b2221 100644
--- a/gcr/gcr-collection-model.c
+++ b/gcr/gcr-collection-model.c
@@ -608,7 +608,8 @@ remove_object_from_sequence (GcrCollectionModel *self,
row->children = NULL;
}
- g_hash_table_remove (self->pv->selected, object);
+ if (self->pv->selected)
+ g_hash_table_remove (self->pv->selected, object);
if (!g_hash_table_remove (self->pv->object_to_seq, object))
g_assert_not_reached ();
@@ -920,6 +921,11 @@ collection_resort_sequence (GcrCollectionModel *self,
g_ptr_array_add (previous, row->object);
}
+ if (previous->len == 0) {
+ g_ptr_array_free (previous, TRUE);
+ return;
+ }
+
/* Actually perform the sort */
g_sequence_sort (sequence, self->pv->order_current, self);
@@ -1304,16 +1310,19 @@ gcr_collection_model_new_full (GcrCollection *collection, const GcrColumn *colum
*
* The columns are accessed as static data. They should continue to remain
* in memory for longer than the GcrCollectionModel object.
+ *
+ * Returns: The number of columns
*/
-void
-gcr_collection_model_set_columns (GcrCollectionModel *self, const GcrColumn *columns)
+guint
+gcr_collection_model_set_columns (GcrCollectionModel *self,
+ const GcrColumn *columns)
{
const GcrColumn *col;
guint n_columns;
- g_return_if_fail (GCR_IS_COLLECTION_MODEL (self));
- g_return_if_fail (columns);
- g_return_if_fail (self->pv->n_columns == 0);
+ g_return_val_if_fail (GCR_IS_COLLECTION_MODEL (self), 0);
+ g_return_val_if_fail (columns, 0);
+ g_return_val_if_fail (self->pv->n_columns == 0, 0);
/* Count the number of columns, extra column for selected */
for (col = columns, n_columns = 1; col->property_name; ++col)
@@ -1323,6 +1332,8 @@ gcr_collection_model_set_columns (GcrCollectionModel *self, const GcrColumn *col
self->pv->columns = columns;
self->pv->n_columns = n_columns;
self->pv->column_sort_closures = g_new0 (GcrCollectionSortClosure, self->pv->n_columns);
+
+ return n_columns - 1;
}
/**
diff --git a/gcr/gcr-collection-model.h b/gcr/gcr-collection-model.h
index 9e3b726..fcd98e1 100644
--- a/gcr/gcr-collection-model.h
+++ b/gcr/gcr-collection-model.h
@@ -57,7 +57,7 @@ GcrCollectionModel* gcr_collection_model_new (GcrCollection *c
GcrCollectionModel* gcr_collection_model_new_full (GcrCollection *collection,
const GcrColumn *columns);
-void gcr_collection_model_set_columns (GcrCollectionModel *self,
+guint gcr_collection_model_set_columns (GcrCollectionModel *self,
const GcrColumn *columns);
GcrCollection * gcr_collection_model_get_collection (GcrCollectionModel *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]