![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
#include "common/folder_survey.h"#include "common/darktable.h"#include "common/datetime.h"#include "common/file_location.h"#include "common/imageio.h"#include "control/conf.h"#include "control/control.h"#include "control/jobs.h"#include "control/jobs/import_jobs.h"#include "gui/gtk.h"#include "views/view.h"#include <gio/gio.h>
Include dependency graph for folder_survey.c:Go to the source code of this file.
Data Structures | |
| struct | dt_folder_survey_entry_t |
| struct | dt_folder_survey_observation_t |
| struct | dt_folder_survey_job_t |
| struct | dt_folder_survey_t |
Macros | |
| #define | DT_FOLDER_SURVEY_STATE_FILE "folder-survey-state.ini" |
Typedefs | |
| typedef enum dt_folder_survey_file_state_t | dt_folder_survey_file_state_t |
| typedef struct dt_folder_survey_entry_t | dt_folder_survey_entry_t |
| typedef struct dt_folder_survey_observation_t | dt_folder_survey_observation_t |
| typedef struct dt_folder_survey_job_t | dt_folder_survey_job_t |
| typedef struct dt_folder_survey_t | dt_folder_survey_t |
Enumerations | |
| enum | dt_folder_survey_file_state_t { DT_FOLDER_SURVEY_FILE_PENDING = 0 , DT_FOLDER_SURVEY_FILE_QUEUED , DT_FOLDER_SURVEY_FILE_DONE } |
Functions | |
| static int | _folder_survey_save_locked () |
| Persist the complete survey baseline while the survey lock is held. | |
| static int | _folder_survey_load_locked () |
| Load the previous file list and convert interrupted imports to retries. | |
| static int | _folder_survey_collect (const char *folder, GHashTable *observed) |
| Recursively collect supported images and their stability metadata. | |
| static GList * | _folder_survey_styles_for_import () |
| Read the ordered auto-apply style list from conf. | |
| static void | _folder_survey_imported (const char *source, const gboolean success, gpointer user_data) |
| Update one persisted entry when its asynchronous import completes. | |
| static int32_t | _folder_survey_job_run (dt_job_t *job) |
| Compare the current directory contents with the prior survey loop. | |
| static void | _folder_survey_job_cleanup (void *data) |
| Release one scan job and allow the next periodic scan to start. | |
| static gboolean | _folder_survey_scan (gpointer user_data) |
| Queue one background scan without overlapping the previous scan. | |
| static gboolean | _folder_survey_scan_once (gpointer user_data) |
| Run the immediate post-configuration scan only once. | |
| static void | _folder_survey_reschedule () |
| Recreate the periodic source after a frequency or state change. | |
| static void | _folder_survey_deactivate () |
| Stop periodic scans without discarding the persisted comparison state. | |
| char * | dt_folder_survey_destination_preview () |
| Build the expanded destination path of a sample file from the current configuration, for GUI preview purposes. | |
| gboolean | dt_folder_survey_can_start (const char **message) |
| Check, without any side effect, whether the persisted configuration has everything dt_folder_survey_start() requires to succeed. | |
| void | dt_folder_survey_init () |
| Initialize the folder survey state from the persisted configuration. | |
| static void | _folder_survey_offer_pending_import () |
| Ask whether images already sitting in the source folder should be imported right away, instead of being silently absorbed into the baseline. | |
| int | dt_folder_survey_start () |
| Validate the persisted configuration and start monitoring. | |
| void | dt_folder_survey_halt () |
| User-requested stop: end monitoring and clear the persisted session marker so the next application start does not propose to resume. | |
| gboolean | dt_folder_survey_is_active () |
| TRUE while the periodic folder scan is running. | |
| gboolean | dt_folder_survey_session_was_active () |
| TRUE when the previous application session quit while monitoring. | |
| int | dt_folder_survey_count_new_files () |
| Count files in the surveyed folder that are unknown to the persisted baseline, i.e. files that appeared while the application was closed. | |
| void | dt_folder_survey_absorb_new_files () |
| Record every file currently in the surveyed folder as already handled, so restarting the survey will not import them. | |
| gboolean | dt_folder_survey_propose_resume () |
| Propose to resume an interrupted studio session at application start. | |
| void | dt_folder_survey_cleanup () |
| Release folder survey state after control workers have stopped. | |
| void | dt_folder_survey_stop () |
| Stop new scans before control workers begin shutting down. | |
Variables | |
| static dt_folder_survey_t | _folder_survey = { 0 } |
| #define DT_FOLDER_SURVEY_STATE_FILE "folder-survey-state.ini" |
Definition at line 31 of file folder_survey.c.
| typedef struct dt_folder_survey_entry_t dt_folder_survey_entry_t |
| typedef struct dt_folder_survey_job_t dt_folder_survey_job_t |
| typedef struct dt_folder_survey_observation_t dt_folder_survey_observation_t |
| typedef struct dt_folder_survey_t dt_folder_survey_t |
| Enumerator | |
|---|---|
| DT_FOLDER_SURVEY_FILE_PENDING | |
| DT_FOLDER_SURVEY_FILE_QUEUED | |
| DT_FOLDER_SURVEY_FILE_DONE | |
Definition at line 33 of file folder_survey.c.
|
static |
Recursively collect supported images and their stability metadata.
The loop looks only for regular image files. Directories are traversed in place so a selected ingest root behaves like selecting a folder in Import.
Definition at line 195 of file folder_survey.c.
References dt_free, dt_supported_image(), error(), IS_NULL_PTR, dt_folder_survey_observation_t::mtime, dt_folder_survey_observation_t::size, and type.
Referenced by _folder_survey_job_run(), dt_folder_survey_absorb_new_files(), and dt_folder_survey_count_new_files().
|
static |
Stop periodic scans without discarding the persisted comparison state.
Imports already queued are allowed to finish. Starting again in the same session resumes comparison from the last saved file list.
Definition at line 579 of file folder_survey.c.
References _folder_survey, _folder_survey_save_locked(), dt_folder_survey_t::active, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::immediate_scan, dt_folder_survey_t::lock, and dt_folder_survey_t::timer.
Referenced by dt_folder_survey_halt().
|
static |
Update one persisted entry when its asynchronous import completes.
Definition at line 303 of file folder_survey.c.
References _folder_survey, _folder_survey_save_locked(), DT_FOLDER_SURVEY_FILE_DONE, DT_FOLDER_SURVEY_FILE_PENDING, dt_free, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_folder_survey_t::files, dt_folder_survey_t::generation, IS_NULL_PTR, dt_folder_survey_t::lock, dt_folder_survey_entry_t::stable_scans, and dt_folder_survey_entry_t::state.
Referenced by _folder_survey_job_run().
Release one scan job and allow the next periodic scan to start.
Definition at line 475 of file folder_survey.c.
References _folder_survey, dt_free, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::initialized, dt_folder_survey_t::lock, and dt_folder_survey_t::scan_running.
Referenced by _folder_survey_scan().
|
static |
Compare the current directory contents with the prior survey loop.
New files are first recorded as pending. An unchanged size and modification time on the following loop proves that the producer has stopped writing before the import job receives the file.
Definition at line 331 of file folder_survey.c.
References _folder_survey, _folder_survey_collect(), _folder_survey_imported(), _folder_survey_save_locked(), _folder_survey_styles_for_import(), dt_folder_survey_t::active, dt_folder_survey_t::baseline_initialized, dt_conf_get_bool(), dt_conf_get_int(), dt_conf_get_string(), dt_control_import(), dt_control_job_get_params(), dt_control_log(), DT_FOLDER_SURVEY_FILE_DONE, DT_FOLDER_SURVEY_FILE_PENDING, DT_FOLDER_SURVEY_FILE_QUEUED, dt_free, dt_free_gpointer(), DT_IMPORT_ONCONFLICT_SKIP, DT_IMPORT_ONCONFLICT_UNIQUE, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_string_to_datetime(), dt_folder_survey_t::files, dt_folder_survey_t::generation, dt_control_import_t::imgs, IS_NULL_PTR, dt_folder_survey_t::lock, dt_folder_survey_entry_t::mtime, dt_folder_survey_observation_t::mtime, dt_folder_survey_t::shutting_down, dt_folder_survey_entry_t::size, dt_folder_survey_observation_t::size, dt_folder_survey_entry_t::stable_scans, dt_folder_survey_entry_t::state, and TRUE.
Referenced by _folder_survey_scan().
|
static |
Load the previous file list and convert interrupted imports to retries.
Definition at line 134 of file folder_survey.c.
References _folder_survey, dt_folder_survey_t::baseline_initialized, DT_FOLDER_SURVEY_FILE_DONE, DT_FOLDER_SURVEY_FILE_PENDING, DT_FOLDER_SURVEY_FILE_QUEUED, dt_free, error(), dt_folder_survey_t::files, dt_folder_survey_t::folder, groups(), IS_NULL_PTR, k, dt_folder_survey_entry_t::mtime, dt_folder_survey_entry_t::size, dt_folder_survey_entry_t::stable_scans, dt_folder_survey_entry_t::state, state, dt_folder_survey_t::state_path, and dt_folder_survey_t::was_active_last_session.
Referenced by dt_folder_survey_init().
|
static |
Ask whether images already sitting in the source folder should be imported right away, instead of being silently absorbed into the baseline.
Runs every time monitoring starts: a plain Start on a never-before- surveyed folder would otherwise treat its existing content as the baseline without importing it, and a resumed session would otherwise import files that appeared while the application was closed without asking. Declining absorbs every currently observed file into the baseline so a later scan does not import it behind the user's back. Accepting on a folder with no baseline yet seeds an initialized, empty one so the next scan treats those files as new pending imports instead of silently absorbing them.
Definition at line 826 of file folder_survey.c.
References _folder_survey, _folder_survey_save_locked(), dt_folder_survey_t::baseline_initialized, darktable, dt_conf_get_bool(), dt_conf_set_bool(), dt_folder_survey_absorb_new_files(), dt_folder_survey_count_new_files(), DT_GUI_BOX_SPACING, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_ui_main_window(), FALSE, darktable_t::gui, dt_folder_survey_t::lock, TRUE, and dt_gui_gtk_t::ui.
Referenced by dt_folder_survey_start().
|
static |
Recreate the periodic source after a frequency or state change.
Definition at line 551 of file folder_survey.c.
References _folder_survey, _folder_survey_scan(), _folder_survey_scan_once(), dt_folder_survey_t::active, dt_conf_get_int(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_folder_survey_t::immediate_scan, dt_folder_survey_t::lock, dt_folder_survey_t::shutting_down, and dt_folder_survey_t::timer.
Referenced by dt_folder_survey_start().
|
static |
Persist the complete survey baseline while the survey lock is held.
The state file is replaced as one transaction so a crash cannot leave a partially-written list that would cause old files to be treated as new.
Definition at line 86 of file folder_survey.c.
References _folder_survey, dt_folder_survey_t::active, dt_folder_survey_t::baseline_initialized, dt_free, error(), FALSE, dt_folder_survey_t::files, dt_folder_survey_t::folder, key, dt_folder_survey_entry_t::mtime, dt_folder_survey_entry_t::size, dt_folder_survey_entry_t::stable_scans, dt_folder_survey_entry_t::state, state, dt_folder_survey_t::state_path, and value.
Referenced by _folder_survey_deactivate(), _folder_survey_imported(), _folder_survey_job_run(), _folder_survey_offer_pending_import(), dt_folder_survey_absorb_new_files(), dt_folder_survey_cleanup(), dt_folder_survey_init(), dt_folder_survey_propose_resume(), dt_folder_survey_start(), and dt_folder_survey_stop().
|
static |
Queue one background scan without overlapping the previous scan.
Definition at line 490 of file folder_survey.c.
References _folder_survey, _folder_survey_job_cleanup(), _folder_survey_job_run(), dt_folder_survey_t::active, darktable_t::control, darktable, dt_conf_get_string(), dt_control_add_job(), dt_control_job_create(), dt_control_job_set_params(), dt_free, DT_JOB_QUEUE_SYSTEM_BG, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::generation, IS_NULL_PTR, dt_folder_survey_t::lock, dt_folder_survey_t::scan_running, dt_folder_survey_t::shutting_down, and TRUE.
Referenced by _folder_survey_reschedule(), and _folder_survey_scan_once().
|
static |
Run the immediate post-configuration scan only once.
Definition at line 541 of file folder_survey.c.
References _folder_survey, _folder_survey_scan(), and dt_folder_survey_t::immediate_scan.
Referenced by _folder_survey_reschedule().
|
static |
Read the ordered auto-apply style list from conf.
Styles are a Studio Capture feature, the survey runs in the background regardless of the active view, so styles are applied even if the user has switched away from Studio Capture while a session keeps monitoring.
Definition at line 278 of file folder_survey.c.
References darktable, dt_conf_get_string(), DT_FOLDER_SURVEY_STYLES_CONF_KEY, DT_FOLDER_SURVEY_STYLES_SEPARATOR, dt_free, dt_view_manager_get_current_view(), IS_NULL_PTR, name, view(), and darktable_t::view_manager.
Referenced by _folder_survey_job_run().
| void dt_folder_survey_absorb_new_files | ( | ) |
Record every file currently in the surveyed folder as already handled, so restarting the survey will not import them.
Definition at line 996 of file folder_survey.c.
References _folder_survey, _folder_survey_collect(), _folder_survey_save_locked(), dt_folder_survey_t::baseline_initialized, dt_conf_get_string(), DT_FOLDER_SURVEY_FILE_DONE, dt_free, dt_free_gpointer(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_folder_survey_t::files, dt_folder_survey_t::initialized, IS_NULL_PTR, dt_folder_survey_t::lock, dt_folder_survey_entry_t::mtime, dt_folder_survey_observation_t::mtime, dt_folder_survey_entry_t::size, dt_folder_survey_observation_t::size, dt_folder_survey_entry_t::state, TRUE, and value.
Referenced by _folder_survey_offer_pending_import().
| gboolean dt_folder_survey_can_start | ( | const char ** | message | ) |
Check, without any side effect, whether the persisted configuration has everything dt_folder_survey_start() requires to succeed.
| message | receives a translated, static explanation when the configuration is incomplete or invalid; left untouched otherwise. Safe to display directly in the GUI (e.g. as a status label or tooltip). |
Definition at line 691 of file folder_survey.c.
References dt_conf_get_bool(), dt_conf_get_string_const(), dt_datetime_entry_to_exif(), DT_DATETIME_LENGTH, dt_folder_survey_destination_preview(), dt_free, dt_util_test_writable_dir(), FALSE, IS_NULL_PTR, and TRUE.
Referenced by _studio_import_update_state(), and dt_folder_survey_start().
| void dt_folder_survey_cleanup | ( | ) |
Release folder survey state after control workers have stopped.
Definition at line 1074 of file folder_survey.c.
References _folder_survey, _folder_survey_save_locked(), dt_folder_survey_stop(), dt_free, dt_pthread_mutex_destroy(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::files, dt_folder_survey_t::folder, dt_folder_survey_t::generation, dt_folder_survey_t::initialized, dt_folder_survey_t::lock, and dt_folder_survey_t::state_path.
Referenced by dt_cleanup().
| int dt_folder_survey_count_new_files | ( | ) |
Count files in the surveyed folder that are unknown to the persisted baseline, i.e. files that appeared while the application was closed.
Definition at line 954 of file folder_survey.c.
References _folder_survey, _folder_survey_collect(), dt_folder_survey_t::baseline_initialized, dt_conf_get_string(), DT_FOLDER_SURVEY_FILE_DONE, dt_free, dt_free_gpointer(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_folder_survey_t::files, dt_folder_survey_t::initialized, IS_NULL_PTR, dt_folder_survey_t::lock, dt_folder_survey_entry_t::state, and value.
Referenced by _folder_survey_offer_pending_import().
| char * dt_folder_survey_destination_preview | ( | ) |
Build the expanded destination path of a sample file from the current configuration, for GUI preview purposes.
Definition at line 598 of file folder_survey.c.
References dt_build_filename_from_pattern(), dt_conf_get_bool(), dt_conf_get_string(), dt_control_import_data_free(), dt_datetime_entry_to_exif(), DT_DATETIME_LENGTH, dt_free, dt_image_init(), dt_string_to_datetime(), dt_util_test_writable_dir(), dt_control_import_t::imgs, IS_NULL_PTR, and TRUE.
Referenced by _studio_import_update_preview(), and dt_folder_survey_can_start().
| void dt_folder_survey_halt | ( | ) |
User-requested stop: end monitoring and clear the persisted session marker so the next application start does not propose to resume.
Definition at line 923 of file folder_survey.c.
References _folder_survey, _folder_survey_deactivate(), dt_folder_survey_t::active, darktable, dt_control_log(), DT_DEBUG_CONTROL_SIGNAL_RAISE, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), DT_SIGNAL_FOLDER_SURVEY_CHANGED, dt_folder_survey_t::initialized, dt_folder_survey_t::lock, and darktable_t::signals.
Referenced by _studio_import_toggle_callback().
| void dt_folder_survey_init | ( | ) |
Initialize the folder survey state from the persisted configuration.
Monitoring is NOT started: it must be requested with dt_folder_survey_start() or through dt_folder_survey_propose_resume().
Definition at line 767 of file folder_survey.c.
References _folder_survey, _folder_survey_load_locked(), _folder_survey_save_locked(), dt_folder_survey_t::baseline_initialized, dt_conf_get_string(), dt_conf_set_string(), DT_FOLDER_SURVEY_STATE_FILE, dt_free, dt_free_gpointer(), dt_loc_get_user_config_dir(), dt_pthread_mutex_init(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::files, dt_folder_survey_t::folder, dt_folder_survey_t::initialized, IS_NULL_PTR, dt_folder_survey_t::lock, PATH_MAX, dt_folder_survey_t::state_path, and TRUE.
Referenced by dt_folder_survey_start(), and dt_init().
| gboolean dt_folder_survey_is_active | ( | ) |
TRUE while the periodic folder scan is running.
Definition at line 939 of file folder_survey.c.
References _folder_survey, dt_folder_survey_t::active, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, dt_folder_survey_t::initialized, and dt_folder_survey_t::lock.
Referenced by _studio_import_update_state().
| gboolean dt_folder_survey_propose_resume | ( | ) |
Propose to resume an interrupted studio session at application start.
When the previous session quit while monitoring, ask the user whether to resume; on acceptance, switch to the Studio Capture view, then ask whether files that appeared meanwhile should be imported now (with an optional delete-source-after-verified-copy). Call after the GUI and views are ready.
Definition at line 1038 of file folder_survey.c.
References _folder_survey, _folder_survey_save_locked(), darktable, dt_conf_get_string(), dt_folder_survey_session_was_active(), dt_folder_survey_start(), dt_free, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_ui_main_window(), dt_view_manager_switch(), FALSE, darktable_t::gui, dt_folder_survey_t::lock, dt_gui_gtk_t::ui, darktable_t::view_manager, and dt_folder_survey_t::was_active_last_session.
Referenced by dt_init().
| gboolean dt_folder_survey_session_was_active | ( | ) |
TRUE when the previous application session quit while monitoring.
Definition at line 949 of file folder_survey.c.
References _folder_survey, dt_folder_survey_t::initialized, and dt_folder_survey_t::was_active_last_session.
Referenced by dt_folder_survey_propose_resume(), and dt_init().
| int dt_folder_survey_start | ( | ) |
Validate the persisted configuration and start monitoring.
All settings are read from the folder_survey conf keys. Validation failures are reported through dt_control_log().
Definition at line 869 of file folder_survey.c.
References _folder_survey, _folder_survey_offer_pending_import(), _folder_survey_reschedule(), _folder_survey_save_locked(), dt_folder_survey_t::active, dt_folder_survey_t::baseline_initialized, darktable, dt_conf_get_bool(), dt_conf_get_string(), dt_conf_set_string(), dt_control_log(), DT_DEBUG_CONTROL_SIGNAL_RAISE, dt_folder_survey_can_start(), dt_folder_survey_init(), dt_free, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), DT_SIGNAL_FOLDER_SURVEY_CHANGED, FALSE, dt_folder_survey_t::files, dt_folder_survey_t::folder, dt_folder_survey_t::generation, dt_folder_survey_t::initialized, dt_folder_survey_t::lock, darktable_t::signals, and TRUE.
Referenced by _studio_import_toggle_callback(), and dt_folder_survey_propose_resume().
| void dt_folder_survey_stop | ( | ) |
Stop new scans before control workers begin shutting down.
The persisted session marker keeps its current state so an active session can be proposed for resume on the next start.
Definition at line 1093 of file folder_survey.c.
References _folder_survey, _folder_survey_save_locked(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_folder_survey_t::immediate_scan, dt_folder_survey_t::initialized, dt_folder_survey_t::lock, dt_folder_survey_t::shutting_down, dt_folder_survey_t::timer, and TRUE.
Referenced by dt_cleanup(), and dt_folder_survey_cleanup().
|
static |
Definition at line 78 of file folder_survey.c.
Referenced by _folder_survey_deactivate(), _folder_survey_imported(), _folder_survey_job_cleanup(), _folder_survey_job_run(), _folder_survey_load_locked(), _folder_survey_offer_pending_import(), _folder_survey_reschedule(), _folder_survey_save_locked(), _folder_survey_scan(), _folder_survey_scan_once(), dt_folder_survey_absorb_new_files(), dt_folder_survey_cleanup(), dt_folder_survey_count_new_files(), dt_folder_survey_halt(), dt_folder_survey_init(), dt_folder_survey_is_active(), dt_folder_survey_propose_resume(), dt_folder_survey_session_was_active(), dt_folder_survey_start(), and dt_folder_survey_stop().