![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
#include "database/tag_repository.h"#include "database/database.h"#include "database/sql_debug.h"#include "system/macros.h"#include "system/mem_alloc.h"#include <sqlite3.h>
Include dependency graph for tag_repository.c:Go to the source code of this file.
Functions | |
| GList * | dt_tag_repository_get_attached_names (const int32_t imgid) |
| Names of the tags attached to an image. | |
| void | dt_tag_count_free (gpointer data) |
Release one dt_tag_count_t, name included. Suits g_list_free_full(). | |
| GList * | dt_tag_repository_get_by_path_with_counts (const char *path, const char *path_prefix) |
Tags at path or below it, each with the number of distinct images carrying it. | |
| static guint | _first_id_for_text (const char *query, const char *value) |
| static void | _run_for_id (const char *query, const guint id) |
| guint | dt_tag_repository_find_by_name (const char *name) |
The id of the tag named name, or 0 when there is none. | |
| guint | dt_tag_repository_find_by_name_nocase (const char *name) |
The id of the tag whose name matches name case-INSENSITIVELY, or 0. | |
| guint | dt_tag_repository_insert (const char *name) |
Insert a tag named name and return its new id, or 0 on failure. | |
| gchar * | dt_tag_repository_get_name (const guint tagid) |
The name of tagid, newly allocated, or NULL. | |
| void | dt_tag_repository_rename (const guint tagid, const char *new_name) |
Rename tagid. The caller checks first that the new name is free. | |
| int | dt_tag_repository_count_attachments (const guint tagid) |
How many attachment ROWS tagid has, or -1 if the count could not be read. See dt_tag_repository_count_distinct_images() for the other question. | |
| void | dt_tag_repository_delete (const guint tagid) |
Delete tagid, its attachments, and its memory.darktable_tags entry. | |
| void | dt_tag_repository_delete_batch (const char *id_list) |
Delete every tag in id_list and its attachments. | |
| void | dt_tag_repository_mark_internal (const guint tagid) |
Record tagid as an internal tag. | |
| void | dt_tag_repository_rebuild_internal (void) |
Rebuild the whole internal-tag cache from data.tags. | |
| gint | dt_tag_repository_get_flags (const guint tagid) |
The flags word of tagid, or 0. | |
| void | dt_tag_repository_set_flags (const guint tagid, const gint flags) |
Replace the flags word of tagid. | |
| void | dt_tag_repository_update_flags (const guint tagid, const gint set, const gint keep_mask) |
Set the bits in set and clear those absent from keep_mask: flags = (IFNULL(flags,0) & keep_mask) | set. | |
| gchar * | dt_tag_repository_get_synonyms (const guint tagid) |
The synonyms of tagid, newly allocated, or NULL. | |
| void | dt_tag_repository_set_synonyms (const guint tagid, const char *synonyms) |
Replace the synonyms of tagid. | |
| gboolean | dt_tag_repository_is_attached (const guint tagid, const int32_t imgid) |
TRUE when tagid is attached to imgid. | |
| static GList * | _collect_imgids (sqlite3_stmt *stmt) |
| GList * | dt_tag_repository_get_images (const guint tagid) |
Images carrying tagid, GINT_TO_POINTER. Free with g_list_free(). | |
| GList * | dt_tag_repository_get_images_in_list (const guint tagid, const char *imgid_list) |
Images carrying tagid, restricted to imgid_list – a comma-separated list of decimal image ids composed by the caller. | |
| uint32_t | dt_tag_repository_count_distinct_images (const guint tagid) |
Distinct images carrying tagid. | |
| void | dt_tag_repository_detach_batch (const int32_t imgid, const char *tagid_list) |
Detach every tag in tagid_list from imgid. | |
| void | dt_tag_repository_attach_batch (const char *values) |
Attach rows given as the VALUES clause of the insert – "(imgid,tagid,pos),…". The position expression is the caller's, which is why this takes text. | |
| static dt_tag_t * | _tag_from_row (sqlite3_stmt *stmt, const gboolean with_count) |
| GList * | dt_tag_repository_get_attached (const int32_t imgid, const gboolean ignore_internal) |
| Tags attached to one image or to the current selection, ordered by name. | |
| GList * | dt_tag_repository_get_attached_for_export (const int32_t imgid) |
Tags attached to imgid for export, plus every ancestor on their paths. | |
| GList * | dt_tag_repository_get_ids_for_images (const char *imgid_list, const dt_tag_kind_t kind) |
| Ids of the tags on a set of images, optionally restricted by kind. | |
| GList * | dt_tag_repository_get_with_usage (const uint32_t nb_selected) |
| Every user tag with how often it is used and how much of the selection carries it. | |
| GList * | dt_tag_repository_get_collection_tags (void) |
| User tags attached to at least one image of the current collection, by name. | |
| GList * | dt_tag_repository_get_names_under (const int32_t imgid, const char *category) |
Names of the tags on imgid that start with category. | |
| static void | _fill_similar_tags (const char *keyword) |
| static void | _clear_similar_tags (void) |
| static int | _scalar (const char *query) |
| void | dt_tag_repository_count_similar (const char *keyword, int *tag_count, int *img_count) |
How many tags match keyword, and how many images carry any of them. | |
| void | dt_tag_repository_get_similar (const char *keyword, GList **tags, GList **imgids) |
The tags matching keyword and the images carrying any of them. | |
| GList * | dt_tag_repository_get_suggestions (const uint32_t nb_selected, const int confidence, const char *recent_tags, const int nb_recent) |
| Tags worth suggesting for the current selection. | |
| gboolean | dt_tag_repository_attach (const guint tagid, const int32_t imgid) |
Attach tagid to imgid, at the end of the tag order. | |
| void | dt_tag_repository_get_agreement (GList *imgids, gboolean *same_tags, gboolean *same_categories) |
Do all of imgids carry exactly the same tags? The same categories? | |
| void | dt_tag_repository_cleanup (void) |
| Finalise whatever this repository still caches – today, nothing. See dt_colorlabel_repository_cleanup() for why the hook stays. | |
Variables | |
| static const char *const | _attached_query [2][2] |
Definition at line 709 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_EXEC, and L.
Referenced by dt_tag_repository_count_similar(), and dt_tag_repository_get_similar().
|
static |
Definition at line 351 of file tag_repository.c.
References L.
Referenced by dt_tag_repository_get_images(), and dt_tag_repository_get_images_in_list().
Definition at line 688 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, and L.
Referenced by dt_tag_repository_count_similar(), and dt_tag_repository_get_similar().
Definition at line 114 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, IS_NULL_PTR, L, and value.
Referenced by dt_tag_repository_find_by_name(), and dt_tag_repository_find_by_name_nocase().
Definition at line 129 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by dt_tag_repository_delete(), and dt_tag_repository_mark_internal().
Definition at line 716 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, L, and v.
Referenced by dt_tag_repository_count_similar().
|
static |
Definition at line 477 of file tag_repository.c.
References IS_NULL_PTR, L, and t.
Referenced by dt_tag_repository_get_attached(), and dt_tag_repository_get_attached_for_export().
| void dt_tag_count_free | ( | gpointer | data | ) |
Release one dt_tag_count_t, name included. Suits g_list_free_full().
Definition at line 61 of file tag_repository.c.
References dt_free, IS_NULL_PTR, and t.
Referenced by dt_map_location_get_locations_by_path().
Attach tagid to imgid, at the end of the tag order.
Definition at line 896 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by _exif_import_tags(), and test_tag_agreement().
Attach rows given as the VALUES clause of the insert – "(imgid,tagid,pos),…". The position expression is the caller's, which is why this takes text.
Definition at line 416 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, IS_NULL_PTR, and L.
Referenced by _bulk_add_tags().
Finalise whatever this repository still caches – today, nothing. See dt_colorlabel_repository_cleanup() for why the hook stays.
Definition at line 963 of file tag_repository.c.
Referenced by dt_tags_cleanup(), and testdb_teardown().
| int dt_tag_repository_count_attachments | ( | const guint | tagid | ) |
How many attachment ROWS tagid has, or -1 if the count could not be read. See dt_tag_repository_count_distinct_images() for the other question.
Definition at line 198 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by dt_map_location_get_images_count(), and dt_tag_remove().
| uint32_t dt_tag_repository_count_distinct_images | ( | const guint | tagid | ) |
Distinct images carrying tagid.
Definition at line 385 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by dt_tag_images_count().
How many tags match keyword, and how many images carry any of them.
Definition at line 726 of file tag_repository.c.
References _clear_similar_tags(), _fill_similar_tags(), _scalar(), IS_NULL_PTR, and L.
Referenced by dt_tag_count_tags_images().
Delete tagid, its attachments, and its memory.darktable_tags entry.
Definition at line 213 of file tag_repository.c.
References _run_for_id().
Referenced by dt_tag_remove().
Delete every tag in id_list and its attachments.
| id_list | a comma-separated list of decimal tag ids, composed by the caller. |
Definition at line 220 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, IS_NULL_PTR, and L.
Referenced by dt_tag_delete_tag_batch().
Detach every tag in tagid_list from imgid.
| tagid_list | comma-separated decimal tag ids. Does nothing when NULL. |
Definition at line 401 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, IS_NULL_PTR, and L.
Referenced by _bulk_remove_tags().
| guint dt_tag_repository_find_by_name | ( | const char * | name | ) |
The id of the tag named name, or 0 when there is none.
Definition at line 138 of file tag_repository.c.
References _first_id_for_text(), and name.
Referenced by _exif_import_tags(), dt_tag_exists(), dt_tag_new(), and dt_tag_repository_insert().
| guint dt_tag_repository_find_by_name_nocase | ( | const char * | name | ) |
The id of the tag whose name matches name case-INSENSITIVELY, or 0.
Definition at line 143 of file tag_repository.c.
References _first_id_for_text(), and name.
Referenced by dt_tag_get_tag_id_by_name().
| void dt_tag_repository_get_agreement | ( | GList * | imgids, |
| gboolean * | same_tags, | ||
| gboolean * | same_categories | ||
| ) |
Do all of imgids carry exactly the same tags? The same categories?
A tag is shared when every image in the set carries it, so the test is per tag: count the distinct images attached to it and compare against the size of the set. Any tag short of that means the images disagree. Tags flagged DT_TF_CATEGORY are answered separately because the panel shows them on their own row. Darktable's internal darktable|* namespace is excluded, as it always was.
Both out-parameters are set to TRUE for an empty or unreadable set – vacuously, nothing disagrees. Either may be NULL.
Definition at line 914 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, DT_TF_CATEGORY, FALSE, L, and TRUE.
Referenced by _concatenate_multiple_images(), and test_tag_agreement().
Tags attached to one image or to the current selection, ordered by name.
| imgid | a positive image id, or <= 0 to read the selection (joining main.selected_images rather than binding an id). |
| ignore_internal | exclude tags in memory.darktable_tags. |
GList of dt_tag_t *; count is the number of DISTINCT images each tag is on. Free with dt_tag_free_result(). Definition at line 490 of file tag_repository.c.
References _attached_query, _tag_from_row(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, IS_NULL_PTR, L, t, and TRUE.
Referenced by dt_tag_get_attached().
Tags attached to imgid for export, plus every ancestor on their paths.
The ancestors are what lets the caller check whether a node in the path is a category, so a hierarchical tag exports the right way. Internal tags are always excluded and count is not filled – the export does not use it.
Definition at line 512 of file tag_repository.c.
References _tag_from_row(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, FALSE, L, and t.
Referenced by _tag_get_attached_export().
Names of the tags attached to an image.
| imgid | the image, or a negative value for every selected image – the convention dt_metadata_get() uses, which is this function's only caller. Across a selection the same name appears once per image carrying it, and that is deliberate: the caller counts occurrences. |
GList of newly allocated names. Free with g_list_free_full(l, g_free). Definition at line 28 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by dt_metadata_get().
Tags at path or below it, each with the number of distinct images carrying it.
| path | exact name to match. |
| path_prefix | names starting with this also match; normally path plus a |. |
GList of newly allocated dt_tag_count_t. Free with g_list_free_full(l, dt_tag_count_free). Definition at line 69 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, L, name, and t.
Referenced by dt_map_location_get_locations_by_path().
User tags attached to at least one image of the current collection, by name.
GList of dt_tag_t * with tag and id set only – the caller shows names. Definition at line 632 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, L, and t.
Referenced by dt_tag_get_collection_tags().
| gint dt_tag_repository_get_flags | ( | const guint | tagid | ) |
The flags word of tagid, or 0.
Definition at line 267 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, flags, and L.
Referenced by dt_tag_get_flags(), and dt_tag_get_tag_order_by_id().
| GList * dt_tag_repository_get_ids_for_images | ( | const char * | imgid_list, |
| const dt_tag_kind_t | kind | ||
| ) |
Ids of the tags on a set of images, optionally restricted by kind.
| imgid_list | a comma-separated list of decimal image ids, composed by the caller – one id for a single image, or the selection's, which common/selection.c already knows how to spell. |
| kind | all tags, only the internal darktable|… ones, or only the others. |
GList of tag ids as GINT_TO_POINTER. Free with g_list_free(). Definition at line 546 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, DT_TAG_KIND_ANY, DT_TAG_KIND_INTERNAL, IS_NULL_PTR, kind, and L.
Referenced by _tag_get_tags().
Images carrying tagid, GINT_TO_POINTER. Free with g_list_free().
Definition at line 362 of file tag_repository.c.
References _collect_imgids(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by dt_tag_get_images().
Images carrying tagid, restricted to imgid_list – a comma-separated list of decimal image ids composed by the caller.
Definition at line 371 of file tag_repository.c.
References _collect_imgids(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, IS_NULL_PTR, and L.
Referenced by dt_tag_get_images_from_list().
| gchar * dt_tag_repository_get_name | ( | const guint | tagid | ) |
The name of tagid, newly allocated, or NULL.
Definition at line 170 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, L, and name.
Referenced by dt_tag_get_name().
Names of the tags on imgid that start with category.
GList of newly allocated full tag names, in query order. The caller slices them into path components; that is string work, not storage. Definition at line 663 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, IS_NULL_PTR, and L.
Referenced by dt_tag_get_subtags().
The tags matching keyword and the images carrying any of them.
| tags | receives dt_tag_t * with id and tag set; appended, not replaced. |
| imgids | receives image ids as GINT_TO_POINTER; appended, not replaced. |
Definition at line 746 of file tag_repository.c.
References _clear_similar_tags(), _fill_similar_tags(), dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_PREPARE_V2, IS_NULL_PTR, L, and t.
Referenced by dt_tag_get_tags_images().
| GList * dt_tag_repository_get_suggestions | ( | const uint32_t | nb_selected, |
| const int | confidence, | ||
| const char * | recent_tags, | ||
| const int | nb_recent | ||
| ) |
Tags worth suggesting for the current selection.
Two sources unioned: tags that co-occur with the selection's tags often enough to clear confidence, and the user's recent-tag list. Tags already on every selected image are rejected from both – suggesting one would be a no-op.
| nb_selected | how many images are selected. Also used to fold select, for the same reason as dt_tag_repository_get_with_usage(). |
| confidence | percentage, 0..100. At 100 the co-occurrence half is skipped entirely and only the recent list is returned – a different query, not a stricter filter. |
| recent_tags | the recent-tag names, already quoted and comma-separated by the caller, dropped into an IN (…). It comes from the user's own configuration. |
| nb_recent | how many of them to keep. |
GList of dt_tag_t *; leave is left to the caller. Definition at line 789 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_EXEC, DT_DEBUG_SQLITE3_PREPARE_V2, dt_free, DT_TS_ALL_IMAGES, DT_TS_NO_IMAGE, DT_TS_SOME_IMAGES, L, and t.
Referenced by dt_tag_get_suggestions().
| gchar * dt_tag_repository_get_synonyms | ( | const guint | tagid | ) |
The synonyms of tagid, newly allocated, or NULL.
Definition at line 306 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by dt_tag_get_synonyms().
Every user tag with how often it is used and how much of the selection carries it.
| nb_selected | how many images are selected, which common/selection.c knows and the database does not. |
GList of dt_tag_t * ordered by name, with count = total attachments and select already folded into the tri-state. leave is left to the caller.select itself, where dt_tag_repository_get_attached() leaves it. There, count IS the per-image number, so the caller can fold it afterwards; here count is the tag's global usage and the per-selection number appears only inside the query. Rather than hand back a second parallel list for it, or park it in a field whose units then lie, the fold happens where the number exists. Definition at line 574 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_EXEC, DT_DEBUG_SQLITE3_PREPARE_V2, DT_TS_ALL_IMAGES, DT_TS_NO_IMAGE, DT_TS_SOME_IMAGES, L, and t.
Referenced by dt_tag_get_with_usage().
| guint dt_tag_repository_insert | ( | const char * | name | ) |
Insert a tag named name and return its new id, or 0 on failure.
Definition at line 151 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, dt_tag_repository_find_by_name(), IS_NULL_PTR, L, and name.
Referenced by _exif_import_tags(), dt_tag_new(), and test_tag_agreement().
TRUE when tagid is attached to imgid.
Definition at line 335 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by dt_is_tag_attached().
Record tagid as an internal tag.
Definition at line 238 of file tag_repository.c.
References _run_for_id().
Referenced by dt_tag_new().
Rebuild the whole internal-tag cache from data.tags.
Definition at line 243 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_EXEC, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by dt_set_darktable_tags().
Rename tagid. The caller checks first that the new name is free.
Definition at line 185 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by dt_tag_rename().
Replace the flags word of tagid.
Definition at line 280 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, flags, and L.
Referenced by dt_tag_set_flags(), and test_tag_agreement().
Replace the synonyms of tagid.
Definition at line 320 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_BIND_TEXT, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by dt_tag_add_synonym(), and dt_tag_set_synonyms().
Set the bits in set and clear those absent from keep_mask: flags = (IFNULL(flags,0) & keep_mask) | set.
Definition at line 291 of file tag_repository.c.
References dt_database_get_sqlite3_global(), DT_DEBUG_SQLITE3_BIND_INT, DT_DEBUG_SQLITE3_PREPARE_V2, and L.
Referenced by dt_tag_set_tag_order_by_id().
Definition at line 442 of file tag_repository.c.
Referenced by dt_tag_repository_get_attached().