diff options
Diffstat (limited to 'src/analysis')
-rw-r--r-- | src/analysis/db/collection-int.h | 2 | ||||
-rw-r--r-- | src/analysis/db/collection.c | 67 | ||||
-rw-r--r-- | src/analysis/db/collection.h | 12 |
3 files changed, 80 insertions, 1 deletions
diff --git a/src/analysis/db/collection-int.h b/src/analysis/db/collection-int.h index 0e69ff8..9c3af67 100644 --- a/src/analysis/db/collection-int.h +++ b/src/analysis/db/collection-int.h @@ -73,6 +73,8 @@ struct _GDbCollectionClass void (* state_changed) (GDbCollection *, GDbItem *); + void (* active_changed) (GDbCollection *, ActiveItemChange, GDbItem *); + }; diff --git a/src/analysis/db/collection.c b/src/analysis/db/collection.c index 4c7a496..dcab73e 100644 --- a/src/analysis/db/collection.c +++ b/src/analysis/db/collection.c @@ -127,6 +127,14 @@ static void g_db_collection_class_init(GDbCollectionClass *klass) g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT); + g_signal_new("active-changed", + G_TYPE_DB_COLLECTION, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GDbCollectionClass, active_changed), + NULL, NULL, + g_cclosure_user_marshal_VOID__ENUM_OBJECT, + G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_OBJECT); + } @@ -587,6 +595,54 @@ GDbItem **g_db_collection_get_items(const GDbCollection *collec, size_t *count) /****************************************************************************** * * +* Paramètres : collec = ensemble d'éléments à consulter. * +* count = taille de la liste constituée. [OUT] * +* * +* Description : Renvoie la liste des éléments actifs. * +* * +* Retour : Liste d'éléments à parcourir. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GDbItem **g_db_collection_get_last_items(GDbCollection *collec, size_t *count) +{ + GDbItem **result; /* Liste à retourner */ + GList *list; /* Liste brute des éléments */ + GList *iter; /* Boucle de parcours #0 */ + size_t i; /* Boucle de parcours #1 */ + + assert(!g_rw_lock_writer_trylock(&collec->params_access)); + + list = g_hash_table_get_values(collec->last_items); + + *count = g_list_length(list); + + if (*count == 0) + result = NULL; + + else + { + result = malloc(*count * sizeof(GDbItem *)); + + for (iter = g_list_first(list), i = 0; iter != NULL; iter = g_list_next(iter), i++) + { + result[i] = iter->data; + g_object_ref(G_OBJECT(result[i])); + } + + } + + g_list_free(list); + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : collec = ensemble d'éléments à considérer. * * item = élément de collection à manipuler. * * new = précise la nature de l'élément à insérer. * @@ -632,16 +688,20 @@ static void g_db_collection_set_last_item(GDbCollection *collec, GDbItem *item, g_object_ref(G_OBJECT(prev)); if (g_db_item_get_flags(item) & DIF_ERASER) + { + g_signal_emit_by_name(collec, "active-changed", AIC_REMOVED, prev); g_hash_table_remove(collec->last_items, prev); + } else { - if (new) + if (!new) g_db_item_add_flag(item, DIF_UPDATED); g_object_ref(G_OBJECT(item)); g_object_ref(G_OBJECT(item)); + g_signal_emit_by_name(collec, "active-changed", AIC_UPDATED, item); g_hash_table_replace(collec->last_items, item, item); } @@ -657,6 +717,7 @@ static void g_db_collection_set_last_item(GDbCollection *collec, GDbItem *item, g_object_ref(G_OBJECT(item)); g_object_ref(G_OBJECT(item)); + g_signal_emit_by_name(collec, "active-changed", AIC_ADDED, item); g_hash_table_add(collec->last_items, item); } @@ -888,13 +949,17 @@ static void g_db_collection_unset_last_item(GDbCollection *collec, GDbItem *item old = collec->items[i - 1]; if (old == NULL || g_db_item_get_flags(old) & DIF_ERASER) + { + g_signal_emit_by_name(collec, "active-changed", AIC_REMOVED, item); g_hash_table_remove(collec->last_items, item); + } else { g_object_ref(G_OBJECT(old)); g_object_ref(G_OBJECT(old)); + g_signal_emit_by_name(collec, "active-changed", AIC_UPDATED, old); g_hash_table_replace(collec->last_items, old, old); } diff --git a/src/analysis/db/collection.h b/src/analysis/db/collection.h index f381af5..6c14624 100644 --- a/src/analysis/db/collection.h +++ b/src/analysis/db/collection.h @@ -95,6 +95,18 @@ void g_db_collection_lock_unlock(GDbCollection *, bool, bool); /* Renvoie la liste des éléments rassemblés. */ GDbItem **g_db_collection_get_items(const GDbCollection *, size_t *); +/* Renvoie la liste des éléments actifs. */ +GDbItem **g_db_collection_get_last_items(GDbCollection *, size_t *); + +/* Evénements concernant les éléments actifs */ +typedef enum _ActiveItemChange +{ + AIC_ADDED, /* Ajout d'un élément */ + AIC_REMOVED, /* Retrait d'un élément */ + AIC_UPDATED, /* Mise à jour d'un élément */ + +} ActiveItemChange; + /* Procède à l'ajout d'un nouvel élément dans la collection. */ bool g_db_collection_add_item(GDbCollection *, GDbItem *); |