Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
variables.c File Reference
#include "widgets/bauhaus.h"
#include "common/paths.h"
#include "database/image_repository.h"
#include "common/variables.h"
#include "metadata/colorlabels.h"
#include "common/file_location.h"
#include "common/image.h"
#include "caches/image_cache.h"
#include "metadata/metadata.h"
#include "common/opencl.h"
#include "common/utility.h"
#include "metadata/tags.h"
#include "common/datetime.h"
#include "common/conf.h"
#include <stdio.h>
#include <string.h>
#include <time.h>
+ Include dependency graph for src/common/variables.c:

Go to the source code of this file.

Data Structures

struct  dt_variables_data_t
 

Typedefs

typedef struct dt_variables_data_t dt_variables_data_t
 
typedef enum _image_case _image_case
 

Enumerations

enum  _image_case {
  NONE ,
  FILENAME ,
  IMGID
}
 

Functions

static char * _expand_source (dt_variables_params_t *params, char **source, char extra_stop)
 
gboolean dt_get_user_pictures_dir (const gchar *homedir, gchar *picdir, size_t picdir_size)
 Gets the path to the current OS pictures directory.
 
static void _init_expansion (dt_variables_params_t *params, gboolean iterate)
 
static void _cleanup_expansion (dt_variables_params_t *params)
 
static gboolean _has_prefix (char **str, const char *prefix)
 
static char * _variables_get_longitude (dt_variables_params_t *params)
 
static char * _variables_get_latitude (dt_variables_params_t *params)
 
static char * _variables_get_iso_timestamp (const GTimeSpan gts)
 
static gboolean _expand_datetime_now (dt_variables_params_t *params, char **variable, char **out)
 Expand the current time, and the import/change/export/print timestamps.
 
static gboolean _expand_exif_datetime (dt_variables_params_t *params, char **variable, char **out)
 Expand the capture time read from EXIF.
 
static gboolean _expand_exif_and_gps (dt_variables_params_t *params, char **variable, char **out)
 Expand EXIF exposure settings, GPS position and camera identity.
 
static gboolean _expand_image_and_version (dt_variables_params_t *params, char **variable, char **out)
 Expand image id, duplicate version, job code and film roll.
 
static gboolean _expand_file_and_folder (dt_variables_params_t *params, char **variable, char **out)
 Expand the source file's path, name and mtime, plus the user's folders.
 
static gboolean _expand_rating_and_metadata (dt_variables_params_t *params, char **variable, char **out, gboolean *escape)
 Expand star rating, colour labels and the Dublin Core fields.
 
static gboolean _expand_geometry_and_misc (dt_variables_params_t *params, char **variable, char **out)
 Expand image dimensions, category, tags and build identity.
 
static char * _get_base_value (dt_variables_params_t *params, char **variable)
 Expand one into its text.
 
static char * _variable_get_value (dt_variables_params_t *params, char **variable)
 
static void _grow_buffer (char **result, char **result_iter, size_t *result_length, size_t extra_space)
 
char * dt_variables_expand (dt_variables_params_t *params, gchar *source, gboolean iterate)
 
void dt_variables_params_init (dt_variables_params_t **params)
 
void dt_variables_params_destroy (dt_variables_params_t *params)
 
void dt_variables_set_datetime (dt_variables_params_t *params, GDateTime *datetime)
 
void dt_variables_set_max_width_height (dt_variables_params_t *params, int max_width, int max_height)
 
void dt_variables_reset_sequence (dt_variables_params_t *params)
 
void dt_variables_set_tags_flags (dt_variables_params_t *params, uint32_t flags)
 

Typedef Documentation

◆ _image_case

typedef enum _image_case _image_case

◆ dt_variables_data_t

Enumeration Type Documentation

◆ _image_case

Enumerator
NONE 
FILENAME 
IMGID 

Definition at line 129 of file src/common/variables.c.

Function Documentation

