Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
folder_survey.c File Reference
#include "system/mem_alloc.h"
#include "common/paths.h"
#include "common/folder_survey.h"
#include "control/settings.h"
#include <glib/gstdio.h>
#include "common/image_extensions.h"
#include "common/datetime.h"
#include "common/file_location.h"
#include "common/conf.h"
#include "control/control.h"
#include "control/jobs.h"
#include "control/jobs/import_jobs.h"
#include <gio/gio.h>
#include "common/utility.h"
#include "common/logging.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.
 
void dt_folder_survey_set_confirm_import_handler (dt_folder_survey_confirm_import_handler_t handler)
 
static void _folder_survey_offer_pending_import ()
 
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_take_session_marker ()
 Consume the "a session was monitoring when we last closed" marker.
 
void dt_folder_survey_forget_session ()
 Persist the cleared session marker, so resume is not proposed again.
 
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 }
 
static dt_folder_survey_confirm_import_handler_t _confirm_import_handler = NULL
 

Macro Definition Documentation

◆ DT_FOLDER_SURVEY_STATE_FILE

#define DT_FOLDER_SURVEY_STATE_FILE   "folder-survey-state.ini"

Definition at line 34 of file folder_survey.c.

Typedef Documentation

◆ dt_folder_survey_entry_t

◆ dt_folder_survey_file_state_t

◆ dt_folder_survey_job_t

◆ dt_folder_survey_observation_t

◆ dt_folder_survey_t

Enumeration Type Documentation

◆ dt_folder_survey_file_state_t

Enumerator
DT_FOLDER_SURVEY_FILE_PENDING 
DT_FOLDER_SURVEY_FILE_QUEUED 
DT_FOLDER_SURVEY_FILE_DONE 

Definition at line 36 of file folder_survey.c.

Function Documentation

◆ _folder_survey_collect()

static int _folder_survey_collect ( const char *  folder,
GHashTable *  observed 
)
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 198 of file folder_survey.c.

References dt_free, dt_supported_image(), error(), folder, 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().

◆ _folder_survey_deactivate()

static void _folder_survey_deactivate ( )
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 582 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().

◆ _folder_survey_imported()

static void _folder_survey_imported ( const char *  source,
const gboolean  success,
gpointer  user_data 
)
static

◆ _folder_survey_job_cleanup()

static void _folder_survey_job_cleanup ( void data)
static

Release one scan job and allow the next periodic scan to start.

Definition at line 478 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().

◆ _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()

static gboolean _folder_survey_scan_once ( gpointer  user_data)
static

Run the immediate post-configuration scan only once.

Definition at line 544 of file folder_survey.c.

References _folder_survey, _folder_survey_scan(), and dt_folder_survey_t::immediate_scan.

Referenced by _folder_survey_reschedule().

◆ _folder_survey_styles_for_import()

static GList * _folder_survey_styles_for_import ( )
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 281 of file folder_survey.c.

References dt_conf_get_string(), DT_FOLDER_SURVEY_STYLES_CONF_KEY, DT_FOLDER_SURVEY_STYLES_SEPARATOR, dt_free, dt_view_manager_get_current_view(), dt_view_manager_get_global(), IS_NULL_PTR, name, names, and view.

Referenced by _folder_survey_job_run().

◆ dt_folder_survey_absorb_new_files()

◆ dt_folder_survey_can_start()

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.

Parameters
messagereceives 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).
Returns
gboolean TRUE when dt_folder_survey_start() would succeed.

Definition at line 694 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, folder, IS_NULL_PTR, preview, and TRUE.

Referenced by _studio_import_update_state(), and dt_folder_survey_start().

◆ dt_folder_survey_cleanup()

◆ dt_folder_survey_count_new_files()

int dt_folder_survey_count_new_files ( )

◆ dt_folder_survey_destination_preview()

char * dt_folder_survey_destination_preview ( )

Build the expanded destination path of a sample file from the current configuration, for GUI preview purposes.

Returns
char* newly allocated preview path, or NULL when the configuration cannot produce a valid destination. Free with dt_free().

Definition at line 601 of file folder_survey.c.

References dt_alloc_align(), 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_free_align, dt_image_init(), dt_string_to_datetime(), dt_util_test_writable_dir(), folder, dt_control_import_t::imgs, IS_NULL_PTR, and TRUE.

Referenced by _studio_import_update_preview(), and dt_folder_survey_can_start().

◆ dt_folder_survey_forget_session()

void dt_folder_survey_forget_session ( )

Persist the cleared session marker, so resume is not proposed again.

Definition at line 1034 of file folder_survey.c.

References _folder_survey, _folder_survey_save_locked(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), and dt_folder_survey_t::lock.

Referenced by dt_folder_survey_propose_resume().

◆ dt_folder_survey_halt()

void dt_folder_survey_halt ( )

◆ dt_folder_survey_init()

◆ dt_folder_survey_is_active()

gboolean dt_folder_survey_is_active ( )

◆ dt_folder_survey_session_was_active()

gboolean dt_folder_survey_session_was_active ( )

TRUE when the previous application session quit while monitoring.

Definition at line 936 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_take_session_marker(), and dt_init().

◆ dt_folder_survey_set_confirm_import_handler()

void dt_folder_survey_set_confirm_import_handler ( dt_folder_survey_confirm_import_handler_t  handler)

Install the handler that asks about pending imports. NULL removes it.

Definition at line 816 of file folder_survey.c.

References _confirm_import_handler.

Referenced by dt_folder_survey_gui_register_handlers().

◆ dt_folder_survey_start()

◆ dt_folder_survey_stop()

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 1060 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().

◆ dt_folder_survey_take_session_marker()

gboolean dt_folder_survey_take_session_marker ( )

Consume the "a session was monitoring when we last closed" marker.

Returns TRUE when the previous run quit while monitoring, and clears the in-memory marker either way, so the resume question is asked at most once per start. Persist the cleared marker with dt_folder_survey_forget_session() if the user declines; accepting leads to dt_folder_survey_start(), which persists it itself.

Definition at line 1025 of file folder_survey.c.

References _folder_survey, dt_folder_survey_session_was_active(), FALSE, TRUE, and dt_folder_survey_t::was_active_last_session.

Referenced by dt_folder_survey_propose_resume().

Variable Documentation

◆ _confirm_import_handler

◆ _folder_survey