Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
import_jobs.c File Reference
#include "system/mem_alloc.h"
#include "common/paths.h"
#include "common/conf.h"
#include "import_jobs.h"
#include "import_sequence.h"
#include "common/collection.h"
#include "common/datetime.h"
#include "metadata/exif.h"
#include "develop/history_merge.h"
#include "metadata/metadata.h"
#include "common/styles.h"
#include "control/control.h"
#include "common/film.h"
#include "common/image.h"
#include "control/jobs/control_jobs.h"
#include <string.h>
#include <glib/gstdio.h>
#include "common/utility.h"
#include "osx/osx.h"
+ Include dependency graph for import_jobs.c:

Go to the source code of this file.

Functions

gboolean _create_dir (const char *path)
 Creates folders from path. Returns TRUE if success.
 
gchar * _path_cleanup (gchar *path_in)
 Replaces separator depending of the current OS and removes whitespaces.
 
gchar * dt_build_filename_from_pattern (const char *const filename, const int index, dt_image_t *img, dt_control_import_t *data)
 Build a full path for a given image file, given a pattern.
 
gboolean _file_exist (const char *dest_file_path)
 Tests if file exist. Returns 1 if so.
 
gboolean _copy_file (const char *filename, const char *dest_file_path)
 Just copy a file. Returns 1 if success.
 
const int32_t _import_job (dt_control_import_t *data, gchar *img_path_to_db)
 Add an image entry in the database and returns its imgID.
 
void dt_import_duplicate_get_dest_name (char *xmp_dest_name, const char *dest_file_path, const int counter)
 Gets the computed xmp file name with apropriate number for import copy. It computes a duplicate name based on the counter value. The first path in the list ALWAYS become the default xmp. So in case the default xmp was not found, the first one in the list is used as default. Else, it's a duplicate.
 
int _import_copy_xmp (const char *const filename, const gchar *dest_file_path)
 Attempt to find all sidecar XMP files along an image file and import (copy) it to destination.
 
int _import_copy_txt (const char *const filename, const char *dest_file_path)
 
int _import_copy_file (const char *const filename, const char *const dest_file_path, dt_control_import_t *data, gchar *img_path_to_db, size_t pathname_len, GList **discarded)
 copy a file to a destination path after checking if everything is allright.
 
void _write_xmp_id (const char *filename, int32_t imgid)
 
int32_t _import_image (const GList *img, dt_control_import_t *data, const char *final_destination, GList **discarded, int *xmps)
 process to copy (or not) and import an image to database.
 
static void _refresh_progress_counter (dt_job_t *job, const int elements, const int index, const gboolean folder_survey)
 Update import progress with wording matching the import origin.
 
static int32_t _control_import_job_run (dt_job_t *job)
 
void dt_control_import_data_free (dt_control_import_t *data)
 
void dt_control_import_set_discarded_files_handler (dt_control_import_discarded_handler_t handler)
 
static void _control_import_job_cleanup (void *p)
 
static void * _control_import_alloc ()
 
static dt_job_t * _control_import_job_create (dt_control_import_t data)
 
int dt_control_import (dt_control_import_t data)
 Process a list of images to import with or without copying the files on an arbitrary hard-drive.
 

Variables

static dt_control_import_discarded_handler_t _discarded_files_handler = NULL
 

Function Documentation

◆ _control_import_alloc()

static void * _control_import_alloc ( )
static

◆ _control_import_job_cleanup()

static void _control_import_job_cleanup ( void *  p)
static

◆ _control_import_job_create()

◆ _control_import_job_run()

static int32_t _control_import_job_run ( dt_job_t *  job)
static

Reserve expanded copy destinations before any filesystem work.

Siblings preserve their capture sequence while their destinations differ. A sibling reservation with that shared sequence consumes one new global sequence and receives one replacement expansion. The replacement is never retried: an unchanged or already-reserved result reaches the configured conflict policy without replacing its first reservation owner. Tables stay alive until after the loop so failed copies and database imports permanently consume their sequence and reservation for this job.

Definition at line 505 of file import_jobs.c.