◆ _cleanup_expansion()

static void _cleanup_expansion ( dt_variables_params_t params)
static

Definition at line 269 of file src/common/variables.c.

References dt_free.

Referenced by dt_variables_expand().

◆ _expand_datetime_now()

static gboolean _expand_datetime_now ( dt_variables_params_t params,
char **  variable,
char **  out 
)
static

Expand the current time, and the import/change/export/print timestamps.

One link of the ordered chain _get_base_value() walks; see the contract documented there. Branch order inside this function is load-bearing for the same reason it is across the chain.

Parameters
paramsexpansion context.
variablein/out: on a match, advanced past the name that was consumed.
outwritten ONLY on a match, with a newly-allocated string the caller owns.
Returns
TRUE if the variable was recognised and consumed, FALSE to try the next link.

Definition at line 344 of file src/common/variables.c.

References _has_prefix(), _variables_get_iso_timestamp(), DT_DATETIME_EXIF_LENGTH, dt_datetime_gdatetime_to_exif(), DT_DATETIME_LENGTH, FALSE, out, and TRUE.

Referenced by _get_base_value().

◆ _expand_exif_and_gps()

static gboolean _expand_exif_and_gps ( dt_variables_params_t params,
char **  variable,
char **  out 
)
static

Expand EXIF exposure settings, GPS position and camera identity.

One link of the ordered chain _get_base_value() walks; see the contract documented there. Branch order inside this function is load-bearing for the same reason it is across the chain.

Parameters
paramsexpansion context.
variablein/out: on a match, advanced past the name that was consumed.
outwritten ONLY on a match, with a newly-allocated string the caller owns.
Returns
TRUE if the variable was recognised and consumed, FALSE to try the next link.

Definition at line 470 of file src/common/variables.c.

References _has_prefix(), _variables_get_latitude(), _variables_get_longitude(), dt_free, dt_util_format_exposure(), dt_util_str_replace(), FALSE, i, out, res, and TRUE.

Referenced by _get_base_value().

◆ _expand_exif_datetime()

static gboolean _expand_exif_datetime ( dt_variables_params_t params,
char **  variable,
char **  out 
)
static

Expand the capture time read from EXIF.

One link of the ordered chain _get_base_value() walks; see the contract documented there. Branch order inside this function is load-bearing for the same reason it is across the chain.

Parameters
paramsexpansion context.
variablein/out: on a match, advanced past the name that was consumed.
outwritten ONLY on a match, with a newly-allocated string the caller owns.
Returns
TRUE if the variable was recognised and consumed, FALSE to try the next link.

Definition at line 416 of file src/common/variables.c.

References _has_prefix(), DT_DATETIME_EXIF_LENGTH, dt_datetime_gdatetime_to_exif(), DT_DATETIME_LENGTH, FALSE, out, and TRUE.

Referenced by _get_base_value().

◆ _expand_file_and_folder()

static gboolean _expand_file_and_folder ( dt_variables_params_t params,
char **  variable,
char **  out 
)
static

Expand the source file's path, name and mtime, plus the user's folders.

One link of the ordered chain _get_base_value() walks; see the contract documented there. Branch order inside this function is load-bearing for the same reason it is across the chain.

Parameters
paramsexpansion context.
variablein/out: on a match, advanced past the name that was consumed.
outwritten ONLY on a match, with a newly-allocated string the caller owns.
Returns
TRUE if the variable was recognised and consumed, FALSE to try the next link.

Definition at line 609 of file src/common/variables.c.

References _has_prefix(), FALSE, out, and TRUE.

Referenced by _get_base_value().

◆ _expand_geometry_and_misc()

static gboolean _expand_geometry_and_misc ( dt_variables_params_t params,
char **  variable,
char **  out 
)
static

Expand image dimensions, category, tags and build identity.

One link of the ordered chain _get_base_value() walks; see the contract documented there. Branch order inside this function is load-bearing for the same reason it is across the chain.

