60#define DT_IOP_ORDER_INFO (darktable.unmuted & DT_DEBUG_IOPORDER)
106 image->
flags &= ~DT_IMAGE_AUTO_PRESETS_APPLIED;
125 "DELETE FROM main.history WHERE imgid = ?1",
129 sqlite3_finalize(stmt);
132 "DELETE FROM main.module_order WHERE imgid = ?1",
136 sqlite3_finalize(stmt);
141 " SET history_end = 0, aspect_ratio = 0.0"
147 sqlite3_finalize(stmt);
150 "DELETE FROM main.masks_history WHERE imgid = ?1",
154 sqlite3_finalize(stmt);
157 "DELETE FROM main.history_hash WHERE imgid = ?1",
161 sqlite3_finalize(stmt);
195 return g_strconcat(enabled ?
"\342\227\217" :
"\342\227\213",
" ",
name, NULL);
200 GList *result = NULL;
205 "SELECT num, operation, enabled, multi_name"
208 " AND num IN (SELECT MAX(num)"
209 " FROM main.history hst2"
210 " WHERE hst2.imgid=?1"
211 " AND hst2.operation=main.history.operation"
212 " GROUP BY multi_priority)"
213 " AND enabled in (1, ?2)"
214 " ORDER BY num DESC",
220 while(sqlite3_step(stmt) == SQLITE_ROW)
222 if(strcmp((
const char*)sqlite3_column_text(stmt, 1),
"mask_manager") == 0)
continue;
224 char name[512] = { 0 };
226 const char *op = (
char *)sqlite3_column_text(stmt, 1);
227 item->
num = sqlite3_column_int(stmt, 0);
228 item->
enabled = sqlite3_column_int(stmt, 2);
230 char *mname = g_strdup((gchar *)sqlite3_column_text(stmt, 3));
232 if(strcmp(mname,
"0") == 0)
235 g_snprintf(
name,
sizeof(
name),
"%s %s",
237 (
char *)sqlite3_column_text(stmt, 3));
239 item->
op = g_strdup(op);
240 result = g_list_prepend(result, item);
244 sqlite3_finalize(stmt);
245 return g_list_reverse(result);
255 "SELECT operation, enabled, multi_name"
257 " WHERE imgid=?1 ORDER BY num DESC", -1, &stmt, NULL);
262 while(sqlite3_step(stmt) == SQLITE_ROW)
264 char *multi_name = NULL;
265 const char *mn = (
char *)sqlite3_column_text(stmt, 2);
267 if(mn && *mn && g_strcmp0(mn,
" ") != 0 && g_strcmp0(mn,
"0") != 0)
268 multi_name = g_strconcat(
" ", sqlite3_column_text(stmt, 2), NULL);
272 sqlite3_column_int(stmt, 1));
274 char *
name = g_strconcat(iname, multi_name ? multi_name :
"", NULL);
282 sqlite3_finalize(stmt);
292 gboolean result =
FALSE;
302 " WHERE imgid= ?1 AND operation = ?2",
308 sqlite3_clear_bindings(stmt);
311 if (sqlite3_step(stmt) == SQLITE_ROW) result =
TRUE;
401 if(imgid <= 0)
return 0;
409 "SELECT history_end FROM main.images WHERE id=?1", -1,
414 sqlite3_clear_bindings(stmt);
416 if(sqlite3_step(stmt) == SQLITE_ROW && sqlite3_column_type(stmt, 0) != SQLITE_NULL)
417 end = sqlite3_column_int(stmt, 0);
425 if(imgid <= 0)
return FALSE;
432 "UPDATE main.images SET history_end = ?1 WHERE id = ?2", -1,
437 sqlite3_clear_bindings(stmt);
440 const gboolean ok = (sqlite3_step(stmt) == SQLITE_DONE);
447 if(imgid <= 0)
return 0;
449 int32_t next_num = 0;
456 "SELECT IFNULL(MAX(num)+1, 0) FROM main.history"
463 sqlite3_clear_bindings(stmt);
465 if(sqlite3_step(stmt) == SQLITE_ROW)
466 next_num = sqlite3_column_int(stmt, 0);
473 if(imgid <= 0)
return FALSE;
479 "DELETE FROM main.history WHERE imgid = ?1", -1,
483 sqlite3_clear_bindings(stmt);
485 const gboolean ok = (sqlite3_step(stmt) == SQLITE_DONE);
492 if(imgid <= 0)
return FALSE;
498 "DELETE FROM main.masks_history WHERE imgid = ?1", -1,
502 sqlite3_clear_bindings(stmt);
504 const gboolean ok = (sqlite3_step(stmt) == SQLITE_DONE);
511 if(imgid <= 0 ||
delta == 0)
return TRUE;
518 "UPDATE main.history SET num = num + ?2 WHERE imgid = ?1", -1,
523 sqlite3_clear_bindings(stmt);
526 const gboolean ok = (sqlite3_step(stmt) == SQLITE_DONE);
533 if(imgid <= 0)
return FALSE;
541 const int op_params_size,
const int module_version,
const gboolean enabled,
542 const void *blendop_params,
const int blendop_params_size,
543 const int blendop_version,
const int multi_priority,
const char *multi_name)
554 "SELECT num FROM main.history WHERE imgid = ?1 AND num = ?2", -1,
558 sqlite3_clear_bindings(stmt);
561 if(sqlite3_step(stmt) != SQLITE_ROW)
565 "INSERT INTO main.history (imgid, num) VALUES (?1, ?2)", -1,
569 sqlite3_clear_bindings(stmt);
572 ok &= (sqlite3_step(stmt) == SQLITE_DONE);
578 "UPDATE main.history"
579 " SET operation = ?1, op_params = ?2, module = ?3, enabled = ?4, "
580 " blendop_params = ?7, blendop_version = ?8, multi_priority = ?9, multi_name = ?10"
581 " WHERE imgid = ?5 AND num = ?6",
586 sqlite3_clear_bindings(stmt);
597 ok &= (sqlite3_step(stmt) == SQLITE_DONE);
613 "SELECT imgid, num, module, operation,"
614 " op_params, enabled, blendop_params,"
615 " blendop_version, multi_priority, multi_name"
625 sqlite3_clear_bindings(stmt);
628 while(sqlite3_step(stmt) == SQLITE_ROW)
630 const int32_t
id = sqlite3_column_int(stmt, 0);
631 const int num = sqlite3_column_int(stmt, 1);
632 const int modversion = sqlite3_column_int(stmt, 2);
633 const char *operation = (
const char *)sqlite3_column_text(stmt, 3);
634 const void *module_params = sqlite3_column_blob(stmt, 4);
635 const gboolean enabled = sqlite3_column_int(stmt, 5) != 0;
636 const void *blendop_params = sqlite3_column_blob(stmt, 6);
637 const int blendop_version = sqlite3_column_int(stmt, 7);
638 const int multi_priority = sqlite3_column_int(stmt, 8);
639 const char *multi_name = (
const char *)sqlite3_column_text(stmt, 9);
640 const int param_length = sqlite3_column_bytes(stmt, 4);
641 const int bl_length = sqlite3_column_bytes(stmt, 6);
643 cb(user_data,
id, num, modversion, operation, module_params, param_length, enabled,
644 blendop_params, bl_length, blendop_version, multi_priority, multi_name,
"");
662 const char *table = use_modern_presets ?
"data.presets" :
"main.legacy_presets";
665 char *query = g_strdup_printf(
666 " SELECT ?1, 0, op_version, operation, op_params,"
667 " enabled, blendop_params, blendop_version, multi_priority, multi_name, name"
669 " WHERE ( (autoapply=1"
670 " AND ((?2 LIKE model AND ?3 LIKE maker) OR (?4 LIKE model AND ?5 LIKE maker))"
671 " AND ?6 LIKE lens AND ?7 BETWEEN iso_min AND iso_max"
672 " AND ?8 BETWEEN exposure_min AND exposure_max"
673 " AND ?9 BETWEEN aperture_min AND aperture_max"
674 " AND ?10 BETWEEN focal_length_min AND focal_length_max"
675 " AND (format = 0 OR (format & ?11 != 0 AND ~format & ?12 != 0)))"
677 " AND operation NOT IN"
678 " ('ioporder', 'metadata', 'modulegroups', 'export', 'tagging', 'collect', 'basecurve')"
679 " ORDER BY writeprotect DESC, LENGTH(model), LENGTH(maker), LENGTH(lens)",
687 sqlite3_stmt *stmt = *stmt_ptr;
689 sqlite3_clear_bindings(stmt);
704 while(sqlite3_step(stmt) == SQLITE_ROW)
706 const int32_t
id = sqlite3_column_int(stmt, 0);
707 const int num = sqlite3_column_int(stmt, 1);
708 const int modversion = sqlite3_column_int(stmt, 2);
709 const char *operation = (
const char *)sqlite3_column_text(stmt, 3);
710 const void *module_params = sqlite3_column_blob(stmt, 4);
711 const int enabled = sqlite3_column_int(stmt, 5);
712 const void *blendop_params = sqlite3_column_blob(stmt, 6);
713 const int blendop_version = sqlite3_column_int(stmt, 7);
714 const int multi_priority = sqlite3_column_int(stmt, 8);
715 const char *multi_name = (
const char *)sqlite3_column_text(stmt, 9);
716 const char *preset_name = (
const char *)sqlite3_column_text(stmt, 10);
717 const int param_length = sqlite3_column_bytes(stmt, 4);
718 const int bl_length = sqlite3_column_bytes(stmt, 6);
720 cb(user_data,
id, num, modversion, operation, module_params, param_length, enabled,
721 blendop_params, bl_length, blendop_version, multi_priority, multi_name, preset_name);
728 const int iformat,
const int excluded,
void **params,
745 " AND ((?2 LIKE model AND ?3 LIKE maker) OR (?4 LIKE model AND ?5 LIKE maker))"
746 " AND ?6 LIKE lens AND ?7 BETWEEN iso_min AND iso_max"
747 " AND ?8 BETWEEN exposure_min AND exposure_max"
748 " AND ?9 BETWEEN aperture_min AND aperture_max"
749 " AND ?10 BETWEEN focal_length_min AND focal_length_max"
750 " AND (format = 0 OR (format & ?11 != 0 AND ~format & ?12 != 0))"
751 " AND operation = 'ioporder'"
752 " ORDER BY writeprotect DESC, LENGTH(model), LENGTH(maker), LENGTH(lens)",
759 sqlite3_clear_bindings(stmt);
774 if(sqlite3_step(stmt) == SQLITE_ROW)
776 const void *blob = sqlite3_column_blob(stmt, 0);
777 const int32_t blob_len = sqlite3_column_bytes(stmt, 0);
778 if(blob && blob_len > 0)
780 *params = g_malloc(blob_len);
781 memcpy(*params, blob, blob_len);
782 *params_len = blob_len;
791#undef DT_IOP_ORDER_INFO
static sqlite3_stmt * _history_check_module_exists_stmt
static sqlite3_stmt * _history_select_history_stmt
char * dt_history_get_items_as_string(const int32_t imgid)
static sqlite3_stmt * _history_get_next_num_stmt
static sqlite3_stmt * _history_update_item_stmt
static void _history_stmt_mutex_ensure(void)
char * dt_history_item_as_string(const char *name, gboolean enabled)
static gsize _history_stmt_mutex_inited
static sqlite3_stmt * _history_hash_set_mipmap_stmt
gboolean dt_history_check_module_exists(int32_t imgid, const char *operation, gboolean enabled)
gboolean dt_history_set_end(const int32_t imgid, const int32_t history_end)
gboolean dt_history_db_write_history_item(const int32_t imgid, const int num, const char *operation, const void *op_params, const int op_params_size, const int module_version, const gboolean enabled, const void *blendop_params, const int blendop_params_size, const int blendop_version, const int multi_priority, const char *multi_name)
static sqlite3_stmt * _history_shift_history_nums_stmt
gboolean dt_history_db_shift_history_nums(const int32_t imgid, const int delta)
static sqlite3_stmt * _history_delete_history_stmt
static sqlite3_stmt * _history_insert_num_stmt
static sqlite3_stmt * _history_auto_presets_legacy_stmt
gboolean dt_history_db_get_autoapply_ioporder_params(const int32_t imgid, const dt_image_t *image, const int iformat, const int excluded, void **params, int32_t *params_len)
int32_t dt_history_db_get_next_history_num(const int32_t imgid)
static sqlite3_stmt * _history_delete_masks_stmt
gboolean dt_history_db_delete_masks_history(const int32_t imgid)
void dt_history_db_foreach_auto_preset_row(const int32_t imgid, const dt_image_t *image, const char *workflow_preset, const int iformat, const int excluded, dt_history_db_row_cb cb, void *user_data)
void dt_history_cleanup(void)
int32_t dt_history_get_end(const int32_t imgid)
void dt_history_delete_on_image_ext(int32_t imgid, gboolean undo)
gboolean dt_history_db_delete_dev_history(const int32_t imgid)
static sqlite3_stmt * _history_set_end_stmt
static sqlite3_stmt * _history_auto_ioporder_stmt
GList * dt_history_get_items(const int32_t imgid, gboolean enabled)
static sqlite3_stmt * _history_get_end_stmt
static dt_pthread_mutex_t _history_stmt_mutex
static void _remove_preset_flag(const int32_t imgid)
void dt_history_delete_on_image(int32_t imgid)
void dt_history_item_free(gpointer data)
static sqlite3_stmt * _history_select_num_stmt
gboolean dt_history_db_delete_history(const int32_t imgid)
void dt_history_db_foreach_history_row(const int32_t imgid, dt_history_db_row_cb cb, void *user_data)
static sqlite3_stmt * _history_auto_presets_stmt
static void dt_free_gpointer(gpointer ptr)
static gchar * delete_underscore(const char *s)
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
sqlite3 * dt_database_get(const dt_database_t *db)
#define DT_DEBUG_SQLITE3_BIND_BLOB(a, b, c, d, e)
#define DT_DEBUG_SQLITE3_PREPARE_V2(a, b, c, d, e)
#define DT_DEBUG_SQLITE3_BIND_TEXT(a, b, c, d, e)
#define DT_DEBUG_SQLITE3_BIND_INT(a, b, c)
#define DT_DEBUG_SQLITE3_BIND_DOUBLE(a, b, c)
static int dt_pthread_mutex_unlock(dt_pthread_mutex_t *mutex) RELEASE(mutex) NO_THREAD_SAFETY_ANALYSIS
static int dt_pthread_mutex_init(dt_pthread_mutex_t *mutex, const pthread_mutexattr_t *mutexattr)
static int dt_pthread_mutex_lock(dt_pthread_mutex_t *mutex) ACQUIRE(mutex) NO_THREAD_SAFETY_ANALYSIS
const dt_collection_sort_t items[]
void(* dt_history_db_row_cb)(void *user_data, const int32_t imgid, const int num, const int module_version, const char *operation, const void *op_params, const int op_params_len, const gboolean enabled, const void *blendop_params, const int blendop_params_len, const int blendop_version, const int multi_priority, const char *multi_name, const char *preset_name)
void dt_history_snapshot_undo_create(const int32_t imgid, int *snap_id, int *history_end)
void dt_history_snapshot_undo_lt_history_data_free(gpointer data)
dt_undo_lt_history_t * dt_history_snapshot_item_init(void)
void dt_history_snapshot_undo_pop(gpointer user_data, dt_undo_type_t type, dt_undo_data_t data, dt_undo_action_t action, GList **imgs)
@ DT_IMAGE_NO_LEGACY_PRESETS
dt_image_t * dt_image_cache_get(dt_image_cache_t *cache, const int32_t imgid, char mode)
void dt_image_cache_write_release(dt_image_cache_t *cache, dt_image_t *img, dt_image_cache_write_mode_t mode)
const gchar * dt_iop_get_localized_name(const gchar *op)
void dt_mipmap_cache_remove(dt_mipmap_cache_t *cache, const int32_t imgid, const gboolean flush_disk)
#define DT_DEBUG_CONTROL_SIGNAL_RAISE(ctlsig, signal,...)
@ DT_SIGNAL_TAG_CHANGED
This signal is raised when a tag is added/deleted/changed
struct dt_gui_gtk_t * gui
struct dt_mipmap_cache_t * mipmap_cache
const struct dt_database_t * db
struct dt_control_signal_t * signals
struct dt_image_cache_t * image_cache
dt_thumbtable_t * thumbtable_lighttable
dt_thumbtable_t * thumbtable_filmstrip
#define dt_thumbtable_refresh_thumbnail(table, imgid, reinit)
void dt_undo_end_group(dt_undo_t *self)
void dt_undo_start_group(dt_undo_t *self, dt_undo_type_t type)
void dt_undo_record(dt_undo_t *self, gpointer user_data, dt_undo_type_t type, dt_undo_data_t data, void(*undo)(gpointer user_data, dt_undo_type_t type, dt_undo_data_t item, dt_undo_action_t action, GList **imgs), void(*free_data)(gpointer data))
gchar * dt_util_glist_to_str(const gchar *separator, GList *items)