void dt_selection_select_unaltered(dt_selection_t *selection) { char *fullq = NULL; if (!selection->collection) return; /* set unaltered collection filter and update query */ uint32_t old_filter_flags = dt_collection_get_filter_flags(selection->collection); dt_collection_set_filter_flags (selection->collection, (dt_collection_get_filter_flags(selection->collection) | COLLECTION_FILTER_UNALTERED)); dt_collection_update(selection->collection); fullq = dt_util_dstrcat(fullq, "%s", "insert or ignore into selected_images "); fullq = dt_util_dstrcat(fullq, "%s", dt_collection_get_query(selection->collection)); /* clean current selection and select unaltered images */ DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "delete from selected_images", NULL, NULL, NULL); DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), fullq, NULL, NULL, NULL); /* restore collection filter and update query */ dt_collection_set_filter_flags(selection->collection, old_filter_flags); dt_collection_update(selection->collection); g_free(fullq); selection->last_single_id = -1; }
static void _lib_filter_combobox_changed(GtkComboBox *widget, gpointer user_data) { /* update last settings */ int i = gtk_combo_box_get_active(widget); /* update collection star filter flags */ if(i == 0) // all dt_collection_set_filter_flags(darktable.collection, dt_collection_get_filter_flags(darktable.collection) & ~(COLLECTION_FILTER_ATLEAST_RATING | COLLECTION_FILTER_EQUAL_RATING | COLLECTION_FILTER_CUSTOM_COMPARE)); else if(i == 1 || i == 7) // unstarred only || rejected only dt_collection_set_filter_flags( darktable.collection, (dt_collection_get_filter_flags(darktable.collection) | COLLECTION_FILTER_EQUAL_RATING) & ~(COLLECTION_FILTER_ATLEAST_RATING | COLLECTION_FILTER_CUSTOM_COMPARE)); else if(i == 8) // all except rejected dt_collection_set_filter_flags(darktable.collection, (dt_collection_get_filter_flags(darktable.collection) | COLLECTION_FILTER_ATLEAST_RATING) & ~COLLECTION_FILTER_CUSTOM_COMPARE); else // explicit stars dt_collection_set_filter_flags(darktable.collection, dt_collection_get_filter_flags(darktable.collection) | COLLECTION_FILTER_CUSTOM_COMPARE); /* set the star filter in collection */ dt_collection_set_rating(darktable.collection, i); dt_control_set_mouse_over_id(-1); // may me I'm storing mouse_over_id (arrows) /* update the gui accordingly */ _lib_filter_sync_combobox_and_comparator(user_data); /* update the query and view */ _lib_filter_update_query(user_data); }
void dt_collection_update_query(const dt_collection_t *collection) { char query[1024], confname[200]; gchar *complete_query = NULL; const int _n_r = dt_conf_get_int("plugins/lighttable/collect/num_rules"); const int num_rules = CLAMP(_n_r, 1, 10); char *conj[] = {"and", "or", "and not"}; complete_query = dt_util_dstrcat(complete_query, "("); for(int i=0; i<num_rules; i++) { snprintf(confname, sizeof(confname), "plugins/lighttable/collect/item%1d", i); const int property = dt_conf_get_int(confname); snprintf(confname, sizeof(confname), "plugins/lighttable/collect/string%1d", i); gchar *text = dt_conf_get_string(confname); if(!text) break; snprintf(confname, sizeof(confname), "plugins/lighttable/collect/mode%1d", i); const int mode = dt_conf_get_int(confname); gchar *escaped_text = dt_util_str_replace(text, "'", "''"); get_query_string(property, escaped_text, query, sizeof(query)); if(i > 0) complete_query = dt_util_dstrcat(complete_query, " %s %s", conj[mode], query); else complete_query = dt_util_dstrcat(complete_query, "%s", query); g_free(escaped_text); g_free(text); } complete_query = dt_util_dstrcat(complete_query, ")"); // printf("complete query: `%s'\n", complete_query); /* set the extended where and the use of it in the query */ dt_collection_set_extended_where (collection, complete_query); dt_collection_set_query_flags (collection, (dt_collection_get_query_flags (collection) | COLLECTION_QUERY_USE_WHERE_EXT)); /* remove film id from default filter */ dt_collection_set_filter_flags (collection, (dt_collection_get_filter_flags (collection) & ~COLLECTION_FILTER_FILM_ID)); /* update query and at last the visual */ dt_collection_update (collection); /* free string */ g_free(complete_query); // remove from selected images where not in this query. sqlite3_stmt *stmt = NULL; const gchar *cquery = dt_collection_get_query(collection); complete_query = NULL; if(cquery && cquery[0] != '\0') { complete_query = dt_util_dstrcat(complete_query, "delete from selected_images where imgid not in (%s)", cquery); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), complete_query, -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, 0); DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, -1); sqlite3_step(stmt); sqlite3_finalize(stmt); /* free allocated strings */ g_free(complete_query); } /* raise signal of collection change, only if this is an original */ if (!collection->clone) dt_control_signal_raise(darktable.signals, DT_SIGNAL_COLLECTION_CHANGED); }