References _import_image(), _refresh_progress_counter(), dt_control_import_t::callback_data, dt_import_sequence_t::captures, dt_control_import_t::copy, dt_import_sequence_t::destinations, dt_control_import_t::discarded, dt_alloc_align(), DT_COLLECTION_CHANGE_NEW_QUERY, dt_collection_get_global(), DT_COLLECTION_IMPORT_VIEW_GRID, DT_COLLECTION_IMPORT_VIEW_IMAGE, DT_COLLECTION_IMPORT_VIEW_KEEP, dt_collection_load_filmroll(), dt_collection_notify_imported(), DT_COLLECTION_PROP_UNDEF, dt_collection_update_query(), dt_conf_set_int(), dt_control_job_get_params(), dt_control_log(), DT_DEBUG_IMPORT, dt_exif_read(), dt_free, dt_free_align, dt_free_gpointer(), dt_image_init(), dt_import_sequence_assign(), dt_import_sequence_destination(), dt_print(), dt_control_import_t::elements, dt_control_import_t::file_imported, dt_control_import_t::folder_survey, dt_control_import_t::imgs, IS_NULL_PTR, params, dt_control_import_t::target_file_pattern, dt_control_import_t::target_subfolder_pattern, TRUE, and UNKNOWN_IMAGE.

Referenced by _control_import_job_create().

◆ _copy_file()

gboolean _copy_file ( const char *  filename,
const char *  dest_file_path 
)

Just copy a file. Returns 1 if success.

Parameters
filename
dest_file_path
Returns
gboolean

Definition at line 160 of file import_jobs.c.

References DT_DEBUG_IMPORT, dt_print(), out, and res.

Referenced by _import_copy_file(), _import_copy_txt(), and _import_copy_xmp().

◆ _create_dir()

gboolean _create_dir ( const char *  path)

Creates folders from path. Returns TRUE if success.

Parameters
patha valid folders path to create.
Returns
gboolean TRUE on error, FALSE on success

Definition at line 54 of file import_jobs.c.

References dt_control_log(), FALSE, and TRUE.

Referenced by _import_copy_file().

◆ _file_exist()

gboolean _file_exist ( const char *  dest_file_path)

Tests if file exist. Returns 1 if so.

Parameters
dest_file_path
Returns
gboolean

Definition at line 148 of file import_jobs.c.

References IS_NULL_PTR.

Referenced by _import_copy_file().

◆ _import_copy_file()

int _import_copy_file ( const char *const  filename,
const char *const  dest_file_path,
dt_control_import_t *  data,
gchar *  img_path_to_db,
size_t  pathname_len,
GList **  discarded 
)

copy a file to a destination path after checking if everything is allright.

Parameters
filenamesource file path.
dest_file_pathfinal borrowed destination selected before import.
dataimport module information.
img_path_to_dbwill be set to the file path for import.
pathname_lenthe img_path_to_db size.
discardedthe list of file pathes discarded because the target already exists
Returns
int -1 on copy error, 0 when the destination already existed, 1 when the file was copied

Definition at line 289 of file import_jobs.c.

References _copy_file(), _create_dir(), _file_exist(), _import_copy_txt(), _import_copy_xmp(), cleanup(), DT_DEBUG_IMPORT, DT_DEBUG_PRINT, dt_free, DT_IMPORT_ONCONFLICT_OVERWRITE, DT_IMPORT_ONCONFLICT_UNIQUE, dt_print(), dt_util_dir_exist(), dt_util_test_writable_dir(), FALSE, dt_control_import_t::on_conflict, and dt_control_import_t::target_dir.

Referenced by _import_image(), and _test_copy_directory_failure_reports_only_its_cause().

◆ _import_copy_txt()

int _import_copy_txt ( const char *const  filename,
const char *  dest_file_path 
)

◆ _import_copy_xmp()

int _import_copy_xmp ( const char *const  filename,
const gchar *  dest_file_path 
)

Attempt to find all sidecar XMP files along an image file and import (copy) it to destination.

Parameters
filenamefull path of original image file
dest_file_pathfull path of destination image file
Returns
int number of imported XMP

Definition at line 232 of file import_jobs.c.

References _copy_file(), DT_DEBUG_IMPORT, dt_free, dt_image_find_xmps(), dt_import_duplicate_get_dest_name(), DT_PATH_MAX, and dt_print().

Referenced by _import_copy_file().

◆ _import_image()

int32_t _import_image ( const GList *  img,
dt_control_import_t *  data,
const char *  final_destination,
GList **  discarded,
int *  xmps 
)

process to copy (or not) and import an image to database.

Sidecars are read only after database import succeeds. Source deletion requires a successful copy and complete byte equality; stream errors preserve the source. Styles are applied in their configured order using one merge batch, followed by cache and thumbnail invalidation because the history was written to the DB.

Parameters
imgthe current image.
datainfo from import module.
final_destinationfinal borrowed copy destination, ignored without copy.
Returns
int32_t the imgid of the imported image (or -1 if import failed)

Definition at line 406 of file import_jobs.c.