Parameters
paramsexpansion context.
variablein/out: on a match, advanced past the name that was consumed.
outwritten ONLY on a match, with a newly-allocated string the caller owns.
Returns
TRUE if the variable was recognised and consumed, FALSE to try the next link.

Definition at line 853 of file src/common/variables.c.

References _has_prefix(), darktable_package_version, dt_free, dt_free_gpointer(), dt_image_get_text_path(), DT_IMAGE_HAS_TXT, dt_tag_get_list_export(), dt_tag_get_subtags(), dt_util_glist_to_str(), FALSE, out, PACKAGE_NAME, and TRUE.

Referenced by _get_base_value().

◆ _expand_image_and_version()

static gboolean _expand_image_and_version ( dt_variables_params_t params,
char **  variable,
char **  out 
)
static

Expand image id, duplicate version, job code and film roll.

One link of the ordered chain _get_base_value() walks; see the contract documented there. Branch order inside this function is load-bearing for the same reason it is across the chain.

Parameters
paramsexpansion context.
variablein/out: on a match, advanced past the name that was consumed.
outwritten ONLY on a match, with a newly-allocated string the caller owns.
Returns
TRUE if the variable was recognised and consumed, FALSE to try the next link.

Definition at line 541 of file src/common/variables.c.

References _has_prefix(), dt_free, dt_free_gpointer(), dt_image_cache_get(), dt_image_cache_read_release(), dt_image_print_exif(), dt_image_repository_get_duplicate_ids(), dt_metadata_get(), FALSE, IS_NULL_PTR, out, res, and TRUE.

Referenced by _get_base_value().

◆ _expand_rating_and_metadata()

static gboolean _expand_rating_and_metadata ( dt_variables_params_t params,
char **  variable,
char **  out,
gboolean *  escape 
)
static

Expand star rating, colour labels and the Dublin Core fields.

One link of the ordered chain _get_base_value() walks; see the contract documented there. Branch order inside this function is load-bearing for the same reason it is across the chain.

Parameters
paramsexpansion context.
variablein/out: on a match, advanced past the name that was consumed.
outwritten ONLY on a match, with a newly-allocated string the caller owns.
escapecleared when the produced text must not be markup-escaped.
Returns
TRUE if the variable was recognised and consumed, FALSE to try the next link.
Todo:
: currently we concatenate all the color labels with a ',' as a separator. Maybe it's better to

Definition at line 709 of file src/common/variables.c.

References _has_prefix(), dt_bauhaus_t::colorlabels, dt_bauhaus_get_global(), dt_colorlabels_to_string(), dt_free_gpointer(), dt_metadata_get(), dt_opencl_is_enabled(), dt_util_dstrcat(), dt_util_glist_to_str(), FALSE, IS_NULL_PTR, out, res, and TRUE.

Referenced by _get_base_value().

◆ _expand_source()

static char * _expand_source ( dt_variables_params_t params,
char **  source,
char  extra_stop 
)
static

◆ _get_base_value()

static char * _get_base_value ( dt_variables_params_t params,
char **  variable 
)
static

Expand one into its text.

The chain below is ORDERED and that order is load-bearing: _has_prefix() is g_str_has_prefix() plus a side effect – on a match it advances variable past the prefix – and it does not require a word boundary. A shorter prefix tried earlier therefore swallows every longer one starting with it, silently. Adding a name means placing it BEFORE any prefix of itself, not merely somewhere in the right group.

Split into one function per family only to keep each readable; the && short-circuit reproduces the single chain this used to be, link by link, in the same order.

Parameters
paramsexpansion context.
variablein/out: advanced past whatever was consumed, including the characters skipped when nothing matched.
Returns
a newly-allocated string the caller owns and must free. NEVER NULL: an unrecognised variable yields "", and callers rely on that.

Definition at line 957 of file src/common/variables.c.

