static void update(dt_lib_module_t *user_data, gboolean early_bark_out) { // early_bark_out = FALSE; // FIXME: when barking out early we don't update on ctrl-a/ctrl-shift-a. but // otherwise it's impossible to edit text const dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_metadata_t *d = (dt_lib_metadata_t *)self->data; const int imgsel = dt_control_get_mouse_over_id(); if(early_bark_out && imgsel == d->imgsel) return; d->imgsel = imgsel; sqlite3_stmt *stmt; GList *title = NULL; uint32_t title_count = 0; GList *description = NULL; uint32_t description_count = 0; GList *creator = NULL; uint32_t creator_count = 0; GList *publisher = NULL; uint32_t publisher_count = 0; GList *rights = NULL; uint32_t rights_count = 0; // using dt_metadata_get() is not possible here. we want to do all this in a single pass, everything else // takes ages. if(imgsel < 0) // selected images { DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT key, value FROM main.meta_data WHERE id IN " "(SELECT imgid FROM main.selected_images) GROUP BY " "key, value ORDER BY value", -1, &stmt, NULL); } else // single image under mouse cursor { DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT key, value FROM main.meta_data " "WHERE id = ?1 GROUP BY key, value ORDER BY value", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgsel); } while(sqlite3_step(stmt) == SQLITE_ROW) { if(sqlite3_column_bytes(stmt, 1)) { char *value = g_strdup((char *)sqlite3_column_text(stmt, 1)); switch(sqlite3_column_int(stmt, 0)) { case DT_METADATA_XMP_DC_CREATOR: creator_count++; creator = g_list_append(creator, value); break; case DT_METADATA_XMP_DC_PUBLISHER: publisher_count++; publisher = g_list_append(publisher, value); break; case DT_METADATA_XMP_DC_TITLE: title_count++; title = g_list_append(title, value); break; case DT_METADATA_XMP_DC_DESCRIPTION: description_count++; description = g_list_append(description, value); break; case DT_METADATA_XMP_DC_RIGHTS: rights_count++; rights = g_list_append(rights, value); break; } } } sqlite3_finalize(stmt); fill_combo_box_entry(d->title, title_count, title, &(d->multi_title)); fill_combo_box_entry(d->description, description_count, description, &(d->multi_description)); fill_combo_box_entry(d->rights, rights_count, rights, &(d->multi_rights)); fill_combo_box_entry(d->creator, creator_count, creator, &(d->multi_creator)); fill_combo_box_entry(d->publisher, publisher_count, publisher, &(d->multi_publisher)); g_list_free_full(title, g_free); g_list_free_full(description, g_free); g_list_free_full(creator, g_free); g_list_free_full(publisher, g_free); g_list_free_full(rights, g_free); }
static void update(dt_lib_module_t *user_data, gboolean early_bark_out) { // early_bark_out = FALSE; // FIXME: when barking out early we don't update on ctrl-a/ctrl-shift-a. but otherwise it's impossible to edit text dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_metadata_t *d = (dt_lib_metadata_t *)self->data; int imgsel = dt_control_get_mouse_over_id(); if(early_bark_out && imgsel == d->imgsel) return; d->imgsel = imgsel; sqlite3_stmt *stmt; GList *title = NULL; uint32_t title_count = 0; GList *description = NULL; uint32_t description_count = 0; GList *creator = NULL; uint32_t creator_count = 0; GList *publisher = NULL; uint32_t publisher_count = 0; GList *rights = NULL; uint32_t rights_count = 0; // using dt_metadata_get() is not possible here. we want to do all this in a single pass, everything else takes ages. if(imgsel < 0) // selected images { DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select key, value from meta_data where id in (select imgid from selected_images) group by key, value order by value", -1, &stmt, NULL); } else // single image under mouse cursor { char query[1024]; snprintf(query, 1024, "select key, value from meta_data where id = %d group by key, value order by value", imgsel); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), query, -1, &stmt, NULL); } while(sqlite3_step(stmt) == SQLITE_ROW) { char *value = g_strdup((char *)sqlite3_column_text(stmt, 1)); if(sqlite3_column_bytes(stmt,1)) { switch(sqlite3_column_int(stmt, 0)) { case DT_METADATA_XMP_DC_CREATOR: creator_count++; creator = g_list_append(creator, value); break; case DT_METADATA_XMP_DC_PUBLISHER: publisher_count++; publisher = g_list_append(publisher, value); break; case DT_METADATA_XMP_DC_TITLE: title_count++; title = g_list_append(title, value); break; case DT_METADATA_XMP_DC_DESCRIPTION: description_count++; description = g_list_append(description, value); break; case DT_METADATA_XMP_DC_RIGHTS: rights_count++; rights = g_list_append(rights, value); break; } } } sqlite3_finalize(stmt); fill_combo_box_entry(&(d->title), title_count, &title, &(d->multi_title)); fill_combo_box_entry(&(d->description), description_count, &description, &(d->multi_description)); fill_combo_box_entry(&(d->rights), rights_count, &rights, &(d->multi_rights)); fill_combo_box_entry(&(d->creator), creator_count, &creator, &(d->multi_creator)); fill_combo_box_entry(&(d->publisher), publisher_count, &publisher, &(d->multi_publisher)); g_list_free(g_list_first(title)); g_list_free(g_list_first(description)); g_list_free(g_list_first(creator)); g_list_free(g_list_first(publisher)); g_list_free(g_list_first(rights)); }