![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
#include <stdio.h>#include <string.h>#include "database/style_repository.h"#include "database/database.h"#include "database/sql_debug.h"#include "system/dtpthread.h"#include "system/macros.h"#include "system/mem_alloc.h"
Include dependency graph for style_repository.c:Go to the source code of this file.
Variables | |
| static sqlite3_stmt * | _styles_get_list_stmt = NULL |
| static sqlite3_stmt * | _styles_apply_items_stmt = NULL |
| static dt_pthread_mutex_t | _styles_stmt_mutex |
| static gsize | _styles_stmt_mutex_inited = 0 |
"num IN (1,2,3)" / "num NOT IN (1,2,3)" for a GList of GINT_TO_POINTER nums.
The callers used to build this with g_strlcat into a 2048-byte buffer, which truncates in silence once a style has enough items – a truncated "num IN (12,3" is not even valid SQL, so the prepare fails and the operation does nothing. A GString has no such cap. Returns NULL for an empty list, which every caller reads as "no filter".
Definition at line 56 of file style_repository.c.
References FALSE, IS_NULL_PTR, and L.
Referenced by dt_style_repository_copy_items_from_history(), dt_style_repository_copy_items_from_style(), and dt_style_repository_delete_items_except().
Definition at line 41 of file style_repository.c.
References _styles_stmt_mutex, _styles_stmt_mutex_inited, dt_pthread_mutex_init(), and L.
Referenced by dt_style_repository_cleanup(), dt_style_repository_foreach_apply_item(), and dt_style_repository_foreach_style().
| void dt_style_repository_append_item_from_history | ( | const int32_t | styleid, |
| const int32_t | imgid, | ||
| const int | history_num | ||
| ) |
append one of an image's history items to the style, numbered after its current last item
Definition at line 580 of file style_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_EXEC, dt_free, and L.
Referenced by _dt_style_update_from_image().
finalise every cached statement. Must run before the connection closes.
Definition at line 712 of file style_repository.c.
References _styles_apply_items_stmt, _styles_get_list_stmt, _styles_stmt_mutex, _styles_stmt_mutex_ensure(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), and L.
Referenced by dt_styles_cleanup(), and testdb_teardown().
| gboolean dt_style_repository_copy_items_from_history | ( | const int32_t | styleid, |
| const int32_t | imgid, | ||
| GList * | nums | ||
| ) |
copy an image's history into a style as items. nums is a GList of history nums to include (as GINT_TO_POINTER); NULL takes the whole history.
Definition at line 443 of file style_repository.c.
References _num_set_predicate(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, FALSE, and L.
Referenced by dt_styles_create_from_image().
| gboolean dt_style_repository_copy_items_from_style | ( | const int32_t | dest_styleid, |
| const int32_t | source_styleid, | ||
| GList * | nums | ||
| ) |
copy another style's items. nums selects which, as above; NULL takes all of them.
Definition at line 490 of file style_repository.c.
References _num_set_predicate(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, FALSE, and L.
Referenced by dt_styles_create_from_style().
| gboolean dt_style_repository_delete | ( | const int32_t | styleid | ) |
delete the header row and every item under it
Definition at line 197 of file style_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, FALSE, L, and TRUE.
Referenced by dt_styles_delete_by_name_adv().
drop every item whose num is NOT in nums
Definition at line 537 of file style_repository.c.
References _num_set_predicate(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, FALSE, IS_NULL_PTR, L, and TRUE.
Referenced by dt_styles_update().
| void dt_style_repository_foreach_apply_item | ( | const int32_t | styleid, |
| dt_style_repository_item_cb | cb, | ||
| void * | user_data | ||
| ) |
every item of the style with its parameter blobs, ordered (num, operation, multi_priority) – the order applying a style walks them in
Definition at line 272 of file style_repository.c.
References _styles_apply_items_stmt, _styles_stmt_mutex, _styles_stmt_mutex_ensure(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), IS_NULL_PTR, and L.
Referenced by _dt_styles_get_apply_items().
| void dt_style_repository_foreach_item | ( | const int32_t | styleid, |
| dt_style_repository_item_cb | cb, | ||
| void * | user_data | ||
| ) |
every item of the style, no blobs, highest num first – for listing it in the GUI.
NOTE this query selects only 8 columns, so there is no blendop_version/iop_order column at all; both come back 0, which is what the original read out of range. Preserved verbatim.
Definition at line 368 of file style_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, IS_NULL_PTR, and L.
Referenced by dt_styles_get_item_list().
| void dt_style_repository_foreach_item_against_image | ( | const int32_t | styleid, |
| const int32_t | imgid, | ||
| dt_style_repository_item_cb | cb, | ||
| void * | user_data | ||
| ) |
the style's items UNION the image's own enabled history items that the style does not cover, so the GUI can show what applying it would replace and what it would add. No blobs; each row carries selimg_num.
Definition at line 397 of file style_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, IS_NULL_PTR, and L.
Referenced by dt_styles_get_item_list().
| void dt_style_repository_foreach_item_for_export | ( | const int32_t | styleid, |
| dt_style_repository_item_cb | cb, | ||
| void * | user_data | ||
| ) |
every item of the style with its parameter blobs, in whatever order SQLite returns them – writing a style to its .dtstyle file, which restores by num and does not depend on the order. Deliberately a separate query from foreach_apply_item(): same columns, no ORDER BY.
Definition at line 311 of file style_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, IS_NULL_PTR, and L.
Referenced by dt_styles_save_to_file().
| void dt_style_repository_foreach_item_with_params | ( | const int32_t | styleid, |
| dt_style_repository_item_cb | cb, | ||
| void * | user_data | ||
| ) |
every item of the style with its parameter blobs, highest num first.
NOTE this query selects blendop_version as its last column and the original read that same column BOTH as blendop_version (int) and as iop_order (double). Preserved verbatim: the callback receives it twice, once each way.
Definition at line 338 of file style_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, IS_NULL_PTR, and L.
Referenced by dt_styles_get_item_list().
| void dt_style_repository_foreach_style | ( | const char * | filter, |
| dt_style_repository_style_cb | cb, | ||
| void * | user_data | ||
| ) |
every style whose name or description matches filter (a bare substring – this module wraps it in the LIKE wildcards), in name order
Definition at line 221 of file style_repository.c.
References _styles_get_list_stmt, _styles_stmt_mutex, _styles_stmt_mutex_ensure(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), IS_NULL_PTR, and L.
Referenced by dt_styles_get_list().
| char * dt_style_repository_get_description | ( | const int32_t | styleid | ) |
the style's description, or NULL. Caller owns it. NULL means either "no such style" or "the description column is NULL" – the two are not distinguishable here, and never were.
Definition at line 92 of file style_repository.c.
References description(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by dt_styles_get_description().
| int32_t dt_style_repository_get_id_by_name | ( | const char * | name | ) |
data.styles and data.style_items, plus the reads and writes of main.history that copy a development into a style and back.
Nothing here returns a dt_style_t or a dt_style_item_t. Those live in common/styles.h, which includes three develop/ headers to declare dt_iop_params_t and dt_develop_blend_params_t – four layers above this one. Rows are handed to a callback as scalars and common/styles.c builds the structs, which is also where a module's localized name has to come from (dt_iop_get_localized_name(), same layer problem).
A row callback runs while this module holds its statement mutex, so a callback must not call back into this repository. In practice they only build a list.
The iop_list column crosses the same boundary: this module stores and returns it as the TEXT it is, and styles.c serialises it through dt_ioppr_*. the id of the newest style with this name, or 0 if there is none
Definition at line 74 of file style_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, IS_NULL_PTR, L, and name.
Referenced by dt_styles_get_id_by_name().
| char * dt_style_repository_get_iop_list | ( | const char * | name | ) |
the style's iop_list column as stored, or NULL when the style has none (or does not exist). That is also the answer to "does this style carry a module order?". Caller owns it.
Definition at line 108 of file style_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, IS_NULL_PTR, L, and name.
Referenced by dt_styles_has_module_order(), and dt_styles_module_order_list().
| gboolean dt_style_repository_get_style | ( | const char * | name, |
| dt_style_repository_style_cb | cb, | ||
| void * | user_data | ||
| ) |
the one style with this exact name; FALSE if there is none
Definition at line 249 of file style_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, FALSE, IS_NULL_PTR, L, name, and TRUE.
Referenced by dt_styles_get_by_name().
| gboolean dt_style_repository_insert_header | ( | const char * | name, |
| const char * | description, | ||
| const char * | iop_list_txt | ||
| ) |
insert a header row, taking the next free id. iop_list_txt may be NULL.
Definition at line 131 of file style_repository.c.
References description(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, FALSE, IS_NULL_PTR, L, and name.
Referenced by dt_styles_create_style_header().
| gboolean dt_style_repository_insert_item | ( | const int32_t | styleid, |
| const int | num, | ||
| const int | module_version, | ||
| const char * | operation, | ||
| const void * | params, | ||
| const int32_t | params_size, | ||
| const int | enabled, | ||
| const void * | blendop_params, | ||
| const int32_t | blendop_params_size, | ||
| const int | blendop_version, | ||
| const int | multi_priority, | ||
| const char * | multi_name | ||
| ) |
insert one fully specified item – what reading a style back from its XML file does
Definition at line 606 of file style_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_BLOB, DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, FALSE, L, and params_size().
Referenced by dt_style_plugin_save().
| gboolean dt_style_repository_normalize_multi_priority | ( | const int32_t | styleid | ) |
give every item a unique multi_priority per operation, numbered from 0 in multi_priority order. SQLite has no ROW_NUMBER, so this reads the rows and writes them back one by one.
Definition at line 641 of file style_repository.c.
References d, dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, dt_free_gpointer(), FALSE, L, and TRUE.
Referenced by dt_styles_create_from_image(), dt_styles_create_from_style(), and dt_styles_update().
replace a style's module order; a NULL iop_list_txt clears the column
Definition at line 157 of file style_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, FALSE, and L.
Referenced by _dt_style_update_iop_order().
| gboolean dt_style_repository_update_header | ( | const int32_t | styleid, |
| const char * | newname, | ||
| const char * | description | ||
| ) |
rename and re-describe an existing style
Definition at line 181 of file style_repository.c.
References description(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, FALSE, and L.
Referenced by dt_styles_update().
| void dt_style_repository_update_item_from_history | ( | const int32_t | styleid, |
| const int | item_num, | ||
| const int32_t | imgid, | ||
| const int | history_num | ||
| ) |
overwrite one style item from one of an image's history items.
These two are the only writes here that interpolate their integers into the query text rather than binding them, because that is what the originals did and a move is the wrong place to rewrite a query. They go through sqlite3_exec(), which reports nothing back, hence void. Every interpolated value is an int, so there is nothing to escape.
Definition at line 556 of file style_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_EXEC, dt_free, FALSE, k, and L.
Referenced by _dt_style_update_from_image().
|
static |
Definition at line 37 of file style_repository.c.
Referenced by dt_style_repository_cleanup(), and dt_style_repository_foreach_apply_item().
|
static |
Definition at line 36 of file style_repository.c.
Referenced by dt_style_repository_cleanup(), and dt_style_repository_foreach_style().
|
static |
Definition at line 38 of file style_repository.c.
Referenced by _styles_stmt_mutex_ensure(), dt_style_repository_cleanup(), dt_style_repository_foreach_apply_item(), and dt_style_repository_foreach_style().
|
static |
Definition at line 39 of file style_repository.c.
Referenced by _styles_stmt_mutex_ensure().