summaryrefslogtreecommitdiff
path: root/src/analysis/db/collection.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2019-09-17 22:06:54 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2019-09-17 22:06:54 (GMT)
commit3dc843b3f7991dcd738a30821ff56c7fe13f1094 (patch)
tree22b40ef7cd933a57942bd01d61c9e6a07fdd80c6 /src/analysis/db/collection.c
parent682159e73cfbf8ec61d2f2aba765be1016a30ded (diff)
Kept tracks of current active DB items.
Diffstat (limited to 'src/analysis/db/collection.c')
-rw-r--r--src/analysis/db/collection.c57
1 files changed, 48 insertions, 9 deletions
diff --git a/src/analysis/db/collection.c b/src/analysis/db/collection.c
index 33145a6..f728718 100644
--- a/src/analysis/db/collection.c
+++ b/src/analysis/db/collection.c
@@ -106,13 +106,13 @@ static void g_db_collection_class_init(GDbCollectionClass *klass)
klass->setup_load = (collec_setup_load_fc)_g_db_collection_setup_load;
- g_signal_new("content-changed",
+ g_signal_new("content-extended",
G_TYPE_DB_COLLECTION,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(GDbCollectionClass, content_changed),
+ G_STRUCT_OFFSET(GDbCollectionClass, content_extended),
NULL, NULL,
- g_cclosure_user_marshal_VOID__ENUM_OBJECT,
- G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_OBJECT);
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1, G_TYPE_OBJECT);
}
@@ -133,6 +133,11 @@ static void g_db_collection_init(GDbCollection *collec)
{
collec->binary = NULL;
+ collec->last_items = g_hash_table_new_full((GHashFunc)g_db_item_hash_key,
+ (GEqualFunc)g_db_item_cmp_key,
+ (GDestroyNotify)g_object_unref,
+ (GDestroyNotify)g_object_unref);
+
g_rw_lock_init(&collec->params_access);
}
@@ -654,6 +659,7 @@ bool g_db_collection_has_item(GDbCollection *collec, GDbItem *item)
bool _g_db_collection_add_item(GDbCollection *collec, GDbItem *item, bool lock)
{
bool result; /* Bilan à faire remonter */
+ GDbItem *prev; /* Elément similaire précédent */
result = true;
@@ -666,7 +672,40 @@ bool _g_db_collection_add_item(GDbCollection *collec, GDbItem *item, bool lock)
g_object_ref(G_OBJECT(item));
collec->sorted = g_list_insert_sorted(collec->sorted, item, (GCompareFunc)g_db_item_compare_with_timestamp);
- g_signal_emit_by_name(collec, "content-changed", DBA_ADD_ITEM, item);
+ prev = g_hash_table_lookup(collec->last_items, item);
+
+ if (prev != NULL)
+ {
+ g_object_ref(G_OBJECT(prev));
+
+ if (g_db_item_get_flags(item) & DIF_ERASER)
+ g_hash_table_remove(collec->last_items, prev);
+
+ else
+ {
+ g_db_item_add_flag(item, DIF_UPDATED);
+
+ g_object_ref(G_OBJECT(item));
+ g_object_ref(G_OBJECT(item));
+
+ g_hash_table_replace(collec->last_items, item, item);
+
+ }
+
+ g_object_unref(G_OBJECT(prev));
+
+ }
+
+ else
+ {
+ g_object_ref(G_OBJECT(item));
+ g_object_ref(G_OBJECT(item));
+
+ g_hash_table_add(collec->last_items, item);
+
+ }
+
+ g_signal_emit_by_name(collec, "content-extended", item);
if (lock)
g_db_collection_wunlock(collec);
@@ -718,7 +757,7 @@ bool _g_db_collection_remove_item(GDbCollection *collec, GDbItem *item, bool loc
collec->items = g_list_delete_link(collec->items, found);
if (signal)
- g_signal_emit_by_name(collec, "content-changed", DBA_REM_ITEM, internal);
+ ;//g_signal_emit_by_name(collec, "content-changed", DBA_REM_ITEM, internal);
g_object_unref(G_OBJECT(internal));
g_object_unref(G_OBJECT(internal));
@@ -816,7 +855,7 @@ bool _g_db_collection_update_item_activity(GDbCollection *collec, GDbItem *item,
result = g_db_item_set_activity(internal, collec->binary, timestamp);
- g_signal_emit_by_name(collec, "content-changed", DBA_CHANGE_STATE, internal);
+ //g_signal_emit_by_name(collec, "content-changed", DBA_CHANGE_STATE, internal);
}
@@ -863,7 +902,7 @@ GList *g_db_collection_set_last_active(GDbCollection *collec, timestamp_t timest
{
/* ... */g_db_item_set_activity(item, collec->binary, NULL);
/* ... */g_db_collection_store_updated_item(collec, item, db);
- g_signal_emit_by_name(collec, "content-changed", DBA_CHANGE_STATE, item);
+ //g_signal_emit_by_name(collec, "content-changed", DBA_CHANGE_STATE, item);
}
}
@@ -911,7 +950,7 @@ bool g_db_collection_set_inactive(GDbCollection *collec, GDbItem *item, timestam
result = g_db_item_set_activity(item, collec->binary, timestamp);
- g_signal_emit_by_name(collec, "content-changed", DBA_CHANGE_STATE, item);
+ //g_signal_emit_by_name(collec, "content-changed", DBA_CHANGE_STATE, item);
return result;