References _expand_datetime_now(), _expand_exif_and_gps(), _expand_exif_datetime(), _expand_file_and_folder(), _expand_geometry_and_misc(), _expand_image_and_version(), _expand_rating_and_metadata(), dt_free, and TRUE.

Referenced by _variable_get_value().

◆ _grow_buffer()

static void _grow_buffer ( char **  result,
char **  result_iter,
size_t *  result_length,
size_t  extra_space 
)
static

Definition at line 1249 of file src/common/variables.c.

Referenced by _expand_source().

◆ _has_prefix()

static gboolean _has_prefix ( char **  str,
const char *  prefix 
)
inlinestatic

◆ _init_expansion()

◆ _variable_get_value()

static char * _variable_get_value ( dt_variables_params_t params,
char **  variable 
)
static
Todo:
: write a dt_util_str_replace that can deal with pattern_length ^^
Todo:
: is there a strstr_len that limits the length of pattern?

Definition at line 988 of file src/common/variables.c.

References _expand_source(), _get_base_value(), dt_free, dt_util_str_replace(), MAX, MIN, and p.

Referenced by _expand_source().

◆ _variables_get_iso_timestamp()

static char * _variables_get_iso_timestamp ( const GTimeSpan  gts)
static

Definition at line 322 of file src/common/variables.c.

References dt_datetime_origin(), and IS_NULL_PTR.

Referenced by _expand_datetime_now().

◆ _variables_get_latitude()

static char * _variables_get_latitude ( dt_variables_params_t params)
static

Definition at line 306 of file src/common/variables.c.

References dt_conf_get_bool(), and dt_util_latitude_str().

Referenced by _expand_exif_and_gps().

◆ _variables_get_longitude()

static char * _variables_get_longitude ( dt_variables_params_t params)
static

Definition at line 290 of file src/common/variables.c.

References dt_conf_get_bool(), and dt_util_longitude_str().

Referenced by _expand_exif_and_gps().

◆ dt_get_user_pictures_dir()

gboolean dt_get_user_pictures_dir ( const gchar *  homedir,
gchar *  picdir,
size_t  picdir_size 
)

Gets the path to the current OS pictures directory.

Parameters
homedirthe user's home directory
picdirthe gchar* to set to the path of the pictures directory
picdir_sizethe size of picdir
Returns
gboolean Returns TRUE if success.

Definition at line 138 of file src/common/variables.c.

References DT_PATH_MAX, and IS_NULL_PTR.

Referenced by _dt_check_basedir(), and _init_expansion().

◆ dt_variables_expand()

char * dt_variables_expand ( dt_variables_params_t params,
gchar *  source,
gboolean  iterate 
)

◆ dt_variables_params_destroy()

void dt_variables_params_destroy ( dt_variables_params_t params)

◆ dt_variables_params_init()

◆ dt_variables_reset_sequence()

void dt_variables_reset_sequence ( dt_variables_params_t params)

reset sequence number

Definition at line 1360 of file src/common/variables.c.

◆ dt_variables_set_datetime()

void dt_variables_set_datetime ( dt_variables_params_t params,
GDateTime *  datetime 
)

reset the date arbitrarily, decrementing reference count of the previous date

Definition at line 1348 of file src/common/variables.c.

Referenced by dt_build_filename_from_pattern().

◆ dt_variables_set_max_width_height()

void dt_variables_set_max_width_height ( dt_variables_params_t params,
int  max_width,
int  max_height 
)

set max image width and height defined for an export session in a dt_variables_params_t.

Definition at line 1354 of file src/common/variables.c.

Referenced by store().

◆ dt_variables_set_tags_flags()

void dt_variables_set_tags_flags ( dt_variables_params_t params,
uint32_t  flags 
)

set flags for tags to be exported

Definition at line 1365 of file src/common/variables.c.

References flags.

Referenced by _watermark_get_svgdoc(), and dt_exif_xmp_attach_export().