For feature #10369 <https://redmine.darktable.org/issues/10369>, I have something that appears to work and am seeking feedback before creating a pull request.
When calling dt_collection_image_offset from within dt_collection_hint_message, it appears that darktable.collection is not available for use. As a result, an similar function, dt_collection_image_offset_with_collection, has been added (with the associated code duplication) for this purpose. One alternative would change dt_collection_image_offset to what is currently dt_collection_image_offset_with_collection so that dt_collection_image_offset will not expect that darktable.collection will always be available (unlike darktable.db?) and operate on the collection that is specified, similar to other functions in common/collections.h. Downstream changes will need to be made to accommodate this change. Other options/feedback? Thanks! Proposed edits to src/common/collections.h: /** returns the image offset in the specified collection **/ int dt_collection_image_offset_with_collection(const dt_collection_t *collection, int imgid); Proposed edits to src/common/collections.c: void dt_collection_hint_message(const dt_collection_t *collection) { /* if relevant, determine offset of selection */ GList *selected_imgids = dt_collection_get_selected(collection, 1); int selected_imgids_count = g_list_length(selected_imgids); int selected = -1; if(selected_imgids_count > 0) { selected = GPOINTER_TO_INT(g_list_nth_data(selected_imgids,0)); selected = dt_collection_image_offset_with_collection(collection, selected); selected++; } /* collection hinting */ gchar message[1024]; int c = dt_collection_get_count(collection); int cs = dt_collection_get_selected_count(collection); g_snprintf(message, sizeof(message), ngettext("%d image of %d (#%d) in current collection is selected", "%d images of %d in current collection are selected", cs), cs, c, selected); dt_control_hinter_message(darktable.control, message); } int dt_collection_image_offset_with_collection(const dt_collection_t *collection, int imgid) { const gchar *qin = dt_collection_get_query(collection); int offset = 0; sqlite3_stmt *stmt; if(qin) { DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), qin, -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, 0); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, -1); gboolean found = FALSE; while(sqlite3_step(stmt) == SQLITE_ROW) { int id = sqlite3_column_int(stmt, 0); if(imgid == id) { found = TRUE; break; } offset++; } if(!found) offset = 0; sqlite3_finalize(stmt); } return offset; } ___________________________________________________________________________ darktable developer mailing list to unsubscribe send a mail to darktable-dev+unsubscr...@lists.darktable.org