References _import_copy_file(), _import_job(), dt_control_import_t::copy, dt_control_import_t::delete_source, dt_control_alert(), DT_DEBUG_IMPORT, DT_HISTORY_MERGE_APPEND, dt_hm_batch_state_cleanup(), dt_image_history_changed(), dt_image_read_duplicates(), DT_PATH_MAX, dt_print(), dt_styles_apply_to_image_merge(), dt_styles_get_id_by_name(), dt_util_streams_equal(), FALSE, IS_NULL_PTR, dt_control_import_t::styles, TRUE, and UNKNOWN_IMAGE.

Referenced by _control_import_job_run().

◆ _import_job()

const int32_t _import_job ( dt_control_import_t *  data,
gchar *  img_path_to_db 
)

Add an image entry in the database and returns its imgID.

Parameters
datainformations from the import module
img_path_to_dbthe file path to import
Returns
const int32_t

Definition at line 181 of file import_jobs.c.

References dt_film_new(), dt_free, dt_image_import(), dt_util_path_get_dirname(), and dt_control_import_t::folder_survey.

Referenced by _import_image().

◆ _path_cleanup()

gchar * _path_cleanup ( gchar *  path_in)

Replaces separator depending of the current OS and removes whitespaces.

Parameters
path
Returns
gchar*

Definition at line 72 of file import_jobs.c.

References dt_cleanup_separators(), dt_free, and dt_util_remove_whitespace().

Referenced by dt_build_filename_from_pattern().

◆ _refresh_progress_counter()

static void _refresh_progress_counter ( dt_job_t *  job,
const int  elements,
const int  index,
const gboolean  folder_survey 
)
static

Update import progress with wording matching the import origin.

Definition at line 487 of file import_jobs.c.

References double(), dt_control_job_set_progress(), and dt_control_job_set_progress_message().

Referenced by _control_import_job_run().

◆ _write_xmp_id()

void _write_xmp_id ( const char *  filename,
int32_t  imgid 
)

◆ dt_build_filename_from_pattern()

gchar * dt_build_filename_from_pattern ( const char *const  filename,
const int  index,
dt_image_t *  img,
dt_control_import_t *  data 
)

Build a full path for a given image file, given a pattern.

Parameters
filenameFull path of the original file
indexIncremental number in a sequence
imgdt_image_t object. Needs to be inited with EXIF fields prior to calling this function, otherwise EXIF variables are expanded to defaults/fallback.
dataImport options
Returns
A newly allocated normalized path after variables expansion, or NULL when expansion, cleanup, normalization, or path construction fails. The caller releases it with dt_free(); data->target_dir remains owned by data and is replaced only after releasing it before a re-expansion.

Definition at line 80 of file import_jobs.c.

References _path_cleanup(), dt_control_import_t::base_folder, dt_control_import_t::datetime, DT_DEBUG_PRINT, dt_free, dt_print(), dt_util_normalize_path(), dt_variables_expand(), dt_variables_params_destroy(), dt_variables_params_init(), dt_variables_set_datetime(), FALSE, IS_NULL_PTR, dt_control_import_t::jobcode, params, res, dt_control_import_t::target_dir, dt_control_import_t::target_file_pattern, dt_control_import_t::target_subfolder_pattern, and UNKNOWN_IMAGE.

Referenced by _set_test_path(), _test_pattern_expansion_rejects_missing_patterns(), dt_folder_survey_destination_preview(), and dt_import_sequence_destination().

◆ dt_control_import()

◆ dt_control_import_data_free()

◆ dt_control_import_set_discarded_files_handler()

void dt_control_import_set_discarded_files_handler ( dt_control_import_discarded_handler_t  handler)

Definition at line 670 of file import_jobs.c.

References _discarded_files_handler.

Referenced by dt_gui_import_init_handlers().

◆ dt_import_duplicate_get_dest_name()

void dt_import_duplicate_get_dest_name ( char *  xmp_dest_name,
const char *  dest_file_path,
const int  counter 
)

Gets the computed xmp file name with apropriate number for import copy. It computes a duplicate name based on the counter value. The first path in the list ALWAYS become the default xmp. So in case the default xmp was not found, the first one in the list is used as default. Else, it's a duplicate.

Parameters
xmp_dest_namethe destination name.
dest_file_paththe full filename path of the destination image.
counterthe number of duplicates.
Returns
void

Definition at line 208 of file import_jobs.c.

References DT_DEBUG_IMPORT, dt_free, DT_PATH_MAX, dt_print(), dt_util_normalize_path(), and safe_strlen().

Referenced by _import_copy_xmp().

Variable Documentation

◆ _discarded_files_handler

dt_control_import_discarded_handler_t _discarded_files_handler = NULL
static