static void _dt_collection_recount_callback_2(gpointer instance, uint8_t id, gpointer user_data) { dt_collection_t *collection = (dt_collection_t *)user_data; int old_count = collection->count; collection->count = _dt_collection_compute_count(collection); if(!collection->clone) { if(old_count != collection->count) dt_collection_hint_message(collection); dt_control_signal_raise(darktable.signals, DT_SIGNAL_COLLECTION_CHANGED); } }
int dt_collection_update (const dt_collection_t *collection) { uint32_t result; gchar *wq, *sq, *selq, *query; wq = sq = selq = query = NULL; /* build where part */ if (!(collection->params.query_flags&COLLECTION_QUERY_USE_ONLY_WHERE_EXT)) { int need_operator = 0; dt_collection_filter_t rating = collection->params.rating; if(rating == DT_COLLECTION_FILTER_NOT_REJECT) rating = DT_COLLECTION_FILTER_STAR_NO; /* add default filters */ if (collection->params.filter_flags & COLLECTION_FILTER_FILM_ID) { wq = dt_util_dstrcat(wq, "(film_id = %d)", collection->params.film_id); need_operator = 1; } // DON'T SELECT IMAGES MARKED TO BE DELETED. wq = dt_util_dstrcat(wq, " %s (flags & %d) != %d", (need_operator)?"and":((need_operator=1)?"":""), DT_IMAGE_REMOVE, DT_IMAGE_REMOVE); if (collection->params.filter_flags & COLLECTION_FILTER_CUSTOM_COMPARE) wq = dt_util_dstrcat(wq, " %s (flags & 7) %s %d and (flags & 7) != 6", (need_operator)?"and":((need_operator=1)?"":""), comparators[collection->params.comparator], rating - 1); else if (collection->params.filter_flags & COLLECTION_FILTER_ATLEAST_RATING) wq = dt_util_dstrcat(wq, " %s (flags & 7) >= %d and (flags & 7) != 6", (need_operator)?"and":((need_operator=1)?"":""), rating - 1); else if (collection->params.filter_flags & COLLECTION_FILTER_EQUAL_RATING) wq = dt_util_dstrcat(wq, " %s (flags & 7) == %d", (need_operator)?"and":((need_operator=1)?"":""), rating - 1); if (collection->params.filter_flags & COLLECTION_FILTER_ALTERED) wq = dt_util_dstrcat(wq, " %s id in (select imgid from history where imgid=id)", (need_operator)?"and":((need_operator=1)?"":"") ); else if (collection->params.filter_flags & COLLECTION_FILTER_UNALTERED) wq = dt_util_dstrcat(wq, " %s id not in (select imgid from history where imgid=id)", (need_operator)?"and":((need_operator=1)?"":"") ); /* add where ext if wanted */ if ((collection->params.query_flags&COLLECTION_QUERY_USE_WHERE_EXT)) wq = dt_util_dstrcat(wq, " %s %s", (need_operator)?"and":"", collection->where_ext); } else wq = dt_util_dstrcat(wq, "%s", collection->where_ext); /* grouping */ if(darktable.gui && darktable.gui->grouping) { wq = dt_util_dstrcat(wq, " and (group_id = id or group_id = %d)", darktable.gui->expanded_group_id); } /* build select part includes where */ if (collection->params.sort == DT_COLLECTION_SORT_COLOR && (collection->params.query_flags & COLLECTION_QUERY_USE_SORT)) selq = dt_util_dstrcat(selq, "select distinct id from (select * from images where %s) as a left outer join color_labels as b on a.id = b.imgid", wq); else if(collection->params.query_flags&COLLECTION_QUERY_USE_ONLY_WHERE_EXT) selq = dt_util_dstrcat(selq, "select distinct images.id from images %s",wq); else selq = dt_util_dstrcat(selq, "select distinct id from images where %s",wq); /* build sort order part */ if (!(collection->params.query_flags&COLLECTION_QUERY_USE_ONLY_WHERE_EXT) && (collection->params.query_flags&COLLECTION_QUERY_USE_SORT)) { sq = dt_collection_get_sort_query(collection); } /* store the new query */ query = dt_util_dstrcat(query, "%s %s%s", selq, sq?sq:"", (collection->params.query_flags&COLLECTION_QUERY_USE_LIMIT)?" "LIMIT_QUERY:""); result = _dt_collection_store(collection, query); /* free memory used */ g_free(sq); g_free(wq); g_free(selq); g_free (query); /* update the cached count. collection isn't a real const anyway, we are writing to it in _dt_collection_store, too. */ ((dt_collection_t*)collection)->count = _dt_collection_compute_count(collection); dt_collection_hint_message(collection); return result; }